2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 freestrlist(char **l, int num)
52 word(char *s, int num, char *wd)
55 char *start, *finish, *ss, *w;
75 if ((cnt == num) && ((s[i] == ' ') || (s[i] == '\t')))
80 if ((s[i] != ' ') && (s[i] != '\t'))
88 else if ((s[i - 1] == ' ') || (s[i - 1] == '\t'))
99 if ((start) && (finish))
101 for (ss = start; ss < finish; ss++)
106 for (ss = start; *ss != 0; ss++)
115 word_mb(char *s, int num, char *wd, int *spaceflag)
118 char *start, *finish, *ss, *w;
124 } *cc, char_class_tbl[] =
127 /* Will be supported on glibc 2.1.3 or later */
137 "jdigit", 0}, /* Japanese */
141 "hanja", 0}, /* Korean */
142 /* {"?????"}, {"?????"}, *//* Chinese */
145 /* SGI IRIX (Japanese, Chinese, Korean, etc..) */
154 /* {"?????"}, {"?????"}, */
157 /* {"?????"}, {"?????"}, */
173 /* Check multibyte character class is available or not */
175 for (cc = char_class_tbl; cc->name != NULL; cc++)
177 cc->wt = wctype(cc->name);
178 if (cc->wt != (wctype_t) 0)
194 len = mblen(s + i, MB_CUR_MAX);
201 /* Check multibyte character class */
207 if ((mbtowc(&wc, s + i, strlen(s + i))) != -1)
209 for (cc = char_class_tbl; cc->name != NULL; cc++)
211 if (cc->wt == (wctype_t) 0)
214 if (iswctype(wc, cc->wt) != 0)
225 if ((cnt == num) && ((s[i] == ' ') || (s[i] == '\t') ||
226 (oldflg != mbflg) || (mbflg > 1)))
232 if ((s[i] != ' ') && (s[i] != '\t'))
235 (s[i - 1] == ' ') || (s[i - 1] == '\t') ||
236 ((oldflg > 1) && (mbflg > 1)) || (oldflg != mbflg))
242 if ((s[i - 1] == ' ') || (s[i - 1] == '\t'))
252 if ((start) && (finish))
254 for (ss = start; ss < finish; ss++)
259 for (ss = start; *ss != 0; ss++)
268 findLocalizedFile(char *fname)
270 char *tmp, *lang, *p[3];
273 if (!(lang = setlocale(LC_MESSAGES, NULL)))
277 lang = strdup(lang); /* lang may be in static space, thus it must
278 * be duplicated before we change it below */
279 p[0] = lang + strlen(lang);
280 p[1] = strchr(lang, '.');
281 p[2] = strchr(lang, '_');
283 for (i = 0; i < 3; i++)
289 sprintf(fname, "%s.%s", tmp, lang);