2025-10-01 11:25:38 -07:00
|
|
|
/* SPDX-License-Identifier: BSD-2-Clause */
|
|
|
|
|
/* Copyright 1996-2016 The NASM Authors - All Rights Reserved */
|
2016-05-25 05:42:47 -07:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* nasmlib.c library routines for the Netwide Assembler
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "nasmlib.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Binary search.
|
|
|
|
|
*/
|
|
|
|
|
int bsi(const 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 = strcmp(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 :( */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int bsii(const 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 :( */
|
|
|
|
|
}
|