2009-11-28 18:28:17 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
;;//// libini.asm //// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;; ;;
|
|
|
|
;; This file is part of Common development libraries (Libs-Dev). ;;
|
|
|
|
;; ;;
|
|
|
|
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
|
|
|
|
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
|
|
|
|
;; of the License, or (at your option) any later version. ;;
|
|
|
|
;; ;;
|
|
|
|
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;;
|
|
|
|
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
|
|
|
|
;; Lesser General Public License for more details. ;;
|
|
|
|
;; ;;
|
|
|
|
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev. ;;
|
|
|
|
;; If not, see <http://www.gnu.org/licenses/>. ;;
|
|
|
|
;; ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;; ;;
|
|
|
|
;; 2009-03-08 (mike.dld) ;;
|
|
|
|
;; bug-fixes: ;;
|
|
|
|
;; - moved buffer bound check in libini._.low.read_value up (reported by Insolor) ;;
|
|
|
|
;; new features: ;;
|
|
|
|
;; - comments support (char is ini.COMMENT_CHAR, defaults to ';') ;;
|
|
|
|
;; inline comments are not supported ;;
|
|
|
|
;; 2008-12-29 (mike.dld) ;;
|
|
|
|
;; bug-fixes: ;;
|
|
|
|
;; - unnecessary 'stosb' in ini.get_str was causing problems ;;
|
|
|
|
;; new features: ;;
|
|
|
|
;; - new functions: ini.get_color and ini.set_color ;;
|
|
|
|
;; 2008-08-06 (mike.dld) ;;
|
|
|
|
;; changes: ;;
|
|
|
|
;; - split private procs into libini_p.asm, added comments ;;
|
|
|
|
;; 2008-02-07 (mike.dld) ;;
|
|
|
|
;; changes: ;;
|
|
|
|
;; - renamed all *.aux.* to *._.* to match overall libraries design ;;
|
|
|
|
;; 2007-09-26 (mike.dld) ;;
|
|
|
|
;; bug-fixes: ;;
|
|
|
|
;; - value was not correctly trimmed (reported by diamond) ;;
|
|
|
|
;; 2007-08-01 (mike.dld) ;;
|
|
|
|
;; bug-fixes: ;;
|
|
|
|
;; - serious defect in ini.set_str causing displaced write operations ;;
|
|
|
|
;; (reported by diamond) ;;
|
|
|
|
;; - another serious defect in ini.enum_keys introduced with refactoring ;;
|
|
|
|
;; changes: ;;
|
|
|
|
;; - callback for enum_keys now takes additional parameter - key value ;;
|
|
|
|
;; - handling trailing spaces in section/key/value ;;
|
|
|
|
;; 2007-05-19 (mike.dld) ;;
|
|
|
|
;; bug-fixes: ;;
|
|
|
|
;; - last char still wasn't read correctly ;;
|
|
|
|
;; - digits of number were reversed when using ini.set_int ;;
|
|
|
|
;; - now using 'ini.aux.unget_char' instead of dangerous 'dec esi' ;;
|
|
|
|
;; changes: ;;
|
|
|
|
;; - all non-public functions now start with ini.aux.* ;;
|
|
|
|
;; - added ini.enum_sections and ini.enum_keys ;;
|
|
|
|
;; - removed ini.query_sec (use ini.enum_* instead) ;;
|
|
|
|
;; ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
format MS COFF
|
|
|
|
|
|
|
|
public @EXPORT as 'EXPORTS'
|
|
|
|
|
|
|
|
include '../../../../proc32.inc'
|
|
|
|
include '../../../../macros.inc'
|
|
|
|
include '../libio/libio.inc'
|
2009-12-21 02:35:51 +03:00
|
|
|
purge section,mov,add,sub
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
include 'libini_p.inc'
|
|
|
|
|
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
|
|
|
include 'libini_p.asm'
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.enum_sections _f_name, _callback ;///////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Enumerate sections, calling callback function for each of them ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _callback = callback function address: func(f_name, sec_name), where ;;
|
|
|
|
;> f_name = ini filename (as passed to the function) <asciiz> ;;
|
|
|
|
;> sec_name = section name found <asciiz> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = -1 (error) / 0 ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
2012-04-12 14:13:30 +04:00
|
|
|
f IniFile
|
2009-11-28 18:28:17 +03:00
|
|
|
f_addr dd ?
|
|
|
|
sec_buf dd ?
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ebx esi edi
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
cld
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke mem.alloc, ini.MAX_NAME_LEN
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error.2
|
|
|
|
mov [sec_buf], eax
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov [f.fh], eax
|
|
|
|
mov [f.buf], eax
|
|
|
|
invoke file.open, [_f_name], O_READ
|
|
|
|
cmp eax, 32
|
2012-12-21 23:26:30 +04:00
|
|
|
jb .exit_file_error
|
2012-04-12 14:13:30 +04:00
|
|
|
mov [f.fh], eax
|
|
|
|
invoke mem.alloc, ini.MEM_SIZE
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error
|
|
|
|
mov [f.buf], eax
|
|
|
|
lea ebx, [f]
|
|
|
|
mov [f_addr], ebx
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.seek, [f.fh], 0, SEEK_SET
|
|
|
|
stdcall libini._.preload_block, [f_addr]
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.next_section:
|
2012-04-12 14:13:30 +04:00
|
|
|
stdcall libini._.find_next_section, [f_addr]
|
|
|
|
or eax, eax
|
|
|
|
jnz .exit_error
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
stdcall libini._.get_char, [f_addr]
|
|
|
|
stdcall libini._.skip_spaces, [f_addr]
|
|
|
|
mov edi, [sec_buf]
|
2009-11-28 18:28:17 +03:00
|
|
|
@@: stdcall libini._.get_char, [f_addr]
|
2012-04-12 14:13:30 +04:00
|
|
|
cmp al, ']'
|
|
|
|
je @f
|
|
|
|
or al, al
|
|
|
|
jz .exit_ok
|
|
|
|
cmp al, 13
|
|
|
|
je .next_section
|
|
|
|
cmp al, 10
|
|
|
|
je .next_section
|
|
|
|
stosb
|
|
|
|
jmp @b
|
|
|
|
@@: xor al, al
|
|
|
|
stosb
|
|
|
|
add edi, -2
|
|
|
|
@@: cmp byte[edi], 32
|
|
|
|
ja @f
|
|
|
|
mov byte[edi], 0
|
|
|
|
dec edi
|
|
|
|
jmp @b
|
2009-11-28 18:28:17 +03:00
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
pushad
|
|
|
|
mov eax, [f_addr]
|
|
|
|
stdcall [_callback], [_f_name], [sec_buf]
|
|
|
|
or eax, eax
|
|
|
|
popad
|
|
|
|
jnz .next_section
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_ok:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
|
|
|
invoke mem.free, [sec_buf]
|
|
|
|
xor eax, eax
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
2012-12-21 23:26:30 +04:00
|
|
|
.exit_file_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke mem.free, [sec_buf]
|
2009-11-28 18:28:17 +03:00
|
|
|
.exit_error.2:
|
2012-04-12 14:13:30 +04:00
|
|
|
or eax, -1
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.enum_keys _f_name, _sec_name, _callback ;////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Enumerate keys within a section, calling callback function for each of them ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _callback = callback function address: func(f_name, sec_name, key_name, key_value), where ;;
|
|
|
|
;> f_name = ini filename (as passed to the function) <asciiz> ;;
|
|
|
|
;> sec_name = section name (as passed to the function) <asciiz> ;;
|
|
|
|
;> key_name = key name found <asciiz> ;;
|
|
|
|
;> key_value = value of key found <asciiz> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = -1 (error) / 0 ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
2012-04-12 14:13:30 +04:00
|
|
|
f IniFile
|
2009-11-28 18:28:17 +03:00
|
|
|
f_addr dd ?
|
|
|
|
key_buf dd ?
|
|
|
|
val_buf dd ?
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ebx esi edi
|
|
|
|
|
|
|
|
cld
|
|
|
|
|
|
|
|
invoke mem.alloc, ini.MAX_NAME_LEN
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error.3
|
|
|
|
mov [key_buf], eax
|
|
|
|
invoke mem.alloc, ini.MAX_VALUE_LEN
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error.2
|
|
|
|
mov [val_buf], eax
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [f.fh], eax
|
|
|
|
mov [f.buf], eax
|
|
|
|
invoke file.open, [_f_name], O_READ
|
|
|
|
cmp eax, 32
|
2012-12-21 23:26:30 +04:00
|
|
|
jb .exit_file_error
|
2012-04-12 14:13:30 +04:00
|
|
|
mov [f.fh], eax
|
|
|
|
invoke mem.alloc, ini.MEM_SIZE
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error
|
|
|
|
mov [f.buf], eax
|
|
|
|
lea ebx, [f]
|
|
|
|
mov [f_addr], ebx
|
|
|
|
stdcall libini._.find_section, ebx, [_sec_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .exit_error
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.next_key:
|
2012-04-12 14:13:30 +04:00
|
|
|
stdcall libini._.skip_line, [f_addr]
|
|
|
|
stdcall libini._.skip_nonblanks, [f_addr]
|
|
|
|
or al, al
|
|
|
|
jz .exit_error
|
|
|
|
cmp al, '['
|
|
|
|
je .exit_error
|
|
|
|
mov edi, [key_buf]
|
2009-11-28 18:28:17 +03:00
|
|
|
@@: stdcall libini._.get_char, [f_addr]
|
2012-04-12 14:13:30 +04:00
|
|
|
or al, al
|
|
|
|
jz .exit_error
|
|
|
|
cmp al, '='
|
|
|
|
je @f
|
|
|
|
stosb
|
|
|
|
jmp @b
|
2009-11-28 18:28:17 +03:00
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
xor al, al
|
|
|
|
stosb
|
|
|
|
add edi, -2
|
|
|
|
@@: cmp byte[edi], 32
|
|
|
|
ja @f
|
|
|
|
mov byte[edi], 0
|
|
|
|
dec edi
|
|
|
|
jmp @b
|
2009-11-28 18:28:17 +03:00
|
|
|
@@: stdcall libini._.low.read_value, [f_addr], [val_buf], ini.MAX_VALUE_LEN
|
2012-04-12 14:13:30 +04:00
|
|
|
pushad
|
|
|
|
stdcall [_callback], [_f_name], [_sec_name], [key_buf], [val_buf]
|
|
|
|
or eax, eax
|
|
|
|
popad
|
|
|
|
jnz .next_key
|
|
|
|
|
|
|
|
@@: invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
|
|
|
xor eax, eax
|
|
|
|
stosb
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
2012-12-21 23:26:30 +04:00
|
|
|
.exit_file_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke mem.free, [val_buf]
|
2009-11-28 18:28:17 +03:00
|
|
|
.exit_error.2:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke mem.free, [key_buf]
|
2009-11-28 18:28:17 +03:00
|
|
|
.exit_error.3:
|
2012-04-12 14:13:30 +04:00
|
|
|
or eax, -1
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.get_str _f_name, _sec_name, _key_name, _buffer, _buf_len, _def_val ;/////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Read string ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _buffer = destination buffer address <byte*> ;;
|
|
|
|
;> _buf_len = buffer size (maximum bytes to read) <dword> ;;
|
|
|
|
;> _def_val = default value to return if no key, section or file found <asciiz> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = -1 (error) / 0 ;;
|
|
|
|
;< [_buffer] = [_def_val] (error) / found key value <asciiz> ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
2012-04-12 14:13:30 +04:00
|
|
|
f IniFile
|
2009-11-28 18:28:17 +03:00
|
|
|
f_addr dd ?
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ebx esi edi
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [f.fh], eax
|
|
|
|
mov [f.buf], eax
|
|
|
|
invoke file.open, [_f_name], O_READ
|
|
|
|
cmp eax, 32
|
2012-12-21 23:26:30 +04:00
|
|
|
jb .exit_file_error
|
2012-04-12 14:13:30 +04:00
|
|
|
mov [f.fh], eax
|
|
|
|
invoke mem.alloc, ini.MEM_SIZE
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error
|
|
|
|
mov [f.buf], eax
|
|
|
|
lea ebx, [f]
|
|
|
|
mov [f_addr], ebx
|
|
|
|
stdcall libini._.find_section, ebx, [_sec_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .exit_error
|
|
|
|
|
|
|
|
stdcall libini._.find_key, ebx, [_key_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .exit_error
|
|
|
|
|
|
|
|
stdcall libini._.low.read_value, [f_addr], [_buffer], [_buf_len]
|
|
|
|
@@: invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
|
|
|
xor eax, eax
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
2012-12-21 23:26:30 +04:00
|
|
|
.exit_file_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov edi, [_buffer]
|
|
|
|
mov esi, [_def_val]
|
|
|
|
xor al, al
|
|
|
|
or esi, esi
|
|
|
|
jz .exit_error.2
|
2009-11-28 18:28:17 +03:00
|
|
|
@@: lodsb
|
|
|
|
.exit_error.2:
|
2012-04-12 14:13:30 +04:00
|
|
|
stosb
|
|
|
|
or al, al
|
|
|
|
jnz @b
|
|
|
|
or eax, -1
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.set_str _f_name, _sec_name, _key_name, _buffer, _buf_len ;///////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Write string ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _buffer = source buffer address <byte*> ;;
|
|
|
|
;> _buf_len = buffer size (bytes to write) <dword> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = -1 (error) / 0 ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
2012-04-12 14:13:30 +04:00
|
|
|
f IniFile
|
2009-11-28 18:28:17 +03:00
|
|
|
f_addr dd ?
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ebx esi edi
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [f.fh], eax
|
|
|
|
mov [f.buf], eax
|
|
|
|
invoke file.open, [_f_name], O_READ + O_WRITE + O_CREATE
|
|
|
|
cmp eax, 32
|
2012-12-21 23:26:30 +04:00
|
|
|
jb .exit_file_error
|
2012-04-12 14:13:30 +04:00
|
|
|
mov [f.fh], eax
|
|
|
|
invoke mem.alloc, ini.MEM_SIZE
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error
|
|
|
|
mov [f.buf], eax
|
|
|
|
lea ebx, [f]
|
|
|
|
mov [f_addr], ebx
|
|
|
|
|
|
|
|
stdcall libini._.find_section, ebx, [_sec_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .create_section
|
|
|
|
|
|
|
|
stdcall libini._.find_key, ebx, [_key_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .create_key
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.modify_key:
|
2012-04-12 14:13:30 +04:00
|
|
|
stdcall libini._.get_value_length, [f_addr]
|
|
|
|
sub eax, [_buf_len]
|
|
|
|
stdcall libini._.shift_content, [f_addr], eax
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.modify_key.ex:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.tell, [f.fh]
|
|
|
|
sub eax, [f.cnt]
|
|
|
|
invoke file.seek, [f.fh], eax, SEEK_SET
|
|
|
|
invoke file.write, [f.fh], [_buffer], [_buf_len]
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-12-21 23:26:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
2012-04-12 14:13:30 +04:00
|
|
|
pop edi esi ebx
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.create_key:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov edi, [f.buf]
|
|
|
|
add edi, ini.BLOCK_SIZE
|
|
|
|
push edi
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.create_key.ex:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov esi, [_key_name]
|
|
|
|
call libini._.string_copy
|
|
|
|
mov byte[edi], '='
|
|
|
|
inc edi
|
|
|
|
mov esi, [_buffer]
|
|
|
|
mov ecx, [_buf_len]
|
|
|
|
rep movsb
|
|
|
|
mov word[edi], 0x0A0D
|
|
|
|
add edi, 2
|
|
|
|
mov eax, edi
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
sub eax, edi
|
|
|
|
mov [_buffer], edi
|
|
|
|
mov [_buf_len], eax
|
|
|
|
neg eax
|
|
|
|
stdcall libini._.shift_content, [f_addr], eax
|
|
|
|
|
|
|
|
jmp .modify_key.ex
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.create_section:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov edi, [f.buf]
|
|
|
|
add edi, ini.BLOCK_SIZE
|
|
|
|
push edi
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
mov esi, [_sec_name]
|
|
|
|
mov byte[edi], '['
|
|
|
|
inc edi
|
|
|
|
call libini._.string_copy
|
|
|
|
mov dword[edi], ']' + (0x0A0D shl 8)
|
|
|
|
add edi, 3
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
jmp .create_key.ex
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-12-21 23:26:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
|
|
|
.exit_file_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
pop edi esi ebx
|
|
|
|
or eax, -1
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.get_int _f_name, _sec_name, _key_name, _def_val ;////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Read integer ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _def_val = default value to return if no key, section or file found <dword> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = [_def_val] (error) / found key value <dword> ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
2012-04-12 14:13:30 +04:00
|
|
|
f IniFile
|
2009-11-28 18:28:17 +03:00
|
|
|
f_addr dd ?
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push edx ebx esi edi
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [f.fh], eax
|
|
|
|
mov [f.buf], eax
|
|
|
|
invoke file.open, [_f_name], O_READ
|
|
|
|
cmp eax, 32
|
2012-12-21 23:26:30 +04:00
|
|
|
jb .exit_file_error
|
2012-04-12 14:13:30 +04:00
|
|
|
mov [f.fh], eax
|
|
|
|
invoke mem.alloc, ini.MEM_SIZE
|
|
|
|
or eax, eax
|
|
|
|
jz .exit_error
|
|
|
|
mov [f.buf], eax
|
|
|
|
lea ebx, [f]
|
|
|
|
mov [f_addr], ebx
|
|
|
|
stdcall libini._.find_section, ebx, [_sec_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .exit_error
|
|
|
|
|
|
|
|
stdcall libini._.find_key, ebx, [_key_name]
|
|
|
|
or eax, eax
|
|
|
|
jnz .exit_error
|
|
|
|
|
|
|
|
stdcall libini._.skip_spaces, [f_addr]
|
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
xor edx, edx
|
|
|
|
stdcall libini._.get_char, [f_addr]
|
|
|
|
cmp al, '-'
|
|
|
|
jne .lp1
|
|
|
|
inc bh
|
2009-11-28 18:28:17 +03:00
|
|
|
@@: stdcall libini._.get_char, [f_addr]
|
2012-04-12 14:13:30 +04:00
|
|
|
.lp1: cmp al, '0'
|
|
|
|
jb @f
|
|
|
|
cmp al, '9'
|
|
|
|
ja @f
|
|
|
|
inc bl
|
|
|
|
add eax, -'0'
|
|
|
|
imul edx, 10
|
|
|
|
add edx, eax
|
|
|
|
jmp @b
|
2009-11-28 18:28:17 +03:00
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
or bl, bl
|
|
|
|
jz .exit_error
|
|
|
|
or bh, bh
|
|
|
|
jz @f
|
|
|
|
neg edx
|
|
|
|
@@: invoke file.close, [f.fh]
|
|
|
|
invoke mem.free, [f.buf]
|
|
|
|
mov eax, edx
|
|
|
|
pop edi esi ebx edx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke file.close, [f.fh]
|
2012-12-21 23:26:30 +04:00
|
|
|
.exit_file_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
invoke mem.free, [f.buf]
|
|
|
|
mov eax, [_def_val]
|
|
|
|
pop edi esi ebx edx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.set_int _f_name, _sec_name, _key_name, _val ;////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Write integer ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _val = value <dword> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = -1 (error) / 0 ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
buf rb 16
|
2013-07-24 23:15:08 +04:00
|
|
|
bNeg rd 1
|
2009-11-28 18:28:17 +03:00
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ecx edx edi
|
|
|
|
|
|
|
|
lea edi, [buf]
|
|
|
|
add edi, 15
|
2013-07-24 23:15:08 +04:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
mov eax, [_val]
|
2013-07-24 23:15:08 +04:00
|
|
|
mov [bNeg],0
|
2012-04-12 14:13:30 +04:00
|
|
|
or eax, eax
|
|
|
|
jns @f
|
2013-07-24 23:15:08 +04:00
|
|
|
mov [bNeg],1
|
2012-04-12 14:13:30 +04:00
|
|
|
neg eax
|
2013-07-24 23:15:08 +04:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
@@: mov ecx, 10
|
|
|
|
@@: xor edx, edx
|
|
|
|
idiv ecx
|
|
|
|
add dl, '0'
|
|
|
|
mov [edi], dl
|
|
|
|
dec edi
|
|
|
|
or eax, eax
|
|
|
|
jnz @b
|
2013-07-24 23:15:08 +04:00
|
|
|
|
|
|
|
cmp [bNeg],0
|
|
|
|
je @f
|
|
|
|
mov byte[edi], '-'
|
|
|
|
dec edi
|
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
lea eax, [buf]
|
|
|
|
add eax, 15
|
|
|
|
sub eax, edi
|
|
|
|
inc edi
|
|
|
|
|
2013-07-24 23:15:08 +04:00
|
|
|
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
stdcall ini.set_str, [_f_name], [_sec_name], [_key_name], edi, eax
|
|
|
|
|
|
|
|
pop edi edx ecx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.get_color _f_name, _sec_name, _key_name, _def_val ;//////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Read color ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _def_val = default value to return if no key, section or file found <dword> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = [_def_val] (error) / found key value <dword> ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
buf rb 14
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ebx esi edi
|
|
|
|
|
|
|
|
lea esi, [buf]
|
|
|
|
stdcall ini.get_str, [_f_name], [_sec_name], [_key_name], esi, 14, 0
|
|
|
|
cmp byte[esi],0
|
|
|
|
je .exit_error
|
|
|
|
|
|
|
|
xor ebx, ebx
|
|
|
|
stdcall libini._.str_to_int
|
|
|
|
movzx ebx, al
|
|
|
|
shl ebx, 16
|
|
|
|
lodsb
|
|
|
|
cmp al, ','
|
|
|
|
jne @f
|
|
|
|
stdcall libini._.str_to_int
|
|
|
|
mov bh, al
|
|
|
|
lodsb
|
|
|
|
cmp al, ','
|
|
|
|
jne @f
|
|
|
|
stdcall libini._.str_to_int
|
|
|
|
mov bl, al
|
|
|
|
|
|
|
|
@@: mov eax, ebx
|
|
|
|
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov eax, [_def_val]
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.set_color _f_name, _sec_name, _key_name, _val ;//////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Write color ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _val = value <dword> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = -1 (error) / 0 ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
buf rb 16
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ecx edx edi
|
|
|
|
|
|
|
|
lea edi, [buf]
|
|
|
|
mov ecx, 10
|
|
|
|
mov ebx, [_val]
|
|
|
|
mov eax, ebx
|
|
|
|
shr eax, 16
|
|
|
|
and eax, 0x0ff
|
|
|
|
stdcall libini._.int_to_str
|
|
|
|
mov byte[edi], ','
|
|
|
|
inc edi
|
|
|
|
movzx eax, bh
|
|
|
|
stdcall libini._.int_to_str
|
|
|
|
mov byte[edi], ','
|
|
|
|
inc edi
|
|
|
|
movzx eax, bl
|
|
|
|
stdcall libini._.int_to_str
|
|
|
|
|
|
|
|
lea eax, [buf]
|
|
|
|
sub edi, eax
|
|
|
|
|
|
|
|
stdcall ini.set_str, [_f_name], [_sec_name], [_key_name], eax, edi
|
|
|
|
|
|
|
|
pop edi edx ecx
|
|
|
|
ret
|
2009-11-28 18:28:17 +03:00
|
|
|
endp
|
|
|
|
|
2013-07-24 23:15:08 +04:00
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.del_section _f_name, _sec_name ;/////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Delete section and all key in this section ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 - success ;;
|
|
|
|
;< -1 - file not found ;;
|
|
|
|
;< 1 - section not found ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
funcFile rb 25
|
|
|
|
fileInfo rb 40
|
|
|
|
begMem rd 1
|
|
|
|
endMem rd 1
|
|
|
|
begDel rd 1
|
|
|
|
endDel rd 1
|
|
|
|
endl
|
|
|
|
push ebx ecx edi esi
|
|
|
|
mov dword[funcFile],5 ;get file info
|
|
|
|
mov dword[funcFile+4],0
|
|
|
|
mov dword[funcFile+8],0
|
|
|
|
mov dword[funcFile+12],0
|
|
|
|
lea eax,[fileInfo]
|
|
|
|
mov dword[funcFile+16],eax
|
|
|
|
mov byte[funcFile+20],0
|
|
|
|
m2m dword[funcFile+21],[_f_name]
|
|
|
|
lea ebx,[funcFile]
|
|
|
|
mcall 70
|
|
|
|
test eax,eax
|
|
|
|
jz @f
|
|
|
|
|
|
|
|
or eax,-1
|
|
|
|
pop esi edi ecx ebx
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
|
|
|
|
mov ecx,dword[fileInfo+32] ;allocation mem for all file
|
|
|
|
mcall 68,12
|
|
|
|
|
|
|
|
mov [begMem],eax
|
|
|
|
mov [endMem],eax
|
|
|
|
add [endMem],ecx
|
|
|
|
|
|
|
|
mov dword[funcFile],0 ;read file to buffer
|
|
|
|
mov dword[funcFile+12],ecx
|
|
|
|
mov dword[funcFile+16],eax
|
|
|
|
lea ebx,[funcFile]
|
|
|
|
mcall 70
|
|
|
|
|
|
|
|
mov edi,[begMem] ;search begin section
|
2013-08-06 23:40:30 +04:00
|
|
|
jmp .searchSect
|
|
|
|
.NoFindSect:
|
|
|
|
mov edi,[begDel]
|
2013-07-24 23:15:08 +04:00
|
|
|
.searchSect:
|
|
|
|
mov al,'['
|
|
|
|
repne scasb
|
|
|
|
test ecx,ecx
|
|
|
|
jnz @f
|
2013-08-06 23:40:30 +04:00
|
|
|
|
2013-07-24 23:15:08 +04:00
|
|
|
pop esi edi ecx ebx
|
|
|
|
mov eax,1
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
mov [begDel],edi
|
|
|
|
mov esi,[_sec_name]
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
test al,al
|
|
|
|
jz @f
|
|
|
|
scasb
|
2013-08-06 23:40:30 +04:00
|
|
|
jne .NoFindSect
|
2013-07-24 23:15:08 +04:00
|
|
|
jmp @b
|
|
|
|
@@:
|
|
|
|
cmp byte[edi],']'
|
2013-08-06 23:40:30 +04:00
|
|
|
jne .NoFindSect
|
2013-07-24 23:15:08 +04:00
|
|
|
|
2013-08-06 23:40:30 +04:00
|
|
|
mov edi,[begDel]
|
2013-07-24 23:15:08 +04:00
|
|
|
dec [begDel]
|
2013-08-06 23:40:30 +04:00
|
|
|
;search end section
|
2013-07-24 23:15:08 +04:00
|
|
|
.searchEndSect:
|
|
|
|
mov al,'['
|
|
|
|
repne scasb
|
|
|
|
|
|
|
|
dec edi
|
|
|
|
mov [endDel],edi
|
|
|
|
|
|
|
|
test ecx,ecx
|
|
|
|
jnz @f
|
|
|
|
jmp .SaveToFile
|
|
|
|
@@:
|
|
|
|
|
|
|
|
|
|
|
|
mov esi,[endDel]
|
|
|
|
mov edi,[begDel]
|
|
|
|
@@: lodsb
|
|
|
|
stosb
|
|
|
|
cmp esi,[endMem]
|
|
|
|
jb @b
|
|
|
|
|
|
|
|
.SaveToFile:
|
|
|
|
mov eax,dword[funcFile+12]
|
|
|
|
sub eax,[endDel]
|
|
|
|
add eax,[begDel]
|
2013-08-06 23:40:30 +04:00
|
|
|
dec eax
|
2013-07-24 23:15:08 +04:00
|
|
|
|
|
|
|
mov dword[funcFile],2 ;write buffer to file
|
|
|
|
mov dword[funcFile+12],eax
|
|
|
|
m2m dword[funcFile+16],[begMem]
|
|
|
|
lea ebx,[funcFile]
|
|
|
|
mcall 70
|
|
|
|
|
|
|
|
xor eax,eax
|
|
|
|
pop esi edi ecx ebx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-21 02:35:51 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc ini.get_shortcut _f_name, _sec_name, _key_name, _def_val, _modifiers ;///////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Read shortcut key ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _f_name = ini filename <asciiz> ;;
|
|
|
|
;> _sec_name = section name <asciiz> ;;
|
|
|
|
;> _key_name = key name <asciiz> ;;
|
|
|
|
;> _def_val = default value to return if no key, section or file found <dword> ;;
|
|
|
|
;> _modifiers = pointer to dword variable which receives modifiers state as in 66.4 <dword*> ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = [_def_val] (error) / shortcut key value as scancode <int> ;;
|
|
|
|
;< [[_modifiers]] = unchanged (error) / modifiers state for this shortcut <int> ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
buf rb 64
|
|
|
|
endl
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
push ebx esi edi
|
2009-12-21 02:35:51 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
lea esi, [buf]
|
|
|
|
stdcall ini.get_str, [_f_name], [_sec_name], [_key_name], esi, 64, 0
|
|
|
|
cmp byte[esi],0
|
|
|
|
je .exit_error
|
2009-12-21 02:35:51 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
xor ebx, ebx ; ebx holds the value of modifiers
|
2009-12-21 02:35:51 +03:00
|
|
|
.loop:
|
|
|
|
; test for end
|
2012-04-12 14:13:30 +04:00
|
|
|
xor eax, eax
|
|
|
|
cmp byte [esi], al
|
|
|
|
jz .exit_ok ; exit with scancode zero
|
2009-12-21 02:35:51 +03:00
|
|
|
; skip all '+'s
|
2012-04-12 14:13:30 +04:00
|
|
|
cmp byte [esi], '+'
|
|
|
|
jnz @f
|
|
|
|
inc esi
|
|
|
|
jmp .loop
|
2009-12-21 02:35:51 +03:00
|
|
|
@@:
|
|
|
|
; test for names
|
2012-04-12 14:13:30 +04:00
|
|
|
mov edi, .names_table
|
|
|
|
xor edx, edx
|
2009-12-21 02:35:51 +03:00
|
|
|
.names_loop:
|
2012-04-12 14:13:30 +04:00
|
|
|
movzx ecx, byte [edi]
|
|
|
|
inc edi
|
|
|
|
push esi
|
2009-12-21 02:35:51 +03:00
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
lodsb
|
|
|
|
or al, 20h
|
|
|
|
scasb
|
|
|
|
loopz @b
|
|
|
|
jz .name_found
|
|
|
|
pop esi
|
|
|
|
lea edi, [edi+ecx+4]
|
|
|
|
inc edx
|
|
|
|
cmp byte [edi], 0
|
|
|
|
jnz .names_loop
|
2009-12-21 02:35:51 +03:00
|
|
|
; special test: functional keys F<number>
|
2012-04-12 14:13:30 +04:00
|
|
|
cmp byte [esi], 'f'
|
|
|
|
jz @f
|
|
|
|
cmp byte [esi], 'F'
|
|
|
|
jnz .no_fx
|
2009-12-21 02:35:51 +03:00
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov edi, esi
|
|
|
|
inc esi
|
|
|
|
call libini._.str_to_int
|
|
|
|
test eax, eax
|
2012-12-15 18:00:13 +04:00
|
|
|
jnz .fx
|
2012-04-12 14:13:30 +04:00
|
|
|
mov esi, edi
|
2009-12-21 02:35:51 +03:00
|
|
|
.no_fx:
|
|
|
|
; name not found, that must be usual key
|
2012-04-12 14:13:30 +04:00
|
|
|
movzx eax, byte [esi]
|
|
|
|
stdcall libini._.ascii_to_scan, eax
|
|
|
|
test eax, eax
|
|
|
|
jz .exit_error
|
2009-12-21 02:35:51 +03:00
|
|
|
; all is ok
|
|
|
|
.exit_ok:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov ecx, [_modifiers]
|
|
|
|
test ecx, ecx
|
|
|
|
jz @f
|
|
|
|
mov [ecx], ebx
|
2009-12-21 02:35:51 +03:00
|
|
|
|
|
|
|
@@:
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-12-21 02:35:51 +03:00
|
|
|
|
|
|
|
.exit_error:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov eax, [_def_val]
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
2009-12-21 02:35:51 +03:00
|
|
|
; handler for Fx
|
|
|
|
; eax = number
|
|
|
|
.fx:
|
2012-04-12 14:13:30 +04:00
|
|
|
cmp eax, 10
|
|
|
|
ja @f
|
|
|
|
add eax, 3Bh-1
|
|
|
|
jmp .exit_ok
|
2009-12-21 02:35:51 +03:00
|
|
|
@@:
|
2012-04-12 14:13:30 +04:00
|
|
|
add eax, 57h-11
|
|
|
|
jmp .exit_ok
|
2009-12-21 02:35:51 +03:00
|
|
|
; handlers for names
|
|
|
|
.name_found:
|
2012-04-12 14:13:30 +04:00
|
|
|
pop eax ; ignore saved esi
|
|
|
|
call dword [edi]
|
|
|
|
cmp edx, .num_modifiers
|
|
|
|
jae .exit_ok
|
|
|
|
jmp .loop
|
2009-12-21 02:35:51 +03:00
|
|
|
; modifiers
|
|
|
|
; syntax of value for each modifier:
|
|
|
|
; 0 = none, 1 = exactly one of L+R, 2 = both L+R, 3 = L, 4 = R
|
|
|
|
; Logic for switching: LShift+RShift=LShift+Shift=Shift+Shift, LShift+LShift=LShift
|
|
|
|
; generic modifier: 0->1->2->2, 3->2, 4->2
|
|
|
|
; left modifier: 0->3->3, 1->2->2, 4->2
|
|
|
|
; right modifier: 0->4->4, 1->2->2, 3->2
|
|
|
|
; Shift corresponds to first hex digit, Ctrl - second, Alt - third
|
|
|
|
macro shortcut_handle_modifiers name,reg,shift
|
|
|
|
{
|
|
|
|
local .set2,.set3,.set4
|
2012-04-12 14:13:30 +04:00
|
|
|
.#name#_handler: ; generic modifier
|
|
|
|
test reg, 0xF
|
|
|
|
jnz .set2
|
2009-12-21 02:35:51 +03:00
|
|
|
if shift
|
2012-04-12 14:13:30 +04:00
|
|
|
or reg, 1 shl shift
|
2009-12-21 02:35:51 +03:00
|
|
|
else
|
2012-04-12 14:13:30 +04:00
|
|
|
inc reg
|
2009-12-21 02:35:51 +03:00
|
|
|
end if
|
2012-04-12 14:13:30 +04:00
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
.set2:
|
2012-04-12 14:13:30 +04:00
|
|
|
and reg, not (0xF shl shift)
|
|
|
|
or reg, 2 shl shift
|
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
.l#name#_handler:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov al, reg
|
|
|
|
and al, 0xF shl shift
|
|
|
|
jz .set3
|
|
|
|
cmp al, 3 shl shift
|
|
|
|
jnz .set2
|
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
.set3:
|
2012-04-12 14:13:30 +04:00
|
|
|
add reg, 3 shl shift
|
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
.r#name#_handler:
|
2012-04-12 14:13:30 +04:00
|
|
|
mov al, reg
|
|
|
|
and al, 0xF shl shift
|
|
|
|
jz .set4
|
|
|
|
cmp al, 4 shl shift
|
|
|
|
jnz .set2
|
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
.set4:
|
2012-04-12 14:13:30 +04:00
|
|
|
add reg, 4 shl shift
|
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
}
|
|
|
|
shortcut_handle_modifiers shift,bl,0
|
|
|
|
shortcut_handle_modifiers ctrl,bl,4
|
|
|
|
shortcut_handle_modifiers alt,bh,0
|
|
|
|
; names of keys
|
|
|
|
.name_handler:
|
2012-04-12 14:13:30 +04:00
|
|
|
movzx eax, byte [.names_scancodes+edx-.num_modifiers]
|
|
|
|
retn
|
2009-12-21 02:35:51 +03:00
|
|
|
endp
|
|
|
|
|
|
|
|
; note: comparison ignores case, so this table keeps lowercase names
|
|
|
|
; macro does this
|
|
|
|
macro shortcut_name_with_handler name,handler
|
|
|
|
{
|
|
|
|
local .start, .end
|
2012-04-12 14:13:30 +04:00
|
|
|
db .end - .start
|
2009-12-21 02:35:51 +03:00
|
|
|
.start:
|
2012-04-12 14:13:30 +04:00
|
|
|
db name
|
2009-12-21 02:35:51 +03:00
|
|
|
.end:
|
|
|
|
repeat .end - .start
|
2012-04-12 14:13:30 +04:00
|
|
|
load .a byte from .start + % - 1
|
|
|
|
store byte .a or 0x20 at .start + % - 1
|
2009-12-21 02:35:51 +03:00
|
|
|
end repeat
|
2012-04-12 14:13:30 +04:00
|
|
|
dd handler
|
2009-12-21 02:35:51 +03:00
|
|
|
}
|
|
|
|
macro shortcut_name [name]
|
|
|
|
{
|
2012-04-12 14:13:30 +04:00
|
|
|
shortcut_name_with_handler name, .name_handler
|
2009-12-21 02:35:51 +03:00
|
|
|
}
|
2013-07-24 23:15:08 +04:00
|
|
|
|
2009-12-21 02:35:51 +03:00
|
|
|
; all names here must be in english
|
|
|
|
; ... or modify lowercasing in macro and in comparison
|
|
|
|
.names_table:
|
|
|
|
; generic modifiers
|
2012-04-12 14:13:30 +04:00
|
|
|
shortcut_name_with_handler 'Ctrl', .ctrl_handler
|
|
|
|
shortcut_name_with_handler 'Alt', .alt_handler
|
|
|
|
shortcut_name_with_handler 'Shift', .shift_handler
|
2009-12-21 02:35:51 +03:00
|
|
|
; concrete modifiers
|
2012-04-12 14:13:30 +04:00
|
|
|
shortcut_name_with_handler 'LCtrl', .lctrl_handler
|
|
|
|
shortcut_name_with_handler 'RCtrl', .rctrl_handler
|
|
|
|
shortcut_name_with_handler 'LAlt', .lalt_handler
|
|
|
|
shortcut_name_with_handler 'RAlt', .ralt_handler
|
|
|
|
shortcut_name_with_handler 'LShift', .lshift_handler
|
|
|
|
shortcut_name_with_handler 'RShift', .rshift_handler
|
2009-12-21 02:35:51 +03:00
|
|
|
.num_modifiers = 9
|
|
|
|
; symbolic names of keys
|
2012-04-12 14:13:30 +04:00
|
|
|
shortcut_name 'Home', 'End', 'PgUp', 'PgDn', 'Ins', 'Insert', 'Del', 'Delete'
|
|
|
|
shortcut_name 'Tab', 'Plus', 'Esc', 'Enter', 'Backspace', 'Space', 'Left', 'Right'
|
|
|
|
shortcut_name 'Up', 'Down'
|
2009-12-21 02:35:51 +03:00
|
|
|
; end of table
|
2012-04-12 14:13:30 +04:00
|
|
|
db 0
|
2009-12-21 02:35:51 +03:00
|
|
|
ini.get_shortcut.names_scancodes:
|
|
|
|
; scancodes for 'Home' ... 'Down'
|
2012-04-12 14:13:30 +04:00
|
|
|
db 47h, 4Fh, 49h, 51h, 52h, 52h, 53h, 53h
|
|
|
|
db 0Fh, 4Eh, 01h, 1Ch, 0Eh, 39h, 4Bh, 4Dh
|
|
|
|
db 48h, 50h
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Imported functions section ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
|
|
|
|
align 16
|
|
|
|
@IMPORT:
|
|
|
|
|
|
|
|
library \
|
2012-04-12 14:13:30 +04:00
|
|
|
libio , 'libio.obj'
|
2009-11-28 18:28:17 +03:00
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
import libio , \
|
|
|
|
file.size , 'file_size' , \
|
|
|
|
file.open , 'file_open' , \
|
|
|
|
file.read , 'file_read' , \
|
|
|
|
file.write , 'file_write' , \
|
|
|
|
file.seek , 'file_seek' , \
|
|
|
|
file.eof? , 'file_iseof' , \
|
|
|
|
file.seteof , 'file_seteof' , \
|
|
|
|
file.tell , 'file_tell' , \
|
|
|
|
file.close , 'file_close'
|
2009-11-28 18:28:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Exported functions section ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
|
|
|
|
align 16
|
|
|
|
@EXPORT:
|
|
|
|
|
2012-04-12 14:13:30 +04:00
|
|
|
export \
|
|
|
|
libini._.init , 'lib_init' , \
|
|
|
|
0x00080009 , 'version' , \
|
|
|
|
ini.enum_sections , 'ini_enum_sections' , \
|
|
|
|
ini.enum_keys , 'ini_enum_keys' , \
|
|
|
|
ini.get_str , 'ini_get_str' , \
|
|
|
|
ini.get_int , 'ini_get_int' , \
|
|
|
|
ini.get_color , 'ini_get_color' , \
|
|
|
|
ini.set_str , 'ini_set_str' , \
|
|
|
|
ini.set_int , 'ini_set_int' , \
|
|
|
|
ini.set_color , 'ini_set_color' , \
|
2013-07-24 23:15:08 +04:00
|
|
|
ini.get_shortcut , 'ini_get_shortcut' , \
|
|
|
|
ini.del_section , 'ini_del_section'
|