libini: get/set color values; bugfixes

git-svn-id: svn://kolibrios.org@988 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Mihail Semenyako (mike.dld) 2008-12-29 19:09:45 +00:00
parent 7e149d6d99
commit e1b2086036
2 changed files with 169 additions and 15 deletions

View File

@ -17,6 +17,9 @@
;; ;; ;; ;;
;;================================================================================================;; ;;================================================================================================;;
;; ;; ;; ;;
;; 2008-12-29 (mike.dld) ;;
;; bug-fixes: ;;
;; - unnecessary 'stosb' in ini.get_str was causing problems ;;
;; 2008-08-06 (mike.dld) ;; ;; 2008-08-06 (mike.dld) ;;
;; changes: ;; ;; changes: ;;
;; - split private procs into libini_p.asm, added comments ;; ;; - split private procs into libini_p.asm, added comments ;;
@ -306,31 +309,22 @@ endl
jnz .exit_error jnz .exit_error
stdcall libini._.low.read_value, [f_addr], [_buffer], [_buf_len] stdcall libini._.low.read_value, [f_addr], [_buffer], [_buf_len]
; mov edi, [_buffer]
; @@: dec [_buf_len]
; jz @f
; stdcall ini.aux.get_char, [f_addr]
; or al, al
; jz @f
; cmp al, 13
; je @f
; cmp al, 10
; je @f
; stosb
; jmp @b
@@: invoke file.close, [f.fh] @@: invoke file.close, [f.fh]
invoke mem.free, [f.buf] invoke mem.free, [f.buf]
xor eax, eax xor eax, eax
stosb
pop edi esi ebx pop edi esi ebx
ret ret
.exit_error: .exit_error:
invoke file.close, [f.fh] invoke file.close, [f.fh]
invoke mem.free, [f.buf] invoke mem.free, [f.buf]
mov esi, [_def_val]
mov edi, [_buffer] mov edi, [_buffer]
mov esi, [_def_val]
xor al, al
or esi, esi
jz .exit_error.2
@@: lodsb @@: lodsb
.exit_error.2:
stosb stosb
or al, al or al, al
jnz @b jnz @b
@ -572,6 +566,98 @@ endl
ret ret
endp 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
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
.exit_error:
mov eax, [_def_val]
pop edi esi ebx
ret
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
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
endp
;;================================================================================================;; ;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;; ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
@ -619,5 +705,7 @@ export \
ini.enum_keys , 'ini.enum_keys' , \ ini.enum_keys , 'ini.enum_keys' , \
ini.get_str , 'ini.get_str' , \ ini.get_str , 'ini.get_str' , \
ini.get_int , 'ini.get_int' , \ ini.get_int , 'ini.get_int' , \
ini.get_color , 'ini.get_color' , \
ini.set_str , 'ini.set_str' , \ ini.set_str , 'ini.set_str' , \
ini.set_int , 'ini.set_int' ini.set_int , 'ini.set_int' , \
ini.set_color , 'ini.set_color'

View File

@ -573,3 +573,69 @@ proc libini._.low.read_value _f_addr, _buffer, _buf_len ;///////////////////////
@@: pop eax edi @@: pop eax edi
ret ret
endp endp
;;================================================================================================;;
proc libini._.str_to_int ;////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;------------------------------------------------------------------------------------------------;;
;> esi = string buffer address ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = binary number representation (no overflow checks made) ;;
;;================================================================================================;;
push edx
xor eax, eax
xor edx, edx
@@: lodsb
cmp al, '0'
jb @f
cmp al, '9'
ja @f
add eax, -'0'
imul edx, 10
add edx, eax
jmp @b
@@: dec esi
mov eax, edx
pop edx
ret
endp
;;================================================================================================;;
proc libini._.int_to_str ;////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;------------------------------------------------------------------------------------------------;;
;> eax = number to convert ;;
;> ecx = base ;;
;> edi = string buffer address ;;
;;------------------------------------------------------------------------------------------------;;
;< --- TBD --- ;;
;;================================================================================================;;
push ecx edx
or eax, eax
jns @f
mov byte[edi], '-'
inc edi
@@: call .recurse
pop edx ecx
ret
.recurse:
cmp eax,ecx
jb @f
xor edx,edx
div ecx
push edx
call .recurse
pop eax
@@: cmp al,10
sbb al,0x69
das
stosb
retn
endp