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.

1925 lines
65 KiB

  1. TITLE USERPRO - interface to WIN.INI file
  2. include kernel.inc
  3. include pdb.inc
  4. externFP GlobalFree
  5. externFP GlobalAlloc
  6. externFP GlobalLock
  7. externFP GlobalUnlock
  8. externFP GlobalReAlloc
  9. externFP GlobalSize
  10. externFP OpenFile
  11. externFP FarMyLower
  12. ;externFP _lopen
  13. externFP _lcreat
  14. externFP _lclose
  15. externFP _lread
  16. externFP _lwrite
  17. externFP _llseek
  18. ifdef FE_SB ;Apr.26,1990 by AkiraK
  19. externFP AnsiPrev
  20. externFP FarMyIsDBCSLeadByte
  21. endif
  22. ifdef WOW
  23. externFP FarMyUpper
  24. externFP GetPrivateProfileSectionNames
  25. endif
  26. externFP TermsrvGetWindowsDir
  27. DataBegin
  28. externB szUserPro
  29. externB fBooting
  30. externW cBytesWinDir
  31. externD lpWindowsDir
  32. ifndef WOW
  33. externW cBytesSysDir
  34. externD lpSystemDir
  35. else
  36. externW cBytesSys16Dir
  37. externD lpSystem16Dir
  38. endif
  39. if 0
  40. externB fUserPro
  41. externB UserProBuf
  42. externB PrivateProBuf
  43. externW hBuffer
  44. ifndef PHILISAWEENIE
  45. externW hWBuffer
  46. externW hPBuffer
  47. endif
  48. externW hFile
  49. externD BufAddr
  50. externD lpszUserPro
  51. endif
  52. externW TopPDB
  53. ;externW MyCSDS
  54. LeftSect DB '['
  55. ; these next two must stay together
  56. RightSect DB ']'
  57. CarRetLF DB 13,10
  58. EquStr DB '='
  59. externB achTermsrvWindowsDir
  60. DataEnd
  61. sBegin MISCCODE
  62. assumes CS,MISCCODE
  63. assumes DS,NOTHING
  64. assumes ES,NOTHING
  65. externNP MISCMapDStoDATA
  66. ; WOW thunks most of these APIs.
  67. ifndef WOW
  68. SECT_LEFT equ byte ptr '['
  69. SECT_RIGHT equ byte ptr ']'
  70. CARRETURN equ byte ptr 13
  71. LINEFEED equ byte ptr 10
  72. SPACE equ byte ptr ' '
  73. TAB equ byte ptr 09
  74. CRLF equ 0A0Dh
  75. NEWRESULT equ 1
  76. NOSECTION equ 2
  77. NOKEY equ 4
  78. REMOVESECTION equ 5
  79. REMOVEKEY equ 6
  80. PROUNKN EQU 0 ; Profile unknown
  81. PROWININI EQU 1 ; Profile WIN.INI
  82. PROPRIVATE EQU 2 ; Profile specified by app
  83. PROWASPRIVATE EQU 3 ; Buffer contains private profile data
  84. ScanTo MACRO StopAt
  85. mov al, StopAt
  86. mov cx, -1
  87. repne scasb
  88. ENDM
  89. ScanBack MACRO StopAt
  90. std
  91. mov al, StopAt
  92. mov cx, di
  93. inc cx
  94. repne scasb
  95. inc di ; Leave pointing to StopAt
  96. cld
  97. ENDM
  98. ;-----------------------------------------------------------------------;
  99. ; SetDefaultPro ;
  100. ; ;
  101. ; Set lpszUserPro to point to WIN.INI if it is not already set ;
  102. ; to point to a private file ;
  103. ; ;
  104. ; Arguments: ;
  105. ; ;
  106. ; Returns: ;
  107. ; ;
  108. ; Error Returns: ;
  109. ; ;
  110. ; Registers Preserved: ;
  111. ; ;
  112. ; Registers Destroyed: ;
  113. ; ;
  114. ; Calls: ;
  115. ; ;
  116. ; History: ;
  117. ; ;
  118. ;-----------------------------------------------------------------------;
  119. assumes ds,code
  120. assumes es,nothing
  121. cProc SetDefaultPro,<PUBLIC,NEAR>
  122. cBegin nogen
  123. cmp fUserPro, PROWASPRIVATE
  124. je SDF_SetIt
  125. cmp fUserPro, PROUNKN ; No file specified
  126. jne SDF_Done
  127. SDF_SetIt:
  128. mov ax, dataOffset szUserPro
  129. mov word ptr [lpszUserPro], ax
  130. mov word ptr [lpszUserPro+2], ds
  131. mov fUserPro, PROWININI
  132. ifndef PHILISAWEENIE
  133. mov si,[hWBuffer]
  134. mov [hBuffer],si
  135. else
  136. mov si,[hBuffer]
  137. call FreeBuffer ; free up any buffer we may have
  138. endif
  139. SDF_Done:
  140. ret
  141. cEnd nogen
  142. ;-----------------------------------------------------------------------;
  143. ; SetPrivatePro ;
  144. ; ;
  145. ; Sets lpszUserPro to point to a private file ;
  146. ; ;
  147. ; Arguments: ;
  148. ; parmD lpFile ;
  149. ; ;
  150. ; Returns: ;
  151. ; ;
  152. ; Error Returns: ;
  153. ; ;
  154. ; Registers Preserved: ;
  155. ; ;
  156. ; Registers Destroyed: ;
  157. ; ;
  158. ; Calls: ;
  159. ; ;
  160. ; History: ;
  161. ; ;
  162. ;-----------------------------------------------------------------------;
  163. assumes ds,code
  164. assumes es,nothing
  165. cProc SetPrivatePro,<PUBLIC,NEAR>,<di>
  166. parmD lpszProfile
  167. localV NewFileBuf, 80h
  168. cBegin
  169. ifndef PHILISAWEENIE
  170. mov si, [hPBuffer]
  171. mov [hBuffer], si
  172. else
  173. cmp fUserPro, PROWASPRIVATE
  174. jne SPP_SetIt
  175. endif
  176. les di,lpszProfile
  177. test fBooting,1
  178. jnz spr_booting
  179. smov es, ss
  180. lea di, NewFileBuf
  181. mov byte ptr es:[di.opFile], 0 ; Zap junk on stack
  182. mov ax,OF_EXIST ; OF_EXIST searches path!
  183. cCall OpenFile,<lpszProfile,es,di,ax>
  184. lea di, [di.opFile]
  185. spr_booting:
  186. lea si, [PrivateProBuf]
  187. xor cx, cx
  188. mov cl, [si.opLen]
  189. lea si, [si.opFile]
  190. sub cx, 8
  191. cld
  192. ifndef PHILISAWEENIE
  193. test fBooting, 1
  194. jz @F
  195. xor bl, bl ; Terminate on null
  196. call strcmpi
  197. je SPP_KeepBuffer
  198. jmps SPP_SetIt
  199. @@:
  200. endif
  201. rep cmpsb
  202. je SPP_KeepBuffer
  203. SPP_SetIt:
  204. mov si,[hBuffer]
  205. call FreeBuffer ; free up any buffer we may have
  206. SPP_KeepBuffer:
  207. mov fUserPro, PROPRIVATE
  208. mov ax, lpszProfile.off
  209. mov [lpszUserPro].off, ax
  210. mov ax, lpszProfile.sel
  211. mov [lpszUserPro].sel, ax
  212. cEnd
  213. ;-----------------------------------------------------------------------;
  214. ; ResetPrivatePro ;
  215. ; ;
  216. ; Sets lpszUserPro to point to nothing ;
  217. ; ;
  218. ; Arguments: ;
  219. ; ;
  220. ; Returns: ;
  221. ; ;
  222. ; Error Returns: ;
  223. ; ;
  224. ; Registers Preserved: ;
  225. ; ;
  226. ; Registers Destroyed: ;
  227. ; ;
  228. ; Calls: ;
  229. ; ;
  230. ; History: ;
  231. ; ;
  232. ;-----------------------------------------------------------------------;
  233. assumes ds,code
  234. assumes es,nothing
  235. cProc ResetPrivatePro,<PUBLIC,NEAR>
  236. cBegin nogen
  237. mov fUserPro, PROWASPRIVATE
  238. ret
  239. cEnd nogen
  240. ;-----------------------------------------------------------------------;
  241. ; GetProfileInt ;
  242. ; ;
  243. ; Gets the integer value for the keyword field. ;
  244. ; ;
  245. ; Arguments: ;
  246. ; parmD lpApplicationName ;
  247. ; parmD lpKeyName ;
  248. ; parmW nDefault ;
  249. ; ;
  250. ; Returns: ;
  251. ; AX = nKeyValue ;
  252. ; ;
  253. ; Error Returns: ;
  254. ; ;
  255. ; Registers Preserved: ;
  256. ; DI,SI,DS ;
  257. ; ;
  258. ; Registers Destroyed: ;
  259. ; BX,CX,DX,ES ;
  260. ; ;
  261. ; Calls: ;
  262. ; ;
  263. ; History: ;
  264. ; ;
  265. ; Sat Oct 10, 1987 04:32:04p -by- David N. Weise [davidw] ;
  266. ; Added this nifty comment block. ;
  267. ;-----------------------------------------------------------------------;
  268. assumes ds,nothing
  269. assumes es,nothing
  270. cProc GetProfileInt,<PUBLIC,FAR>,<si,di>
  271. parmD section
  272. parmD keyword
  273. parmW defint
  274. cBegin
  275. cCall MISCMapDStoDATA ; point at data segment
  276. ReSetKernelDS
  277. cCall SetDefaultPro
  278. cCall GetString, <section,keyword>
  279. ; DX:AX contains pointer to return string
  280. ; CX is the length of the string, -1 if none
  281. mov si,ax ; save pointer offset
  282. mov ax,defint ; if so, return default integer
  283. cmp cx,-1 ; was there no string?
  284. jz intdone ; if none, use default
  285. push ds ; save DS
  286. mov ds,dx ; DS:SI has string
  287. ; AtoI function, CX has count of characters, AX is result, DS:SI is string.
  288. xor ax,ax
  289. AtoI: mov dx,10
  290. mov bl,[si]
  291. sub bl,'0'
  292. jc AtoIDone
  293. cmp bl,10
  294. jnc AtoIDone
  295. inc si
  296. mul dx
  297. xor bh,bh
  298. add ax,bx
  299. loop AtoI
  300. AtoIdone:
  301. pop ds ; restore DS
  302. intdone:
  303. push ax
  304. call UnlockBuffer
  305. pop ax ; get result to return
  306. cEnd
  307. ;-----------------------------------------------------------------------;
  308. ; GetProfileString ;
  309. ; ;
  310. ; Returns the string for the keyword field. ;
  311. ; ;
  312. ; Arguments: ;
  313. ; parmD lpApplicationName ;
  314. ; parmD lpKeyName ;
  315. ; parmD lpDefault ;
  316. ; parmD lpReturnedString ;
  317. ; parmW nSize ;
  318. ; ;
  319. ; Returns: ;
  320. ; AX = nLength ;
  321. ; ;
  322. ; Error Returns: ;
  323. ; ;
  324. ; Registers Preserved: ;
  325. ; DI,SI,DS ;
  326. ; ;
  327. ; Registers Destroyed: ;
  328. ; BX,CX,DX,ES ;
  329. ; ;
  330. ; Calls: ;
  331. ; ;
  332. ; History: ;
  333. ; ;
  334. ; Sat Oct 10, 1987 04:45:20p -by- David N. Weise [davidw] ;
  335. ; Added this nifty comment block. ;
  336. ;-----------------------------------------------------------------------;
  337. assumes ds,nothing
  338. assumes es,nothing
  339. cProc GetProfileString,<PUBLIC,FAR>,<si,di>
  340. parmD section
  341. parmD keyword
  342. parmD defString
  343. parmD resString
  344. parmW cchMax
  345. cBegin
  346. cCall MISCMapDStoDATA ; point at data segment
  347. ReSetKernelDS
  348. cCall SetDefaultPro
  349. if KDEBUG
  350. mov dx, off_defString
  351. or dx, seg_defString ; Catch those NULL pointers
  352. jnz ok_def
  353. mkerror ERR_BADDEFAULT,<GetProfileString: NULL lpDefault>,dx,dx
  354. ok_def:
  355. endif
  356. mov ax,off_keyword
  357. mov dx,seg_keyword
  358. or ax,dx
  359. jnz GPS_Normal
  360. cCall GetKeys,<section,resString,cchMax>
  361. ; Carry if the section not found, AX has length of "string".
  362. jnc GPS_End
  363. jmps GPS_DefString
  364. GPS_Normal:
  365. cCall GetString,<section,keyword>
  366. ; DX:AX contains pointer to return string
  367. ; CX has length, -1 if string not found
  368. cmp cx,-1 ; see if there is any string
  369. jz GPS_DefString
  370. mov SEG_defstring,dx
  371. mov OFF_defstring,ax
  372. GPS_DefString:
  373. xor ax, ax ; bug fixed.
  374. cmp SEG_defstring, 0
  375. je GPS_End ; Save us from the GP fault
  376. les di,defString ; DI = front of string
  377. ifdef FE_SB ;Apr.26,1990 by AkiraK
  378. call strlen ; CX = strlen, di = end of string
  379. ;get last character behind terminater
  380. push si
  381. les si,defString ; SI = front of string
  382. gps_dbcs_l1:
  383. mov al,es:[si]
  384. call FarMyIsDBCSLeadByte
  385. cmc
  386. adc si,1
  387. cmp si,di
  388. jb gps_dbcs_l1
  389. pop si
  390. else
  391. call strlen ; CX = strlen, di = end of string
  392. mov al,es:[di-1] ; AL = last character of string
  393. endif
  394. les di,defString ; DI = front of string
  395. ; Strip off single and double quotes
  396. cmp cx,2 ; strlen < 2?
  397. jb strdone ; yes, skip
  398. mov ah,es:[di] ; AH = first character in the string
  399. cmp ah,al ; first char = last char?
  400. jnz strdone ; if no match, then no quotes
  401. cmp al,"'"
  402. jz strq
  403. cmp al,'"'
  404. jnz strdone
  405. strq: sub cx,2 ; string is really two smaller
  406. inc di ; and starts here
  407. strdone:
  408. ; CX now has length of return string, use it for copying.
  409. mov dx,cchMax
  410. dec dx
  411. cmp cx,dx
  412. jbe GPS1
  413. mov cx,dx
  414. GPS1:
  415. push ds ; save DS
  416. push es
  417. pop ds
  418. mov si,di ; ds:si has string
  419. push cx ; save length for return
  420. les di,ResString
  421. rep movsb ; copy string
  422. mov byte ptr es:[di], 0 ; null terminate
  423. pop ax
  424. pop ds ; restore DS
  425. GPS_End:
  426. push ax
  427. call UnlockBuffer
  428. pop ax ; get length of returned string
  429. cEnd
  430. cProc GetKeys,<PUBLIC,NEAR>,<si,di,ds>
  431. parmD section
  432. parmD resstr
  433. parmW cchMax
  434. cBegin
  435. xor di,di ; make sure buffer is ready
  436. call BufferInit
  437. ; DX:AX has buffer address, NULL if it didn't work.
  438. mov di,ax ; save offset
  439. or ax,dx ; see if no address
  440. ifdef FE_SB
  441. jnz skip1
  442. jmp GetKeysNone ; if no address, done
  443. skip1:
  444. else
  445. jz GetKeysNone ; if no address, done
  446. endif
  447. dec cchMax ; Leave room for terminating null byte
  448. mov es,dx
  449. cCall FindSection, <section>
  450. jc GetKeysNone
  451. lds si,resstr
  452. xor dx,dx
  453. GK3: ; Key name loop
  454. mov bx,di
  455. GK3a:
  456. mov al,es:[di]
  457. ifdef FE_SB ;Apr.26,1990 by AkiraK
  458. call FarMyIsDBCSLeadByte
  459. cmc ;if the char is lead byte of DBCS,
  460. adc di,1 ; then di += 2 else di += 1
  461. else
  462. inc di
  463. endif
  464. cmp al,'='
  465. je GK3c
  466. cmp al,LINEFEED ; Ignore lines without =
  467. je GK3
  468. cmp al,SECT_LEFT ; Done if it's a section header
  469. je GK4
  470. or al,al ; or null.
  471. jnz GK3a
  472. jmps GK4
  473. GK3c:
  474. mov di,bx
  475. GK3d:
  476. mov al,es:[di]
  477. inc di
  478. cmp al,'='
  479. jne GK3e
  480. xor al,al
  481. GK3e:
  482. mov [si],al
  483. inc dx
  484. inc si
  485. cmp dx,cchMax
  486. jb GK3f
  487. dec si
  488. dec dx
  489. GK3f:
  490. ifdef FE_SB ;Apr.26,1990 by AkiraK
  491. call FarMyIsDBCSLeadByte
  492. jc GK3_s1
  493. mov al,es:[di]
  494. inc di
  495. mov [si],al
  496. inc dx
  497. inc si
  498. cmp dx,cchMax
  499. jb GK3f2
  500. dec si
  501. dec dx
  502. GK3f2:
  503. GK3_s1:
  504. endif
  505. or al,al
  506. jnz GK3d
  507. ScanTo LINEFEED
  508. jmp GK3
  509. GetKeysNone:
  510. stc
  511. jmps GetKeysDone
  512. GK4:
  513. mov byte ptr [si], 0 ; Terminating null
  514. or dx, dx ; No extra zapping if nothing found
  515. jz GK4x
  516. ifdef FE_SB ;Apr.26,1990 by AkiraK
  517. push dx
  518. cCall AnsiPrev,<resstr,ds,si>
  519. mov si,ax
  520. mov byte ptr [si], 0
  521. mov byte ptr [si+1], 0
  522. pop dx
  523. else
  524. mov byte ptr [si-1], 0 ; [si-1] already zero unless we hit
  525. ; cchMax above in which case, we must
  526. ; zap the previous character.
  527. endif
  528. GK4x:
  529. mov ax,dx
  530. clc
  531. GetKeysDone:
  532. cEnd
  533. ; Scan through buffer, looking for section.
  534. cProc FindSection, <PUBLIC, NEAR>
  535. parmD section
  536. cBegin
  537. SS1:
  538. cmp byte ptr es:[di],SECT_LEFT ; see if it's a section header
  539. jne SS2
  540. inc di
  541. lds si,section
  542. mov bl,SECT_RIGHT
  543. call strcmpi ; case insensitive compare
  544. je SSfound ; terminate on SECT_RIGHT
  545. SS2:
  546. ScanTo LINEFEED
  547. cmp byte ptr es:[di], 0
  548. jne SS1
  549. ; If it gets here, there wasn't a match.
  550. stc ; Fail
  551. jmps SSdone
  552. SSfound:
  553. ScanTo LINEFEED ; read to beginning of first keyline
  554. clc ; Success
  555. SSdone:
  556. cEnd
  557. cProc FindKey, <PUBLIC, NEAR>
  558. parmD keyword
  559. cBegin
  560. mov ax, SEG_keyword
  561. or ax, OFF_keyword ; Do we have something to look for?
  562. jz FK_NoMatch
  563. FK_Next:
  564. mov al,es:[di]
  565. or al,al
  566. jz FK_NoMatch
  567. cmp al,SECT_LEFT
  568. jz FK_NoMatch
  569. lds si,keyword
  570. mov bl,'=' ; term on =.
  571. call strcmpi ; case insensitive compare, term on 0
  572. je FK_Found ; es:di has result string
  573. ScanTo LINEFEED
  574. jmp FK_Next
  575. FK_NoMatch:
  576. stc
  577. jmps FK_Done
  578. FK_Found:
  579. clc
  580. FK_Done:
  581. cEnd
  582. cProc GetString,<PUBLIC,NEAR>,<si,di,ds>
  583. parmD section
  584. parmD key
  585. cBegin
  586. xor di,di ; make sure buffer is ready
  587. call BufferInit
  588. ; DX:AX has buffer address, NULL if it didn't work.
  589. mov di,ax ; save offset
  590. or ax,dx ; see if no address
  591. jz NoMatch ; no address, nothing to match against
  592. mov es,dx
  593. ; DX:DI now has the buffer address, buffer is locked down.
  594. cCall FindSection, <section> ; Look for the section
  595. jc NoMatch
  596. cCall FindKey, <key>
  597. jnc HaveKey
  598. NoMatch:
  599. mov cx,-1 ; string was not found
  600. jmps GetStrDone
  601. ; if it gets here, it matched
  602. HaveKey:
  603. inc di ; pointing at =
  604. mov dx,es
  605. mov bx,di
  606. ScanTo CARRETURN ; traverse string until reach end
  607. inc cx
  608. inc cx
  609. neg cx ; will now contain string length
  610. mov ax,bx
  611. GetStrDone:
  612. cEnd
  613. ; make sure the buffer has been filled
  614. public BufferInit ; this is for the debugger
  615. BufferInit:
  616. assumes DS,CODE
  617. mov ax,[hBuffer]
  618. or ax,ax
  619. jnz bf0
  620. xor dx,dx
  621. ret
  622. bf0:
  623. call LockBuffer
  624. mov bx,ax
  625. or bx,dx
  626. jz bf1
  627. ret
  628. bf1:
  629. mov bx,GA_MODIFY ; make block not discardable
  630. cCall GlobalReAlloc,<hBuffer,ax,ax,bx>
  631. mov ax,di
  632. les dx, lpszUserPro
  633. cmp fUserPro, PROPRIVATE
  634. jne bf1a1
  635. mov bx,codeOffset PrivateProBuf ; Private ie not WIN.INI
  636. cCall OpenFile,<es,dx,dsbx,ax>
  637. cmp ax, -1 ; File not found?
  638. jne bf1a2
  639. or di, di
  640. jz bf1a2 ; Don't create if we want to read it.
  641. mov ax, di
  642. or ax, OF_CREATE ; Writing it, create it silently.
  643. les dx, lpszUserPro
  644. mov bx,codeOffset PrivateProBuf
  645. jmps bf1a
  646. bf1a1:
  647. or di,di
  648. jz bf1a0
  649. or ax,OF_CREATE
  650. bf1a0:
  651. mov bx,codeOffset UserProBuf
  652. cmp byte ptr [bx],0
  653. jz bf1a
  654. mov dx,dataOffset szUserPro
  655. and ax,NOT OF_CREATE
  656. or ax,OF_REOPEN or OF_PROMPT
  657. bf1a:
  658. cCall OpenFile,<es,dx,dsbx,ax>
  659. bf1a2:
  660. mov [hFile],ax
  661. inc ax
  662. jnz @F
  663. jmp bf3 ; if file not found, return 0:0
  664. @@: mov ax,0002h
  665. call Rewind2 ; seek to end of file
  666. add ax,3 ; tack on room for cr,lf and 0
  667. adc dx,0
  668. jz bf1aa ; ok if less than 64k
  669. mov ax, -1 ; Limit memory used
  670. xor dx, dx
  671. bf1aa:
  672. push ax ; Length to read
  673. mov bx,GA_ZEROINIT
  674. regptr LONGINT,DX,AX
  675. cCall GlobalReAlloc,<hBuffer,LONGINT,bx> ; global block
  676. pop bx ; Stand on our head to preserve length
  677. or ax,ax
  678. jz bf3
  679. mov hBuffer, ax
  680. push bx
  681. call LockBuffer
  682. call Rewind ; rewind to beginning of file
  683. les bx,[BufAddr]
  684. mov es:[bx],2020h ; space space
  685. pop cx ; read in the whole file
  686. sub cx, 3 ; don't fill extra space in the buffer
  687. jcxz bf1zz ; Don't bother if nothing to read
  688. cCall _lread,<hFile,esbx,cx>
  689. inc ax
  690. jz bf2
  691. dec ax
  692. mov cx,ax ; cx has file size
  693. bf1zz:
  694. cmp cx,2
  695. jae bf1z
  696. mov cx,2
  697. bf1z:
  698. jmps PackBuffer
  699. bf2: call UnlockBuffer
  700. FreeBuffer:
  701. xor ax,ax
  702. mov dx,GA_DISCARDABLE shl 8 OR GA_MODIFY
  703. cCall GlobalReAlloc,<si,ax,ax,dx>
  704. xor ax,ax
  705. mov dx,(GA_SHAREABLE) shl 8 OR GA_MOVEABLE
  706. cCall GlobalReAlloc,<si,ax,ax,dx>
  707. bf3: xor ax,ax
  708. xor dx,dx
  709. mov word ptr [BufAddr][0],ax
  710. mov word ptr [BufAddr][2],dx
  711. ret
  712. public packbuffer
  713. PackBuffer:
  714. push ds
  715. mov dx,di
  716. les di,[BufAddr]
  717. lds si,[BufAddr]
  718. pb1:
  719. ifdef FE_SB ;Apr.26,1990 by AkiraK
  720. ;TAB or SPACE are never found in lead byte of DBCS.
  721. ;so, this loop is safe in DBCS.
  722. endif
  723. jcxz pb9 ; while leading space or tab
  724. mov bx, di ; Initialize first valid character
  725. lodsb
  726. dec cx
  727. cmp al, SPACE ; remove leading spaces
  728. jz pb1
  729. cmp al, TAB ; and tabs
  730. jz pb1
  731. dec si ; refetch last character
  732. inc cx
  733. pb2:
  734. lodsb
  735. dec cx
  736. or dx,dx ; Are we writing?
  737. jnz pb20 ; Yes, leave comments in
  738. cmp al,';' ; No, is this a comment?
  739. jne pb20 ; No, continue
  740. jcxz pb9 ; if done
  741. pb2loop:
  742. ifdef FE_SB ;Apr.26,1990 by AkiraK
  743. ;LINEFEED is never found in lead byte of DBCS.
  744. ;so, this loop is safe in DBCS.
  745. endif
  746. lodsb
  747. dec cx
  748. jz pb9 ; if done
  749. cmp al, LINEFEED ; if end of line, go on
  750. jz pb1
  751. jmps pb2loop
  752. pb20:
  753. stosb ; first character of line
  754. ifdef FE_SB ;Apr.26,1990 by AkiraK
  755. call FarMyIsDBCSLeadByte
  756. jc pb_dbcs_s1
  757. movsb
  758. dec cx
  759. jz pb9
  760. pb_dbcs_s1:
  761. endif
  762. cmp al,'=' ; if '=', then end of left hand side
  763. jz pb2a
  764. jcxz pb9
  765. cmp al, SPACE ; if space, might be trailing space
  766. jz pb2
  767. cmp al, TAB
  768. jz pb2
  769. cmp al, LINEFEED ; if end of line, go on
  770. jz pb1
  771. mov bx,di ; ow save last valid character+1
  772. jmp pb2
  773. pb2a:
  774. mov di,bx ; remove trailing spaces on left
  775. stosb ; resave '='
  776. pb3: ; now work on right hand side
  777. jcxz pb9 ; while leading space or tab
  778. lodsb ; remove leading spaces
  779. dec cx
  780. cmp al, SPACE
  781. jz pb3 ; and tabs
  782. cmp al, TAB
  783. jz pb3
  784. dec si ; refetch last character
  785. inc cx
  786. pb5:
  787. ifdef FE_SB ;Apr.26,1990 by AkiraK
  788. ;LINEFEED is never found in lead byte of DBCS.
  789. ;so, this loop is safe in DBCS.
  790. endif
  791. lodsb
  792. stosb ; store character
  793. dec cx
  794. jz pb9
  795. cmp al, LINEFEED ; at end of line?
  796. jz pb1 ; yes, go on
  797. jmp pb5
  798. pb9:
  799. or di, di
  800. jz pb9a ; NOTHING THERE!!
  801. dec di ; remove trailing ^Z's
  802. cmp byte ptr es:[di],"Z"-"@"
  803. jz pb9
  804. inc di
  805. pb9a:
  806. mov ax,CRLF
  807. stosw ; make sure there is a final
  808. xor ax,ax ; CARRETURN and NULL
  809. stosb
  810. pop ds ; restore DS
  811. mov si,[hBuffer]
  812. cCall GlobalUnlock,<si>
  813. xor ax,ax
  814. regptr xsize,ax,di
  815. cCall GlobalReAlloc,<si,xsize,ax>
  816. public lockbuffer
  817. LockBuffer:
  818. mov si,ax
  819. cCall GlobalLock,<ax>
  820. mov word ptr BufAddr[0],ax
  821. mov word ptr BufAddr[2],dx
  822. ret
  823. public unlockbuffer
  824. UnlockBuffer:
  825. mov si,hBuffer
  826. cCall GlobalUnlock,<si>
  827. xor ax,ax
  828. mov dx,(GA_MODIFY + (GA_DISCARDABLE SHL 8)) ; make block discardable
  829. cCall GlobalReAlloc,<si,ax,ax,dx>
  830. mov bx,-1
  831. xchg bx,[hFile]
  832. inc bx
  833. jz ulbdone
  834. dec bx
  835. cCall _lclose,<bx> ; close file
  836. ulbdone:
  837. ret
  838. Rewind:
  839. xor ax,ax ; rewind the tape
  840. Rewind2:
  841. xor cx,cx
  842. cCall _llseek,<hFile,cx,cx,ax>
  843. ret
  844. ; this proc calculates the length of the string pointed to by es:di
  845. ; and returns it in cx. It searches for a CR and then backs thru any
  846. ; trailing spaces.
  847. ; it uses cx, es, and di
  848. public strlen
  849. strlen PROC NEAR
  850. ifdef FE_SB ;Apr.26,1990 by AkiraK
  851. ; Space, Carridge Return, NULL are never in lead byte of DBCS.
  852. ; So, we don't need to enable here.
  853. endif
  854. push ax ; Save ax
  855. mov cx,di ; cx = start of string
  856. dec di
  857. str1: inc di ; Search for CR or NULL
  858. mov al,es:[di] ; AL has CR or NULL
  859. cmp al,CARRETURN
  860. ja str1
  861. str2: dec di ; Remove trailing blanks
  862. cmp di,cx ; Check for start of string
  863. jb str3
  864. cmp byte ptr es:[di],SPACE
  865. jz str2
  866. str3: inc di ; Restore CR or NULL
  867. cmp es:[di],al
  868. jz maybe_in_code
  869. mov es:[di],al
  870. maybe_in_code:
  871. neg cx
  872. add cx,di
  873. pop ax ; Restore ax
  874. ret
  875. strlen ENDP
  876. public strcmpi
  877. strcmpi PROC NEAR
  878. ; es:di and ds:si have strings
  879. ; es:di should be terminated by the char in bl
  880. ; ds:si is null terminated
  881. ifdef FE_SB ;Apr.26,1990 by AkiraK
  882. sti_l1:
  883. mov al,es:[di]
  884. cmp al,bl
  885. jz sti_s1
  886. call FarMyLower
  887. mov cl,al
  888. mov al,ds:[si]
  889. call FarMyLower
  890. inc si
  891. inc di
  892. cmp al,cl
  893. jnz sti_exit
  894. call FarMyIsDBCSLeadByte
  895. jc sti_l1
  896. mov al,es:[di]
  897. cmp al,ds:[si]
  898. jnz sti_exit
  899. inc si
  900. inc di
  901. jmp short sti_l1
  902. sti_exit:
  903. ret
  904. sti_s1:
  905. mov al,ds:[si]
  906. or al,al
  907. ret
  908. else
  909. stci10:
  910. mov al,es:[di]
  911. cmp al,bl ; At the end?
  912. jnz stci15 ; yes, get out of here.
  913. mov al,[si] ; are we at the end of the string
  914. or al,al
  915. jmps stciex
  916. stci15:
  917. call FarMyLower
  918. stci30:
  919. mov cl,[si]
  920. xchg al,cl
  921. call FarMyLower
  922. xchg cl,al
  923. stci40:
  924. inc si
  925. inc di
  926. cmp al,cl ; Still matching chars?
  927. jz stci10 ; Yes, go try the next char.
  928. stciex:
  929. ret
  930. endif
  931. strcmpi ENDP
  932. ;-----------------------------------------------------------------------;
  933. ; WriteProfileString ;
  934. ; ;
  935. ; Copies the given character string to WIN.INI. ;
  936. ; ;
  937. ; Arguments: ;
  938. ; parmD lpApplicationName ;
  939. ; parmD lpKeyName ;
  940. ; parmD lpString ;
  941. ; ;
  942. ; Returns: ;
  943. ; AX = bResult ;
  944. ; ;
  945. ; Error Returns: ;
  946. ; ;
  947. ; Registers Preserved: ;
  948. ; DI,SI,DS ;
  949. ; ;
  950. ; Registers Destroyed: ;
  951. ; BX,CX,DX,ES ;
  952. ; ;
  953. ; Calls: ;
  954. ; ;
  955. ; History: ;
  956. ; ;
  957. ; Sat Oct 10, 1987 05:12:51p -by- David N. Weise [davidw] ;
  958. ; Added this nifty comment block. ;
  959. ;-----------------------------------------------------------------------;
  960. assumes ds,nothing
  961. assumes es,nothing
  962. cProc WriteProfileString,<PUBLIC,FAR>,<si,di,ds>
  963. parmD section
  964. parmD keyword
  965. parmD result
  966. localD ptrTmp
  967. localW WhatIsMissing
  968. localW nBytes
  969. localW fh
  970. cBegin
  971. cCall MISCMapDStoDATA ; point at data segment
  972. ReSetKernelDS
  973. cCall SetDefaultPro
  974. ;make sure buffer is ready
  975. mov si,[hBuffer]
  976. call FreeBuffer ; free up any buffer we may have
  977. cmp ax,SEG_section
  978. jne WPS0
  979. cmp ax,SEG_keyword
  980. jne WPS0
  981. cmp ax,SEG_result
  982. jne WPS0
  983. jmp WriteDone
  984. WPS0:
  985. mov di,2 ; write
  986. call BufferInit ; read in a fresh copy
  987. ; DX:AX has buffer address, NULL if it didn't work
  988. mov di,ax
  989. or ax,dx
  990. jnz WPS1
  991. jmp WriteDone
  992. WPS1: push dx ; save buffer selector
  993. cCall GlobalSize, <hBuffer> ; how big is he?
  994. or dx, dx ; more than 64k, icky
  995. jnz WPS_TooBig
  996. cmp ax, 0FF00h ; more than 64K-256, icky
  997. jb WPS_SmallEnough
  998. WPS_TooBig:
  999. pop ax ; throw away saved buffer selector
  1000. xor ax, ax ; return FALSE if file too big
  1001. jmp WriteDone
  1002. WPS_SmallEnough:
  1003. pop es ; selector of buffer popped into es
  1004. push ds
  1005. call Rewind
  1006. ; ES:DI now has the buffer address, buffer is locked down
  1007. ; scan through buffer, looking for section
  1008. cCall FindSection, <section>
  1009. jc WPS5
  1010. mov ax, SEG_keyword
  1011. or ax, OFF_keyword
  1012. jnz WPS2
  1013. mov WhatIsMissing, REMOVESECTION
  1014. ScanBack SECT_LEFT
  1015. jmps WPS9
  1016. WPS2:
  1017. cCall FindKey, <keyword>
  1018. jnc WPS7
  1019. ; if it gets here, there wasn't a match
  1020. mov WhatIsMissing,NOKEY
  1021. jmps WPS8
  1022. ; if it gets here, there wasn't a match
  1023. WPS5:
  1024. mov WhatIsMissing,NOSECTION
  1025. jmps WPS8
  1026. WPS7:
  1027. inc di ; di now points to result
  1028. mov WhatIsMissing,NEWRESULT
  1029. mov ax, SEG_result
  1030. or ax, OFF_result
  1031. jnz WPS9 ; NEWRESULT
  1032. ScanBack LINEFEED
  1033. inc di ; Now points to the keyword
  1034. jmps WPS9
  1035. WPS8:
  1036. cmp WhatIsMissing,NEWRESULT
  1037. jz WPS9
  1038. WPS14: ; get rid of extra CRLF
  1039. or di, di
  1040. jz WPS9
  1041. dec di
  1042. mov al,es:[di]
  1043. cmp al,CARRETURN
  1044. jz WPS14
  1045. cmp al,LINEFEED
  1046. jz WPS14
  1047. add di,3
  1048. WPS9:
  1049. ; write out up to here in file
  1050. pop ds
  1051. push ds
  1052. mov bx,[hFile]
  1053. cmp bx,-1
  1054. jnz WPS10
  1055. lds dx,lpszUserPro ; create win.ini
  1056. xor cx,cx ; no special attributes
  1057. cCall _lcreat,<ds,dx,cx> ; create the file
  1058. pop ds
  1059. push ds
  1060. mov [hFile],ax
  1061. mov bx,ax ; bx has file handle
  1062. inc ax
  1063. jz WPSError ; -1 means didn't work
  1064. xor dx,dx
  1065. cCall _lwrite,<bx,dsdx,dx> ; Zero length write to reset file
  1066. or ax,ax
  1067. jz WPS10 ; size on a network file (3.0 bug)
  1068. WPSError:
  1069. pop ds
  1070. call UnlockBuffer
  1071. xor ax,ax
  1072. jmp WriteDone
  1073. WPS10:
  1074. mov bx,[hFile]
  1075. mov fh,bx ; save file handle in local variable
  1076. xor cx,cx
  1077. mov nBytes,cx
  1078. ; write file
  1079. mov off_ptrTmp,di
  1080. mov seg_ptrTmp,es
  1081. mov cx,di ; cx has file size
  1082. push es
  1083. pop ds
  1084. xor dx,dx
  1085. call WriteCheck ; write and check the write
  1086. cmp WhatIsMissing,NOSECTION
  1087. jnz WPS11
  1088. mov ax, SEG_keyword ; Wanted to delete it?
  1089. or ax, OFF_keyword
  1090. jnz WPS10a
  1091. jmp WPS13 ; Yes, don't do anything
  1092. WPS10a:
  1093. pop ds
  1094. push ds
  1095. mov dx,codeOffset CarRetLF
  1096. mov cx,2
  1097. call WriteCheck
  1098. mov dx,codeOffset LeftSect
  1099. mov cx,1
  1100. call WriteCheck
  1101. les di,section
  1102. call strlen
  1103. lds dx,section
  1104. call WriteCheck
  1105. pop ds
  1106. push ds
  1107. mov dx,codeOffset RightSect
  1108. mov cx,3
  1109. call WriteCheck
  1110. WPS11:
  1111. cmp WHatIsMissing, REMOVESECTION
  1112. jne WPS11a
  1113. WPS11b:
  1114. ScanTo LINEFEED ; Skip Current Line
  1115. WPS11c:
  1116. mov al, es:[di]
  1117. or al, al
  1118. jz WPS13
  1119. cmp al, SECT_LEFT
  1120. je WPS13
  1121. cmp al, ';'
  1122. jne WPS11b ; Skip this line
  1123. ; Preserve Comment lines
  1124. smov ds, es ; Write from ds:dx
  1125. mov dx, di
  1126. ScanTo LINEFEED
  1127. mov cx, di
  1128. sub cx, dx
  1129. call WriteCheck
  1130. jmps WPS11c
  1131. WPS11a:
  1132. cmp WhatIsMissing,NEWRESULT
  1133. jz WPS15
  1134. ; WhatIsMissing == NOKEY
  1135. mov ax, SEG_result ; Delete keyword?
  1136. or ax, OFF_result
  1137. jz WPS13 ; Yes, do nothing since not there!
  1138. les di,keyword
  1139. call strlen
  1140. lds dx,keyword
  1141. call WriteCheck
  1142. pop ds
  1143. push ds
  1144. mov dx,codeOffset EquStr
  1145. mov cx,1
  1146. call WriteCheck
  1147. jmps WPS15a ; and write out result
  1148. WPS15: ; Found keyword, have new result
  1149. mov ax, SEG_result
  1150. or ax, OFF_result ; Have result to set?
  1151. jnz WPS15a
  1152. ScanTo LINEFEED ; No result, delete line
  1153. jmps WPS13
  1154. WPS15a:
  1155. les di,result
  1156. call strlen
  1157. lds dx,result
  1158. call WriteCheck
  1159. pop ds
  1160. push ds
  1161. mov dx,codeOffset CarRetLF
  1162. mov cx,2
  1163. call WriteCheck
  1164. WPS12:
  1165. les di,ptrTmp
  1166. cmp WhatIsMissing,NEWRESULT
  1167. jnz WPS13
  1168. ; get rid of old result
  1169. ScanTo LINEFEED
  1170. WPS13:
  1171. mov dx,di
  1172. xor al,al
  1173. mov cx,-1
  1174. repne scasb
  1175. sub di,3 ; one past end, plus extra CRLF
  1176. sub di,dx
  1177. if 1
  1178. jbe WPS23 ; if di points before dx blow it off
  1179. endif
  1180. mov cx,di
  1181. if 0
  1182. or cx,cx ; if <= 0 then nothing to write
  1183. jle WPS23
  1184. endif
  1185. mov si,dx
  1186. mov dx,cx ; We are growing the file. Seek
  1187. add dx,nBytes
  1188. xor cx,cx ; to new EOF and set file size
  1189. cCall _llseek,<fh,cx,dx,cx>
  1190. ; with zero length write (DOS 2.X
  1191. ; BIOS bug with writes past current
  1192. xor cx,cx ; EOF with DTA near end of memory)
  1193. call WriteCheck
  1194. mov dx,nBytes ; Now backup to write rest of file
  1195. xor cx,cx
  1196. cCall _llseek,<fh,cx,dx,cx>
  1197. push es
  1198. pop ds
  1199. mov cx,di
  1200. mov dx,si
  1201. call WriteCheck
  1202. WPS23:
  1203. xor cx,cx
  1204. call WriteCheck
  1205. pop ds
  1206. call UnlockBuffer
  1207. call FreeBuffer
  1208. mov ax,1
  1209. WriteDone:
  1210. cEnd
  1211. public WriteCheck
  1212. WriteCheck:
  1213. cCall _lwrite,<fh,dsdx,cx>
  1214. mov cx,ax
  1215. inc ax
  1216. jz WC1
  1217. dec ax
  1218. add [nBytes],cx
  1219. ret
  1220. WC1:
  1221. pop ax ; return address
  1222. jmp WPSError
  1223. ;-----------------------------------------------------------------------;
  1224. ; GetPrivateProfileInt ;
  1225. ; ;
  1226. ; Gets the integer value for the keyword field from a private file ;
  1227. ; ;
  1228. ; Arguments: ;
  1229. ; parmD lpApplicationName ;
  1230. ; parmD lpKeyName ;
  1231. ; parmW nDefault ;
  1232. ; parmD lpFile ;
  1233. ; ;
  1234. ; Returns: ;
  1235. ; AX = nKeyValue ;
  1236. ; ;
  1237. ; Error Returns: ;
  1238. ; ;
  1239. ; Registers Preserved: ;
  1240. ; DI,SI,DS ;
  1241. ; ;
  1242. ; Registers Destroyed: ;
  1243. ; BX,CX,DX,ES ;
  1244. ; ;
  1245. ; Calls: ;
  1246. ; ;
  1247. ; History: ;
  1248. ; ;
  1249. ; Sat Oct 10, 1987 04:32:04p -by- David N. Weise [davidw] ;
  1250. ; Added this nifty comment block. ;
  1251. ;-----------------------------------------------------------------------;
  1252. assumes ds,nothing
  1253. assumes es,nothing
  1254. cProc GetPrivateProfileInt,<PUBLIC,FAR>,<si>
  1255. parmD Section
  1256. parmD keyword
  1257. parmW defint
  1258. parmD lpFile
  1259. localV Buffer,80h
  1260. cBegin
  1261. cCall MISCMapDStoDATA ; Safety
  1262. lea si,Buffer
  1263. cCall ForcePrivatePro,<ss,si,lpFile>
  1264. cCall SetPrivatePro,<ss,si>
  1265. cCall GetProfileInt,<section, keyword, defint>
  1266. cCall ResetPrivatePro
  1267. cEnd
  1268. ;-----------------------------------------------------------------------;
  1269. ; GetPrivateProfileString ;
  1270. ; ;
  1271. ; Returns the string for the keyword field from a private file ;
  1272. ; ;
  1273. ; Arguments: ;
  1274. ; parmD lpApplicationName ;
  1275. ; parmD lpKeyName ;
  1276. ; parmD lpDefault ;
  1277. ; parmD lpReturnedString ;
  1278. ; parmW nSize ;
  1279. ; parmD lpFile ;
  1280. ; ;
  1281. ; Returns: ;
  1282. ; AX = nLength ;
  1283. ; ;
  1284. ; Error Returns: ;
  1285. ; ;
  1286. ; Registers Preserved: ;
  1287. ; DI,SI,DS ;
  1288. ; ;
  1289. ; Registers Destroyed: ;
  1290. ; BX,CX,DX,ES ;
  1291. ; ;
  1292. ; Calls: ;
  1293. ; ;
  1294. ; History: ;
  1295. ; ;
  1296. ; Sat Oct 10, 1987 04:45:20p -by- David N. Weise [davidw] ;
  1297. ; Added this nifty comment block. ;
  1298. ;-----------------------------------------------------------------------;
  1299. assumes ds,nothing
  1300. assumes es,nothing
  1301. cProc GetPrivateProfileString,<PUBLIC,FAR>,<si>
  1302. parmD section
  1303. parmD keyword
  1304. parmD defString
  1305. parmD resString
  1306. parmW cchMax
  1307. parmD lpFile
  1308. localV Buffer,80h
  1309. cBegin
  1310. cCall MISCMapDStoDATA ; Safety
  1311. lea si,Buffer
  1312. cCall ForcePrivatePro,<ss,si,lpFile>
  1313. cCall SetPrivatePro,<ss,si>
  1314. cCall GetProfileString,<section,keyword,defString,resString,cchMax>
  1315. cCall ResetPrivatePro
  1316. cEnd
  1317. ;-----------------------------------------------------------------------;
  1318. ; WritePrivateProfileString ;
  1319. ; ;
  1320. ; Copies the given character string to a private file ;
  1321. ; ;
  1322. ; Arguments: ;
  1323. ; parmD lpApplicationName ;
  1324. ; parmD lpKeyName ;
  1325. ; parmD lpString ;
  1326. ; parmD lpFile ;
  1327. ; ;
  1328. ; Returns: ;
  1329. ; AX = bResult ;
  1330. ; ;
  1331. ; Error Returns: ;
  1332. ; ;
  1333. ; Registers Preserved: ;
  1334. ; DI,SI,DS ;
  1335. ; ;
  1336. ; Registers Destroyed: ;
  1337. ; BX,CX,DX,ES ;
  1338. ; ;
  1339. ; Calls: ;
  1340. ; ;
  1341. ; History: ;
  1342. ; ;
  1343. ; Sat Oct 10, 1987 05:12:51p -by- David N. Weise [davidw] ;
  1344. ; Added this nifty comment block. ;
  1345. ;-----------------------------------------------------------------------;
  1346. assumes ds,nothing
  1347. assumes es,nothing
  1348. cProc WritePrivateProfileString,<PUBLIC,FAR>,<si>
  1349. parmD section
  1350. parmD keyword
  1351. parmD result
  1352. parmD lpFile
  1353. localV Buffer,80h
  1354. cBegin
  1355. cCall MISCMapDStoDATA ; Safety
  1356. lea si,Buffer
  1357. cCall ForcePrivatePro,<ss,si,lpFile>
  1358. cCall SetPrivatePro,<ss,si>
  1359. cCall WriteProfileString,<section, keyword, result>
  1360. cCall ResetPrivatePro
  1361. cEnd
  1362. ;-----------------------------------------------------------------------;
  1363. ; ForcePrivatePro
  1364. ;
  1365. ; If the file pointed to is not qualified then we force
  1366. ; the file into the Windows directory.
  1367. ;
  1368. ; Entry:
  1369. ; BX = buffer on stack
  1370. ;
  1371. ; Returns:
  1372. ;
  1373. ; Registers Destroyed:
  1374. ;
  1375. ; History:
  1376. ; Tue 14-Nov-1989 20:30:48 -by- David N. Weise [davidw]
  1377. ; Wrote it!
  1378. ;-----------------------------------------------------------------------;
  1379. assumes ds,nothing
  1380. assumes es,nothing
  1381. cProc ForcePrivatePro,<PUBLIC,NEAR>,<di,si,ds>
  1382. parmD lpDest
  1383. parmD lpSource
  1384. cBegin
  1385. ifdef FE_SB ;Apr.26,1990 by AkiraK
  1386. cld
  1387. xor ax,ax
  1388. mov bx,'/' shl 8 + '\'
  1389. xor dx,dx
  1390. lds si,lpSource ; first get length of string
  1391. mov cx,si
  1392. mov al,ds:[si]
  1393. call FarMyIsDBCSLeadByte
  1394. jnc fpp_s1
  1395. cmp byte ptr ds:[si].1,':' ; is it qualified with a drive?
  1396. jnz fpp_s1
  1397. inc dx
  1398. fpp_s1:
  1399. fpp_l1:
  1400. lodsb
  1401. or al,al
  1402. jz fpp_got_length
  1403. cmp al,bh
  1404. jz fpp_qualified
  1405. cmp al,bl
  1406. jz fpp_qualified
  1407. fpp_s2:
  1408. call FarMyIsDBCSLeadByte
  1409. jc fpp_l1
  1410. inc si
  1411. jmp fpp_l1
  1412. fpp_qualified:
  1413. inc dx
  1414. jmp fpp_s2
  1415. else
  1416. cld
  1417. xor ax,ax
  1418. mov bx,'/' shl 8 + '\'
  1419. xor dx,dx
  1420. lds si,lpSource ; first get length of string
  1421. mov cx,si
  1422. cmp byte ptr ds:[si].1,':' ; is it qualified with a drive?
  1423. jnz @F
  1424. inc dx
  1425. @@: lodsb
  1426. or al,al
  1427. jz fpp_got_length
  1428. cmp al,bh
  1429. jz fpp_qualified
  1430. cmp al,bl
  1431. jnz @B
  1432. fpp_qualified:
  1433. inc dx
  1434. jmp @B
  1435. endif
  1436. fpp_got_length:
  1437. sub si,cx
  1438. xchg si,cx
  1439. les di,lpDest
  1440. or dx,dx
  1441. jnz fpp_copy_name
  1442. push cx
  1443. cCall MISCMapDStoDATA
  1444. ResetKernelDS
  1445. mov cx,cBytesWinDir
  1446. lds si,lpWindowsDir
  1447. rep movsb
  1448. mov al,'\'
  1449. stosb
  1450. pop cx
  1451. lds si,lpSource
  1452. fpp_copy_name:
  1453. rep movsb
  1454. cEnd
  1455. endif
  1456. ; ndef WOW
  1457. ;-----------------------------------------------------------------------;
  1458. ; GetWindowsDirectory
  1459. ;
  1460. ;
  1461. ; Entry:
  1462. ; parmD lpBuffer pointer to buffer
  1463. ; parmW cbBuffer size of buffer
  1464. ;
  1465. ; Returns:
  1466. ; AX = size of string copied
  1467. ;
  1468. ; Registers Destroyed:
  1469. ;
  1470. ; History:
  1471. ; Sun 24-Sep-1989 16:18:46 -by- David N. Weise [davidw]
  1472. ; Wrote it!
  1473. ;-----------------------------------------------------------------------;
  1474. assumes ds,nothing
  1475. assumes es,nothing
  1476. cProc IGetWindowsDirectory,<PUBLIC,FAR>,<di,si>
  1477. parmD lpBuf
  1478. parmW cbBuffer
  1479. cBegin
  1480. cCall MISCMapDStoDATA ; point at data segment
  1481. ResetKernelDS
  1482. if 1 ;HYDRA
  1483. ; Get the current windows directory, since it depends on the state of ini-file
  1484. ; mapping (assumes lpWindowsDir already points to achCtxWindowsDir - ldboot.asm).
  1485. mov si, offset achTermsrvWindowsDir
  1486. cCall TermsrvGetWindowsDir,<ds, si, MaxFileLen>
  1487. or ax, ax ; ax != 0 -> success
  1488. jz short gwd_exit
  1489. push es
  1490. smov es,ds
  1491. mov di, si ; es:di points to windows path
  1492. mov cx,-1
  1493. xor ax,ax
  1494. repnz scasb
  1495. not cx
  1496. dec cx
  1497. mov cBytesWinDir, cx
  1498. pop es
  1499. else ; HYDRA
  1500. mov cx,cBytesWinDir
  1501. lds si,lpWindowsDir
  1502. endif
  1503. inc cx ; Room for NULL
  1504. mov ax, cx
  1505. cmp cx, 3 ; Just 3 bytes implies <drive>:
  1506. jne gwd_notroot
  1507. ifdef FE_SB ;Apr.26,1990 by AkiraK
  1508. mov al,ds:[si+0] ;Make sure the 1st byte is not
  1509. call FarMyIsDBCSLeadByte ; DBCS lead byte.
  1510. jnc gwd_notroot
  1511. endif
  1512. cmp byte ptr ds:[si+1], ':' ; Make sure
  1513. jne gwd_notroot
  1514. inc ax ; Allow for \
  1515. gwd_notroot:
  1516. cmp ax,cbBuffer ; is there enough room in buffer?
  1517. ja gwd_exit
  1518. dec cx ; don't copy null
  1519. les di,lpBuf
  1520. cld
  1521. ifdef WOW
  1522. ;; For WOW we might be running on a file system that supports lower case
  1523. ;; however some apps can't cope with lowercase names so we uppercase it here
  1524. push ax
  1525. gwd_loop:
  1526. lodsb
  1527. ;; LATER
  1528. ;; call FarMyUpper ; Convert char to UpperCase
  1529. stosb
  1530. ifdef FE_SB
  1531. ;; call MyIsDBCSLeadByte
  1532. ;; jc gwd_loop ; copy second byte in east
  1533. ;; movsb
  1534. endif
  1535. loop gwd_loop
  1536. pop ax
  1537. else ; WOW
  1538. rep movsb
  1539. endif; WOW
  1540. mov es:[di],cl
  1541. dec ax
  1542. cmp ax, 3
  1543. jne gwd_exit
  1544. mov di, word ptr lpBuf ; Get pointer to dest again
  1545. ifdef FE_SB ;Apr.26,1990 by AkiraK
  1546. mov al,ds:[di+0] ;Make sure the 1st byte is not
  1547. call FarMyIsDBCSLeadByte ; DBCS lead byte.
  1548. jnc gwd_exit
  1549. endif
  1550. cmp byte ptr es:[di+1], ':'
  1551. jne gwd_exit
  1552. mov byte ptr es:[di+2], '\'
  1553. mov byte ptr es:[di+3], cl
  1554. gwd_exit:
  1555. cEnd
  1556. ;-----------------------------------------------------------------------;
  1557. ; GetSystemDirectory
  1558. ;
  1559. ; Entry:
  1560. ; parmD lpBuf pointer to buffer
  1561. ; parmW cbBuffer size of buffer
  1562. ;
  1563. ; Returns:
  1564. ; AX = size of string copied
  1565. ;
  1566. ; Registers Destroyed:
  1567. ;
  1568. ; History:
  1569. ; Sun 24-Sep-1989 16:18:46 -by- David N. Weise [davidw]
  1570. ;
  1571. ;-----------------------------------------------------------------------;
  1572. assumes ds,nothing
  1573. assumes es,nothing
  1574. cProc IGetSystemDirectory,<PUBLIC,FAR>,<di,si>
  1575. parmD lpBuf
  1576. parmW cbBuffer
  1577. cBegin
  1578. cCall MISCMapDStoDATA ; point at data segment
  1579. ResetKernelDS
  1580. ifndef WOW
  1581. mov cx,cBytesSysDir
  1582. lds si,lpSystemDir
  1583. else
  1584. mov cx,cBytesSys16Dir
  1585. lds si,lpSystem16Dir
  1586. endif
  1587. inc cx ; Room for NULL
  1588. mov ax, cx
  1589. cmp cx, 3 ; Just 3 bytes implies <drive>:
  1590. jne gsd_notroot
  1591. ifdef FE_SB ;Apr.26,1990 by AkiraK
  1592. mov al,ds:[si+0] ;Make sure the 1st byte is not
  1593. call FarMyIsDBCSLeadByte ; DBCS lead byte.
  1594. jnc gsd_notroot
  1595. endif
  1596. cmp byte ptr ds:[si+1], ':' ; Make sure
  1597. jne gsd_notroot
  1598. inc ax ; Allow for \
  1599. gsd_notroot:
  1600. cmp ax,cbBuffer ; is there enough room in buffer?
  1601. ja gsd_exit
  1602. dec cx ; don't copy null
  1603. les di,lpBuf
  1604. cld
  1605. ifdef WOW
  1606. ;; For WOW we might be running on a file system that supports lower case
  1607. ;; however some apps can't cope with lowercase names so we uppercase it here
  1608. push ax
  1609. gsd_loop:
  1610. lodsb
  1611. call FarMyUpper ; Convert char to UpperCase
  1612. stosb
  1613. ifdef FE_SB
  1614. ;; call MyIsDBCSLeadByte
  1615. ;; jc gsd_loop ; copy second byte in east
  1616. ;; movsb
  1617. endif
  1618. loop gsd_loop
  1619. pop ax
  1620. else ; WOW
  1621. rep movsb
  1622. endif; WOW
  1623. mov es:[di],cl
  1624. dec ax ; return number of bytes in string
  1625. cmp ax, 3
  1626. jne gsd_exit
  1627. mov di, word ptr lpBuf ; Get pointer to dest again
  1628. ifdef FE_SB ;Apr.26,1990 by AkiraK
  1629. mov al,ds:[di+0] ;Make sure the 1st byte is not
  1630. call FarMyIsDBCSLeadByte ; DBCS lead byte.
  1631. jnc gsd_exit
  1632. endif
  1633. cmp byte ptr es:[di+1], ':'
  1634. jne gsd_exit
  1635. mov byte ptr es:[di+2], '\'
  1636. mov byte ptr es:[di+3], cl
  1637. gsd_exit:
  1638. cEnd
  1639. ;-----------------------------------------------------------------------;
  1640. ; GetProfileSectionNames
  1641. ;
  1642. ; Entry:
  1643. ; parmD lpBuf pointer to buffer for section names
  1644. ; parmW cbBuffer size of buffer
  1645. ;
  1646. ; Returns:
  1647. ;
  1648. ; Registers Destroyed:
  1649. ;
  1650. ; History:
  1651. ;
  1652. ;-----------------------------------------------------------------------;
  1653. assumes ds,nothing
  1654. assumes es,nothing
  1655. cProc GetProfileSectionNames,<PUBLIC,FAR>,<di,si>
  1656. parmD lpBuf
  1657. parmW cbBuffer
  1658. cBegin
  1659. cCall MISCMapDStoDATA ; point at data segment
  1660. ResetKernelDS
  1661. mov si, dataoffset szUserPro
  1662. regptr xWinDotIni,ds,si
  1663. cCall GetPrivateProfileSectionNames, <lpBuf, cbBuffer, xWinDotIni>
  1664. cEnd
  1665. sEnd MISCCODE
  1666. ifndef WOW
  1667. sBegin INITCODE
  1668. assumes cs, CODE
  1669. assumes ds, nothing
  1670. assumes es, nothing
  1671. szWININI db 'WININI='
  1672. lenWININI equ $-codeoffset szWININI
  1673. ;-----------------------------------------------------------------------;
  1674. ; SetUserPro ;
  1675. ; ;
  1676. ; Set szUserPro to the string given in the environment variable WININI ;
  1677. ; The default is WIN.INI ;
  1678. ; ;
  1679. ; Arguments: ;
  1680. ; ;
  1681. ; Returns: ;
  1682. ; ;
  1683. ; Error Returns: ;
  1684. ; ;
  1685. ; Registers Preserved: ;
  1686. ; ;
  1687. ; Registers Destroyed: ;
  1688. ; ;
  1689. ; Calls: ;
  1690. ; ;
  1691. ; History: ;
  1692. ; ;
  1693. ;-----------------------------------------------------------------------;
  1694. cProc SetUserPro,<PUBLIC,NEAR>,<ax,cx,si,di,ds,es>
  1695. cBegin
  1696. SetKernelDS es
  1697. mov ds, TopPDB
  1698. mov ds, ds:[PDB_environ]
  1699. cld
  1700. xor si, si
  1701. smov es,cs
  1702. assumes es,CODE
  1703. FindWinIni:
  1704. cmp byte ptr ds:[si], 0
  1705. je EndEnv
  1706. mov di, codeoffset szWININI
  1707. mov cx, lenWININI
  1708. rep cmpsb
  1709. je FoundEntry
  1710. dec si
  1711. SkipEntry:
  1712. lodsb
  1713. or al, al
  1714. jnz SkipEntry
  1715. jmps FindWinIni
  1716. FoundEntry:
  1717. SetKernelDS es
  1718. mov di, dataoffset szUserPro
  1719. CopyEntry:
  1720. lodsb
  1721. stosb
  1722. or al, al
  1723. jnz CopyEntry
  1724. EndEnv:
  1725. assumes es, nothing
  1726. cEnd
  1727. sEnd INITCODE
  1728. endif
  1729. ; ndef WOW
  1730. end