void po_lex_charset_set (const char *header_entry, const char *filename) { /* Verify the validity of CHARSET. It is necessary 1. for the correct treatment of multibyte characters containing 0x5C bytes in the PO lexer, 2. so that at run time, gettext() can call iconv() to convert msgstr. */ const char *charsetstr = c_strstr (header_entry, "charset="); if (charsetstr != NULL) { size_t len; char *charset; const char *canon_charset; charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); charset = (char *) xmalloca (len + 1); memcpy (charset, charsetstr, len); charset[len] = '\0'; canon_charset = po_charset_canonicalize (charset); if (canon_charset == NULL) { /* Don't warn for POT files, because POT files usually contain only ASCII msgids. */ size_t filenamelen = strlen (filename); if (!(filenamelen >= 4 && memcmp (filename + filenamelen - 4, ".pot", 4) == 0 && strcmp (charset, "CHARSET") == 0)) { char *warning_message = xasprintf (_("\ Charset \"%s\" is not a portable encoding name.\n\ Message conversion to user's charset might not work.\n"), charset); po_xerror (PO_SEVERITY_WARNING, NULL, filename, (size_t)(-1), (size_t)(-1), true, warning_message); free (warning_message); }
static void wrap (const message_ty *mp, ostream_t stream, const char *line_prefix, int extra_indent, const char *css_class, const char *name, const char *value, enum is_wrap do_wrap, size_t page_width, const char *charset) { const char *canon_charset; char *fmtdir; char *fmtdirattr; const char *s; bool first_line; #if HAVE_ICONV const char *envval; iconv_t conv; #endif bool weird_cjk; canon_charset = po_charset_canonicalize (charset); #if HAVE_ICONV /* The old Solaris/openwin msgfmt and GNU msgfmt <= 0.10.35 don't know about multibyte encodings, and require a spurious backslash after every multibyte character whose last byte is 0x5C. Some programs, like vim, distribute PO files in this broken format. It is important for such programs that GNU msgmerge continues to support this old PO file format when the Makefile requests it. */ envval = getenv ("OLD_PO_FILE_OUTPUT"); if (envval != NULL && *envval != '\0') /* Write a PO file in old format, with extraneous backslashes. */ conv = (iconv_t)(-1); else if (canon_charset == NULL) /* Invalid PO file encoding. */ conv = (iconv_t)(-1); else /* Avoid glibc-2.1 bug with EUC-KR. */ # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION if (strcmp (canon_charset, "EUC-KR") == 0) conv = (iconv_t)(-1); else # endif /* Avoid Solaris 2.9 bug with GB2312, EUC-TW, BIG5, BIG5-HKSCS, GBK, GB18030. */ # if defined __sun && !defined _LIBICONV_VERSION if ( strcmp (canon_charset, "GB2312") == 0 || strcmp (canon_charset, "EUC-TW") == 0 || strcmp (canon_charset, "BIG5") == 0 || strcmp (canon_charset, "BIG5-HKSCS") == 0 || strcmp (canon_charset, "GBK") == 0 || strcmp (canon_charset, "GB18030") == 0) conv = (iconv_t)(-1); else # endif /* Use iconv() to parse multibyte characters. */ conv = iconv_open ("UTF-8", canon_charset); if (conv != (iconv_t)(-1)) weird_cjk = false; else #endif if (canon_charset == NULL) weird_cjk = false; else weird_cjk = po_is_charset_weird_cjk (canon_charset); if (canon_charset == NULL) canon_charset = po_charset_ascii; /* Determine the extent of format string directives. */ fmtdir = NULL; fmtdirattr = NULL; if (value[0] != '\0') { bool is_msgstr = (strlen (name) >= 6 && memcmp (name, "msgstr", 6) == 0); /* or equivalent: = (css_class == class_msgstr) */ size_t i; for (i = 0; i < NFORMATS; i++) if (possible_format_p (mp->is_format[i])) { size_t len = strlen (value); struct formatstring_parser *parser = formatstring_parsers[i]; char *invalid_reason = NULL; void *descr; const char *fdp; const char *fd_end; char *fdap; fmtdir = XCALLOC (len, char); descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason); if (descr != NULL) parser->free (descr); /* Locate the FMTDIR_* bits and transform the array to an array of attributes. */ fmtdirattr = XCALLOC (len, char); fdap = fmtdirattr; fd_end = fmtdir + len; for (fdp = fmtdir, fdap = fmtdirattr; fdp < fd_end; fdp++, fdap++) if (*fdp & FMTDIR_START) { const char *fdq; for (fdq = fdp; fdq < fd_end; fdq++) if (*fdq & (FMTDIR_END | FMTDIR_ERROR)) break; if (!(fdq < fd_end)) /* The ->parse method has determined the start of a formatstring directive but not stored a bit indicating its end. It is a bug in the ->parse method. */ abort (); if (*fdq & FMTDIR_ERROR) memset (fdap, ATTR_INVALID_FORMAT_DIRECTIVE, fdq - fdp + 1); else memset (fdap, ATTR_FORMAT_DIRECTIVE, fdq - fdp + 1); fdap += fdq - fdp; fdp = fdq; } else *fdap = 0; break; }