OpenCoverage

locale.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/locale.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* locale.c - Miscellaneous internationalization functions. */-
2-
3/* Copyright (C) 1996-2009,2012,2016 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash 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-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include "config.h"-
22-
23#include "bashtypes.h"-
24-
25#if defined (HAVE_UNISTD_H)-
26# include <unistd.h>-
27#endif-
28-
29#if HAVE_LANGINFO_CODESET-
30# include <langinfo.h>-
31#endif-
32-
33#include "bashintl.h"-
34#include "bashansi.h"-
35#include <stdio.h>-
36#include "chartypes.h"-
37#include <errno.h>-
38-
39#include "shell.h"-
40#include "input.h" /* For bash_input */-
41-
42#ifndef errno-
43extern int errno;-
44#endif-
45-
46int locale_utf8locale; /* set but unused for now */-
47int locale_mb_cur_max; /* value of MB_CUR_MAX for current locale (LC_CTYPE) */-
48int locale_shiftstates;-
49-
50extern int dump_translatable_strings, dump_po_strings;-
51-
52/* The current locale when the program begins */-
53static char *default_locale;-
54-
55/* The current domain for textdomain(3). */-
56static char *default_domain;-
57static char *default_dir;-
58-
59/* tracks the value of LC_ALL; used to override values for other locale-
60 categories */-
61static char *lc_all;-
62-
63/* tracks the value of LC_ALL; used to provide defaults for locale-
64 categories */-
65static char *lang;-
66-
67/* Called to reset all of the locale variables to their appropriate values-
68 if (and only if) LC_ALL has not been assigned a value. */-
69static int reset_locale_vars __P((void));-
70-
71static void locale_setblanks __P((void));-
72static int locale_isutf8 __P((char *));-
73-
74/* Set the value of default_locale and make the current locale the-
75 system default locale. This should be called very early in main(). */-
76void-
77set_default_locale ()-
78{-
79#if defined (HAVE_SETLOCALE)-
80 default_locale = setlocale (LC_ALL, "");-
81 if (default_locale)
default_localeDescription
TRUEevaluated 5431 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-5431
82 default_locale = savestring (default_locale);
executed 5431 times by 1 test: default_locale = (char *)strcpy (sh_xmalloc((1 + strlen (default_locale)), "locale.c", 82), (default_locale));
Executed by:
  • Self test
5431
83#endif /* HAVE_SETLOCALE */-
84 bindtextdomain (PACKAGE, LOCALEDIR);-
85 textdomain (PACKAGE);-
86-
87 locale_mb_cur_max = MB_CUR_MAX;-
88 locale_utf8locale = locale_isutf8 (default_locale);-
89 locale_shiftstates = mblen ((char *)NULL, 0);-
90}
executed 5432 times by 1 test: end of block
Executed by:
  • Self test
