fix in libini._.low.read_value (reported by Insolor)

comments support (lines starting with ';' by default)
version bump

git-svn-id: svn://kolibrios.org@1048 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Mihail Semenyako (mike.dld) 2009-03-08 10:46:47 +00:00
parent 3021284b0a
commit b7c6be3b16
4 changed files with 25 additions and 46 deletions

View File

@ -74,8 +74,6 @@ endp
s_key1 db "LeftViewMode",0 s_key1 db "LeftViewMode",0
s_key2 db "RightViewMode",0 s_key2 db "RightViewMode",0
s_null db "",0
macro wildcard_test_data label1, label2, label3, [str1, str2, res] macro wildcard_test_data label1, label2, label3, [str1, str2, res]
{ {
common common
@ -170,10 +168,10 @@ START:
mov dword[buf],'103' mov dword[buf],'103'
invoke ini.set_str,s_ini,s_sec,s_key2,buf,3 invoke ini.set_str,s_ini,s_sec,s_key2,buf,3
invoke ini.get_str,s_ini,s_sec,s_key1,buf,1024,s_null invoke ini.get_str,s_ini,s_sec,s_key1,buf,1024,0
cmp dword[buf],'102' cmp dword[buf],'102'
jne exit jne exit
invoke ini.get_str,s_ini,s_sec,s_key2,buf,1024,s_null invoke ini.get_str,s_ini,s_sec,s_key2,buf,1024,0
cmp dword[buf],'103' cmp dword[buf],'103'
jne exit jne exit

View File

@ -17,6 +17,12 @@
;; ;; ;; ;;
;;================================================================================================;; ;;================================================================================================;;
;; ;; ;; ;;
;; 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) ;; ;; 2008-12-29 (mike.dld) ;;
;; bug-fixes: ;; ;; bug-fixes: ;;
;; - unnecessary 'stosb' in ini.get_str was causing problems ;; ;; - unnecessary 'stosb' in ini.get_str was causing problems ;;
@ -117,8 +123,6 @@ endl
stdcall libini._.get_char, [f_addr] stdcall libini._.get_char, [f_addr]
stdcall libini._.skip_spaces, [f_addr] stdcall libini._.skip_spaces, [f_addr]
; inc esi
; dec [f.cnt]
mov edi, [sec_buf] mov edi, [sec_buf]
@@: stdcall libini._.get_char, [f_addr] @@: stdcall libini._.get_char, [f_addr]
cmp al, ']' cmp al, ']'
@ -385,7 +389,6 @@ endl
.modify_key.ex: .modify_key.ex:
invoke file.tell, [f.fh] invoke file.tell, [f.fh]
sub eax, [f.cnt] sub eax, [f.cnt]
; dec eax
invoke file.seek, [f.fh], eax, SEEK_SET invoke file.seek, [f.fh], eax, SEEK_SET
invoke file.write, [f.fh], [_buffer], [_buf_len] invoke file.write, [f.fh], [_buffer], [_buf_len]
@ -399,8 +402,6 @@ endl
push edi push edi
.create_key.ex: .create_key.ex:
; mov word[edi], 0x0A0D
; add edi,2
mov esi, [_key_name] mov esi, [_key_name]
call libini._.string_copy call libini._.string_copy
mov byte[edi], '=' mov byte[edi], '='
@ -427,13 +428,9 @@ endl
push edi push edi
mov esi, [_sec_name] mov esi, [_sec_name]
; mov dword[edi], 0x0A0D + ('[' shl 16)
; add edi, 3
mov byte[edi], '[' mov byte[edi], '['
inc edi inc edi
call libini._.string_copy call libini._.string_copy
; mov byte[edi], ']'
; inc edi
mov dword[edi], ']' + (0x0A0D shl 8) mov dword[edi], ']' + (0x0A0D shl 8)
add edi, 3 add edi, 3
@ -485,7 +482,7 @@ endl
or eax, eax or eax, eax
jnz .exit_error jnz .exit_error
stdcall libini._.skip_nonblanks, [f_addr] stdcall libini._.skip_spaces, [f_addr]
xor eax, eax xor eax, eax
xor ebx, ebx xor ebx, ebx
xor edx, edx xor edx, edx
@ -702,7 +699,7 @@ align 16
export \ export \
libini._.init , 'lib_init' , \ libini._.init , 'lib_init' , \
0x00040006 , 'version' , \ 0x00040007 , 'version' , \
ini.enum_sections , 'ini.enum_sections' , \ ini.enum_sections , 'ini.enum_sections' , \
ini.enum_keys , 'ini.enum_keys' , \ ini.enum_keys , 'ini.enum_keys' , \
ini.get_str , 'ini.get_str' , \ ini.get_str , 'ini.get_str' , \

View File

@ -60,12 +60,6 @@ proc libini._.unget_char _f ;///////////////////////////////////////////////////
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;< --- TBD --- ;; ;< --- TBD --- ;;
;;================================================================================================;; ;;================================================================================================;;
;push ecx
;mov ecx,[f]
;inc [ecx+INIFILE.cnt]
;dec esi
;pop ecx
;ret
push eax ecx push eax ecx
mov ecx, [_f] mov ecx, [_f]
inc [ecx + IniFile.cnt] inc [ecx + IniFile.cnt]
@ -74,8 +68,7 @@ proc libini._.unget_char _f ;///////////////////////////////////////////////////
cmp [ecx + IniFile.cnt], eax cmp [ecx + IniFile.cnt], eax
jle @f jle @f
stdcall libini._.unload_block, [_f] stdcall libini._.unload_block, [_f]
@@: ;mov al,[esi-1] @@: pop ecx eax
pop ecx eax
ret ret
endp endp
@ -116,8 +109,11 @@ proc libini._.skip_nonblanks _f ;///////////////////////////////////////////////
je @b je @b
cmp al, 9 cmp al, 9
je @b je @b
cmp al, ini.COMMENT_CHAR
jne @f
stdcall libini._.skip_line, [_f]
jmp @b
@@: stdcall libini._.unget_char, [_f] @@: stdcall libini._.unget_char, [_f]
;inc [ecx+INIFILE.cnt]
ret ret
endp endp
@ -137,7 +133,6 @@ proc libini._.skip_spaces _f ;//////////////////////////////////////////////////
cmp al, 9 cmp al, 9
je @b je @b
@@: stdcall libini._.unget_char, [_f] @@: stdcall libini._.unget_char, [_f]
;inc [ecx+INIFILE.cnt]
ret ret
endp endp
@ -159,7 +154,6 @@ proc libini._.skip_line _f ;////////////////////////////////////////////////////
cmp al, 10 cmp al, 10
jne @b jne @b
@@: stdcall libini._.unget_char, [_f] @@: stdcall libini._.unget_char, [_f]
;inc [ecx+INIFILE.cnt]
ret ret
endp endp
@ -178,7 +172,7 @@ proc libini._.unload_block _f ;/////////////////////////////////////////////////
add eax, -ini.BLOCK_SIZE add eax, -ini.BLOCK_SIZE
invoke file.seek, [ebx + IniFile.fh], eax, SEEK_SET invoke file.seek, [ebx + IniFile.fh], eax, SEEK_SET
stdcall libini._.preload_block, ebx stdcall libini._.preload_block, ebx
add esi, eax ; ini.BLOCK_SIZE add esi, eax
mov [ebx + IniFile.cnt], 0 mov [ebx + IniFile.cnt], 0
pop ecx ebx eax pop ecx ebx eax
ret ret
@ -208,8 +202,7 @@ proc libini._.preload_block _f ;////////////////////////////////////////////////
mov esi,[ebx + IniFile.buf] mov esi,[ebx + IniFile.buf]
cmp eax,ini.BLOCK_SIZE cmp eax,ini.BLOCK_SIZE
jl @f jl @f
;dec eax @@: mov [ebx + IniFile.cnt], eax
@@: mov [ebx + IniFile.cnt], eax;ini.BLOCK_SIZE-1
mov [ebx + IniFile.bsize], eax mov [ebx + IniFile.bsize], eax
pop ecx ebx eax pop ecx ebx eax
ret ret
@ -273,9 +266,7 @@ endl
mov ecx, [ebx + IniFile.cnt] mov ecx, [ebx + IniFile.cnt]
mov ebx, [ebx + IniFile.fh] mov ebx, [ebx + IniFile.fh]
invoke file.tell, ebx invoke file.tell, ebx
; push eax
sub eax, ecx sub eax, ecx
; dec eax
invoke file.seek, ebx, eax, SEEK_SET invoke file.seek, ebx, eax, SEEK_SET
@@: invoke file.seek, ebx, [_delta], SEEK_CUR @@: invoke file.seek, ebx, [_delta], SEEK_CUR
invoke file.eof?, ebx invoke file.eof?, ebx
@ -285,17 +276,15 @@ endl
mov ecx, eax mov ecx, eax
mov eax, [_delta] mov eax, [_delta]
neg eax neg eax
sub eax, ecx;ini.BLOCK_SIZE sub eax, ecx
invoke file.seek, ebx, eax, SEEK_CUR invoke file.seek, ebx, eax, SEEK_CUR
invoke file.write, ebx, [buf], ecx;ini.BLOCK_SIZE invoke file.write, ebx, [buf], ecx
jmp @b jmp @b
.done: .done:
mov eax, [_delta] mov eax, [_delta]
neg eax neg eax
invoke file.seek, ebx, eax, SEEK_CUR invoke file.seek, ebx, eax, SEEK_CUR
invoke file.seteof, ebx invoke file.seteof, ebx
; pop eax
; invoke file.seek, ebx, SEEK_SET;, eax
stdcall libini._.reload_block, [_f] stdcall libini._.reload_block, [_f]
invoke mem.free, [buf] invoke mem.free, [buf]
pop ecx ebx pop ecx ebx
@ -313,7 +302,6 @@ endl
mov ecx, [ebx + IniFile.cnt] mov ecx, [ebx + IniFile.cnt]
mov ebx, [ebx + IniFile.fh] mov ebx, [ebx + IniFile.fh]
invoke file.tell, ebx invoke file.tell, ebx
; push eax
sub eax, ecx sub eax, ecx
lea edx, [eax - 1] lea edx, [eax - 1]
push edx push edx
@ -339,11 +327,6 @@ endl
@@: @@:
.skip.2: .skip.2:
add esp, 4 add esp, 4
; mov eax,[delta]
; neg eax
; invoke file.seek,ebx,SEEK_CUR,eax
; pop eax
; invoke file.seek,ebx,SEEK_SET;,eax
stdcall libini._.reload_block, [_f] stdcall libini._.reload_block, [_f]
invoke mem.free, [buf] invoke mem.free, [buf]
pop ecx ebx pop ecx ebx
@ -451,8 +434,6 @@ proc libini._.find_section _f, _sec_name ;//////////////////////////////////////
jnz .exit_error jnz .exit_error
stdcall libini._.get_char, [_f] stdcall libini._.get_char, [_f]
; inc esi
; dec [ecx + IniFile.cnt]
stdcall libini._.skip_spaces, [_f] stdcall libini._.skip_spaces, [_f]
mov edi, [_sec_name] mov edi, [_sec_name]
@@: stdcall libini._.get_char, [_f] @@: stdcall libini._.get_char, [_f]
@ -564,12 +545,13 @@ proc libini._.low.read_value _f_addr, _buffer, _buf_len ;///////////////////////
@@: stdcall libini._.unget_char, [_f_addr] @@: stdcall libini._.unget_char, [_f_addr]
mov byte[edi], 0 mov byte[edi], 0
dec edi dec edi
@@: cmp byte[edi], 32 @@: cmp edi, [_buffer]
jb @f
cmp byte[edi], 32
ja @f ja @f
mov byte[edi], 0 mov byte[edi], 0
dec edi dec edi
cmp edi, [_buffer] jmp @b
jae @b
@@: pop eax edi @@: pop eax edi
ret ret
endp endp

View File

@ -23,6 +23,8 @@ ini.MAX_VALUE_LEN = 4096
ini.MEM_SIZE = 4096 ini.MEM_SIZE = 4096
ini.BLOCK_SIZE = ini.MEM_SIZE / 2 ini.BLOCK_SIZE = ini.MEM_SIZE / 2
ini.COMMENT_CHAR = ';'
struct IniFile struct IniFile
fh dd ? fh dd ?
buf dd ? buf dd ?