1 /* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
2 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
4 This file is part of the GNU C Library. Its master source is NOT part of
5 the C library, however. The master source lives in /gd/gnu/lib.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If
19 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
20 Cambridge, MA 02139, USA. */
26 #if defined _LIBC && (defined __ARGZ_COUNT || defined __ARGZ_STRINGIFY)
31 #if defined STDC_HEADERS || defined _LIBC
35 #if defined HAVE_STRING_H || defined _LIBC
40 #if !HAVE_STRCHR && !defined _LIBC
48 /* @@ end of prolog @@ */
51 /* Rename the non ANSI C functions. This is required by the standard
52 because some ANSI C functions will require linking with this object
53 file and the name space must not be polluted. */
54 # define stpcpy(dest, src) __stpcpy(dest, src)
57 static char *stpcpy
PARAMS ((char *dest
, const char *src
));
61 /* Define function which are usually not available. */
63 #if !defined _LIBC && !defined __ARGZ_COUNT
64 /* Returns the number of strings in ARGZ. */
65 static size_t __argz_count
PARAMS ((const char *argz
, size_t len
));
68 __argz_count (argz
, len
)
75 size_t part_len
= strlen (argz
);
82 #endif /* !_LIBC && !__ARGZ_COUNT */
84 #if !defined _LIBC && !defined __ARGZ_STRINGIFY
85 /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
86 except the last into the character SEP. */
87 static void __argz_stringify
PARAMS ((char *argz
, size_t len
, int sep
));
90 __argz_stringify (argz
, len
, sep
)
97 size_t part_len
= strlen (argz
);
104 #endif /* !_LIBC && !__ARGZ_COUNT */
106 #if !defined _LIBC && !defined __ARGZ_NEXT
108 __argz_next (argz
, argz_len
, entry
)
115 if (entry
< argz
+ argz_len
)
116 entry
= strchr (entry
, '\0') + 1;
118 return entry
>= argz
+ argz_len
? NULL
: (char *) entry
;
129 /* Return number of bits set in X. */
130 static int pop
PARAMS ((int x
));
136 /* We assume that no more than 16 bits are used. */
137 x
= ((x
& ~0x5555) >> 1) + (x
& 0x5555);
138 x
= ((x
& ~0x3333) >> 2) + (x
& 0x3333);
139 x
= ((x
>> 4) + x
) & 0x0f0f;
140 x
= ((x
>> 8) + x
) & 0xff;
146 struct loaded_l10nfile
*
147 _nl_make_l10nflist (l10nfile_list
, dirlist
, dirlist_len
, mask
, language
,
148 territory
, codeset
, normalized_codeset
, modifier
, special
,
149 sponsor
, revision
, filename
, do_allocate
)
150 struct loaded_l10nfile
**l10nfile_list
;
154 const char *language
;
155 const char *territory
;
157 const char *normalized_codeset
;
158 const char *modifier
;
161 const char *revision
;
162 const char *filename
;
166 struct loaded_l10nfile
*last
= NULL
;
167 struct loaded_l10nfile
*retval
;
172 /* Allocate room for the full file name. */
173 abs_filename
= (char *) malloc (dirlist_len
175 + ((mask
& TERRITORY
) != 0
176 ? strlen (territory
) + 1 : 0)
177 + ((mask
& XPG_CODESET
) != 0
178 ? strlen (codeset
) + 1 : 0)
179 + ((mask
& XPG_NORM_CODESET
) != 0
180 ? strlen (normalized_codeset
) + 1 : 0)
181 + (((mask
& XPG_MODIFIER
) != 0
182 || (mask
& CEN_AUDIENCE
) != 0) ?
183 strlen (modifier
) + 1 : 0)
184 + ((mask
& CEN_SPECIAL
) != 0
185 ? strlen (special
) + 1 : 0)
186 + ((mask
& CEN_SPONSOR
) != 0
187 ? strlen (sponsor
) + 1 : 0)
188 + ((mask
& CEN_REVISION
) != 0
189 ? strlen (revision
) + 1 : 0)
190 + 1 + strlen (filename
) + 1);
192 if (abs_filename
== NULL
)
198 /* Construct file name. */
199 memcpy (abs_filename
, dirlist
, dirlist_len
);
200 __argz_stringify (abs_filename
, dirlist_len
, ':');
201 cp
= abs_filename
+ (dirlist_len
- 1);
203 cp
= stpcpy (cp
, language
);
205 if ((mask
& TERRITORY
) != 0)
208 cp
= stpcpy (cp
, territory
);
210 if ((mask
& XPG_CODESET
) != 0)
213 cp
= stpcpy (cp
, codeset
);
215 if ((mask
& XPG_NORM_CODESET
) != 0)
218 cp
= stpcpy (cp
, normalized_codeset
);
220 if ((mask
& (XPG_MODIFIER
| CEN_AUDIENCE
)) != 0)
222 /* This component can be part of both syntaces but has different
223 leading characters. For CEN we use `+', else `@'. */
224 *cp
++ = (mask
& CEN_AUDIENCE
) != 0 ? '+' : '@';
225 cp
= stpcpy (cp
, modifier
);
227 if ((mask
& CEN_SPECIAL
) != 0)
230 cp
= stpcpy (cp
, special
);
232 if ((mask
& CEN_SPONSOR
) != 0)
235 cp
= stpcpy (cp
, sponsor
);
237 if ((mask
& CEN_REVISION
) != 0)
240 cp
= stpcpy (cp
, revision
);
244 stpcpy (cp
, filename
);
246 /* Look in list of already loaded domains whether it is already
249 for (retval
= *l10nfile_list
; retval
!= NULL
; retval
= retval
->next
)
250 if (retval
->filename
!= NULL
)
252 int compare
= strcmp (retval
->filename
, abs_filename
);
258 /* It's not in the list. */
266 if (retval
!= NULL
|| do_allocate
== 0)
272 retval
= (struct loaded_l10nfile
*)
273 malloc (sizeof (*retval
) + (__argz_count (dirlist
, dirlist_len
)
275 * sizeof (struct loaded_l10nfile
*)));
279 retval
->filename
= abs_filename
;
280 retval
->decided
= (__argz_count (dirlist
, dirlist_len
) != 1
281 || ((mask
& XPG_CODESET
) != 0
282 && (mask
& XPG_NORM_CODESET
) != 0));
287 retval
->next
= *l10nfile_list
;
288 *l10nfile_list
= retval
;
292 retval
->next
= last
->next
;
297 /* If the DIRLIST is a real list the RETVAL entry correcponds not to
298 a real file. So we have to use the DIRLIST separation machanism
299 of the inner loop. */
300 cnt
= __argz_count (dirlist
, dirlist_len
) == 1 ? mask
- 1 : mask
;
301 for (; cnt
>= 0; --cnt
)
302 if ((cnt
& ~mask
) == 0
303 && ((cnt
& CEN_SPECIFIC
) == 0 || (cnt
& XPG_SPECIFIC
) == 0)
304 && ((cnt
& XPG_CODESET
) == 0 || (cnt
& XPG_NORM_CODESET
) == 0))
306 /* Iterate over all elements of the DIRLIST. */
309 while ((dir
= __argz_next ((char *) dirlist
, dirlist_len
, dir
))
311 retval
->successor
[entries
++]
312 = _nl_make_l10nflist (l10nfile_list
, dir
, strlen (dir
) + 1, cnt
,
313 language
, territory
, codeset
,
314 normalized_codeset
, modifier
, special
,
315 sponsor
, revision
, filename
, 1);
317 retval
->successor
[entries
] = NULL
;
322 /* Normalize codeset name. There is no standard for the codeset
323 names. Normalization allows the user to use any of the common
326 _nl_normalize_codeset (codeset
, name_len
)
336 for (cnt
= 0; cnt
< name_len
; ++cnt
)
337 if (isalnum (codeset
[cnt
]))
341 if (isalpha (codeset
[cnt
]))
345 retval
= (char *) malloc ((only_digit
? 3 : 0) + len
+ 1);
350 wp
= stpcpy (retval
, "ISO");
354 for (cnt
= 0; cnt
< name_len
; ++cnt
)
355 if (isalpha (codeset
[cnt
]))
356 *wp
++ = tolower (codeset
[cnt
]);
357 else if (isdigit (codeset
[cnt
]))
358 *wp
++ = codeset
[cnt
];
363 return (const char *) retval
;
367 /* @@ begin of epilog @@ */
369 /* We don't want libintl.a to depend on any other library. So we
370 avoid the non-standard function stpcpy. In GNU C Library this
371 function is available, though. Also allow the symbol HAVE_STPCPY
373 #if !_LIBC && !HAVE_STPCPY
379 while ((*dest
++ = *src
++) != '\0')