5432
91-
92/* Set default values for LC_CTYPE, LC_COLLATE, LC_MESSAGES, LC_NUMERIC and-
93 LC_TIME if they are not specified in the environment, but LC_ALL is. This-
94 should be called from main() after parsing the environment. */-
95void-
96set_default_locale_vars ()-
97{-
98 char *val;-
99-
100#if defined (HAVE_SETLOCALE)-
101-
102# if defined (LC_CTYPE)-
103 val = get_string_value ("LC_CTYPE");-
104 if (val == 0 && lc_all && *lc_all)
val == 0Description
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lc_allDescription
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*lc_allDescription
TRUEevaluated 397 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5050 times by 1 test
Evaluated by:
  • Self test
0-5447
105 {-
106 setlocale (LC_CTYPE, lc_all);-
107 locale_setblanks ();-
108 locale_mb_cur_max = MB_CUR_MAX;-
109 locale_utf8locale = locale_isutf8 (lc_all);-
110 locale_shiftstates = mblen ((char *)NULL, 0);-
111 u32reset ();-
112 }
executed 397 times by 1 test: end of block
Executed by:
  • Self test
397
113# endif-
114-
115# if defined (LC_COLLATE)-
116 val = get_string_value ("LC_COLLATE");-
117 if (val == 0 && lc_all && *lc_all)
val == 0Description
TRUEevaluated 5440 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
lc_allDescription
TRUEevaluated 5440 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*lc_allDescription
TRUEevaluated 394 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5046 times by 1 test
Evaluated by:
  • Self test
0-5440
118 setlocale (LC_COLLATE, lc_all);
executed 394 times by 1 test: setlocale ( 3 , lc_all);
Executed by:
  • Self test
394
119# endif /* LC_COLLATE */-
120-
121# if defined (LC_MESSAGES)-
122 val = get_string_value ("LC_MESSAGES");-
123 if (val == 0 && lc_all && *lc_all)
val == 0Description
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lc_allDescription
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*lc_allDescription
TRUEevaluated 397 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5050 times by 1 test
Evaluated by:
  • Self test
0-5447
124 setlocale (LC_MESSAGES, lc_all);
executed 397 times by 1 test: setlocale ( 5 , lc_all);
Executed by:
  • Self test
397
125# endif /* LC_MESSAGES */-
126-
127# if defined (LC_NUMERIC)-
128 val = get_string_value ("LC_NUMERIC");-
129 if (val == 0 && lc_all && *lc_all)
val == 0Description
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lc_allDescription
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*lc_allDescription
TRUEevaluated 397 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5050 times by 1 test
Evaluated by:
  • Self test
0-5447
130 setlocale (LC_NUMERIC, lc_all);
executed 397 times by 1 test: setlocale ( 1 , lc_all);
Executed by:
  • Self test
397
131# endif /* LC_NUMERIC */-
132-
133# if defined (LC_TIME)-
134 val = get_string_value ("LC_TIME");-
135 if (val == 0 && lc_all && *lc_all)
val == 0Description
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lc_allDescription
TRUEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*lc_allDescription
TRUEevaluated 397 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5050 times by 1 test
Evaluated by:
  • Self test
0-5447
136 setlocale (LC_TIME, lc_all);
executed 397 times by 1 test: setlocale ( 2 , lc_all);
Executed by:
  • Self test
397
137# endif /* LC_TIME */-
138-
139#endif /* HAVE_SETLOCALE */-
140-
141 val = get_string_value ("TEXTDOMAIN");-
142 if (val && *val)
valDescription
TRUEnever evaluated
FALSEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
*valDescription
TRUEnever evaluated
FALSEnever evaluated
0-5447
143 {-
144 FREE (default_domain);
never executed: sh_xfree((default_domain), "locale.c", 144);
default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
0
145 default_domain = savestring (val);-
146 if (default_dir && *default_dir)
default_dirDescription
TRUEnever evaluated
FALSEnever evaluated
*default_dirDescription
TRUEnever evaluated
FALSEnever evaluated
0
147 bindtextdomain (default_domain, default_dir);
never executed: bindtextdomain (default_domain, default_dir);
0
148 }
never executed: end of block
0
149-
150 val = get_string_value ("TEXTDOMAINDIR");-
151 if (val && *val)
valDescription
TRUEnever evaluated
FALSEevaluated 5447 times by 1 test
Evaluated by:
  • Self test
*valDescription
TRUEnever evaluated
FALSEnever evaluated
0-5447
152 {-
153 FREE (default_dir);
never executed: sh_xfree((default_dir), "locale.c", 153);
default_dirDescription
TRUEnever evaluated
FALSEnever evaluated
0
154 default_dir = savestring (val);-
155 if (default_domain && *default_domain)
default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
*default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
0
156 bindtextdomain (default_domain, default_dir);
never executed: bindtextdomain (default_domain, default_dir);
0
157 }
never executed: end of block
0
158}
executed 5447 times by 1 test: end of block
Executed by:
  • Self test
