1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
3 // UNSUPPORTED: target={{.*(linux|solaris).*}}, darwin
15 int ch
= toascii(0x1);
16 vis(visout
, ch
, VIS_SAFE
| VIS_NOSLASH
, 0);
17 printf("vis: %s\n", visout
);
22 int ch
= toascii(0x2);
23 nvis(visout
, sizeof visout
, ch
, VIS_SAFE
| VIS_NOSLASH
, 0);
24 printf("nvis: %s\n", visout
);
29 strvis(visout
, "\3", VIS_SAFE
| VIS_NOSLASH
);
30 printf("strvis: %s\n", visout
);
35 stravis(&visout
, "\4", VIS_SAFE
| VIS_NOSLASH
);
36 printf("stravis: %s\n", visout
);
42 strnvis(visout
, sizeof visout
, "\5", VIS_SAFE
| VIS_NOSLASH
);
43 printf("strnvis: %s\n", visout
);
49 strvisx(visout
, src
, sizeof src
- 1 /* skip final \0 */,
50 VIS_SAFE
| VIS_NOSLASH
);
51 printf("strvisx: %s\n", visout
);
54 void test_strnvisx() {
57 strnvisx(visout
, sizeof visout
, src
, sizeof src
- 1 /* skip final \0 */,
58 VIS_SAFE
| VIS_NOSLASH
);
59 printf("strnvisx: %s\n", visout
);
62 void test_strenvisx() {
65 strenvisx(visout
, sizeof visout
, src
, sizeof src
- 1 /* skip final \0 */,
66 VIS_SAFE
| VIS_NOSLASH
, NULL
);
67 printf("strenvisx: %s\n", visout
);
72 int ch
= toascii(0x3);
73 svis(visout
, ch
, VIS_SAFE
| VIS_NOSLASH
, 0, "x");
74 printf("svis: %s\n", visout
);
79 int ch
= toascii(0x2);
80 snvis(visout
, sizeof visout
, ch
, VIS_SAFE
| VIS_NOSLASH
, 0, "x");
81 printf("snvis: %s\n", visout
);
86 strsvis(visout
, "\4", VIS_SAFE
| VIS_NOSLASH
, "x");
87 printf("strsvis: %s\n", visout
);
90 void test_strsnvis() {
92 strsnvis(visout
, sizeof visout
, "\5", VIS_SAFE
| VIS_NOSLASH
, "x");
93 printf("strsnvis: %s\n", visout
);
96 void test_strsvisx() {
99 strsvisx(visout
, src
, sizeof src
- 1 /* skip final \0 */,
100 VIS_SAFE
| VIS_NOSLASH
, "x");
101 printf("strsvisx: %s\n", visout
);
104 void test_strsnvisx() {
107 strsnvisx(visout
, sizeof visout
, src
, sizeof src
- 1 /* skip final \0 */,
108 VIS_SAFE
| VIS_NOSLASH
, "x");
109 printf("strsnvisx: %s\n", visout
);
112 void test_strsenvisx() {
115 strsenvisx(visout
, sizeof visout
, src
, sizeof src
- 1 /* skip final \0 */,
116 VIS_SAFE
| VIS_NOSLASH
, "x", NULL
);
117 printf("strsenvisx: %s\n", visout
);
122 int ch
= toascii(0x1);
123 vis(visout
, ch
, VIS_SAFE
, 0);
128 while ((ch
= *(p
++)) != '\0') {
130 switch (unvis(&out
, ch
, &state
, 0)) {
135 printf("unvis: %" PRIx8
"\n", (unsigned char)out
);
137 case UNVIS_VALIDPUSH
:
138 printf("unvis: %" PRIx8
"\n", (unsigned char)out
);
141 errx(1, "Bad character sequence!");
144 if (unvis(&out
, '\0', &state
, UNVIS_END
) == UNVIS_VALID
)
145 printf("unvis: %" PRIx8
"\n", (unsigned char)out
);
148 void test_strunvis() {
150 int ch
= toascii(0x2);
151 vis(visout
, ch
, VIS_SAFE
, 0);
157 while ((ch
= *(pp
++)) != '\0')
158 printf("strunvis: %" PRIx8
"\n", (unsigned char)ch
);
161 void test_strnunvis() {
163 int ch
= toascii(0x3);
164 vis(visout
, ch
, VIS_SAFE
, 0);
167 strnunvis(p
, sizeof p
, visout
);
170 while ((ch
= *(pp
++)) != '\0')
171 printf("strnunvis: %" PRIx8
"\n", (unsigned char)ch
);
174 void test_strunvisx() {
176 int ch
= toascii(0x4);
177 vis(visout
, ch
, VIS_SAFE
, 0);
180 strunvisx(p
, visout
, VIS_SAFE
);
183 while ((ch
= *(pp
++)) != '\0')
184 printf("strunvisx: %" PRIx8
"\n", (unsigned char)ch
);
187 void test_strnunvisx() {
189 int ch
= toascii(0x5);
190 vis(visout
, ch
, VIS_SAFE
, 0);
193 strnunvisx(p
, sizeof p
, visout
, VIS_SAFE
);
196 while ((ch
= *(pp
++)) != '\0')
197 printf("strnunvisx: %" PRIx8
"\n", (unsigned char)ch
);
228 // CHECK: stravis: ^D
229 // CHECK: strnvis: ^E
230 // CHECK: strvisx: ^F
231 // CHECK: strnvisx: ^A
232 // CHECK: strenvisx: ^B
235 // CHECK: strsvis: ^D
236 // CHECK: strsnvis: ^E
237 // CHECK: strsvisx: ^E
238 // CHECK: strsnvisx: ^F
239 // CHECK: strsenvisx: ^A
241 // CHECK: strunvis: 2
242 // CHECK: strnunvis: 3
243 // CHECK: strunvisx: 4
244 // CHECK: strnunvisx: 5