Depend in dlfcn, not db2.
[glibc/history.git] / locale / weightwc.h
blobfc517eb91525eeceb61557f6cb19d1a7a9c47eba
1 /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Ulrich Drepper, <drepper@cygnus.com>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* Find index of weight. */
21 static inline int32_t
22 findidx (const wint_t **cpp)
24 int_fast32_t i;
25 const wint_t *cp;
26 wint_t ch;
27 size_t idx;
28 size_t cnt = 0;
30 ch = *(*cpp)++;
31 idx = ch % size;
32 while (names[idx] != ch)
34 if (++cnt == layers)
35 /* We didn't find the name. It is case for UNDEFINED. */
36 return 0;
37 idx += size;
39 i = table[idx];
41 if (i >= 0)
42 /* This is an index into the weight table. Cool. */
43 return i;
45 /* Oh well, more than one sequence starting with this byte.
46 Search for the correct one. */
47 cp = &extra[-i];
48 while (1)
50 size_t nhere;
51 const wint_t *usrc = *cpp;
53 /* The first thing is the index. */
54 i = *((int32_t *) cp);
55 cp += sizeof (int32_t);
57 /* Next is the length of the byte sequence. These are always
58 short byte sequences so there is no reason to call any
59 function (even if they are inlined). */
60 nhere = *cp++;
62 if (i >= 0)
64 /* It is a single character. If it matches we found our
65 index. Note that at the end of each list there is an
66 entry of length zero which represents the single byte
67 sequence. The first (and here only) byte was tested
68 already. */
69 size_t cnt;
71 for (cnt = 0; cnt < nhere; ++cnt)
72 if (cp[cnt] != usrc[cnt])
73 break;
75 if (cnt == nhere)
77 /* Found it. */
78 *cpp += nhere;
79 return i;
82 /* Up to the next entry. */
83 cp += nhere;
85 else
87 /* This is a range of characters. First decide whether the
88 current byte sequence lies in the range. */
89 size_t cnt;
90 size_t offset = 0;
92 for (cnt = 0; cnt < nhere; ++cnt)
93 if (cp[cnt] != usrc[cnt])
94 break;
96 if (cnt != nhere)
98 if (cp[cnt] > usrc[cnt])
100 /* Cannot be in this range. */
101 cp += 2 * nhere;
102 continue;
105 /* Test against the end of the range. */
106 for (cnt = 0; cnt < nhere; ++cnt)
107 if (cp[nhere + cnt] != usrc[cnt])
108 break;
110 if (cnt != nhere && cp[nhere + cnt] < usrc[cnt])
112 /* Cannot be in this range. */
113 cp += 2 * nhere;
114 continue;
117 /* This range matches the next characters. Now find
118 the offset in the indirect table. */
119 for (cnt = 0; cp[cnt] == usrc[cnt]; ++cnt);
123 offset <<= 8;
124 offset += usrc[cnt] - cp[cnt];
126 while (++cnt < nhere);
129 *cpp += nhere;
130 return offset;
134 /* NOTREACHED */
135 return 0x43219876;