diff --git a/nasmlib.c b/nasmlib.c index e380542d..64d85b91 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -1088,6 +1088,22 @@ int bsi(char *string, const char **array, int size) return -1; /* we haven't got it :( */ } +int bsii(char *string, const char **array, int size) +{ + int i = -1, j = size; /* always, i < index < j */ + while (j - i >= 2) { + int k = (i + j) / 2; + int l = nasm_stricmp(string, array[k]); + if (l < 0) /* it's in the first half */ + j = k; + else if (l > 0) /* it's in the second half */ + i = k; + else /* we've got it :) */ + return k; + } + return -1; /* we haven't got it :( */ +} + static char *file_name = NULL; static int32_t line_number = 0; diff --git a/nasmlib.h b/nasmlib.h index 4bfec686..70da2146 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -257,8 +257,11 @@ int32_t reloc_wrt(expr *); * Binary search routine. Returns index into `array' of an entry * matching `string', or <0 if no match. `array' is taken to * contain `size' elements. + * + * bsi() is case sensitive, bsii() is case insensitive. */ int bsi(char *string, const char **array, int size); +int bsii(char *string, const char **array, int size); char *src_set_fname(char *newname); int32_t src_set_linnum(int32_t newline);