1 /* gen_tables.h -- Declarations used for lookup tables.
2 * Copyright 2008 Red Hat Inc., Durham, North Carolina.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Miloslav Trmač <mitr@redhat.com>
22 #ifndef GEN_TABLES_H__
23 #define GEN_TABLES_H__
28 /* Assumes ASCII; verified in gen_tables.c. */
29 #define GT_ISUPPER(X) ((X) >= 'A' && (X) <= 'Z')
30 #define GT_ISLOWER(X) ((X) >= 'a' && (X) <= 'z')
32 inline static int s2i__(const char *strings, const unsigned *s_table,
33 const int *i_table, size_t n, const char *s, int *value)
39 while (left <= right) { /* invariant: left <= x <= right */
43 mid = (left + right) / 2;
44 /* FIXME? avoid recomparing a common prefix */
45 r = strcmp(s, strings + s_table[mid]);
47 *value = i_table[mid];
58 inline static const char *i2s_direct__(const char *strings,
59 const unsigned *table, int min, int max,
64 if (v < min || v > max)
72 inline static const char *i2s_bsearch__(const char *strings,
74 const unsigned *s_table, size_t n,
81 while (left <= right) { /* invariant: left <= x <= right */
85 mid = (left + right) / 2;
86 mid_val = i_table[mid];
88 return strings + s_table[mid];