Module Name:    src
Committed By:   christos
Date:           Sat May 23 14:01:08 UTC 2015

Modified Files:
        src/lib/libc/gen: vis.c

Log Message:
Grr need to deal with isgraph(3). Is there a better way?


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/lib/libc/gen/vis.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/gen/vis.c
diff -u src/lib/libc/gen/vis.c:1.67 src/lib/libc/gen/vis.c:1.68
--- src/lib/libc/gen/vis.c:1.67	Sat May 23 07:47:56 2015
+++ src/lib/libc/gen/vis.c	Sat May 23 10:01:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: vis.c,v 1.67 2015/05/23 11:47:56 christos Exp $	*/
+/*	$NetBSD: vis.c,v 1.68 2015/05/23 14:01:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -57,7 +57,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vis.c,v 1.67 2015/05/23 11:47:56 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.68 2015/05/23 14:01:07 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 #ifdef __FBSDID
 __FBSDID("$FreeBSD$");
@@ -97,6 +97,25 @@ static wchar_t *do_svis(wchar_t *, wint_
 
 #undef BELL
 #define BELL L'\a'
+ 
+#if defined(__NetBSD__) && defined(_CTYPE_G)
+#define iscgraph(c)      ((int)((_C_ctype_tab_ + 1)[(c)] & _CTYPE_G)) 
+#else
+static int
+iscgraph(int c) {
+	int rv;
+	char *ol;
+
+	ol = setlocale(LC_CTYPE, "C");
+	rv = isgraph(c);
+	if (ol)
+		setlocale(LC_CTYPE, ol);
+	return rv;
+}
+#endif
+
+#define ISGRAPH(flags, c) \
+    (((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
 
 #define iswoctal(c)	(((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
 #define iswwhite(c)	(c == L' ' || c == L'\t' || c == L'\n')
@@ -232,7 +251,7 @@ do_mbyte(wchar_t *dst, wint_t c, int fla
 		case L'$': /* vis(1) -l */
 			break;
 		default:
-			if (iswgraph(c) && !iswoctal(c)) {
+			if (ISGRAPH(flags, c) && !iswoctal(c)) {
 				*dst++ = L'\\';
 				*dst++ = c;
 				return dst;
@@ -284,7 +303,7 @@ do_svis(wchar_t *dst, wint_t c, int flag
 	uint64_t bmsk, wmsk;
 
 	iswextra = wcschr(extra, c) != NULL;
-	if (!iswextra && (iswgraph(c) || iswwhite(c) ||
+	if (!iswextra && (ISGRAPH(flags, c) || iswwhite(c) ||
 	    ((flags & VIS_SAFE) && iswsafe(c)))) {
 		*dst++ = c;
 		return dst;

Reply via email to