diff options
Diffstat (limited to 'openbsd-compat/vis.c')
-rw-r--r-- | openbsd-compat/vis.c | 62 |
1 files changed, 24 insertions, 38 deletions
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c index 1fb7a01e3..3a087b341 100644 --- a/openbsd-compat/vis.c +++ b/openbsd-compat/vis.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* OPENBSD ORIGINAL: lib/libc/gen/vis.c */ | 1 | /* $OpenBSD: vis.c,v 1.19 2005/09/01 17:15:49 millert Exp $ */ |
2 | |||
3 | /*- | 2 | /*- |
4 | * Copyright (c) 1989, 1993 | 3 | * Copyright (c) 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -28,36 +27,34 @@ | |||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
30 | */ | 29 | */ |
30 | |||
31 | /* OPENBSD ORIGINAL: lib/libc/gen/vis.c */ | ||
32 | |||
31 | #include "includes.h" | 33 | #include "includes.h" |
32 | #if !defined(HAVE_STRNVIS) | 34 | #if !defined(HAVE_STRNVIS) |
33 | 35 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | ||
35 | static char rcsid[] = "$OpenBSD: vis.c,v 1.12 2003/06/02 20:18:35 millert Exp $"; | ||
36 | #endif /* LIBC_SCCS and not lint */ | ||
37 | |||
38 | #include <ctype.h> | 36 | #include <ctype.h> |
39 | #include <string.h> | 37 | #include <string.h> |
40 | 38 | ||
41 | #include "vis.h" | 39 | #include "vis.h" |
42 | 40 | ||
43 | #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') | 41 | #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') |
44 | #define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \ | 42 | #define isvisible(c) \ |
45 | isgraph((u_char)(c))) || \ | 43 | (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \ |
46 | ((flag & VIS_SP) == 0 && (c) == ' ') || \ | 44 | (((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \ |
47 | ((flag & VIS_TAB) == 0 && (c) == '\t') || \ | 45 | (flag & VIS_GLOB) == 0) && isgraph((u_char)(c))) || \ |
48 | ((flag & VIS_NL) == 0 && (c) == '\n') || \ | 46 | ((flag & VIS_SP) == 0 && (c) == ' ') || \ |
49 | ((flag & VIS_SAFE) && ((c) == '\b' || \ | 47 | ((flag & VIS_TAB) == 0 && (c) == '\t') || \ |
50 | (c) == '\007' || (c) == '\r' || \ | 48 | ((flag & VIS_NL) == 0 && (c) == '\n') || \ |
51 | isgraph((u_char)(c))))) | 49 | ((flag & VIS_SAFE) && ((c) == '\b' || \ |
50 | (c) == '\007' || (c) == '\r' || \ | ||
51 | isgraph((u_char)(c))))) | ||
52 | 52 | ||
53 | /* | 53 | /* |
54 | * vis - visually encode characters | 54 | * vis - visually encode characters |
55 | */ | 55 | */ |
56 | char * | 56 | char * |
57 | vis(dst, c, flag, nextc) | 57 | vis(char *dst, int c, int flag, int nextc) |
58 | register char *dst; | ||
59 | int c, nextc; | ||
60 | register int flag; | ||
61 | { | 58 | { |
62 | if (isvisible(c)) { | 59 | if (isvisible(c)) { |
63 | *dst++ = c; | 60 | *dst++ = c; |
@@ -111,7 +108,8 @@ vis(dst, c, flag, nextc) | |||
111 | goto done; | 108 | goto done; |
112 | } | 109 | } |
113 | } | 110 | } |
114 | if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) { | 111 | if (((c & 0177) == ' ') || (flag & VIS_OCTAL) || |
112 | ((flag & VIS_GLOB) && (c == '*' || c == '?' || c == '[' || c == '#'))) { | ||
115 | *dst++ = '\\'; | 113 | *dst++ = '\\'; |
116 | *dst++ = ((u_char)c >> 6 & 07) + '0'; | 114 | *dst++ = ((u_char)c >> 6 & 07) + '0'; |
117 | *dst++ = ((u_char)c >> 3 & 07) + '0'; | 115 | *dst++ = ((u_char)c >> 3 & 07) + '0'; |
@@ -124,7 +122,7 @@ vis(dst, c, flag, nextc) | |||
124 | c &= 0177; | 122 | c &= 0177; |
125 | *dst++ = 'M'; | 123 | *dst++ = 'M'; |
126 | } | 124 | } |
127 | if (iscntrl(c)) { | 125 | if (iscntrl((u_char)c)) { |
128 | *dst++ = '^'; | 126 | *dst++ = '^'; |
129 | if (c == 0177) | 127 | if (c == 0177) |
130 | *dst++ = '?'; | 128 | *dst++ = '?'; |
@@ -153,12 +151,9 @@ done: | |||
153 | * This is useful for encoding a block of data. | 151 | * This is useful for encoding a block of data. |
154 | */ | 152 | */ |
155 | int | 153 | int |
156 | strvis(dst, src, flag) | 154 | strvis(char *dst, const char *src, int flag) |
157 | register char *dst; | ||
158 | register const char *src; | ||
159 | int flag; | ||
160 | { | 155 | { |
161 | register char c; | 156 | char c; |
162 | char *start; | 157 | char *start; |
163 | 158 | ||
164 | for (start = dst; (c = *src);) | 159 | for (start = dst; (c = *src);) |
@@ -168,16 +163,11 @@ strvis(dst, src, flag) | |||
168 | } | 163 | } |
169 | 164 | ||
170 | int | 165 | int |
171 | strnvis(dst, src, siz, flag) | 166 | strnvis(char *dst, const char *src, size_t siz, int flag) |
172 | char *dst; | ||
173 | const char *src; | ||
174 | size_t siz; | ||
175 | int flag; | ||
176 | { | 167 | { |
177 | char c; | ||
178 | char *start, *end; | 168 | char *start, *end; |
179 | char tbuf[5]; | 169 | char tbuf[5]; |
180 | int i; | 170 | int c, i; |
181 | 171 | ||
182 | i = 0; | 172 | i = 0; |
183 | for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { | 173 | for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { |
@@ -217,13 +207,9 @@ strnvis(dst, src, siz, flag) | |||
217 | } | 207 | } |
218 | 208 | ||
219 | int | 209 | int |
220 | strvisx(dst, src, len, flag) | 210 | strvisx(char *dst, const char *src, size_t len, int flag) |
221 | register char *dst; | ||
222 | register const char *src; | ||
223 | register size_t len; | ||
224 | int flag; | ||
225 | { | 211 | { |
226 | register char c; | 212 | char c; |
227 | char *start; | 213 | char *start; |
228 | 214 | ||
229 | for (start = dst; len > 1; len--) { | 215 | for (start = dst; len > 1; len--) { |