Mercurial > hg > octave-kai > gnulib-hg
annotate lib/quotearg.c @ 10391:f0a681493fa6
New module 'xconcat-filename', split off from module 'concat-filename'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 02 Sep 2008 01:34:21 +0200 |
parents | b991e0ca089c |
children | a0bbe1a6f787 |
rev | line source |
---|---|
1248 | 1 /* quotearg.c - quote arguments for output |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
2 |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
4 2008 Free Software Foundation, Inc. |
1248 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8433
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
1248 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8433
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8433
diff
changeset
|
9 (at your option) any later version. |
1248 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8433
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
1248 | 18 |
19 /* Written by Paul Eggert <eggert@twinsun.com> */ | |
20 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6582
diff
changeset
|
21 #include <config.h> |
1248 | 22 |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
23 #include "quotearg.h" |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
24 |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
25 #include "xalloc.h" |
1248 | 26 |
27 #include <ctype.h> | |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
28 #include <errno.h> |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
29 #include <limits.h> |
5159 | 30 #include <stdbool.h> |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
31 #include <stdlib.h> |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
32 #include <string.h> |
7888
b6376840b47b
* modules/fnmatch (Depends-on): Depend on wchar.
Eric Blake <ebb9@byu.net>
parents:
7733
diff
changeset
|
33 #include <wchar.h> |
8433
51634bc628de
* lib/quotearg.c: Include <wctype.h> early, before the definition of
Paul Eggert <eggert@cs.ucla.edu>
parents:
7888
diff
changeset
|
34 #include <wctype.h> |
1248 | 35 |
3966
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3709
diff
changeset
|
36 #include "gettext.h" |
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3709
diff
changeset
|
37 #define _(msgid) gettext (msgid) |
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3709
diff
changeset
|
38 #define N_(msgid) msgid |
1920
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
39 |
3174 | 40 #if !HAVE_MBRTOWC |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
41 /* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
42 other macros are defined only for documentation and to satisfy C |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
43 syntax. */ |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
44 # undef MB_CUR_MAX |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
45 # define MB_CUR_MAX 1 |
7394
cb46a07630b7
* quotearg.c (mbstate_t) [!HAVE_MBRTOWC]: #define to int.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
46 # undef mbstate_t |
cb46a07630b7
* quotearg.c (mbstate_t) [!HAVE_MBRTOWC]: #define to int.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
47 # define mbstate_t int |
2692
0013b0a829f1
(mbrtowc): Assign to *pwc, and return 1 only if result is nonzero.
Jim Meyering <jim@meyering.net>
parents:
2689
diff
changeset
|
48 # define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0) |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
49 # define iswprint(wc) isprint ((unsigned char) (wc)) |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
50 # undef HAVE_MBSINIT |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
51 #endif |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
52 |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
53 #if !defined mbsinit && !HAVE_MBSINIT |
2641
0fd2ca768e87
Include <wctype.h> after <wchar.h>,
Jim Meyering <jim@meyering.net>
parents:
2299
diff
changeset
|
54 # define mbsinit(ps) 1 |
0fd2ca768e87
Include <wctype.h> after <wchar.h>,
Jim Meyering <jim@meyering.net>
parents:
2299
diff
changeset
|
55 #endif |
0fd2ca768e87
Include <wctype.h> after <wchar.h>,
Jim Meyering <jim@meyering.net>
parents:
2299
diff
changeset
|
56 |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
57 #ifndef SIZE_MAX |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
58 # define SIZE_MAX ((size_t) -1) |
2234
c4a8e51bfd93
(ISASCII): Add #undef and move definition to follow
Jim Meyering <jim@meyering.net>
parents:
2183
diff
changeset
|
59 #endif |
2856
21b199ffea14
Rename ISASCII to IN_CTYPE_DOMAIN.
Jim Meyering <jim@meyering.net>
parents:
2799
diff
changeset
|
60 |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
61 #define INT_BITS (sizeof (int) * CHAR_BIT) |
2234
c4a8e51bfd93
(ISASCII): Add #undef and move definition to follow
Jim Meyering <jim@meyering.net>
parents:
2183
diff
changeset
|
62 |
1248 | 63 struct quoting_options |
64 { | |
65 /* Basic quoting style. */ | |
66 enum quoting_style style; | |
67 | |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
68 /* Additional flags. Bitwise combination of enum quoting_flags. */ |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
69 int flags; |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
70 |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
71 /* Quote the characters indicated by this bit vector even if the |
1248 | 72 quoting style would not normally require them to be quoted. */ |
5415
6b74fae0519f
(struct quoting_options): Use unsigned int for quote_these_too, so
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
73 unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1]; |
1248 | 74 }; |
75 | |
76 /* Names of quoting styles. */ | |
77 char const *const quoting_style_args[] = | |
78 { | |
1597
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
79 "literal", |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
80 "shell", |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
81 "shell-always", |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
82 "c", |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
83 "c-maybe", |
1597
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
84 "escape", |
1920
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
85 "locale", |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
86 "clocale", |
1597
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
87 0 |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
88 }; |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
89 |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
90 /* Correspondences to quoting style names. */ |
1597
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
91 enum quoting_style const quoting_style_vals[] = |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
92 { |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
93 literal_quoting_style, |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
94 shell_quoting_style, |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
95 shell_always_quoting_style, |
287550eb5c15
(quotearg_buffer): Cast -1 to size_t before comparing.
Jim Meyering <jim@meyering.net>
parents:
1565
diff
changeset
|
96 c_quoting_style, |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
97 c_maybe_quoting_style, |
1920
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
98 escape_quoting_style, |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
99 locale_quoting_style, |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
100 clocale_quoting_style |
1248 | 101 }; |
102 | |
1282 | 103 /* The default quoting options. */ |
104 static struct quoting_options default_quoting_options; | |
105 | |
1248 | 106 /* Allocate a new set of quoting options, with contents initially identical |
1282 | 107 to O if O is not null, or to the default if O is null. |
1248 | 108 It is the caller's responsibility to free the result. */ |
109 struct quoting_options * | |
110 clone_quoting_options (struct quoting_options *o) | |
111 { | |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
112 int e = errno; |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
113 struct quoting_options *p = xmemdup (o ? o : &default_quoting_options, |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
114 sizeof *o); |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
115 errno = e; |
1248 | 116 return p; |
117 } | |
118 | |
1282 | 119 /* Get the value of O's quoting style. If O is null, use the default. */ |
1248 | 120 enum quoting_style |
121 get_quoting_style (struct quoting_options *o) | |
122 { | |
1282 | 123 return (o ? o : &default_quoting_options)->style; |
1248 | 124 } |
125 | |
1282 | 126 /* In O (or in the default if O is null), |
127 set the value of the quoting style to S. */ | |
1248 | 128 void |
129 set_quoting_style (struct quoting_options *o, enum quoting_style s) | |
130 { | |
1282 | 131 (o ? o : &default_quoting_options)->style = s; |
1248 | 132 } |
133 | |
1282 | 134 /* In O (or in the default if O is null), |
135 set the value of the quoting options for character C to I. | |
1248 | 136 Return the old value. Currently, the only values defined for I are |
137 0 (the default) and 1 (which means to quote the character even if | |
138 it would not otherwise be quoted). */ | |
139 int | |
140 set_char_quoting (struct quoting_options *o, char c, int i) | |
141 { | |
142 unsigned char uc = c; | |
5415
6b74fae0519f
(struct quoting_options): Use unsigned int for quote_these_too, so
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
143 unsigned int *p = |
6b74fae0519f
(struct quoting_options): Use unsigned int for quote_these_too, so
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
144 (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS; |
1248 | 145 int shift = uc % INT_BITS; |
146 int r = (*p >> shift) & 1; | |
147 *p ^= ((i & 1) ^ r) << shift; | |
148 return r; | |
149 } | |
150 | |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
151 /* In O (or in the default if O is null), |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
152 set the value of the quoting options flag to I, which can be a |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
153 bitwise combination of enum quoting_flags, or 0 for default |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
154 behavior. Return the old value. */ |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
155 int |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
156 set_quoting_flags (struct quoting_options *o, int i) |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
157 { |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
158 int r; |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
159 if (!o) |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
160 o = &default_quoting_options; |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
161 r = o->flags; |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
162 o->flags = i; |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
163 return r; |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
164 } |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
165 |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
166 /* Return quoting options for STYLE, with no extra quoting. */ |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
167 static struct quoting_options |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
168 quoting_options_from_style (enum quoting_style style) |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
169 { |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
170 struct quoting_options o; |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
171 o.style = style; |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
172 o.flags = 0; |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
173 memset (o.quote_these_too, 0, sizeof o.quote_these_too); |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
174 return o; |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
175 } |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
176 |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
177 /* MSGID approximates a quotation mark. Return its translation if it |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
178 has one; otherwise, return either it or "\"", depending on S. */ |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
179 static char const * |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
180 gettext_quote (char const *msgid, enum quoting_style s) |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
181 { |
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
182 char const *translation = _(msgid); |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
183 if (translation == msgid && s == clocale_quoting_style) |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
184 translation = "\""; |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
185 return translation; |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
186 } |
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
187 |
1282 | 188 /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
189 argument ARG (of size ARGSIZE), using QUOTING_STYLE, FLAGS, and |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
190 QUOTE_THESE_TOO to control quoting. |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
191 Terminate the output with a null character, and return the written |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
192 size of the output, not counting the terminating null. |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
193 If BUFFERSIZE is too small to store the output string, return the |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
194 value that would have been returned had BUFFERSIZE been large enough. |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
195 If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE. |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
196 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
197 This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG, |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
198 ARGSIZE, O), except it breaks O into its component pieces and is |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
199 not careful about errno. */ |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
200 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
201 static size_t |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
202 quotearg_buffer_restyled (char *buffer, size_t buffersize, |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
203 char const *arg, size_t argsize, |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
204 enum quoting_style quoting_style, int flags, |
9701 | 205 unsigned int const *quote_these_too) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
206 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
207 size_t i; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
208 size_t len = 0; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
209 char const *quote_string = 0; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
210 size_t quote_string_len = 0; |
5159 | 211 bool backslash_escapes = false; |
212 bool unibyte_locale = MB_CUR_MAX == 1; | |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
213 bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
214 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
215 #define STORE(c) \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
216 do \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
217 { \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
218 if (len < buffersize) \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
219 buffer[len] = (c); \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
220 len++; \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
221 } \ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
222 while (0) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
223 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
224 switch (quoting_style) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
225 { |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
226 case c_maybe_quoting_style: |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
227 quoting_style = c_quoting_style; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
228 elide_outer_quotes = true; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
229 /* Fall through. */ |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
230 case c_quoting_style: |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
231 if (!elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
232 STORE ('"'); |
5159 | 233 backslash_escapes = true; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
234 quote_string = "\""; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
235 quote_string_len = 1; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
236 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
237 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
238 case escape_quoting_style: |
5159 | 239 backslash_escapes = true; |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
240 elide_outer_quotes = false; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
241 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
242 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
243 case locale_quoting_style: |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
244 case clocale_quoting_style: |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
245 { |
5990
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
246 /* TRANSLATORS: |
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
247 Get translations for open and closing quotation marks. |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
248 |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
249 The message catalog should translate "`" to a left |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
250 quotation mark suitable for the locale, and similarly for |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
251 "'". If the catalog has no translation, |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
252 locale_quoting_style quotes `like this', and |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
253 clocale_quoting_style quotes "like this". |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
254 |
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
255 For example, an American English Unicode locale should |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
256 translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
257 should translate "'" to U+201D (RIGHT DOUBLE QUOTATION |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
258 MARK). A British English Unicode locale should instead |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
259 translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and |
5990
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
260 U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. |
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
261 |
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
262 If you don't know what to put here, please see |
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
263 <http://en.wikipedia.org/wiki/Quotation_mark#Glyphs> |
56dddeef06ca
Add translator comment suggested by Bruno Haible, with a minor change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
264 and use glyphs suitable for your language. */ |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
265 |
2736
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
266 char const *left = gettext_quote (N_("`"), quoting_style); |
af22c6dccf1c
(quoting_style_args, quoting_style_vals,
Jim Meyering <jim@meyering.net>
parents:
2722
diff
changeset
|
267 char const *right = gettext_quote (N_("'"), quoting_style); |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
268 if (!elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
269 for (quote_string = left; *quote_string; quote_string++) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
270 STORE (*quote_string); |
5159 | 271 backslash_escapes = true; |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
272 quote_string = right; |
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
273 quote_string_len = strlen (quote_string); |
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
274 } |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
275 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
276 |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
277 case shell_quoting_style: |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
278 quoting_style = shell_always_quoting_style; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
279 elide_outer_quotes = true; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
280 /* Fall through. */ |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
281 case shell_always_quoting_style: |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
282 if (!elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
283 STORE ('\''); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
284 quote_string = "'"; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
285 quote_string_len = 1; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
286 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
287 |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
288 case literal_quoting_style: |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
289 elide_outer_quotes = false; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
290 break; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
291 |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
292 default: |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
293 abort (); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
294 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
295 |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
296 for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
297 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
298 unsigned char c; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
299 unsigned char esc; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
300 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
301 if (backslash_escapes |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
302 && quote_string_len |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
303 && i + quote_string_len <= argsize |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
304 && memcmp (arg + i, quote_string, quote_string_len) == 0) |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
305 { |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
306 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
307 goto force_outer_quoting_style; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
308 STORE ('\\'); |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
309 } |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
310 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
311 c = arg[i]; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
312 switch (c) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
313 { |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
314 case '\0': |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
315 if (backslash_escapes) |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
316 { |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
317 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
318 goto force_outer_quoting_style; |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
319 STORE ('\\'); |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
320 if (i + 1 < argsize && '0' <= arg[i + 1] && arg[i + 1] <= '9') |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
321 { |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
322 STORE ('0'); |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
323 STORE ('0'); |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
324 } |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
325 c = '0'; |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
326 } |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
327 else if (flags & QA_ELIDE_NULL_BYTES) |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
328 continue; |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
329 break; |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
330 |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
331 case '?': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
332 switch (quoting_style) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
333 { |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
334 case shell_always_quoting_style: |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
335 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
336 goto force_outer_quoting_style; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
337 break; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
338 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
339 case c_quoting_style: |
9706
bb55fced39b8
Avoid trigraph quoting in default output.
Eric Blake <ebb9@byu.net>
parents:
9701
diff
changeset
|
340 if ((flags & QA_SPLIT_TRIGRAPHS) |
bb55fced39b8
Avoid trigraph quoting in default output.
Eric Blake <ebb9@byu.net>
parents:
9701
diff
changeset
|
341 && i + 2 < argsize && arg[i + 1] == '?') |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
342 switch (arg[i + 2]) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
343 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
344 case '!': case '\'': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
345 case '(': case ')': case '-': case '/': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
346 case '<': case '=': case '>': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
347 /* Escape the second '?' in what would otherwise be |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
348 a trigraph. */ |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
349 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
350 goto force_outer_quoting_style; |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
351 c = arg[i + 2]; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
352 i += 2; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
353 STORE ('?'); |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
354 STORE ('"'); |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
355 STORE ('"'); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
356 STORE ('?'); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
357 break; |
6582
29fdf7a22b20
* quotearg.c (quotearg_buffer_restyled): Add "default: break;"
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
358 |
29fdf7a22b20
* quotearg.c (quotearg_buffer_restyled): Add "default: break;"
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
359 default: |
29fdf7a22b20
* quotearg.c (quotearg_buffer_restyled): Add "default: break;"
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
360 break; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
361 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
362 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
363 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
364 default: |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
365 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
366 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
367 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
368 |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
369 case '\a': esc = 'a'; goto c_escape; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
370 case '\b': esc = 'b'; goto c_escape; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
371 case '\f': esc = 'f'; goto c_escape; |
2145
d0a924014953
(quotearg_buffer_restyled): Do not quote
Jim Meyering <jim@meyering.net>
parents:
2124
diff
changeset
|
372 case '\n': esc = 'n'; goto c_and_shell_escape; |
d0a924014953
(quotearg_buffer_restyled): Do not quote
Jim Meyering <jim@meyering.net>
parents:
2124
diff
changeset
|
373 case '\r': esc = 'r'; goto c_and_shell_escape; |
d0a924014953
(quotearg_buffer_restyled): Do not quote
Jim Meyering <jim@meyering.net>
parents:
2124
diff
changeset
|
374 case '\t': esc = 't'; goto c_and_shell_escape; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
375 case '\v': esc = 'v'; goto c_escape; |
9707
b991e0ca089c
Avoid doubling \ in common case of "c-maybe" quoting style.
Eric Blake <ebb9@byu.net>
parents:
9706
diff
changeset
|
376 case '\\': esc = c; |
b991e0ca089c
Avoid doubling \ in common case of "c-maybe" quoting style.
Eric Blake <ebb9@byu.net>
parents:
9706
diff
changeset
|
377 /* No need to escape the escape if we are trying to elide |
b991e0ca089c
Avoid doubling \ in common case of "c-maybe" quoting style.
Eric Blake <ebb9@byu.net>
parents:
9706
diff
changeset
|
378 outer quotes and nothing else is problematic. */ |
b991e0ca089c
Avoid doubling \ in common case of "c-maybe" quoting style.
Eric Blake <ebb9@byu.net>
parents:
9706
diff
changeset
|
379 if (backslash_escapes && elide_outer_quotes && quote_string_len) |
b991e0ca089c
Avoid doubling \ in common case of "c-maybe" quoting style.
Eric Blake <ebb9@byu.net>
parents:
9706
diff
changeset
|
380 goto store_c; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
381 |
2145
d0a924014953
(quotearg_buffer_restyled): Do not quote
Jim Meyering <jim@meyering.net>
parents:
2124
diff
changeset
|
382 c_and_shell_escape: |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
383 if (quoting_style == shell_always_quoting_style |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
384 && elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
385 goto force_outer_quoting_style; |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
386 /* Fall through. */ |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
387 c_escape: |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
388 if (backslash_escapes) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
389 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
390 c = esc; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
391 goto store_escape; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
392 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
393 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
394 |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
395 case '{': case '}': /* sometimes special if isolated */ |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
396 if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1)) |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
397 break; |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
398 /* Fall through. */ |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
399 case '#': case '~': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
400 if (i != 0) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
401 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
402 /* Fall through. */ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
403 case ' ': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
404 case '!': /* special in bash */ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
405 case '"': case '$': case '&': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
406 case '(': case ')': case '*': case ';': |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
407 case '<': |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
408 case '=': /* sometimes special in 0th or (with "set -k") later args */ |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
409 case '>': case '[': |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
410 case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
411 case '`': case '|': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
412 /* A shell special character. In theory, '$' and '`' could |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
413 be the first bytes of multibyte characters, which means |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
414 we should check them with mbrtowc, but in practice this |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
415 doesn't happen so it's not worth worrying about. */ |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
416 if (quoting_style == shell_always_quoting_style |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
417 && elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
418 goto force_outer_quoting_style; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
419 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
420 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
421 case '\'': |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
422 if (quoting_style == shell_always_quoting_style) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
423 { |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
424 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
425 goto force_outer_quoting_style; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
426 STORE ('\''); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
427 STORE ('\\'); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
428 STORE ('\''); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
429 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
430 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
431 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
432 case '%': case '+': case ',': case '-': case '.': case '/': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
433 case '0': case '1': case '2': case '3': case '4': case '5': |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
434 case '6': case '7': case '8': case '9': case ':': |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
435 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
436 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
437 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
438 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
439 case 'Y': case 'Z': case ']': case '_': case 'a': case 'b': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
440 case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
441 case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
442 case 'o': case 'p': case 'q': case 'r': case 's': case 't': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
443 case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
444 /* These characters don't cause problems, no matter what the |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
445 quoting style is. They cannot start multibyte sequences. */ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
446 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
447 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
448 default: |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
449 /* If we have a multibyte sequence, copy it until we reach |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
450 its end, find an error, or come back to the initial shift |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
451 state. For C-like styles, if the sequence has |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
452 unprintable characters, escape the whole sequence, since |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
453 we can't easily escape single characters within it. */ |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
454 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
455 /* Length of multibyte sequence found so far. */ |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
456 size_t m; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
457 |
5159 | 458 bool printable; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
459 |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
460 if (unibyte_locale) |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
461 { |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
462 m = 1; |
5159 | 463 printable = isprint (c) != 0; |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
464 } |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
465 else |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
466 { |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
467 mbstate_t mbstate; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
468 memset (&mbstate, 0, sizeof mbstate); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
469 |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
470 m = 0; |
5159 | 471 printable = true; |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
472 if (argsize == SIZE_MAX) |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
473 argsize = strlen (arg); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
474 |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
475 do |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
476 { |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
477 wchar_t w; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
478 size_t bytes = mbrtowc (&w, &arg[i + m], |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
479 argsize - (i + m), &mbstate); |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
480 if (bytes == 0) |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
481 break; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
482 else if (bytes == (size_t) -1) |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
483 { |
5159 | 484 printable = false; |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
485 break; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
486 } |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
487 else if (bytes == (size_t) -2) |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
488 { |
5159 | 489 printable = false; |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
490 while (i + m < argsize && arg[i + m]) |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
491 m++; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
492 break; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
493 } |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
494 else |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
495 { |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
496 /* Work around a bug with older shells that "see" a '\' |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
497 that is really the 2nd byte of a multibyte character. |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
498 In practice the problem is limited to ASCII |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
499 chars >= '@' that are shell special chars. */ |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
500 if ('[' == 0x5b && elide_outer_quotes |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
501 && quoting_style == shell_always_quoting_style) |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
502 { |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
503 size_t j; |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
504 for (j = 1; j < bytes; j++) |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
505 switch (arg[i + m + j]) |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
506 { |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
507 case '[': case '\\': case '^': |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
508 case '`': case '|': |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
509 goto force_outer_quoting_style; |
6582
29fdf7a22b20
* quotearg.c (quotearg_buffer_restyled): Add "default: break;"
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
510 |
29fdf7a22b20
* quotearg.c (quotearg_buffer_restyled): Add "default: break;"
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
511 default: |
29fdf7a22b20
* quotearg.c (quotearg_buffer_restyled): Add "default: break;"
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
512 break; |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
513 } |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
514 } |
5159 | 515 |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
516 if (! iswprint (w)) |
5159 | 517 printable = false; |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
518 m += bytes; |
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
519 } |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
520 } |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
521 while (! mbsinit (&mbstate)); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
522 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
523 |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
524 if (1 < m || (backslash_escapes && ! printable)) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
525 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
526 /* Output a multibyte sequence, or an escaped |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
527 unprintable unibyte character. */ |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
528 size_t ilim = i + m; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
529 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
530 for (;;) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
531 { |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
532 if (backslash_escapes && ! printable) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
533 { |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
534 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
535 goto force_outer_quoting_style; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
536 STORE ('\\'); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
537 STORE ('0' + (c >> 6)); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
538 STORE ('0' + ((c >> 3) & 7)); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
539 c = '0' + (c & 7); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
540 } |
2768
0ba16adfc3ae
Streamline by invoking multibyte code only if needed.
Jim Meyering <jim@meyering.net>
parents:
2761
diff
changeset
|
541 if (ilim <= i + 1) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
542 break; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
543 STORE (c); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
544 c = arg[++i]; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
545 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
546 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
547 goto store_c; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
548 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
549 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
550 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
551 |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
552 if (! ((backslash_escapes || elide_outer_quotes) |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
553 && quote_these_too |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
554 && quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS)))) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
555 goto store_c; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
556 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
557 store_escape: |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
558 if (elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
559 goto force_outer_quoting_style; |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
560 STORE ('\\'); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
561 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
562 store_c: |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
563 STORE (c); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
564 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
565 |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
566 if (len == 0 && quoting_style == shell_always_quoting_style |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
567 && elide_outer_quotes) |
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
568 goto force_outer_quoting_style; |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
569 |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
570 if (quote_string && !elide_outer_quotes) |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
571 for (; *quote_string; quote_string++) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
572 STORE (*quote_string); |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
573 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
574 if (len < buffersize) |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
575 buffer[len] = '\0'; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
576 return len; |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
577 |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
578 force_outer_quoting_style: |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
579 /* Don't reuse quote_these_too, since the addition of outer quotes |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
580 sufficiently quotes the specified characters. */ |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
581 return quotearg_buffer_restyled (buffer, buffersize, arg, argsize, |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
582 quoting_style, |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
583 flags & ~QA_ELIDE_OUTER_QUOTES, NULL); |
2124
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
584 } |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
585 |
30abc8682bdf
Quote multibyte characters correctly.
Jim Meyering <jim@meyering.net>
parents:
1920
diff
changeset
|
586 /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of |
1248 | 587 argument ARG (of size ARGSIZE), using O to control quoting. |
1282 | 588 If O is null, use the default. |
1248 | 589 Terminate the output with a null character, and return the written |
590 size of the output, not counting the terminating null. | |
1282 | 591 If BUFFERSIZE is too small to store the output string, return the |
592 value that would have been returned had BUFFERSIZE been large enough. | |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
593 If ARGSIZE is SIZE_MAX, use the string length of the argument for |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
594 ARGSIZE. */ |
1248 | 595 size_t |
1282 | 596 quotearg_buffer (char *buffer, size_t buffersize, |
1248 | 597 char const *arg, size_t argsize, |
598 struct quoting_options const *o) | |
599 { | |
1282 | 600 struct quoting_options const *p = o ? o : &default_quoting_options; |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
601 int e = errno; |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
602 size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize, |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
603 p->style, p->flags, p->quote_these_too); |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
604 errno = e; |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
605 return r; |
1248 | 606 } |
607 | |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
608 /* Equivalent to quotearg_alloc (ARG, ARGSIZE, NULL, O). */ |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
609 char * |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
610 quotearg_alloc (char const *arg, size_t argsize, |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
611 struct quoting_options const *o) |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
612 { |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
613 return quotearg_alloc_mem (arg, argsize, NULL, o); |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
614 } |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
615 |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
616 /* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
617 allocated storage containing the quoted string, and store the |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
618 resulting size into *SIZE, if non-NULL. The result can contain |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
619 embedded null bytes only if ARGSIZE is not SIZE_MAX, SIZE is not |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
620 NULL, and set_quoting_flags has not set the null byte elision |
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
621 flag. */ |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
622 char * |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
623 quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size, |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
624 struct quoting_options const *o) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
625 { |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
626 struct quoting_options const *p = o ? o : &default_quoting_options; |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
627 int e = errno; |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
628 /* Elide embedded null bytes if we can't return a size. */ |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
629 int flags = p->flags | (size ? 0 : QA_ELIDE_NULL_BYTES); |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
630 size_t bufsize = quotearg_buffer_restyled (0, 0, arg, argsize, p->style, |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
631 flags, p->quote_these_too) + 1; |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
632 char *buf = xcharalloc (bufsize); |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
633 quotearg_buffer_restyled (buf, bufsize, arg, argsize, p->style, flags, |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
634 p->quote_these_too); |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
635 errno = e; |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
636 if (size) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
637 *size = bufsize - 1; |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
638 return buf; |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
639 } |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
640 |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
641 /* A storage slot with size and pointer to a value. */ |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
642 struct slotvec |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
643 { |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
644 size_t size; |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
645 char *val; |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
646 }; |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
647 |
7627
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
648 /* Preallocate a slot 0 buffer, so that the caller can always quote |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
649 one small component of a "memory exhausted" message in slot 0. */ |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
650 static char slot0[256]; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
651 static unsigned int nslots = 1; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
652 static struct slotvec slotvec0 = {sizeof slot0, slot0}; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
653 static struct slotvec *slotvec = &slotvec0; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
654 |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
655 void |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
656 quotearg_free (void) |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
657 { |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
658 struct slotvec *sv = slotvec; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
659 unsigned int i; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
660 for (i = 1; i < nslots; i++) |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
661 free (sv[i].val); |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
662 if (sv[0].val != slot0) |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
663 { |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
664 free (sv[0].val); |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
665 slotvec0.size = sizeof slot0; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
666 slotvec0.val = slot0; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
667 } |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
668 if (sv != &slotvec0) |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
669 { |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
670 free (sv); |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
671 slotvec = &slotvec0; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
672 } |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
673 nslots = 1; |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
674 } |
9b212deb2601
* lib/quotearg.h (quotearg_free): New decl.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7587
diff
changeset
|
675 |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
676 /* Use storage slot N to return a quoted version of argument ARG. |
4943
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
677 ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a |
686726300104
New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4830
diff
changeset
|
678 null-terminated string. |
1248 | 679 OPTIONS specifies the quoting options. |
680 The returned value points to static storage that can be | |
681 reused by the next call to this function with the same value of N. | |
2722
4ccbe804b834
The old behavior of quoting `like this' doesn't look good with
Jim Meyering <jim@meyering.net>
parents:
2711
diff
changeset
|
682 N must be nonnegative. N is deliberately declared with type "int" |
1663
8ae2c5884032
(quotearg_n_options): Revert type of parameter `n'
Jim Meyering <jim@meyering.net>
parents:
1650
diff
changeset
|
683 to allow for future extensions (using negative values). */ |
1248 | 684 static char * |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
685 quotearg_n_options (int n, char const *arg, size_t argsize, |
1598
d0dff44eca51
(quotearg_n_options): Make `options' parameter be `const'.
Jim Meyering <jim@meyering.net>
parents:
1597
diff
changeset
|
686 struct quoting_options const *options) |
1248 | 687 { |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
688 int e = errno; |
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
689 |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
690 unsigned int n0 = n; |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
691 struct slotvec *sv = slotvec; |
1248 | 692 |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
693 if (n < 0) |
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
694 abort (); |
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
695 |
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
696 if (nslots <= n0) |
1248 | 697 { |
6275 | 698 /* FIXME: technically, the type of n1 should be `unsigned int', |
699 but that evokes an unsuppressible warning from gcc-4.0.1 and | |
700 older. If gcc ever provides an option to suppress that warning, | |
701 revert to the original type, so that the test in xalloc_oversized | |
702 is once again performed only at compile time. */ | |
703 size_t n1 = n0 + 1; | |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
704 bool preallocated = (sv == &slotvec0); |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
705 |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
706 if (xalloc_oversized (n1, sizeof *sv)) |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
707 xalloc_die (); |
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
708 |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
709 slotvec = sv = xrealloc (preallocated ? NULL : sv, n1 * sizeof *sv); |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
710 if (preallocated) |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
711 *sv = slotvec0; |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
712 memset (sv + nslots, 0, (n1 - nslots) * sizeof *sv); |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
713 nslots = n1; |
1248 | 714 } |
715 | |
716 { | |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
717 size_t size = sv[n].size; |
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
718 char *val = sv[n].val; |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
719 /* Elide embedded null bytes since we don't return a size. */ |
9699
cdc5f14da027
Quotearg part 3: add flag to control outer quote elision.
Eric Blake <ebb9@byu.net>
parents:
9698
diff
changeset
|
720 int flags = options->flags | QA_ELIDE_NULL_BYTES; |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
721 size_t qsize = quotearg_buffer_restyled (val, size, arg, argsize, |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
722 options->style, flags, |
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
723 options->quote_these_too); |
1248 | 724 |
725 if (size <= qsize) | |
726 { | |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
727 sv[n].size = size = qsize + 1; |
4825
4f0f5b3860c9
(quotearg_n_options): Use free/xmalloc rather than xrealloc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4004
diff
changeset
|
728 if (val != slot0) |
4f0f5b3860c9
(quotearg_n_options): Use free/xmalloc rather than xrealloc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4004
diff
changeset
|
729 free (val); |
7587
1ce8d03ae034
Avoid some C++ diagnostics reported by Bruno Haible.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7394
diff
changeset
|
730 sv[n].val = val = xcharalloc (size); |
9698
2351f4d6d9f7
Quotearg part 2: add flag that can control NUL elision.
Eric Blake <ebb9@byu.net>
parents:
9697
diff
changeset
|
731 quotearg_buffer_restyled (val, size, arg, argsize, options->style, |
9700
f6f2dedca815
Quotearg part 4: add tests, fix c-maybe colon quoting.
Eric Blake <ebb9@byu.net>
parents:
9699
diff
changeset
|
732 flags, options->quote_these_too); |
1248 | 733 } |
734 | |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
735 errno = e; |
1248 | 736 return val; |
737 } | |
738 } | |
739 | |
740 char * | |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
741 quotearg_n (int n, char const *arg) |
1248 | 742 { |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
743 return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options); |
1248 | 744 } |
745 | |
746 char * | |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
747 quotearg_n_mem (int n, char const *arg, size_t argsize) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
748 { |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
749 return quotearg_n_options (n, arg, argsize, &default_quoting_options); |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
750 } |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
751 |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
752 char * |
1248 | 753 quotearg (char const *arg) |
754 { | |
755 return quotearg_n (0, arg); | |
756 } | |
757 | |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
758 char * |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
759 quotearg_mem (char const *arg, size_t argsize) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
760 { |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
761 return quotearg_n_mem (0, arg, argsize); |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
762 } |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
763 |
1248 | 764 char * |
3657
a7dfda2c0db7
(quotearg_n, quotearg_n_style): Likewise.
Jim Meyering <jim@meyering.net>
parents:
3410
diff
changeset
|
765 quotearg_n_style (int n, enum quoting_style s, char const *arg) |
1920
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
766 { |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
767 struct quoting_options const o = quoting_options_from_style (s); |
4004
c36d2363d485
Include quotearg.h immediately after config.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
3966
diff
changeset
|
768 return quotearg_n_options (n, arg, SIZE_MAX, &o); |
3709
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
769 } |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
770 |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
771 char * |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
772 quotearg_n_style_mem (int n, enum quoting_style s, |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
773 char const *arg, size_t argsize) |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
774 { |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
775 struct quoting_options const o = quoting_options_from_style (s); |
8158714ca8ba
(quotearg_buffer_restyled):
Jim Meyering <jim@meyering.net>
parents:
3657
diff
changeset
|
776 return quotearg_n_options (n, arg, argsize, &o); |
1920
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
777 } |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
778 |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
779 char * |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
780 quotearg_style (enum quoting_style s, char const *arg) |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
781 { |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
782 return quotearg_n_style (0, s, arg); |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
783 } |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
784 |
78f6058b59a6
Include <libintl.h> if ENABLE_NLS.
Jim Meyering <jim@meyering.net>
parents:
1891
diff
changeset
|
785 char * |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
786 quotearg_style_mem (enum quoting_style s, char const *arg, size_t argsize) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
787 { |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
788 return quotearg_n_style_mem (0, s, arg, argsize); |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
789 } |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
790 |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
791 char * |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
792 quotearg_char_mem (char const *arg, size_t argsize, char ch) |
1248 | 793 { |
794 struct quoting_options options; | |
1282 | 795 options = default_quoting_options; |
1248 | 796 set_char_quoting (&options, ch, 1); |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
797 return quotearg_n_options (0, arg, argsize, &options); |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
798 } |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
799 |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
800 char * |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
801 quotearg_char (char const *arg, char ch) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
802 { |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
803 return quotearg_char_mem (arg, SIZE_MAX, ch); |
1248 | 804 } |
805 | |
806 char * | |
807 quotearg_colon (char const *arg) | |
808 { | |
809 return quotearg_char (arg, ':'); | |
810 } | |
9697
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
811 |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
812 char * |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
813 quotearg_colon_mem (char const *arg, size_t argsize) |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
814 { |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
815 return quotearg_char_mem (arg, argsize, ':'); |
6dd30e9cb2a1
Quotearg part 1: more wrappers, restore quotearg_char state.
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
816 } |