diff options
author | Darren Tucker <dtucker@zip.com.au> | 2005-10-09 11:40:03 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2005-10-09 11:40:03 +1000 |
commit | 9ac1a65acb80ac607eaabcba4c9ea4e0182d8a02 (patch) | |
tree | 3f3945a3d761f002db3b552ca8f2abfe5edc568f /openbsd-compat | |
parent | e04ec6fdfd1d5b71d18e2dd94d5a2aede8c45455 (diff) |
- (dtucker) [configure.ac defines.h openbsd-compat/vis.{c,h}] Sync current
versions from OpenBSD. ok djm@
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/vis.c | 58 | ||||
-rw-r--r-- | openbsd-compat/vis.h | 11 |
2 files changed, 30 insertions, 39 deletions
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c index 1fb7a01e3..52d19ac55 100644 --- a/openbsd-compat/vis.c +++ b/openbsd-compat/vis.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* OPENBSD ORIGINAL: lib/libc/gen/vis.c */ | 1 | /* OPENBSD ORIGINAL: lib/libc/gen/vis.c */ |
2 | 2 | ||
3 | /* $OpenBSD: vis.c,v 1.19 2005/09/01 17:15:49 millert Exp $ */ | ||
3 | /*- | 4 | /*- |
4 | * Copyright (c) 1989, 1993 | 5 | * Copyright (c) 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 6 | * The Regents of the University of California. All rights reserved. |
@@ -28,36 +29,32 @@ | |||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. |
30 | */ | 31 | */ |
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--) { |
diff --git a/openbsd-compat/vis.h b/openbsd-compat/vis.h index 663355a24..0588f68da 100644 --- a/openbsd-compat/vis.h +++ b/openbsd-compat/vis.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* OPENBSD ORIGINAL: include/vis.h */ | 1 | /* OPENBSD ORIGINAL: include/vis.h */ |
2 | 2 | ||
3 | /* $OpenBSD: vis.h,v 1.6 2003/06/02 19:34:12 millert Exp $ */ | 3 | /* $OpenBSD: vis.h,v 1.11 2005/08/09 19:38:31 millert Exp $ */ |
4 | /* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ | 4 | /* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ |
5 | 5 | ||
6 | /*- | 6 | /*- |
@@ -63,6 +63,7 @@ | |||
63 | * other | 63 | * other |
64 | */ | 64 | */ |
65 | #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ | 65 | #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ |
66 | #define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */ | ||
66 | 67 | ||
67 | /* | 68 | /* |
68 | * unvis return codes | 69 | * unvis return codes |
@@ -80,10 +81,14 @@ | |||
80 | 81 | ||
81 | char *vis(char *, int, int, int); | 82 | char *vis(char *, int, int, int); |
82 | int strvis(char *, const char *, int); | 83 | int strvis(char *, const char *, int); |
83 | int strnvis(char *, const char *, size_t, int); | 84 | int strnvis(char *, const char *, size_t, int) |
84 | int strvisx(char *, const char *, size_t, int); | 85 | __attribute__ ((__bounded__(__string__,1,3))); |
86 | int strvisx(char *, const char *, size_t, int) | ||
87 | __attribute__ ((__bounded__(__string__,1,3))); | ||
85 | int strunvis(char *, const char *); | 88 | int strunvis(char *, const char *); |
86 | int unvis(char *, char, int *, int); | 89 | int unvis(char *, char, int *, int); |
90 | ssize_t strnunvis(char *, const char *, size_t) | ||
91 | __attribute__ ((__bounded__(__string__,1,3))); | ||
87 | 92 | ||
88 | #endif /* !_VIS_H_ */ | 93 | #endif /* !_VIS_H_ */ |
89 | 94 | ||