| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/unicode.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | extern char *get_locale_var (char *); | - | ||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | extern int locale_utf8locale; | - | ||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | static int u32init = 0; | - | ||||||||||||||||||
| 16 | static int utf8locale = 0; | - | ||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | static iconv_t localconv; | - | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | static char charsetbuf[40]; | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | static char * | - | ||||||||||||||||||
| 25 | stub_charset () | - | ||||||||||||||||||
| 26 | { | - | ||||||||||||||||||
| 27 | char *locale, *s, *t; | - | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | locale = get_locale_var ("LC_CTYPE"); | - | ||||||||||||||||||
| 30 | if (locale == 0
| 0 | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 | strcpy (charsetbuf, "ASCII"); | - | ||||||||||||||||||
| 33 | return never executed: charsetbuf;return charsetbuf;never executed: return charsetbuf; | 0 | ||||||||||||||||||
| 34 | } | - | ||||||||||||||||||
| 35 | s = strrchr (locale, '.'); | - | ||||||||||||||||||
| 36 | if (s
| 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 (
| 0 | ||||||||||||||||||
| 50 | '@'
| 0 | ||||||||||||||||||
| 51 | )
| 0 | ||||||||||||||||||
| 52 | charsetbuf
| 0 | ||||||||||||||||||
| 53 | )
| 0 | ||||||||||||||||||
| 54 | '@'
| 0 | ||||||||||||||||||
| 55 | ) == '\0'
| 0 | ||||||||||||||||||
| 56 | charsetbuf | - | ||||||||||||||||||
| 57 | , | - | ||||||||||||||||||
| 58 | '@' | - | ||||||||||||||||||
| 59 | ) : __builtin_strchr ( | - | ||||||||||||||||||
| 60 | charsetbuf | - | ||||||||||||||||||
| 61 | , | - | ||||||||||||||||||
| 62 | '@' | - | ||||||||||||||||||
| 63 | ))) | - | ||||||||||||||||||
| 64 | ; | - | ||||||||||||||||||
| 65 | if (t
| 0 | ||||||||||||||||||
| 66 | * never executed: t = 0;*t = 0;never executed: *t = 0; | 0 | ||||||||||||||||||
| 67 | return never executed: charsetbuf;return 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: charsetbuf;return charsetbuf;never executed: return charsetbuf; | 0 | ||||||||||||||||||
| 80 | } | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | void | - | ||||||||||||||||||
| 84 | u32reset () | - | ||||||||||||||||||
| 85 | { | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | if (u32init
| 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 blockExecuted by:
| 18822 | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | int | - | ||||||||||||||||||
| 99 | u32tochar (x, s) | - | ||||||||||||||||||
| 100 | unsigned long x; | - | ||||||||||||||||||
| 101 | char *s; | - | ||||||||||||||||||
| 102 | { | - | ||||||||||||||||||
| 103 | int l; | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | l = (
| 0 | ||||||||||||||||||
| 106 | (0x7f * 2 + 1)
| 0 | ||||||||||||||||||
| 107 | )
| 0 | ||||||||||||||||||
| 108 | (0x7fff * 2 + 1)
| 0 | ||||||||||||||||||
| 109 | )
| 0 | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | if (x <=
| 0 | ||||||||||||||||||
| 112 | (0x7f * 2 + 1)
| 0 | ||||||||||||||||||
| 113 | ) | - | ||||||||||||||||||
| 114 | s[0] = x & 0xFF; never executed: s[0] = x & 0xFF; | 0 | ||||||||||||||||||
| 115 | else if (x <=
| 0 | ||||||||||||||||||
| 116 | (0x7fff * 2 + 1)
| 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: l;return l;never executed: return l; | 0 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | int | - | ||||||||||||||||||
| 134 | u32tocesc (wc, s) | - | ||||||||||||||||||
| 135 | unsigned int wc; | - | ||||||||||||||||||
| 136 | char *s; | - | ||||||||||||||||||
| 137 | { | - | ||||||||||||||||||
| 138 | int l; | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | if (wc < 0x10000
| 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: l;return l;never executed: return l; | 0 | ||||||||||||||||||
| 145 | } | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | int | - | ||||||||||||||||||
| 149 | u32toutf8 (wc, s) | - | ||||||||||||||||||
| 150 | unsigned int wc; | - | ||||||||||||||||||
| 151 | char *s; | - | ||||||||||||||||||
| 152 | { | - | ||||||||||||||||||
| 153 | int l; | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | if (wc < 0x0080
| 0-28 | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | s[0] = (char)wc; | - | ||||||||||||||||||
| 158 | l = 1; | - | ||||||||||||||||||
| 159 | } never executed: end of block | 0 | ||||||||||||||||||
| 160 | else if (wc < 0x0800
| 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
| 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
| 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
| 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
| 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:
| 28 | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | s[l] = '\0'; | - | ||||||||||||||||||
| 206 | return executed 28 times by 1 test: l;return l;Executed by:
executed 28 times by 1 test: return l;Executed by:
| 28 | ||||||||||||||||||
| 207 | } | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | int | - | ||||||||||||||||||
| 212 | u32toutf16 (c, s) | - | ||||||||||||||||||
| 213 | unsigned int c; | - | ||||||||||||||||||
| 214 | unsigned short *s; | - | ||||||||||||||||||
| 215 | { | - | ||||||||||||||||||
| 216 | int l; | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | l = 0; | - | ||||||||||||||||||
| 219 | if (c < 0x0d800
| 0 | ||||||||||||||||||
| 220 | { | - | ||||||||||||||||||
| 221 | s[0] = (unsigned short) (c & 0xFFFF); | - | ||||||||||||||||||
| 222 | l = 1; | - | ||||||||||||||||||
| 223 | } never executed: end of block | 0 | ||||||||||||||||||
| 224 | else if (c >= 0x10000
| 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: l;return l;never executed: return l; | 0 | ||||||||||||||||||
| 233 | } | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | int | - | ||||||||||||||||||
| 238 | u32cconv (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
| 0-1112 | ||||||||||||||||||
| 256 | n = wctomb (s, wc); executed 1084 times by 1 test: n = wctomb (s, wc);Executed by:
| 1084 | ||||||||||||||||||
| 257 | else if (sizeof (wchar_t) == 2
| 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:
| 28 | ||||||||||||||||||
| 263 | if (n != -1
| 28-1084 | ||||||||||||||||||
| 264 | return executed 1084 times by 1 test: n;return n;Executed by:
executed 1084 times by 1 test: return n;Executed by:
| 1084 | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | if (u32init == 0
| 12-16 | ||||||||||||||||||
| 270 | { | - | ||||||||||||||||||
| 271 | utf8locale = locale_utf8locale; | - | ||||||||||||||||||
| 272 | localconv = (iconv_t)-1; | - | ||||||||||||||||||
| 273 | if (utf8locale == 0
| 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
| 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 blockExecuted by:
| 16 | ||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | n = u32toutf8 (c, s); | - | ||||||||||||||||||
| 294 | if (utf8locale
| 0-28 | ||||||||||||||||||
| 295 | return executed 28 times by 1 test: n;return n;Executed by:
executed 28 times by 1 test: return n;Executed by:
| 28 | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | if (localconv == (iconv_t)-1
| 0 | ||||||||||||||||||
| 301 | return never executed: n;return 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
| 0 | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | n = u32tocesc (c, s); | - | ||||||||||||||||||
| 322 | return never executed: n;return n;never executed: return n; | 0 | ||||||||||||||||||
| 323 | } | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | *optr = '\0'; | - | ||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | strcpy (s, obuf); | - | ||||||||||||||||||
| 330 | return never executed: (optr - obuf);return (optr - obuf);never executed: return (optr - obuf); | 0 | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | if dead code: (locale_utf8locale)if (locale_utf8locale) n = u32toutf8 (c, s); else n = u32tocesc (c, s);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: n;return n;dead code: return n; | - | ||||||||||||||||||
| 338 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |