Example #1
0
int
po_message_is_format (po_message_t message, const char *format_type)
{
  message_ty *mp = (message_ty *) message;
  size_t len = strlen (format_type);
  size_t i;

  if (len >= 7 && memcmp (format_type + len - 7, "-format", 7) == 0)
    for (i = 0; i < NFORMATS; i++)
      if (strlen (format_language[i]) == len - 7
	  && memcmp (format_language[i], format_type, len - 7) == 0)
	/* The given format_type corresponds to (enum format_type) i.  */
	return (possible_format_p (mp->is_format[i]) ? 1 : 0);
  return 0;
}
Example #2
0
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;
	  }