Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Grr need to deal with isgraph(3). Is there a be...



details:   https://anonhg.NetBSD.org/src/rev/296079c39865
branches:  trunk
changeset: 808563:296079c39865
user:      christos <christos%NetBSD.org@localhost>
date:      Sat May 23 14:01:07 2015 +0000

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

diffstat:

 lib/libc/gen/vis.c |  27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diffs (62 lines):

diff -r c315611f0c45 -r 296079c39865 lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c        Sat May 23 13:44:40 2015 +0000
+++ b/lib/libc/gen/vis.c        Sat May 23 14:01:07 2015 +0000
@@ -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 @@
 
 #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 @@
                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 @@
        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;



Home | Main Index | Thread Index | Old Index