(*************************************************************************** $RCSfile: HalveFile.mod $ Description: A quick hack to halve a file too big to edit Created by: fjc (Frank Copeland) $Revision: 1.2 $ $Author: fjc $ $Date: 1994/08/08 16:28:05 $ Copyright © 1994, Frank Copeland. This file is part of Oberon-A. See Oberon-A.doc for conditions of use and distribution. Log entries are at the end of the file. ***************************************************************************) MODULE HalveFile; (* $P- allow non-portable code *) IMPORT F := Files, Str := Strings, IO := StdIO, Args, SYS := SYSTEM; TYPE Path = ARRAY 256 OF CHAR; VAR fileName, firstHalf, secondHalf : Path; (*------------------------------------*) PROCEDURE GetArgs (); BEGIN (* GetArgs *) IF Args.argc = 2 THEN COPY (Args.argv [1]^, fileName); COPY (fileName, firstHalf); Str.Append (firstHalf, "_1"); COPY (fileName, secondHalf); Str.Append (secondHalf, "_2"); IO.WriteF3 ( "Copying %s to %s & %s\n", SYS.ADR (fileName), SYS.ADR (firstHalf), SYS.ADR (secondHalf) ) ELSE IO.WriteStr ("Usage : HalveFile \n"); HALT (20) END; (* ELSE *) END GetArgs; (*------------------------------------*) PROCEDURE CopyFile (); VAR f, f1, f2 : F.File; r, w : F.Rider; len, count, bytes : LONGINT; buf : POINTER TO ARRAY 1024 OF SYS.BYTE; BEGIN (* CopyFile *) NEW (buf); f := F.Old (fileName); IF f # NIL THEN len := F.Length (f); f1 := F.New (firstHalf); IF f1 # NIL THEN F.Set (r, f, 0); F.Set (w, f1, 0); count := len DIV 2; WHILE count > 0 DO IF count > 1024 THEN bytes := 1024 ELSE bytes := count END; F.ReadBytes (r, buf^, bytes); F.WriteBytes (w, buf^, bytes); DEC (count, bytes) END; (* WHILE *) F.Register (f1); f2 := F.New (secondHalf); IF f2 # NIL THEN F.Set (w, f2, 0); count := len - (len DIV 2); WHILE count > 0 DO IF count > 1024 THEN bytes := 1024 ELSE bytes := count END; F.ReadBytes (r, buf^, bytes); F.WriteBytes (w, buf^, bytes); DEC (count, bytes) END; (* WHILE *) F.Register (f2) ELSE IO.WriteF1 ("Could not open %s\n", SYS.ADR (secondHalf)) END; (* ELSE *) ELSE IO.WriteF1 ("Could not open %s\n", SYS.ADR (firstHalf)) END; (* ELSE *) F.Close (f) ELSE IO.WriteF1 ("Could not open %s\n", SYS.ADR (fileName)) END; (* ELSE *) END CopyFile; BEGIN (* HalveFile *) IO.WriteStr ("HalveFile\n"); IO.WriteStr ("Written by Frank Copeland\n\n"); GetArgs (); CopyFile () END HalveFile. (*************************************************************************** $Log: HalveFile.mod $ Revision 1.2 1994/08/08 16:28:05 fjc Release 1.4 Revision 1.1 1994/05/12 20:20:07 fjc - Prepared for release Revision 1.0 1994/01/16 13:54:25 fjc Start of version control ***************************************************************************)