bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Word wrapping in PO


From: Bruno Haible
Subject: Re: Word wrapping in PO
Date: Wed, 26 Dec 2007 16:45:41 +0100
User-agent: KMail/1.5.4

Dwayne Bailey wrote in [1]:
> Two more cases I've now seen that make things rather confusing.
> 
> Variables: %s can break over two lines
> Tags: </b> it is perfectly permissible to break these over lines.
> 
> Unfortunately the Unicode algorithms are very focused on text and will
> break anywhere not always in ideal places.

I'm applying this; it fixes the problem with breaking format directives like
%s.

2007-12-22  Bruno Haible  <address@hidden>

        * write-po.c (wrap): Avoid breaking line in the middle of a format
        directive.
        Reported by Dwayne Bailey <address@hidden>.

diff -r -c3 --exclude='*.po*' --exclude='*.info*' --exclude='*_*.html' 
--exclude='*.*.html' --exclude='*.[13]' --exclude='*.1.in' 
--exclude=Makefile.in --exclude=aclocal.m4 --exclude=configure 
--exclude=config.h.in --exclude=version.texi --exclude=stamp-vti 
--exclude='po-*-gen*.[ch]' --exclude='*.o' --exclude='*.lo' --exclude='*.gmo' 
--exclude=ABOUT-NLS --exclude=gnulib-lib --exclude=gnulib-m4 
--exclude=Makefile.gnulib --exclude='javadoc[12]' --exclude=CVS 
gettext-cvs/gettext-tools/src/write-po.c 
gettext-work/gettext-tools/src/write-po.c
*** gettext-cvs/gettext-tools/src/write-po.c    Mon Oct 22 04:01:35 2007
--- gettext-work/gettext-tools/src/write-po.c   Sat Dec 22 12:39:40 2007
***************
*** 522,527 ****
--- 522,528 ----
  {
    const char *canon_charset;
    char *fmtdir;
+   char *fmtdirattr;
    const char *s;
    bool first_line;
  #if HAVE_ICONV
***************
*** 583,589 ****
  
    /* Determine the extent of format string directives.  */
    fmtdir = NULL;
!   if (is_stylable (stream) && value[0] != '\0')
      {
        bool is_msgstr =
        (strlen (name) >= 6 && memcmp (name, "msgstr", 6) == 0);
--- 584,591 ----
  
    /* 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);
***************
*** 597,604 ****
            struct formatstring_parser *parser = formatstring_parsers[i];
            char *invalid_reason = NULL;
            void *descr;
!           char *fdp;
!           char *fd_end;
  
            fmtdir = XCALLOC (len, char);
            descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason);
--- 599,607 ----
            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);
***************
*** 607,617 ****
  
            /* Locate the FMTDIR_* bits and transform the array to an array
               of attributes.  */
            fd_end = fmtdir + len;
!           for (fdp = fmtdir; fdp < fd_end; fdp++)
              if (*fdp & FMTDIR_START)
                {
!                 char *fdq;
                  for (fdq = fdp; fdq < fd_end; fdq++)
                    if (*fdq & (FMTDIR_END | FMTDIR_ERROR))
                      break;
--- 610,622 ----
  
            /* 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;
***************
*** 621,633 ****
                       its end. It is a bug in the ->parse method.  */
                    abort ();
                  if (*fdq & FMTDIR_ERROR)
!                   memset (fdp, ATTR_INVALID_FORMAT_DIRECTIVE, fdq - fdp + 1);
                  else
!                   memset (fdp, ATTR_FORMAT_DIRECTIVE, fdq - fdp + 1);
                  fdp = fdq;
                }
              else
!               *fdp = 0;
  
            break;
          }
--- 626,639 ----
                       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;
          }
***************
*** 733,744 ****
        }
        portion = XNMALLOC (portion_len, char);
        overrides = XNMALLOC (portion_len, char);
