From 4e1e9d0cf1a4efd6e9dc3be1666202a0481d8319 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 27 Dec 2006 22:50:52 +0100 Subject: [PATCH] The little Christmas candy bar: allow utf-8 chars in Tochars \o/ Signed-off-by: Pierre Habouzit --- Makefile.am | 4 ++-- lib-lib/utf8.c | 6 +++--- lib-lib/utf8.h | 16 ++++++++++++++ lib-ui/hdrline.c | 56 ++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5fc7486..5b068a4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,9 +29,9 @@ madmutt_SOURCES = $(BUILT_SOURCES) \ score.c send.c sendlib.c sort.c state.c thread.c account.c remailer.c madmutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ - -Llib-lib -llib -Llib-mime -lmime -Llib-crypt -lcrypt -Llib-mx -lmx \ + -Llib-mime -lmime -Llib-crypt -lcrypt -Llib-mx -lmx \ -Limap -limap -Lpop -lpop $(LIBNNTP) \ - -Llib-hash -lhash -Llib-sys -lsys -Llib-ui -lui \ + -Llib-hash -lhash -Llib-sys -lsys -Llib-ui -lui -Llib-lib -llib \ $(MUTTLIBS) $(INTLLIBS) $(LIBICONV) madmutt_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ diff --git a/lib-lib/utf8.c b/lib-lib/utf8.c index 7c928a6..7ac3e23 100644 --- a/lib-lib/utf8.c +++ b/lib-lib/utf8.c @@ -42,7 +42,7 @@ static const uint8_t __utf8_mark[7] = { 0x00, 0x00, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc }; -static inline int ustrlen(const char *s) +int m_ustrlen(const char *s) { int len = 0; @@ -53,7 +53,7 @@ static inline int ustrlen(const char *s) return len; } -static inline int ustrgetc(const char *s, const char **outp) +int m_ustrgetc(const char *s, const char **outp) { uint32_t ret = 0; int trail = __utf8_trail[(unsigned char)*s]; @@ -72,7 +72,7 @@ static inline int ustrgetc(const char *s, const char **outp) return ret - __utf8_offs[trail]; } -static inline int ustrputc(char *dst, ssize_t n, int c) +int m_ustrputc(char *dst, ssize_t n, int c) { int bytes = 1 + (c >= 0x80) + (c >= 0x800) + (c >= 0x10000); diff --git a/lib-lib/utf8.h b/lib-lib/utf8.h index 2f1e0da..72bf704 100644 --- a/lib-lib/utf8.h +++ b/lib-lib/utf8.h @@ -23,6 +23,22 @@ /** \addtogroup mutt_strings */ /*@{*/ +int m_ustrlen(const char *s); +int m_ustrgetc(const char *s, const char **outp); +int m_ustrputc(char *dst, ssize_t n, int c); + +static inline char *m_vustrskipc(char *s) { + if (*s++ & 0x80) { + while ((*s & 0xc0) == 0x80) + s++; + } + return s; +} + +static inline const char *m_ustrskipc(const char *s) { + return m_vustrskipc((char *)s); +} + /*@}*/ #endif /* MUTT_LIB_LIB_UTF8_H */ diff --git a/lib-ui/hdrline.c b/lib-ui/hdrline.c index e0047a5..24aa3de 100644 --- a/lib-ui/hdrline.c +++ b/lib-ui/hdrline.c @@ -220,7 +220,7 @@ hdr_format_str(char *dest, ssize_t destlen, HEADER *hdr, *htmp; CONTEXT *ctx; char fmt[STRING], buf2[STRING], ch, *p; - int do_locales, i; + int do_locales, i, c; int optional = (flags & M_FORMAT_OPTIONAL); int threads = ((Sort & SORT_MASK) == SORT_THREADS); int is_index = (flags & M_FORMAT_INDEX); @@ -576,9 +576,26 @@ hdr_format_str(char *dest, ssize_t destlen, break; case 'T': - snprintf (fmt, sizeof (fmt), "%%%sc", prefix); - snprintf (dest, destlen, fmt, - ((i = mutt_user_is_recipient(hdr)) < m_strlen(Tochars)) ? Tochars[i] : ' '); + i = mutt_user_is_recipient(hdr); + assert (i >= 0); /* help compiler to see c is initialized */ + + if (Charset_is_utf8) { + const char *s = Tochars; + + snprintf (fmt, sizeof (fmt), "%%%slc", prefix); + while (i-- >= 0) { + c = m_ustrgetc(s, &s); + if (c <= 0) { + c = ' '; + break; + } + } + + snprintf(dest, destlen, fmt, c); + } else { + snprintf(fmt, sizeof (fmt), "%%%sc", prefix); + snprintf(dest, destlen, fmt, i < m_strlen(Tochars) ? Tochars[i] : ' '); + } break; case 'u': @@ -645,17 +662,38 @@ hdr_format_str(char *dest, ssize_t destlen, else if (hdr->security & PGPKEY) ch = 'K'; - snprintf(buf2, sizeof (buf2), "%c%c%c", + if (hdr->tagged) { + c = '*'; + } else + if (hdr->flagged) { + c = '!'; + } else { + i = mutt_user_is_recipient(hdr); + assert (i >= 0); /* help compiler to see c is initialized */ + + if (Charset_is_utf8) { + const char *s = Tochars; + + snprintf (fmt, sizeof (fmt), "%%%slc", prefix); + while (i-- >= 0) { + c = m_ustrgetc(s, &s); + if (c <= 0) { + c = ' '; + break; + } + } + } else { + c = i < m_strlen(Tochars) ? Tochars[i] : ' '; + } + } + snprintf(buf2, sizeof (buf2), Charset_is_utf8 ? "%c%c%lc" : "%c%c%c", (THREAD_NEW ? 'n' : (THREAD_OLD ? 'o' : ((hdr->read && (ctx && ctx->msgnotreadyet != hdr->msgno)) ? (hdr->replied ? 'r' : ' ') : (hdr->old ? 'O' : 'N')))), - hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch), - hdr->tagged ? '*' - : (hdr->flagged ? '!' - : ((i = mutt_user_is_recipient(hdr)) < m_strlen(Tochars) ? Tochars[i] : ' '))); + hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch), c); mutt_format_s (dest, destlen, prefix, buf2); break; -- 2.20.1