2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 06:55:30 +00:00

case sensitive switch for symbol tables

This commit is contained in:
Bob Halley
1999-01-04 22:30:28 +00:00
parent 94d102893a
commit d386111bff
3 changed files with 45 additions and 19 deletions

View File

@@ -45,12 +45,9 @@ main(int argc, char *argv[]) {
int trace = 0; int trace = 0;
int c; int c;
isc_symexists_t exists_policy = isc_symexists_reject; isc_symexists_t exists_policy = isc_symexists_reject;
isc_boolean_t case_sensitive = ISC_FALSE;
INSIST(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); while ((c = getopt(argc, argv, "tarc")) != -1) {
INSIST(isc_symtab_create(mctx, 691, undefine_action, &st) ==
ISC_R_SUCCESS);
while ((c = getopt(argc, argv, "tar")) != -1) {
switch (c) { switch (c) {
case 't': case 't':
trace = 1; trace = 1;
@@ -61,9 +58,16 @@ main(int argc, char *argv[]) {
case 'r': case 'r':
exists_policy = isc_symexists_replace; exists_policy = isc_symexists_replace;
break; break;
case 'c':
case_sensitive = ISC_TRUE;
break;
} }
} }
INSIST(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
INSIST(isc_symtab_create(mctx, 691, undefine_action, case_sensitive,
&st) == ISC_R_SUCCESS);
while (gets(s) != NULL) { while (gets(s) != NULL) {
len = strlen(s); len = strlen(s);

View File

@@ -104,6 +104,7 @@ typedef struct isc_symtab isc_symtab_t;
isc_result_t isc_result_t
isc_symtab_create(isc_mem_t *mctx, unsigned int size, isc_symtab_create(isc_mem_t *mctx, unsigned int size,
isc_symtabaction_t undefine_action, isc_symtabaction_t undefine_action,
isc_boolean_t case_sensitive,
isc_symtab_t **symtabp); isc_symtab_t **symtabp);
void void

View File

@@ -47,11 +47,13 @@ struct isc_symtab {
unsigned int size; unsigned int size;
eltlist_t * table; eltlist_t * table;
isc_symtabaction_t undefine_action; isc_symtabaction_t undefine_action;
isc_boolean_t case_sensitive;
}; };
isc_result_t isc_result_t
isc_symtab_create(isc_mem_t *mctx, unsigned int size, isc_symtab_create(isc_mem_t *mctx, unsigned int size,
isc_symtabaction_t undefine_action, isc_symtabaction_t undefine_action,
isc_boolean_t case_sensitive,
isc_symtab_t **symtabp) isc_symtab_t **symtabp)
{ {
isc_symtab_t *symtab; isc_symtab_t *symtab;
@@ -75,6 +77,7 @@ isc_symtab_create(isc_mem_t *mctx, unsigned int size,
symtab->mctx = mctx; symtab->mctx = mctx;
symtab->size = size; symtab->size = size;
symtab->undefine_action = undefine_action; symtab->undefine_action = undefine_action;
symtab->case_sensitive = case_sensitive;
symtab->magic = SYMTAB_MAGIC; symtab->magic = SYMTAB_MAGIC;
*symtabp = symtab; *symtabp = symtab;
@@ -111,7 +114,7 @@ isc_symtab_destroy(isc_symtab_t **symtabp) {
} }
static inline unsigned int static inline unsigned int
hash(const char *key) { hash(const char *key, isc_boolean_t case_sensitive) {
const char *s; const char *s;
unsigned int h = 0; unsigned int h = 0;
unsigned int g; unsigned int g;
@@ -123,14 +126,24 @@ hash(const char *key) {
* and Ullman, Addison-Wesley, 1986, ISBN 0-201-10088-6. * and Ullman, Addison-Wesley, 1986, ISBN 0-201-10088-6.
*/ */
for (s = key; *s != '\0'; s++) { if (case_sensitive) {
c = *s; for (s = key; *s != '\0'; s++) {
if (isascii(c) && isupper(c)) h = ( h << 4 ) + *s;
c = tolower(c); if ((g = ( h & 0xf0000000 )) != 0) {
h = ( h << 4 ) + c; h = h ^ (g >> 24);
if ((g = ( h & 0xf0000000 )) != 0) { h = h ^ g;
h = h ^ (g >> 24); }
h = h ^ g; }
} else {
for (s = key; *s != '\0'; s++) {
c = *s;
if (isascii(c) && isupper(c))
c = tolower(c);
h = ( h << 4 ) + c;
if ((g = ( h & 0xf0000000 )) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
} }
} }
@@ -138,11 +151,19 @@ hash(const char *key) {
} }
#define FIND(s, k, t, b, e) \ #define FIND(s, k, t, b, e) \
b = hash((k)) % (s)->size; \ b = hash((k), (s)->case_sensitive) % (s)->size; \
for (e = HEAD((s)->table[b]); e != NULL; e = NEXT(e, link)) { \ if ((s)->case_sensitive) { \
if (((t) == 0 || e->type == (t)) && \ for (e = HEAD((s)->table[b]); e != NULL; e = NEXT(e, link)) { \
strcasecmp(e->key, (k)) == 0) \ if (((t) == 0 || e->type == (t)) && \
break; \ strcmp(e->key, (k)) == 0) \
break; \
} \
} else { \
for (e = HEAD((s)->table[b]); e != NULL; e = NEXT(e, link)) { \
if (((t) == 0 || e->type == (t)) && \
strcasecmp(e->key, (k)) == 0) \
break; \
} \
} }
isc_result_t isc_result_t