summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/COMMAND/TMISC1.ASM
diff options
context:
space:
mode:
authorGravatar Mark Zbikowski2024-04-25 21:24:10 +0100
committerGravatar Microsoft Open Source2024-04-25 22:32:27 +0000
commit2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch)
tree80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/CMD/COMMAND/TMISC1.ASM
parentMerge pull request #430 from jpbaltazar/typoptbr (diff)
downloadms-dos-main.tar.gz
ms-dos-main.tar.xz
ms-dos-main.zip
MZ is back!HEADmain
Diffstat (limited to 'v4.0/src/CMD/COMMAND/TMISC1.ASM')
-rw-r--r--v4.0/src/CMD/COMMAND/TMISC1.ASM655
1 files changed, 655 insertions, 0 deletions
diff --git a/v4.0/src/CMD/COMMAND/TMISC1.ASM b/v4.0/src/CMD/COMMAND/TMISC1.ASM
new file mode 100644
index 0000000..4b55aac
--- /dev/null
+++ b/v4.0/src/CMD/COMMAND/TMISC1.ASM
@@ -0,0 +1,655 @@
1 page 80,132
2; SCCSID = @(#)tmisc1.asm 4.1 85/09/22
3; SCCSID = @(#)tmisc1.asm 4.1 85/09/22
4TITLE Part7 COMMAND Transient Routines
5
6; More misc routines
7
8.xlist
9.xcref
10 INCLUDE comsw.asm
11 INCLUDE DOSSYM.INC
12 INCLUDE comseg.asm
13 INCLUDE comequ.asm
14.list
15.cref
16
17
18
19CODERES SEGMENT PUBLIC BYTE ;AC000;
20 EXTRN RSTACK:BYTE
21CodeRes ENDS
22
23DATARES SEGMENT PUBLIC BYTE ;AC000;
24 EXTRN CALL_FLAG:BYTE
25 EXTRN EchoFlag:BYTE
26 EXTRN EXEC_BLOCK:BYTE
27 EXTRN EXTCOM:BYTE
28 EXTRN PIPEFLAG:BYTE
29 EXTRN PIPEPTR:WORD
30 EXTRN PIPESTR:BYTE
31 EXTRN RESTDIR:BYTE
32 EXTRN RE_OUT_APP:BYTE
33 EXTRN RE_OUTSTR:BYTE
34DATARES ENDS
35
36TRANDATA SEGMENT PUBLIC BYTE ;AC000;
37 EXTRN BADDRV_PTR:WORD
38 EXTRN BADNAM_PTR:WORD
39 EXTRN COMTAB:BYTE ;AC000;
40 EXTRN extend_buf_ptr:word ;AN000;
41 EXTRN msg_disp_class:byte ;AN000;
42TRANDATA ENDS
43
44TRANSPACE SEGMENT PUBLIC BYTE ;AC000;
45 EXTRN arg:byte ; the arg structure!
46 EXTRN APPEND_EXEC:BYTE ;AN041;
47 EXTRN CHKDRV:BYTE
48 EXTRN COMBUF:BYTE
49 EXTRN EXECPATH:BYTE
50 EXTRN EXEC_ADDR:DWORD
51 EXTRN FILTYP:BYTE
52 EXTRN IDLEN:BYTE
53 EXTRN KPARSE:BYTE ;AC000;
54 EXTRN PARM1:BYTE
55 EXTRN PARM2:BYTE
56 EXTRN PathPos:word
57 EXTRN RESSEG:WORD
58 EXTRN RE_INSTR:BYTE
59 EXTRN SPECDRV:BYTE
60 EXTRN SWITCHAR:BYTE
61 EXTRN switch_list:byte
62 EXTRN TRAN_TPA:WORD
63
64 IF IBM
65 EXTRN ROM_CALL:BYTE
66 EXTRN ROM_CS:WORD
67 EXTRN ROM_IP:WORD
68 ENDIF
69
70TRANSPACE ENDS
71
72TRANCODE SEGMENT PUBLIC byte
73
74ASSUME CS:TRANGROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING
75
76 EXTRN APPEND_PARSE:NEAR ;AN010;
77 EXTRN BATCOM:NEAR
78 EXTRN DOCOM1:NEAR
79 EXTRN PIPEERRSYN:NEAR
80 EXTRN TCOMMAND:NEAR
81
82 IF IBM
83 EXTRN ROM_EXEC:NEAR
84 EXTRN ROM_SCAN:NEAR
85 ENDIF
86
87 PUBLIC CERROR
88 PUBLIC DRVBAD
89 PUBLIC EXTERNAL
90 PUBLIC FNDCOM
91 PUBLIC PRESCAN
92 PUBLIC SWITCH
93
94
95ASSUME DS:TRANGROUP
96
97;---------------------------
98; We can get rid of this switch processing code if we can take
99; care of the remaining two calls to switch, later in the file.
100; However, I have not checked whether or not any other files use
101; switch -- after all, it IS public!
102;---------------------------
103RETSW:
104 XCHG AX,BX ; Put switches in AX
105 return
106
107SWITCH:
108 XOR BX,BX ; Initialize - no switches set
109SWLOOP:
110 INVOKE SCANOFF ; Skip any delimiters
111 CMP AL,[SWITCHAR] ; Is it a switch specifier?
112 JNZ RETSW ; No -- we're finished
113 OR BX,fSwitch ; Indicate there is a switch specified
114 INC SI ; Skip over the switch character
115 INVOKE SCANOFF
116 CMP AL,0DH
117 JZ RETSW ; Oops
118 INC SI
119; Convert lower case input to upper case
120 INVOKE UPCONV
121 MOV DI,OFFSET TRANGROUP:switch_list
122 MOV CX,SWCOUNT
123 REPNE SCASB ; Look for matching switch
124 JNZ BADSW
125 MOV AX,1
126 SHL AX,CL ; Set a bit for the switch
127 OR BX,AX
128 JMP SHORT SWLOOP
129
130BADSW:
131 JMP SHORT SWLOOP
132
133SWCOUNT EQU 5 ; Length of switch_list
134
135DRVBAD:
136 MOV DX,OFFSET TRANGROUP:BADDRV_ptr
137 JMP CERROR
138
139externalj:
140 jmp EXTERNAL
141
142fndcom: ; search the internal command table
143 OR AL,AL ; Get real length of first arg
144 jz externalj ; If 0, it must begin with "\" so has
145 ; to be external.
146; barryf code starts here
147
148 IF IBM
149 call test_append ; see if APPEND installed
150 je contcom ; not loaded
151
152append_internal:
153 mov cl,TRANGROUP:IDLEN
154 mov ch,0
155 mov pathpos,cx
156 inc append_exec ;AN041; set APPEND to ON
157
158 invoke ioset ; re-direct the o'l io
159
160 mov SI, offset TRANGROUP:IDLEN ; address command name, DS already set
161 mov DX,-1 ; set invoke function
162 mov di,offset TRANGROUP:APPEND_PARSE;AN010; Get the entry point for PARSE for APPEND
163 mov AX,0AE01H
164 int 2FH ; execute command
165 cmp TRANGROUP:IDLEN,0 ; execute requested
166 jne contcom
167 jmp Cmd_done
168
169contcom: ; continue with internal scan
170 ENDIF
171
172; barryf code ends here
173
174 mov DI, OFFSET TRANGROUP:COMTAB
175 XOR CX,CX
176
177findcom:
178 mov SI, offset TRANGROUP:IDLEN+1 ; pointer to command argument
179 mov CL, [DI] ; load length of internal command
180 inc di ; advance past length
181 jcxz externalj ; if it's zero, we're out of internals
182 cmp CL, IDLEN ; that of the command argument
183 jnz abcd ; lengths not equal ==> strings not eq
184 MOV PathPos,CX ; store length of command
185 repz cmpsb
186
187abcd:
188 lahf ; save the good ol' flags
189 add DI, CX ; skip over remaining internal, if any
190 mov AL, BYTE PTR [DI] ; load drive-check indicator byte (DCIB)
191 mov [CHKDRV], AL ; save command flag byte in chkdrv
192 inc DI ; increment DI (OK, OK, I'll stop)
193 mov BX, WORD PTR [DI] ; load internal command address
194 inc DI ; skip over the puppy
195 inc DI
196 sahf ; remember those flags?
197 jnz findcom ; well, if all the cmps worked...
198;
199; All messages get redirected.
200;
201 cmp append_exec,0 ;AN041; APPEND just executed?
202 jnz dont_set_io ;AN041; Yes - this junk is already set
203 invoke ioset ; re-direct the ol' i/o
204
205dont_set_io: ;AN041;
206 invoke SETSTDINON ;AN026; turn on critical error on STDIN
207 invoke SETSTDOUTOFF ;AN026; turn off critical error on STDOUT
208 test [CHKDRV], fCheckDrive ; did we wanna check those drives?
209 jz nocheck
210 mov AL, [PARM1] ; parse_file_descriptor results tell
211 or AL, [PARM2] ; us whether those drives were OK
212 cmp AL, -1
213 jnz nocheck
214 jmp drvbad
215
216
217;
218; The user may have omitted the space between the command and its arguments.
219; We need to copy the remainder of the user's command line into the buffer.
220; Note that thisdoes not screw up the arg structure; it points into COMBUF not
221; into the command line at 80.
222;
223nocheck:
224 call cmd_copy
225
226switcheck:
227 test [CHKDRV], fSwitchAllowed ; Does the command take switches
228 jnz realwork ; Yes, process the command
229 call noswit ; No, check to see if any switches
230 jnz realwork ; None, process the command
231 mov msg_disp_class,parse_msg_class ;AN000; set up parse error msg class
232 MOV DX,OFFSET TranGroup:Extend_Buf_ptr ;AC000; get extended message pointer
233 mov Extend_Buf_ptr,BadSwt_ptr ;AN000; get "Invalid switch" message number
234 jmp CERROR ; Print error and chill out...
235realwork:
236 call BX ; do some real work, at last
237
238; See if we're in a batch CALL command. If we are, reprocess the command line,
239; otherwise, go get another command.
240
241Cmd_done:
242 push cs ; g restore data segment
243 pop ds ; g
244 push ds ; g save data segment
245 mov ds,[resseg] ; g get segment containing call flag
246 ASSUME ds:resgroup
247 cmp call_flag, call_in_progress ; G Is a call in progress?
248 mov call_flag, 0 ; G Either way, reset flag
249 pop ds ; g get data segment back
250 jz incall ; G
251 jmp tcommand ; chill out...
252
253incall:
254 JMP DOCOM1
255
256noswit:
257 push di ; Save di
258 mov di,81h ; di = ptr to command args
259 mov si,80h ; Get address of length of command args
260 lodsb ; Load length
261 mov cl,al ; Move length to cl
262 xor ch,ch ; Zero ch
263 mov al,[SWITCHAR] ; al = switch character
264 cmp al,0 ; Turn off ZF
265 repnz scasb ; Scan for a switch character and return
266 pop di ; with ZF set if one was found
267 ret
268
269EXTERNAL:
270
271IF IBM
272 call test_append ; check to see if append installed
273 je not_barryf ; no - truly external command
274 jmp append_internal ; yes - go to Barryf code
275
276not_barryf:
277
278ENDIF
279
280 MOV [FILTYP],0
281 MOV DL,[SPECDRV]
282 MOV [IDLEN],DL
283IF IBM
284 MOV [ROM_CALL],0
285 PUSH DX
286 MOV DX,OFFSET TRANGROUP:IDLEN
287 CALL ROM_SCAN
288 POP DX
289 JNC DO_SCAN
290 INC [ROM_CALL]
291 JMP PostSave
292DO_SCAN:
293ENDIF
294IF IBM
295PostSave:
296ENDIF
297 MOV DI,OFFSET TRANGROUP:EXECPATH
298 MOV BYTE PTR [DI],0 ; Initialize to current directory
299IF IBM
300 CMP [ROM_CALL],0
301 JZ Research
302 JMP NeoExecute
303ENDIF
304RESEARCH:
305 invoke path_search ; find the mother (result in execpath)
306 or AX, AX ; did we find anything?
307 je badcomj45 ; null means no (sob)
308 cmp AX, 04H ; 04H and 08H are .exe and .com
309 jl rsrch_br1 ; fuckin' sixteen-bit machine ought
310 jmp execute ; to be able to handle a SIXTEEN-BIT
311rsrch_br1: ; DISPLACEMENT!!
312 jmp batcom ; 02H is .bat
313BADCOMJ45:
314 JMP BADCOM
315
316ASSUME DS:TRANGROUP,ES:TRANGROUP
317
318EXECUTE:
319NeoExecute:
320 invoke IOSET
321 invoke SETSTDINOFF ;AN026; turn off critical error on STDIN
322 invoke SETSTDOUTOFF ;AN026; turn off critical error on STDOUT
323 MOV ES,[TRAN_TPA]
324 MOV AH,DEALLOC
325 INT int_command ; Now running in "free" space
326 MOV ES,[RESSEG]
327ASSUME ES:RESGROUP
328 INC [EXTCOM] ; Indicate external command
329 MOV [RESTDIR],0 ; Since USERDIR1 is in transient, insure
330 ; this flag value for re-entry to COMMAND
331 MOV DI,FCB
332 MOV SI,DI
333 MOV CX,052H ; moving (100h-5Ch)/2 = 80h-2Eh
334 REP MOVSW ; Transfer parameters to resident header
335 MOV DX,OFFSET TRANGROUP:EXECPATH
336 MOV BX,OFFSET RESGROUP:EXEC_BLOCK
337 MOV AX,EXEC SHL 8
338IF IBM
339 TEST [ROM_CALL],-1
340 JZ OK_EXEC
341 JMP ROM_EXEC
342OK_EXEC:
343ENDIF
344;
345; we are now running in free space. anything we do from here on may get
346; trashed. Move the stack (also in free space) to allocated space because
347; since EXEC restores the stack, somebody may trash what is on the stack.
348;
349 MOV CX,ES
350 MOV SS,CX
351 MOV SP,OFFSET RESGROUP:RSTACK
352 JMP [EXEC_ADDR] ; Jmp to the EXEC in the resident
353
354BADCOM:
355 PUSH CS
356 POP DS
357 MOV DX,OFFSET TRANGROUP:BADNAM_ptr
358
359CERROR:
360 INVOKE std_eprintf
361 JMP TCOMMAND
362
363;
364; Prescan converts the input buffer into a canonicalized form. All
365; redirections and pipes are removed.
366;
367PRESCAN: ; Cook the input buffer
368
369ASSUME DS:TRANGROUP,ES:TRANGROUP
370
371 XOR CX,CX
372 MOV ES,[RESSEG]
373ASSUME ES:RESGROUP
374 MOV SI,OFFSET TRANGROUP:COMBUF+2
375 MOV DI,SI
376
377CountQuotes:
378 LODSB ; get a byte
379 CMP AL,22h ; is it a quote?
380 JNZ CountEnd ; no, try for end of road
381 INC CH ; bump count
382 JMP CountQuotes ; go get next char
383
384CountEnd:
385 CMP AL,13 ; end of road?
386 JNZ CountQuotes ; no, go back for next char
387
388;;;; IF KANJI 3/3/KK
389 PUSH CX ; save count
390 MOV SI,DI ; get back beginning of buffer
391
392KanjiScan:
393 LODSB ; get a byte
394 INVOKE TestKanj ; is it a leadin byte
395 JZ KanjiQuote ; no, check for quotes
396 MOV AH,AL ; save leadin
397 LODSB ; get trailing byte
398 CMP AX,8140h ; is it Kanji space
399 JNZ KanjiScan ; no, go get next
400 MOV [SI-2],2020h ; replace with spaces
401 JMP KanjiScan ; go get next char
402
403KanjiQuote:
404 CMP AL,22h ; beginning of quoted string
405 JNZ KanjiEnd ; no, check for end
406 DEC CH ; drop count
407 JZ KanjiScan ; if count is zero, no quoting
408
409KanjiQuoteLoop:
410 LODSB ; get next byte
411 CMP AL,22h ; is it another quote
412 JNZ KanjiQuoteLoop ; no, get another
413 DEC CH ; yes, drop count
414 JMP KanjiScan ; go get next char
415
416KanjiEnd:
417 CMP AL,13 ; end of line character?
418 JNZ KanjiScan ; go back to beginning
419 POP CX ; get back original count
420;;;; ENDIF 3/3/KK
421
422 MOV SI,DI ; restore pointer to begining
423
424PRESCANLP:
425 LODSB
426
427;;;; IF KANJI 3/3/KK
428 INVOKE TESTKANJ
429 JZ NOTKANJ6
430 MOV [DI],AL
431 INC DI ; fake STOSB into DS
432 LODSB ; grab second byte
433 MOV [DI],AL ; fake stosb into DS
434 INC DI
435 INC CL
436 INC CL
437 JMP PRESCANLP
438
439NOTKANJ6:
440;;;; ENDIF 3/3/KK
441
442 CMP AL,'"' ; " character
443 JNZ TRYGREATER
444 DEC CH
445 JZ TRYGREATER
446
447QLOOP:
448 MOV [DI],AL
449 INC DI
450 INC CL
451 LODSB
452 CMP AL,'"' ; " character
453 JNZ QLOOP
454 DEC CH
455
456TRYGREATER:
457 CMP AL,rabracket
458 JNZ NOOUT
459;
460; We have found a ">" char. We need to see if there is another ">"
461; following it.
462;
463 CMP BYTE PTR [SI],al
464 JNZ NOAPPND
465 LODSB
466 INC [RE_OUT_APP] ; Flag >>
467
468NOAPPND:
469;
470; Now we attempt to find the file name. First, scan off all whitespace
471;
472 INVOKE SCANOFF
473 CMP AL,labracket ;AN040; was there no filename?
474 JZ REOUT_ERRSET ;AN040; yes - set up error
475 CMP AL,0DH
476 JNZ GOTREOFIL
477;
478; There was no file present. Set us up at end-of-line.
479;
480REOUT_ERRSET: ;AN040; set up for an error
481 mov byte ptr [di], 0dh ; Clobber first ">"
482 MOV WORD PTR [RE_OUTSTR],09H ; Cause an error later
483 JMP PRESCANEND
484
485GOTREOFIL:
486 PUSH DI
487 MOV DI,OFFSET RESGROUP:RE_OUTSTR
488 MOV BX,DI
489 PUSH ES
490
491SETREOUTSTR: ; Get the output redirection name
492 LODSB
493 CMP AL,0DH
494 JZ GOTRESTR
495 INVOKE DELIM
496 JZ GOTRESTR
497 CMP AL,[SWITCHAR]
498 JZ GOTRESTR
499 CMP AL,'"' ;AN033; Is the character a quote?
500 JZ PIPEERRSYNJ5 ;AN033; Yes - get out quick - or system crashes
501 CMP AL,labracket ;AN002; Is char for input redirection
502 JZ ABRACKET_TERM ;AN002; yes - end of string
503 CMP AL,rabracket ;AN002; Is char for output redirection
504 JNZ NO_ABRACKET ;AN002; no - not end of string
505
506abracket_term: ;AN002; have end of string by < or >
507 DEC SI ;AN002; back up over symbol
508 MOV AL,BLANK ;AN002; show delimiter as char
509 JMP SHORT GOTRESTR ;AN002; go process it
510
511no_abracket: ;AN002; not at end of string
512 STOSB ; store it into resgroup
513 JMP SHORT SETREOUTSTR
514
515NOOUT:
516 CMP AL,labracket
517 JNZ CHKPIPE
518 mov bx,si ; Save loc of "<"
519 INVOKE SCANOFF
520 CMP AL,rabracket ;AN040; was there no filename?
521 JZ REIN_ERRSET ;AN040; yes - set up error
522 CMP AL,0DH
523 JNZ GOTREIFIL
524
525REIN_ERRSET: ;AN040; set up for error
526 mov byte ptr [di],0dh ; Clobber "<"
527 MOV WORD PTR [RE_INSTR],09H ; Cause an error later
528 JMP SHORT PRESCANEND
529
530GOTREIFIL:
531 PUSH DI
532 MOV DI,OFFSET TranGROUP:RE_INSTR
533 MOV BX,DI
534 PUSH ES
535 PUSH CS
536 POP ES ; store in TRANGROUP
537 JMP SHORT SETREOUTSTR ; Get the input redirection name
538
539CHKPIPE:
540 MOV AH,AL
541 CMP AH,AltPipeChr
542 JZ IsPipe3
543 CMP AH,vbar
544 JNZ CONTPRESCAN
545
546IsPipe3:
547;
548; Only push the echo flag if we are entering the pipe for the first time.
549;
550 CMP PipeFlag,0
551 JNZ NoEchoPush
552 SHL EchoFlag,1 ; push echo state and turn it off
553NoEchoPush:
554 INC [PIPEFLAG]
555 INVOKE SCANOFF
556 CMP AL,0DH
557 JZ PIPEERRSYNJ5
558 CMP AL,AltPipeChr
559 JZ PIPEERRSYNJ5
560 CMP AL,vbar ; Double '|'?
561 JNZ CONTPRESCAN
562
563PIPEERRSYNJ5:
564 PUSH ES
565 POP DS ; DS->RESGROUP
566 JMP PIPEERRSYN
567
568;
569; Trailing :s are allowed on devices. Check to be sure that there is more
570; than just a : in the redir string.
571;
572GOTRESTR:
573 XCHG AH,AL
574 mov al,':'
575 SUB BX,DI ; compute negatinve of number of chars
576 CMP BX,-1 ; is there just a :?
577 JZ NotTrailCol ; yep, don't change
578 CMP BYTE PTR ES:[DI-1],al ; Trailing ':' OK on devices
579 JNZ NOTTRAILCOL
580 DEC DI ; Back up over trailing ':'
581
582NOTTRAILCOL:
583 XOR AL,AL
584 STOSB ; NUL terminate the string
585 POP ES
586 POP DI ; Remember the start
587
588CONTPRESCAN:
589 MOV [DI],AH ; "delete" the redirection string
590 INC DI
591 CMP AH,0DH
592 JZ PRESCANEND
593 INC CL
594 JMP PRESCANLP
595
596PRESCANEND:
597 CMP [PIPEFLAG],0
598 JZ ISNOPIPE
599 MOV DI,OFFSET RESGROUP:PIPESTR
600 MOV [PIPEPTR],DI
601 MOV SI,OFFSET TRANGROUP:COMBUF+2
602 INVOKE SCANOFF
603
604PIPESETLP: ; Transfer the pipe into the resident
605 LODSB ; pipe buffer
606 STOSB
607 CMP AL,0DH
608 JNZ PIPESETLP
609
610ISNOPIPE:
611 MOV [COMBUF+1],CL
612 CMP [PIPEFLAG],0
613 PUSH CS
614 POP ES
615 return
616
617cmd_copy proc near
618
619 MOV SI,OFFSET TRANGROUP:COMBUF+2
620 INVOKE Scanoff ; advance past separators...
621 add si,PathPos
622 mov di,81h
623 xor cx,cx
624
625CmdCopy:
626 lodsb
627 stosb
628 cmp al,0dh
629 jz CopyDone
630 inc cx
631 jmp CmdCopy
632
633CopyDone:
634 mov byte ptr ds:[80h],cl ; Store count
635
636 ret
637cmd_copy endp
638
639
640test_append proc near
641
642 mov BX,offset TRANGROUP:COMBUF ; barry can address
643 mov SI, offset TRANGROUP:IDLEN ; address command name, DS already set
644 mov DX,-1 ; set install check function
645 mov AX,0AE00H
646 int 2FH ; see if loaded
647 cmp AL,00H
648
649 ret
650
651test_append endp
652
653TRANCODE ENDS
654 END
655 \ No newline at end of file