{ Program: CPY.PAS Author: Joe Wright Date: 10 Sept 89 Version: 0.1 This single-file copy program uses the NZ-TOOL.BOX to add many Z3LIB functions to Turbo Pascal programs. Update log: 5 Sep 90, Lee Bradley, Z-Node #12, 203 665-1100. Turbo Pascal Version 2 uses a different BlockRead than Turbo Pascal Version 3 and does not support a ParamStr builtin function. Using End Address of 7500 hex to compile. Fixed usage of multiple command line buffer. Other mostly cosmetic changes. } Program CPY; {$I nz-tool.box} Label 100; { Constants are used very much like EQUates. } Const ver = 0.4; { Version Number } cr = ^M; lf = ^J; bel = ^G; recs = 128; { Sector size } bufs = 128; { 128 of them for 16k (Max) } bufbytesize = 16384; { 128*128 } Var inpbuf : Array[1..bufbytesize] of Byte; i : Integer; cks : Integer; { Checksum variable } ch : Char; { Keyboard response } o : Boolean; { Overwrite option } n : Boolean; { No verify option } noofrecstoread : Integer; remaining : Integer; tail : str80; {$I paramstr.pas} Procedure help; Begin Write(ParamStr(0),' Ver ',ver:1:1,' Single-File Copy Program',cr,lf, ' Syntax: ',ParamStr(0),' [dir:]source [[dir:]destination] [/oo]',cr,lf, ' where ''/oo'' is [O]verwrite and/or [N]o Verify options.'); End; Begin {ning of CPY.PAS} o := false; n := false; CURDU := retud; { retud from NZ-TOOL.BOX } DSTDU := CURDU; If Length(ParamStr(1))=0 Then Begin help; Goto 100; End; tail := ParamStr(1)+' '+ParamStr(2)+' '+ParamStr(3); i := Pos('/',tail); If i<>0 Then Repeat i := i+1; If tail[i]='O' Then o := true; If tail[i]='N' Then n := true; If tail[i]='/' Then Begin help; Goto 100; End; Until tail[i]=#0; SPEC1 := ParamStr(1); parse(SPEC1); { parse dir: part to dirs } SRCDU := dnscan; { dnscan resolves d:, u:, du: and dir: } logud(SRCDU); { log it in } Assign(SOURCE,SPEC1); {$I-} Reset(SOURCE); { open the input file } {$I+} If IOresult<>0 Then Write('Can''t find ',SPEC1) Else Begin {destin} SPEC2 := SPEC1; SPEC1 := ParamStr(2); parse(SPEC1); If (Length(SPEC1)=0) Or (SPEC1[1]='/') Then SPEC1 := SPEC2; DSTDU := dnscan; If (DSTDU=SRCDU) And (SPEC1=SPEC2) Then Write(bel,'Don''t be silly..') { source=destination } Else Begin {copy} logud(DSTDU); { Log into destination area } Assign(DESTIN,SPEC1); If Not o Then Begin {$I-} Reset(DESTIN); {$I+} If IOresult=0 Then Begin pdu(DSTDU); If dutdir(DSTDU) Then Write(NAME,' '); Write(SPEC1,' Exists. Overwrite? (Y or N) '); Read(Kbd,ch); WriteLn(ch); If UpCase(ch)<>'Y' Then Halt; End; End; ReWrite(DESTIN); { erases any existing file } { Tell the user we're up to something } Write(' Copying '); pdu(SRCDU); If dutdir(SRCDU) Then Write(NAME,' '); Write(SPEC2,' to '); pdu(DSTDU); If dutdir(DSTDU) Then Write(NAME,' '); WriteLn(SPEC1); cks := 0; { clear the checksum word } remaining := FileSize(SOURCE); While remaining>0 Do Begin If bufs<=remaining Then noofrecstoread := bufs Else noofrecstoread := remaining; Write('.'); logud(SRCDU); BlockRead(SOURCE,inpbuf,noofrecstoread); If Not n Then For i := 0 To noofrecstoread - 1 Do cks := cks + Mem[Addr(inpbuf) + i]; logud(DSTDU); BlockWrite(DESTIN,inpbuf,noofrecstoread); remaining := remaining - noofrecstoread; End; Close(DESTIN); If Not n Then Begin {verify} Reset(DESTIN); { Prepare to read it } Write(cr,lf,' Verifying '); pdu(DSTDU); If dutdir(DSTDU) Then Write(NAME,' '); WriteLn(SPEC1); remaining := FileSize(DESTIN); While remaining>0 Do Begin Write('.'); If bufs<=remaining Then noofrecstoread := bufs Else noofrecstoread := remaining; BlockRead(DESTIN,inpbuf,noofrecstoread); For i := 0 To noofrecstoread - 1 Do cks := cks - Mem[Addr(inpbuf) + i]; remaining := remaining - noofrecstoread; End; If cks<>0 Then Write(bel,cr,lf,' Failed!') End; {verify} End; {copy} End; {destin} 100: End. {of CPY.PAS}