home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / JSAGE / ZSUS / PROGPACK / NZ-TOOL4.LBR / CPY.PZS / CPY.PAS
Pascal/Delphi Source File  |  2000-06-30  |  5KB  |  154 lines

  1. {
  2. Program:  CPY.PAS
  3. Author:   Joe Wright
  4. Date:     10 Sept 89
  5. Version:  0.1
  6.  
  7. This single-file copy program uses the NZ-TOOL.BOX to add many Z3LIB
  8. functions to Turbo Pascal programs.
  9.  
  10. Update log: 5 Sep 90, Lee Bradley, Z-Node #12, 203 665-1100.
  11.  
  12. Turbo Pascal Version 2 uses a different BlockRead than Turbo Pascal Version
  13. 3 and does not support a ParamStr builtin function. Using End Address of
  14. 7500 hex to compile. Fixed usage of multiple command line buffer. Other
  15. mostly cosmetic changes.
  16. }
  17.  
  18. Program CPY;
  19. {$I nz-tool.box}
  20. Label 100;
  21. { Constants are used very much like EQUates. }
  22. Const
  23.   ver  = 0.4;    { Version Number }
  24.   cr   = ^M;
  25.   lf   = ^J;
  26.   bel  = ^G;
  27.   recs = 128;    { Sector size }
  28.   bufs = 128;    { 128 of them for 16k (Max) }
  29.   bufbytesize = 16384;    { 128*128 }
  30. Var
  31.   inpbuf : Array[1..bufbytesize] of Byte;
  32.   i      : Integer;
  33.   cks    : Integer;  { Checksum variable }
  34.   ch     : Char;     { Keyboard response }
  35.   o      : Boolean;  { Overwrite option  }
  36.   n      : Boolean;  { No verify option  }
  37.   noofrecstoread : Integer;
  38.   remaining : Integer;
  39.   tail      : str80;
  40. {$I paramstr.pas}
  41. Procedure help;
  42. Begin
  43.   Write(ParamStr(0),' Ver ',ver:1:1,' Single-File Copy Program',cr,lf,
  44.   ' Syntax: ',ParamStr(0),' [dir:]source [[dir:]destination] [/oo]',cr,lf,
  45.   '  where ''/oo'' is [O]verwrite and/or [N]o Verify options.');
  46. End;
  47. Begin {ning of CPY.PAS}
  48.   o := false;
  49.   n := false;
  50.   CURDU := retud;       { retud from NZ-TOOL.BOX }
  51.   DSTDU := CURDU;
  52.   If Length(ParamStr(1))=0 Then Begin help; Goto 100; End;
  53.   tail := ParamStr(1)+' '+ParamStr(2)+' '+ParamStr(3);
  54.   i := Pos('/',tail);
  55.   If i<>0 Then
  56.     Repeat
  57.       i := i+1;
  58.       If tail[i]='O' Then o := true;
  59.       If tail[i]='N' Then n := true;
  60.       If tail[i]='/' Then Begin help; Goto 100; End;
  61.     Until tail[i]=#0;
  62.   SPEC1 := ParamStr(1);
  63.   parse(SPEC1);         { parse dir: part to dirs }
  64.   SRCDU := dnscan;      { dnscan resolves d:, u:, du: and dir: }
  65.   logud(SRCDU);         { log it in }
  66.   Assign(SOURCE,SPEC1);
  67.   {$I-}
  68.   Reset(SOURCE);        { open the input file }
  69.   {$I+}
  70.   If IOresult<>0 Then
  71.     Write('Can''t find ',SPEC1)
  72.   Else
  73.     Begin {destin}
  74.       SPEC2 := SPEC1;
  75.       SPEC1 := ParamStr(2);
  76.       parse(SPEC1);
  77.       If (Length(SPEC1)=0) Or (SPEC1[1]='/') Then SPEC1 := SPEC2;
  78.       DSTDU := dnscan;
  79.       If (DSTDU=SRCDU) And (SPEC1=SPEC2) Then
  80.         Write(bel,'Don''t be silly..') { source=destination }
  81.       Else
  82.         Begin {copy}
  83.           logud(DSTDU);  { Log into destination area }
  84.           Assign(DESTIN,SPEC1);
  85.           If Not o Then
  86.             Begin
  87.               {$I-}
  88.               Reset(DESTIN);
  89.               {$I+}
  90.               If IOresult=0 Then
  91.                 Begin
  92.                   pdu(DSTDU);
  93.                   If dutdir(DSTDU) Then Write(NAME,' ');
  94.                   Write(SPEC1,' Exists.  Overwrite? (Y or N) ');
  95.                   Read(Kbd,ch); WriteLn(ch);
  96.                   If UpCase(ch)<>'Y' Then Halt;
  97.                 End;
  98.             End;
  99.           ReWrite(DESTIN);  { erases any existing file }
  100.           { Tell the user we're up to something }
  101.           Write(' Copying ');
  102.           pdu(SRCDU);
  103.           If dutdir(SRCDU) Then Write(NAME,' ');
  104.           Write(SPEC2,' to ');
  105.           pdu(DSTDU);
  106.           If dutdir(DSTDU) Then Write(NAME,' ');
  107.           WriteLn(SPEC1);
  108.           cks := 0;  { clear the checksum word }
  109.           remaining := FileSize(SOURCE);
  110.           While remaining>0 Do
  111.             Begin
  112.               If bufs<=remaining Then
  113.                 noofrecstoread := bufs
  114.               Else
  115.                 noofrecstoread := remaining;    
  116.               Write('.');
  117.               logud(SRCDU);
  118.               BlockRead(SOURCE,inpbuf,noofrecstoread);
  119.               If Not n Then
  120.                 For i := 0 To noofrecstoread - 1 Do
  121.                   cks := cks + Mem[Addr(inpbuf) + i];
  122.               logud(DSTDU);
  123.               BlockWrite(DESTIN,inpbuf,noofrecstoread);
  124.               remaining := remaining - noofrecstoread;
  125.             End; 
  126.           Close(DESTIN);
  127.           If Not n Then
  128.             Begin {verify}
  129.               Reset(DESTIN);   { Prepare to read it }
  130.               Write(cr,lf,' Verifying ');
  131.               pdu(DSTDU);
  132.               If dutdir(DSTDU) Then Write(NAME,' ');
  133.               WriteLn(SPEC1);
  134.               remaining := FileSize(DESTIN);
  135.               While remaining>0 Do
  136.                 Begin
  137.                   Write('.');
  138.                   If bufs<=remaining Then
  139.                     noofrecstoread := bufs
  140.                   Else
  141.                     noofrecstoread := remaining;
  142.                   BlockRead(DESTIN,inpbuf,noofrecstoread);
  143.                   For i := 0 To noofrecstoread - 1 Do
  144.                     cks := cks - Mem[Addr(inpbuf) + i];
  145.                   remaining := remaining - noofrecstoread;
  146.                 End;
  147.               If cks<>0 Then Write(bel,cr,lf,'  Failed!')
  148.             End; {verify}
  149.         End; {copy}
  150.     End; {destin}
  151. 100:    
  152. End. {of CPY.PAS}
  153.  
  154.