]> wirehaze git hosting - MS-DOS.git/blob - v2.0/source/CPARSE.ASM

wirehaze git hosting

Merge pull request #91 from abnerescocio/patch-2
[MS-DOS.git] / v2.0 / source / CPARSE.ASM
1 TITLE CPARSE
2
3 INCLUDE COMSW.ASM
4
5 .xlist
6 .xcref
7 INCLUDE DOSSYM.ASM
8 INCLUDE DEVSYM.ASM
9 INCLUDE COMSEG.ASM
10 .list
11 .cref
12
13 INCLUDE COMEQU.ASM
14
15 DATARES SEGMENT PUBLIC
16 DATARES ENDS
17
18 TRANDATA SEGMENT PUBLIC
19 EXTRN BADCPMES:BYTE
20 TRANDATA ENDS
21
22 TRANSPACE SEGMENT PUBLIC
23 EXTRN CURDRV:BYTE,ELPOS:BYTE,STARTEL:WORD
24 EXTRN SKPDEL:BYTE,SWITCHAR:BYTE,ELCNT:BYTE
25
26 TRANSPACE ENDS
27
28 TRANCODE SEGMENT PUBLIC BYTE
29
30 ASSUME CS:TRANGROUP,DS:TRANGROUP,ES:TRANGROUP
31
32 EXTRN DELIM:NEAR,UPCONV:NEAR,PATHCHRCMP:NEAR
33 EXTRN SWLIST:BYTE,BADCDERR:NEAR,SCANOFF:NEAR,CERROR:NEAR
34
35 if KANJI
36 EXTRN TESTKANJ:NEAR
37 endif
38
39 SWCOUNT EQU 5
40
41 PUBLIC CPARSE
42
43 CPARSE:
44
45 ;-----------------------------------------------------------------------;
46 ; ENTRY: ;
47 ; DS:SI Points input buffer ;
48 ; ES:DI Points to the token buffer ;
49 ; BL Special delimiter for this call ;
50 ; Always checked last ;
51 ; set it to space if there is no special delimiter ;
52 ; EXIT: ;
53 ; DS:SI Points to next char in the input buffer ;
54 ; ES:DI Points to the token buffer ;
55 ; [STARTEL] Points to start of last element of path in token ;
56 ; points to a NUL for no element strings 'd:' 'd:/' ;
57 ; CX Character count ;
58 ; BH Condition Code ;
59 ; Bit 1H of BH set if switch character ;
60 ; Token buffer contains char after ;
61 ; switch character ;
62 ; BP has switch bits set (ORing only) ;
63 ; Bit 2H of BH set if ? or * in token ;
64 ; if * found element ? filled ;
65 ; Bit 4H of BH set if path sep in token ;
66 ; Bit 80H of BH set if the special delimiter ;
67 ; was skipped at the start of this token ;
68 ; Token buffer always starts d: for non switch tokens ;
69 ; CARRY SET ;
70 ; if CR on input ;
71 ; token buffer not altered ;
72 ; ;
73 ; DOES NOT RETURN ON BAD PATH ERROR ;
74 ; MODIFIES: ;
75 ; CX, SI, AX, BH, DX and the Carry Flag ; ;
76 ; ;
77 ; -----------------------------------------------------------------------;
78
79 xor ax,ax
80 mov [STARTEL],DI ; No path element (Is DI correct?)
81 mov [ELPOS],al ; Start in 8 char prefix
82 mov [SKPDEL],al ; No skip delimiter yet
83 mov bh,al ; Init nothing
84 pushf ; save flags
85 push di ; save the token buffer addrss
86 xor cx,cx ; no chars in token buffer
87 moredelim:
88 LODSB
89 CALL DELIM
90 JNZ SCANCDONE
91 CMP AL,' '
92 JZ moredelim
93 CMP AL,9
94 JZ moredelim
95 xchg al,[SKPDEL]
96 or al,al
97 jz moredelim ; One non space/tab delimiter allowed
98 JMP x_done ; Nul argument
99
100 SCANCDONE:
101
102 IF NOT KANJI
103 call UPCONV
104 ENDIF
105
106 cmp al,bl ; Special delimiter?
107 jnz nospec
108 or bh,80H
109 jmp short moredelim
110
111 nospec:
112 cmp al,0DH ; a CR?
113 jne ncperror
114 jmp cperror
115 ncperror:
116 cmp al,[SWITCHAR] ; is the char the switch char?
117 jne na_switch ; yes, process...
118 jmp a_switch
119 na_switch:
120 cmp byte ptr [si],':'
121 jne anum_chard ; Drive not specified
122
123 IF KANJI
124 call UPCONV
125 ENDIF
126
127 call move_char
128 lodsb ; Get the ':'
129 call move_char
130 mov [STARTEL],di
131 mov [ELCNT],0
132 jmp anum_test
133
134 anum_chard:
135 mov [STARTEL],di
136 mov [ELCNT],0 ; Store of this char sets it to one
137 call PATHCHRCMP ; Starts with a pathchar?
138 jnz anum_char ; no
139 push ax
140 mov al,[CURDRV] ; Insert drive spec
141 add al,'A'
142 call move_char
143 mov al,':'
144 call move_char
145 pop ax
146 mov [STARTEL],di
147 mov [ELCNT],0
148
149 anum_char:
150
151 IF KANJI
152 call TESTKANJ
153 jz TESTDOT
154 call move_char
155 lodsb
156 jmp short notspecial
157
158 TESTDOT:
159 ENDIF
160
161 cmp al,'.'
162 jnz testquest
163 inc [ELPOS] ; flag in extension
164 mov [ELCNT],0FFH ; Store of the '.' resets it to 0
165 testquest:
166 cmp al,'?'
167 jnz testsplat
168 or bh,2
169 testsplat:
170 cmp al,'*'
171 jnz testpath
172 or bh,2
173 mov ah,7
174 cmp [ELPOS],0
175 jz gotelcnt
176 mov ah,2
177 gotelcnt:
178 mov al,'?'
179 sub ah,[ELCNT]
180 jc badperr2
181 xchg ah,cl
182 jcxz testpathx
183 qmove:
184 xchg ah,cl
185 call move_char
186 xchg ah,cl
187 loop qmove
188 testpathx:
189 xchg ah,cl
190 testpath:
191 call PATHCHRCMP
192 jnz notspecial
193 or bh,4
194 test bh,2 ; If just hit a '/', cannot have ? or * yet
195 jnz badperr
196 mov [STARTEL],di ; New element
197 INC [STARTEL] ; Point to char after /
198 mov [ELCNT],0FFH ; Store of '/' sets it to 0
199 mov [ELPOS],0
200 notspecial:
201 call move_char ; just an alphanum string
202 anum_test:
203 lodsb
204
205 IF NOT KANJI
206 call UPCONV
207 ENDIF
208
209 call DELIM
210 je x_done
211 cmp al,0DH
212 je x_done
213 cmp al,[SWITCHAR]
214 je x_done
215 cmp al,bl
216 je x_done
217 cmp al,':' ; ':' allowed as trailer because
218 ; of devices
219 IF KANJI
220 je FOO15
221 jmp anum_char
222 FOO15:
223 ELSE
224 jne anum_char
225 ENDIF
226
227 mov byte ptr [si-1],' ' ; Change the trailing ':' to a space
228 jmp short x_done
229
230 badperr2:
231 mov dx,offset trangroup:BADCPMES
232 jmp CERROR
233
234 badperr:
235 jmp BADCDERR
236
237 cperror:
238 dec si ; adjust the pointer
239 pop di ; retrive token buffer address
240 popf ; restore flags
241 stc ; set the carry bit
242 return
243
244 x_done:
245 dec si ; adjust for next round
246 jmp short out_token
247
248 a_switch:
249 OR BH,1 ; Indicate switch
250 OR BP,GOTSWITCH
251 CALL SCANOFF
252 INC SI
253 cmp al,0DH
254 je cperror
255 call move_char ; store the character
256 CALL UPCONV
257 PUSH ES
258 PUSH DI
259 PUSH CX
260 PUSH CS
261 POP ES
262 ASSUME ES:TRANGROUP
263 MOV DI,OFFSET TRANGROUP:SWLIST
264 MOV CX,SWCOUNT
265 REPNE SCASB
266 JNZ out_tokenp
267 MOV AX,1
268 SHL AX,CL
269 OR BP,AX
270 out_tokenp:
271 POP CX
272 POP DI
273 POP ES
274 ASSUME ES:NOTHING
275 out_token:
276 mov al,0
277 stosb ; null at the end
278 pop di ; restore token buffer pointer
279 popf
280 clc ; clear carry flag
281 return
282
283 move_char:
284 stosb ; store char in token buffer
285 inc cx ; increment char count
286 inc [ELCNT] ; increment element count for * substi
287 return
288
289 TRANCODE ENDS
290 END
291