This source file includes following definitions.
- compare
- compare_strings
- use_quotearg_buffer
- use_quotearg
- use_quotearg_colon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 struct result_strings {
20 char const *str1;
21 char const *str2;
22 size_t len2;
23 char const *str3;
24 char const *str4;
25 char const *str5;
26 char const *str6;
27 char const *str7;
28 char const *str8a;
29 char const *str8b;
30 };
31
32 struct result_groups {
33 struct result_strings group1;
34 struct result_strings group2;
35 struct result_strings group3;
36 };
37
38
39 # define LQ "\302\253"
40 # define RQ "\302\273"
41 # define LQ_ENC "\\302\\253"
42 # define RQ_ENC "\\302\\273"
43 # define RQ_ESC "\\\302\273"
44
45 static struct result_strings inputs = {
46 "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
47 "a' b", LQ RQ, NULL
48 };
49
50 static void
51 compare (char const *a, size_t la, char const *b, size_t lb)
52 {
53 ASSERT (la == lb);
54 ASSERT (memcmp (a, b, la) == 0);
55 ASSERT (b[lb] == '\0');
56 }
57
58 static void
59 compare_strings (char *(func) (char const *, size_t *),
60 struct result_strings *results, bool ascii_only)
61 {
62 size_t len;
63 char *p;
64
65 len = 0;
66 p = func (inputs.str1, &len);
67 compare (results->str1, strlen (results->str1), p, len);
68
69 len = inputs.len2;
70 p = func (inputs.str2, &len);
71 compare (results->str2, results->len2, p, len);
72
73 len = SIZE_MAX;
74 p = func (inputs.str3, &len);
75 compare (results->str3, strlen (results->str3), p, len);
76
77 len = strlen (inputs.str4);
78 p = func (inputs.str4, &len);
79 compare (results->str4, strlen (results->str4), p, len);
80
81 len = SIZE_MAX;
82 p = func (inputs.str5, &len);
83 compare (results->str5, strlen (results->str5), p, len);
84
85 len = strlen (inputs.str6);
86 p = func (inputs.str6, &len);
87 compare (results->str6, strlen (results->str6), p, len);
88
89 len = strlen (inputs.str7);
90 p = func (inputs.str7, &len);
91 compare (results->str7, strlen (results->str7), p, len);
92
93 len = strlen (inputs.str8a);
94 p = func (inputs.str8a, &len);
95 if (ascii_only)
96 compare (results->str8a, strlen (results->str8a), p, len);
97 else
98 compare (results->str8b, strlen (results->str8b), p, len);
99 }
100
101 static char *
102 use_quotearg_buffer (const char *str, size_t *len)
103 {
104 static char buf[100];
105 size_t size;
106 memset (buf, 0xa5, 100);
107 size = quotearg_buffer (buf, 100, str, *len, NULL);
108 *len = size;
109 ASSERT ((unsigned char) buf[size + 1] == 0xa5);
110 return buf;
111 }
112
113 static char *
114 use_quotearg (const char *str, size_t *len)
115 {
116 char *p = *len == SIZE_MAX ? quotearg (str) : quotearg_mem (str, *len);
117 *len = strlen (p);
118 return p;
119 }
120
121 static char *
122 use_quotearg_colon (const char *str, size_t *len)
123 {
124 char *p = (*len == SIZE_MAX ? quotearg_colon (str)
125 : quotearg_colon_mem (str, *len));
126 *len = strlen (p);
127 return p;
128 }