source: grub-pc/trunk/fuentes/grub-core/gnulib-fix-width.diff @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 6.7 KB
  • lib/argp-fmtstream.c

    diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c
    index 7aa317c..02406ff 100644
    a b  
    2929#include <errno.h>
    3030#include <stdarg.h>
    3131#include <ctype.h>
     32#include <wchar.h>
    3233
    3334#include "argp-fmtstream.h"
    3435#include "argp-namefrob.h"
     36#include "mbswidth.h"
    3537
    3638#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
    3739
    weak_alias (__argp_fmtstream_free, argp_fmtstream_free) 
    116118#endif
    117119#endif
    118120
    119121
     122
     123/* Return the pointer to the first character that doesn't fit in l columns.  */
     124static inline const ptrdiff_t
     125add_width (const char *ptr, const char *end, size_t l)
     126{
     127  mbstate_t ps;
     128  const char *ptr0 = ptr;
     129
     130  memset (&ps, 0, sizeof (ps));
     131
     132  while (ptr < end)
     133    {
     134      wchar_t wc;
     135      size_t s, k;
     136
     137      s = mbrtowc (&wc, ptr, end - ptr, &ps);
     138      if (s == (size_t) -1)
     139        break;
     140      if (s == (size_t) -2)
     141        {
     142          if (1 >= l)
     143            break;
     144          l--;
     145          ptr++;
     146          continue;
     147        }
     148
     149      if (wc == '\e' && ptr + 3 < end
     150          && ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1')
     151          && ptr[3] == 'm')
     152        {
     153          ptr += 4;
     154          continue;
     155        }
     156
     157      k = wcwidth (wc);
     158
     159      if (k >= l)
     160        break;
     161      l -= k;
     162      ptr += s;
     163    }
     164  return ptr - ptr0;
     165}
     166
    120167/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
    121168   end of its buffer.  This code is mostly from glibc stdio/linewrap.c.  */
  • lib/argp-help.c

     void
    @@ -168,14 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
     
           if (!nl)
             {
    +	  size_t display_width = mbsnwidth (buf, fs->p - buf, MBSW_STOP_AT_NUL);
               /* The buffer ends in a partial line.  */
     
    -          if (fs->point_col + len < fs->rmargin)
    +          if (fs->point_col + display_width < fs->rmargin)
                 {
                   /* The remaining buffer text is a partial line and fits
                      within the maximum line width.  Advance point for the
                      characters to be written and stop scanning.  */
    -              fs->point_col += len;
    +              fs->point_col += display_width;
                   break;
                 }
               else
    @@ -183,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
                    the end of the buffer.  */
                 nl = fs->p;
             }
    -      else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
    -        {
    -          /* The buffer contains a full line that fits within the maximum
    -             line width.  Reset point and scan the next line.  */
    -          fs->point_col = 0;
    -          buf = nl + 1;
    -          continue;
    -        }
    +      else
    +	{
    +	  size_t display_width = mbsnwidth (buf, nl - buf, MBSW_STOP_AT_NUL);
    +	  if (display_width < (ssize_t) fs->rmargin)
    +	    {
    +	      /* The buffer contains a full line that fits within the maximum
    +		 line width.  Reset point and scan the next line.  */
    +	      fs->point_col = 0;
    +	      buf = nl + 1;
    +	      continue;
    +	    }
    +	}
     
           /* This line is too long.  */
           r = fs->rmargin - 1;
    @@ -226,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
               char *p, *nextline;
               int i;
     
    -          p = buf + (r + 1 - fs->point_col);
    +	  p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col));
               while (p >= buf && !isblank ((unsigned char) *p))
                 --p;
               nextline = p + 1;     /* This will begin the next line.  */
    @@ -244,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
                 {
                   /* A single word that is greater than the maximum line width.
                      Oh well.  Put it on an overlong line by itself.  */
    -              p = buf + (r + 1 - fs->point_col);
    +              p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col));
                   /* Find the end of the long word.  */
                   if (p < nl)
                     do
    @@ -278,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
                   && fs->p > nextline)
                 {
                   /* The margin needs more blanks than we removed.  */
    -              if (fs->end - fs->p > fs->wmargin + 1)
    +              if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL)
    +		  > fs->wmargin + 1)
                     /* Make some space for them.  */
                     {
                       size_t mv = fs->p - nextline;
    diff --git a/lib/argp-help.c b/lib/argp-help.c
    index 354f1e2..2914f47 100644
    a b  
    5050#include "argp.h"
    5151#include "argp-fmtstream.h"
    5252#include "argp-namefrob.h"
     53#include "mbswidth.h"
    5354
    5455#ifndef SIZE_MAX
    5556# define SIZE_MAX ((size_t) -1)
    argp_args_usage (const struct argp *argp, const struct argp_state *state, 
    14521453
    14531454      /* Manually do line wrapping so that it (probably) won't get wrapped at
    14541455         any embedded spaces.  */
    1455       space (stream, 1 + nl - cp);
     1456      space (stream, 1 + mbsnwidth (cp, nl - cp, MBSW_STOP_AT_NUL));
    14561457
    14571458      __argp_fmtstream_write (stream, cp, nl - cp);
    14581459    }
  • lib/mbswidth.c

    diff --git a/lib/mbswidth.c b/lib/mbswidth.c
    index 7c2dfce..baa4f27 100644
    a b mbsnwidth (const char *string, size_t nbytes, int flags) 
    9090              p++;
    9191              width++;
    9292              break;
     93            case '\0':
     94              if (flags & MBSW_STOP_AT_NUL)
     95                return width;
    9396            default:
    9497              /* If we have a multibyte sequence, scan it up to its end.  */
    9598              {
    mbsnwidth (const char *string, size_t nbytes, int flags) 
    168171    {
    169172      unsigned char c = (unsigned char) *p++;
    170173
     174      if (c == 0 && (flags & MBSW_STOP_AT_NUL))
     175        return width;
     176
    171177      if (isprint (c))
    172178        {
    173179          if (width == INT_MAX)
  • lib/mbswidth.h

    diff --git a/lib/mbswidth.h b/lib/mbswidth.h
    index e9c0b03..d7207c5 100644
    a b extern "C" { 
    4545   control characters and 1 otherwise.  */
    4646#define MBSW_REJECT_UNPRINTABLE 2
    4747
     48/* If this bit is set \0 is treated as the end of string.
     49   Otherwise it's treated as a normal one column width character.  */
     50#define MBSW_STOP_AT_NUL 4
    4851
    4952/* Returns the number of screen columns needed for STRING.  */
    5053#define mbswidth gnu_mbswidth  /* avoid clash with UnixWare 7.1.1 function */
  • modules/argp

    diff --git a/modules/argp b/modules/argp
    index 125046a..6f14d10 100644
    a b stdalign 
    4040strerror
    4141memchr
    4242memmove
     43mbswidth
    4344
    4445configure.ac:
    4546gl_ARGP
  • modules/argp-tests

    diff --git a/modules/argp-tests b/modules/argp-tests
    index 8f92a4d..0463927 100644
    a b  
    11Files:
    22tests/test-argp.c
    33tests/test-argp-2.sh
     4tests/test-argp-2-utf.sh
    45
    56Depends-on:
    67progname
    78
    89Makefile.am:
    910TESTS += test-argp test-argp-2.sh
    10 check_PROGRAMS += test-argp
     11TESTS += test-argp test-argp-2.sh test-argp-2-utf.sh
     12check_PROGRAMS += test-argp test-argp-utf8
    1113test_argp_LDADD = $(LDADD) @LIBINTL@
Note: See TracBrowser for help on using the repository browser.