]>
wirehaze git hosting - MS-DOS.git/blob - v4.0/src/CMD/COMMAND/CPARSE.ASM
2 ; SCCSID = @(#)cparse.asm 1.1 85/05/14
3 ; SCCSID = @(#)cparse.asm 1.1 85/05/14
16 TRANDATA
SEGMENT PUBLIC BYTE ;AC000;
17 EXTRN BADCD_PTR
:WORD ;AC022;
18 EXTRN BADCPMES_ptr
:word ;AC000;
21 TRANSPACE
SEGMENT PUBLIC BYTE ;AC000;
27 EXTRN EXPAND_STAR
:BYTE
31 EXTRN switch_list
:byte
35 TRANCODE
SEGMENT PUBLIC BYTE
37 ASSUME
CS:TRANGROUP
,DS:TRANGROUP
,ES:TRANGROUP
,SS:NOTHING
41 PUBLIC BADCDERR
;AC022;
44 SWCOUNT EQU
5 ; Must agree with length of switch_list
46 ;-----------------------------------------------------------------------;
48 ; DS:SI Points input buffer ;
49 ; ES:DI Points to the token buffer ;
50 ; BL Special delimiter for this call ;
51 ; Always checked last ;
52 ; set it to space if there is no special delimiter ;
54 ; DS:SI Points to next char in the input buffer ;
55 ; ES:DI Points to the token buffer ;
56 ; [STARTEL] Points to start of last element of path in token ;
57 ; points to a NUL for no element strings 'd:' 'd:/' ;
58 ; CX Character count ;
60 ; Bit 1H of BH set if switch character ;
61 ; Token buffer contains char after ;
63 ; BP has switch bits set (ORing only) ;
64 ; Bit 2H of BH set if ? or * in token ;
65 ; if * found element ? filled ;
66 ; Bit 4H of BH set if path sep in token ;
67 ; Bit 80H of BH set if the special delimiter ;
68 ; was skipped at the start of this token ;
69 ; Token buffer always starts d: for non switch tokens ;
72 ; token buffer not altered ;
74 ; DOES NOT RETURN ON BAD PATH, OR TRAILING SWITCH CHAR ERROR ;
76 ; CX, SI, AX, BH, DX and the Carry Flag ; ;
78 ; -----------------------------------------------------------------------;
80 ; Modifications to cparse: recognition of right and left parentheses
81 ; as integral tokens, and removal of automatic upper-case conversion code.
83 ; Both modifications were installed in the course of adding a coherent
84 ; command-line parser to COMMAND.COM which builds a UNIX-style argv[]/argc
85 ; structure for command-line arguments. This parser relies on cparse to
86 ; recognize individual tokens.
88 ; To process for-loops correctly, parentheses must therefore be
89 ; recognized as tokens. The upper-case conversion code was removed so
90 ; that commands (such as for and echo) would be able to use the "original"
91 ; text of the command line.
93 ; Note also the modification to prevent the automatic conversion of colons
94 ; into spaces WITHIN THE SOURCE TEXT!
96 ; Also note that BP is also clobbered if cparse recognizes any switches
97 ; on the command line.
99 ; Alan L, OS/MSDOS 14 August 1983
103 ASSUME
DS:TRANGROUP
,ES:TRANGROUP
106 mov [STARTEL
],DI ; No path element (Is DI correct?)
107 mov [ELPOS
],al ; Start in 8 char prefix
108 mov [SKPDEL
],al ; No skip delimiter yet
109 mov bh,al ; Init nothing
111 push di ; save the token buffer addrss
112 xor cx,cx ; no chars in token buffer
113 mov comma
,cl ;g reset comma flag
124 jz moredelim
; One non space/tab delimiter allowed
125 test bh,080h ;g has a special char been found?
126 jz no_comma
;g no - just exit
127 mov comma
,1 ;g set comma flag
129 JMP x_done
; Nul argument
133 ;;;; IF NOT KANJI 3/3/KK
135 ; Mod to avoid upper-case conversion.
136 ; cmp cpyflag,1 3/3/KK
138 ; invoke UPCONV 3/3/KK
143 cmp al,bl ; Special delimiter?
154 cmp al,[SWITCHAR
] ; is the char the switch char?
155 jne na_switch
; yes, process...
161 jne anum_chard
; Drive not specified
165 ; Mod to avoid upper-case conversion.
182 mov [ELCNT
],0 ; Store of this char sets it to one
183 cmp cpyflag
,1 ; Was CPARSE called from COPY?
184 jnz anum_char
; No, don't add drive spec.
185 invoke PATHCHRCMP
; Starts with a pathchar?
188 mov al,[CURDRV
] ; Insert drive spec
206 NOTKANJ: ;AN048; If not kanji
207 cmp cpyflag
,1 ;AN048; and if we're in COPY
209 invoke upconv
;AN048; upper case the char
216 inc [ELPOS
] ; flag in extension
217 mov [ELCNT
],0FFH ; Store of the '.' resets it to 0
228 cmp byte ptr [expand_star
],0
261 cmp byte ptr [expand_star
],0
263 test bh,2 ; If just hit a '/', cannot have ? or * yet
267 mov [STARTEL
],di ; New element
268 INC [STARTEL
] ; Point to char after /
269 mov [ELCNT
],0FFH ; Store of '/' sets it to 0
273 call move_char
; just an alphanum string
278 ;;;; IF NOT KANJI 3/3/KK
280 ; Mod to avoid upper-case conversion.
281 ; cmp cpyflag,1 3/3/KK
283 ; invoke UPCONV 3/3/KK
297 cmp al,':' ; ':' allowed as trailer because
304 ;;; jne anum_charj 3/3/KK
308 ; Modification made for parseline.
309 ; Why would it be necessary to change colons to spaces? In this
310 ; case, EVERY colon is changed to a space; e.g., 'f:' yields 'f ',
311 ; but so does 'echo foo:bar' yield 'echo foo bar'.
313 cmp cpyflag
,2 ; Is CPARSE parsing the 1st token from
315 jnz cpcont4
; No, continue
316 call move_char
; Yes, save the ':' and go get another
317 jmp anum_test
; character.
327 mov dx,offset trangroup
:BADCPMES_ptr
331 BADCDERR: ;AC022; Issue "Invalid Directory"
332 MOV DX,OFFSET TRANGROUP
:BADCD_ptr
;AC022; message
336 dec si ; adjust the pointer
337 pop di ; retrive token buffer address
339 stc ; set the carry bit
343 dec si ; adjust for next round
345 ; Mod to recognize right and left parens as integral tokens.
351 OR BH,1 ; Indicate switch
355 invoke testkanj
;AN057; See if DBCS lead byte
356 jz a_switch_notkanj
;AN057; no - continue processing
357 call move_char
;AN057; DBCS - store first byte
358 lodsb ;AN057; get second byte
359 call move_char
;AN057; store second byte
360 or bp,fBadSwitch
;AN057; DBCS switch is invalid
361 jmp short out_token
;AN057; don't bother checking switch
362 a_switch_notkanj: ;AN057;
366 stosb ; null at the end
368 jmp cperror
; Trailing switch character error
369 ; BP = fSwitch but no switch
370 ; bit is set (unknown switch)
372 call move_char
; store the character
375 ; This upconv call must stay. It is used to identify copy-switches
376 ; on the command line, and won't store anything into the output buffer.
386 MOV DI,OFFSET TRANGROUP
:switch_list
391 AND BP,NOT fBadSwitch
404 stosb ; null at the end
405 pop di ; restore token buffer pointer
407 clc ; clear carry flag
411 stosb ; store char in token buffer
412 inc cx ; increment char count
413 inc [ELCNT
] ; increment element count for * substi