Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Mar 2001 20:56:28 +0800
From:      Clive Lin <clive@CirX.ORG>
To:        "Andrey A. Chernov" <ache@nagual.pp.ru>
Cc:        "Michael C . Wu" <keichii@peorth.iteration.net>, imp@FreeBSD.ORG, freebsd-i18n@FreeBSD.ORG, thinker@branda.to
Subject:   fix for single char locale (Was: Re: ls(1) mb patch)
Message-ID:  <20010318205628.A10534@cartier.cirx.org>
In-Reply-To: <20010318144136.A40114@nagual.pp.ru>; from ache@nagual.pp.ru on Sun, Mar 18, 2001 at 02:41:36PM %2B0300
References:  <20010318174101.A8012@cartier.cirx.org> <20010318050746.A4964@peorth.iteration.net> <20010318144136.A40114@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Mar 18, 2001 at 02:41:36PM +0300, Andrey A. Chernov wrote:
> Objection. It breaks isprint() for single char locales.

Sorry about that.. originally submitter fixed this.
It should be ok now ,hopefully.

-- 
pub  1024D/F8D2B472 2000-08-05 Clive Lin <clive@CirX.ORG>
     Key fingerprint = 7F9D 57A8 55C7 AA18 49B5  3820 570B 27F6 F8D2 B472

--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ls.diff"

Index: util.c
===================================================================
RCS file: /home/ncvs/src/bin/ls/util.c,v
retrieving revision 1.23
diff -u -r1.23 util.c
--- util.c	2000/07/22 05:28:46	1.23
+++ util.c	2001/03/18 12:51:29
@@ -52,6 +52,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <rune.h>
 
 #include "ls.h"
 #include "extern.h"
@@ -60,15 +61,33 @@
 prn_printable(s)
 	const char *s;
 {
-	unsigned char c;
-	int n;
+	const char *p1, *p2;
+	char *r, *ri;
+	int len, dc;
+	rune_t c;
 
-	for (n = 0; (c = *s) != '\0'; ++s, ++n)
-		if (isprint(c))
-			putchar(c);
-		else
-			putchar('?');
-	return n;
+	p1 = s;
+	dc = len = strlen(s);
+	ri = r = (char *)malloc(len + 1);
+	while(*p1 != 0) {
+		c = sgetrune(p1, dc, &p2);
+		if(c == _INVALID_RUNE) {
+			p1++;
+			dc--;
+			*ri++ = '?';
+		} else {
+			dc -= p2 - p1;
+			if(isprint(c))
+				while(p1 != p2)
+					*ri++ = *p1++;
+			else
+				while(p1 != p2)
+					*ri++ = '?';
+		}
+	}
+	*ri = 0;
+	printf("%s", r);
+	return len;
 }
 
 /*

--RnlQjJ0d97Da+TV1--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-i18n" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010318205628.A10534>