Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen If VIS_CSTYLE is specified, use \ to escape any...



details:   https://anonhg.NetBSD.org/src/rev/92809fc00aef
branches:  trunk
changeset: 549574:92809fc00aef
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Jul 16 22:34:34 2003 +0000

description:
If VIS_CSTYLE is specified, use \ to escape any printable characters
(especially \ itself, and anything else in 'extra').
Fix strvis() and strvisx() to pass 0..255 to isgraph() etc.

diffstat:

 lib/libc/gen/vis.c |  62 +++++++++++++++++++++++++++++------------------------
 1 files changed, 34 insertions(+), 28 deletions(-)

diffs (133 lines):

diff -r 9b0d01895453 -r 92809fc00aef lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c        Wed Jul 16 21:26:33 2003 +0000
+++ b/lib/libc/gen/vis.c        Wed Jul 16 22:34:34 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vis.c,v 1.24 2002/07/03 17:18:09 pooka Exp $   */
+/*     $NetBSD: vis.c,v 1.25 2003/07/16 22:34:34 dsl Exp $     */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vis.c,v 1.24 2002/07/03 17:18:09 pooka Exp $");
+__RCSID("$NetBSD: vis.c,v 1.25 2003/07/16 22:34:34 dsl Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -115,49 +115,53 @@
  */
 #define SVIS(dst, c, flag, nextc, extra)                                     \
 do {                                                                         \
-       int isextra, isc;                                                     \
+       int isextra;                                                          \
        isextra = strchr(extra, c) != NULL;                                   \
        if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) ||            \
            ((flag & VIS_SAFE) && issafe(c)))) {                              \
                *dst++ = c;                                                   \
                break;                                                        \
        }                                                                     \
-       isc = 0;                                                              \
        if (flag & VIS_CSTYLE) {                                              \
                switch (c) {                                                  \
                case '\n':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 'n';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 'n';                          \
+                       continue;                                             \
                case '\r':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 'r';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 'r';                          \
+                       continue;                                             \
                case '\b':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 'b';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 'b';                          \
+                       continue;                                             \
                case BELL:                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 'a';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 'a';                          \
+                       continue;                                             \
                case '\v':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 'v';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 'v';                          \
+                       continue;                                             \
                case '\t':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 't';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 't';                          \
+                       continue;                                             \
                case '\f':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = 'f';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 'f';                          \
+                       continue;                                             \
                case ' ':                                                     \
-                       isc = 1; *dst++ = '\\'; *dst++ = 's';                 \
-                       break;                                                \
+                       *dst++ = '\\'; *dst++ = 's';                          \
+                       continue;                                             \
                case '\0':                                                    \
-                       isc = 1; *dst++ = '\\'; *dst++ = '0';                 \
+                       *dst++ = '\\'; *dst++ = '0';                          \
                        if (isoctal(nextc)) {                                 \
                                *dst++ = '0';                                 \
                                *dst++ = '0';                                 \
                        }                                                     \
+                       continue;                                             \
+               default:                                                      \
+                       if (isgraph(c)) {                                     \
+                               *dst++ = '\\'; *dst++ = c;                    \
+                               continue;                                     \
+                       }                                                     \
                }                                                             \
        }                                                                     \
-       if (isc) break;                                                       \
        if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) {           \
                *dst++ = '\\';                                                \
                *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0';    \
@@ -220,15 +224,16 @@
  *     This is useful for encoding a block of data.
  */
 int
-strsvis(dst, src, flag, extra)
+strsvis(dst, csrc, flag, extra)
        char *dst;
-       const char *src;
+       const char *csrc;
        int flag;
        const char *extra;
 {
-       char c;
+       int c;
        char *start;
        char *nextra;
+       const unsigned char *src = (const unsigned char *)csrc;
 
        _DIAGASSERT(dst != NULL);
        _DIAGASSERT(src != NULL);
@@ -247,16 +252,17 @@
 
 
 int
-strsvisx(dst, src, len, flag, extra)
+strsvisx(dst, csrc, len, flag, extra)
        char *dst;
-       const char *src;
+       const char *csrc;
        size_t len;
        int flag;
        const char *extra;
 {
-       char c;
+       int c;
        char *start;
        char *nextra;
+       const unsigned char *src = (const unsigned char *)csrc;
 
        _DIAGASSERT(dst != NULL);
        _DIAGASSERT(src != NULL);



Home | Main Index | Thread Index | Old Index