Source code of Windows XP (NT5)
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.

467 lines
15 KiB

  1. PAGE ,132
  2. TITLE DXINI.ASM -- Dos Extender INI File Processing
  3. ; Copyright (c) Microsoft Corporation 1989-1991. All Rights Reserved.
  4. ;***********************************************************************
  5. ;
  6. ; DXINI.ASM -- Dos Extender INI FIle Processing
  7. ;
  8. ;-----------------------------------------------------------------------
  9. ;
  10. ; This module provides the 286 DOS extender's ...
  11. ;
  12. ;-----------------------------------------------------------------------
  13. ;
  14. ; 09/27/89 jimmat Modified to use FindFile instead of using its
  15. ; own file search logic
  16. ; 05/24/89 w-glenns Original (UNCUT, UNCENSORED!) version
  17. ;
  18. ;***********************************************************************
  19. .286
  20. ; -------------------------------------------------------
  21. ; INCLUDE FILE DEFINITIONS
  22. ; -------------------------------------------------------
  23. .xlist
  24. .sall
  25. include segdefs.inc
  26. include gendefs.inc
  27. include intmac.inc
  28. .list
  29. ; -------------------------------------------------------
  30. ; GENERAL SYMBOL DEFINITIONS
  31. ; -------------------------------------------------------
  32. CR equ 13
  33. LF equ 10
  34. TAB equ 9
  35. EOF equ 26
  36. ; -------------------------------------------------------
  37. ; EXTERNAL SYMBOL DEFINITIONS
  38. ; -------------------------------------------------------
  39. extrn strcpy:NEAR
  40. extrn FindFile:NEAR
  41. ; -------------------------------------------------------
  42. ; DATA SEGMENT DEFINITIONS
  43. ; -------------------------------------------------------
  44. DXDATA segment
  45. extrn rgbXfrBuf1:BYTE
  46. DXDATA ends
  47. ; -------------------------------------------------------
  48. subttl Read INI File Routine
  49. page
  50. ; -------------------------------------------------------
  51. ; READ INI FILE ROUTINE
  52. ; -------------------------------------------------------
  53. DXCODE segment
  54. assume cs:DXCODE
  55. ;******************************************************************************
  56. ;
  57. ; ReadIniFile
  58. ;
  59. ; DESCRIPTION: read and parse a .INI file for the 286 DOS Extender
  60. ; initialization.
  61. ;
  62. ; ENTRY: dx points to the file name
  63. ; bx points to structure to fill with ini fields
  64. ;
  65. ; EXIT: Carry set, if file not found, or not enough memory
  66. ;
  67. ; USES: ax, cx
  68. ;
  69. ;==============================================================================
  70. assume ds:DGROUP
  71. public ReadIniFile
  72. ReadIniFile PROC NEAR
  73. push es
  74. push bx
  75. push si
  76. push di
  77. push ds
  78. pop es
  79. assume es:DGROUP
  80. push bx ; ptr to ini structure to fill
  81. mov si,dx
  82. mov di,offset RELOC_BUFFER ; FindFile wants the name here
  83. call strcpy
  84. call FindFile ; locate the .INI file
  85. jc ri_error
  86. mov ax,3D00h ; open the .INI file
  87. mov dx,offset EXEC_PROGNAME ; FindFile puts path name here
  88. int 21h
  89. jc ri_error ; shouldn't happen, but...
  90. mov si, ax ; file handle
  91. mov ah, 48h ; alloc DOS conventional memory
  92. mov bx, 4096d ; want 64k block
  93. int 21h
  94. jc ri_error
  95. pop dx ; ptr to ini structure to fill
  96. call parse_ini ; do the work, and come back
  97. assume es:NOTHING
  98. pushf ; save parse_ini flags
  99. mov ah, 49h ; dealloc DOS conventional memory
  100. int 21h ; es already points to block
  101. npopf ; carry set = problem
  102. ri_end:
  103. pop di
  104. pop si
  105. pop bx
  106. pop es
  107. ret
  108. ri_error: ; error exit
  109. pop bx ; clear stack
  110. stc ; force carry on
  111. jmp short ri_end ; split
  112. ReadIniFile ENDP
  113. ;******************************************************************************
  114. ;
  115. ; Parse_Ini
  116. ;
  117. ; DESCRIPTION: Read in, and parse the ini file opened
  118. ; and find the variable values specified
  119. ;
  120. ; ENTRY: ax points to the memory block for the file image buffer
  121. ; dx points to structure to fill with ini fields
  122. ; si has the handle to the file opened
  123. ;
  124. ; EXIT: Carry set, if file not found, or not enough memory
  125. ;
  126. ; USES: ax, bx, cx, es
  127. ;
  128. ;==============================================================================
  129. Parse_Ini PROC NEAR
  130. push bp
  131. push dx
  132. mov bp,dx ; bp = index into structure (es:)
  133. assume ds:NOTHING
  134. push ds
  135. mov ds, ax ; ptr to mem block
  136. mov ah, 3Fh
  137. mov bx, si
  138. mov cx, 0FFFFh ; guess extremely high
  139. xor dx, dx ; offset 0
  140. int 21h
  141. pop es
  142. assume es:DGROUP ; NOTE:!!! es is now data segment !!!
  143. pushf ; save flags from read
  144. push ax ; save # bytes read
  145. mov ah, 3Eh ; close file
  146. mov bx, si
  147. int 21h
  148. pop di ; number bytes read
  149. npopf ; CY flag
  150. jnc @f
  151. jmp parse_done_jump ; if couldn't read, return bad
  152. @@:
  153. mov byte ptr ds:[di], EOF ; write EOF char'r in case none present
  154. ; ds:si points to the file image buffer
  155. ; es:di/bx structure to fill with ini stuff
  156. xor si,si
  157. ; search until section found
  158. find_section:
  159. call Get_Char
  160. jc short parse_done_jump ; end of file, and section not found
  161. cmp al, '[' ; a section ?
  162. jne short find_section
  163. mov di, bp ; point to ini structure
  164. ; a section has been found, but is it the right one ?
  165. xor bx, bx ; use as secondary index
  166. cmp_section:
  167. mov al, byte ptr ds:[si+bx] ; char'r from section name in file
  168. inc bx ; bx starts at zero for file pointer
  169. ; index, and starts at one for
  170. ; structure index
  171. mov ah, byte ptr es:[di+bx]
  172. or ah, ah
  173. jz short find_keyword_start ; yes: found the right section !
  174. call Conv_Char_Lower ; convert char'r in AL to lower case
  175. cmp al, ah ; same so far ?
  176. jne short find_section
  177. jmp short cmp_section
  178. find_keyword_start:
  179. add si,bx ; update file pointer past section name
  180. add bp,bx ; update structure ptr past section name
  181. ; now that section is found, want to find keywords
  182. find_keyword:
  183. call Get_Char ; points to 1st char'r of next keyword
  184. jc short parse_done_jump ; end of file, and keyword not found
  185. cmp al, '[' ; new section ?
  186. je short parse_done_jump ; hit a new section, so we're done
  187. search_keyword:
  188. xor di,di
  189. ; use beginning of file image buffer for temporary storage of the
  190. ; keyword name currently being checked
  191. find_keyword_loop:
  192. mov byte ptr ds:[di], al ; copy the char'r
  193. inc di
  194. mov dx,si ; save position in file image buffer
  195. call Get_Char ; points to 1st char'r of next keyword
  196. jc short parse_done_jump ; end of file, and keyword not found
  197. pushf
  198. cmp al, '='
  199. je short compare_keyword
  200. ; yes: found a keyword, lets do some comparisons
  201. npopf
  202. jz short find_keyword_loop ; no white space yet...copy keyword
  203. skip_keyword:
  204. ; white space has been skipped, yet there is no '='
  205. ; must be an error...ignore, and get next keyword
  206. mov si,dx ; point to last char'r in keyword
  207. mov byte ptr ds:[si], ';'
  208. ; fake a comment, so that the rest of the
  209. ; line is ignored in the next Get_Char call
  210. ; and the next keyword is pointed to
  211. jmp short find_keyword
  212. parse_done_jump:
  213. jmp parse_done
  214. ; char'r is an equals, so compare this keyword to the list
  215. compare_keyword:
  216. npopf ; clean top-of-stack
  217. mov byte ptr ds:[di], 0 ; NULL at end of keyword for compare
  218. mov bx,bp ; get index into INI structure in
  219. ; data segment DGROUP (where es points)
  220. cmp_keyword1:
  221. xor di,di ; point to start of keyword found
  222. cmp_keyword:
  223. inc bx
  224. mov ah, byte ptr es:[bx] ; next char'r in ini struct keyword
  225. mov al, byte ptr ds:[di] ; next char'r of found keyword
  226. inc di
  227. or al, ah
  228. jz short convert_number ; yes: found the right keyword
  229. call Conv_Char_Lower ; convert char'r in AL to lower case
  230. cmp al, ah ; same so far ?
  231. je short cmp_keyword
  232. xor al,al
  233. dec bx
  234. cmp_keyword_loop:
  235. inc bx
  236. cmp byte ptr es:[bx], al ; next keyword yet?
  237. jne cmp_keyword_loop ; nope: go back until done
  238. ; keywords don't match..try next key word in ini structure
  239. inc bx
  240. inc bx ; jump over variable space (1 word)
  241. cmp byte ptr es:[bx+1], al ; more keywords to compare with ?
  242. jne short cmp_keyword1 ; yes: compare the next one
  243. jmp short skip_keyword
  244. ; no: search file for next keyword
  245. convert_number:
  246. push si ; save current file pointer
  247. call Get_Char
  248. dec si ; point to first char'r position in number to convert
  249. xor di,di
  250. mov ax,di
  251. mov cx,ax
  252. cmp byte ptr ds:[si], '+' ; positive number ? (default)
  253. jne short cn_1
  254. inc si ; just skip the char'r - positive is default anyway
  255. cn_1: cmp byte ptr ds:[si], '-' ; negative number ?
  256. jne short cn_2
  257. inc si
  258. inc cl ; negative number - flag so we can negate it later
  259. cn_2: push bx
  260. mov bx,si ; save ptr in file buffer - check later if it changed
  261. push cx ; save flag
  262. convert_get_loop:
  263. mov cl, byte ptr ds:[si]
  264. cmp cl, '0'
  265. jb short convert_done
  266. cmp cl, '9'
  267. ja short convert_done
  268. sub cx,'0' ; de-ascii'ize cx ==> 0h - 09h
  269. inc si ; increment pointer
  270. mov dx,010d
  271. mul dx ; multiply ax by 10 : dx is set to zero
  272. add ax,cx ; add number in
  273. jmp short convert_get_loop
  274. convert_done:
  275. pop cx ; restore -ve/+ve flag
  276. jcxz convert_done_1 ; Q: -ve number ?
  277. neg ax ; negate the number
  278. convert_done_1:
  279. cmp si,bx ; Q: has index changed, i.e.
  280. ; is the first char'r invalid ?
  281. pop bx
  282. je short convert_done_2 ; Y: don't save number
  283. inc bx ; N: point to number in structure
  284. mov word ptr es:[bx], ax ; save value into ini structure
  285. convert_done_2:
  286. pop si ; get old file pointer
  287. mov byte ptr ds:[si], ';'
  288. ; fake a comment, so that the rest of the
  289. ; line is ignored in the next Get_Char call
  290. ; and the next keyword is pointed to
  291. jmp find_keyword ; go back & get another
  292. ; *** single exit point for parsing code
  293. parse_done:
  294. mov ax,es ; swap extended and data segment ptrs
  295. mov bx,ds
  296. mov es,bx
  297. mov ds,ax
  298. pop dx
  299. pop bp
  300. ret
  301. Parse_Ini ENDP
  302. ;******************************************************************************
  303. ;
  304. ; Get_Char
  305. ;
  306. ; DESCRIPTION: Local routine which gets the next valid ascii
  307. ; character from the file image, while skipping white
  308. ; space.
  309. ;
  310. ; ENTRY: ds:si -> buffer pointer
  311. ;
  312. ; EXIT: ds:si -> new buffer pointer
  313. ; al --> character
  314. ; Z flag --> set = no white space between last char'r and current
  315. ; C flag --> set = reached end of file
  316. ;
  317. ; USES: cx
  318. ;
  319. ;==============================================================================
  320. Get_Char PROC NEAR
  321. mov cx,si
  322. inc cx
  323. get_char_loop:
  324. lodsb ; get char from file image
  325. cmp al,EOF
  326. je short get_char_EOF
  327. cmp al,CR
  328. je short get_char_loop
  329. cmp al,LF
  330. je short get_char_loop
  331. cmp al,TAB
  332. je short get_char_loop
  333. cmp al,' '
  334. je short get_char_loop
  335. cmp al,';'
  336. je short get_char_skip_comment
  337. ; must have got a good character finally...
  338. call Conv_Char_Lower
  339. cmp cx,si ; skipped a white space ?
  340. clc ; continue
  341. ret
  342. get_char_EOF:
  343. stc ; flag end of the file
  344. ret
  345. get_char_skip_comment:
  346. lodsb ; get char from file image
  347. cmp al,EOF
  348. je short get_char_EOF
  349. cmp al,CR
  350. jne short get_char_skip_comment
  351. jmp short get_char_loop
  352. Get_Char ENDP
  353. Conv_Char_Lower PROC NEAR
  354. cmp al, 'A' ; want char'r 'A'-'Z' to be
  355. jb short lower_done ; converted to 'a'-'z'
  356. cmp al, 'Z'
  357. ja short lower_done
  358. or al, 020h ; convert to lower case
  359. lower_done:
  360. ret
  361. Conv_Char_Lower ENDP
  362. ; -------------------------------------------------------
  363. DXCODE ends
  364. ;****************************************************************
  365. end