summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/COMMAND/COPYPR1.ASM
blob: e7279107845311f9598a4ea5f6da05c0fb63b17a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
 page 80,132
;	SCCSID = @(#)copypr1.asm	1.1 85/05/14
;	SCCSID = @(#)copypr1.asm	1.1 85/05/14
	INCLUDE comsw.asm

.xlist
.xcref
	INCLUDE DOSSYM.INC
;	INCLUDE DEVSYM.INC
	INCLUDE comseg.asm
	INCLUDE comequ.asm
.list
.cref


TRANDATA	SEGMENT PUBLIC BYTE	;AC000;
	EXTRN	DEVWMES_ptr:word
	EXTRN	ext_open_parms:byte	;AN000;
	EXTRN	ext_open_seg:word	;AN000;
	EXTRN	ext_open_off:word	;AN000;
	EXTRN	Extend_buf_sub:byte	;AN000;
	EXTRN	LOSTERR_ptr:word
	EXTRN	NOSPACE_ptr:word
	EXTRN	OVERWR_ptr:word
TRANDATA ENDS

TRANSPACE	SEGMENT PUBLIC BYTE	;AC000;
	EXTRN	ASCII:BYTE
	EXTRN	BINARY:BYTE
	EXTRN	CFLAG:BYTE
	EXTRN	CONCAT:BYTE
	EXTRN	concat_xa:byte		;AC000;
	EXTRN	DESTBUF:BYTE
	EXTRN	DESTCLOSED:BYTE
	EXTRN	DESTHAND:WORD
	EXTRN	DESTISDEV:BYTE
	EXTRN	DESTSWITCH:WORD
	EXTRN	INEXACT:BYTE
	EXTRN	NOWRITE:BYTE
	EXTRN	NXTADD:WORD
	EXTRN	plus_comma:byte 	;AN000;
	EXTRN	RDEOF:BYTE
	EXTRN	src_xa_seg:word 	;AN000;
	EXTRN	SRCISDEV:BYTE
	EXTRN	string_ptr_2:word	;AN000;
	EXTRN	TERMREAD:BYTE
	EXTRN	TPA:WORD
	EXTRN	WRITTEN:WORD
TRANSPACE	ENDS

TRANCODE	SEGMENT PUBLIC BYTE

	EXTRN	ENDCOPY:NEAR

	PUBLIC	FLSHFIL
	PUBLIC	TRYFLUSH

ASSUME	CS:TRANGROUP,DS:TRANGROUP,ES:TRANGROUP,SS:NOTHING

TRYFLUSH:
	mov	al,[CONCAT]
	push	ax
	call	FLSHFIL
	pop	ax
	cmp	al,[CONCAT]
	return

FLSHFIL:
;
; Write out any data remaining in memory.
; Inputs:
;	[NXTADD] = No. of bytes to write
;	[CFLAG] <> 0 if file has been created
; Outputs:
;	[NXTADD] = 0
;
	MOV	[TERMREAD],0
	cmp	[CFLAG],0
	JZ	NOTEXISTS
	JMP	EXISTS

NOTEXISTS:
	invoke	BUILDDEST			; Find out all about the destination
	invoke	COMPNAME			; Source and dest. the same?
	JNZ	PROCDEST			; If not, go ahead
	CMP	[SRCISDEV],0
	JNZ	PROCDEST			; Same name on device OK
	CMP	[CONCAT],0			; Concatenation?
	MOV	DX,OFFSET TRANGROUP:OVERWR_ptr
	JNZ	NO_CONCAT_ERR			;AC000; If not, overwrite error
	JMP	COPERR				;AC000;

NO_CONCAT_ERR:					;AC000;
	MOV	[NOWRITE],1			; Flag not writting (just seeking)

PROCDEST:
	MOV	AX,EXTOPEN SHL 8		;AC000; open the file
	mov	si,offset trangroup:destbuf	;AN030; get file name
	mov	di,-1				;AN030; indicate no parameters
	cmp	src_xa_seg,no_xa_seg		;AN030; is there an XA segment?
	jz	cont_no_xa			;AN030; no - no parameters
	mov	di,offset trangroup:Ext_open_parms ;AN030; get parameters
	mov	bx,src_xa_seg			;AN030; get extended attribute segment
	mov	ext_open_seg,bx 		;AN030; put it in parameter list
	mov	ext_open_off,0			;AN030; offset is 0

cont_no_xa:					;AN030;
	mov	bx,write_open_mode		;AN000; get open mode for COPY
	xor	cx,cx				;AN000; no special files
	mov	dx,write_open_flag		;AN000; set up open flags

	CMP	[NOWRITE],0
	JNZ	DODESTOPEN		; Don't actually create if NOWRITE set
	mov	dx,creat_open_flag		;AC000; set up create flags

DODESTOPEN:
	INT	int_command
;
; We assume that the error is normal.  TriageError will correct the DX value
; appropriately.
;
	JNC	dest_open_okay			;AC030;

xa_set_error:					;AN030; error occurred on XA
	invoke	set_ext_error_msg		;AN030; get extended error

ext_err_set:					;AN030;
	mov	string_ptr_2,offset trangroup:destbuf ;AN000; get address of failed string
	mov	Extend_buf_sub,one_subst	;AN030; put number of subst in control block

COPERRJ2:					;AN030;
	jmp	COPERR				;AN030; go issue message

dest_open_okay: 				;AC030
	mov	[DESTHAND],ax			; Save handle
	mov	[CFLAG],1			; Destination now exists
	mov	bx,ax
	mov	cx,bx				;AN030; get handle into CX
	invoke	set_file_code_page		;AN030; set the code page for the target
	jc	ext_err_set			;AN030; if no error, continue

	mov	[concat_xa],0			;AN000; set first file flag off
	mov	ax,(IOCTL SHL 8)
	INT	int_command			; Get device stuff
	mov	[DESTISDEV],dl			; Set dest info
	test	dl,devid_ISDEV
	jz	exists				;AC030; Dest a device

	mov	al,BYTE PTR [DESTSWITCH]
	AND	AL,SwitchA+SwitchB
	JNZ	TESTBOTH
	MOV	AL,[ASCII]			; Neither set, use current setting
	OR	AL,[BINARY]
	JZ	EXSETA				; Neither set, default to ASCII

TESTBOTH:
	JPE	EXISTS				; Both are set, ignore
	test	AL,SwitchB
	jz	EXISTS				; Leave in cooked mode
	mov	ax,(IOCTL SHL 8) OR 1
	xor	dh,dh
	or	dl,devid_RAW
	mov	[DESTISDEV],dl			; New value
	INT	int_command			; Set device to RAW mode
	jmp	short EXISTS

COPERRJ:
	jmp	SHORT COPERR

EXSETA:
;
; What we read in may have been in binary mode, flag zapped write OK
;
	mov	[ASCII],SwitchA 		; Set ASCII mode
	or	[INEXACT],SwitchA		; ASCII -> INEXACT

EXISTS:
	cmp	[NOWRITE],0
	jnz	NOCHECKING			; If nowrite don't bother with name check
	cmp	plus_comma,1			;g  don't check if just doing +,,
	jz	NOCHECKING			;g
	invoke	COMPNAME			; Source and dest. the same?
	JNZ	NOCHECKING			; If not, go ahead
	CMP	[SRCISDEV],0
	JNZ	NOCHECKING			; Same name on device OK
;
; At this point we know in append (would have gotten overwrite error on first
; destination create otherwise), and user trying to specify destination which
; has been scribbled already (if dest had been named first, NOWRITE would
; be set).
;
	MOV	DX,OFFSET TRANGROUP:LOSTERR_ptr ; Tell him he's not going to get it
	invoke	std_Eprintf			;AC022;
	MOV	[NXTADD],0			; Set return
	INC	[TERMREAD]			; Tell Read to give up

RET60:
	return

NOCHECKING:
	mov	bx,[DESTHAND]			; Get handle
	XOR	CX,CX
	XCHG	CX,[NXTADD]
	JCXZ	RET60				; If Nothing to write, forget it
	INC	[WRITTEN]			; Flag that we wrote something
	CMP	[NOWRITE],0			; If NOWRITE set, just seek CX bytes
	JNZ	SEEKEND
	XOR	DX,DX
	PUSH	DS
	MOV	DS,[TPA]
ASSUME	DS:NOTHING
	MOV	AH,WRITE
	INT	int_command
	POP	DS
ASSUME	DS:TRANGROUP
	MOV	DX,OFFSET TRANGROUP:NOSPACE_ptr
	JC	xa_set_error_Jmp		;AC022; Failure
	sub	cx,ax
	retz					; Wrote all supposed to
	test	[DESTISDEV],devid_ISDEV
	jz	COPERR				; Is a file, error
	test	[DESTISDEV],devid_RAW
	jnz	DEVWRTERR			; Is a raw device, error
	cmp	[INEXACT],0
	retnz					; INEXACT so OK
	dec	cx
	retz					; Wrote one byte less (the ^Z)

DEVWRTERR:
	MOV	DX,OFFSET TRANGROUP:DEVWMES_ptr

PUBLIC COPERR
COPERR:
	INVOKE	std_Eprintf			;AC022;

COPERRP:
	inc	[DESTCLOSED]
	cmp	[CFLAG],0
	jz	ENDCOPYJ			; Never actually got it open
	MOV	bx,[DESTHAND]
	CMP	BX,0
	JLE	NoClose
	MOV	AH,CLOSE			; Close the file
	INT	int_command

NoClose:
	MOV	DX,OFFSET TRANGROUP:DESTBUF
	MOV	AH,UNLINK
	INT	int_command			; And delete it
	MOV	[CFLAG],0

ENDCOPYJ:
	JMP	ENDCOPY

XA_SET_ERROR_JMP:				;AN022; Go set up error message
	jmp	xa_set_error			;AN022;

SEEKEND:
	xor	dx,dx				; Zero high half of offset
	xchg	dx,cx				; cx:dx is seek location
	mov	ax,(LSEEK SHL 8) OR 1
	INT	int_command			; Seek ahead in the file
	cmp	[RDEOF],0
	retz
;
; If a ^Z has been read we must set the file size to the current
; file pointer location
;
	MOV	AH,WRITE
	INT	int_command			; CX is zero, truncates file
	jc	xa_set_error_Jmp		;AC022; Failure
	return

TRANCODE ENDS
	 END