5447
159-
160/* Set one of the locale categories (specified by VAR) to VALUE. Returns 1-
161 if successful, 0 otherwise. */-
162int-
163set_locale_var (var, value)-
164 char *var, *value;-
165{-
166 int r;-
167 char *x;-
168-
169 x = "";-
170 errno = 0;-
171 if (var[0] == 'T' && var[10] == 0) /* TEXTDOMAIN */
var[0] == 'T'Description
TRUEnever evaluated
FALSEevaluated 8333 times by 1 test
Evaluated by:
  • Self test
var[10] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-8333
172 {-
173 FREE (default_domain);
never executed: sh_xfree((default_domain), "locale.c", 173);
default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 default_domain = value ? savestring (value) : (char *)NULL;
valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
175 if (default_dir && *default_dir)
default_dirDescription
TRUEnever evaluated
FALSEnever evaluated
*default_dirDescription
TRUEnever evaluated
FALSEnever evaluated
0
176 bindtextdomain (default_domain, default_dir);
never executed: bindtextdomain (default_domain, default_dir);
0
177 return (1);
never executed: return (1);
0
178 }-
179 else if (var[0] == 'T') /* TEXTDOMAINDIR */
var[0] == 'T'Description
TRUEnever evaluated
FALSEevaluated 8333 times by 1 test
Evaluated by:
  • Self test
0-8333
180 {-
181 FREE (default_dir);
never executed: sh_xfree((default_dir), "locale.c", 181);
default_dirDescription
TRUEnever evaluated
FALSEnever evaluated
0
182 default_dir = value ? savestring (value) : (char *)NULL;
valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
183 if (default_domain && *default_domain)
default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
*default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
0
184 bindtextdomain (default_domain, default_dir);
never executed: bindtextdomain (default_domain, default_dir);
0
185 return (1);
never executed: return (1);
0
186 }-
187-
188 /* var[0] == 'L' && var[1] == 'C' && var[2] == '_' */-
189-
190 else if (var[3] == 'A') /* LC_ALL */
var[3] == 'A'Description
TRUEevaluated 5544 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2789 times by 1 test
Evaluated by:
  • Self test
2789-5544
191 {-
192 FREE (lc_all);
executed 112 times by 1 test: sh_xfree((lc_all), "locale.c", 192);
Executed by:
  • Self test
lc_allDescription
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5432 times by 1 test
Evaluated by:
  • Self test
112-5432
193 if (value)
valueDescription
TRUEevaluated 484 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5060 times by 1 test
Evaluated by:
  • Self test
484-5060
194 lc_all = savestring (value);
executed 484 times by 1 test: lc_all = (char *)strcpy (sh_xmalloc((1 + strlen (value)), "locale.c", 194), (value));
Executed by:
  • Self test
484
195 else-
196 {-
197 lc_all = (char *)xmalloc (1);-
198 lc_all[0] = '\0';-
199 }
executed 5060 times by 1 test: end of block
Executed by:
  • Self test
5060
200#if defined (HAVE_SETLOCALE)-
201 r = *lc_all ? ((x = setlocale (LC_ALL, lc_all)) != 0) : reset_locale_vars ();
*lc_allDescription
TRUEevaluated 484 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5060 times by 1 test
Evaluated by:
  • Self test
484-5060
202 if (x == 0)
x == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5539 times by 1 test
Evaluated by:
  • Self test
5-5539
203 {-
204 if (errno == 0)
(*__errno_location ()) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
2-3
205 internal_warning(_("setlocale: LC_ALL: cannot change locale (%s)"), lc_all);
executed 2 times by 1 test: internal_warning( dcgettext (((void *)0), "setlocale: LC_ALL: cannot change locale (%s)" , 5) , lc_all);
Executed by:
  • Self test
2
206 else-
207 internal_warning(_("setlocale: LC_ALL: cannot change locale (%s): %s"), lc_all, strerror (errno));
executed 3 times by 1 test: internal_warning( dcgettext (((void *)0), "setlocale: LC_ALL: cannot change locale (%s): %s" , 5) , lc_all, strerror ( (*__errno_location ()) ));
Executed by:
  • Self test
3
208 }-
209 locale_setblanks ();-
210 locale_mb_cur_max = MB_CUR_MAX;-
211 /* if LC_ALL == "", reset_locale_vars has already called this */-
212 if (*lc_all && x)
*lc_allDescription
TRUEevaluated 484 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5060 times by 1 test
Evaluated by:
  • Self test
xDescription
TRUEevaluated 479 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-5060
213 locale_utf8locale = locale_isutf8 (lc_all);
executed 479 times by 1 test: locale_utf8locale = locale_isutf8 (lc_all);
Executed by:
  • Self test
479
214 locale_shiftstates = mblen ((char *)NULL, 0);-
215 u32reset ();-
216 return r;
executed 5544 times by 1 test: return r;
Executed by:
  • Self test
5544
217#else-
218 return (1);-
219#endif-
220 }-
221-
222#if defined (HAVE_SETLOCALE)-
223 else if (var[3] == 'C' && var[4] == 'T') /* LC_CTYPE */
var[3] == 'C'Description
TRUEevaluated 2775 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
var[4] == 'T'Description
TRUEevaluated 2767 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8-2775
224 {-
225# if defined (LC_CTYPE)-
226 if (lc_all == 0 || *lc_all == '\0')
lc_all == 0Description
TRUEnever evaluated
FALSEevaluated 2767 times by 1 test
Evaluated by:
  • Self test
*lc_all == '\0'Description
TRUEevaluated 2758 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-2767
227 {-
228 x = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE"));-
229 locale_setblanks ();-
230 locale_mb_cur_max = MB_CUR_MAX;-
231 /* if setlocale() returns NULL, the locale is not changed */-
232 if (x)
xDescription
TRUEevaluated 2378 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 380 times by 1 test
Evaluated by:
  • Self test
380-2378
233 locale_utf8locale = locale_isutf8 (x);
executed 2378 times by 1 test: locale_utf8locale = locale_isutf8 (x);
Executed by:
  • Self test
2378
234 locale_shiftstates = mblen ((char *)NULL, 0);-
235 u32reset ();-
236 }
executed 2758 times by 1 test: end of block
Executed by:
  • Self test
2758
237# endif-
238 }
executed 2767 times by 1 test: end of block
Executed by:
  • Self test
2767
239 else if (var[3] == 'C' && var[4] == 'O') /* LC_COLLATE */
var[3] == 'C'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
var[4] == 'O'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-14
240 {-
241# if defined (LC_COLLATE)-
242 if (lc_all == 0 || *lc_all == '\0')
lc_all == 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
*lc_all == '\0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-8
243 x = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE"));
executed 2 times by 1 test: x = setlocale ( 3 , get_locale_var ("LC_COLLATE"));
Executed by:
  • Self test
2
244# endif /* LC_COLLATE */-
245 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
246 else if (var[3] == 'M' && var[4] == 'E') /* LC_MESSAGES */
var[3] == 'M'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
var[4] == 'E'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
247 {-
248# if defined (LC_MESSAGES)-
249 if (lc_all == 0 || *lc_all == '\0')
lc_all == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
*lc_all == '\0'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
250 x = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES"));
never executed: x = setlocale ( 5 , get_locale_var ("LC_MESSAGES"));
0
251# endif /* LC_MESSAGES */-
252 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
253 else if (var[3] == 'N' && var[4] == 'U') /* LC_NUMERIC */
var[3] == 'N'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
var[4] == 'U'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
254 {-
255# if defined (LC_NUMERIC)-
256 if (lc_all == 0 || *lc_all == '\0')
lc_all == 0Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
*lc_all == '\0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-9
257 x = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC"));
executed 2 times by 1 test: x = setlocale ( 1 , get_locale_var ("LC_NUMERIC"));
Executed by:
  • Self test
2
258# endif /* LC_NUMERIC */-
259 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
260 else if (var[3] == 'T' && var[4] == 'I') /* LC_TIME */
var[3] == 'T'Description
TRUEnever evaluated
FALSEnever evaluated
var[4] == 'I'Description
TRUEnever evaluated
FALSEnever evaluated
0
261 {-
262# if defined (LC_TIME)-
263 if (lc_all == 0 || *lc_all == '\0')
lc_all == 0Description
TRUEnever evaluated
FALSEnever evaluated
*lc_all == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
264 x = setlocale (LC_TIME, get_locale_var ("LC_TIME"));
never executed: x = setlocale ( 2 , get_locale_var ("LC_TIME"));
0
265# endif /* LC_TIME */-
266 }
never executed: end of block
0
267#endif /* HAVE_SETLOCALE */-
268 -
269 if (x == 0)
x == 0Description
TRUEevaluated 380 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2409 times by 1 test
Evaluated by:
  • Self test
380-2409
270 {-
271 if (errno == 0)
(*__errno_location ()) == 0Description
TRUEevaluated 378 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-378
272 internal_warning(_("setlocale: %s: cannot change locale (%s)"), var, get_locale_var (var));
executed 378 times by 1 test: internal_warning( dcgettext (((void *)0), "setlocale: %s: cannot change locale (%s)" , 5) , var, get_locale_var (var));
Executed by:
  • Self test
378
273 else-
274 internal_warning(_("setlocale: %s: cannot change locale (%s): %s"), var, get_locale_var (var), strerror (errno));
executed 2 times by 1 test: internal_warning( dcgettext (((void *)0), "setlocale: %s: cannot change locale (%s): %s" , 5) , var, get_locale_var (var), strerror ( (*__errno_location ()) ));
Executed by:
  • Self test
2
275 }-
276-
277 return (x != 0);
executed 2789 times by 1 test: return (x != 0);
Executed by:
  • Self test
2789
278}-
279-
280/* Called when LANG is assigned a value. Tracks value in `lang'. Calls-
281 reset_locale_vars() to reset any default values if LC_ALL is unset or-
282 null. */-
283int-
284set_lang (var, value)-
285 char *var, *value;-
286{-
287 FREE (lang);
executed 126 times by 1 test: sh_xfree((lang), "locale.c", 287);
Executed by:
  • Self test
langDescription
TRUEevaluated 126 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5432 times by 1 test
Evaluated by:
  • Self test
126-5432
288 if (value)
valueDescription
TRUEevaluated 5553 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-5553
289 lang = savestring (value);
executed 5553 times by 1 test: lang = (char *)strcpy (sh_xmalloc((1 + strlen (value)), "locale.c", 289), (value));
Executed by:
  • Self test
5553
290 else-
291 {-
292 lang = (char *)xmalloc (1);-
293 lang[0] = '\0';-
294 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
295-
296 return ((lc_all == 0 || *lc_all == 0) ? reset_locale_vars () : 0);
executed 5558 times by 1 test: return ((lc_all == 0 || *lc_all == 0) ? reset_locale_vars () : 0);
Executed by:
  • Self test
5558
297}-
298-
299/* Set default values for LANG and LC_ALL. Default values for all other-
300 locale-related variables depend on these. */-
301void-
302set_default_lang ()-
303{-
304 char *v;-
305-
306 v = get_string_value ("LC_ALL");-
307 set_locale_var ("LC_ALL", v);-
308-
309 v = get_string_value ("LANG");-
310 set_lang ("LANG", v);-
311}
executed 5447 times by 1 test: end of block
Executed by:
  • Self test
5447
312-
313/* Get the value of one of the locale variables (LC_MESSAGES, LC_CTYPE).-
314 The precedence is as POSIX.2 specifies: LC_ALL has precedence over-
315 the specific locale variables, and LANG, if set, is used as the default. */-
316char *-
317get_locale_var (var)-
318 char *var;-
319{-
320 char *locale;-
321-
322 locale = lc_all;-
323-
324 if (locale == 0 || *locale == 0)
locale == 0Description
TRUEnever evaluated
FALSEevaluated 53787 times by 1 test
Evaluated by:
  • Self test
*locale == 0Description
TRUEevaluated 53787 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-53787
325 locale = get_string_value (var); /* XXX - no mem leak */
executed 53787 times by 1 test: locale = get_string_value (var);
Executed by:
  • Self test
53787
326 if (locale == 0 || *locale == 0)
locale == 0Description
TRUEevaluated 52019 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1768 times by 1 test
Evaluated by:
  • Self test
*locale == 0Description
TRUEnever evaluated
FALSEevaluated 1768 times by 1 test
Evaluated by:
  • Self test
0-52019
327 locale = lang;
executed 52019 times by 1 test: locale = lang;
Executed by:
  • Self test
52019
328 if (locale == 0 || *locale == 0)
locale == 0Description
TRUEevaluated 25181 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28606 times by 1 test
Evaluated by:
  • Self test
*locale == 0Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28581 times by 1 test
Evaluated by:
  • Self test
25-28606
329#if 0-
330 locale = default_locale; /* system-dependent; not really portable. should it be "C"? */-
331#else-
332 locale = "";
executed 25206 times by 1 test: locale = "";
Executed by:
  • Self test
25206
333#endif-
334 return (locale);
executed 53787 times by 1 test: return (locale);
Executed by:
  • Self test
53787
335}-
336-
337/* Called to reset all of the locale variables to their appropriate values-
338 if (and only if) LC_ALL has not been assigned a value. DO NOT CALL THIS-
339 IF LC_ALL HAS BEEN ASSIGNED A VALUE. */-
340static int-
341reset_locale_vars ()-
342{-
343 char *t, *x;-
344#if defined (HAVE_SETLOCALE)-
345 if (lang == 0 || *lang == '\0')
lang == 0Description
TRUEevaluated 5037 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5092 times by 1 test
Evaluated by:
  • Self test
*lang == '\0'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5087 times by 1 test
Evaluated by:
  • Self test
5-5092
346 maybe_make_export_env (); /* trust that this will change environment for setlocale */
executed 5042 times by 1 test: maybe_make_export_env ();
Executed by:
  • Self test
5042
347 if (setlocale (LC_ALL, lang ? lang : "") == 0)
setlocale ( 6 ...ang : "") == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10123 times by 1 test
Evaluated by:
  • Self test
6-10123
348 return 0;
executed 6 times by 1 test: return 0;
Executed by:
  • Self test
6
349-
350 x = 0;-
351# if defined (LC_CTYPE)-
352 x = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE"));-
353# endif-
354# if defined (LC_COLLATE)-
355 t = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE"));-
356# endif-
357# if defined (LC_MESSAGES)-
358 t = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES"));-
359# endif-
360# if defined (LC_NUMERIC)-
361 t = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC"));-
362# endif-
363# if defined (LC_TIME)-
364 t = setlocale (LC_TIME, get_locale_var ("LC_TIME"));-
365# endif-
366-
367 locale_setblanks (); -
368 locale_mb_cur_max = MB_CUR_MAX;-
369 if (x)
xDescription
TRUEevaluated 10123 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-10123
370 locale_utf8locale = locale_isutf8 (x);
executed 10123 times by 1 test: locale_utf8locale = locale_isutf8 (x);
Executed by:
  • Self test
10123
371 locale_shiftstates = mblen ((char *)NULL, 0);-
372 u32reset ();-
373#endif-
374 return 1;
executed 10123 times by 1 test: return 1;
Executed by:
  • Self test
10123
375}-
376-
377/* Translate the contents of STRING, a $"..." quoted string, according-
378 to the current locale. In the `C' or `POSIX' locale, or if gettext()-
379 is not available, the passed string is returned unchanged. The-
380 length of the translated string is returned in LENP, if non-null. */-
381char *-
382localetrans (string, len, lenp)-
383 char *string;-
384 int len, *lenp;-
385{-
386 char *locale, *t;-
387 char *translated;-
388 int tlen;-
389-
390 /* Don't try to translate null strings. */-
391 if (string == 0 || *string == 0)
string == 0Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
*string == 0Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
0-30
392 {-
393 if (lenp)
lenpDescription
TRUEnever evaluated
FALSEnever evaluated
0
394 *lenp = 0;
never executed: *lenp = 0;
0
395 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
396 }-
397-
398 locale = get_locale_var ("LC_MESSAGES");-
399-
400 /* If we don't have setlocale() or the current locale is `C' or `POSIX',-
401 just return the string. If we don't have gettext(), there's no use-
402 doing anything else. */-
403 if (locale == 0 || locale[0] == '\0' ||
locale == 0Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
locale[0] == '\0'Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
0-30
404 (locale[0] == 'C' && locale[1] == '\0') || STREQ (locale, "POSIX"))
never executed: __result = (((const unsigned char *) (const char *) ( locale ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "POSIX" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
locale[0] == 'C'Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
locale[1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
(locale)[0] == ("POSIX")[0]Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-30
405 {-
406 t = (char *)xmalloc (len + 1);-
407 strcpy (t, string);-
408 if (lenp)
lenpDescription
TRUEnever evaluated
FALSEnever evaluated
0
409 *lenp = len;
never executed: *lenp = len;
0
410 return (t);
never executed: return (t);
0
411 }-
412-
413 /* Now try to translate it. */-
414 if (default_domain && *default_domain)
default_domainDescription
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
*default_domainDescription
TRUEnever evaluated
FALSEnever evaluated
0-30
415 translated = dgettext (default_domain, string);
never executed: translated = dcgettext ( default_domain , string , 5) ;
0
416 else-
417 translated = string;
executed 30 times by 1 test: translated = string;
Executed by:
  • Self test
30
418-
419 if (translated == string) /* gettext returns its argument if untranslatable */
translated == stringDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-30
420 {-
421 t = (char *)xmalloc (len + 1);-
422 strcpy (t, string);-
423 if (lenp)
lenpDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-30
424 *lenp = len;
executed 30 times by 1 test: *lenp = len;
Executed by:
  • Self test
30
425 }
executed 30 times by 1 test: end of block
Executed by:
  • Self test
30
426 else-
427 {-
428 tlen = strlen (translated);-
429 t = (char *)xmalloc (tlen + 1);-
430 strcpy (t, translated);-
431 if (lenp)
lenpDescription
TRUEnever evaluated
FALSEnever evaluated
0
432 *lenp = tlen;
never executed: *lenp = tlen;
0
433 }
never executed: end of block
0
434 return (t);
executed 30 times by 1 test: return (t);
Executed by:
  • Self test
30
435}-
436-
437/* Change a bash string into a string suitable for inclusion in a `po' file.-
438 This backslash-escapes `"' and `\' and changes newlines into \\\n"\n". */-
439char *-
440mk_msgstr (string, foundnlp)-
441 char *string;-
442 int *foundnlp;-
443{-
444 register int c, len;-
445 char *result, *r, *s;-
446-
447 for (len = 0, s = string; s && *s; s++)
sDescription
TRUEnever evaluated
FALSEnever evaluated
*sDescription
TRUEnever evaluated
FALSEnever evaluated
0
448 {-
449 len++;-
450 if (*s == '"' || *s == '\\')
*s == '"'Description
TRUEnever evaluated
FALSEnever evaluated
*s == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
0
451 len++;
never executed: len++;
0
452 else if (*s == '\n')
*s == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
453 len += 5;
never executed: len += 5;
0
454 }
never executed: end of block
0
455 -
456 r = result = (char *)xmalloc (len + 3);-
457 *r++ = '"';-
458-
459 for (s = string; s && (c = *s); s++)
sDescription
TRUEnever evaluated
FALSEnever evaluated
(c = *s)Description
TRUEnever evaluated
FALSEnever evaluated
0
460 {-
461 if (c == '\n') /* <NL> -> \n"<NL>" */
c == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
462 {-
463 *r++ = '\\';-
464 *r++ = 'n';-
465 *r++ = '"';-
466 *r++ = '\n';-
467 *r++ = '"';-
468 if (foundnlp)
foundnlpDescription
TRUEnever evaluated
FALSEnever evaluated
0
469 *foundnlp = 1;
never executed: *foundnlp = 1;
0
470 continue;
never executed: continue;
0
471 }-
472 if (c == '"' || c == '\\')
c == '"'Description
TRUEnever evaluated
FALSEnever evaluated
c == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
0
473 *r++ = '\\';
never executed: *r++ = '\\';
0
474 *r++ = c;-
475 }
never executed: end of block
0
476-
477 *r++ = '"';-
478 *r++ = '\0';-
479-
480 return result;
never executed: return result;
0
481}-
482-
483/* $"..." -- Translate the portion of STRING between START and END-
484 according to current locale using gettext (if available) and return-
485 the result. The caller will take care of leaving the quotes intact.-
486 The string will be left without the leading `$' by the caller.-
487 If translation is performed, the translated string will be double-quoted-
488 by the caller. The length of the translated string is returned in LENP,-
489 if non-null. */-
490char *-
491localeexpand (string, start, end, lineno, lenp)-
492 char *string;-
493 int start, end, lineno, *lenp;-
494{-
495 int len, tlen, foundnl;-
496 char *temp, *t, *t2;-
497-
498 temp = (char *)xmalloc (end - start + 1);-
499 for (tlen = 0, len = start; len < end; )
len < endDescription
TRUEevaluated 290 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
35-290
500 temp[tlen++] = string[len++];
executed 290 times by 1 test: temp[tlen++] = string[len++];
Executed by:
  • Self test
290
501 temp[tlen] = '\0';-
502-
503 /* If we're just dumping translatable strings, don't do anything with the-
504 string itself, but if we're dumping in `po' file format, convert it into-
505 a form more palatable to gettext(3) and friends by quoting `"' and `\'-
506 with backslashes and converting <NL> into `\n"<NL>"'. If we find a-
507 newline in TEMP, we first output a `msgid ""' line and then the-
508 translated string; otherwise we output the `msgid' and translated-
509 string all on one line. */-
510 if (dump_translatable_strings)
dump_translatable_stringsDescription
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
0-35
511 {-
512 if (dump_po_strings)
dump_po_stringsDescription
TRUEnever evaluated
FALSEnever evaluated
0
513 {-
514 foundnl = 0;-
515 t = mk_msgstr (temp, &foundnl);-
516 t2 = foundnl ? "\"\"\n" : "";
foundnlDescription
TRUEnever evaluated
FALSEnever evaluated
0
517-
518 printf ("#: %s:%d\nmsgid %s%s\nmsgstr \"\"\n",-
519 yy_input_name (), lineno, t2, t);-
520 free (t);-
521 }
never executed: end of block
0
522 else-
523 printf ("\"%s\"\n", temp);
never executed: printf ("\"%s\"\n", temp);
0
524-
525 if (lenp)
lenpDescription
TRUEnever evaluated
FALSEnever evaluated
0
526 *lenp = tlen;
never executed: *lenp = tlen;
0
527 return (temp);
never executed: return (temp);
0
528 }-
529 else if (*temp)
*tempDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-30
530 {-
531 t = localetrans (temp, tlen, &len);-
532 free (temp);-
533 if (lenp)
lenpDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-30
534 *lenp = len;
executed 30 times by 1 test: *lenp = len;
Executed by:
  • Self test
30
535 return (t);
executed 30 times by 1 test: return (t);
Executed by:
  • Self test
30
536 }-
537 else-
538 {-
539 if (lenp)
lenpDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
540 *lenp = 0;
executed 5 times by 1 test: *lenp = 0;
Executed by:
  • Self test
5
541 return (temp);
executed 5 times by 1 test: return (temp);
Executed by:
  • Self test
5
542 }-
543}-
544-
545/* Set every character in the <blank> character class to be a shell break-
546 character for the lexical analyzer when the locale changes. */-
547static void-
548locale_setblanks ()-
549{-
550 int x;-
551-
552 for (x = 0; x < sh_syntabsiz; x++)
x < sh_syntabsizDescription
TRUEevaluated 4818432 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18822 times by 1 test
Evaluated by:
  • Self test
18822-4818432
553 {-
554 if (isblank ((unsigned char)x))
((*__ctype_b_l...int) _ISblank)Description
TRUEevaluated 37644 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4780788 times by 1 test
Evaluated by:
  • Self test
37644-4780788
555 sh_syntaxtab[x] |= CSHBRK|CBLANK;
executed 37644 times by 1 test: sh_syntaxtab[x] |= 0x0002|0x2000;
Executed by:
  • Self test
37644
556 else if (member (x, shell_break_chars))
((x) ? ((char ...id *)0) ) : 0)Description
TRUEevaluated 150576 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4630212 times by 1 test
Evaluated by:
  • Self test
(x)Description
TRUEevaluated 4761966 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18822 times by 1 test
Evaluated by:
  • Self test
18822-4761966
557 {-
558 sh_syntaxtab[x] |= CSHBRK;-
559 sh_syntaxtab[x] &= ~CBLANK;-
560 }
executed 150576 times by 1 test: end of block
Executed by:
  • Self test
150576
561 else-
562 sh_syntaxtab[x] &= ~(CSHBRK|CBLANK);
executed 4630212 times by 1 test: sh_syntaxtab[x] &= ~(0x0002|0x2000);
Executed by:
  • Self test
4630212
563 }-
564}
executed 18822 times by 1 test: end of block
Executed by:
  • Self test
18822
565-
566/* Parse a locale specification-
567 language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]-
568 and return TRUE if the codeset is UTF-8 or utf8 */-
569static int-
570locale_isutf8 (lspec)-
571 char *lspec;-
572{-
573 char *cp, *encoding;-
574-
575#if HAVE_LANGINFO_CODESET-
576 cp = nl_langinfo (CODESET);-
577 return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8"));
executed 18809 times by 1 test: return (((cp)[0] == ("UTF-8")[0] && __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( cp ) && __builtin_constant_p ( "UTF-8" ) && (__s1_len = __builtin_strlen ( cp ), __s2_len = __builtin_strlen ( "UTF-8" ), (!((size_t)(const void *)(( c...lt = (((const unsigned char *) (const char *) ( "utf8" ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "utf8" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( cp , "utf8" )))); }) == 0));
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( cp ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "UTF-8" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( cp ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "utf8" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-18809
578#elif HAVE_LOCALE_CHARSET-
579 cp = locale_charset ();-
580 return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8"));-
581#else-
582 /* Take a shot */-
583 for (cp = lspec; *cp && *cp != '@' && *cp != '+' && *cp != ','; cp++)-
584 {-
585 if (*cp == '.')-
586 {-
587 for (encoding = ++cp; *cp && *cp != '@' && *cp != '+' && *cp != ','; cp++)-
588 ;-
589 /* The encoding (codeset) is the substring between encoding and cp */-
590 if ((cp - encoding == 5 && STREQN (encoding, "UTF-8", 5)) ||-
591 (cp - encoding == 4 && STREQN (encoding, "utf8", 4)))-
592 return 1;-
593 else-
594 return 0;-
595 }-
596 }-
597 return 0;-
598#endif-
599}-
600-
601#if defined (HAVE_LOCALECONV)-
602int-
603locale_decpoint ()-
604{-
605 struct lconv *lv;-
606-
607 lv = localeconv ();-
608 return (lv && lv->decimal_point && lv->decimal_point[0]) ? lv->decimal_point[0] : '.';
executed 20 times by 1 test: return (lv && lv->decimal_point && lv->decimal_point[0]) ? lv->decimal_point[0] : '.';
Executed by:
  • Self test
20
609}-
610#else-
611# undef locale_decpoint-
612int-
613locale_decpoint ()-
614{-
615 return '.';-
616}-
617#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2