From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29565 invoked from network); 13 Oct 2005 12:58:37 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 13 Oct 2005 12:58:37 -0000 Received: (qmail 80462 invoked from network); 13 Oct 2005 12:58:30 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 13 Oct 2005 12:58:30 -0000 Received: (qmail 11078 invoked by alias); 13 Oct 2005 12:58:27 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21869 Received: (qmail 11069 invoked from network); 13 Oct 2005 12:58:27 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 13 Oct 2005 12:58:27 -0000 Received: (qmail 80141 invoked from network); 13 Oct 2005 12:58:27 -0000 Received: from cluster-d.mailcontrol.com (HELO rly13d.srv.mailcontrol.com) (217.69.20.190) by a.mx.sunsite.dk with SMTP; 13 Oct 2005 12:58:25 -0000 Received: from exchange03.csr.com (mailhost1.csr.com [81.105.217.43]) by rly13d.srv.mailcontrol.com (MailControl) with ESMTP id j9DCwNOa009737 for ; Thu, 13 Oct 2005 13:58:23 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 13 Oct 2005 14:00:28 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j9DCwLg0021187 for ; Thu, 13 Oct 2005 13:58:22 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j9DCwKv9021184 for ; Thu, 13 Oct 2005 13:58:20 +0100 Message-Id: <200510131258.j9DCwKv9021184@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: multibyte characters in prompt substitution Date: Thu, 13 Oct 2005 13:58:20 +0100 From: Peter Stephenson X-OriginalArrivalTime: 13 Oct 2005 13:00:28.0854 (UTC) FILETIME=[16094D60:01C5CFF6] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-05-40-01 (www.mailcontrol.com) on 10.68.0.123 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 This should fix the output of mulibyte characters in text resulting from % substitutions in prompts. The other bit is a mistake in the code I was copying from. Index: Src/prompt.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v retrieving revision 1.25 diff -u -r1.25 prompt.c --- Src/prompt.c 22 Sep 2005 01:36:35 -0000 1.25 +++ Src/prompt.c 13 Oct 2005 12:55:40 -0000 @@ -736,6 +736,46 @@ void stradd(char *d) { +#ifdef ZLE_UNICODE_SUPPORT + char *ums, *ups; + int upslen; + mbstate_t ps; + + memset(&ps, 0, sizeof(ps)); + ums = ztrdup(d); + ups = unmetafy(ums, &upslen); + + /* + * We now have a raw string of possibly multibyte characters. + * Read each character one by one. + */ + while (upslen > 0) { + wchar_t cc; + char *pc; + int ret = mbrtowc(&cc, ups, upslen, &ps); + + if (ret <= 0) + { + /* Bad character. Take the next byte on its own. */ + pc = nicechar(*ups); + ret = 1; + } else { + /* Take full wide character in one go */ + pc = wcs_nicechar(cc, NULL, NULL); + } + /* Keep output as metafied string. */ + addbufspc(strlen(pc)); + + upslen -= ret; + ups += ret; + + /* Put printed representation into the buffer */ + while (*pc) + *bp++ = *pc++; + } + + free(ums); +#else char *ps, *pc; addbufspc(niceztrlen(d)); /* This loop puts the nice representation of the string into the prompt * @@ -743,6 +783,7 @@ for(ps=d; *ps; ps++) for(pc=nicechar(*ps == Meta ? STOUC(*++ps)^32 : STOUC(*ps)); *pc; pc++) *bp++ = *pc; +#endif } /* tsetcap(), among other things, can write a termcap string into the buffer. */ Index: Src/Zle/complist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v retrieving revision 1.75 diff -u -r1.75 complist.c --- Src/Zle/complist.c 4 Oct 2005 14:27:13 -0000 1.75 +++ Src/Zle/complist.c 13 Oct 2005 12:55:41 -0000 @@ -599,7 +599,7 @@ * an input NULL, which we want to be a real character * rather than terminator. */ - sptr = nicechar(*s); + sptr = nicechar(*uptr); /* everything here is ASCII... */ width = strlen(sptr); wptr = sptr + width; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com