Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/quotearg.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* quotearg.c - quote arguments for output | - | ||||||||||||||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||||||||||||||
3 | Copyright (C) 1998-2002, 2004-2018 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||||||||||||||||||||
5 | This program is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||||||||
6 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||||||||
7 | the Free Software Foundation; either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||||||||
8 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||||||||||||||||||||
10 | This program is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||||||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||||||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||||||||
13 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||||||||
14 | - | |||||||||||||||||||||||||||||||||||||||||||
15 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||||||||
16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | - | ||||||||||||||||||||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||||||||||||||||||||
18 | /* Written by Paul Eggert <eggert@twinsun.com> */ | - | ||||||||||||||||||||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||||||||||||||||||||
20 | /* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that | - | ||||||||||||||||||||||||||||||||||||||||||
21 | the quoting_options_from_style function might be candidate for | - | ||||||||||||||||||||||||||||||||||||||||||
22 | attribute 'pure' */ | - | ||||||||||||||||||||||||||||||||||||||||||
23 | #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ | - | ||||||||||||||||||||||||||||||||||||||||||
24 | # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" | - | ||||||||||||||||||||||||||||||||||||||||||
25 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||||||||||||||||||||
27 | #include <config.h> | - | ||||||||||||||||||||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||||||||||||||||||||
29 | #include "quotearg.h" | - | ||||||||||||||||||||||||||||||||||||||||||
30 | #include "quote.h" | - | ||||||||||||||||||||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||||||||||||||||||||
32 | #include "minmax.h" | - | ||||||||||||||||||||||||||||||||||||||||||
33 | #include "xalloc.h" | - | ||||||||||||||||||||||||||||||||||||||||||
34 | #include "c-strcaseeq.h" | - | ||||||||||||||||||||||||||||||||||||||||||
35 | #include "localcharset.h" | - | ||||||||||||||||||||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||||||||||||||||||||
37 | #include <ctype.h> | - | ||||||||||||||||||||||||||||||||||||||||||
38 | #include <errno.h> | - | ||||||||||||||||||||||||||||||||||||||||||
39 | #include <limits.h> | - | ||||||||||||||||||||||||||||||||||||||||||
40 | #include <stdbool.h> | - | ||||||||||||||||||||||||||||||||||||||||||
41 | #include <stdint.h> | - | ||||||||||||||||||||||||||||||||||||||||||
42 | #include <stdlib.h> | - | ||||||||||||||||||||||||||||||||||||||||||
43 | #include <string.h> | - | ||||||||||||||||||||||||||||||||||||||||||
44 | #include <wchar.h> | - | ||||||||||||||||||||||||||||||||||||||||||
45 | #include <wctype.h> | - | ||||||||||||||||||||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||||||||||||||||||||
47 | #include "gettext.h" | - | ||||||||||||||||||||||||||||||||||||||||||
48 | #define _(msgid) gettext (msgid) | - | ||||||||||||||||||||||||||||||||||||||||||
49 | #define N_(msgid) msgid | - | ||||||||||||||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||||||||||||||
51 | #ifndef SIZE_MAX | - | ||||||||||||||||||||||||||||||||||||||||||
52 | # define SIZE_MAX ((size_t) -1) | - | ||||||||||||||||||||||||||||||||||||||||||
53 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||||||||||||||||||||
55 | #define INT_BITS (sizeof (int) * CHAR_BIT) | - | ||||||||||||||||||||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||||||||||||||||||||
57 | #ifndef FALLTHROUGH | - | ||||||||||||||||||||||||||||||||||||||||||
58 | # if __GNUC__ < 7 | - | ||||||||||||||||||||||||||||||||||||||||||
59 | # define FALLTHROUGH ((void) 0) | - | ||||||||||||||||||||||||||||||||||||||||||
60 | # else | - | ||||||||||||||||||||||||||||||||||||||||||
61 | # define FALLTHROUGH __attribute__ ((__fallthrough__)) | - | ||||||||||||||||||||||||||||||||||||||||||
62 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||
63 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||||||||||||||||||||
65 | struct quoting_options | - | ||||||||||||||||||||||||||||||||||||||||||
66 | { | - | ||||||||||||||||||||||||||||||||||||||||||
67 | /* Basic quoting style. */ | - | ||||||||||||||||||||||||||||||||||||||||||
68 | enum quoting_style style; | - | ||||||||||||||||||||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||||||||||||||||||||
70 | /* Additional flags. Bitwise combination of enum quoting_flags. */ | - | ||||||||||||||||||||||||||||||||||||||||||
71 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||||||||||||||||||||
73 | /* Quote the characters indicated by this bit vector even if the | - | ||||||||||||||||||||||||||||||||||||||||||
74 | quoting style would not normally require them to be quoted. */ | - | ||||||||||||||||||||||||||||||||||||||||||
75 | unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1]; | - | ||||||||||||||||||||||||||||||||||||||||||
76 | - | |||||||||||||||||||||||||||||||||||||||||||
77 | /* The left quote for custom_quoting_style. */ | - | ||||||||||||||||||||||||||||||||||||||||||
78 | char const *left_quote; | - | ||||||||||||||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||||||||||||||
80 | /* The right quote for custom_quoting_style. */ | - | ||||||||||||||||||||||||||||||||||||||||||
81 | char const *right_quote; | - | ||||||||||||||||||||||||||||||||||||||||||
82 | }; | - | ||||||||||||||||||||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||||||||||||||||||||
84 | /* Names of quoting styles. */ | - | ||||||||||||||||||||||||||||||||||||||||||
85 | char const *const quoting_style_args[] = | - | ||||||||||||||||||||||||||||||||||||||||||
86 | { | - | ||||||||||||||||||||||||||||||||||||||||||
87 | "literal", | - | ||||||||||||||||||||||||||||||||||||||||||
88 | "shell", | - | ||||||||||||||||||||||||||||||||||||||||||
89 | "shell-always", | - | ||||||||||||||||||||||||||||||||||||||||||
90 | "shell-escape", | - | ||||||||||||||||||||||||||||||||||||||||||
91 | "shell-escape-always", | - | ||||||||||||||||||||||||||||||||||||||||||
92 | "c", | - | ||||||||||||||||||||||||||||||||||||||||||
93 | "c-maybe", | - | ||||||||||||||||||||||||||||||||||||||||||
94 | "escape", | - | ||||||||||||||||||||||||||||||||||||||||||
95 | "locale", | - | ||||||||||||||||||||||||||||||||||||||||||
96 | "clocale", | - | ||||||||||||||||||||||||||||||||||||||||||
97 | 0 | - | ||||||||||||||||||||||||||||||||||||||||||
98 | }; | - | ||||||||||||||||||||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||||||||||||||||||||
100 | /* Correspondences to quoting style names. */ | - | ||||||||||||||||||||||||||||||||||||||||||
101 | enum quoting_style const quoting_style_vals[] = | - | ||||||||||||||||||||||||||||||||||||||||||
102 | { | - | ||||||||||||||||||||||||||||||||||||||||||
103 | literal_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
104 | shell_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
105 | shell_always_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
106 | shell_escape_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
107 | shell_escape_always_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
108 | c_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
109 | c_maybe_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
110 | escape_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
111 | locale_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
112 | clocale_quoting_style | - | ||||||||||||||||||||||||||||||||||||||||||
113 | }; | - | ||||||||||||||||||||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||||||||||||||||||||
115 | /* The default quoting options. */ | - | ||||||||||||||||||||||||||||||||||||||||||
116 | static struct quoting_options default_quoting_options; | - | ||||||||||||||||||||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||||||||||||||||||||
118 | /* Allocate a new set of quoting options, with contents initially identical | - | ||||||||||||||||||||||||||||||||||||||||||
119 | to O if O is not null, or to the default if O is null. | - | ||||||||||||||||||||||||||||||||||||||||||
120 | It is the caller's responsibility to free the result. */ | - | ||||||||||||||||||||||||||||||||||||||||||
121 | struct quoting_options * | - | ||||||||||||||||||||||||||||||||||||||||||
122 | clone_quoting_options (struct quoting_options *o) | - | ||||||||||||||||||||||||||||||||||||||||||
123 | { | - | ||||||||||||||||||||||||||||||||||||||||||
124 | int e = errno; | - | ||||||||||||||||||||||||||||||||||||||||||
125 | struct quoting_options *p = xmemdup (o ? o : &default_quoting_options, | - | ||||||||||||||||||||||||||||||||||||||||||
126 | sizeof *o); | - | ||||||||||||||||||||||||||||||||||||||||||
127 | errno = e; | - | ||||||||||||||||||||||||||||||||||||||||||
128 | return p; executed 2332 times by 3 tests Executed by:
| 2332 | ||||||||||||||||||||||||||||||||||||||||||
129 | } | - | ||||||||||||||||||||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||||||||||||||||||||
131 | /* Get the value of O's quoting style. If O is null, use the default. */ | - | ||||||||||||||||||||||||||||||||||||||||||
132 | enum quoting_style | - | ||||||||||||||||||||||||||||||||||||||||||
133 | get_quoting_style (struct quoting_options const *o) | - | ||||||||||||||||||||||||||||||||||||||||||
134 | { | - | ||||||||||||||||||||||||||||||||||||||||||
135 | return (o ? o : &default_quoting_options)->style; executed 2349 times by 4 tests Executed by:
| 2349 | ||||||||||||||||||||||||||||||||||||||||||
136 | } | - | ||||||||||||||||||||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||||||||||||||||||||
138 | /* In O (or in the default if O is null), | - | ||||||||||||||||||||||||||||||||||||||||||
139 | set the value of the quoting style to S. */ | - | ||||||||||||||||||||||||||||||||||||||||||
140 | void | - | ||||||||||||||||||||||||||||||||||||||||||
141 | set_quoting_style (struct quoting_options *o, enum quoting_style s) | - | ||||||||||||||||||||||||||||||||||||||||||
142 | { | - | ||||||||||||||||||||||||||||||||||||||||||
143 | (o ? o : &default_quoting_options)->style = s; | - | ||||||||||||||||||||||||||||||||||||||||||
144 | } executed 236 times by 4 tests Executed by:
| 236 | ||||||||||||||||||||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||||||||||||||||||||
146 | /* In O (or in the default if O is null), | - | ||||||||||||||||||||||||||||||||||||||||||
147 | set the value of the quoting options for character C to I. | - | ||||||||||||||||||||||||||||||||||||||||||
148 | Return the old value. Currently, the only values defined for I are | - | ||||||||||||||||||||||||||||||||||||||||||
149 | 0 (the default) and 1 (which means to quote the character even if | - | ||||||||||||||||||||||||||||||||||||||||||
150 | it would not otherwise be quoted). */ | - | ||||||||||||||||||||||||||||||||||||||||||
151 | int | - | ||||||||||||||||||||||||||||||||||||||||||
152 | set_char_quoting (struct quoting_options *o, char c, int i) | - | ||||||||||||||||||||||||||||||||||||||||||
153 | { | - | ||||||||||||||||||||||||||||||||||||||||||
154 | unsigned char uc = c; | - | ||||||||||||||||||||||||||||||||||||||||||
155 | unsigned int *p = | - | ||||||||||||||||||||||||||||||||||||||||||
156 | (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
| 0-1365 | ||||||||||||||||||||||||||||||||||||||||||
157 | int shift = uc % INT_BITS; | - | ||||||||||||||||||||||||||||||||||||||||||
158 | int r = (*p >> shift) & 1; | - | ||||||||||||||||||||||||||||||||||||||||||
159 | *p ^= ((i & 1) ^ r) << shift; | - | ||||||||||||||||||||||||||||||||||||||||||
160 | return r; executed 1365 times by 27 tests Executed by:
| 1365 | ||||||||||||||||||||||||||||||||||||||||||
161 | } | - | ||||||||||||||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||||||||||||||
163 | /* In O (or in the default if O is null), | - | ||||||||||||||||||||||||||||||||||||||||||
164 | set the value of the quoting options flag to I, which can be a | - | ||||||||||||||||||||||||||||||||||||||||||
165 | bitwise combination of enum quoting_flags, or 0 for default | - | ||||||||||||||||||||||||||||||||||||||||||
166 | behavior. Return the old value. */ | - | ||||||||||||||||||||||||||||||||||||||||||
167 | int | - | ||||||||||||||||||||||||||||||||||||||||||
168 | set_quoting_flags (struct quoting_options *o, int i) | - | ||||||||||||||||||||||||||||||||||||||||||
169 | { | - | ||||||||||||||||||||||||||||||||||||||||||
170 | int r; | - | ||||||||||||||||||||||||||||||||||||||||||
171 | if (!o)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
172 | o = &default_quoting_options; never executed: = o->flags; | 0 | ||||||||||||||||||||||||||||||||||||||||||
173 | r = o->flags; | - | ||||||||||||||||||||||||||||||||||||||||||
174 | o->flags = i; | - | ||||||||||||||||||||||||||||||||||||||||||
175 | return r; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
176 | } | - | ||||||||||||||||||||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||||||||||||||||||||
178 | void | - | ||||||||||||||||||||||||||||||||||||||||||
179 | set_custom_quoting (struct quoting_options *o, | - | ||||||||||||||||||||||||||||||||||||||||||
180 | char const *left_quote, char const *right_quote) | - | ||||||||||||||||||||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||||||||||||||||||||
182 | if (!o)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
183 | o = &default_quoting_options; never executed: >style = custom_quoting_style | 0 | ||||||||||||||||||||||||||||||||||||||||||
184 | o->style = custom_quoting_style; | - | ||||||||||||||||||||||||||||||||||||||||||
185 | if (!left_quote || !right_quote)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
186 | abort (); never executed: >left_quo | 0 | ||||||||||||||||||||||||||||||||||||||||||
187 | o->left_quote = left_quote; | - | ||||||||||||||||||||||||||||||||||||||||||
188 | o->right_quote = right_quote; | - | ||||||||||||||||||||||||||||||||||||||||||
189 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||||||||||||||
191 | /* Return quoting options for STYLE, with no extra quoting. */ | - | ||||||||||||||||||||||||||||||||||||||||||
192 | static struct quoting_options /* NOT PURE!! */ | - | ||||||||||||||||||||||||||||||||||||||||||
193 | quoting_options_from_style (enum quoting_style style) | - | ||||||||||||||||||||||||||||||||||||||||||
194 | { | - | ||||||||||||||||||||||||||||||||||||||||||
195 | struct quoting_options o = { literal_quoting_style, 0, { 0 }, NULL, NULL }; | - | ||||||||||||||||||||||||||||||||||||||||||
196 | if (style == custom_quoting_style)
| 0-1443 | ||||||||||||||||||||||||||||||||||||||||||
197 | abort (); never executed: style = s | 0 | ||||||||||||||||||||||||||||||||||||||||||
198 | o.style = style; | - | ||||||||||||||||||||||||||||||||||||||||||
199 | return o; executed 1443 times by 50 tests Executed by:
| 1443 | ||||||||||||||||||||||||||||||||||||||||||
200 | } | - | ||||||||||||||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||||||||||||||
202 | /* MSGID approximates a quotation mark. Return its translation if it | - | ||||||||||||||||||||||||||||||||||||||||||
203 | has one; otherwise, return either it or "\"", depending on S. | - | ||||||||||||||||||||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||||||||||||||||||||
205 | S is either clocale_quoting_style or locale_quoting_style. */ | - | ||||||||||||||||||||||||||||||||||||||||||
206 | static char const * | - | ||||||||||||||||||||||||||||||||||||||||||
207 | gettext_quote (char const *msgid, enum quoting_style s) | - | ||||||||||||||||||||||||||||||||||||||||||
208 | { | - | ||||||||||||||||||||||||||||||||||||||||||
209 | char const *translation = _(msgid); | - | ||||||||||||||||||||||||||||||||||||||||||
210 | char const *locale_code; | - | ||||||||||||||||||||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||||||||||||||||||||
212 | if (translation != msgid)
| 0-1638 | ||||||||||||||||||||||||||||||||||||||||||
213 | return translation; never executed: cale_code = locale_ | 0 | ||||||||||||||||||||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||||||||||||||||||||
215 | /* For UTF-8 and GB-18030, use single quotes U+2018 and U+2019. | - | ||||||||||||||||||||||||||||||||||||||||||
216 | Here is a list of other locales that include U+2018 and U+2019: | - | ||||||||||||||||||||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||||||||||||||||||||
218 | ISO-8859-7 0xA1 KOI8-T 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
219 | CP869 0x8B CP874 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
220 | CP932 0x81 0x65 CP936 0xA1 0xAE | - | ||||||||||||||||||||||||||||||||||||||||||
221 | CP949 0xA1 0xAE CP950 0xA1 0xA5 | - | ||||||||||||||||||||||||||||||||||||||||||
222 | CP1250 0x91 CP1251 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
223 | CP1252 0x91 CP1253 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
224 | CP1254 0x91 CP1255 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
225 | CP1256 0x91 CP1257 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
226 | EUC-JP 0xA1 0xC6 EUC-KR 0xA1 0xAE | - | ||||||||||||||||||||||||||||||||||||||||||
227 | EUC-TW 0xA1 0xE4 BIG5 0xA1 0xA5 | - | ||||||||||||||||||||||||||||||||||||||||||
228 | BIG5-HKSCS 0xA1 0xA5 EUC-CN 0xA1 0xAE | - | ||||||||||||||||||||||||||||||||||||||||||
229 | GBK 0xA1 0xAE Georgian-PS 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
230 | PT154 0x91 | - | ||||||||||||||||||||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||||||||||||||||||||
232 | None of these is still in wide use; using iconv is overkill. */ | - | ||||||||||||||||||||||||||||||||||||||||||
233 | locale_code = locale_charset (); | - | ||||||||||||||||||||||||||||||||||||||||||
234 | if (STRCASEEQ (locale_code, "UTF-8", 'U','T','F','-','8',0,0,0,0))
| 0-1638 | ||||||||||||||||||||||||||||||||||||||||||
235 | return msgid[0] == '`' ? "\xe2\x80\x98": "\xe2\x80\x99"; never executed: (strcaseeq0 (locale_code, "GB18030", 'G', 'B', '1', '8' | 0 | ||||||||||||||||||||||||||||||||||||||||||
236 | if (STRCASEEQ (locale_code, "GB18030", 'G','B','1','8','0','3','0',0,0))
| 0-1638 | ||||||||||||||||||||||||||||||||||||||||||
237 | return msgid[0] == '`' ? "\xa1\ae": "\xa1\xaf"; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||||||||||||||||||||
239 | return (s == clocale_quoting_style ? "\"" : "'"); executed 1638 times by 58 tests Executed by:
| 1638 | ||||||||||||||||||||||||||||||||||||||||||
240 | } | - | ||||||||||||||||||||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||||||||||||||||||||
242 | /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of | - | ||||||||||||||||||||||||||||||||||||||||||
243 | argument ARG (of size ARGSIZE), using QUOTING_STYLE, FLAGS, and | - | ||||||||||||||||||||||||||||||||||||||||||
244 | QUOTE_THESE_TOO to control quoting. | - | ||||||||||||||||||||||||||||||||||||||||||
245 | Terminate the output with a null character, and return the written | - | ||||||||||||||||||||||||||||||||||||||||||
246 | size of the output, not counting the terminating null. | - | ||||||||||||||||||||||||||||||||||||||||||
247 | If BUFFERSIZE is too small to store the output string, return the | - | ||||||||||||||||||||||||||||||||||||||||||
248 | value that would have been returned had BUFFERSIZE been large enough. | - | ||||||||||||||||||||||||||||||||||||||||||
249 | If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE. | - | ||||||||||||||||||||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||||||||||||||||||||
251 | This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG, | - | ||||||||||||||||||||||||||||||||||||||||||
252 | ARGSIZE, O), except it breaks O into its component pieces and is | - | ||||||||||||||||||||||||||||||||||||||||||
253 | not careful about errno. */ | - | ||||||||||||||||||||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||||||||||||||||||||
255 | static size_t | - | ||||||||||||||||||||||||||||||||||||||||||
256 | quotearg_buffer_restyled (char *buffer, size_t buffersize, | - | ||||||||||||||||||||||||||||||||||||||||||
257 | char const *arg, size_t argsize, | - | ||||||||||||||||||||||||||||||||||||||||||
258 | enum quoting_style quoting_style, int flags, | - | ||||||||||||||||||||||||||||||||||||||||||
259 | unsigned int const *quote_these_too, | - | ||||||||||||||||||||||||||||||||||||||||||
260 | char const *left_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
261 | char const *right_quote) | - | ||||||||||||||||||||||||||||||||||||||||||
262 | { | - | ||||||||||||||||||||||||||||||||||||||||||
263 | size_t i; | - | ||||||||||||||||||||||||||||||||||||||||||
264 | size_t len = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
265 | size_t orig_buffersize = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
266 | char const *quote_string = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
267 | size_t quote_string_len = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
268 | bool backslash_escapes = false; | - | ||||||||||||||||||||||||||||||||||||||||||
269 | bool unibyte_locale = MB_CUR_MAX == 1; | - | ||||||||||||||||||||||||||||||||||||||||||
270 | bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0; | - | ||||||||||||||||||||||||||||||||||||||||||
271 | bool pending_shell_escape_end = false; | - | ||||||||||||||||||||||||||||||||||||||||||
272 | bool encountered_single_quote = false; | - | ||||||||||||||||||||||||||||||||||||||||||
273 | bool all_c_and_shell_quote_compat = true; | - | ||||||||||||||||||||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||||||||||||||||||||
275 | #define STORE(c) \ | - | ||||||||||||||||||||||||||||||||||||||||||
276 | do \ | - | ||||||||||||||||||||||||||||||||||||||||||
277 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||
278 | if (len < buffersize) \ | - | ||||||||||||||||||||||||||||||||||||||||||
279 | buffer[len] = (c); \ | - | ||||||||||||||||||||||||||||||||||||||||||
280 | len++; \ | - | ||||||||||||||||||||||||||||||||||||||||||
281 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||
282 | while (0) | - | ||||||||||||||||||||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||||||||||||||||||||
284 | #define START_ESC() \ | - | ||||||||||||||||||||||||||||||||||||||||||
285 | do \ | - | ||||||||||||||||||||||||||||||||||||||||||
286 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||
287 | if (elide_outer_quotes) \ | - | ||||||||||||||||||||||||||||||||||||||||||
288 | goto force_outer_quoting_style; \ | - | ||||||||||||||||||||||||||||||||||||||||||
289 | escaping = true; \ | - | ||||||||||||||||||||||||||||||||||||||||||
290 | if (quoting_style == shell_always_quoting_style \ | - | ||||||||||||||||||||||||||||||||||||||||||
291 | && ! pending_shell_escape_end) \ | - | ||||||||||||||||||||||||||||||||||||||||||
292 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||
293 | STORE ('\''); \ | - | ||||||||||||||||||||||||||||||||||||||||||
294 | STORE ('$'); \ | - | ||||||||||||||||||||||||||||||||||||||||||
295 | STORE ('\''); \ | - | ||||||||||||||||||||||||||||||||||||||||||
296 | pending_shell_escape_end = true; \ | - | ||||||||||||||||||||||||||||||||||||||||||
297 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||
298 | STORE ('\\'); \ | - | ||||||||||||||||||||||||||||||||||||||||||
299 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||
300 | while (0) | - | ||||||||||||||||||||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||||||||||||||||||||
302 | #define END_ESC() \ | - | ||||||||||||||||||||||||||||||||||||||||||
303 | do \ | - | ||||||||||||||||||||||||||||||||||||||||||
304 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||
305 | if (pending_shell_escape_end && ! escaping) \ | - | ||||||||||||||||||||||||||||||||||||||||||
306 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||
307 | STORE ('\''); \ | - | ||||||||||||||||||||||||||||||||||||||||||
308 | STORE ('\''); \ | - | ||||||||||||||||||||||||||||||||||||||||||
309 | pending_shell_escape_end = false; \ | - | ||||||||||||||||||||||||||||||||||||||||||
310 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||
311 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||
312 | while (0) | - | ||||||||||||||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||||||||||||||
314 | process_input: code before this statement executed 3544 times by 77 tests Executed by:
| 3544 | ||||||||||||||||||||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||||||||||||||||||||
316 | switch (quoting_style) | - | ||||||||||||||||||||||||||||||||||||||||||
317 | { | - | ||||||||||||||||||||||||||||||||||||||||||
318 | case c_maybe_quoting_style: executed 2 times by 1 test: quoting_style = c_quoting Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
319 | quoting_style = c_quoting_style; | - | ||||||||||||||||||||||||||||||||||||||||||
320 | elide_outer_quotes = true; | - | ||||||||||||||||||||||||||||||||||||||||||
321 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
322 | case c_quoting_style: code before this statement executed 2 times by 1 test: if (!elide_outer_qu Executed by:
executed 10 times by 3 tests: if (!elide_outer_qu Executed by:
| 2-10 | ||||||||||||||||||||||||||||||||||||||||||
323 | if (!elide_outer_quotes)
| 2-10 | ||||||||||||||||||||||||||||||||||||||||||
324 | STORE ('"'); executed 10 times by 3 tests Executed by:
executed 10 times by 3 tests Executed by:
| 0-10 | ||||||||||||||||||||||||||||||||||||||||||
325 | backslash_escapes = true; | - | ||||||||||||||||||||||||||||||||||||||||||
326 | quote_string = "\""; | - | ||||||||||||||||||||||||||||||||||||||||||
327 | quote_string_len = 1; | - | ||||||||||||||||||||||||||||||||||||||||||
328 | break; executed 12 times by 4 tests Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||
329 | - | |||||||||||||||||||||||||||||||||||||||||||
330 | case escape_quoting_style: executed 46 times by 3 tests: backslash_escapes = Executed by:
| 46 | ||||||||||||||||||||||||||||||||||||||||||
331 | backslash_escapes = true; | - | ||||||||||||||||||||||||||||||||||||||||||
332 | elide_outer_quotes = false; | - | ||||||||||||||||||||||||||||||||||||||||||
333 | break; executed 46 times by 3 tests Executed by:
| 46 | ||||||||||||||||||||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||||||||||||||||||||
335 | case locale_quoting_style: executed 815 times by 58 tests: case clocale_quoting_style Executed by:
| 815 | ||||||||||||||||||||||||||||||||||||||||||
336 | case clocale_quoting_style: executed 4 times by 1 test: case custom_quoting_style: Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||
337 | case custom_quoting_style: never executed: { | 0 | ||||||||||||||||||||||||||||||||||||||||||
338 | { | - | ||||||||||||||||||||||||||||||||||||||||||
339 | if (quoting_style != custom_quoting_style)
| 0-819 | ||||||||||||||||||||||||||||||||||||||||||
340 | { | - | ||||||||||||||||||||||||||||||||||||||||||
341 | /* TRANSLATORS: | - | ||||||||||||||||||||||||||||||||||||||||||
342 | Get translations for open and closing quotation marks. | - | ||||||||||||||||||||||||||||||||||||||||||
343 | The message catalog should translate "`" to a left | - | ||||||||||||||||||||||||||||||||||||||||||
344 | quotation mark suitable for the locale, and similarly for | - | ||||||||||||||||||||||||||||||||||||||||||
345 | "'". For example, a French Unicode local should translate | - | ||||||||||||||||||||||||||||||||||||||||||
346 | these to U+00AB (LEFT-POINTING DOUBLE ANGLE | - | ||||||||||||||||||||||||||||||||||||||||||
347 | QUOTATION MARK), and U+00BB (RIGHT-POINTING DOUBLE ANGLE | - | ||||||||||||||||||||||||||||||||||||||||||
348 | QUOTATION MARK), respectively. | - | ||||||||||||||||||||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||||||||||||||||||||
350 | If the catalog has no translation, we will try to | - | ||||||||||||||||||||||||||||||||||||||||||
351 | use Unicode U+2018 (LEFT SINGLE QUOTATION MARK) and | - | ||||||||||||||||||||||||||||||||||||||||||
352 | Unicode U+2019 (RIGHT SINGLE QUOTATION MARK). If the | - | ||||||||||||||||||||||||||||||||||||||||||
353 | current locale is not Unicode, locale_quoting_style | - | ||||||||||||||||||||||||||||||||||||||||||
354 | will quote 'like this', and clocale_quoting_style will | - | ||||||||||||||||||||||||||||||||||||||||||
355 | quote "like this". You should always include translations | - | ||||||||||||||||||||||||||||||||||||||||||
356 | for "`" and "'" even if U+2018 and U+2019 are appropriate | - | ||||||||||||||||||||||||||||||||||||||||||
357 | for your locale. | - | ||||||||||||||||||||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||||||||||||||||||||
359 | If you don't know what to put here, please see | - | ||||||||||||||||||||||||||||||||||||||||||
360 | <https://en.wikipedia.org/wiki/Quotation_marks_in_other_languages> | - | ||||||||||||||||||||||||||||||||||||||||||
361 | and use glyphs suitable for your language. */ | - | ||||||||||||||||||||||||||||||||||||||||||
362 | left_quote = gettext_quote (N_("`"), quoting_style); | - | ||||||||||||||||||||||||||||||||||||||||||
363 | right_quote = gettext_quote (N_("'"), quoting_style); | - | ||||||||||||||||||||||||||||||||||||||||||
364 | } executed 819 times by 58 tests Executed by:
| 819 | ||||||||||||||||||||||||||||||||||||||||||
365 | if (!elide_outer_quotes)
| 0-819 | ||||||||||||||||||||||||||||||||||||||||||
366 | for (quote_string = left_quote; *quote_string; quote_string++)
| 819 | ||||||||||||||||||||||||||||||||||||||||||
367 | STORE (*quote_string); executed 752 times by 58 tests Executed by:
executed 819 times by 58 tests Executed by:
| 67-819 | ||||||||||||||||||||||||||||||||||||||||||
368 | backslash_escapes = true; | - | ||||||||||||||||||||||||||||||||||||||||||
369 | quote_string = right_quote; | - | ||||||||||||||||||||||||||||||||||||||||||
370 | quote_string_len = strlen (quote_string); | - | ||||||||||||||||||||||||||||||||||||||||||
371 | } | - | ||||||||||||||||||||||||||||||||||||||||||
372 | break; executed 819 times by 58 tests Executed by:
| 819 | ||||||||||||||||||||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||||||||||||||||||||
374 | case shell_escape_quoting_style: executed 145 times by 25 tests: backslash_escapes = Executed by:
| 145 | ||||||||||||||||||||||||||||||||||||||||||
375 | backslash_escapes = true; | - | ||||||||||||||||||||||||||||||||||||||||||
376 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
377 | case shell_quoting_style: code before this statement executed 145 times by 25 tests: elide_outer_quotes = Executed by:
executed 4 times by 1 test: elide_outer_quotes = Executed by:
| 4-145 | ||||||||||||||||||||||||||||||||||||||||||
378 | elide_outer_quotes = true; | - | ||||||||||||||||||||||||||||||||||||||||||
379 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
380 | case shell_escape_always_quoting_style: code before this statement executed 149 times by 25 tests: if (!elide_outer_quotes) Executed by:
executed 1407 times by 31 tests: if (!elide_outer_quotes) Executed by:
| 149-1407 | ||||||||||||||||||||||||||||||||||||||||||
381 | if (!elide_outer_quotes)
| 149-1407 | ||||||||||||||||||||||||||||||||||||||||||
382 | backslash_escapes = true; executed 1407 times by 31 tests: 1 ; ((void) 0); Executed by:
| 1407 | ||||||||||||||||||||||||||||||||||||||||||
383 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
384 | case shell_always_quoting_style: code before this statement executed 1556 times by 41 tests: quoting_style = shell_always_q Executed by:
executed 4 times by 1 test: quoting_style = shell_always_q Executed by:
| 4-1556 | ||||||||||||||||||||||||||||||||||||||||||
385 | quoting_style = shell_always_quoting_style; | - | ||||||||||||||||||||||||||||||||||||||||||
386 | if (!elide_outer_quotes)
| 149-1411 | ||||||||||||||||||||||||||||||||||||||||||
387 | STORE ('\''); executed 1286 times by 31 tests Executed by:
executed 1411 times by 31 tests Executed by:
| 125-1411 | ||||||||||||||||||||||||||||||||||||||||||
388 | quote_string = "'"; | - | ||||||||||||||||||||||||||||||||||||||||||
389 | quote_string_len = 1; | - | ||||||||||||||||||||||||||||||||||||||||||
390 | break; executed 1560 times by 41 tests Executed by:
| 1560 | ||||||||||||||||||||||||||||||||||||||||||
391 | - | |||||||||||||||||||||||||||||||||||||||||||
392 | case literal_quoting_style: executed 1107 times by 2 tests: elide_outer_quotes = Executed by:
| 1107 | ||||||||||||||||||||||||||||||||||||||||||
393 | elide_outer_quotes = false; | - | ||||||||||||||||||||||||||||||||||||||||||
394 | break; executed 1107 times by 2 tests Executed by:
| 1107 | ||||||||||||||||||||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||||||||||||||||||||
396 | default: never executed: abort | 0 | ||||||||||||||||||||||||||||||||||||||||||
397 | abort (); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
398 | } | - | ||||||||||||||||||||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||||||||||||||||||||
400 | for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
| 0-42132 | ||||||||||||||||||||||||||||||||||||||||||
401 | { | - | ||||||||||||||||||||||||||||||||||||||||||
402 | unsigned char c; | - | ||||||||||||||||||||||||||||||||||||||||||
403 | unsigned char esc; | - | ||||||||||||||||||||||||||||||||||||||||||
404 | bool is_right_quote = false; | - | ||||||||||||||||||||||||||||||||||||||||||
405 | bool escaping = false; | - | ||||||||||||||||||||||||||||||||||||||||||
406 | bool c_and_shell_quote_compat = false; | - | ||||||||||||||||||||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||||||||||||||||||||
408 | if (backslash_escapes
| 14648-27484 | ||||||||||||||||||||||||||||||||||||||||||
409 | && quoting_style != shell_always_quoting_style
| 5270-9378 | ||||||||||||||||||||||||||||||||||||||||||
410 | && quote_string_len
| 292-4978 | ||||||||||||||||||||||||||||||||||||||||||
411 | && (i + quote_string_len
| 0-4978 | ||||||||||||||||||||||||||||||||||||||||||
412 | <= (argsize == SIZE_MAX && 1 < quote_string_len
| 0-4978 | ||||||||||||||||||||||||||||||||||||||||||
413 | /* Use strlen only if we must: when argsize is SIZE_MAX,
| 0-4978 | ||||||||||||||||||||||||||||||||||||||||||
414 | and when the quote string is more than 1 byte long.
| 0-4978 | ||||||||||||||||||||||||||||||||||||||||||
415 | If we do call strlen, save the result. */
| 0-4978 | ||||||||||||||||||||||||||||||||||||||||||
416 | ? (argsize = strlen (arg)) : argsize))
| 0-4978 | ||||||||||||||||||||||||||||||||||||||||||
417 | && memcmp (arg + i, quote_string, quote_string_len) == 0)
| 2-4976 | ||||||||||||||||||||||||||||||||||||||||||
418 | { | - | ||||||||||||||||||||||||||||||||||||||||||
419 | if (elide_outer_quotes)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
420 | goto force_outer_quoting_style; never executed: _right_quote = | 0 | ||||||||||||||||||||||||||||||||||||||||||
421 | is_right_quote = true; | - | ||||||||||||||||||||||||||||||||||||||||||
422 | } executed 2 times by 2 tests Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||||||||||||||||||||
424 | c = arg[i]; | - | ||||||||||||||||||||||||||||||||||||||||||
425 | switch (c) | - | ||||||||||||||||||||||||||||||||||||||||||
426 | { | - | ||||||||||||||||||||||||||||||||||||||||||
427 | case '\0': never executed: if (back | 0 | ||||||||||||||||||||||||||||||||||||||||||
428 | if (backslash_escapes)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
429 | { | - | ||||||||||||||||||||||||||||||||||||||||||
430 | START_ESC (); never executed never executed never executed never executed never executed never executed
| 0 | ||||||||||||||||||||||||||||||||||||||||||
431 | /* If quote_string were to begin with digits, we'd need to | - | ||||||||||||||||||||||||||||||||||||||||||
432 | test for the end of the arg as well. However, it's | - | ||||||||||||||||||||||||||||||||||||||||||
433 | hard to imagine any locale that would use digits in | - | ||||||||||||||||||||||||||||||||||||||||||
434 | quotes, and set_custom_quoting is documented not to | - | ||||||||||||||||||||||||||||||||||||||||||
435 | accept them. Use only a single \0 with shell-escape | - | ||||||||||||||||||||||||||||||||||||||||||
436 | as currently digits are not printed within $'...' */ | - | ||||||||||||||||||||||||||||||||||||||||||
437 | if (quoting_style != shell_always_quoting_style
| 0 | ||||||||||||||||||||||||||||||||||||||||||
438 | && i + 1 < argsize && '0' <= arg[i + 1] && arg[i + 1] <= '9')
| 0 | ||||||||||||||||||||||||||||||||||||||||||
439 | { | - | ||||||||||||||||||||||||||||||||||||||||||
440 | STORE ('0'); never executed: buffer[len] = ('0');
| 0 | ||||||||||||||||||||||||||||||||||||||||||
441 | STORE ('0'); never executed
| 0 | ||||||||||||||||||||||||||||||||||||||||||
442 | } never executed: = | 0 | ||||||||||||||||||||||||||||||||||||||||||
443 | c = '0'; | - | ||||||||||||||||||||||||||||||||||||||||||
444 | /* We don't have to worry that this last '0' will be | - | ||||||||||||||||||||||||||||||||||||||||||
445 | backslash-escaped because, again, quote_string should | - | ||||||||||||||||||||||||||||||||||||||||||
446 | not start with it and because quote_these_too is | - | ||||||||||||||||||||||||||||||||||||||||||
447 | documented as not accepting it. */ | - | ||||||||||||||||||||||||||||||||||||||||||
448 | } never executed: s | 0 | ||||||||||||||||||||||||||||||||||||||||||
449 | else if (flags & QA_ELIDE_NULL_BYTES)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
450 | continue; never executed: eak; | 0 | ||||||||||||||||||||||||||||||||||||||||||
451 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
452 | - | |||||||||||||||||||||||||||||||||||||||||||
453 | case '?': executed 10 times by 1 test: switch Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||
454 | switch (quoting_style) | - | ||||||||||||||||||||||||||||||||||||||||||
455 | { | - | ||||||||||||||||||||||||||||||||||||||||||
456 | case shell_always_quoting_style: executed 10 times by 1 test: if (elide_outer_quotes) Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||
457 | if (elide_outer_quotes)
| 0-10 | ||||||||||||||||||||||||||||||||||||||||||
458 | goto force_outer_quoting_style; never executed: eak; | 0 | ||||||||||||||||||||||||||||||||||||||||||
459 | break; executed 10 times by 1 test Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||||||||||||||||||||
461 | case c_quoting_style: never executed: if ((flags & QA_SPL | 0 | ||||||||||||||||||||||||||||||||||||||||||
462 | if ((flags & QA_SPLIT_TRIGRAPHS)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
463 | && i + 2 < argsize && arg[i + 1] == '?')
| 0 | ||||||||||||||||||||||||||||||||||||||||||
464 | switch (arg[i + 2]) | - | ||||||||||||||||||||||||||||||||||||||||||
465 | { | - | ||||||||||||||||||||||||||||||||||||||||||
466 | case '!': case '\'': never executed: case '(': never executed: case ')': | 0 | ||||||||||||||||||||||||||||||||||||||||||
467 | case '(': case ')': case '-': case '/': never executed: case '<': never executed: case '=': never executed: case '>': never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
468 | case '<': case '=': case '>': never executed never executed never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
469 | /* Escape the second '?' in what would otherwise be | - | ||||||||||||||||||||||||||||||||||||||||||
470 | a trigraph. */ | - | ||||||||||||||||||||||||||||||||||||||||||
471 | if (elide_outer_quotes)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
472 | goto force_outer_quoting_style; never executed: = arg[i + 2]; | 0 | ||||||||||||||||||||||||||||||||||||||||||
473 | c = arg[i + 2]; | - | ||||||||||||||||||||||||||||||||||||||||||
474 | i += 2; | - | ||||||||||||||||||||||||||||||||||||||||||
475 | STORE ('?'); never executed: buffer[len] = ('"');
| 0 | ||||||||||||||||||||||||||||||||||||||||||
476 | STORE ('"'); never executed: buffer[len] = ('"');
| 0 | ||||||||||||||||||||||||||||||||||||||||||
477 | STORE ('"'); never executed: buffer[len] = ('?');
| 0 | ||||||||||||||||||||||||||||||||||||||||||
478 | STORE ('?'); never executed
| 0 | ||||||||||||||||||||||||||||||||||||||||||
479 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
480 | - | |||||||||||||||||||||||||||||||||||||||||||
481 | default: never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||
482 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
483 | } | - | ||||||||||||||||||||||||||||||||||||||||||
484 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||||||||||||||||||||
486 | default: never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||
487 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
488 | } | - | ||||||||||||||||||||||||||||||||||||||||||
489 | break; executed 10 times by 1 test Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||||||||||||||||||||
491 | case '\a': esc = 'a'; goto c_escape; executed 44 times by 1 test: goto c_escape; Executed by:
executed 44 times by 1 test: case '\b': Executed by:
| 44 | ||||||||||||||||||||||||||||||||||||||||||
492 | case '\b': esc = 'b'; goto c_escape; never executed: goto c_escape; never executed: case '\f': | 0 | ||||||||||||||||||||||||||||||||||||||||||
493 | case '\f': esc = 'f'; goto c_escape; never executed: goto c_and_she never executed: case '\n': | 0 | ||||||||||||||||||||||||||||||||||||||||||
494 | case '\n': esc = 'n'; goto c_and_shell_escape; executed 2 times by 1 test: goto c_and_shell_escape; Executed by:
executed 2 times by 1 test: case '\r': Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
495 | case '\r': esc = 'r'; goto c_and_shell_escape; executed 2 times by 1 test: goto c_and_shell_escape; Executed by:
executed 2 times by 1 test: case '\t': Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
496 | case '\t': esc = 't'; goto c_and_shell_escape; never executed: goto c_escape; never executed: case '\v': | 0 | ||||||||||||||||||||||||||||||||||||||||||
497 | case '\v': esc = 'v'; goto c_escape; never executed never executed: case '\\': | 0 | ||||||||||||||||||||||||||||||||||||||||||
498 | case '\\': esc = c; executed 2 times by 1 test Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
499 | /* Never need to escape '\' in shell case. */ | - | ||||||||||||||||||||||||||||||||||||||||||
500 | if (quoting_style == shell_always_quoting_style)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
501 | { | - | ||||||||||||||||||||||||||||||||||||||||||
502 | if (elide_outer_quotes)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
503 | goto force_outer_quoting_style; never executed: to store_c; | 0 | ||||||||||||||||||||||||||||||||||||||||||
504 | goto store_c; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
505 | } | - | ||||||||||||||||||||||||||||||||||||||||||
506 | - | |||||||||||||||||||||||||||||||||||||||||||
507 | /* No need to escape the escape if we are trying to elide | - | ||||||||||||||||||||||||||||||||||||||||||
508 | outer quotes and nothing else is problematic. */ | - | ||||||||||||||||||||||||||||||||||||||||||
509 | if (backslash_escapes && elide_outer_quotes && quote_string_len)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
510 | goto store_c; executed 2 times by 1 test Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||||||||||||||||||||
512 | c_and_shell_escape: code before this statement never executed: if (quoting_style | 0 | ||||||||||||||||||||||||||||||||||||||||||
513 | if (quoting_style == shell_always_quoting_style
| 0-4 | ||||||||||||||||||||||||||||||||||||||||||
514 | && elide_outer_quotes)
| 2 | ||||||||||||||||||||||||||||||||||||||||||
515 | goto force_outer_quoting_style; executed 2 times by 2 tests Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
516 | /* fall through */ | - | ||||||||||||||||||||||||||||||||||||||||||
517 | c_escape: code before this statement executed 2 times by 2 tests: if (bac Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
518 | if (backslash_escapes)
| 18-28 | ||||||||||||||||||||||||||||||||||||||||||
519 | { | - | ||||||||||||||||||||||||||||||||||||||||||
520 | c = esc; | - | ||||||||||||||||||||||||||||||||||||||||||
521 | goto store_escape; executed 28 times by 3 tests Executed by:
| 28 | ||||||||||||||||||||||||||||||||||||||||||
522 | } | - | ||||||||||||||||||||||||||||||||||||||||||
523 | break; executed 18 times by 1 test Executed by:
| 18 | ||||||||||||||||||||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||||||||||||||||||||
525 | case '{': case '}': /* sometimes special if isolated */ never executed: if (! ( never executed: rgsize == | 0 | ||||||||||||||||||||||||||||||||||||||||||
526 | if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
| 0 | ||||||||||||||||||||||||||||||||||||||||||
527 | break; never executed: void) | 0 | ||||||||||||||||||||||||||||||||||||||||||
528 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
529 | case '#': case '~': code before this statement never executed: if (i ! never executed: if (i ! executed 21 times by 4 tests: 0) Executed by:
| 0-21 | ||||||||||||||||||||||||||||||||||||||||||
530 | if (i != 0)
| 2-19 | ||||||||||||||||||||||||||||||||||||||||||
531 | break; executed 19 times by 4 tests: void) Executed by:
| 19 | ||||||||||||||||||||||||||||||||||||||||||
532 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
533 | case ' ': code before this statement executed 2 times by 1 test: c_and_s Executed by:
executed 67 times by 11 tests: c_and_s Executed by:
| 2-67 | ||||||||||||||||||||||||||||||||||||||||||
534 | c_and_shell_quote_compat = true; | - | ||||||||||||||||||||||||||||||||||||||||||
535 | FALLTHROUGH; | - | ||||||||||||||||||||||||||||||||||||||||||
536 | case '!': /* special in bash */ code before this statement executed 69 times by 11 tests: case '"': Executed by:
never executed: case '"': | 0-69 | ||||||||||||||||||||||||||||||||||||||||||
537 | case '"': case '$': case '&': executed 6 times by 2 tests: case '(': Executed by:
never executed: case ')': never executed: case '*': | 0-6 | ||||||||||||||||||||||||||||||||||||||||||
538 | case '(': case ')': case '*': case ';': never executed: case '<': never executed executed 30 times by 1 test Executed by:
never executed | 0-30 | ||||||||||||||||||||||||||||||||||||||||||
539 | case '<': never executed: case '=': | 0 | ||||||||||||||||||||||||||||||||||||||||||
540 | case '=': /* sometimes special in 0th or (with "set -k") later args */ executed 3 times by 2 tests: case '>': Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
541 | case '>': case '[': executed 1 time by 1 test: case '^': Executed by:
never executed | 0-1 | ||||||||||||||||||||||||||||||||||||||||||
542 | case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */ executed 3 times by 1 test: case '`': Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
543 | case '`': case '|': never executed never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
544 | /* A shell special character. In theory, '$' and '`' could | - | ||||||||||||||||||||||||||||||||||||||||||
545 | be the first bytes of multibyte characters, which means | - | ||||||||||||||||||||||||||||||||||||||||||
546 | we should check them with mbrtowc, but in practice this | - | ||||||||||||||||||||||||||||||||||||||||||
547 | doesn't happen so it's not worth worrying about. */ | - | ||||||||||||||||||||||||||||||||||||||||||
548 | if (quoting_style == shell_always_quoting_style
| 37-75 | ||||||||||||||||||||||||||||||||||||||||||
549 | && elide_outer_quotes)
| 17-58 | ||||||||||||||||||||||||||||||||||||||||||
550 | goto force_outer_quoting_style; executed 17 times by 4 tests: eak; Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||||||||
551 | break; executed 95 times by 15 tests Executed by:
| 95 | ||||||||||||||||||||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||||||||||||||||||||
553 | case '\'': executed 7 times by 3 tests: encounte Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||
554 | encountered_single_quote = true; | - | ||||||||||||||||||||||||||||||||||||||||||
555 | c_and_shell_quote_compat = true; | - | ||||||||||||||||||||||||||||||||||||||||||
556 | if (quoting_style == shell_always_quoting_style)
| 3-4 | ||||||||||||||||||||||||||||||||||||||||||
557 | { | - | ||||||||||||||||||||||||||||||||||||||||||
558 | if (elide_outer_quotes)
| 1-2 | ||||||||||||||||||||||||||||||||||||||||||
559 | goto force_outer_quoting_style; executed 1 time by 1 test Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||||||||||||||||||||
561 | if (buffersize && ! orig_buffersize)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
562 | { | - | ||||||||||||||||||||||||||||||||||||||||||
563 | /* Just scan string to see if supports a more concise | - | ||||||||||||||||||||||||||||||||||||||||||
564 | representation, rather than writing a longer string | - | ||||||||||||||||||||||||||||||||||||||||||
565 | but returning the length of the more concise form. */ | - | ||||||||||||||||||||||||||||||||||||||||||
566 | orig_buffersize = buffersize; | - | ||||||||||||||||||||||||||||||||||||||||||
567 | buffersize = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
568 | } executed 2 times by 2 tests Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
569 | - | |||||||||||||||||||||||||||||||||||||||||||
570 | STORE ('\''); never executed: buffer[len] = ('\\');
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
571 | STORE ('\\'); never executed: buffer[len] = ('\'');
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
572 | STORE ('\''); never executed
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
573 | pending_shell_escape_end = false; | - | ||||||||||||||||||||||||||||||||||||||||||
574 | } executed 2 times by 2 tests: e Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
575 | break; executed 6 times by 3 tests Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||
576 | - | |||||||||||||||||||||||||||||||||||||||||||
577 | case '%': case '+': case ',': case '-': case '.': case '/': executed 21 times by 3 tests: case '0': Executed by:
executed 12 times by 7 tests: case '1': Executed by:
executed 4 times by 2 tests: case '2': Executed by:
executed 1168 times by 51 tests: case '3': Executed by:
executed 1350 times by 27 tests: case '4': Executed by:
executed 5842 times by 30 tests: case '5': Executed by:
| 4-5842 | ||||||||||||||||||||||||||||||||||||||||||
578 | case '0': case '1': case '2': case '3': case '4': case '5': executed 286 times by 26 tests: case '6': Executed by:
executed 273 times by 39 tests: case '7': Executed by:
executed 221 times by 22 tests: case '8': Executed by:
executed 112 times by 20 tests: case '9': Executed by:
executed 250 times by 19 tests: case ':': Executed by:
executed 81 times by 15 tests Executed by:
| 81-286 | ||||||||||||||||||||||||||||||||||||||||||
579 | case '6': case '7': case '8': case '9': case ':': executed 101 times by 19 tests: case 'A': Executed by:
executed 119 times by 18 tests: case 'B': Executed by:
executed 110 times by 17 tests: case 'C': Executed by:
executed 465 times by 18 tests: case 'D': Executed by:
executed 8 times by 4 tests: case 'E': Executed by:
| 8-465 | ||||||||||||||||||||||||||||||||||||||||||
580 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': executed 28 times by 8 tests: case 'G': Executed by:
executed 11 times by 3 tests: case 'H': Executed by:
executed 126 times by 4 tests: case 'I': Executed by:
executed 15 times by 7 tests: case 'J': Executed by:
executed 14 times by 3 tests: case 'K': Executed by:
executed 34 times by 5 tests: case 'L': Executed by:
| 11-126 | ||||||||||||||||||||||||||||||||||||||||||
581 | case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': executed 9 times by 1 test: case 'M': Executed by:
executed 13 times by 3 tests: case 'N': Executed by:
executed 17 times by 4 tests: case 'O': Executed by:
executed 7 times by 2 tests: case 'P': Executed by:
executed 7 times by 2 tests: case 'Q': Executed by:
executed 15 times by 4 tests: case 'R': Executed by:
| 7-17 | ||||||||||||||||||||||||||||||||||||||||||
582 | case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': executed 25 times by 5 tests: case 'S': Executed by:
executed 28 times by 7 tests: case 'T': Executed by:
executed 14 times by 4 tests: case 'U': Executed by:
executed 11 times by 2 tests: case 'V': Executed by:
executed 22 times by 2 tests: case 'W': Executed by:
executed 4 times by 3 tests: case 'X': Executed by:
| 4-28 | ||||||||||||||||||||||||||||||||||||||||||
583 | case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': executed 125 times by 3 tests: case 'Y': Executed by:
executed 8 times by 4 tests: case 'Z': Executed by:
executed 13 times by 4 tests: case ']': Executed by:
executed 13 times by 3 tests: case '_': Executed by:
executed 17 times by 2 tests: case 'a': Executed by:
executed 44 times by 4 tests: case 'b': Executed by:
| 8-125 | ||||||||||||||||||||||||||||||||||||||||||
584 | case 'Y': case 'Z': case ']': case '_': case 'a': case 'b': executed 8 times by 2 tests: case 'c': Executed by:
executed 21 times by 4 tests: case 'd': Executed by:
never executed: case 'e': executed 72 times by 11 tests: case 'f': Executed by:
executed 1726 times by 44 tests: case 'g': Executed by:
executed 792 times by 23 tests: case 'h': Executed by:
| 0-1726 | ||||||||||||||||||||||||||||||||||||||||||
585 | case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': executed 1829 times by 31 tests: case 'i': Executed by:
executed 530 times by 43 tests: case 'j': Executed by:
executed 3353 times by 47 tests: case 'k': Executed by:
executed 719 times by 29 tests: case 'l': Executed by:
executed 1185 times by 21 tests: case 'm': Executed by:
executed 766 times by 47 tests: case 'n': Executed by:
| 530-3353 | ||||||||||||||||||||||||||||||||||||||||||
586 | case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': executed 1712 times by 39 tests: case 'o': Executed by:
executed 8 times by 4 tests: case 'p': Executed by:
executed 156 times by 24 tests: case 'q': Executed by:
executed 1281 times by 49 tests: case 'r': Executed by:
executed 791 times by 26 tests: case 's': Executed by:
executed 1569 times by 45 tests: case 't': Executed by:
| 8-1712 | ||||||||||||||||||||||||||||||||||||||||||
587 | case 'o': case 'p': case 'q': case 'r': case 's': case 't': executed 2457 times by 45 tests: case 'u': Executed by:
executed 1644 times by 42 tests: case 'v': Executed by:
executed 178 times by 5 tests: case 'w': Executed by:
executed 2666 times by 36 tests: case 'x': Executed by:
executed 3575 times by 39 tests: case 'y': Executed by:
executed 1399 times by 34 tests: case 'z': Executed by:
| 178-3575 | ||||||||||||||||||||||||||||||||||||||||||
588 | case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': executed 1225 times by 35 tests: c_and_s Executed by:
executed 593 times by 14 tests: ell_quote Executed by:
executed 280 times by 12 tests: compat = Executed by:
executed 146 times by 27 tests Executed by:
executed 106 times by 20 tests Executed by:
executed 101 times by 12 tests Executed by:
| 101-1225 | ||||||||||||||||||||||||||||||||||||||||||
589 | /* These characters don't cause problems, no matter what the | - | ||||||||||||||||||||||||||||||||||||||||||
590 | quoting style is. They cannot start multibyte sequences. | - | ||||||||||||||||||||||||||||||||||||||||||
591 | A digit or a special letter would cause trouble if it | - | ||||||||||||||||||||||||||||||||||||||||||
592 | appeared at the beginning of quote_string because we'd then | - | ||||||||||||||||||||||||||||||||||||||||||
593 | escape by prepending a backslash. However, it's hard to | - | ||||||||||||||||||||||||||||||||||||||||||
594 | imagine any locale that would use digits or letters as | - | ||||||||||||||||||||||||||||||||||||||||||
595 | quotes, and set_custom_quoting is documented not to accept | - | ||||||||||||||||||||||||||||||||||||||||||
596 | them. Also, a digit or a special letter would cause | - | ||||||||||||||||||||||||||||||||||||||||||
597 | trouble if it appeared in quote_these_too, but that's also | - | ||||||||||||||||||||||||||||||||||||||||||
598 | documented as not accepting them. */ | - | ||||||||||||||||||||||||||||||||||||||||||
599 | c_and_shell_quote_compat = true; | - | ||||||||||||||||||||||||||||||||||||||||||
600 | break; executed 41931 times by 76 tests Executed by:
| 41931 | ||||||||||||||||||||||||||||||||||||||||||
601 | - | |||||||||||||||||||||||||||||||||||||||||||
602 | default: executed 3 times by 2 tests Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
603 | /* If we have a multibyte sequence, copy it until we reach | - | ||||||||||||||||||||||||||||||||||||||||||
604 | its end, find an error, or come back to the initial shift | - | ||||||||||||||||||||||||||||||||||||||||||
605 | state. For C-like styles, if the sequence has | - | ||||||||||||||||||||||||||||||||||||||||||
606 | unprintable characters, escape the whole sequence, since | - | ||||||||||||||||||||||||||||||||||||||||||
607 | we can't easily escape single characters within it. */ | - | ||||||||||||||||||||||||||||||||||||||||||
608 | { | - | ||||||||||||||||||||||||||||||||||||||||||
609 | /* Length of multibyte sequence found so far. */ | - | ||||||||||||||||||||||||||||||||||||||||||
610 | size_t m; | - | ||||||||||||||||||||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||||||||||||||||||||
612 | bool printable; | - | ||||||||||||||||||||||||||||||||||||||||||
613 | - | |||||||||||||||||||||||||||||||||||||||||||
614 | if (unibyte_locale)
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
615 | { | - | ||||||||||||||||||||||||||||||||||||||||||
616 | m = 1; | - | ||||||||||||||||||||||||||||||||||||||||||
617 | printable = isprint (c) != 0; | - | ||||||||||||||||||||||||||||||||||||||||||
618 | } executed 3 times by 2 tests: s Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
619 | else | - | ||||||||||||||||||||||||||||||||||||||||||
620 | { | - | ||||||||||||||||||||||||||||||||||||||||||
621 | mbstate_t mbstate; | - | ||||||||||||||||||||||||||||||||||||||||||
622 | memset (&mbstate, 0, sizeof mbstate); | - | ||||||||||||||||||||||||||||||||||||||||||
623 | - | |||||||||||||||||||||||||||||||||||||||||||
624 | m = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
625 | printable = true; | - | ||||||||||||||||||||||||||||||||||||||||||
626 | if (argsize == SIZE_MAX)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
627 | argsize = strlen (arg); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||||||||||||||||||||
629 | do | - | ||||||||||||||||||||||||||||||||||||||||||
630 | { | - | ||||||||||||||||||||||||||||||||||||||||||
631 | wchar_t w; | - | ||||||||||||||||||||||||||||||||||||||||||
632 | size_t bytes = mbrtowc (&w, &arg[i + m], | - | ||||||||||||||||||||||||||||||||||||||||||
633 | argsize - (i + m), &mbstate); | - | ||||||||||||||||||||||||||||||||||||||||||
634 | if (bytes == 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
635 | break; never executed: se if | 0 | ||||||||||||||||||||||||||||||||||||||||||
636 | else if (bytes == (size_t) -1)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
637 | { | - | ||||||||||||||||||||||||||||||||||||||||||
638 | printable = false; | - | ||||||||||||||||||||||||||||||||||||||||||
639 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
640 | } | - | ||||||||||||||||||||||||||||||||||||||||||
641 | else if (bytes == (size_t) -2)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
642 | { | - | ||||||||||||||||||||||||||||||||||||||||||
643 | printable = false; | - | ||||||||||||||||||||||||||||||||||||||||||
644 | while (i + m < argsize && arg[i + m])
| 0 | ||||||||||||||||||||||||||||||||||||||||||
645 | m++; never executed: eak; | 0 | ||||||||||||||||||||||||||||||||||||||||||
646 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
647 | } | - | ||||||||||||||||||||||||||||||||||||||||||
648 | else | - | ||||||||||||||||||||||||||||||||||||||||||
649 | { | - | ||||||||||||||||||||||||||||||||||||||||||
650 | /* Work around a bug with older shells that "see" a '\' | - | ||||||||||||||||||||||||||||||||||||||||||
651 | that is really the 2nd byte of a multibyte character. | - | ||||||||||||||||||||||||||||||||||||||||||
652 | In practice the problem is limited to ASCII | - | ||||||||||||||||||||||||||||||||||||||||||
653 | chars >= '@' that are shell special chars. */ | - | ||||||||||||||||||||||||||||||||||||||||||
654 | if ('[' == 0x5b && elide_outer_quotes
| 0 | ||||||||||||||||||||||||||||||||||||||||||
655 | && quoting_style == shell_always_quoting_style)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
656 | { | - | ||||||||||||||||||||||||||||||||||||||||||
657 | size_t j; | - | ||||||||||||||||||||||||||||||||||||||||||
658 | for (j = 1; j < bytes; j++)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
659 | switch (arg[i + m + j]) | - | ||||||||||||||||||||||||||||||||||||||||||
660 | { | - | ||||||||||||||||||||||||||||||||||||||||||
661 | case '[': case '\\': case '^': never executed: case '`': never executed: case '|': never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
662 | case '`': case '|': never executed: goto fo never executed: ce_outer_ | 0 | ||||||||||||||||||||||||||||||||||||||||||
663 | goto force_outer_quoting_style; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
664 | - | |||||||||||||||||||||||||||||||||||||||||||
665 | default: never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||
666 | break; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
667 | } | - | ||||||||||||||||||||||||||||||||||||||||||
668 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
669 | - | |||||||||||||||||||||||||||||||||||||||||||
670 | if (! iswprint (w))
| 0 | ||||||||||||||||||||||||||||||||||||||||||
671 | printable = false; never executed: 0 ; m += bytes; | 0 | ||||||||||||||||||||||||||||||||||||||||||
672 | m += bytes; | - | ||||||||||||||||||||||||||||||||||||||||||
673 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
674 | } | - | ||||||||||||||||||||||||||||||||||||||||||
675 | while (! mbsinit (&mbstate));
| 0 | ||||||||||||||||||||||||||||||||||||||||||
676 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||||||||||||||||||||
678 | c_and_shell_quote_compat = printable; | - | ||||||||||||||||||||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||||||||||||||||||||
680 | if (1 < m || (backslash_escapes && ! printable))
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
681 | { | - | ||||||||||||||||||||||||||||||||||||||||||
682 | /* Output a multibyte sequence, or an escaped | - | ||||||||||||||||||||||||||||||||||||||||||
683 | unprintable unibyte character. */ | - | ||||||||||||||||||||||||||||||||||||||||||
684 | size_t ilim = i + m; | - | ||||||||||||||||||||||||||||||||||||||||||
685 | - | |||||||||||||||||||||||||||||||||||||||||||
686 | for (;;) | - | ||||||||||||||||||||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||||||||||||||||||||
688 | if (backslash_escapes && ! printable)
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
689 | { | - | ||||||||||||||||||||||||||||||||||||||||||
690 | START_ESC (); never executed never executed never executed never executed never executed: o executed 3 times by 2 tests: fer[len] = ('0' + (c Executed by:
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
691 | STORE ('0' + (c >> 6)); executed 3 times by 2 tests: buffer[len] = ('0' + ((c >> 3) Executed by:
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
692 | STORE ('0' + ((c >> 3) & 7)); executed 3 times by 2 tests Executed by:
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
693 | c = '0' + (c & 7); | - | ||||||||||||||||||||||||||||||||||||||||||
694 | } executed 3 times by 2 tests: s Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
695 | else if (is_right_quote)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
696 | { | - | ||||||||||||||||||||||||||||||||||||||||||
697 | STORE ('\\'); never executed
| 0 | ||||||||||||||||||||||||||||||||||||||||||
698 | is_right_quote = false; | - | ||||||||||||||||||||||||||||||||||||||||||
699 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
700 | if (ilim <= i + 1)
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
701 | break; executed 3 times by 2 tests: { if Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
702 | END_ESC (); never executed never executed never executed: o
| 0 | ||||||||||||||||||||||||||||||||||||||||||
703 | STORE (c); never executed
| 0 | ||||||||||||||||||||||||||||||||||||||||||
704 | c = arg[++i]; | - | ||||||||||||||||||||||||||||||||||||||||||
705 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
706 | - | |||||||||||||||||||||||||||||||||||||||||||
707 | goto store_c; executed 3 times by 2 tests Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
708 | } | - | ||||||||||||||||||||||||||||||||||||||||||
709 | } | - | ||||||||||||||||||||||||||||||||||||||||||
710 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
711 | - | |||||||||||||||||||||||||||||||||||||||||||
712 | if (! (((backslash_escapes && quoting_style != shell_always_quoting_style)
| 5247-27484 | ||||||||||||||||||||||||||||||||||||||||||
713 | || elide_outer_quotes)
| 2312-34520 | ||||||||||||||||||||||||||||||||||||||||||
714 | && quote_these_too
| 1-7558 | ||||||||||||||||||||||||||||||||||||||||||
715 | && quote_these_too[c / INT_BITS] >> (c % INT_BITS) & 1)
| 0-7558 | ||||||||||||||||||||||||||||||||||||||||||
716 | && !is_right_quote)
| 2-42077 | ||||||||||||||||||||||||||||||||||||||||||
717 | goto store_c; executed 42077 times by 76 tests Executed by:
| 42077 | ||||||||||||||||||||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||||||||||||||||||||
719 | store_escape: code before this statement executed 2 times by 2 tests: do { if (el Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
720 | START_ESC (); executed 4 times by 1 test Executed by:
executed 6 times by 3 tests Executed by:
executed 6 times by 3 tests Executed by:
executed 6 times by 3 tests Executed by:
executed 6 times by 3 tests Executed by:
executed 26 times by 5 tests Executed by:
| 0-26 | ||||||||||||||||||||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||||||||||||||||||||
722 | store_c: code before this statement executed 26 times by 5 tests: do { i Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||||||||
723 | END_ESC (); executed 1 time by 1 test Executed by:
executed 1 time by 1 test Executed by:
executed 1 time by 1 test: o Executed by:
| 0-42101 | ||||||||||||||||||||||||||||||||||||||||||
724 | STORE (c); executed 40275 times by 77 tests Executed by:
| 1833-40275 | ||||||||||||||||||||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||||||||||||||||||||
726 | if (! c_and_shell_quote_compat)
| 119-41989 | ||||||||||||||||||||||||||||||||||||||||||
727 | all_c_and_shell_quote_compat = false; executed 119 times by 11 tests: 0 ; } Executed by:
| 119 | ||||||||||||||||||||||||||||||||||||||||||
728 | } executed 42108 times by 77 tests Executed by:
| 42108 | ||||||||||||||||||||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||||||||||||||||||||
730 | if (len == 0 && quoting_style == shell_always_quoting_style
| 0-3517 | ||||||||||||||||||||||||||||||||||||||||||
731 | && elide_outer_quotes)
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||
732 | goto force_outer_quoting_style; executed 3 times by 2 tests Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||
733 | - | |||||||||||||||||||||||||||||||||||||||||||
734 | /* Single shell quotes (') are commonly enough used as an apostrophe, | - | ||||||||||||||||||||||||||||||||||||||||||
735 | that we attempt to minimize the quoting in this case. Note itʼs | - | ||||||||||||||||||||||||||||||||||||||||||
736 | better to use the apostrophe modifier "\u02BC" if possible, as that | - | ||||||||||||||||||||||||||||||||||||||||||
737 | renders better and works with the word match regex \W+ etc. */ | - | ||||||||||||||||||||||||||||||||||||||||||
738 | if (quoting_style == shell_always_quoting_style && ! elide_outer_quotes
| 122-1984 | ||||||||||||||||||||||||||||||||||||||||||
739 | && encountered_single_quote)
| 2-1409 | ||||||||||||||||||||||||||||||||||||||||||
740 | { | - | ||||||||||||||||||||||||||||||||||||||||||
741 | if (all_c_and_shell_quote_compat)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||
742 | return quotearg_buffer_restyled (buffer, orig_buffersize, arg, argsize, executed 2 times by 2 tests: c_quoting_style, flags, quote_these_too, left_quote, right_quote); else if (! buffersize && orig_buffersize) Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
743 | c_quoting_style, executed 2 times by 2 tests: c_quoting_style, flags, quote_these_too, left_quote, right_quote); else if (! buffersize && orig_buffersize) Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
744 | flags, quote_these_too, executed 2 times by 2 tests: c_quoting_style, flags, quote_these_too, left_quote, right_quote); else if (! buffersize && orig_buffersize) Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
745 | left_quote, right_quote); executed 2 times by 2 tests: c_quoting_style, flags, quote_these_too, left_quote, right_quote); else if (! buffersize && orig_buffersize) Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||
746 | else if (! buffersize && orig_buffersize)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
747 | { | - | ||||||||||||||||||||||||||||||||||||||||||
748 | /* Disable read-only scan, and reprocess to write quoted string. */ | - | ||||||||||||||||||||||||||||||||||||||||||
749 | buffersize = orig_buffersize; | - | ||||||||||||||||||||||||||||||||||||||||||
750 | len = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
751 | goto process_input; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
752 | } | - | ||||||||||||||||||||||||||||||||||||||||||
753 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
754 | - | |||||||||||||||||||||||||||||||||||||||||||
755 | if (quote_string && !elide_outer_quotes)
| 124-2362 | ||||||||||||||||||||||||||||||||||||||||||
756 | for (; *quote_string; quote_string++)
| 2238 | ||||||||||||||||||||||||||||||||||||||||||
757 | STORE (*quote_string); executed 2045 times by 71 tests Executed by:
executed 2238 times by 71 tests Executed by:
| 193-2238 | ||||||||||||||||||||||||||||||||||||||||||
758 | - | |||||||||||||||||||||||||||||||||||||||||||
759 | if (len < buffersize)
| 196-3319 | ||||||||||||||||||||||||||||||||||||||||||
760 | buffer[len] = '\0'; executed 3319 times by 77 tests: turn len; Executed by:
| 3319 | ||||||||||||||||||||||||||||||||||||||||||
761 | return len; executed 3515 times by 77 tests Executed by:
| 3515 | ||||||||||||||||||||||||||||||||||||||||||
762 | - | |||||||||||||||||||||||||||||||||||||||||||
763 | force_outer_quoting_style: | - | ||||||||||||||||||||||||||||||||||||||||||
764 | /* Don't reuse quote_these_too, since the addition of outer quotes | - | ||||||||||||||||||||||||||||||||||||||||||
765 | sufficiently quotes the specified characters. */ | - | ||||||||||||||||||||||||||||||||||||||||||
766 | if (quoting_style == shell_always_quoting_style && backslash_escapes)
| 0-27 | ||||||||||||||||||||||||||||||||||||||||||
767 | quoting_style = shell_escape_always_quoting_style; executed 27 times by 7 tests: turn quotearg_buffer_restyled (buffer, buffersize, Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||
768 | return quotearg_buffer_restyled (buffer, buffersize, arg, argsize, executed 27 times by 7 tests: quoting_style, flags & ~QA_ELIDE_OUTER_QUOTES, ((void *)0) , left_quote, right_quote); } Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||
769 | quoting_style, executed 27 times by 7 tests: quoting_style, flags & ~QA_ELIDE_OUTER_QUOTES, ((void *)0) , left_quote, right_quote); } Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||
770 | flags & ~QA_ELIDE_OUTER_QUOTES, NULL, executed 27 times by 7 tests: quoting_style, flags & ~QA_ELIDE_OUTER_QUOTES, ((void *)0) , left_quote, right_quote); } Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||
771 | left_quote, right_quote); executed 27 times by 7 tests: quoting_style, flags & ~QA_ELIDE_OUTER_QUOTES, ((void *)0) , left_quote, right_quote); } Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||
772 | } | - | ||||||||||||||||||||||||||||||||||||||||||
773 | - | |||||||||||||||||||||||||||||||||||||||||||
774 | /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of | - | ||||||||||||||||||||||||||||||||||||||||||
775 | argument ARG (of size ARGSIZE), using O to control quoting. | - | ||||||||||||||||||||||||||||||||||||||||||
776 | If O is null, use the default. | - | ||||||||||||||||||||||||||||||||||||||||||
777 | Terminate the output with a null character, and return the written | - | ||||||||||||||||||||||||||||||||||||||||||
778 | size of the output, not counting the terminating null. | - | ||||||||||||||||||||||||||||||||||||||||||
779 | If BUFFERSIZE is too small to store the output string, return the | - | ||||||||||||||||||||||||||||||||||||||||||
780 | value that would have been returned had BUFFERSIZE been large enough. | - | ||||||||||||||||||||||||||||||||||||||||||
781 | If ARGSIZE is SIZE_MAX, use the string length of the argument for | - | ||||||||||||||||||||||||||||||||||||||||||
782 | ARGSIZE. */ | - | ||||||||||||||||||||||||||||||||||||||||||
783 | size_t | - | ||||||||||||||||||||||||||||||||||||||||||
784 | quotearg_buffer (char *buffer, size_t buffersize, | - | ||||||||||||||||||||||||||||||||||||||||||
785 | char const *arg, size_t argsize, | - | ||||||||||||||||||||||||||||||||||||||||||
786 | struct quoting_options const *o) | - | ||||||||||||||||||||||||||||||||||||||||||
787 | { | - | ||||||||||||||||||||||||||||||||||||||||||
788 | struct quoting_options const *p = o ? o : &default_quoting_options;
| 0-1180 | ||||||||||||||||||||||||||||||||||||||||||
789 | int e = errno; | - | ||||||||||||||||||||||||||||||||||||||||||
790 | size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize, | - | ||||||||||||||||||||||||||||||||||||||||||
791 | p->style, p->flags, p->quote_these_too, | - | ||||||||||||||||||||||||||||||||||||||||||
792 | p->left_quote, p->right_quote); | - | ||||||||||||||||||||||||||||||||||||||||||
793 | errno = e; | - | ||||||||||||||||||||||||||||||||||||||||||
794 | return r; executed 1180 times by 3 tests Executed by:
| 1180 | ||||||||||||||||||||||||||||||||||||||||||
795 | } | - | ||||||||||||||||||||||||||||||||||||||||||
796 | - | |||||||||||||||||||||||||||||||||||||||||||
797 | /* Equivalent to quotearg_alloc (ARG, ARGSIZE, NULL, O). */ | - | ||||||||||||||||||||||||||||||||||||||||||
798 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
799 | quotearg_alloc (char const *arg, size_t argsize, | - | ||||||||||||||||||||||||||||||||||||||||||
800 | struct quoting_options const *o) | - | ||||||||||||||||||||||||||||||||||||||||||
801 | { | - | ||||||||||||||||||||||||||||||||||||||||||
802 | return quotearg_alloc_mem (arg, argsize, NULL, o); never executed: ((void *)0) , o); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
803 | } | - | ||||||||||||||||||||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||||||||||||||||||||
805 | /* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly | - | ||||||||||||||||||||||||||||||||||||||||||
806 | allocated storage containing the quoted string, and store the | - | ||||||||||||||||||||||||||||||||||||||||||
807 | resulting size into *SIZE, if non-NULL. The result can contain | - | ||||||||||||||||||||||||||||||||||||||||||
808 | embedded null bytes only if ARGSIZE is not SIZE_MAX, SIZE is not | - | ||||||||||||||||||||||||||||||||||||||||||
809 | NULL, and set_quoting_flags has not set the null byte elision | - | ||||||||||||||||||||||||||||||||||||||||||
810 | flag. */ | - | ||||||||||||||||||||||||||||||||||||||||||
811 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
812 | quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size, | - | ||||||||||||||||||||||||||||||||||||||||||
813 | struct quoting_options const *o) | - | ||||||||||||||||||||||||||||||||||||||||||
814 | { | - | ||||||||||||||||||||||||||||||||||||||||||
815 | struct quoting_options const *p = o ? o : &default_quoting_options;
| 0 | ||||||||||||||||||||||||||||||||||||||||||
816 | int e = errno; | - | ||||||||||||||||||||||||||||||||||||||||||
817 | /* Elide embedded null bytes if we can't return a size. */ | - | ||||||||||||||||||||||||||||||||||||||||||
818 | int flags = p->flags | (size ? 0 : QA_ELIDE_NULL_BYTES); | - | ||||||||||||||||||||||||||||||||||||||||||
819 | size_t bufsize = quotearg_buffer_restyled (0, 0, arg, argsize, p->style, | - | ||||||||||||||||||||||||||||||||||||||||||
820 | flags, p->quote_these_too, | - | ||||||||||||||||||||||||||||||||||||||||||
821 | p->left_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
822 | p->right_quote) + 1; | - | ||||||||||||||||||||||||||||||||||||||||||
823 | char *buf = xcharalloc (bufsize); | - | ||||||||||||||||||||||||||||||||||||||||||
824 | quotearg_buffer_restyled (buf, bufsize, arg, argsize, p->style, flags, | - | ||||||||||||||||||||||||||||||||||||||||||
825 | p->quote_these_too, | - | ||||||||||||||||||||||||||||||||||||||||||
826 | p->left_quote, p->right_quote); | - | ||||||||||||||||||||||||||||||||||||||||||
827 | errno = e; | - | ||||||||||||||||||||||||||||||||||||||||||
828 | if (size)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
829 | *size = bufsize - 1; never executed: turn buf; | 0 | ||||||||||||||||||||||||||||||||||||||||||
830 | return buf; never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
831 | } | - | ||||||||||||||||||||||||||||||||||||||||||
832 | - | |||||||||||||||||||||||||||||||||||||||||||
833 | /* A storage slot with size and pointer to a value. */ | - | ||||||||||||||||||||||||||||||||||||||||||
834 | struct slotvec | - | ||||||||||||||||||||||||||||||||||||||||||
835 | { | - | ||||||||||||||||||||||||||||||||||||||||||
836 | size_t size; | - | ||||||||||||||||||||||||||||||||||||||||||
837 | char *val; | - | ||||||||||||||||||||||||||||||||||||||||||
838 | }; | - | ||||||||||||||||||||||||||||||||||||||||||
839 | - | |||||||||||||||||||||||||||||||||||||||||||
840 | /* Preallocate a slot 0 buffer, so that the caller can always quote | - | ||||||||||||||||||||||||||||||||||||||||||
841 | one small component of a "memory exhausted" message in slot 0. */ | - | ||||||||||||||||||||||||||||||||||||||||||
842 | static char slot0[256]; | - | ||||||||||||||||||||||||||||||||||||||||||
843 | static int nslots = 1; | - | ||||||||||||||||||||||||||||||||||||||||||
844 | static struct slotvec slotvec0 = {sizeof slot0, slot0}; | - | ||||||||||||||||||||||||||||||||||||||||||
845 | static struct slotvec *slotvec = &slotvec0; | - | ||||||||||||||||||||||||||||||||||||||||||
846 | - | |||||||||||||||||||||||||||||||||||||||||||
847 | void | - | ||||||||||||||||||||||||||||||||||||||||||
848 | quotearg_free (void) | - | ||||||||||||||||||||||||||||||||||||||||||
849 | { | - | ||||||||||||||||||||||||||||||||||||||||||
850 | struct slotvec *sv = slotvec; | - | ||||||||||||||||||||||||||||||||||||||||||
851 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||
852 | for (i = 1; i < nslots; i++)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
853 | free (sv[i].val); never executed: (sv[0].val != sl | 0 | ||||||||||||||||||||||||||||||||||||||||||
854 | if (sv[0].val != slot0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
855 | { | - | ||||||||||||||||||||||||||||||||||||||||||
856 | free (sv[0].val); | - | ||||||||||||||||||||||||||||||||||||||||||
857 | slotvec0.size = sizeof slot0; | - | ||||||||||||||||||||||||||||||||||||||||||
858 | slotvec0.val = slot0; | - | ||||||||||||||||||||||||||||||||||||||||||
859 | } never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
860 | if (sv != &slotvec0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
861 | { | - | ||||||||||||||||||||||||||||||||||||||||||
862 | free (sv); | - | ||||||||||||||||||||||||||||||||||||||||||
863 | slotvec = &slotvec0; | - | ||||||||||||||||||||||||||||||||||||||||||
864 | } never executed: l | 0 | ||||||||||||||||||||||||||||||||||||||||||
865 | nslots = 1; | - | ||||||||||||||||||||||||||||||||||||||||||
866 | } never executed: s | 0 | ||||||||||||||||||||||||||||||||||||||||||
867 | - | |||||||||||||||||||||||||||||||||||||||||||
868 | /* Use storage slot N to return a quoted version of argument ARG. | - | ||||||||||||||||||||||||||||||||||||||||||
869 | ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a | - | ||||||||||||||||||||||||||||||||||||||||||
870 | null-terminated string. | - | ||||||||||||||||||||||||||||||||||||||||||
871 | OPTIONS specifies the quoting options. | - | ||||||||||||||||||||||||||||||||||||||||||
872 | The returned value points to static storage that can be | - | ||||||||||||||||||||||||||||||||||||||||||
873 | reused by the next call to this function with the same value of N. | - | ||||||||||||||||||||||||||||||||||||||||||
874 | N must be nonnegative. N is deliberately declared with type "int" | - | ||||||||||||||||||||||||||||||||||||||||||
875 | to allow for future extensions (using negative values). */ | - | ||||||||||||||||||||||||||||||||||||||||||
876 | static char * | - | ||||||||||||||||||||||||||||||||||||||||||
877 | quotearg_n_options (int n, char const *arg, size_t argsize, | - | ||||||||||||||||||||||||||||||||||||||||||
878 | struct quoting_options const *options) | - | ||||||||||||||||||||||||||||||||||||||||||
879 | { | - | ||||||||||||||||||||||||||||||||||||||||||
880 | int e = errno; | - | ||||||||||||||||||||||||||||||||||||||||||
881 | - | |||||||||||||||||||||||||||||||||||||||||||
882 | struct slotvec *sv = slotvec; | - | ||||||||||||||||||||||||||||||||||||||||||
883 | - | |||||||||||||||||||||||||||||||||||||||||||
884 | if (n < 0)
| 0-2139 | ||||||||||||||||||||||||||||||||||||||||||
885 | abort (); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
886 | - | |||||||||||||||||||||||||||||||||||||||||||
887 | if (nslots <= n)
| 185-1954 | ||||||||||||||||||||||||||||||||||||||||||
888 | { | - | ||||||||||||||||||||||||||||||||||||||||||
889 | bool preallocated = (sv == &slotvec0); | - | ||||||||||||||||||||||||||||||||||||||||||
890 | int nmax = MIN (INT_MAX, MIN (PTRDIFF_MAX, SIZE_MAX) / sizeof *sv) - 1;
| 0-185 | ||||||||||||||||||||||||||||||||||||||||||
891 | - | |||||||||||||||||||||||||||||||||||||||||||
892 | if (nmax < n)
| 0-185 | ||||||||||||||||||||||||||||||||||||||||||
893 | xalloc_die (); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
894 | - | |||||||||||||||||||||||||||||||||||||||||||
895 | slotvec = sv = xrealloc (preallocated ? NULL : sv, (n + 1) * sizeof *sv); | - | ||||||||||||||||||||||||||||||||||||||||||
896 | if (preallocated)
| 0-185 | ||||||||||||||||||||||||||||||||||||||||||
897 | *sv = slotvec0; executed 185 times by 20 tests: mset (sv + nslo Executed by:
| 185 | ||||||||||||||||||||||||||||||||||||||||||
898 | memset (sv + nslots, 0, (n + 1 - nslots) * sizeof *sv); | - | ||||||||||||||||||||||||||||||||||||||||||
899 | nslots = n + 1; | - | ||||||||||||||||||||||||||||||||||||||||||
900 | } executed 185 times by 20 tests Executed by:
| 185 | ||||||||||||||||||||||||||||||||||||||||||
901 | - | |||||||||||||||||||||||||||||||||||||||||||
902 | { | - | ||||||||||||||||||||||||||||||||||||||||||
903 | size_t size = sv[n].size; | - | ||||||||||||||||||||||||||||||||||||||||||
904 | char *val = sv[n].val; | - | ||||||||||||||||||||||||||||||||||||||||||
905 | /* Elide embedded null bytes since we don't return a size. */ | - | ||||||||||||||||||||||||||||||||||||||||||
906 | int flags = options->flags | QA_ELIDE_NULL_BYTES; | - | ||||||||||||||||||||||||||||||||||||||||||
907 | size_t qsize = quotearg_buffer_restyled (val, size, arg, argsize, | - | ||||||||||||||||||||||||||||||||||||||||||
908 | options->style, flags, | - | ||||||||||||||||||||||||||||||||||||||||||
909 | options->quote_these_too, | - | ||||||||||||||||||||||||||||||||||||||||||
910 | options->left_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
911 | options->right_quote); | - | ||||||||||||||||||||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||||||||||||||||||||
913 | if (size <= qsize)
| 196-1943 | ||||||||||||||||||||||||||||||||||||||||||
914 | { | - | ||||||||||||||||||||||||||||||||||||||||||
915 | sv[n].size = size = qsize + 1; | - | ||||||||||||||||||||||||||||||||||||||||||
916 | if (val != slot0)
| 1-195 | ||||||||||||||||||||||||||||||||||||||||||
917 | free (val); executed 195 times by 20 tests: [n].val = v Executed by:
| 195 | ||||||||||||||||||||||||||||||||||||||||||
918 | sv[n].val = val = xcharalloc (size); | - | ||||||||||||||||||||||||||||||||||||||||||
919 | quotearg_buffer_restyled (val, size, arg, argsize, options->style, | - | ||||||||||||||||||||||||||||||||||||||||||
920 | flags, options->quote_these_too, | - | ||||||||||||||||||||||||||||||||||||||||||
921 | options->left_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
922 | options->right_quote); | - | ||||||||||||||||||||||||||||||||||||||||||
923 | } executed 196 times by 21 tests Executed by:
| 196 | ||||||||||||||||||||||||||||||||||||||||||
924 | - | |||||||||||||||||||||||||||||||||||||||||||
925 | errno = e; | - | ||||||||||||||||||||||||||||||||||||||||||
926 | return val; executed 2139 times by 77 tests Executed by:
| 2139 | ||||||||||||||||||||||||||||||||||||||||||
927 | } | - | ||||||||||||||||||||||||||||||||||||||||||
928 | } | - | ||||||||||||||||||||||||||||||||||||||||||
929 | - | |||||||||||||||||||||||||||||||||||||||||||
930 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
931 | quotearg_n (int n, char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
932 | { | - | ||||||||||||||||||||||||||||||||||||||||||
933 | return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options); never executed: (18446744073709551615UL) , &default_quoting_options); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
934 | } | - | ||||||||||||||||||||||||||||||||||||||||||
935 | - | |||||||||||||||||||||||||||||||||||||||||||
936 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
937 | quotearg_n_mem (int n, char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
938 | { | - | ||||||||||||||||||||||||||||||||||||||||||
939 | return quotearg_n_options (n, arg, argsize, &default_quoting_options); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
940 | } | - | ||||||||||||||||||||||||||||||||||||||||||
941 | - | |||||||||||||||||||||||||||||||||||||||||||
942 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
943 | quotearg (char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
944 | { | - | ||||||||||||||||||||||||||||||||||||||||||
945 | return quotearg_n (0, arg); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
946 | } | - | ||||||||||||||||||||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||||||||||||||||||||
948 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
949 | quotearg_mem (char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
950 | { | - | ||||||||||||||||||||||||||||||||||||||||||
951 | return quotearg_n_mem (0, arg, argsize); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
952 | } | - | ||||||||||||||||||||||||||||||||||||||||||
953 | - | |||||||||||||||||||||||||||||||||||||||||||
954 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
955 | quotearg_n_style (int n, enum quoting_style s, char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
956 | { | - | ||||||||||||||||||||||||||||||||||||||||||
957 | struct quoting_options const o = quoting_options_from_style (s); | - | ||||||||||||||||||||||||||||||||||||||||||
958 | return quotearg_n_options (n, arg, SIZE_MAX, &o); executed 1307 times by 38 tests: (18446744073709551615UL) , &o); } Executed by:
| 1307 | ||||||||||||||||||||||||||||||||||||||||||
959 | } | - | ||||||||||||||||||||||||||||||||||||||||||
960 | - | |||||||||||||||||||||||||||||||||||||||||||
961 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
962 | quotearg_n_style_mem (int n, enum quoting_style s, | - | ||||||||||||||||||||||||||||||||||||||||||
963 | char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
964 | { | - | ||||||||||||||||||||||||||||||||||||||||||
965 | struct quoting_options const o = quoting_options_from_style (s); | - | ||||||||||||||||||||||||||||||||||||||||||
966 | return quotearg_n_options (n, arg, argsize, &o); executed 1 time by 1 test Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||
967 | } | - | ||||||||||||||||||||||||||||||||||||||||||
968 | - | |||||||||||||||||||||||||||||||||||||||||||
969 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
970 | quotearg_style (enum quoting_style s, char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
971 | { | - | ||||||||||||||||||||||||||||||||||||||||||
972 | return quotearg_n_style (0, s, arg); executed 1014 times by 29 tests Executed by:
| 1014 | ||||||||||||||||||||||||||||||||||||||||||
973 | } | - | ||||||||||||||||||||||||||||||||||||||||||
974 | - | |||||||||||||||||||||||||||||||||||||||||||
975 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
976 | quotearg_style_mem (enum quoting_style s, char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
977 | { | - | ||||||||||||||||||||||||||||||||||||||||||
978 | return quotearg_n_style_mem (0, s, arg, argsize); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
979 | } | - | ||||||||||||||||||||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||||||||||||||||||||
981 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
982 | quotearg_char_mem (char const *arg, size_t argsize, char ch) | - | ||||||||||||||||||||||||||||||||||||||||||
983 | { | - | ||||||||||||||||||||||||||||||||||||||||||
984 | struct quoting_options options; | - | ||||||||||||||||||||||||||||||||||||||||||
985 | options = default_quoting_options; | - | ||||||||||||||||||||||||||||||||||||||||||
986 | set_char_quoting (&options, ch, 1); | - | ||||||||||||||||||||||||||||||||||||||||||
987 | return quotearg_n_options (0, arg, argsize, &options); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
988 | } | - | ||||||||||||||||||||||||||||||||||||||||||
989 | - | |||||||||||||||||||||||||||||||||||||||||||
990 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
991 | quotearg_char (char const *arg, char ch) | - | ||||||||||||||||||||||||||||||||||||||||||
992 | { | - | ||||||||||||||||||||||||||||||||||||||||||
993 | return quotearg_char_mem (arg, SIZE_MAX, ch); never executed: (18446744073709551615UL) , ch); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
994 | } | - | ||||||||||||||||||||||||||||||||||||||||||
995 | - | |||||||||||||||||||||||||||||||||||||||||||
996 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
997 | quotearg_colon (char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
998 | { | - | ||||||||||||||||||||||||||||||||||||||||||
999 | return quotearg_char (arg, ':'); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
1000 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1001 | - | |||||||||||||||||||||||||||||||||||||||||||
1002 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
1003 | quotearg_colon_mem (char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
1004 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1005 | return quotearg_char_mem (arg, argsize, ':'); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
1006 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1007 | - | |||||||||||||||||||||||||||||||||||||||||||
1008 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
1009 | quotearg_n_style_colon (int n, enum quoting_style s, char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
1010 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1011 | struct quoting_options options; | - | ||||||||||||||||||||||||||||||||||||||||||
1012 | options = quoting_options_from_style (s); | - | ||||||||||||||||||||||||||||||||||||||||||
1013 | set_char_quoting (&options, ':', 1); | - | ||||||||||||||||||||||||||||||||||||||||||
1014 | return quotearg_n_options (n, arg, SIZE_MAX, &options); executed 135 times by 24 tests: (18446744073709551615UL) , &options); } Executed by:
| 135 | ||||||||||||||||||||||||||||||||||||||||||
1015 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1016 | - | |||||||||||||||||||||||||||||||||||||||||||
1017 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
1018 | quotearg_n_custom (int n, char const *left_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
1019 | char const *right_quote, char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
1020 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1021 | return quotearg_n_custom_mem (n, left_quote, right_quote, arg, never executed: (18446744073709551615UL) ); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
1022 | SIZE_MAX); never executed: (18446744073709551615UL) ); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
1023 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1024 | - | |||||||||||||||||||||||||||||||||||||||||||
1025 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
1026 | quotearg_n_custom_mem (int n, char const *left_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
1027 | char const *right_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
1028 | char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
1029 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1030 | struct quoting_options o = default_quoting_options; | - | ||||||||||||||||||||||||||||||||||||||||||
1031 | set_custom_quoting (&o, left_quote, right_quote); | - | ||||||||||||||||||||||||||||||||||||||||||
1032 | return quotearg_n_options (n, arg, argsize, &o); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
1033 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||||||||||||||||||||
1035 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
1036 | quotearg_custom (char const *left_quote, char const *right_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
1037 | char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
1038 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1039 | return quotearg_n_custom (0, left_quote, right_quote, arg); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
1040 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1041 | - | |||||||||||||||||||||||||||||||||||||||||||
1042 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
1043 | quotearg_custom_mem (char const *left_quote, char const *right_quote, | - | ||||||||||||||||||||||||||||||||||||||||||
1044 | char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
1045 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1046 | return quotearg_n_custom_mem (0, left_quote, right_quote, arg, never executed: argsize); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
1047 | argsize); never executed: argsize); } | 0 | ||||||||||||||||||||||||||||||||||||||||||
1048 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1049 | - | |||||||||||||||||||||||||||||||||||||||||||
1050 | - | |||||||||||||||||||||||||||||||||||||||||||
1051 | /* The quoting option used by the functions of quote.h. */ | - | ||||||||||||||||||||||||||||||||||||||||||
1052 | struct quoting_options quote_quoting_options = | - | ||||||||||||||||||||||||||||||||||||||||||
1053 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1054 | locale_quoting_style, | - | ||||||||||||||||||||||||||||||||||||||||||
1055 | 0, | - | ||||||||||||||||||||||||||||||||||||||||||
1056 | { 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||
1057 | NULL, NULL | - | ||||||||||||||||||||||||||||||||||||||||||
1058 | }; | - | ||||||||||||||||||||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||||||||||||||||||||
1060 | char const * | - | ||||||||||||||||||||||||||||||||||||||||||
1061 | quote_n_mem (int n, char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
1062 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1063 | return quotearg_n_options (n, arg, argsize, "e_quoting_options); executed 696 times by 56 tests Executed by:
| 696 | ||||||||||||||||||||||||||||||||||||||||||
1064 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||||||||||||||||||||
1066 | char const * | - | ||||||||||||||||||||||||||||||||||||||||||
1067 | quote_mem (char const *arg, size_t argsize) | - | ||||||||||||||||||||||||||||||||||||||||||
1068 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1069 | return quote_n_mem (0, arg, argsize); never executed | 0 | ||||||||||||||||||||||||||||||||||||||||||
1070 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1071 | - | |||||||||||||||||||||||||||||||||||||||||||
1072 | char const * | - | ||||||||||||||||||||||||||||||||||||||||||
1073 | quote_n (int n, char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
1074 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1075 | return quote_n_mem (n, arg, SIZE_MAX); executed 696 times by 56 tests: (18446744073709551615UL) ); } Executed by:
| 696 | ||||||||||||||||||||||||||||||||||||||||||
1076 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||||||||||||||||||||
1078 | char const * | - | ||||||||||||||||||||||||||||||||||||||||||
1079 | quote (char const *arg) | - | ||||||||||||||||||||||||||||||||||||||||||
1080 | { | - | ||||||||||||||||||||||||||||||||||||||||||
1081 | return quote_n (0, arg); executed 593 times by 55 tests Executed by:
| 593 | ||||||||||||||||||||||||||||||||||||||||||
1082 | } | - | ||||||||||||||||||||||||||||||||||||||||||
1083 | - | |||||||||||||||||||||||||||||||||||||||||||
1084 | /* | - | ||||||||||||||||||||||||||||||||||||||||||
1085 | * Hey Emacs! | - | ||||||||||||||||||||||||||||||||||||||||||
1086 | * Local Variables: | - | ||||||||||||||||||||||||||||||||||||||||||
1087 | * coding: utf-8 | - | ||||||||||||||||||||||||||||||||||||||||||
1088 | * End: | - | ||||||||||||||||||||||||||||||||||||||||||
1089 | */ | - | ||||||||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |