0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00

nasmlib: add bsii() case-insensitive version of bsi()

This commit is contained in:
H. Peter Anvin
2007-08-29 16:25:46 +00:00
parent 12fc7bc4b2
commit 14f8bf2edf
2 changed files with 19 additions and 0 deletions

View File

@@ -1088,6 +1088,22 @@ int bsi(char *string, const char **array, int size)
return -1; /* we haven't got it :( */ 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 char *file_name = NULL;
static int32_t line_number = 0; static int32_t line_number = 0;

View File

@@ -257,8 +257,11 @@ int32_t reloc_wrt(expr *);
* Binary search routine. Returns index into `array' of an entry * Binary search routine. Returns index into `array' of an entry
* matching `string', or <0 if no match. `array' is taken to * matching `string', or <0 if no match. `array' is taken to
* contain `size' elements. * contain `size' elements.
*
* bsi() is case sensitive, bsii() is case insensitive.
*/ */
int bsi(char *string, const char **array, int size); int bsi(char *string, const char **array, int size);
int bsii(char *string, const char **array, int size);
char *src_set_fname(char *newname); char *src_set_fname(char *newname);
int32_t src_set_linnum(int32_t newline); int32_t src_set_linnum(int32_t newline);