OpenCoverage

unicode.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/unicode.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10extern char *get_locale_var (char *);-
11-
12-
13extern int locale_utf8locale;-
14-
15static int u32init = 0;-
16static int utf8locale = 0;-
17-
18static iconv_t localconv;-
19-
20-
21-
22static char charsetbuf[40];-
23-
24static char *-
25stub_charset ()-
26{-
27 char *locale, *s, *t;-
28-
29 locale = get_locale_var ("LC_CTYPE");-
30 if (locale == 0
locale == 0Description
TRUEnever evaluated
FALSEnever evaluated
|| *
*locale == 0Description
TRUEnever evaluated
FALSEnever evaluated
locale == 0
*locale == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
31 {-
32 strcpy (charsetbuf, "ASCII");-
33 return
never executed: return charsetbuf;
charsetbuf;
never executed: return charsetbuf;
0
34 }-
35 s = strrchr (locale, '.');-
36 if (s
sDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
37 {-
38 -
39 __builtin_strncpy (-
40 charsetbuf-
41 , -
42 s+1-
43 , -
44 sizeof (charsetbuf) - 1-
45 )-
46 ;-
47 charsetbuf[sizeof (charsetbuf) - 1] = '\0';-
48 t = -
49 (__extension__ (__builtin_constant_p (
__builtin_constant_p ( '@' )Description
TRUEnever evaluated
FALSEnever evaluated
0
50 '@'
__builtin_constant_p ( '@' )Description
TRUEnever evaluated
FALSEnever evaluated
0
51 )
__builtin_constant_p ( '@' )Description
TRUEnever evaluated
FALSEnever evaluated
&& !__builtin_constant_p (
!__builtin_con...( charsetbuf )Description
TRUEnever evaluated
FALSEnever evaluated
0
52 charsetbuf
!__builtin_con...( charsetbuf )Description
TRUEnever evaluated
FALSEnever evaluated
0
53 )
!__builtin_con...( charsetbuf )Description
TRUEnever evaluated
FALSEnever evaluated
&& (
( '@' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
54 '@'
( '@' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
55 ) == '\0'
( '@' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
? (char *) __rawmemchr (
0
56 charsetbuf-
57 , -
58 '@'-
59 ) : __builtin_strchr (-
60 charsetbuf-
61 , -
62 '@'-
63 )))-
64 ;-
65 if (t
tDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
66 *
never executed: *t = 0;
t = 0;
never executed: *t = 0;
0
67 return
never executed: return charsetbuf;
charsetbuf;
never executed: return charsetbuf;
0
68 }-
69 -
70 __builtin_strncpy (-
71 charsetbuf-
72 , -
73 locale-
74 , -
75 sizeof (charsetbuf) - 1-
76 )-
77 ;-
78 charsetbuf[sizeof (charsetbuf) - 1] = '\0';-
79 return
never executed: return charsetbuf;
charsetbuf;
never executed: return charsetbuf;
0
80}-
81-
82-
83void-
84u32reset ()-
85{-
86-
87 if (u32init
u32initDescription
TRUEnever evaluated
FALSEevaluated 18822 times by 1 test
Evaluated by:
  • Self test
&& localconv != (iconv_t)-1
localconv != (iconv_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
)
0-18822
88 {-
89 iconv_close (localconv);-
90 localconv = (iconv_t)-1;-
91 }
never executed: end of block
0
92-
93 u32init = 0;-
94 utf8locale = 0;-
95}
executed 18822 times by 1 test: end of block
Executed by:
  • Self test
18822
96-
97-
98int-
99u32tochar (x, s)-
100 unsigned long x;-
101 char *s;-
102{-
103 int l;-
104-
105 l = (
(x <= (0x7f * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
x <=
(x <= (0x7f * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
0
106 (0x7f * 2 + 1)
(x <= (0x7f * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
0
107 )
(x <= (0x7f * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
? 1 : ((
(x <= (0x7fff * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
x <=
(x <= (0x7fff * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
0
108 (0x7fff * 2 + 1)
(x <= (0x7fff * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
0
109 )
(x <= (0x7fff * 2 + 1) )Description
TRUEnever evaluated
FALSEnever evaluated
? 2 : 4);
0
110-
111 if (x <=
x <= (0x7f * 2 + 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
112 (0x7f * 2 + 1)
x <= (0x7f * 2 + 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
113 )-
114 s[0] = x & 0xFF;
never executed: s[0] = x & 0xFF;
0
115 else if (x <=
x <= (0x7fff * 2 + 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
116 (0x7fff * 2 + 1)
x <= (0x7fff * 2 + 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
117 )-
118 {-
119 s[0] = (x >> 8) & 0xFF;-
120 s[1] = x & 0xFF;-
121 }
never executed: end of block
0
122 else-
123 {-
124 s[0] = (x >> 24) & 0xFF;-
125 s[1] = (x >> 16) & 0xFF;-
126 s[2] = (x >> 8) & 0xFF;-
127 s[3] = x & 0xFF;-
128 }
never executed: end of block
0
129 s[l] = '\0';-
130 return
never executed: return l;
l;
never executed: return l;
0
131}-
132-
133int-
134u32tocesc (wc, s)-
135 unsigned int wc;-
136 char *s;-
137{-
138 int l;-
139-
140 if (wc < 0x10000
wc < 0x10000Description
TRUEnever evaluated
FALSEnever evaluated
)
0
141 l = sprintf (s, "\\u%04X", wc);
never executed: l = sprintf (s, "\\u%04X", wc);
0
142 else-
143 l = sprintf (s, "\\u%08X", wc);
never executed: l = sprintf (s, "\\u%08X", wc);
0
144 return
never executed: return l;
l;
never executed: return l;
0
145}-
146-
147-
148int-
149u32toutf8 (wc, s)-
150 unsigned int wc;-
151 char *s;-
152{-
153 int l;-
154-
155 if (wc < 0x0080
wc < 0x0080Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-28
156 {-
157 s[0] = (char)wc;-
158 l = 1;-
159 }
never executed: end of block
0
160 else if (wc < 0x0800
wc < 0x0800Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-28
161 {-
162 s[0] = (wc >> 6) | 0xc0;-
163 s[1] = (wc & 0x3f) | 0x80;-
164 l = 2;-
165 }
never executed: end of block
0
166 else if (wc < 0x10000
wc < 0x10000Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-28
167 {-
168-
169 s[0] = (wc >> 12) | 0xe0;-
170 s[1] = ((wc >> 6) & 0x3f) | 0x80;-
171 s[2] = (wc & 0x3f) | 0x80;-
172 l = 3;-
173 }
never executed: end of block
0
174 else if (wc < 0x200000
wc < 0x200000Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-28
175 {-
176 s[0] = (wc >> 18) | 0xf0;-
177 s[1] = ((wc >> 12) & 0x3f) | 0x80;-
178 s[2] = ((wc >> 6) & 0x3f) | 0x80;-
179 s[3] = (wc & 0x3f) | 0x80;-
180 l = 4;-
181 }
never executed: end of block
0
182-
183 else if (wc < 0x04000000
wc < 0x04000000Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-28
184 {-
185 s[0] = (wc >> 24) | 0xf8;-
186 s[1] = ((wc >> 18) & 0x3f) | 0x80;-
187 s[2] = ((wc >> 12) & 0x3f) | 0x80;-
188 s[3] = ((wc >> 6) & 0x3f) | 0x80;-
189 s[4] = (wc & 0x3f) | 0x80;-
190 l = 5;-
191 }
never executed: end of block
0
192 else if (wc < 0x080000000
wc < 0x080000000Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-28
193 {-
194 s[0] = (wc >> 30) | 0xf8;-
195 s[1] = ((wc >> 24) & 0x3f) | 0x80;-
196 s[2] = ((wc >> 18) & 0x3f) | 0x80;-
197 s[3] = ((wc >> 12) & 0x3f) | 0x80;-
198 s[4] = ((wc >> 6) & 0x3f) | 0x80;-
199 s[5] = (wc & 0x3f) | 0x80;-
200 l = 6;-
201 }
never executed: end of block
0
202 else-
203 l = 0;
executed 28 times by 1 test: l = 0;
Executed by:
  • Self test
28
204-
205 s[l] = '\0';-
206 return
executed 28 times by 1 test: return l;
Executed by:
  • Self test
l;
executed 28 times by 1 test: return l;
Executed by:
  • Self test
28
207}-
208-
209-
210-
211int-
212u32toutf16 (c, s)-
213 unsigned int c;-
214 unsigned short *s;-
215{-
216 int l;-
217-
218 l = 0;-
219 if (c < 0x0d800
c < 0x0d800Description
TRUEnever evaluated
FALSEnever evaluated
|| (c >= 0x0e000
c >= 0x0e000Description
TRUEnever evaluated
FALSEnever evaluated
&& c <= 0x0ffff
c <= 0x0ffffDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
220 {-
221 s[0] = (unsigned short) (c & 0xFFFF);-
222 l = 1;-
223 }
never executed: end of block
0
224 else if (c >= 0x10000
c >= 0x10000Description
TRUEnever evaluated
FALSEnever evaluated
&& c <= 0x010ffff
c <= 0x010ffffDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
225 {-
226 c -= 0x010000;-
227 s[0] = (unsigned short)((c >> 10) + 0xd800);-
228 s[1] = (unsigned short)((c & 0x3ff) + 0xdc00);-
229 l = 2;-
230 }
never executed: end of block
0
231 s[l] = 0;-
232 return
never executed: return l;
l;
never executed: return l;
0
233}-
234-
235-
236-
237int-
238u32cconv (c, s)-
239 unsigned long c;-
240 char *s;-
241{-
242 wchar_t wc;-
243 wchar_t ws[3];-
244 int n;-
245-
246 const char *charset;-
247 char obuf[25], *optr;-
248 size_t obytesleft;-
249 const char *iptr;-
250 size_t sn;-
251-
252-
253-
254 wc = c;-
255 if (sizeof (wchar_t) == 4
sizeof (wchar_t) == 4Description
TRUEevaluated 1112 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
&& c <= 0x7fffffff
c <= 0x7fffffffDescription
TRUEevaluated 1084 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
0-1112
256 n = wctomb (s, wc);
executed 1084 times by 1 test: n = wctomb (s, wc);
Executed by:
  • Self test
1084
257 else if (sizeof (wchar_t) == 2
sizeof (wchar_t) == 2Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
&& c <= 0x10ffff
c <= 0x10ffffDescription
TRUEnever evaluated
FALSEnever evaluated
&& u32toutf16 (c, ws)
u32toutf16 (c, ws)Description
TRUEnever evaluated
FALSEnever evaluated
)
0-28
258 n = wcstombs (s, ws,
never executed: n = wcstombs (s, ws, 16 );
0
259 16
never executed: n = wcstombs (s, ws, 16 );
0
260 );
never executed: n = wcstombs (s, ws, 16 );
0
261 else-
262 n = -1;
executed 28 times by 1 test: n = -1;
Executed by:
  • Self test
28
263 if (n != -1
n != -1Description
TRUEevaluated 1084 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
)
28-1084
264 return
executed 1084 times by 1 test: return n;
Executed by:
  • Self test
n;
executed 1084 times by 1 test: return n;
Executed by:
  • Self test
1084
265-
266-
267-
268-
269 if (u32init == 0
u32init == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
)
12-16
270 {-
271 utf8locale = locale_utf8locale;-
272 localconv = (iconv_t)-1;-
273 if (utf8locale == 0
utf8locale == 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
)
0-16
274 {-
275-
276-
277-
278-
279-
280 charset = stub_charset ();-
281-
282 localconv = iconv_open (charset, "UTF-8");-
283 if (localconv == (iconv_t)-1
localconv == (iconv_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
284-
285 localconv = iconv_open ("ASCII", "UTF-8");
never executed: localconv = iconv_open ("ASCII", "UTF-8");
0
286 }
never executed: end of block
0
287 u32init = 1;-
288 }
executed 16 times by 1 test: end of block
Executed by:
  • Self test
16
289-
290-
291-
292-
293 n = u32toutf8 (c, s);-
294 if (utf8locale
utf8localeDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
)
0-28
295 return
executed 28 times by 1 test: return n;
Executed by:
  • Self test
n;
executed 28 times by 1 test: return n;
Executed by:
  • Self test
28
296-
297-
298-
299-
300 if (localconv == (iconv_t)-1
localconv == (iconv_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
301 return
never executed: return n;
n;
never executed: return n;
0
302-
303 optr = obuf;-
304 obytesleft = sizeof (obuf);-
305 iptr = s;-
306 sn = n;-
307-
308 iconv (localconv, -
309 ((void *)0)-
310 , -
311 ((void *)0)-
312 , -
313 ((void *)0)-
314 , -
315 ((void *)0)-
316 );-
317-
318 if (iconv (localconv, ( char **)&iptr, &sn, &optr, &obytesleft) == (size_t)-1
iconv (localco... == (size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
319 {-
320-
321 n = u32tocesc (c, s);-
322 return
never executed: return n;
n;
never executed: return n;
0
323 }-
324-
325 *optr = '\0';-
326-
327-
328-
329 strcpy (s, obuf);-
330 return
never executed: return (optr - obuf);
(optr - obuf);
never executed: return (optr - obuf);
0
331-
332-
333 if
dead code: if (locale_utf8locale) n = u32toutf8 (c, s); else n = u32tocesc (c, s);
(locale_utf8locale)
dead code: if (locale_utf8locale) n = u32toutf8 (c, s); else n = u32tocesc (c, s);
-
334 n = u32toutf8 (c, s);
dead code: if (locale_utf8locale) n = u32toutf8 (c, s); else n = u32tocesc (c, s);
-
335 else
dead code: if (locale_utf8locale) n = u32toutf8 (c, s); else n = u32tocesc (c, s);
-
336 n = u32tocesc (c, s);
dead code: if (locale_utf8locale) n = u32toutf8 (c, s); else n = u32tocesc (c, s);
-
337 return
dead code: return n;
n;
dead code: return n;
-
338}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2