From owner-freebsd-current Tue Mar 20 2:11: 9 2001 Delivered-To: freebsd-current@freebsd.org Received: from hell.branda.to (61-216-80-81.HINET-IP.hinet.net [61.216.80.81]) by hub.freebsd.org (Postfix) with ESMTP id 2101637B73F for ; Tue, 20 Mar 2001 02:11:03 -0800 (PST) (envelope-from thinker@branda.to) Received: from localhost (localhost [127.0.0.1]) (uid 1000) by hell.branda.to with local; Tue, 20 Mar 2001 18:13:20 +0000 Date: Tue, 20 Mar 2001 18:13:20 +0000 From: thinker To: freebsd-current@freebsd.org Subject: Re: patch /bin/ls again, for mb supporting. Message-ID: <20010320181320.A15057@hell.branda.to> References: <20010320164901.A14424@hell.branda.to> <20010320011246.O29888@fw.wintelcom.net> <20010320173710.A14702@hell.branda.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010320173710.A14702@hell.branda.to>; from thinker@branda.to on Tue, Mar 20, 2001 at 05:37:10PM +0000 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG For style reason, I make another patch file. ------------- begin --------------- --- util.c.orig Sun Mar 18 16:35:12 2001 +++ util.c Tue Mar 20 18:12:23 2001 @@ -60,15 +60,43 @@ prn_printable(s) const char *s; { - unsigned char c; - int n; + const char *p; /* String walker. */ + char *r, *ri; /* Ptr for result string & walker of it. */ + int len; + int dc; /* Count down of length after 'p' . */ + size_t sz; /* Number of bytes been processed. */ + wchar_t c; - for (n = 0; (c = *s) != '\0'; ++s, ++n) - if (isprint(c)) - putchar(c); - else - putchar('?'); - return n; + if (s == NULL) + return (0); + p = s; + dc = len = strlen(s); + ri = r = (char *)malloc(len + 1); + if (r == NULL) + return (0); + + while (dc > 0) { + sz = mbtowc(&c, p, dc); + if (sz < 0) { /* Not be recognized. */ + p++; + dc--; + *ri++ = '?'; + } else { + dc -= sz; + if (isprint(c)) { + while(sz--) + *ri++ = *p++; + } else { /* Non-printable char. */ + p += sz; + while(sz--) + *ri++ = '?'; + } + } + } + *ri = '\0'; + printf("%s", r); + free(r); + return (len); } /* ------------- end ----------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message