summaryrefslogtreecommitdiff
path: root/v2.0/source/CPARSE.ASM
blob: 967efaaccbe8391d82a2a69dc931283e2742e783 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
TITLE   CPARSE

        INCLUDE COMSW.ASM

.xlist
.xcref
        INCLUDE DOSSYM.ASM
        INCLUDE DEVSYM.ASM
        INCLUDE COMSEG.ASM
.list
.cref

        INCLUDE COMEQU.ASM

DATARES SEGMENT PUBLIC
DATARES ENDS

TRANDATA        SEGMENT PUBLIC
        EXTRN   BADCPMES:BYTE
TRANDATA        ENDS

TRANSPACE       SEGMENT PUBLIC
        EXTRN   CURDRV:BYTE,ELPOS:BYTE,STARTEL:WORD
        EXTRN   SKPDEL:BYTE,SWITCHAR:BYTE,ELCNT:BYTE

TRANSPACE       ENDS

TRANCODE        SEGMENT PUBLIC BYTE

ASSUME  CS:TRANGROUP,DS:TRANGROUP,ES:TRANGROUP

        EXTRN   DELIM:NEAR,UPCONV:NEAR,PATHCHRCMP:NEAR
        EXTRN   SWLIST:BYTE,BADCDERR:NEAR,SCANOFF:NEAR,CERROR:NEAR

        if  KANJI
        EXTRN   TESTKANJ:NEAR
        endif

SWCOUNT EQU 5

        PUBLIC  CPARSE

CPARSE:

;-----------------------------------------------------------------------;
; ENTRY:                                                                ;
;       DS:SI   Points input buffer                                     ;
;       ES:DI   Points to the token buffer                              ;
;       BL      Special delimiter for this call                         ;
;                   Always checked last                                 ;
;                   set it to space if there is no special delimiter    ;
; EXIT:                                                                 ;
;       DS:SI   Points to next char in the input buffer                 ;
;       ES:DI   Points to the token buffer                              ;
;       [STARTEL] Points to start of last element of path in token      ;
;               points to a NUL for no element strings 'd:' 'd:/'       ;
;       CX      Character count                                         ;
;       BH      Condition Code                                          ;
;                       Bit 1H of BH set if switch character            ;
;                               Token buffer contains char after        ;
;                               switch character                        ;
;                               BP has switch bits set (ORing only)     ;
;                       Bit 2H of BH set if ? or * in token             ;
;                               if * found element ? filled             ;
;                       Bit 4H of BH set if path sep in token           ;
;                       Bit 80H of BH set if the special delimiter      ;
;                          was skipped at the start of this token       ;
;               Token buffer always starts d: for non switch tokens     ;
;       CARRY SET                                                       ;
;           if CR on input                                              ;
;               token buffer not altered                                ;
;                                                                       ;
;       DOES NOT RETURN ON BAD PATH ERROR                               ;
; MODIFIES:                                                             ;
;       CX, SI, AX, BH, DX and the Carry Flag                           ;       ;
;                                                                       ;
; -----------------------------------------------------------------------;

        xor     ax,ax
        mov     [STARTEL],DI            ; No path element (Is DI correct?)
        mov     [ELPOS],al              ; Start in 8 char prefix
        mov     [SKPDEL],al             ; No skip delimiter yet
        mov     bh,al                   ; Init nothing
        pushf                           ; save flags
        push    di                      ; save the token buffer addrss
        xor     cx,cx                   ; no chars in token buffer
moredelim:
        LODSB
        CALL    DELIM
        JNZ     SCANCDONE
        CMP     AL,' '
        JZ      moredelim
        CMP     AL,9
        JZ      moredelim
        xchg    al,[SKPDEL]
        or      al,al
        jz      moredelim               ; One non space/tab delimiter allowed
        JMP     x_done                  ; Nul argument

SCANCDONE:

        IF      NOT KANJI
        call    UPCONV
        ENDIF

        cmp     al,bl                   ; Special delimiter?
        jnz     nospec
        or      bh,80H
        jmp     short moredelim

nospec:
        cmp     al,0DH                  ; a CR?
        jne     ncperror
        jmp     cperror
ncperror:
        cmp     al,[SWITCHAR]           ; is the char the switch char?
        jne     na_switch               ; yes, process...
        jmp     a_switch
