home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / oberon-a-1.4ß.lha / Oberon-A / source / Misc / HalveFile.mod < prev    next >
Text File  |  1994-08-08  |  3KB  |  125 lines

  1. (***************************************************************************
  2.  
  3.      $RCSfile: HalveFile.mod $
  4.   Description: A quick hack to halve a file too big to edit
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 1.2 $
  8.       $Author: fjc $
  9.         $Date: 1994/08/08 16:28:05 $
  10.  
  11.   Copyright © 1994, Frank Copeland.
  12.   This file is part of Oberon-A.
  13.   See Oberon-A.doc for conditions of use and distribution.
  14.  
  15.   Log entries are at the end of the file.
  16.  
  17. ***************************************************************************)
  18.  
  19. MODULE HalveFile;
  20.  
  21. (* $P- allow non-portable code *)
  22.  
  23. IMPORT F := Files, Str := Strings, IO := StdIO, Args, SYS := SYSTEM;
  24.  
  25. TYPE
  26.   Path = ARRAY 256 OF CHAR;
  27.  
  28. VAR
  29.   fileName, firstHalf, secondHalf : Path;
  30.  
  31. (*------------------------------------*)
  32. PROCEDURE GetArgs ();
  33.  
  34. BEGIN (* GetArgs *)
  35.   IF Args.argc = 2 THEN
  36.     COPY (Args.argv [1]^, fileName);
  37.     COPY (fileName, firstHalf);
  38.     Str.Append (firstHalf, "_1");
  39.     COPY (fileName, secondHalf);
  40.     Str.Append (secondHalf, "_2");
  41.     IO.WriteF3
  42.       ( "Copying %s to %s & %s\n",
  43.         SYS.ADR (fileName), SYS.ADR (firstHalf), SYS.ADR (secondHalf) )
  44.   ELSE
  45.     IO.WriteStr ("Usage : HalveFile <file>\n");
  46.     HALT (20)
  47.   END; (* ELSE *)
  48. END GetArgs;
  49.  
  50. (*------------------------------------*)
  51. PROCEDURE CopyFile ();
  52.  
  53.   VAR
  54.     f, f1, f2 : F.File;
  55.     r, w : F.Rider;
  56.     len, count, bytes : LONGINT;
  57.     buf : POINTER TO ARRAY 1024 OF SYS.BYTE;
  58.  
  59. BEGIN (* CopyFile *)
  60.   NEW (buf);
  61.   f := F.Old (fileName);
  62.   IF f # NIL THEN
  63.     len := F.Length (f);
  64.     f1 := F.New (firstHalf);
  65.     IF f1 # NIL THEN
  66.       F.Set (r, f, 0);
  67.       F.Set (w, f1, 0);
  68.       count := len DIV 2;
  69.       WHILE count > 0 DO
  70.         IF count > 1024 THEN bytes := 1024
  71.         ELSE                 bytes := count
  72.         END;
  73.         F.ReadBytes (r, buf^, bytes);
  74.         F.WriteBytes (w, buf^, bytes);
  75.         DEC (count, bytes)
  76.       END; (* WHILE *)
  77.       F.Register (f1);
  78.       f2 := F.New (secondHalf);
  79.       IF f2 # NIL THEN
  80.         F.Set (w, f2, 0);
  81.         count := len - (len DIV 2);
  82.         WHILE count > 0 DO
  83.           IF count > 1024 THEN bytes := 1024
  84.           ELSE                 bytes := count
  85.           END;
  86.           F.ReadBytes (r, buf^, bytes);
  87.           F.WriteBytes (w, buf^, bytes);
  88.           DEC (count, bytes)
  89.         END; (* WHILE *)
  90.         F.Register (f2)
  91.       ELSE
  92.         IO.WriteF1 ("Could not open %s\n", SYS.ADR (secondHalf))
  93.       END; (* ELSE *)
  94.     ELSE
  95.       IO.WriteF1 ("Could not open %s\n", SYS.ADR (firstHalf))
  96.     END; (* ELSE *)
  97.     F.Close (f)
  98.   ELSE
  99.     IO.WriteF1 ("Could not open %s\n", SYS.ADR (fileName))
  100.   END; (* ELSE *)
  101. END CopyFile;
  102.  
  103. BEGIN (* HalveFile *)
  104.   IO.WriteStr ("HalveFile\n");
  105.   IO.WriteStr ("Written by Frank Copeland\n\n");
  106.   GetArgs ();
  107.   CopyFile ()
  108. END HalveFile.
  109.  
  110. (***************************************************************************
  111.  
  112.   $Log: HalveFile.mod $
  113.   Revision 1.2  1994/08/08  16:28:05  fjc
  114.   Release 1.4
  115.  
  116.   Revision 1.1  1994/05/12  20:20:07  fjc
  117.   - Prepared for release
  118.  
  119.   Revision 1.0  1994/01/16  13:54:25  fjc
  120.   Start of version control
  121.  
  122.  
  123. ***************************************************************************)
  124.  
  125.