Subversion Repositories Kolibri OS

Rev

Rev 989 | Rev 1048 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;================================================================================================;;
  2. ;;//// libini.asm //// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////;;
  3. ;;================================================================================================;;
  4. ;;                                                                                                ;;
  5. ;; This file is part of Common development libraries (Libs-Dev).                                  ;;
  6. ;;                                                                                                ;;
  7. ;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
  8. ;; General Public License as published by the Free Software Foundation, either version 3 of the   ;;
  9. ;; License, or (at your option) any later version.                                                ;;
  10. ;;                                                                                                ;;
  11. ;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
  12. ;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
  13. ;; General Public License for more details.                                                       ;;
  14. ;;                                                                                                ;;
  15. ;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
  16. ;; see <http://www.gnu.org/licenses/>.                                                            ;;
  17. ;;                                                                                                ;;
  18. ;;================================================================================================;;
  19. ;;                                                                                                ;;
  20. ;; 2008-12-29 (mike.dld)                                                                          ;;
  21. ;;   bug-fixes:                                                                                   ;;
  22. ;;     - unnecessary 'stosb' in ini.get_str was causing problems                                  ;;
  23. ;;   new features:                                                                                ;;
  24. ;;     - new functions: ini.get_color and ini.set_color                                           ;;
  25. ;; 2008-08-06 (mike.dld)                                                                          ;;
  26. ;;   changes:                                                                                     ;;
  27. ;;     - split private procs into libini_p.asm, added comments                                    ;;
  28. ;; 2008-02-07 (mike.dld)                                                                          ;;
  29. ;;   changes:                                                                                     ;;
  30. ;;     - renamed all *.aux.* to *._.* to match overall libraries design                           ;;
  31. ;; 2007-09-26 (mike.dld)                                                                          ;;
  32. ;;   bug-fixes:                                                                                   ;;
  33. ;;     - value was not correctly trimmed (reported by diamond)                                    ;;
  34. ;; 2007-08-01 (mike.dld)                                                                          ;;
  35. ;;   bug-fixes:                                                                                   ;;
  36. ;;     - serious defect in ini.set_str causing displaced write operations                         ;;
  37. ;;       (reported by diamond)                                                                    ;;
  38. ;;     - another serious defect in ini.enum_keys introduced with refactoring                      ;;
  39. ;;   changes:                                                                                     ;;
  40. ;;     - callback for enum_keys now takes additional parameter - key value                        ;;
  41. ;;     - handling trailing spaces in section/key/value                                            ;;
  42. ;; 2007-05-19 (mike.dld)                                                                          ;;
  43. ;;   bug-fixes:                                                                                   ;;
  44. ;;     - last char still wasn't read correctly                                                    ;;
  45. ;;     - digits of number were reversed when using ini.set_int                                    ;;
  46. ;;     - now using 'ini.aux.unget_char' instead of dangerous 'dec esi'                            ;;
  47. ;;   changes:                                                                                     ;;
  48. ;;     - all non-public functions now start with ini.aux.*                                        ;;
  49. ;;     - added ini.enum_sections and ini.enum_keys                                                ;;
  50. ;;     - removed ini.query_sec (use ini.enum_* instead)                                           ;;
  51. ;;                                                                                                ;;
  52. ;;================================================================================================;;
  53.  
  54. format MS COFF
  55.  
  56. public @EXPORT as 'EXPORTS'
  57.  
  58. include '../../../../proc32.inc'
  59. include '../../../../macros.inc'
  60. include '../libio/libio.inc'
  61. purge section ; mov,add,sub
  62.  
  63. include 'libini_p.inc'
  64.  
  65. section '.flat' code readable align 16
  66.  
  67. include 'libini_p.asm'
  68.  
  69. ;;================================================================================================;;
  70. proc ini.enum_sections _f_name, _callback ;///////////////////////////////////////////////////////;;
  71. ;;------------------------------------------------------------------------------------------------;;
  72. ;? Enumerate sections, calling callback function for each of them                                 ;;
  73. ;;------------------------------------------------------------------------------------------------;;
  74. ;> _f_name = ini filename <asciiz>                                                                ;;
  75. ;> _callback = callback function address: func(f_name, sec_name), where                           ;;
  76. ;>   f_name = ini filename (as passed to the function) <asciiz>                                   ;;
  77. ;>   sec_name = section name found <asciiz>                                                       ;;
  78. ;;------------------------------------------------------------------------------------------------;;
  79. ;< eax = -1 (error) / 0                                                                           ;;
  80. ;;================================================================================================;;
  81. locals
  82.   f       IniFile
  83.   f_addr  dd ?
  84.   sec_buf dd ?
  85. endl
  86.  
  87.         push    ebx esi edi
  88.  
  89.         cld
  90.  
  91.         invoke  mem.alloc, ini.MAX_NAME_LEN
  92.         or      eax, eax
  93.         jz      .exit_error.2
  94.         mov     [sec_buf], eax
  95.  
  96.         xor     eax, eax
  97.         mov     [f.fh], eax
  98.         mov     [f.buf], eax
  99.         invoke  file.open, [_f_name], O_READ
  100.         cmp     eax, 32
  101.         jb      .exit_error
  102.         mov     [f.fh], eax
  103.         invoke  mem.alloc, ini.MEM_SIZE
  104.         or      eax, eax
  105.         jz      .exit_error
  106.         mov     [f.buf], eax
  107.         lea     ebx, [f]
  108.         mov     [f_addr], ebx
  109.  
  110.         invoke  file.seek, [f.fh], 0, SEEK_SET
  111.         stdcall libini._.preload_block, [f_addr]
  112.  
  113.   .next_section:
  114.         stdcall libini._.find_next_section, [f_addr]
  115.         or      eax, eax
  116.         jnz     .exit_error
  117.  
  118.         stdcall libini._.get_char, [f_addr]
  119.         stdcall libini._.skip_spaces, [f_addr]
  120. ;       inc     esi
  121. ;       dec     [f.cnt]
  122.         mov     edi, [sec_buf]
  123.     @@: stdcall libini._.get_char, [f_addr]
  124.         cmp     al, ']'
  125.         je      @f
  126.         or      al, al
  127.         jz      .exit_ok
  128.         cmp     al, 13
  129.         je      .next_section
  130.         cmp     al, 10
  131.         je      .next_section
  132.         stosb
  133.         jmp     @b
  134.     @@: xor     al, al
  135.         stosb
  136.         add     edi, -2
  137.     @@: cmp     byte[edi], 32
  138.         ja      @f
  139.         mov     byte[edi], 0
  140.         dec     edi
  141.         jmp     @b
  142.     @@:
  143.         pushad
  144.         mov     eax, [f_addr]
  145.         stdcall [_callback], [_f_name], [sec_buf]
  146.         or      eax, eax
  147.         popad
  148.         jnz     .next_section
  149.  
  150.   .exit_ok:
  151.         invoke  file.close, [f.fh]
  152.         invoke  mem.free, [f.buf]
  153.         invoke  mem.free, [sec_buf]
  154.         xor     eax, eax
  155.         pop     edi esi ebx
  156.         ret
  157.  
  158.   .exit_error:
  159.         invoke  file.close, [f.fh]
  160.         invoke  mem.free, [f.buf]
  161.         invoke  mem.free, [sec_buf]
  162.   .exit_error.2:
  163.         or      eax, -1
  164.         pop     edi esi ebx
  165.         ret
  166. endp
  167.  
  168. ;;================================================================================================;;
  169. proc ini.enum_keys _f_name, _sec_name, _callback ;////////////////////////////////////////////////;;
  170. ;;------------------------------------------------------------------------------------------------;;
  171. ;? Enumerate keys within a section, calling callback function for each of them                    ;;
  172. ;;------------------------------------------------------------------------------------------------;;
  173. ;> _f_name = ini filename <asciiz>                                                                ;;
  174. ;> _sec_name = section name <asciiz>                                                              ;;
  175. ;> _callback = callback function address: func(f_name, sec_name, key_name, key_value), where      ;;
  176. ;>   f_name = ini filename (as passed to the function) <asciiz>                                   ;;
  177. ;>   sec_name = section name (as passed to the function) <asciiz>                                 ;;
  178. ;>   key_name = key name found <asciiz>                                                           ;;
  179. ;>   key_value = value of key found <asciiz>                                                      ;;
  180. ;;------------------------------------------------------------------------------------------------;;
  181. ;< eax = -1 (error) / 0                                                                           ;;
  182. ;;================================================================================================;;
  183. locals
  184.   f       IniFile
  185.   f_addr  dd ?
  186.   key_buf dd ?
  187.   val_buf dd ?
  188. endl
  189.  
  190.         push    ebx esi edi
  191.  
  192.         cld
  193.  
  194.         invoke  mem.alloc, ini.MAX_NAME_LEN
  195.         or      eax, eax
  196.         jz      .exit_error.3
  197.         mov     [key_buf], eax
  198.         invoke  mem.alloc, ini.MAX_VALUE_LEN
  199.         or      eax, eax
  200.         jz      .exit_error.2
  201.         mov     [val_buf], eax
  202.  
  203.         xor     eax, eax
  204.         mov     [f.fh], eax
  205.         mov     [f.buf], eax
  206.         invoke  file.open, [_f_name], O_READ
  207.         cmp     eax, 32
  208.         jb      .exit_error
  209.         mov     [f.fh], eax
  210.         invoke  mem.alloc, ini.MEM_SIZE
  211.         or      eax, eax
  212.         jz      .exit_error
  213.         mov     [f.buf], eax
  214.         lea     ebx, [f]
  215.         mov     [f_addr], ebx
  216.         stdcall libini._.find_section, ebx, [_sec_name]
  217.         or      eax, eax
  218.         jnz     .exit_error
  219.  
  220.   .next_key:
  221.         stdcall libini._.skip_line, [f_addr]
  222.         stdcall libini._.skip_nonblanks, [f_addr]
  223.         or      al, al
  224.         jz      .exit_error
  225.         cmp     al, '['
  226.         je      .exit_error
  227.         mov     edi, [key_buf]
  228.     @@: stdcall libini._.get_char, [f_addr]
  229.         or      al, al
  230.         jz      .exit_error
  231.         cmp     al, '='
  232.         je      @f
  233.         stosb
  234.         jmp     @b
  235.     @@:
  236.         xor     al, al
  237.         stosb
  238.         add     edi, -2
  239.     @@: cmp     byte[edi], 32
  240.         ja      @f
  241.         mov     byte[edi], 0
  242.         dec     edi
  243.         jmp     @b
  244.     @@: stdcall libini._.low.read_value, [f_addr], [val_buf], ini.MAX_VALUE_LEN
  245.         pushad
  246.         stdcall [_callback], [_f_name], [_sec_name], [key_buf], [val_buf]
  247.         or      eax, eax
  248.         popad
  249.         jnz     .next_key
  250.  
  251.     @@: invoke  file.close, [f.fh]
  252.         invoke  mem.free, [f.buf]
  253.         xor     eax, eax
  254.         stosb
  255.         pop     edi esi ebx
  256.         ret
  257.  
  258.   .exit_error:
  259.         invoke  file.close, [f.fh]
  260.         invoke  mem.free, [f.buf]
  261.         invoke  mem.free, [val_buf]
  262.   .exit_error.2:
  263.         invoke  mem.free, [key_buf]
  264.   .exit_error.3:
  265.         or      eax, -1
  266.         pop     edi esi ebx
  267.         ret
  268. endp
  269.  
  270. ;;================================================================================================;;
  271. proc ini.get_str _f_name, _sec_name, _key_name, _buffer, _buf_len, _def_val ;/////////////////////;;
  272. ;;------------------------------------------------------------------------------------------------;;
  273. ;? Read string                                                                                    ;;
  274. ;;------------------------------------------------------------------------------------------------;;
  275. ;> _f_name = ini filename <asciiz>                                                                ;;
  276. ;> _sec_name = section name <asciiz>                                                              ;;
  277. ;> _key_name = key name <asciiz>                                                                  ;;
  278. ;> _buffer = destination buffer address <byte*>                                                   ;;
  279. ;> _buf_len = buffer size (maximum bytes to read) <dword>                                         ;;
  280. ;> _def_val = default value to return if no key, section or file found <asciiz>                   ;;
  281. ;;------------------------------------------------------------------------------------------------;;
  282. ;< eax = -1 (error) / 0                                                                           ;;
  283. ;< [_buffer] = [_def_val] (error) / found key value <asciiz>                                      ;;
  284. ;;================================================================================================;;
  285. locals
  286.   f      IniFile
  287.   f_addr dd ?
  288. endl
  289.  
  290.         push    ebx esi edi
  291.  
  292.         xor     eax, eax
  293.         mov     [f.fh], eax
  294.         mov     [f.buf], eax
  295.         invoke  file.open, [_f_name], O_READ
  296.         cmp     eax, 32
  297.         jb      .exit_error
  298.         mov     [f.fh], eax
  299.         invoke  mem.alloc, ini.MEM_SIZE
  300.         or      eax, eax
  301.         jz      .exit_error
  302.         mov     [f.buf], eax
  303.         lea     ebx, [f]
  304.         mov     [f_addr], ebx
  305.         stdcall libini._.find_section, ebx, [_sec_name]
  306.         or      eax, eax
  307.         jnz     .exit_error
  308.  
  309.         stdcall libini._.find_key, ebx, [_key_name]
  310.         or      eax, eax
  311.         jnz     .exit_error
  312.  
  313.         stdcall libini._.low.read_value, [f_addr], [_buffer], [_buf_len]
  314.     @@: invoke  file.close, [f.fh]
  315.         invoke  mem.free, [f.buf]
  316.         xor     eax, eax
  317.         pop     edi esi ebx
  318.         ret
  319.  
  320.   .exit_error:
  321.         invoke  file.close, [f.fh]
  322.         invoke  mem.free, [f.buf]
  323.         mov     edi, [_buffer]
  324.         mov     esi, [_def_val]
  325.         xor     al, al
  326.         or      esi, esi
  327.         jz      .exit_error.2
  328.     @@: lodsb
  329.   .exit_error.2:
  330.         stosb
  331.         or      al, al
  332.         jnz     @b
  333.         or      eax, -1
  334.         pop     edi esi ebx
  335.         ret
  336. endp
  337.  
  338. ;;================================================================================================;;
  339. proc ini.set_str _f_name, _sec_name, _key_name, _buffer, _buf_len ;///////////////////////////////;;
  340. ;;------------------------------------------------------------------------------------------------;;
  341. ;? Write string                                                                                   ;;
  342. ;;------------------------------------------------------------------------------------------------;;
  343. ;> _f_name = ini filename <asciiz>                                                                ;;
  344. ;> _sec_name = section name <asciiz>                                                              ;;
  345. ;> _key_name = key name <asciiz>                                                                  ;;
  346. ;> _buffer = source buffer address <byte*>                                                        ;;
  347. ;> _buf_len = buffer size (bytes to write) <dword>                                                ;;
  348. ;;------------------------------------------------------------------------------------------------;;
  349. ;< eax = -1 (error) / 0                                                                           ;;
  350. ;;================================================================================================;;
  351. locals
  352.   f      IniFile
  353.   f_addr dd ?
  354. endl
  355.  
  356.         push    ebx esi edi
  357.  
  358.         xor     eax, eax
  359.         mov     [f.fh], eax
  360.         mov     [f.buf], eax
  361.         invoke  file.open, [_f_name], O_READ + O_WRITE + O_CREATE
  362.         cmp     eax, 32
  363.         jb      .exit_error
  364.         mov     [f.fh], eax
  365.         invoke  mem.alloc, ini.MEM_SIZE
  366.         or      eax, eax
  367.         jz      .exit_error
  368.         mov     [f.buf], eax
  369.         lea     ebx, [f]
  370.         mov     [f_addr], ebx
  371.  
  372.         stdcall libini._.find_section, ebx, [_sec_name]
  373.         or      eax, eax
  374.         jnz     .create_section
  375.  
  376.         stdcall libini._.find_key, ebx, [_key_name]
  377.         or      eax, eax
  378.         jnz     .create_key
  379.  
  380.   .modify_key:
  381.         stdcall libini._.get_value_length, [f_addr]
  382.         sub     eax, [_buf_len]
  383.         stdcall libini._.shift_content, [f_addr], eax
  384.  
  385.   .modify_key.ex:
  386.         invoke  file.tell, [f.fh]
  387.         sub     eax, [f.cnt]
  388. ;       dec     eax
  389.         invoke  file.seek, [f.fh], eax, SEEK_SET
  390.         invoke  file.write, [f.fh], [_buffer], [_buf_len]
  391.  
  392.         pop     edi esi ebx
  393.         xor     eax, eax
  394.         ret
  395.  
  396.   .create_key:
  397.         mov     edi, [f.buf]
  398.         add     edi, ini.BLOCK_SIZE
  399.         push    edi
  400.  
  401.   .create_key.ex:
  402. ;       mov     word[edi], 0x0A0D
  403. ;       add     edi,2
  404.         mov     esi, [_key_name]
  405.         call    libini._.string_copy
  406.         mov     byte[edi], '='
  407.         inc     edi
  408.         mov     esi, [_buffer]
  409.         mov     ecx, [_buf_len]
  410.         rep     movsb
  411.         mov     word[edi], 0x0A0D
  412.         add     edi, 2
  413.         mov     eax, edi
  414.  
  415.         pop     edi
  416.         sub     eax, edi
  417.         mov     [_buffer], edi
  418.         mov     [_buf_len], eax
  419.         neg     eax
  420.         stdcall libini._.shift_content, [f_addr], eax
  421.  
  422.         jmp     .modify_key.ex
  423.  
  424.   .create_section:
  425.         mov     edi, [f.buf]
  426.         add     edi, ini.BLOCK_SIZE
  427.         push    edi
  428.  
  429.         mov     esi, [_sec_name]
  430. ;       mov     dword[edi], 0x0A0D + ('[' shl 16)
  431. ;       add     edi, 3
  432.         mov     byte[edi], '['
  433.         inc     edi
  434.         call    libini._.string_copy
  435. ;       mov     byte[edi], ']'
  436. ;       inc     edi
  437.         mov     dword[edi], ']' + (0x0A0D shl 8)
  438.         add     edi, 3
  439.  
  440.         jmp     .create_key.ex
  441.  
  442.   .exit_error:
  443.         pop     edi esi ebx
  444.         or      eax, -1
  445.         ret
  446. endp
  447.  
  448. ;;================================================================================================;;
  449. proc ini.get_int _f_name, _sec_name, _key_name, _def_val ;////////////////////////////////////////;;
  450. ;;------------------------------------------------------------------------------------------------;;
  451. ;? Read integer                                                                                   ;;
  452. ;;------------------------------------------------------------------------------------------------;;
  453. ;> _f_name = ini filename <asciiz>                                                                ;;
  454. ;> _sec_name = section name <asciiz>                                                              ;;
  455. ;> _key_name = key name <asciiz>                                                                  ;;
  456. ;> _def_val = default value to return if no key, section or file found <dword>                    ;;
  457. ;;------------------------------------------------------------------------------------------------;;
  458. ;< eax = [_def_val] (error) / found key value <dword>                                             ;;
  459. ;;================================================================================================;;
  460. locals
  461.   f      IniFile
  462.   f_addr dd ?
  463. endl
  464.  
  465.         push    ebx esi edi
  466.  
  467.         xor     eax, eax
  468.         mov     [f.fh], eax
  469.         mov     [f.buf], eax
  470.         invoke  file.open, [_f_name], O_READ
  471.         cmp     eax, 32
  472.         jb      .exit_error
  473.         mov     [f.fh], eax
  474.         invoke  mem.alloc, ini.MEM_SIZE
  475.         or      eax, eax
  476.         jz      .exit_error
  477.         mov     [f.buf], eax
  478.         lea     ebx, [f]
  479.         mov     [f_addr], ebx
  480.         stdcall libini._.find_section, ebx, [_sec_name]
  481.         or      eax, eax
  482.         jnz     .exit_error
  483.  
  484.         stdcall libini._.find_key, ebx, [_key_name]
  485.         or      eax, eax
  486.         jnz     .exit_error
  487.  
  488.         stdcall libini._.skip_nonblanks, [f_addr]
  489.         xor     eax, eax
  490.         xor     ebx, ebx
  491.         xor     edx, edx
  492.         stdcall libini._.get_char, [f_addr]
  493.         cmp     al, '-'
  494.         jne     .lp1
  495.         inc     bh
  496.     @@: stdcall libini._.get_char, [f_addr]
  497.   .lp1: cmp     al, '0'
  498.         jb      @f
  499.         cmp     al, '9'
  500.         ja      @f
  501.         inc     bl
  502.         add     eax, -'0'
  503.         imul    edx, 10
  504.         add     edx, eax
  505.         jmp     @b
  506.     @@:
  507.         or      bl, bl
  508.         jz      .exit_error
  509.         or      bh, bh
  510.         jz      @f
  511.         neg     edx
  512.     @@: invoke  file.close, [f.fh]
  513.         invoke  mem.free, [f.buf]
  514.         mov     eax, edx
  515.         pop     edi esi ebx
  516.         ret
  517.  
  518.   .exit_error:
  519.         invoke  file.close, [f.fh]
  520.         invoke  mem.free, [f.buf]
  521.         mov     eax, [_def_val]
  522.         pop     edi esi ebx
  523.         ret
  524. endp
  525.  
  526. ;;================================================================================================;;
  527. proc ini.set_int _f_name, _sec_name, _key_name, _val ;////////////////////////////////////////////;;
  528. ;;------------------------------------------------------------------------------------------------;;
  529. ;? Write integer                                                                                  ;;
  530. ;;------------------------------------------------------------------------------------------------;;
  531. ;> _f_name = ini filename <asciiz>                                                                ;;
  532. ;> _sec_name = section name <asciiz>                                                              ;;
  533. ;> _key_name = key name <asciiz>                                                                  ;;
  534. ;> _val = value <dword>                                                                           ;;
  535. ;;------------------------------------------------------------------------------------------------;;
  536. ;< eax = -1 (error) / 0                                                                           ;;
  537. ;;================================================================================================;;
  538. locals
  539.   buf rb 16
  540. endl
  541.  
  542.         push    ecx edx edi
  543.  
  544.         lea     edi, [buf]
  545.         add     edi, 15
  546.         mov     eax, [_val]
  547.         or      eax, eax
  548.         jns     @f
  549.         mov     byte[edi], '-'
  550.         neg     eax
  551.         inc     edi
  552.     @@: mov     ecx, 10
  553.     @@: xor     edx, edx
  554.         idiv    ecx
  555.         add     dl, '0'
  556.         mov     [edi], dl
  557.         dec     edi
  558.         or      eax, eax
  559.         jnz     @b
  560.         lea     eax, [buf]
  561.         add     eax, 15
  562.         sub     eax, edi
  563.         inc     edi
  564.  
  565.         stdcall ini.set_str, [_f_name], [_sec_name], [_key_name], edi, eax
  566.  
  567.         pop     edi edx ecx
  568.         ret
  569. endp
  570.  
  571. ;;================================================================================================;;
  572. proc ini.get_color _f_name, _sec_name, _key_name, _def_val ;//////////////////////////////////////;;
  573. ;;------------------------------------------------------------------------------------------------;;
  574. ;? Read color                                                                                     ;;
  575. ;;------------------------------------------------------------------------------------------------;;
  576. ;> _f_name = ini filename <asciiz>                                                                ;;
  577. ;> _sec_name = section name <asciiz>                                                              ;;
  578. ;> _key_name = key name <asciiz>                                                                  ;;
  579. ;> _def_val = default value to return if no key, section or file found <dword>                    ;;
  580. ;;------------------------------------------------------------------------------------------------;;
  581. ;< eax = [_def_val] (error) / found key value <dword>                                             ;;
  582. ;;================================================================================================;;
  583. locals
  584.   buf rb 14
  585. endl
  586.  
  587.         push    ebx esi edi
  588.  
  589.         lea     esi, [buf]
  590.         stdcall ini.get_str, [_f_name], [_sec_name], [_key_name], esi, 14, 0
  591.         cmp     byte[esi],0
  592.         je      .exit_error
  593.  
  594.         xor     ebx, ebx
  595.         stdcall libini._.str_to_int
  596.         movzx   ebx, al
  597.         shl     ebx, 16
  598.         lodsb
  599.         cmp     al, ','
  600.         jne     @f
  601.         stdcall libini._.str_to_int
  602.         mov     bh, al
  603.         lodsb
  604.         cmp     al, ','
  605.         jne     @f
  606.         stdcall libini._.str_to_int
  607.         mov     bl, al
  608.  
  609.     @@: mov     eax, ebx
  610.  
  611.         pop     edi esi ebx
  612.         ret
  613.  
  614.   .exit_error:
  615.         mov     eax, [_def_val]
  616.         pop     edi esi ebx
  617.         ret
  618. endp
  619.  
  620. ;;================================================================================================;;
  621. proc ini.set_color _f_name, _sec_name, _key_name, _val ;//////////////////////////////////////////;;
  622. ;;------------------------------------------------------------------------------------------------;;
  623. ;? Write color                                                                                    ;;
  624. ;;------------------------------------------------------------------------------------------------;;
  625. ;> _f_name = ini filename <asciiz>                                                                ;;
  626. ;> _sec_name = section name <asciiz>                                                              ;;
  627. ;> _key_name = key name <asciiz>                                                                  ;;
  628. ;> _val = value <dword>                                                                           ;;
  629. ;;------------------------------------------------------------------------------------------------;;
  630. ;< eax = -1 (error) / 0                                                                           ;;
  631. ;;================================================================================================;;
  632. locals
  633.   buf rb 16
  634. endl
  635.  
  636.         push    ecx edx edi
  637.  
  638.         lea     edi, [buf]
  639.         mov     ecx, 10
  640.         mov     ebx, [_val]
  641.         mov     eax, ebx
  642.         shr     eax, 16
  643.         and     eax, 0x0ff
  644.         stdcall libini._.int_to_str
  645.         mov     byte[edi], ','
  646.         inc     edi
  647.         movzx   eax, bh
  648.         stdcall libini._.int_to_str
  649.         mov     byte[edi], ','
  650.         inc     edi
  651.         movzx   eax, bl
  652.         stdcall libini._.int_to_str
  653.  
  654.         lea     eax, [buf]
  655.         sub     edi, eax
  656.  
  657.         stdcall ini.set_str, [_f_name], [_sec_name], [_key_name], eax, edi
  658.  
  659.         pop     edi edx ecx
  660.         ret
  661. endp
  662.  
  663.  
  664. ;;================================================================================================;;
  665. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  666. ;;================================================================================================;;
  667. ;! Imported functions section                                                                     ;;
  668. ;;================================================================================================;;
  669. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  670. ;;================================================================================================;;
  671.  
  672.  
  673. align 16
  674. @IMPORT:
  675.  
  676. library \
  677.         libio , 'libio.obj'
  678.  
  679. import  libio                       , \
  680.         file.size   , 'file.size'   , \
  681.         file.open   , 'file.open'   , \
  682.         file.read   , 'file.read'   , \
  683.         file.write  , 'file.write'  , \
  684.         file.seek   , 'file.seek'   , \
  685.         file.eof?   , 'file.eof?'   , \
  686.         file.seteof , 'file.seteof' , \
  687.         file.tell   , 'file.tell'   , \
  688.         file.close  , 'file.close'
  689.  
  690.  
  691. ;;================================================================================================;;
  692. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  693. ;;================================================================================================;;
  694. ;! Exported functions section                                                                     ;;
  695. ;;================================================================================================;;
  696. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  697. ;;================================================================================================;;
  698.  
  699.  
  700. align 16
  701. @EXPORT:
  702.  
  703. export                                            \
  704.         libini._.init     , 'lib_init'          , \
  705.         0x00040006        , 'version'           , \
  706.         ini.enum_sections , 'ini.enum_sections' , \
  707.         ini.enum_keys     , 'ini.enum_keys'     , \
  708.         ini.get_str       , 'ini.get_str'       , \
  709.         ini.get_int       , 'ini.get_int'       , \
  710.         ini.get_color     , 'ini.get_color'     , \
  711.         ini.set_str       , 'ini.set_str'       , \
  712.         ini.set_int       , 'ini.set_int'       , \
  713.         ini.set_color     , 'ini.set_color'
  714.