-       memset (overrides, UC_BREAK_UNDEFINED, portion_len);
        attributes = XNMALLOC (portion_len, char);
        for (ep = s, pp = portion, op = overrides, ap = attributes; ep < es; 
ep++)
        {
          char c = *ep;
!         char attr = (fmtdir != NULL ? fmtdir[ep - value] : 0);
          if (is_escape (c))
            {
              switch (c)
--- 739,754 ----
        }
        portion = XNMALLOC (portion_len, char);
        overrides = XNMALLOC (portion_len, char);
        attributes = XNMALLOC (portion_len, char);
        for (ep = s, pp = portion, op = overrides, ap = attributes; ep < es; 
ep++)
        {
          char c = *ep;
!         char attr = (fmtdirattr != NULL ? fmtdirattr[ep - value] : 0);
!         char brk = UC_BREAK_UNDEFINED;
!         /* Don't break inside format directives.  */
!         if (attr == ATTR_FORMAT_DIRECTIVE
!             && (fmtdir[ep - value] & FMTDIR_START) == 0)
!           brk = UC_BREAK_PROHIBITED;
          if (is_escape (c))
            {
              switch (c)
***************
*** 754,760 ****
                }
              *pp++ = '\\';
              *pp++ = c;
!             op++;
              *op++ = UC_BREAK_PROHIBITED;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
--- 764,770 ----
                }
              *pp++ = '\\';
              *pp++ = c;
!             *op++ = brk;
              *op++ = UC_BREAK_PROHIBITED;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
***************
*** 777,783 ****
              *pp++ = '0' + (((unsigned char) c >> 6) & 7);
              *pp++ = '0' + (((unsigned char) c >> 3) & 7);
              *pp++ = '0' + ((unsigned char) c & 7);
!             op++;
              *op++ = UC_BREAK_PROHIBITED;
              *op++ = UC_BREAK_PROHIBITED;
              *op++ = UC_BREAK_PROHIBITED;
--- 787,793 ----
              *pp++ = '0' + (((unsigned char) c >> 6) & 7);
              *pp++ = '0' + (((unsigned char) c >> 3) & 7);
              *pp++ = '0' + ((unsigned char) c & 7);
!             *op++ = brk;
              *op++ = UC_BREAK_PROHIBITED;
              *op++ = UC_BREAK_PROHIBITED;
              *op++ = UC_BREAK_PROHIBITED;
***************
*** 790,796 ****
            {
              *pp++ = '\\';
              *pp++ = c;
!             op++;
              *op++ = UC_BREAK_PROHIBITED;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
--- 800,806 ----
            {
              *pp++ = '\\';
              *pp++ = c;
!             *op++ = brk;
              *op++ = UC_BREAK_PROHIBITED;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
              *ap++ = attr | ATTR_ESCAPE_SEQUENCE;
***************
*** 838,843 ****
--- 848,855 ----
                  insize = inptr - ep;
                  memcpy_small (pp, ep, insize);
                  pp += insize;
+                 *op = brk;
+                 memset_small (op + 1, UC_BREAK_PROHIBITED, insize - 1);
                  op += insize;
                  memset_small (ap, attr, insize);
                  ap += insize;
***************
*** 855,868 ****
                      *pp++ = c;
                      ep += 1;
                      *pp++ = *ep;
!                     op += 2;
                      *ap++ = attr;
                      *ap++ = attr;
                    }
                  else
                    {
                      *pp++ = c;
!                     op++;
                      *ap++ = attr;
                    }
                }
--- 867,881 ----
                      *pp++ = c;
                      ep += 1;
                      *pp++ = *ep;
!                     *op++ = brk;
!                     *op++ = UC_BREAK_PROHIBITED;
                      *ap++ = attr;
                      *ap++ = attr;
                    }
                  else
                    {
                      *pp++ = c;
!                     *op++ = brk;
                      *ap++ = attr;
                    }
                }
***************
*** 1118,1123 ****
--- 1131,1138 ----
      }
    while (*s);
  
+   if (fmtdirattr != NULL)
+     free (fmtdirattr);
    if (fmtdir != NULL)
      free (fmtdir);
  

[1] http://lists.gnu.org/archive/html/bug-gnu-utils/2007-12/msg00054.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]