]>
wirehaze git hosting - MS-DOS.git/blob - v2.0/source/COPYPROC.ASM
1 TITLE COPYRPOC
;Procedures called by COPY
15 DATARES
SEGMENT PUBLIC
18 TRANDATA
SEGMENT PUBLIC
20 EXTRN OVERWR
:BYTE,FULDIR
:BYTE,LOSTERR
:BYTE
21 EXTRN DEVWMES
:BYTE,INBDEV
:BYTE,NOSPACE
:BYTE
25 TRANSPACE
SEGMENT PUBLIC
27 EXTRN CFLAG
:BYTE,NXTADD
:WORD,DESTCLOSED
:BYTE
28 EXTRN PLUS
:BYTE,BINARY:BYTE,ASCII
:BYTE,FILECNT
:WORD
29 EXTRN WRITTEN
:BYTE,CONCAT
:BYTE,DESTBUF
:BYTE,SRCBUF
:BYTE
30 EXTRN SDIRBUF
:BYTE,DIRBUF
:BYTE,DESTFCB
:BYTE,MELCOPY
:BYTE
31 EXTRN FIRSTDEST
:BYTE,DESTISDIR
:BYTE,DESTSWITCH
:WORD
32 EXTRN DESTTAIL
:WORD,DESTINFO
:BYTE,INEXACT
:BYTE
33 EXTRN DESTVARS
:BYTE,SRCINFO
:BYTE,RDEOF
:BYTE
34 EXTRN USERDIR1
:BYTE,NOWRITE
:BYTE
35 EXTRN SRCHAND
:WORD,CPDATE
:WORD,CPTIME
:WORD
36 EXTRN SRCISDEV
:BYTE,BYTCNT
:WORD,TPA
:WORD,TERMREAD
:BYTE
37 EXTRN DESTHAND
:WORD,DESTISDEV
:BYTE,DIRCHAR
:BYTE
41 TRANCODE
SEGMENT PUBLIC BYTE
43 PUBLIC SEARCH
,SEARCHNEXT
,DOCOPY
,CLOSEDEST
,FLSHFIL
,SETASC
44 PUBLIC BUILDNAME
,COPERR
46 EXTRN PRINT
:NEAR,BUILDPATH
:NEAR,RESTUDIR1
:NEAR
47 EXTRN COMPNAME
:NEAR,ENDCOPY
:NEAR
49 ASSUME
CS:TRANGROUP
,DS:TRANGROUP
,ES:TRANGROUP
,SS:NOTHING
53 MOV AH,DIR_SEARCH_NEXT
55 JNZ SEARCH
; Do serach-next if ambig
56 OR AH,AH ; Reset zero flag
61 MOV DX,OFFSET TRANGROUP
:DIRBUF
62 INT int_command
; Put result of search in DIRBUF
63 POP AX ; Restore search first/next command
65 INT int_command
; Do the search
70 mov [RDEOF
],0 ; No EOF yet
71 mov dx,offset trangroup
:SRCBUF
74 retc
; If open fails, ignore
75 mov bx,ax ; Save handle
76 mov [SRCHAND
],bx ; Save handle
77 mov ax,(FILE_TIMES
SHL 8)
79 mov [CPDATE
],dx ; Save DATE
80 mov [CPTIME
],cx ; Save TIME
82 INT int_command
; Get device stuff
84 mov [SRCISDEV
],dl ; Set source info
85 jz COPYLP
; Source not a device
87 jz COPYLP
; ASCII device OK
88 mov dx,offset trangroup
:INBDEV
; Cannot do binary input
95 sub cx,dx ; Compute available space
99 JNZ CLOSESRC
; Give up
109 jc CLOSESRC
; Give up if error
110 mov cx,ax ; Get count
111 jcxz CLOSESRC
; No more to read
113 jnz NOTESTA
; Is a device, ASCII mode
122 REPNE SCASB ; Scan for EOF
133 CMP CX,[BYTCNT
] ; Is buffer full?
134 JB TESTDEV
; If not, we may have found EOF
137 JNZ CLOSESRC
; Give up
142 JZ CLOSESRC
; If file then EOF
144 JZ COPYLP
; On device, go till ^Z
153 retnz
; Don't double close
154 MOV AL,BYTE PTR [DESTSWITCH
]
155 CALL SETASC
; Check for B or A switch on destination
158 CMP BX,[BYTCNT
] ; Is memory full?
160 call TRYFLUSH
; Make room for one lousy byte
162 CONCHNG: ; Concat flag changed on us
170 MOV WORD PTR [BX],1
AH ; Add End-of-file mark (Ctrl-Z)
173 MOV [NOWRITE
],0 ; Make sure our ^Z gets written
179 JZ FORGETIT
; WRITTEN = 0 NXTADD = 1 (the ^Z)
184 jz FORGETIT
; Never wrote nothin
188 CMP [INEXACT
],0 ; Copy not exact?
189 JZ DODCLOSE
; If no, copy date & time
193 SHL CL,1 ; Left justify min in CL
196 SHL CX,1 ; hours to high 5 bits, min to 5-10
197 SHR DH,1 ; Divide seconds by 2 (now 5 bits)
198 OR CL,DH ; And stick into low 5 bits of CX
199 PUSH CX ; Save packed time
204 SHL CX,1 ; Year to high 7 bits
205 SHL DH,1 ; Month to high 3 bits
209 SHL DH,1 ; Most sig bit of month in carry
210 ADC CH,0 ; Put that bit next to year
211 OR DL,DH ; Or low three of month into day
212 MOV DH,CH ; Get year and high bit of month
213 POP CX ; Get time back
215 MOV AX,(FILE_TIMES
SHL 8) OR 1
216 INT int_command
; Set date and time
227 CALL DODCLOSE
; Close the dest
228 MOV DX,OFFSET TRANGROUP
:DESTBUF
230 INT int_command
; And delete it
231 MOV [FILECNT
],0 ; No files transferred
243 ; Write out any data remaining in memory.
245 ; [NXTADD] = No. of bytes to write
246 ; [CFLAG] <>0 if file has been created
255 call BUILDDEST
; Find out all about the destination
256 CALL COMPNAME
; Source and dest. the same?
257 JNZ PROCDEST
; If not, go ahead
259 JNZ PROCDEST
; Same name on device OK
260 CMP [CONCAT
],0 ; Concatenation?
261 MOV DX,OFFSET TRANGROUP
:OVERWR
262 JZ COPERRJ
; If not, overwrite error
263 MOV [NOWRITE
],1 ; Flag not writting (just seeking)
265 mov ax,(OPEN
SHL 8) OR 1
267 JNZ DODESTOPEN
; Don't actually create if NOWRITE set
271 mov dx,offset trangroup
:DESTBUF
273 MOV DX,OFFSET TRANGROUP
:FULDIR
275 mov [DESTHAND
],ax ; Save handle
276 mov [CFLAG
],1 ; Destination now exists
279 INT int_command
; Get device stuff
280 mov [DESTISDEV
],dl ; Set dest info
282 jz EXISTS
; Dest not a device
283 mov al,BYTE PTR [DESTSWITCH
]
284 AND AL,ASWITCH
+BSWITCH
286 MOV AL,[ASCII
] ; Neither set, use current setting
288 JZ EXSETA
; Neither set, default to ASCII
290 JPE EXISTS
; Both are set, ignore
292 jz EXISTS
; Leave in cooked mode
293 mov ax,(IOCTL
SHL 8) OR 1
296 mov [DESTISDEV
],dl ; New value
297 INT int_command
; Set device to RAW mode
304 ; What we read in may have been in binary mode, flag zapped write OK
305 mov [ASCII
],ASWITCH
; Set ASCII mode
306 or [INEXACT
],ASWITCH
; ASCII -> INEXACT
309 jnz NOCHECKING
; If nowrite don't bother with name check
310 CALL COMPNAME
; Source and dest. the same?
311 JNZ NOCHECKING
; If not, go ahead
313 JNZ NOCHECKING
; Same name on device OK
314 ; At this point we know in append (would have gotten overwrite error on first
315 ; destination create otherwise), and user trying to specify destination which
316 ; has been scribbled already (if dest had been named first, NOWRITE would
318 MOV DX,OFFSET TRANGROUP
:LOSTERR
; Tell him he's not going to get it
320 MOV [NXTADD
],0 ; Set return
321 INC [TERMREAD
] ; Tell Read to give up
326 mov bx,[DESTHAND
] ; Get handle
329 JCXZ RET60
; If Nothing to write, forget it
330 INC [WRITTEN
] ; Flag that we wrote something
331 CMP [NOWRITE
],0 ; If NOWRITE set, just seek CX bytes
341 MOV DX,OFFSET TRANGROUP
:NOSPACE
344 retz
; Wrote all supposed to
345 test [DESTISDEV
],devid_ISDEV
346 jz COPERR
; Is a file, error
347 test [DESTISDEV
],devid_RAW
348 jnz DEVWRTERR
; Is a raw device, error
350 retnz
; INEXACT so OK
352 retz
; Wrote one byte less (the ^Z)
354 MOV DX,OFFSET TRANGROUP
:DEVWMES
359 jz ENDCOPYJ
; Never actually got it open
361 MOV AH,CLOSE
; Close the file
363 MOV DX,OFFSET TRANGROUP
:DESTBUF
365 INT int_command
; And delete it
372 xor dx,dx ; Zero high half of offset
373 xchg dx,cx ; cx:dx is seek location
374 mov ax,(LSEEK
SHL 8) OR 1
375 INT int_command
; Seek ahead in the file
378 ; If a ^Z has been read we must set the file size to the current
379 ; file pointer location
381 INT int_command
; CX is zero, truncates file
385 ; Given switch vector in AX,
386 ; Set ASCII switch if A is set
387 ; Clear ASCII switch if B is set
388 ; BINARY set if B specified
389 ; Leave ASCII unchanged if neither or both are set
390 ; Also sets INEXACT if ASCII is ever set. AL = ASCII on exit, flags set
391 AND AL,ASWITCH
+BSWITCH
392 JPE LOADSW
; PE means both or neither are set
407 jnz KNOWABOUTDEST
; Already done the figuring
408 MOV DI,OFFSET TRANGROUP
:USERDIR1
409 mov bp,offset trangroup
:DESTVARS
413 ; Now know all about the destination
422 mov si,[DESTTAIL
] ; Create an FCB of the original DEST
423 mov di,offset trangroup
:DESTFCB
424 mov ax,PARSE_FILE_DESCRIPTOR
SHL 8
426 mov ax,word ptr [DESTBUF
] ; Get drive
431 MOV CL,[ASCII
] ; Save current ASCII setting
443 inc [MELCOPY
] ; ambig source, ambig dest, and pluses
448 xor al,2 ; al=2 if unambig dest, =0 if ambig dest
450 shr al,1 ; al=1 if unambig dest AND ambig sorce
451 ; Implies concatination
453 or al,[PLUS
] ; al=1 if concat
457 mov [INEXACT
],al ; Concat -> inexact copy
459 jnz NOTFIRSTDEST
; Binary explicitly given, all OK
460 mov [ASCII
],al ; Concat -> ASCII
462 jnz NOTFIRSTDEST
; ASCII flag set before, DATA read correctly
464 JZ NOTFIRSTDEST
; ASCII flag did not change states
465 ; At this point there may already be binary read data in the read buffer.
466 ; We need to find the first ^Z (if there is one) and trim the amount
467 ; of data in the buffer correctly.
469 JCXZ NOTFIRSTDEST
; No data, everything OK
474 REPNE SCASB ; Scan for EOF
476 JNZ NOTFIRSTDEST
; No ^Z in buffer, everything OK
478 MOV [NXTADD
],DI ; New buffer
480 mov bx,offset trangroup
:DIRBUF
+1 ; Source of replacement chars
482 jz GOTCHRSRC
; Not a concat
483 mov bx,offset trangroup
:SDIRBUF
+1 ; Source of replacement chars
485 mov si,offset trangroup
:DESTFCB
+1 ; Original dest name
486 mov di,[DESTTAIL
] ; Where to put result
503 cmp byte ptr [SI],' '
504 jz ENDDEST
; No extension
521 stosb ; NUL terminate