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.

654 lines
14 KiB

  1. PAGE ,132
  2. TITLE PARSE CODE AND CONTROL BLOCKS FOR KEYB.COM
  3. ;****************** START OF SPECIFICATIONS **************************
  4. ;
  5. ; MODULE NAME: PARSER.ASM
  6. ;
  7. ; DESCRIPTIVE NAME: PARSES THE COMMAND LINE PARAMETERS FOR KEYB.COM
  8. ;
  9. ; FUNCTION: THE COMMAND LINE IN THE PSP IS PARSED FOR PARAMETERS.
  10. ;
  11. ; ENTRY POINT: PARSE_PARAMETERS
  12. ;
  13. ; INPUT: BP POINTS TO PARAMETER LIST
  14. ; DS & ES POINT TO PSP
  15. ;
  16. ; AT EXIT:
  17. ; PARAMETER LIST FILLED IN AS REQUIRED.
  18. ;
  19. ; INTERNAL REFERENCES:
  20. ;
  21. ; ROUTINES: SYSPARSE - PARSING CODE
  22. ;
  23. ; DATA AREAS: PARMS - PARSE CONTROL BLOCK FOR SYSPARSE
  24. ;
  25. ; EXTERNAL REFERENCES:
  26. ;
  27. ; ROUTINES: N/A
  28. ;
  29. ; DATA AREAS: PARAMETER LIST BLOCK TO BE FILLED.
  30. ;
  31. ; NOTES:
  32. ;
  33. ; REVISION HISTORY:
  34. ; A000 - DOS Version 3.40
  35. ; 3/24/88 AN003 - P3906 PARSER changes to return "bogus" parameter on the
  36. ; "Parameter value not allowed " message - CNS
  37. ; 5/12/88 AN004 - P4867 /ID:NON-Numeric hangs the sytem as a 1st positional
  38. ;
  39. ;
  40. ; (C) Copyright Microsoft Corp. 1987-1990
  41. ; MS-DOS 5.00 - NLS Support - KEYB Command
  42. ;
  43. ;
  44. ;****************** END OF SPECIFICATIONS ****************************
  45. INCLUDE KEYBDCL.INC
  46. ID_VALID EQU 0
  47. ID_INVALID EQU 1
  48. NO_ID EQU 2
  49. LANGUAGE_VALID EQU 0
  50. LANGUAGE_INVALID EQU 1
  51. NO_LANGUAGE EQU 2
  52. NO_IDLANG EQU 3
  53. CODE_PAGE_VALID EQU 0
  54. CODE_PAGE_INVALID EQU 1
  55. NO_CODE_PAGE EQU 2
  56. VALID_SYNTAX EQU 0
  57. INVALID_SYNTAX EQU 1
  58. COMMAND_LINE_START EQU 81H
  59. RC_EOL EQU -1
  60. RC_NO_ERROR EQU 0
  61. RC_OP_MISSING EQU 2
  62. RC_NOT_IN_SW EQU 3
  63. ;***CNS P4867 1st CHECK for /ID:ALPHA
  64. RC_SW_FIRST EQU 9
  65. ;***CNS P4867 1st CHECK for /ID:ALPHA
  66. ERROR_COND EQU -1
  67. NUMBER EQU 1
  68. STRING EQU 3
  69. FILE_SPEC EQU 5
  70. MAX_ID EQU 999
  71. LANG_LENGTH EQU 2
  72. INVALID_SWITCH EQU 3
  73. TOO_MANY EQU 1
  74. INVALID_PARAM EQU 10
  75. VALUE_DISALLOW EQU 8
  76. PUBLIC PARSE_PARAMETERS ; near procedure for parsing command line
  77. PUBLIC CUR_PTR ; near procedure for parsing command line
  78. PUBLIC OLD_PTR ; near procedure for parsing command line
  79. PUBLIC ERR_PART ; near procedure for parsing command line
  80. EXTRN BAD_ID:BYTE ; WGR to match old code
  81. EXTRN FOURTH_PARM:BYTE ; WGR to match old code
  82. EXTRN ONE_PARMID:BYTE ; WGR to match old code
  83. EXTRN FTH_PARMID:BYTE ; WGR to match old code
  84. EXTRN ALPHA:BYTE ; WGR to match old code
  85. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  86. ; Set assemble switches for parse code that is not required!!
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  88. DateSW EQU 0
  89. TimeSW EQU 0
  90. CmpxSW EQU 0
  91. DrvSW EQU 0
  92. QusSW EQU 0
  93. KeySW EQU 0
  94. Val1SW EQU 0
  95. Val2SW EQU 0
  96. Val3SW EQU 0
  97. CODE SEGMENT PUBLIC 'CODE' BYTE
  98. ASSUME CS:CODE,DS:CODE
  99. .XLIST
  100. INCLUDE PARSE.ASM ; Parsing code
  101. .LIST
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103. ; PARM control blocks for KEYB
  104. ; Parsing command line as follows:
  105. ;
  106. ; KEYB [lang],[cp],[[d:][path]KEYBOARD.SYS][/ID:id][/e][/?]
  107. ;
  108. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  109. PARMS LABEL WORD
  110. DW PARMSX
  111. DB 0 ; no extra delimeters or EOLs.
  112. PARMSX LABEL BYTE
  113. DB 0,3 ; min,max positional operands
  114. DW LANG ; pointer to control block
  115. DW CP ; pointer to control block
  116. DW FILE_NAME ; pointer to control block
  117. DB 3 ; 3 switches
  118. DW ID_VALUE ; pointer to control block
  119. dw help_value ; pointer to control block
  120. dw ext_value ; pointer to control block
  121. DB 0 ; no keywords
  122. LANG LABEL WORD
  123. DW 0A001H ; sstring or numeric value (optional)
  124. DW 0002H ; cap result by char table (sstring)
  125. DW RESULT_BUF ; result
  126. DW NOVALS ; no value checking done
  127. DB 0 ; no keyword/switch synonyms
  128. CP LABEL WORD
  129. DW 8001H ; numeric
  130. DW 0 ; no functions
  131. DW RESULT_BUF ; result
  132. DW NOVALS ; no value checking done
  133. DB 0 ; no keyword/switch synonyms
  134. FILE_NAME LABEL WORD
  135. DW 0201H ; file spec
  136. DW 0001H ; cap by file table
  137. DW RESULT_BUF ; result
  138. DW NOVALS ; no value checking done
  139. DB 0 ; no keyword/switch synonyms
  140. ID_VALUE LABEL WORD
  141. DW 8010H ; numeric
  142. DW 0 ; no functions
  143. DW RESULT_BUF ; result
  144. DW NOVALS ; no value checking done
  145. DB 1 ; 1 switch synonym
  146. id_name:
  147. DB "/ID",0 ; ID switch
  148. help_value label word
  149. dw 0 ; no values
  150. dw 0 ; no functions
  151. dw RESULT_BUF ; result
  152. dw novals ; no value checking done
  153. db 1 ; 1 switch synonym
  154. help_name:
  155. db "/?",0 ; /? switch
  156. ext_value label word
  157. dw 0 ; no values
  158. dw 0 ; no functions
  159. dw result_buf ; result
  160. dw novals ; no value checking done
  161. db 1 ; 1 switch synonym
  162. ext_name:
  163. db "/E",0 ; /e switch
  164. NOVALS LABEL BYTE
  165. DB 0 ; no value checking done
  166. RESULT_BUF LABEL BYTE
  167. RESULT_TYPE DB 0 ; type returned (number, string, etc.)
  168. DB ? ; matched item tag (if applicable)
  169. RESULT_SYN_PTR DW ? ; synonym ptr (if applicable)
  170. RESULT_VAL DD ? ; value
  171. LOOP_COUNT DB 0 ; keeps track of parameter position
  172. ;***CNS
  173. CUR_PTR DW 0 ; keeps track of parameter position
  174. OLD_PTR DW 0 ; keeps track of parameter position
  175. ERR_PART DW 0 ; keeps track of parameter position
  176. ;***CNS
  177. ;..and reports an error condition
  178. public pswitches
  179. pswitches db 0 ; bit 0, /?, bit 1 /e
  180. TEMP_FILE_NAME DB 128 DUP(0) ; place for file name
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. ;
  183. ; PROCEDURE_NAME: PARSE_PARAMETERS
  184. ;
  185. ; FUNCTION:
  186. ; THIS PROCEDURE PARSES THE COMMAND LINE PARAMETERS IN THE PSP FOR
  187. ; KEYB.COM. THE PARAMETER LIST BLOCK IS FILLED IN ACCORDINGLY.
  188. ;
  189. ; AT ENTRY: AS ABOVE.
  190. ;
  191. ; AT EXIT:
  192. ; AS ABOVE.
  193. ;
  194. ; AUTHOR: WGR
  195. ;
  196. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  197. PARSE_PARAMETERS PROC NEAR
  198. XOR AX,AX ; setup default parameters.
  199. MOV [BP].RET_CODE_1,NO_IDLANG
  200. MOV [BP].RET_CODE_2,NO_CODE_PAGE
  201. MOV [BP].RET_CODE_3,VALID_SYNTAX
  202. MOV [BP].RET_CODE_4,NO_ID
  203. MOV [BP].PATH_LENGTH,AX
  204. LEA DI,PARMS ; setup parse blocks
  205. MOV SI,COMMAND_LINE_START
  206. call save_curptr
  207. XOR CX,CX
  208. XOR DX,DX
  209. CALL SYSPARSE
  210. kbs_10:
  211. cmp ax,RC_EOL ; while not end of line and...
  212. jnz kbs_11
  213. jmp kbs_12
  214. kbs_11:
  215. cmp LOOP_COUNT,ERROR_COND ; parameters valid, do...
  216. jnz kbs_13
  217. jmp kbs_12
  218. kbs_13:
  219. cmp ax,RC_NOT_IN_SW ; invalid switch?
  220. jz kbs_08
  221. cmp ax,RC_SW_FIRST
  222. jnz kbs_09
  223. kbs_08:
  224. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; set invalid syntax flag.
  225. MOV LOOP_COUNT,ERROR_COND ; set error flag to exit parse.
  226. ;***CNS
  227. MOV ERR_PART,INVALID_SWITCH
  228. call save_curptr
  229. ;***CNS
  230. jmp kbs_10
  231. kbs_09:
  232. cmp RESULT_SYN_PTR,offset id_name ; was /id:xxx switch found?
  233. jnz not_id_switch
  234. MOV AX,WORD PTR RESULT_VAL+2 ; is it valid?
  235. OR AX,AX
  236. jnz kbs_01
  237. mov ax,word ptr RESULT_VAL
  238. cmp ax,MAX_ID
  239. jna kbs_02
  240. kbs_01:
  241. MOV [BP].RET_CODE_1,ID_INVALID ; no...invalid id.
  242. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; syntax error.
  243. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse
  244. mov bad_id,1
  245. MOV [ERR_PART],VALUE_DISALLOW ; SET ERROR TYPE FOR DISPLAY
  246. call save_curptr
  247. jmp short kbs_03
  248. kbs_02:
  249. MOV [BP].RET_CODE_4,ID_VALID ; yes...set return code 4.
  250. MOV [BP].ID_PARM,AX
  251. mov fourth_parm,1
  252. mov fth_parmid,1
  253. jmp short kbs_03
  254. not_id_switch:
  255. cmp RESULT_SYN_PTR,offset help_name ; was /? switch found?
  256. jnz not_help_switch
  257. or pswitches,1 ; set flag for /?
  258. jmp short kbs_03
  259. not_help_switch:
  260. cmp RESULT_SYN_PTR,offset ext_name
  261. jnz kbs_07
  262. or pswitches,2 ; set flag for /e
  263. jmp short kbs_03
  264. kbs_07:
  265. INC LOOP_COUNT ; positional encountered...
  266. cmp LOOP_COUNT,1 ; check for language
  267. jnz kbs_04
  268. CALL PROCESS_1ST_PARM
  269. call save_curptr
  270. jmp short kbs_03
  271. kbs_04:
  272. cmp LOOP_COUNT,2 ; check for code page
  273. jnz kbs_05
  274. CALL PROCESS_2ND_PARM
  275. call save_curptr
  276. jmp short kbs_03
  277. kbs_05:
  278. cmp LOOP_COUNT,3 ; check for file name
  279. jnz kbs_06
  280. CALL PROCESS_3RD_PARM
  281. call save_curptr
  282. jmp short kbs_03
  283. ; all other cases
  284. kbs_06:
  285. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; too many parms
  286. call save_curptr
  287. MOV ERR_PART,TOO_MANY
  288. MOV LOOP_COUNT,ERROR_COND ; set error flag to exit parse.
  289. kbs_03:
  290. MOV RESULT_TYPE,0 ; reset result block.
  291. CALL SYSPARSE ; parse next parameter.
  292. jmp kbs_10
  293. kbs_12:
  294. cmp [bp].RET_CODE_4,ID_VALID
  295. jnz kbs_14 ; ensure that if switch was
  296. cmp [bp].RET_CODE_1,LANGUAGE_VALID ; used, it was valid keyword
  297. jz kbs_14
  298. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; code was used..
  299. ;***CNS
  300. call save_curptr
  301. MOV ERR_PART,VALUE_DISALLOW
  302. ;***CNS
  303. kbs_14:
  304. RET
  305. PARSE_PARAMETERS ENDP
  306. save_curptr proc near
  307. PUSH AX ;Save environment
  308. MOV AX,CUR_PTR ;Set advancing ptr to end of argument
  309. MOV OLD_PTR,AX ;after saving the beginning the string
  310. MOV CUR_PTR,SI
  311. POP AX ;Restore the environment
  312. ret
  313. save_curptr endp
  314. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  315. ;
  316. ; PROCEDURE_NAME: PROCESS_1ST_PARM
  317. ;
  318. ; FUNCTION:
  319. ; THIS PROCEDURE PROCESSES THE FIRST POSITIONAL PARAMETER. THIS SHOULD
  320. ; BE THE LANGUAGE ID OR THE KEYBOARD ID.
  321. ;
  322. ; AT ENTRY: PARSE RESULT BLOCK CONTAINS VALUES IF AX HAS NO ERROR.
  323. ;
  324. ; AT EXIT:
  325. ; PARAMETER CONTROL BLOCK UPDATED FOR LANGUAGE ID.
  326. ;
  327. ; AUTHOR: WGR
  328. ;
  329. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  330. PROCESS_1ST_PARM PROC NEAR
  331. cmp ax,RC_NO_ERROR ; error on parse?
  332. jng kbs_23
  333. MOV [BP].RET_CODE_1,LANGUAGE_INVALID ; yes...set invalid language
  334. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; and syntax error..
  335. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse.
  336. MOV ERR_PART,AX
  337. jmp kbs_18
  338. kbs_23:
  339. cmp RESULT_TYPE,NUMBER ; was this a number (id?)
  340. jnz kbs_24
  341. MOV AX,WORD PTR RESULT_VAL+2 ; yes...check to see if
  342. OR AX,AX ; within range.
  343. jnz kbs_19
  344. MOV AX,WORD PTR RESULT_VAL
  345. cmp ax,max_id
  346. jna kbs_17
  347. kbs_19:
  348. MOV [BP].RET_CODE_1,ID_INVALID ; no...invalid id.
  349. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; syntax error.
  350. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse
  351. mov bad_id,1
  352. jmp short kbs_18
  353. kbs_17:
  354. MOV [BP].RET_CODE_1,ID_VALID ; valid id...set
  355. MOV [BP].RET_CODE_4,ID_VALID ; valid id...set
  356. MOV [BP].ID_PARM,AX ; and value moved into block
  357. MOV LOOP_COUNT,4 ; there should be no more parms
  358. mov one_parmid,1
  359. jmp short kbs_18
  360. kbs_24:
  361. cmp RESULT_TYPE,STRING ; must be a string then???
  362. jnz kbs_26
  363. PUSH SI
  364. PUSH DI
  365. PUSH CX
  366. PUSH DS
  367. LDS SI,RESULT_VAL ; get ptr to string
  368. MOV DI,BP
  369. ADD DI,LANGUAGE_PARM ; point to block for copy.
  370. MOV CX,LANG_LENGTH ; maximum length = 2
  371. LODSB ; load AL with 1st char..
  372. kbs_16:
  373. jcxz kbs_15 ; do twice, unless only 1 char
  374. or al,al
  375. jz kbs_15
  376. STOSB ; store
  377. DEC CX ; dec count
  378. LODSB ; load
  379. jmp kbs_16
  380. kbs_15:
  381. or cx,cx ; if there was less than 2 or..
  382. jnz kbs_20
  383. or al,al ; greater than 2 chars, then..
  384. jz kbs_21
  385. kbs_20:
  386. MOV [BP].RET_CODE_1,LANGUAGE_INVALID ; invalid.
  387. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; syntax error
  388. MOV ERR_PART,INVALID_PARAM
  389. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse.
  390. jmp short kbs_22
  391. kbs_21:
  392. MOV [BP].RET_CODE_1,LANGUAGE_VALID ; valid language has been copied
  393. MOV ALPHA,1 ; language found
  394. kbs_22:
  395. POP DS
  396. POP CX
  397. POP DI
  398. POP SI
  399. jmp short kbs_18
  400. ; omitted parameter...
  401. kbs_26:
  402. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; invalid since further parameters.
  403. kbs_18:
  404. RET
  405. PROCESS_1ST_PARM ENDP
  406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  407. ;
  408. ; PROCEDURE_NAME: PROCESS_2ND_PARM
  409. ;
  410. ; FUNCTION:
  411. ; THIS PROCEDURE PROCESSES THE 2ND POSITIONAL PARAMETER. THIS SHOULD
  412. ; BE THE CODE PAGE, IF REQUESTED.
  413. ;
  414. ; AT ENTRY: PARSE RESULT BLOCK CONTAINS VALUES IF AX HAS NO ERROR.
  415. ;
  416. ; AT EXIT:
  417. ; PARAMETER CONTROL BLOCK UPDATED FOR CODE PAGE.
  418. ;
  419. ; AUTHOR: WGR
  420. ;
  421. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  422. PROCESS_2ND_PARM PROC NEAR
  423. cmp ax,RC_NO_ERROR ; if parse error
  424. jle kbs_32
  425. MOV [BP].RET_CODE_2,CODE_PAGE_INVALID ; mark invalid..
  426. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; syntax error
  427. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse
  428. MOV ERR_PART,AX
  429. jmp short kbs_31
  430. kbs_32:
  431. cmp RESULT_TYPE,NUMBER ; was parameter specified?
  432. jnz kbs_30
  433. MOV AX,WORD PTR RESULT_VAL+2 ; yes..if code page not..
  434. OR AX,AX
  435. jnz kbs_27
  436. MOV AX,WORD PTR RESULT_VAL ; valid..then
  437. cmp ax,MAX_ID
  438. jna kbs_28
  439. kbs_27:
  440. MOV [BP].RET_CODE_2,CODE_PAGE_INVALID ; mark invalid..
  441. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; syntax error
  442. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse
  443. jmp short kbs_31
  444. kbs_28:
  445. MOV [BP].RET_CODE_2,CODE_PAGE_VALID ; else...valid code page
  446. MOV [BP].CODE_PAGE_PARM,AX ; move into parm
  447. jmp short kbs_31
  448. kbs_30:
  449. MOV [BP].RET_CODE_2,NO_CODE_PAGE ; mark as not specified.
  450. kbs_31:
  451. RET
  452. PROCESS_2ND_PARM ENDP
  453. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  454. ;
  455. ; PROCEDURE_NAME: PROCESS_3RD_PARM
  456. ;
  457. ; FUNCTION:
  458. ; THIS PROCEDURE PROCESSES THE 3RD POSITIONAL PARAMETER. THIS SHOULD
  459. ; BE THE KEYBOARD DEFINITION FILE PATH, IF SPECIFIED.
  460. ;
  461. ; AT ENTRY: PARSE RESULT BLOCK CONTAINS VALUES IF AX HAS NO ERROR.
  462. ;
  463. ; AT EXIT:
  464. ; PARAMETER CONTROL BLOCK UPDATED FOR FILE NAME.
  465. ;
  466. ; AUTHOR: WGR
  467. ;
  468. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  469. PROCESS_3RD_PARM PROC NEAR
  470. cmp ax,RC_NO_ERROR ; if parse error, then...
  471. jle kbs_33
  472. MOV [BP].RET_CODE_3,INVALID_SYNTAX ; syntax error.
  473. MOV LOOP_COUNT,ERROR_COND ; set flag to exit parse
  474. MOV ERR_PART,AX
  475. jmp short kbs_34
  476. kbs_33:
  477. cmp RESULT_TYPE,FILE_SPEC
  478. jnz kbs_34
  479. PUSH DS
  480. PUSH SI
  481. PUSH DI
  482. PUSH CX
  483. LDS SI,RESULT_VAL ; load offset of file name
  484. LEA DI,TEMP_FILE_NAME
  485. MOV [BP].PATH_OFFSET,DI ; copy to parameter block
  486. XOR CX,CX
  487. LODSB ; count the length of the path.
  488. kbs_35:
  489. or al,al
  490. jz kbs_36
  491. STOSB
  492. LODSB
  493. INC CX
  494. jmp short kbs_35
  495. kbs_36:
  496. MOV [BP].PATH_LENGTH,CX ; copy to parameter block
  497. POP CX
  498. POP DI
  499. POP SI
  500. POP DS
  501. kbs_34:
  502. RET
  503. PROCESS_3RD_PARM ENDP
  504. CODE ENDS
  505. END
  506.