From 61550b159587fd7e88863f26809381877443b224 Mon Sep 17 00:00:00 2001 From: vkos Date: Sun, 25 Oct 2009 18:43:31 +0000 Subject: [PATCH] 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 --- .../libraries/libs-dev/libini/find_str.asm | 49 +++++++++++++++ .../libraries/libs-dev/libini/libini.asm | 60 +++++++++++++++++-- 2 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 programs/develop/libraries/libs-dev/libini/find_str.asm diff --git a/programs/develop/libraries/libs-dev/libini/find_str.asm b/programs/develop/libraries/libs-dev/libini/find_str.asm new file mode 100644 index 0000000000..b99f2cf0f2 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libini/find_str.asm @@ -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 . ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; 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 diff --git a/programs/develop/libraries/libs-dev/libini/libini.asm b/programs/develop/libraries/libs-dev/libini/libini.asm index f7e544cf69..8d10570cd6 100644 --- a/programs/develop/libraries/libs-dev/libini/libini.asm +++ b/programs/develop/libraries/libs-dev/libini/libini.asm @@ -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 ;; +;> _sec_name = section name ;; +;> _key_name = key name ;; +;> _option_list = list of options ;; +;> _length = maximum length of string ;; +;> _def_val = default value to return if no key, section or file found ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = [_def_val] (error) / number of option string in _option_list ;; +;;================================================================================================;; +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';, \