Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

435 lines
9.9 KiB

  1. page ,132
  2. ;/*
  3. ; * Microsoft Confidential
  4. ; * Copyright (C) Microsoft Corporation 1991
  5. ; * All Rights Reserved.
  6. ; */
  7. ; SCCSID = @(#)cparse.asm 1.1 85/05/14
  8. ; SCCSID = @(#)cparse.asm 1.1 85/05/14
  9. INCLUDE comsw.asm
  10. .xlist
  11. .xcref
  12. INCLUDE DOSSYM.INC
  13. INCLUDE DEVSYM.INC
  14. INCLUDE comseg.asm
  15. INCLUDE comequ.asm
  16. .list
  17. .cref
  18. TRANDATA SEGMENT PUBLIC BYTE ;AC000;
  19. EXTRN BADCD_PTR:WORD ;AC022;
  20. EXTRN BADCPMES_ptr:word ;AC000;
  21. TRANDATA ENDS
  22. TRANSPACE SEGMENT PUBLIC BYTE ;AC000;
  23. EXTRN comma:byte
  24. EXTRN cpyflag:byte
  25. EXTRN CURDRV:BYTE
  26. EXTRN ELCNT:BYTE
  27. EXTRN ELPOS:BYTE
  28. EXTRN EXPAND_STAR:BYTE
  29. EXTRN SKPDEL:BYTE
  30. EXTRN STARTEL:WORD
  31. EXTRN SWITCHAR:BYTE
  32. EXTRN switch_list:byte
  33. EXTRN TPA:WORD
  34. TRANSPACE ENDS
  35. TRANCODE SEGMENT PUBLIC BYTE
  36. ASSUME CS:TRANGROUP,DS:TRANGROUP,ES:TRANGROUP,SS:NOTHING
  37. EXTRN CERROR:NEAR
  38. PUBLIC BADCDERR ;AC022;
  39. PUBLIC CPARSE
  40. SWCOUNT EQU 6 ; Must agree with length of switch_list
  41. ;-----------------------------------------------------------------------;
  42. ; ENTRY: ;
  43. ; DS:SI Points input buffer ;
  44. ; ES:DI Points to the token buffer ;
  45. ; BL Special delimiter for this call ;
  46. ; Always checked last ;
  47. ; set it to space if there is no special delimiter ;
  48. ; EXIT: ;
  49. ; DS:SI Points to next char in the input buffer ;
  50. ; ES:DI Points to the token buffer ;
  51. ; [STARTEL] Points to start of last element of path in token ;
  52. ; points to a NUL for no element strings 'd:' 'd:/' ;
  53. ; CX Character count ;
  54. ; BH Condition Code ;
  55. ; Bit 1H of BH set if switch character ;
  56. ; Token buffer contains char after ;
  57. ; switch character ;
  58. ; BP has switch bits set (ORing only) ;
  59. ; Bit 2H of BH set if ? or * in token ;
  60. ; if * found element ? filled ;
  61. ; Bit 4H of BH set if path sep in token ;
  62. ; Bit 80H of BH set if the special delimiter ;
  63. ; was skipped at the start of this token ;
  64. ; Token buffer always starts d: for non switch tokens ;
  65. ; CARRY SET ;
  66. ; if CR on input ;
  67. ; token buffer not altered ;
  68. ; ;
  69. ; DOES NOT RETURN ON BAD PATH, OR TRAILING SWITCH CHAR ERROR ;
  70. ; MODIFIES: ;
  71. ; CX, SI, AX, BH, DX and the Carry Flag ; ;
  72. ; ;
  73. ; -----------------------------------------------------------------------;
  74. ;---------------
  75. ; Modifications to cparse: recognition of right and left parentheses
  76. ; as integral tokens, and removal of automatic upper-case conversion code.
  77. ;
  78. ; Both modifications were installed in the course of adding a coherent
  79. ; command-line parser to COMMAND.COM which builds a UNIX-style argv[]/argc
  80. ; structure for command-line arguments. This parser relies on cparse to
  81. ; recognize individual tokens.
  82. ;
  83. ; To process for-loops correctly, parentheses must therefore be
  84. ; recognized as tokens. The upper-case conversion code was removed so
  85. ; that commands (such as for and echo) would be able to use the "original"
  86. ; text of the command line.
  87. ;
  88. ; Note also the modification to prevent the automatic conversion of colons
  89. ; into spaces WITHIN THE SOURCE TEXT!
  90. ;
  91. ; Also note that BP is also clobbered if cparse recognizes any switches
  92. ; on the command line.
  93. ;
  94. ; Alan L, OS/MSDOS 14 August 1983
  95. ;---------------
  96. CPARSE:
  97. ASSUME DS:TRANGROUP,ES:TRANGROUP
  98. xor ax,ax
  99. mov [STARTEL],DI ; No path element (Is DI correct?)
  100. mov [ELPOS],al ; Start in 8 char prefix
  101. mov [SKPDEL],al ; No skip delimiter yet
  102. mov bh,al ; Init nothing
  103. pushf ; save flags
  104. push di ; save the token buffer addrss
  105. xor cx,cx ; no chars in token buffer
  106. mov comma,cl ;g reset comma flag
  107. moredelim:
  108. LODSB
  109. INVOKE DELIM
  110. JNZ SCANCDONE
  111. CMP AL,' '
  112. JZ moredelim
  113. CMP AL,9
  114. JZ moredelim
  115. xchg al,[SKPDEL]
  116. or al,al
  117. jz moredelim ; One non space/tab delimiter allowed
  118. test bh,080h ;g has a special char been found?
  119. jz no_comma ;g no - just exit
  120. mov comma,1 ;g set comma flag
  121. no_comma:
  122. JMP x_done ; Nul argument
  123. SCANCDONE:
  124. ;;;; IFNDEF DBCS 3/3/KK
  125. ;---------------
  126. ; Mod to avoid upper-case conversion.
  127. ; cmp cpyflag,1 3/3/KK
  128. ; jnz cpcont1 3/3/KK
  129. ; invoke UPCONV 3/3/KK
  130. cpcont1:
  131. ;---------------
  132. ;;;; ENDIF 3/3/KK
  133. cmp al,bl ; Special delimiter?
  134. jnz nospec
  135. or bh,80H
  136. jmp short moredelim
  137. nospec:
  138. cmp al,0DH ; a CR?
  139. jne ncperror
  140. jmp cperror
  141. ncperror:
  142. cmp al,[SWITCHAR] ; is the char the switch char?
  143. jne na_switch ; yes, process...
  144. jmp a_switch
  145. na_switch:
  146. mov dl,':'
  147. cmp byte ptr [si],dl
  148. jne anum_chard ; Drive not specified
  149. ;;;; IFDEF DBCS 3/3/KK
  150. ;---------------
  151. ; Mod to avoid upper-case conversion.
  152. cmp cpyflag,1
  153. jnz cpcont2
  154. invoke UPCONV
  155. cpcont2:
  156. ;---------------
  157. ;;;; ENDIF 3/3/KK
  158. call move_char
  159. lodsb ; Get the ':'
  160. call move_char
  161. mov [STARTEL],di
  162. mov [ELCNT],0
  163. jmp anum_test
  164. anum_chard:
  165. mov [STARTEL],di
  166. mov [ELCNT],0 ; Store of this char sets it to one
  167. cmp cpyflag,1 ; Was CPARSE called from COPY?
  168. jnz anum_char ; No, don't add drive spec.
  169. invoke PATHCHRCMP ; Starts with a pathchar?
  170. jnz anum_char ; no
  171. push ax
  172. mov al,[CURDRV] ; Insert drive spec
  173. add al,capital_A
  174. call move_char
  175. mov al,':'
  176. call move_char
  177. pop ax
  178. mov [STARTEL],di
  179. mov [ELCNT],0
  180. anum_char:
  181. ;;;; IFDEF DBCS 3/3/KK
  182. invoke TESTKANJ
  183. jz NOTKANJ ;AC048;
  184. ifdef NEC_98
  185. if BUGFIX
  186. cmp byte ptr [si],' '
  187. jb NOTKANJ
  188. endif
  189. endif ;NEC_98
  190. call move_char
  191. lodsb
  192. jmp short notspecial
  193. NOTKANJ: ;AN048; If not kanji
  194. cmp cpyflag,1 ;AN048; and if we're in COPY
  195. jnz testdot ;AN048;
  196. invoke upconv ;AN048; upper case the char
  197. TESTDOT:
  198. ;;;; ENDIF 3/3/KK
  199. cmp al,dot_chr
  200. jnz testquest
  201. inc [ELPOS] ; flag in extension
  202. mov [ELCNT],0FFH ; Store of the '.' resets it to 0
  203. testquest:
  204. cmp al,'?'
  205. jnz testsplat
  206. or bh,2
  207. testsplat:
  208. cmp al,star
  209. jnz testpath
  210. or bh,2
  211. cmp byte ptr [expand_star],0
  212. jnz expand_filename
  213. jmp SHORT testpath
  214. badperr2j:
  215. jmp short badperr2
  216. expand_filename:
  217. mov ah,7
  218. cmp [ELPOS],0
  219. jz gotelcnt
  220. mov ah,2
  221. gotelcnt:
  222. mov al,'?'
  223. sub ah,[ELCNT]
  224. jc badperr2j
  225. xchg ah,cl
  226. jcxz testpathx
  227. qmove:
  228. xchg ah,cl
  229. call move_char
  230. xchg ah,cl
  231. loop qmove
  232. testpathx:
  233. xchg ah,cl
  234. testpath:
  235. invoke PATHCHRCMP
  236. jnz notspecial
  237. or bh,4
  238. cmp byte ptr [expand_star],0
  239. jz no_err_check
  240. test bh,2 ; If just hit a '/', cannot have ? or * yet
  241. jnz badperr
  242. no_err_check:
  243. mov [STARTEL],di ; New element
  244. INC [STARTEL] ; Point to char after /
  245. mov [ELCNT],0FFH ; Store of '/' sets it to 0
  246. mov [ELPOS],0
  247. notspecial:
  248. call move_char ; just an alphanum string
  249. anum_test:
  250. lodsb
  251. ;;;; IFNDEF DBCS 3/3/KK
  252. ;---------------
  253. ; Mod to avoid upper-case conversion.
  254. ; cmp cpyflag,1 3/3/KK
  255. ; jnz cpcont3 3/3/KK
  256. ; invoke UPCONV 3/3/KK
  257. cpcont3:
  258. ;---------------
  259. ;;;; ENDIF 3/3/KK
  260. INVOKE DELIM
  261. je x_done
  262. cmp al,0DH
  263. je x_done
  264. cmp al,[SWITCHAR]
  265. je x_done
  266. cmp al,bl
  267. je x_done
  268. cmp al,':' ; ':' allowed as trailer because
  269. ; of devices
  270. ;;;; IFDEF DBCS 3/3/KK
  271. je FOO15
  272. jmp anum_char
  273. FOO15:
  274. ;;; ELSE 3/3/KK
  275. ;;; jne anum_charj 3/3/KK
  276. ;;; ENDIF 3/3/KK
  277. ;---------------
  278. ; Modification made for parseline.
  279. ; Why would it be necessary to change colons to spaces? In this
  280. ; case, EVERY colon is changed to a space; e.g., 'f:' yields 'f ',
  281. ; but so does 'echo foo:bar' yield 'echo foo bar'.
  282. ;---------------
  283. cmp cpyflag,2 ; Is CPARSE parsing the 1st token from
  284. ; from PARSELINE?
  285. jnz cpcont4 ; No, continue
  286. call move_char ; Yes, save the ':' and go get another
  287. jmp anum_test ; character.
  288. cpcont4:
  289. inc si ;Skip the ':'
  290. jmp short x_done
  291. anum_charj:
  292. jmp anum_char
  293. badperr2:
  294. mov dx,offset trangroup:BADCPMES_ptr
  295. jmp CERROR
  296. badperr:
  297. BADCDERR: ;AC022; Issue "Invalid Directory"
  298. MOV DX,OFFSET TRANGROUP:BADCD_ptr ;AC022; message
  299. JMP CERROR ;AC022;
  300. cperror:
  301. dec si ; adjust the pointer
  302. pop di ; retrive token buffer address
  303. popf ; restore flags
  304. stc ; set the carry bit
  305. return
  306. x_done:
  307. dec si ; adjust for next round
  308. ;---------------
  309. ; Mod to recognize right and left parens as integral tokens.
  310. x_done2:
  311. ;---------------
  312. jmp short out_token
  313. a_switch:
  314. OR BH,1 ; Indicate switch
  315. OR BP,fSwitch
  316. INVOKE SCANOFF
  317. INC SI
  318. invoke testkanj ;AN057; See if DBCS lead byte
  319. jz a_switch_notkanj ;AN057; no - continue processing
  320. ifdef NEC_98
  321. if BUGFIX
  322. cmp byte ptr [si],' '
  323. jb a_switch_notkanj ;AN057; no - continue processing
  324. endif
  325. endif ;NEC_98
  326. call move_char ;AN057; DBCS - store first byte
  327. lodsb ;AN057; get second byte
  328. call move_char ;AN057; store second byte
  329. or bp,fBadSwitch ;AN057; DBCS switch is invalid
  330. jmp short out_token ;AN057; don't bother checking switch
  331. a_switch_notkanj: ;AN057;
  332. cmp al,0DH
  333. jne Store_swt
  334. mov al,0
  335. stosb ; null at the end
  336. OR BP,fBadSwitch
  337. jmp cperror ; Trailing switch character error
  338. ; BP = fSwitch but no switch
  339. ; bit is set (unknown switch)
  340. Store_swt:
  341. call move_char ; store the character
  342. ;
  343. ;---------------
  344. ; This upconv call must stay. It is used to identify copy-switches
  345. ; on the command line, and won't store anything into the output buffer.
  346. invoke UPCONV
  347. ;---------------
  348. ;
  349. PUSH ES
  350. PUSH DI
  351. PUSH CX
  352. PUSH CS
  353. POP ES
  354. ASSUME ES:TRANGROUP
  355. MOV DI,OFFSET TRANGROUP:switch_list
  356. MOV CX,SWCOUNT
  357. OR BP,fBadSwitch
  358. REPNE SCASB
  359. JNZ out_tokenp
  360. AND BP,NOT fBadSwitch
  361. MOV AX,1
  362. SHL AX,CL
  363. OR BP,AX
  364. out_tokenp:
  365. POP CX
  366. POP DI
  367. POP ES
  368. ASSUME ES:NOTHING
  369. out_token:
  370. mov al,0
  371. stosb ; null at the end
  372. pop di ; restore token buffer pointer
  373. popf
  374. clc ; clear carry flag
  375. return
  376. move_char:
  377. stosb ; store char in token buffer
  378. inc cx ; increment char count
  379. inc [ELCNT] ; increment element count for * substi
  380. return
  381. TRANCODE ENDS
  382. END
  383.