na_switch:
        cmp     byte ptr [si],':'
        jne     anum_chard              ; Drive not specified

        IF      KANJI
        call    UPCONV
        ENDIF

        call    move_char
        lodsb                           ; Get the ':'
        call    move_char
        mov     [STARTEL],di
        mov     [ELCNT],0
        jmp     anum_test

anum_chard:
        mov     [STARTEL],di
        mov     [ELCNT],0               ; Store of this char sets it to one
        call    PATHCHRCMP              ; Starts with a pathchar?
        jnz     anum_char               ; no
        push    ax
        mov     al,[CURDRV]             ; Insert drive spec
        add     al,'A'
        call    move_char
        mov     al,':'
        call    move_char
        pop     ax
        mov     [STARTEL],di
        mov     [ELCNT],0

anum_char:

        IF      KANJI
        call    TESTKANJ
        jz      TESTDOT
        call    move_char
        lodsb
        jmp     short notspecial

TESTDOT:
        ENDIF

        cmp     al,'.'
        jnz     testquest
        inc     [ELPOS]                 ; flag in extension
        mov     [ELCNT],0FFH            ; Store of the '.' resets it to 0
testquest:
        cmp     al,'?'
        jnz     testsplat
        or      bh,2
testsplat:
        cmp     al,'*'
        jnz     testpath
        or      bh,2
        mov     ah,7
        cmp     [ELPOS],0
        jz      gotelcnt
        mov     ah,2
gotelcnt:
        mov     al,'?'
        sub     ah,[ELCNT]
        jc      badperr2
        xchg    ah,cl
        jcxz    testpathx
qmove:
        xchg    ah,cl
        call    move_char
        xchg    ah,cl
        loop    qmove
testpathx:
        xchg    ah,cl
testpath:
        call    PATHCHRCMP
        jnz     notspecial
        or      bh,4
        test    bh,2                    ; If just hit a '/', cannot have ? or * yet
        jnz     badperr
        mov     [STARTEL],di            ; New element
        INC     [STARTEL]               ; Point to char after /
        mov     [ELCNT],0FFH            ; Store of '/' sets it to 0
        mov     [ELPOS],0
notspecial:
        call    move_char               ; just an alphanum string
anum_test:
        lodsb

        IF      NOT KANJI
        call    UPCONV
        ENDIF

        call    DELIM
        je      x_done
        cmp     al,0DH
        je      x_done
        cmp     al,[SWITCHAR]
        je      x_done
        cmp     al,bl
        je      x_done
        cmp     al,':'                  ; ':' allowed as trailer because
                                        ; of devices
        IF      KANJI
        je      FOO15
        jmp     anum_char
FOO15:
        ELSE
        jne     anum_char
        ENDIF

        mov     byte ptr [si-1],' '     ; Change the trailing ':' to a space
        jmp     short x_done

badperr2:
        mov     dx,offset trangroup:BADCPMES
        jmp     CERROR

badperr:
        jmp     BADCDERR

cperror:
        dec     si                      ; adjust the pointer
        pop     di                      ; retrive token buffer address
        popf                            ; restore flags
        stc                             ; set the carry bit
        return

x_done:
        dec     si                      ; adjust for next round
        jmp     short out_token

a_switch:
        OR      BH,1                    ; Indicate switch
        OR      BP,GOTSWITCH
        CALL    SCANOFF
        INC     SI
        cmp     al,0DH
        je      cperror
        call    move_char               ; store the character
        CALL    UPCONV
        PUSH    ES
        PUSH    DI
        PUSH    CX
        PUSH    CS
        POP     ES
ASSUME  ES:TRANGROUP
        MOV     DI,OFFSET TRANGROUP:SWLIST
        MOV     CX,SWCOUNT
        REPNE   SCASB
        JNZ     out_tokenp
        MOV     AX,1
        SHL     AX,CL
        OR      BP,AX
out_tokenp:
        POP     CX
        POP     DI
        POP     ES
ASSUME  ES:NOTHING
out_token:
        mov     al,0
        stosb                           ; null at the end
        pop     di                      ; restore token buffer pointer
        popf
        clc                             ; clear carry flag
        return

move_char:
        stosb                           ; store char in token buffer
        inc     cx                      ; increment char count
        inc     [ELCNT]                 ; increment element count for * substi
        return

TRANCODE        ENDS
        END