annotate lib/quotearg.h @ 6790:f638a03c525c

Cygwin recognition fix.
author Bruno Haible <bruno@clisp.org>
date Wed, 17 May 2006 10:46:10 +0000
parents a48fb0e98c8c
children 9b212deb2601
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1 /* quotearg.h - quote arguments for output
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
2
4943
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
4 Foundation, Inc.
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
5
Jim Meyering <jim@meyering.net>
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
Jim Meyering <jim@meyering.net>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
Jim Meyering <jim@meyering.net>
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
Jim Meyering <jim@meyering.net>
parents:
diff changeset
9 any later version.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
Jim Meyering <jim@meyering.net>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14 GNU General Public License for more details.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
15
Jim Meyering <jim@meyering.net>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
Jim Meyering <jim@meyering.net>
parents:
diff changeset
17 along with this program; if not, write to the Free Software Foundation,
5848
a48fb0e98c8c *** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
19
Jim Meyering <jim@meyering.net>
parents:
diff changeset
20 /* Written by Paul Eggert <eggert@twinsun.com> */
Jim Meyering <jim@meyering.net>
parents:
diff changeset
21
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
22 #ifndef QUOTEARG_H_
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
23 # define QUOTEARG_H_ 1
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
24
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
25 # include <stddef.h>
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
26
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
27 /* Basic quoting styles. */
Jim Meyering <jim@meyering.net>
parents:
diff changeset
28 enum quoting_style
Jim Meyering <jim@meyering.net>
parents:
diff changeset
29 {
4943
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
30 /* Output names as-is (ls --quoting-style=literal). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
31 literal_quoting_style,
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4943
diff changeset
32
4943
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
33 /* Quote names for the shell if they contain shell metacharacters
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
34 or would cause ambiguous output (ls --quoting-style=shell). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
35 shell_quoting_style,
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
36
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
37 /* Quote names for the shell, even if they would normally not
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
38 require quoting (ls --quoting-style=shell-always). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
39 shell_always_quoting_style,
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
40
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
41 /* Quote names as for a C language string (ls --quoting-style=c). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
42 c_quoting_style,
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
43
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
44 /* Like c_quoting_style except omit the surrounding double-quote
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
45 characters (ls --quoting-style=escape). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
46 escape_quoting_style,
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
47
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
48 /* Like clocale_quoting_style, but quote `like this' instead of
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
49 "like this" in the default C locale (ls --quoting-style=locale). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
50 locale_quoting_style,
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
51
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
52 /* Like c_quoting_style except use quotation marks appropriate for
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
53 the locale (ls --quoting-style=clocale). */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
54 clocale_quoting_style
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
55 };
Jim Meyering <jim@meyering.net>
parents:
diff changeset
56
1921
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
57 /* For now, --quoting-style=literal is the default, but this may change. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
58 # ifndef DEFAULT_QUOTING_STYLE
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
59 # define DEFAULT_QUOTING_STYLE literal_quoting_style
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
60 # endif
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
61
1605
e88d6bf51916 (quoting_style_vals): New public array.
Jim Meyering <jim@meyering.net>
parents: 1282
diff changeset
62 /* Names of quoting styles and their corresponding values. */
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
63 extern char const *const quoting_style_args[];
1605
e88d6bf51916 (quoting_style_vals): New public array.
Jim Meyering <jim@meyering.net>
parents: 1282
diff changeset
64 extern enum quoting_style const quoting_style_vals[];
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
65
Jim Meyering <jim@meyering.net>
parents:
diff changeset
66 struct quoting_options;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
67
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
68 /* The functions listed below set and use a hidden variable
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
69 that contains the default quoting style options. */
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
70
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
71 /* Allocate a new set of quoting options, with contents initially identical
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
72 to O if O is not null, or to the default if O is null.
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
73 It is the caller's responsibility to free the result. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
74 struct quoting_options *clone_quoting_options (struct quoting_options *o);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
75
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
76 /* Get the value of O's quoting style. If O is null, use the default. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
77 enum quoting_style get_quoting_style (struct quoting_options *o);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
78
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
79 /* In O (or in the default if O is null),
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
80 set the value of the quoting style to S. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
81 void set_quoting_style (struct quoting_options *o, enum quoting_style s);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
82
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
83 /* In O (or in the default if O is null),
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
84 set the value of the quoting options for character C to I.
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
85 Return the old value. Currently, the only values defined for I are
Jim Meyering <jim@meyering.net>
parents:
diff changeset
86 0 (the default) and 1 (which means to quote the character even if
Jim Meyering <jim@meyering.net>
parents:
diff changeset
87 it would not otherwise be quoted). */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
88 int set_char_quoting (struct quoting_options *o, char c, int i);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
89
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
90 /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
91 argument ARG (of size ARGSIZE), using O to control quoting.
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
92 If O is null, use the default.
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
93 Terminate the output with a null character, and return the written
Jim Meyering <jim@meyering.net>
parents:
diff changeset
94 size of the output, not counting the terminating null.
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
95 If BUFFERSIZE is too small to store the output string, return the
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
96 value that would have been returned had BUFFERSIZE been large enough.
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
97 If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
98 size_t quotearg_buffer (char *buffer, size_t buffersize,
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
99 char const *arg, size_t argsize,
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
100 struct quoting_options const *o);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
101
4943
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
102 /* Like quotearg_buffer, except return the result in a newly allocated
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
103 buffer. It is the caller's responsibility to free the result. */
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
104 char *quotearg_alloc (char const *arg, size_t argsize,
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
105 struct quoting_options const *o);
686726300104 New function quotearg_alloc. Treat { } = as special sometimes.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4003
diff changeset
106
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
107 /* Use storage slot N to return a quoted version of the string ARG.
1282
c5862deb63ad Update from patch-2.5.3.
Jim Meyering <jim@meyering.net>
parents: 1248
diff changeset
108 Use the default quoting options.
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
109 The returned value points to static storage that can be
Jim Meyering <jim@meyering.net>
parents:
diff changeset
110 reused by the next call to this function with the same value of N.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
111 N must be nonnegative. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
112 char *quotearg_n (int n, char const *arg);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
113
1605
e88d6bf51916 (quoting_style_vals): New public array.
Jim Meyering <jim@meyering.net>
parents: 1282
diff changeset
114 /* Equivalent to quotearg_n (0, ARG). */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
115 char *quotearg (char const *arg);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
116
1921
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
117 /* Use style S and storage slot N to return a quoted version of the string ARG.
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
118 This is like quotearg_n (N, ARG), except that it uses S with no other
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
119 options to specify the quoting method. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
120 char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
121
3710
2b37ca0328bd (quotearg_n_style_mem): New function.
Jim Meyering <jim@meyering.net>
parents: 3658
diff changeset
122 /* Use style S and storage slot N to return a quoted version of the
2b37ca0328bd (quotearg_n_style_mem): New function.
Jim Meyering <jim@meyering.net>
parents: 3658
diff changeset
123 argument ARG of size ARGSIZE. This is like quotearg_n_style
2b37ca0328bd (quotearg_n_style_mem): New function.
Jim Meyering <jim@meyering.net>
parents: 3658
diff changeset
124 (N, S, ARG), except it can quote null bytes. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
125 char *quotearg_n_style_mem (int n, enum quoting_style s,
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
126 char const *arg, size_t argsize);
1921
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
127
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
128 /* Equivalent to quotearg_n_style (0, S, ARG). */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
129 char *quotearg_style (enum quoting_style s, char const *arg);
1921
d92e0bf8d650 (locale_quoting_style): New enum value.
Jim Meyering <jim@meyering.net>
parents: 1605
diff changeset
130
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
131 /* Like quotearg (ARG), except also quote any instances of CH. */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
132 char *quotearg_char (char const *arg, char ch);
1248
Jim Meyering <jim@meyering.net>
parents:
diff changeset
133
Jim Meyering <jim@meyering.net>
parents:
diff changeset
134 /* Equivalent to quotearg_char (ARG, ':'). */
4003
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
135 char *quotearg_colon (char const *arg);
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
136
9df30611f84c Allow multiple inclusion by surrounding with
Paul Eggert <eggert@cs.ucla.edu>
parents: 3710
diff changeset
137 #endif /* !QUOTEARG_H_ */