]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/CMD/COMMAND/TMISC2.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / CMD / COMMAND / TMISC2.ASM
1 page 80,132
2 ; SCCSID = @(#)tmisc2.asm 4.3 85/06/25
3 ; SCCSID = @(#)tmisc2.asm 4.3 85/06/25
4 TITLE Part7 COMMAND Transient Routines
5
6 ; More misc routines
7
8
9 .xlist
10 .xcref
11 INCLUDE comsw.asm
12 INCLUDE DOSSYM.INC
13 INCLUDE comseg.asm
14 INCLUDE comequ.asm
15 INCLUDE ioctl.inc
16 .list
17 .cref
18
19
20 CODERES SEGMENT PUBLIC BYTE ;AC000;
21 CodeRes ENDS
22
23 DATARES SEGMENT PUBLIC BYTE ;AC000;
24 EXTRN IFFlag:BYTE
25 EXTRN PIPEFLAG:BYTE
26 EXTRN RE_OUTSTR:BYTE
27 EXTRN RE_OUT_APP:BYTE
28 DATARES ENDS
29
30 TRANDATA SEGMENT PUBLIC BYTE ;AC000;
31 EXTRN AccDen_PTR:WORD
32 EXTRN Extend_buf_ptr:word ;AN000;
33 EXTRN FULDIR_PTR:WORD
34 EXTRN msg_disp_class:byte ;AN000;
35 TRANDATA ENDS
36
37 TRANSPACE SEGMENT PUBLIC BYTE ;AC000;
38 EXTRN DESTINFO:BYTE
39 EXTRN DESTISDIR:BYTE
40 EXTRN KPARSE:BYTE ;AC000;
41 EXTRN ONE_CHAR_VAL:BYTE ;AN011;
42 EXTRN PATHCNT:WORD
43 EXTRN PATHPOS:WORD
44 EXTRN PATHSW:WORD
45 EXTRN RE_INSTR:BYTE
46 EXTRN RESSEG:WORD
47 EXTRN SRCBUF:BYTE
48 EXTRN SWITCHAR:BYTE
49
50 IF IBM
51 EXTRN ROM_CALL:BYTE
52 EXTRN ROM_CS:WORD
53 EXTRN ROM_IP:WORD
54 ENDIF
55
56 TRANSPACE ENDS
57
58 TRANCODE SEGMENT PUBLIC byte
59
60 ASSUME CS:TRANGROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING
61
62 EXTRN CERROR:NEAR
63
64 IF IBM
65 EXTRN ROM_EXEC:NEAR
66 EXTRN ROM_SCAN:NEAR
67 ENDIF
68
69 PUBLIC IOSET
70 PUBLIC MOVE_TO_SRCBUF ;AN000;
71 PUBLIC PGETARG
72 PUBLIC SETPATH
73 PUBLIC TESTDOREIN
74 PUBLIC TESTDOREOUT
75
76
77 ASSUME DS:TRANGROUP
78
79 SETPATH:
80 ;
81 ; Get an ASCIZ argument from the unformatted parms
82 ; DESTISDIR set if pathchars in string
83 ; DESTINFO set if ? or * in string
84 ;
85 MOV AX,[PATHCNT] ;AC000; get length of string
86 MOV SI,[PATHPOS] ;AC000; get start of source buffer
87
88 GETPATH:
89 MOV [DESTINFO],0
90 MOV [DESTISDIR],0
91 MOV SI,[PATHPOS]
92 MOV CX,[PATHCNT]
93 MOV DX,SI
94 JCXZ PATHDONE
95 PUSH CX
96 PUSH SI
97 INVOKE SWITCH
98 MOV [PATHSW],AX
99 POP BX
100 SUB BX,SI
101 POP CX
102 ADD CX,BX
103 MOV DX,SI
104
105 SKIPPATH:
106
107 ;;;; IF KANJI 3/3/KK
108 MOV [KPARSE],0
109
110 SKIPPATH2:
111 ;;;; ENDIF 3/3/KK
112
113 JCXZ PATHDONE
114 DEC CX
115 LODSB
116
117 ;;;; IF KANJI 3/3/KK
118 INVOKE TESTKANJ
119 JZ TESTPPSEP
120 DEC CX
121 INC SI
122 INC [KPARSE]
123 JMP SKIPPATH2
124
125 TESTPPSEP:
126 ;;;; ENDIF 3/3/KK
127
128 INVOKE PATHCHRCMP
129 JNZ TESTPMETA
130 INC [DESTISDIR]
131
132 TESTPMETA:
133 CMP AL,'?'
134 JNZ TESTPSTAR
135 OR [DESTINFO],2
136
137 TESTPSTAR:
138 CMP AL,star
139 JNZ TESTPDELIM
140 OR [DESTINFO],2
141
142 TESTPDELIM:
143 INVOKE DELIM
144 JZ PATHDONEDEC
145 CMP AL,[SWITCHAR]
146 JNZ SKIPPATH
147
148 PATHDONEDEC:
149 DEC SI
150
151 PATHDONE:
152 XOR AL,AL
153 XCHG AL,[SI]
154 INC SI
155 CMP AL,0DH
156 JNZ NOPSTORE
157 MOV [SI],AL ;Don't loose the CR
158
159 NOPSTORE:
160 MOV [PATHPOS],SI
161 MOV [PATHCNT],CX
162 return
163
164 PGETARG:
165 MOV SI,80H
166 LODSB
167 OR AL,AL
168 retz
169 CALL PSCANOFF
170 CMP AL,13
171 return
172
173 PSCANOFF:
174 LODSB
175 INVOKE DELIM
176 JNZ PSCANOFFD
177 CMP AL,';'
178 JNZ PSCANOFF ; ';' is not a delimiter
179
180 PSCANOFFD:
181 DEC SI ; Point to first non-delimiter
182 return
183
184 IOSET:
185 ;
186 ; ALL REGISTERS PRESERVED
187 ;
188 ASSUME DS:NOTHING,ES:NOTHING,SS:NOTHING
189
190 PUSH DS
191 PUSH DX
192 PUSH AX
193 PUSH BX
194 PUSH CX
195 MOV DS,[RESSEG]
196 ASSUME DS:RESGROUP
197
198 CMP [PIPEFLAG],0
199 JNZ NOREDIR ; Don't muck up the pipe
200 TEST IFFlag,-1
201 JNZ NoRedir
202 CALL TESTDOREIN
203 CALL TESTDOREOUT
204
205 NOREDIR:
206 POP CX
207 POP BX
208 POP AX
209 POP DX
210 POP DS
211 ASSUME DS:NOTHING
212 return
213
214 TESTDOREIN:
215
216 ASSUME DS:RESGROUP
217
218 CMP [RE_INSTR],0
219 retz
220 PUSH DS
221 PUSH CS
222 POP DS
223 MOV DX,OFFSET tranGROUP:RE_INSTR
224 MOV AX,(OPEN SHL 8)
225 MOV BX,AX
226 INT int_command
227 POP DS
228 JC REDIRERR
229 MOV BX,AX
230 MOV AL,0FFH
231 ;
232 ; Mega sleaze!! We move the SFN from the new handle spot into the old stdin
233 ; spot. We invalidate the new JFN we got.
234 ;
235 XCHG AL,[BX.PDB_JFN_Table]
236 MOV DS:[PDB_JFN_Table],AL
237
238 return
239 ;
240 ; We had some kind of error on the redirection. Figure out what the
241 ; appropriate message should be; BX has the system call that failed
242 ;
243 REDIRERR:
244 PUSH CS
245 POP DS
246 Call TriageError
247 ;
248 ; At this point, we have recognized the network-generated access denied error.
249 ; The correct message is in DX
250 ;
251 CMP AX,65
252 JZ CERRORJ ;AC000; just issue message returned
253 CMP BH,OPEN
254 JZ OpenError
255 ;
256 ; The error was for a create operation. Report the error as a creation error.
257 ;
258 MOV DX,OFFSET TranGroup:FULDIR_PTR
259
260 CERRORJ:
261 JMP CERROR
262 ;
263 ; The system call was an OPEN. Report either file not found or path not found.
264 ;
265
266 OpenError:
267 mov msg_disp_class,ext_msg_class ;AN000; set up extended error msg class
268 mov dx,offset TranGroup:Extend_Buf_ptr ;AC000; get extended message pointer
269 mov Extend_Buf_ptr,ax ;AN000; get message number in control block
270 JMP CERROR
271
272 TESTDOREOUT:
273
274 ASSUME DS:RESGROUP
275
276 CMP [RE_OUTSTR],0
277 JNZ REOUTEXISTS ;AN017; need long jump
278 JMP NOREOUT ;AN017;
279
280 REOUTEXISTS:
281 CMP [RE_OUT_APP],0
282 JZ REOUTCRT
283 ;
284 ; The output redirection was for append. We open for write and seek to the
285 ; end.
286 ;
287 MOV DX,OFFSET RESGROUP:RE_OUTSTR
288 MOV AX,(OPEN SHL 8) OR 2 ;AC011; Open for read/write
289 PUSH AX
290 INT int_command
291 POP BX
292 JC OpenWriteError
293
294 MOV BX,AX
295 MOV AX,IOCTL SHL 8 ;AN035; Get attributes of handle
296 INT int_command ;AN035;
297 TEST DL,devid_ISDEV ;AN035; Is it a device?
298 JNZ SET_REOUT ;AN035; Yes, don't read from it
299
300 MOV AX,(LSEEK SHL 8) OR 2
301 MOV CX,-1 ;AC011; MOVE TO EOF -1
302 MOV DX,CX ;AC011;
303 INT int_command
304 PUSH CS ;AN011; Get transient seg to DS
305 POP DS ;AN011;
306 assume DS:Trangroup ;AN011;
307 MOV AX,(READ SHL 8) ;AN011; Read one byte from the
308 MOV CX,1 ;AN011; file into one_char_val
309 MOV DX,OFFSET Trangroup:ONE_CHAR_VAL;AN011;
310 INT int_command ;AN011;
311 JC OpenWriteError ;AN011; If error, exit
312 cmp ax,cx ;AN017; Did we read 1 byte?
313 jnz reout_0_length ;AN017; No - file must be 0 length
314
315 cmp one_char_val,01ah ;AN011; Was char an eof mark?
316 mov DS,[resseg] ;AN011; Get resident segment back
317 assume DS:Resgroup ;AN011;
318 JNZ SET_REOUT ;AN011; No, just continue
319 MOV AX,(LSEEK SHL 8) OR 1 ;AN011; EOF mark found
320 MOV CX,-1 ;AN011; LSEEK back one byte
321 MOV DX,CX ;AN011;
322 INT int_command ;AN011;
323 JMP SHORT SET_REOUT
324
325 reout_0_length: ;AN017; We have a 0 length file
326 mov DS,[resseg] ;AN017; Get resident segment back
327 assume DS:Resgroup ;AN017;
328 MOV AX,(LSEEK SHL 8) ;AN017; Move to beginning of file
329 XOR CX,CX ;AN017; Offset is 0
330 MOV DX,CX ;AN017;
331 INT int_command ;AN017;
332 JMP SHORT SET_REOUT ;AN017; now finish setting up redirection
333
334 OpenWriteError:
335 CMP AX,error_access_denied
336 STC ; preserve error
337 JNZ REOUTCRT ;AN017; need long jump
338 JMP REDIRERR ;AN017;
339
340 REOUTCRT:
341 MOV DX,OFFSET RESGROUP:RE_OUTSTR
342 XOR CX,CX
343 MOV AH,CREAT
344 PUSH AX
345 INT int_command
346 POP BX
347 JNC NOREDIRERR ;AC011;
348 JMP REDIRERR ;AC011;
349
350 NOREDIRERR: ;AN011;
351 MOV BX,AX
352
353 SET_REOUT:
354 ;
355 ; Mega sleaze!! We move the SFN from the new handle spot into the old stdout
356 ; spot. We invalidate the new JFN we got.
357 ;
358 MOV AL,0FFH
359 XCHG AL,[BX.PDB_JFN_Table]
360 MOV DS:[PDB_JFN_Table+1],AL
361
362 NOREOUT:
363 return
364
365 ;
366 ; Compute length of string (including NUL) in DS:SI into CX. Change no other
367 ; registers
368 ;
369 Procedure DSTRLEN,NEAR
370
371 SaveReg <AX>
372 XOR CX,CX
373 CLD
374
375 DLoop: LODSB
376 INC CX
377 OR AL,AL
378 JNZ DLoop
379 SUB SI,CX
380 RestoreReg <AX>
381 return
382
383 EndProc DSTRLEN
384
385 Break <Extended error support>
386
387 ;
388 ; TriageError will examine the return from a carry-set system call and
389 ; return the correct error if applicable.
390 ;
391 ; Inputs: outputs from a carry-settable system call
392 ; No system calls may be done in the interrim
393 ; Outputs: If carry was set on input
394 ; carry set on output
395 ; DX contains trangroup offset to printf message
396 ; else
397 ; No registers changed
398 ;
399
400 Procedure TriageError,NEAR
401
402 retnc ; no carry => do nothing...
403 PUSHF
404 SaveReg <BX,CX,SI,DI,BP,ES,DS,AX,DX>
405 MOV AH,GetExtendedError
406 INT 21h
407 RestoreReg <CX,BX> ; restore original AX
408 MOV DX,OFFSET TranGroup:AccDen_PTR
409 CMP AX,65 ; network access denied?
410 JZ NoMove ; Yes, return it.
411 MOV AX,BX
412 MOV DX,CX
413
414 NoMove:
415 RestoreReg <DS,ES,BP,DI,SI,CX,BX>
416 popf
417 return
418
419 EndProc TriageError
420
421 PUBLIC Triage_Init
422 Triage_Init proc FAR
423 call TriageError
424 ret
425 Triage_Init endp
426
427
428 ; ****************************************************************
429 ; *
430 ; * ROUTINE: MOVE_TO_SRCBUF
431 ; *
432 ; * FUNCTION: Move ASCIIZ string from DS:SI to SRCBUF. Change
433 ; * terminating 0 to 0dH. Set PATHCNT to length of
434 ; * string. Set PATHPOS to start of SRCBUF.
435 ; *
436 ; * INPUT: DS:SI points to ASCIIZ string
437 ; * ES points to TRANGROUP
438 ; *
439 ; * OUTPUT: SRCBUF filled in with string terminated by 0dH
440 ; * PATHCNT set to length of string
441 ; * PATHPOS set to start of SRCBUF
442 ; * CX,AX changed
443 ; *
444 ; ****************************************************************
445
446 assume es:trangroup,ds:nothing ;AN000;
447
448 MOVE_TO_SRCBUF PROC NEAR ;AN000;
449
450 push si ;AN000; save si,di
451 push di ;AN000;
452 push cx ;AN000;
453 mov di,offset TRANGROUP:srcbuf ;AN000; set ES:DI to srcbuf
454 xor cx,cx ;AN000; clear cx for counint
455 mov ax,cx ;AN000; clear ax
456 push di ;AN000; save start of srcbuf
457 lodsb ;AN000; get a character from DS:SI
458
459 mts_get_chars: ;AN000;
460 cmp al,0 ;AN000; was it a null char?
461 jz mts_end_string ;AN000; yes - exit
462 stosb ;AN000; no - store it in srcbuf
463 inc cx ;AN000; increment length count
464 lodsb ;AN000; get a character from DS:SI
465 jmp short mts_get_chars ;AN000; go check it
466
467 mts_end_string: ;AN000; we've reached the end of line
468 mov al,end_of_line_in ;AN000; store 0dH in srcbuf
469 stosb ;AN000;
470 pop di ;AN000; restore start of srcbuf
471
472 push cs ;AN000; set DS to local segment
473 pop ds ;AN000;
474 assume ds:trangroup ;AN000;
475 mov [pathcnt],cx ;AN000; set patchcnt to length count
476 mov [pathpos],di ;AN000; set pathpos to start of srcbuf
477 pop cx ;AN000; restore cx,di,si
478 pop di ;AN000;
479 pop si ;AN000;
480
481 RET ;AN000; exit
482
483 MOVE_TO_SRCBUF ENDP ;AN000;
484
485 TRANCODE ENDS
486 END
487 \1a