forked from KolibriOS/kolibrios
Added function get_option_str: read string, compare with list of possible & return its' number
git-svn-id: svn://kolibrios.org@1234 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f064c3cbc1
commit
61550b1595
49
programs/develop/libraries/libs-dev/libini/find_str.asm
Normal file
49
programs/develop/libraries/libs-dev/libini/find_str.asm
Normal file
@ -0,0 +1,49 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Copyright (C) Vasiliy Kosenko (vkos), 2009 ;;
|
||||
;; This program is free software: you can redistribute it and/or modify it under the terms of ;;
|
||||
;; the GNU General Public License as published by the Free Software Foundation, either version 3 ;;
|
||||
;; of the License, or (at your option) any later version. ;;
|
||||
;; ;;
|
||||
;; This program 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 General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with this program. ;;
|
||||
;; If not, see <http://www.gnu.org/licenses/>. ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Now there is only one function now: find string in array of strings ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; int str_find_in_array(char **options, char *str)
|
||||
;; NOTE: options should be zero-ended array
|
||||
str_find_in_array:
|
||||
push ebx
|
||||
|
||||
mov ebx, [esp+8]
|
||||
cld
|
||||
.convert_nxt:
|
||||
add ebx, 4
|
||||
mov esi, dword [ebx-4]
|
||||
test esi, esi
|
||||
je .set_default ;; String is incorrect, so set default
|
||||
mov edi, [esp+0xc]
|
||||
.conv_loop:
|
||||
cmpsb
|
||||
jne .convert_nxt ;; Not equal, so try next
|
||||
dec esi
|
||||
lodsb
|
||||
test al, al
|
||||
jne .conv_loop
|
||||
.found:
|
||||
sub ebx, [esp+8]
|
||||
shr ebx, 2
|
||||
mov eax, ebx
|
||||
.exit:
|
||||
dec eax
|
||||
pop ebx
|
||||
ret
|
||||
.set_default:
|
||||
xor eax, eax
|
||||
jmp .exit
|
@ -1,5 +1,7 @@
|
||||
;;================================================================================================;;
|
||||
;;//// libini.asm //// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////;;
|
||||
;;//// libini.asm ////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;//// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////////////////;;
|
||||
;;//// (c) Vasiliy Kosenko, 2009 ///////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; This file is part of Common development libraries (Libs-Dev). ;;
|
||||
@ -17,6 +19,9 @@
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 2009-10-25 (vkos) ;;
|
||||
;; new features: ;;
|
||||
;; - new function: ini.get_option_str ;;
|
||||
;; 2009-03-08 (mike.dld) ;;
|
||||
;; bug-fixes: ;;
|
||||
;; - moved buffer bound check in libini._.low.read_value up (reported by Insolor) ;;
|
||||
@ -72,6 +77,10 @@ section '.flat' code readable align 16
|
||||
|
||||
include 'libini_p.asm'
|
||||
|
||||
;; For ini.get_option_str
|
||||
str_find_in_array fix libini._.find_string
|
||||
include 'find_str.asm'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc ini.enum_sections _f_name, _callback ;///////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
@ -657,6 +666,49 @@ endl
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc ini.get_option_str _f_name, _sec_name, _key_name, _option_list, _length, _def_val ;//////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Read string, compare with list of possible & return its' number ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _f_name = ini filename <asciiz> ;;
|
||||
;> _sec_name = section name <asciiz> ;;
|
||||
;> _key_name = key name <asciiz> ;;
|
||||
;> _option_list = list of options <pointer to zero-ended archive of asciiz-pointers> ;;
|
||||
;> _length = maximum length of string ;;
|
||||
;> _def_val = default value to return if no key, section or file found <dword> ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = [_def_val] (error) / number of option string in _option_list <dword> ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
buff rb ini.MAX_VALUE_LEN
|
||||
endl
|
||||
|
||||
lea eax, [buff]
|
||||
stdcall ini.get_str, [_f_name], [_sec_name], [_key_name], eax, ini.MAX_VALUE_LEN
|
||||
|
||||
inc eax
|
||||
test eax, eax
|
||||
je .default
|
||||
|
||||
;; Now convert option from string to number
|
||||
lea eax, [buff]
|
||||
sub esp, 4
|
||||
stdcall libini._.find_string, [_option_list], eax
|
||||
add esp, 4
|
||||
|
||||
inc eax
|
||||
test eax, eax
|
||||
je .default
|
||||
dec eax
|
||||
|
||||
.default:
|
||||
mov eax, dword [_def_val]
|
||||
|
||||
.exit:
|
||||
; leave
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
@ -697,8 +749,7 @@ import libio , \
|
||||
align 16
|
||||
@EXPORT:
|
||||
|
||||
export \
|
||||
libini._.init , 'lib_init' , \
|
||||
export libini._.init , 'lib_init' , \
|
||||
0x00080008 , 'version' , \
|
||||
ini.enum_sections , 'ini_enum_sections' , \
|
||||
ini.enum_keys , 'ini_enum_keys' , \
|
||||
@ -707,4 +758,5 @@ export \
|
||||
ini.get_color , 'ini_get_color' , \
|
||||
ini.set_str , 'ini_set_str' , \
|
||||
ini.set_int , 'ini_set_int' , \
|
||||
ini.set_color , 'ini_set_color'
|
||||
ini.set_color , 'ini_set_color' , \
|
||||
ini.get_option_str, 'ini_get_option_str';, \
|
||||
|
Loading…
Reference in New Issue
Block a user