| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | #include <config.h> | - |
| 21 | | - |
| 22 | | - |
| 23 | #include "unicodeio.h" | - |
| 24 | | - |
| 25 | #include <stdio.h> | - |
| 26 | #include <string.h> | - |
| 27 | #include <errno.h> | - |
| 28 | | - |
| 29 | #if HAVE_ICONV | - |
| 30 | # include <iconv.h> | - |
| 31 | #endif | - |
| 32 | | - |
| 33 | #include <error.h> | - |
| 34 | | - |
| 35 | #include "gettext.h" | - |
| 36 | #define _(msgid) gettext (msgid) | - |
| 37 | #define N_(msgid) msgid | - |
| 38 | | - |
| 39 | #include "localcharset.h" | - |
| 40 | #include "unistr.h" | - |
| 41 | | - |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | | - |
| 48 | | - |
| 49 | | - |
| 50 | | - |
| 51 | | - |
| 52 | | - |
| 53 | | - |
| 54 | | - |
| 55 | #define UTF8_NAME "UTF-8" | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | long | - |
| 64 | unicode_to_mb (unsigned int code, | - |
| 65 | long (*success) (const char *buf, size_t buflen, | - |
| 66 | void *callback_arg), | - |
| 67 | long (*failure) (unsigned int code, const char *msg, | - |
| 68 | void *callback_arg), | - |
| 69 | void *callback_arg) | - |
| 70 | { | - |
| 71 | static int initialized; | - |
| 72 | static int is_utf8; | - |
| 73 | #if HAVE_ICONV | - |
| 74 | static iconv_t utf8_to_local; | - |
| 75 | #endif | - |
| 76 | | - |
| 77 | char inbuf[6]; | - |
| 78 | int count; | - |
| 79 | | - |
| 80 | if (!initialized)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 81 | { | - |
| 82 | const char *charset = locale_charset (); | - |
| 83 | | - |
| 84 | is_utf8 = !strcmp (charset, UTF8_NAME); never executed: __result = (((const unsigned char *) (const char *) ( charset ))[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 | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 85 | #if HAVE_ICONV | - |
| 86 | if (!is_utf8)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 87 | { | - |
| 88 | utf8_to_local = iconv_open (charset, UTF8_NAME); | - |
| 89 | if (utf8_to_local == (iconv_t)(-1))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 90 | | - |
| 91 | utf8_to_local = iconv_open ("ASCII", UTF8_NAME); never executed: utf8_to_local = iconv_open ("ASCII", "UTF-8"); | 0 |
| 92 | } never executed: end of block | 0 |
| 93 | #endif | - |
| 94 | initialized = 1; | - |
| 95 | } never executed: end of block | 0 |
| 96 | | - |
| 97 | | - |
| 98 | if (!is_utf8)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 99 | { | - |
| 100 | #if HAVE_ICONV | - |
| 101 | if (utf8_to_local == (iconv_t)(-1))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 102 | return failure (code, N_("iconv function not usable"), callback_arg); never executed: return failure (code, "iconv function not usable", callback_arg); | 0 |
| 103 | #else | - |
| 104 | return failure (code, N_("iconv function not available"), callback_arg); | - |
| 105 | #endif | - |
| 106 | } never executed: end of block | 0 |
| 107 | | - |
| 108 | | - |
| 109 | count = u8_uctomb ((unsigned char *) inbuf, code, sizeof (inbuf)); | - |
| 110 | if (count < 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 111 | return failure (code, N_("character out of range"), callback_arg); never executed: return failure (code, "character out of range", callback_arg); | 0 |
| 112 | | - |
| 113 | #if HAVE_ICONV | - |
| 114 | if (!is_utf8)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 115 | { | - |
| 116 | char outbuf[25]; | - |
| 117 | const char *inptr; | - |
| 118 | size_t inbytesleft; | - |
| 119 | char *outptr; | - |
| 120 | size_t outbytesleft; | - |
| 121 | size_t res; | - |
| 122 | | - |
| 123 | inptr = inbuf; | - |
| 124 | inbytesleft = count; | - |
| 125 | outptr = outbuf; | - |
| 126 | outbytesleft = sizeof (outbuf); | - |
| 127 | | - |
| 128 | | - |
| 129 | res = iconv (utf8_to_local, | - |
| 130 | (ICONV_CONST char **)&inptr, &inbytesleft, | - |
| 131 | &outptr, &outbytesleft); | - |
| 132 | if (inbytesleft > 0 || res == (size_t)(-1)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 133 | | - |
| 134 | # if !defined _LIBICONV_VERSION && (defined sgi || defined __sgi) | - |
| 135 | || (res > 0 && code != 0 && outptr - outbuf == 1 && *outbuf == '\0') | - |
| 136 | # endif | - |
| 137 | ) | - |
| 138 | return failure (code, NULL, callback_arg); never executed: return failure (code, ((void *)0) , callback_arg); | 0 |
| 139 | | - |
| 140 | | - |
| 141 | # if defined _LIBICONV_VERSION \ | - |
| 142 | || !(((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) \ | - |
| 143 | && !defined __UCLIBC__) \ | - |
| 144 | || defined __sun) | - |
| 145 | | - |
| 146 | | - |
| 147 | res = iconv (utf8_to_local, NULL, NULL, &outptr, &outbytesleft); | - |
| 148 | if (res == (size_t)(-1))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 149 | return failure (code, NULL, callback_arg); never executed: return failure (code, ((void *)0) , callback_arg); | 0 |
| 150 | # endif | - |
| 151 | | - |
| 152 | return success (outbuf, outptr - outbuf, callback_arg); never executed: return success (outbuf, outptr - outbuf, callback_arg); | 0 |
| 153 | } | - |
| 154 | #endif | - |
| 155 | | - |
| 156 | | - |
| 157 | return success (inbuf, count, callback_arg); never executed: return success (inbuf, count, callback_arg); | 0 |
| 158 | } | - |
| 159 | | - |
| 160 | | - |
| 161 | | - |
| 162 | long | - |
| 163 | fwrite_success_callback (const char *buf, size_t buflen, void *callback_arg) | - |
| 164 | { | - |
| 165 | FILE *stream = (FILE *) callback_arg; | - |
| 166 | | - |
| 167 | | - |
| 168 | | - |
| 169 | | - |
| 170 | | - |
| 171 | fwrite (buf, 1, buflen, stream); | - |
| 172 | return 0; never executed: return 0; | 0 |
| 173 | } | - |
| 174 | | - |
| 175 | | - |
| 176 | static long | - |
| 177 | exit_failure_callback (unsigned int code, const char *msg, | - |
| 178 | void *callback_arg _GL_UNUSED) | - |
| 179 | { | - |
| 180 | if (msg == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 181 | error (1, 0, _("cannot convert U+%04X to local character set"), code); never executed: error (1, 0, dcgettext (((void *)0), "cannot convert U+%04X to local character set" , 5) , code); | 0 |
| 182 | else | - |
| 183 | error (1, 0, _("cannot convert U+%04X to local character set: %s"), code, never executed: error (1, 0, dcgettext (((void *)0), "cannot convert U+%04X to local character set: %s" , 5) , code, dcgettext (((void *)0), msg , 5) ); | 0 |
| 184 | gettext (msg)); never executed: error (1, 0, dcgettext (((void *)0), "cannot convert U+%04X to local character set: %s" , 5) , code, dcgettext (((void *)0), msg , 5) ); | 0 |
| 185 | return -1; never executed: return -1; | 0 |
| 186 | } | - |
| 187 | | - |
| 188 | | - |
| 189 | | - |
| 190 | static long | - |
| 191 | fallback_failure_callback (unsigned int code, | - |
| 192 | const char *msg _GL_UNUSED, | - |
| 193 | void *callback_arg) | - |
| 194 | { | - |
| 195 | FILE *stream = (FILE *) callback_arg; | - |
| 196 | | - |
| 197 | if (code < 0x10000)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 198 | fprintf (stream, "\\u%04X", code); never executed: fprintf (stream, "\\u%04X", code); | 0 |
| 199 | else | - |
| 200 | fprintf (stream, "\\U%08X", code); never executed: fprintf (stream, "\\U%08X", code); | 0 |
| 201 | return -1; never executed: return -1; | 0 |
| 202 | } | - |
| 203 | | - |
| 204 | | - |
| 205 | | - |
| 206 | | - |
| 207 | void | - |
| 208 | print_unicode_char (FILE *stream, unsigned int code, int exit_on_error) | - |
| 209 | { | - |
| 210 | unicode_to_mb (code, fwrite_success_callback, | - |
| 211 | exit_on_error | - |
| 212 | ? exit_failure_callback | - |
| 213 | : fallback_failure_callback, | - |
| 214 | stream); | - |
| 215 | } never executed: end of block | 0 |
| | |