1 /* Handle list of needed message catalogs
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */
19 #include "intlconfig.h"
21 #if defined HAVE_STRING_H || defined _LIBC
23 # define _GNU_SOURCE 1
29 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
32 #if !HAVE_STRCHR && !defined _LIBC
38 #if defined _LIBC || defined HAVE_ARGZ_H
42 #include <sys/types.h>
44 #if defined STDC_HEADERS || defined _LIBC
50 /* On some strange systems still no definition of NULL is found. Sigh! */
52 # if defined __STDC__ && __STDC__
53 # define NULL ((void *) 0)
59 /* @@ end of prolog @@ */
62 /* Rename the non ANSI C functions. This is required by the standard
63 because some ANSI C functions will require linking with this object
64 file and the name space must not be polluted. */
66 # define stpcpy(dest, src) __stpcpy(dest, src)
70 static char *stpcpy PARAMS ((char *dest, const char *src));
74 /* Define function which are usually not available. */
76 #if !defined _LIBC && !defined HAVE___ARGZ_COUNT
77 /* Returns the number of strings in ARGZ. */
78 static size_t argz_count__ PARAMS ((const char *argz, size_t len));
81 argz_count__ (argz, len)
88 size_t part_len = strlen (argz);
96 # define __argz_count(argz, len) argz_count__ (argz, len)
97 #endif /* !_LIBC && !HAVE___ARGZ_COUNT */
99 #if !defined _LIBC && !defined HAVE___ARGZ_STRINGIFY
100 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
101 except the last into the character SEP. */
102 static void argz_stringify__ PARAMS ((char *argz, size_t len, int sep));
105 argz_stringify__ (argz, len, sep)
112 size_t part_len = strlen (argz);
119 # undef __argz_stringify
120 # define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep)
121 #endif /* !_LIBC && !HAVE___ARGZ_STRINGIFY */
123 #if !defined _LIBC && !defined HAVE___ARGZ_NEXT
124 static char *argz_next__ PARAMS ((char *argz, size_t argz_len,
128 argz_next__ (argz, argz_len, entry)
135 if (entry < argz + argz_len)
136 entry = strchr (entry, '\0') + 1;
138 return entry >= argz + argz_len ? NULL : (char *) entry;
147 # define __argz_next(argz, len, entry) argz_next__ (argz, len, entry)
148 #endif /* !_LIBC && !HAVE___ARGZ_NEXT */
151 /* Return number of bits set in X. */
152 static int pop PARAMS ((int x));
158 /* We assume that no more than 16 bits are used. */
159 x = ((x & ~0x5555) >> 1) + (x & 0x5555);
160 x = ((x & ~0x3333) >> 2) + (x & 0x3333);
161 x = ((x >> 4) + x) & 0x0f0f;
162 x = ((x >> 8) + x) & 0xff;
168 struct loaded_l10nfile *
169 _nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, mask, language,
170 territory, codeset, normalized_codeset, modifier, special,
171 sponsor, revision, filename, do_allocate)
172 struct loaded_l10nfile **l10nfile_list;
176 const char *language;
177 const char *territory;
179 const char *normalized_codeset;
180 const char *modifier;
183 const char *revision;
184 const char *filename;
188 struct loaded_l10nfile *last = NULL;
189 struct loaded_l10nfile *retval;
194 /* Allocate room for the full file name. */
195 abs_filename = (char *) malloc (dirlist_len
197 + ((mask & TERRITORY) != 0
198 ? strlen (territory) + 1 : 0)
199 + ((mask & XPG_CODESET) != 0
200 ? strlen (codeset) + 1 : 0)
201 + ((mask & XPG_NORM_CODESET) != 0
202 ? strlen (normalized_codeset) + 1 : 0)
203 + (((mask & XPG_MODIFIER) != 0
204 || (mask & CEN_AUDIENCE) != 0)
205 ? strlen (modifier) + 1 : 0)
206 + ((mask & CEN_SPECIAL) != 0
207 ? strlen (special) + 1 : 0)
208 + (((mask & CEN_SPONSOR) != 0
209 || (mask & CEN_REVISION) != 0)
210 ? (1 + ((mask & CEN_SPONSOR) != 0
211 ? strlen (sponsor) + 1 : 0)
212 + ((mask & CEN_REVISION) != 0
213 ? strlen (revision) + 1 : 0)) : 0)
214 + 1 + strlen (filename) + 1);
216 if (abs_filename == NULL)
222 /* Construct file name. */
223 memcpy (abs_filename, dirlist, dirlist_len);
224 __argz_stringify (abs_filename, dirlist_len, ';'); /*FRANCO changed : to ; for win32*/
225 cp = abs_filename + (dirlist_len - 1);
227 cp = stpcpy (cp, language);
229 if ((mask & TERRITORY) != 0)
232 cp = stpcpy (cp, territory);
234 if ((mask & XPG_CODESET) != 0)
237 cp = stpcpy (cp, codeset);
239 if ((mask & XPG_NORM_CODESET) != 0)
242 cp = stpcpy (cp, normalized_codeset);
244 if ((mask & (XPG_MODIFIER | CEN_AUDIENCE)) != 0)
246 /* This component can be part of both syntaces but has different
247 leading characters. For CEN we use `+', else `@'. */
248 *cp++ = (mask & CEN_AUDIENCE) != 0 ? '+' : '@';
249 cp = stpcpy (cp, modifier);
251 if ((mask & CEN_SPECIAL) != 0)
254 cp = stpcpy (cp, special);
256 if ((mask & (CEN_SPONSOR | CEN_REVISION)) != 0)
259 if ((mask & CEN_SPONSOR) != 0)
260 cp = stpcpy (cp, sponsor);
261 if ((mask & CEN_REVISION) != 0)
264 cp = stpcpy (cp, revision);
269 stpcpy (cp, filename);
271 /* Look in list of already loaded domains whether it is already
274 for (retval = *l10nfile_list; retval != NULL; retval = retval->next)
275 if (retval->filename != NULL)
277 int compare = strcmp (retval->filename, abs_filename);
283 /* It's not in the list. */
291 if (retval != NULL || do_allocate == 0)
297 retval = (struct loaded_l10nfile *)
298 malloc (sizeof (*retval) + (__argz_count (dirlist, dirlist_len)
300 * sizeof (struct loaded_l10nfile *)));
304 retval->filename = abs_filename;
305 retval->decided = (__argz_count (dirlist, dirlist_len) != 1
306 || ((mask & XPG_CODESET) != 0
307 && (mask & XPG_NORM_CODESET) != 0));
312 retval->next = *l10nfile_list;
313 *l10nfile_list = retval;
317 retval->next = last->next;
322 /* If the DIRLIST is a real list the RETVAL entry corresponds not to
323 a real file. So we have to use the DIRLIST separation mechanism
324 of the inner loop. */
325 cnt = __argz_count (dirlist, dirlist_len) == 1 ? mask - 1 : mask;
326 for (; cnt >= 0; --cnt)
327 if ((cnt & ~mask) == 0
328 && ((cnt & CEN_SPECIFIC) == 0 || (cnt & XPG_SPECIFIC) == 0)
329 && ((cnt & XPG_CODESET) == 0 || (cnt & XPG_NORM_CODESET) == 0))
331 /* Iterate over all elements of the DIRLIST. */
334 while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir))
336 retval->successor[entries++]
337 = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt,
338 language, territory, codeset,
339 normalized_codeset, modifier, special,
340 sponsor, revision, filename, 1);
342 retval->successor[entries] = NULL;
347 /* Normalize codeset name. There is no standard for the codeset
348 names. Normalization allows the user to use any of the common
351 _nl_normalize_codeset (codeset, name_len)
352 const unsigned char *codeset;
361 for (cnt = 0; cnt < name_len; ++cnt)
362 if (isalnum (codeset[cnt]))
366 if (isalpha (codeset[cnt]))
370 retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);
375 wp = stpcpy (retval, "iso");
379 for (cnt = 0; cnt < name_len; ++cnt)
380 if (isalpha (codeset[cnt]))
381 *wp++ = tolower (codeset[cnt]);
382 else if (isdigit (codeset[cnt]))
383 *wp++ = codeset[cnt];
388 return (const char *) retval;
392 /* @@ begin of epilog @@ */
394 /* We don't want libintl.a to depend on any other library. So we
395 avoid the non-standard function stpcpy. In GNU C Library this
396 function is available, though. Also allow the symbol HAVE_STPCPY
398 #if !_LIBC && !HAVE_STPCPY
404 while ((*dest++ = *src++) != '\0')