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



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?= yes  # data-driven bugs?
 USE_EDITLINE?=yes
 MIME_SUPPORT?=yes      # currently requires USE_EDITLINE
 CHARSET_SUPPORT?=yes   # requires MIME_SUPPORT
+WIDECHAR?=yes          # avoid multibyte sequence -hickups- disruptions
 THREAD_SUPPORT?=yes    # EXPERIMENTAL
 
 # Work around some problems in -current.
@@ -52,6 +53,10 @@ CPPFLAGS+=   -DMIME_SUPPORT
 CPPFLAGS+=     -DCHARSET_SUPPORT
 .endif
 
+.if ${WIDECHAR:Uno} == "yes"
+CPPFLAGS+=     -DWIDECHAR
+.endif
+
 LDADD+=                -lmagic -lz
 DPADD+=                ${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
 
 #include <assert.h>
 #include <util.h>
+#ifdef WIDECHAR
+# include <wchar.h>
+#endif
 
 #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;
 
        /* Don't realpath(3) if it's only an update request */
        if (name != NULL && realpath(name, mailname) == NULL) {
@@ -153,32 +156,41 @@ update_mailname(const char *name)
                return;
        }
 
+       mailp = mailname;
+       dispp = displayname;
+
+       /* Don't display an absolute path but "+FOLDER" if under *folder* */
        if (getfold(tbuf, sizeof(tbuf)) >= 0) {
-               l = strlen(tbuf);
-               if (l < sizeof(tbuf) - 1)
-                       tbuf[l++] = '/';
-               if (strncmp(tbuf, mailname, l) == 0) {
-                       char const *sep = "", *cp = mailname + l;
-
-                       l = strlen(cp);
-                       if (l >= sizeof(displayname)) {
-                               cp += l;
-                               cp -= sizeof(displayname) - 5;
-                               sep = "...";
-                       }
-                       (void)snprintf(displayname, sizeof(displayname),
-                           "+%s%s", sep, cp);
-                       return;
+               i = strlen(tbuf);
+               if (i < sizeof(tbuf) - 1)
+                       tbuf[i++] = '/';
+               if (strncmp(tbuf, mailp, i) == 0) {
+                       mailp += i;
+                       *dispp++ = '+';
                }
        }
 
-       l = strlen(mailname);
-       if (l < sizeof(displayname))
-               strcpy(displayname, mailname);
+       /* We want to see the name of the folder .. on the screen */
+       i = strlen(mailp);
+       if (i < sizeof(displayname) - 1)
+               memcpy(dispp, mailp, i + 1);
        else {
-               l -= 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 = i;
+#endif
+               j = sizeof(displayname) / 3;
+               i -= 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);
        }
 }
 


Home | Main Index | Thread Index | Old Index