NetBSD-Bugs archive

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

Re: PR/47577 CVS commit: src/usr.bin/mail



The following reply was made to PR bin/47577; it has been noted by GNATS.

From: Steffen "Daode" Nurpmeso <sdaoden%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: PR/47577 CVS commit: src/usr.bin/mail
Date: Mon, 25 Feb 2013 19:58:24 +0100

 ach, it's a mess!
 No thought of multibyte awareness until saturday, when doing
 something completely different..
 So this should make it multibyte aware (i hope).
 
 --steffen
 
 diff -Napru mail.orig/Makefile mail/Makefile
 --- mail.orig/Makefile 2013-02-25 14:58:37.000000000 +0100
 +++ mail/Makefile      2013-02-25 16:02:01.000000000 +0100
 @@ -8,6 +8,7 @@ USE_FORT?=3D yes       # data-driven bugs?
  USE_EDITLINE?=3Dyes
  MIME_SUPPORT?=3Dyes   # currently requires USE_EDITLINE
  CHARSET_SUPPORT?=3Dyes        # requires MIME_SUPPORT
 +WIDECHAR?=3Dyes               # avoid multibyte sequence -hickups- disruptions
  THREAD_SUPPORT?=3Dyes # EXPERIMENTAL
 =20
  # Work around some problems in -current.
 @@ -52,6 +53,10 @@ CPPFLAGS+=3D        -DMIME_SUPPORT
  CPPFLAGS+=3D  -DCHARSET_SUPPORT
  .endif
 =20
 +.if ${WIDECHAR:Uno} =3D=3D "yes"
 +CPPFLAGS+=3D  -DWIDECHAR
 +.endif
 +
  LDADD+=3D             -lmagic -lz
  DPADD+=3D             ${LIBMAGIC} ${LIBZ}
  .endif
 diff -Napru mail.orig/lex.c mail/lex.c
 --- mail.orig/lex.c    2013-02-25 14:58:37.000000000 +0100
 +++ mail/lex.c 2013-02-25 18:47:19.000000000 +0100
 @@ -40,6 +40,9 @@ __RCSID("$NetBSD: lex.c,v 1.43 2013/02/2
 =20
  #include <assert.h>
  #include <util.h>
 +#ifdef WIDECHAR
 +# include <wchar.h>
 +#endif
 =20
  #include "rcv.h"
  #include "extern.h"
 @@ -144,8 +147,8 @@ file_leak_check(void)
  static void
  update_mailname(const char *name)
  {
 -      char tbuf[PATHSIZE];
 -      size_t l;
 +      char tbuf[PATHSIZE], *mailp, *dispp;
 +      size_t i, j;
 =20
        /* Don't realpath(3) if it's only an update request */
        if (name !=3D NULL && realpath(name, mailname) =3D=3D NULL) {
 @@ -153,32 +156,41 @@ update_mailname(const char *name)
                return;
        }
 =20
 +      mailp =3D mailname;
 +      dispp =3D displayname;
 +
 +      /* Don't display an absolute path but "+FOLDER" if under *folder* */
        if (getfold(tbuf, sizeof(tbuf)) >=3D 0) {
 -              l =3D strlen(tbuf);
 -              if (l < sizeof(tbuf) - 1)
 -                      tbuf[l++] =3D '/';
 -              if (strncmp(tbuf, mailname, l) =3D=3D 0) {
 -                      char const *sep =3D "", *cp =3D mailname + l;
 -
 -                      l =3D strlen(cp);
 -                      if (l >=3D sizeof(displayname)) {
 -                              cp +=3D l;
 -                              cp -=3D sizeof(displayname) - 5;
 -                              sep =3D "...";
 -                      }
 -                      (void)snprintf(displayname, sizeof(displayname),
 -                          "+%s%s", sep, cp);
 -                      return;
 +              i =3D strlen(tbuf);
 +              if (i < sizeof(tbuf) - 1)
 +                      tbuf[i++] =3D '/';
 +              if (strncmp(tbuf, mailp, i) =3D=3D 0) {
 +                      mailp +=3D i;
 +                      *dispp++ =3D '+';
                }
        }
 =20
 -      l =3D strlen(mailname);
 -      if (l < sizeof(displayname))
 -              strcpy(displayname, mailname);
 +      /* We want to see the name of the folder .. on the screen */
 +      i =3D strlen(mailp);
 +      if (i < sizeof(displayname) - 1)
 +              memcpy(dispp, mailp, i + 1);
        else {
 -              l -=3D sizeof(displayname) - 4 - sizeof(displayname) / 3;
 -              (void)snprintf(displayname, sizeof(displayname), "%.*s...%s",
 -                      (int)sizeof(displayname) / 3, mailname, mailname + l);
 +#ifdef WIDECHAR
 +              size_t si =3D i;
 +#endif
 +              j =3D sizeof(displayname) / 3;
 +              i -=3D sizeof(displayname) - (1 /* "+" */ + 4) - j;
 +              /* Avoid disrupting multibyte sequences */
 +#ifdef WIDECHAR
 +              goto jmblen;
 +              while (i < si && mblen(mailp + i, si - i) < 0) {
 +                      ++i;
 +jmblen:
 +                      mblen(NULL, 0);
 +              }
 +#endif
 +              (void)snprintf(dispp, sizeof(displayname) - 1, "%.*s...%s",
 +                      (int)j, mailp, mailp + i);
        }
  }
 =20
 


Home | Main Index | Thread Index | Old Index