xref: /dflybsd-src/contrib/grep/lib/quotearg.h (revision 91b9ed38d3db6a8a8ac5b66da1d43e6e331e259a)
195b7b453SJohn Marino /* quotearg.h - quote arguments for output
295b7b453SJohn Marino 
3*09d4459fSDaniel Fojt    Copyright (C) 1998-2002, 2004, 2006, 2008-2020 Free Software Foundation,
4200fbe8dSJohn Marino    Inc.
595b7b453SJohn Marino 
695b7b453SJohn Marino    This program is free software: you can redistribute it and/or modify
795b7b453SJohn Marino    it under the terms of the GNU General Public License as published by
895b7b453SJohn Marino    the Free Software Foundation; either version 3 of the License, or
995b7b453SJohn Marino    (at your option) any later version.
1095b7b453SJohn Marino 
1195b7b453SJohn Marino    This program is distributed in the hope that it will be useful,
1295b7b453SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
1395b7b453SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1495b7b453SJohn Marino    GNU General Public License for more details.
1595b7b453SJohn Marino 
1695b7b453SJohn Marino    You should have received a copy of the GNU General Public License
17*09d4459fSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
1895b7b453SJohn Marino 
1995b7b453SJohn Marino /* Written by Paul Eggert <eggert@twinsun.com> */
2095b7b453SJohn Marino 
2195b7b453SJohn Marino #ifndef QUOTEARG_H_
2295b7b453SJohn Marino # define QUOTEARG_H_ 1
2395b7b453SJohn Marino 
2495b7b453SJohn Marino # include <stddef.h>
2595b7b453SJohn Marino 
2695b7b453SJohn Marino /* Basic quoting styles.  For each style, an example is given on the
2795b7b453SJohn Marino    input strings "simple", "\0 \t\n'\"\033?""?/\\", and "a:b", using
2895b7b453SJohn Marino    quotearg_buffer, quotearg_mem, and quotearg_colon_mem with that
2995b7b453SJohn Marino    style and the default flags and quoted characters.  Note that the
3095b7b453SJohn Marino    examples are shown here as valid C strings rather than what
3195b7b453SJohn Marino    displays on a terminal (with "??/" as a trigraph for "\\").  */
3295b7b453SJohn Marino enum quoting_style
3395b7b453SJohn Marino   {
3495b7b453SJohn Marino     /* Output names as-is (ls --quoting-style=literal).  Can result in
3595b7b453SJohn Marino        embedded null bytes if QA_ELIDE_NULL_BYTES is not in
3695b7b453SJohn Marino        effect.
3795b7b453SJohn Marino 
3895b7b453SJohn Marino        quotearg_buffer:
3995b7b453SJohn Marino        "simple", "\0 \t\n'\"\033??/\\", "a:b"
4095b7b453SJohn Marino        quotearg:
4195b7b453SJohn Marino        "simple", " \t\n'\"\033??/\\", "a:b"
4295b7b453SJohn Marino        quotearg_colon:
4395b7b453SJohn Marino        "simple", " \t\n'\"\033??/\\", "a:b"
4495b7b453SJohn Marino     */
4595b7b453SJohn Marino     literal_quoting_style,
4695b7b453SJohn Marino 
4795b7b453SJohn Marino     /* Quote names for the shell if they contain shell metacharacters
4895b7b453SJohn Marino        or would cause ambiguous output (ls --quoting-style=shell).
4995b7b453SJohn Marino        Can result in embedded null bytes if QA_ELIDE_NULL_BYTES is not
5095b7b453SJohn Marino        in effect.
5195b7b453SJohn Marino 
5295b7b453SJohn Marino        quotearg_buffer:
5395b7b453SJohn Marino        "simple", "'\0 \t\n'\\''\"\033??/\\'", "a:b"
5495b7b453SJohn Marino        quotearg:
5595b7b453SJohn Marino        "simple", "' \t\n'\\''\"\033??/\\'", "a:b"
5695b7b453SJohn Marino        quotearg_colon:
5795b7b453SJohn Marino        "simple", "' \t\n'\\''\"\033??/\\'", "'a:b'"
5895b7b453SJohn Marino     */
5995b7b453SJohn Marino     shell_quoting_style,
6095b7b453SJohn Marino 
6195b7b453SJohn Marino     /* Quote names for the shell, even if they would normally not
6295b7b453SJohn Marino        require quoting (ls --quoting-style=shell-always).  Can result
6395b7b453SJohn Marino        in embedded null bytes if QA_ELIDE_NULL_BYTES is not in effect.
6495b7b453SJohn Marino        Behaves like shell_quoting_style if QA_ELIDE_OUTER_QUOTES is in
6595b7b453SJohn Marino        effect.
6695b7b453SJohn Marino 
6795b7b453SJohn Marino        quotearg_buffer:
6895b7b453SJohn Marino        "'simple'", "'\0 \t\n'\\''\"\033??/\\'", "'a:b'"
6995b7b453SJohn Marino        quotearg:
7095b7b453SJohn Marino        "'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
7195b7b453SJohn Marino        quotearg_colon:
7295b7b453SJohn Marino        "'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
7395b7b453SJohn Marino     */
7495b7b453SJohn Marino     shell_always_quoting_style,
7595b7b453SJohn Marino 
76*09d4459fSDaniel Fojt     /* Quote names for the shell if they contain shell metacharacters
77*09d4459fSDaniel Fojt        or other problematic characters (ls --quoting-style=shell-escape).
78*09d4459fSDaniel Fojt        Non printable characters are quoted using the $'...' syntax,
79*09d4459fSDaniel Fojt        which originated in ksh93 and is widely supported by most shells,
80*09d4459fSDaniel Fojt        and proposed for inclusion in POSIX.
81*09d4459fSDaniel Fojt 
82*09d4459fSDaniel Fojt        quotearg_buffer:
83*09d4459fSDaniel Fojt        "simple", "''$'\\0'' '$'\\t\\n'\\''\"'$'\\033''??/\\'", "a:b"
84*09d4459fSDaniel Fojt        quotearg:
85*09d4459fSDaniel Fojt        "simple", "''$'\\0'' '$'\\t\\n'\\''\"'$'\\033''??/\\'", "a:b"
86*09d4459fSDaniel Fojt        quotearg_colon:
87*09d4459fSDaniel Fojt        "simple", "''$'\\0'' '$'\\t\\n'\\''\"'$'\\033''??/\\'", "'a:b'"
88*09d4459fSDaniel Fojt     */
89*09d4459fSDaniel Fojt     shell_escape_quoting_style,
90*09d4459fSDaniel Fojt 
91*09d4459fSDaniel Fojt     /* Quote names for the shell even if they would normally not
92*09d4459fSDaniel Fojt        require quoting (ls --quoting-style=shell-escape).
93*09d4459fSDaniel Fojt        Non printable characters are quoted using the $'...' syntax,
94*09d4459fSDaniel Fojt        which originated in ksh93 and is widely supported by most shells,
95*09d4459fSDaniel Fojt        and proposed for inclusion in POSIX.  Behaves like
96*09d4459fSDaniel Fojt        shell_escape_quoting_style if QA_ELIDE_OUTER_QUOTES is in effect.
97*09d4459fSDaniel Fojt 
98*09d4459fSDaniel Fojt        quotearg_buffer:
99*09d4459fSDaniel Fojt        "simple", "''$'\\0'' '$'\\t\\n'\\''\"'$'\\033''??/\'", "a:b"
100*09d4459fSDaniel Fojt        quotearg:
101*09d4459fSDaniel Fojt        "simple", "''$'\\0'' '$'\\t\\n'\\''\"'$'\\033''??/\'", "a:b"
102*09d4459fSDaniel Fojt        quotearg_colon:
103*09d4459fSDaniel Fojt        "simple", "''$'\\0'' '$'\\t\\n'\\''\"'$'\\033''??/\'", "'a:b'"
104*09d4459fSDaniel Fojt     */
105*09d4459fSDaniel Fojt     shell_escape_always_quoting_style,
106*09d4459fSDaniel Fojt 
10795b7b453SJohn Marino     /* Quote names as for a C language string (ls --quoting-style=c).
10895b7b453SJohn Marino        Behaves like c_maybe_quoting_style if QA_ELIDE_OUTER_QUOTES is
10995b7b453SJohn Marino        in effect.  Split into consecutive strings if
11095b7b453SJohn Marino        QA_SPLIT_TRIGRAPHS.
11195b7b453SJohn Marino 
11295b7b453SJohn Marino        quotearg_buffer:
11395b7b453SJohn Marino        "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
11495b7b453SJohn Marino        quotearg:
11595b7b453SJohn Marino        "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
11695b7b453SJohn Marino        quotearg_colon:
11795b7b453SJohn Marino        "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
11895b7b453SJohn Marino     */
11995b7b453SJohn Marino     c_quoting_style,
12095b7b453SJohn Marino 
12195b7b453SJohn Marino     /* Like c_quoting_style except omit the surrounding double-quote
12295b7b453SJohn Marino        characters if no quoted characters are encountered.
12395b7b453SJohn Marino 
12495b7b453SJohn Marino        quotearg_buffer:
12595b7b453SJohn Marino        "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
12695b7b453SJohn Marino        quotearg:
12795b7b453SJohn Marino        "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
12895b7b453SJohn Marino        quotearg_colon:
12995b7b453SJohn Marino        "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
13095b7b453SJohn Marino     */
13195b7b453SJohn Marino     c_maybe_quoting_style,
13295b7b453SJohn Marino 
13395b7b453SJohn Marino     /* Like c_quoting_style except always omit the surrounding
13495b7b453SJohn Marino        double-quote characters and ignore QA_SPLIT_TRIGRAPHS
13595b7b453SJohn Marino        (ls --quoting-style=escape).
13695b7b453SJohn Marino 
13795b7b453SJohn Marino        quotearg_buffer:
13895b7b453SJohn Marino        "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
13995b7b453SJohn Marino        quotearg:
14095b7b453SJohn Marino        "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
14195b7b453SJohn Marino        quotearg_colon:
14295b7b453SJohn Marino        "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a\\:b"
14395b7b453SJohn Marino     */
14495b7b453SJohn Marino     escape_quoting_style,
14595b7b453SJohn Marino 
146cf28ed85SJohn Marino     /* Like clocale_quoting_style, but use single quotes in the
147cf28ed85SJohn Marino        default C locale or if the program does not use gettext
148cf28ed85SJohn Marino        (ls --quoting-style=locale).  For UTF-8 locales, quote
149cf28ed85SJohn Marino        characters will use Unicode.
15095b7b453SJohn Marino 
15195b7b453SJohn Marino        LC_MESSAGES=C
15295b7b453SJohn Marino        quotearg_buffer:
15395b7b453SJohn Marino        "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
15495b7b453SJohn Marino        quotearg:
15595b7b453SJohn Marino        "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
15695b7b453SJohn Marino        quotearg_colon:
15795b7b453SJohn Marino        "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a\\:b'"
15895b7b453SJohn Marino 
15995b7b453SJohn Marino        LC_MESSAGES=pt_PT.utf8
16095b7b453SJohn Marino        quotearg_buffer:
16195b7b453SJohn Marino        "\302\253simple\302\273",
16295b7b453SJohn Marino        "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
16395b7b453SJohn Marino        quotearg:
16495b7b453SJohn Marino        "\302\253simple\302\273",
16595b7b453SJohn Marino        "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
16695b7b453SJohn Marino        quotearg_colon:
16795b7b453SJohn Marino        "\302\253simple\302\273",
16895b7b453SJohn Marino        "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
16995b7b453SJohn Marino     */
17095b7b453SJohn Marino     locale_quoting_style,
17195b7b453SJohn Marino 
17295b7b453SJohn Marino     /* Like c_quoting_style except use quotation marks appropriate for
17395b7b453SJohn Marino        the locale and ignore QA_SPLIT_TRIGRAPHS
17495b7b453SJohn Marino        (ls --quoting-style=clocale).
17595b7b453SJohn Marino 
17695b7b453SJohn Marino        LC_MESSAGES=C
17795b7b453SJohn Marino        quotearg_buffer:
17895b7b453SJohn Marino        "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
17995b7b453SJohn Marino        quotearg:
18095b7b453SJohn Marino        "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
18195b7b453SJohn Marino        quotearg_colon:
18295b7b453SJohn Marino        "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
18395b7b453SJohn Marino 
18495b7b453SJohn Marino        LC_MESSAGES=pt_PT.utf8
18595b7b453SJohn Marino        quotearg_buffer:
18695b7b453SJohn Marino        "\302\253simple\302\273",
18795b7b453SJohn Marino        "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
18895b7b453SJohn Marino        quotearg:
18995b7b453SJohn Marino        "\302\253simple\302\273",
19095b7b453SJohn Marino        "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
19195b7b453SJohn Marino        quotearg_colon:
19295b7b453SJohn Marino        "\302\253simple\302\273",
19395b7b453SJohn Marino        "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
19495b7b453SJohn Marino     */
19595b7b453SJohn Marino     clocale_quoting_style,
19695b7b453SJohn Marino 
19795b7b453SJohn Marino     /* Like clocale_quoting_style except use the custom quotation marks
19895b7b453SJohn Marino        set by set_custom_quoting.  If custom quotation marks are not
19995b7b453SJohn Marino        set, the behavior is undefined.
20095b7b453SJohn Marino 
20195b7b453SJohn Marino        left_quote = right_quote = "'"
20295b7b453SJohn Marino        quotearg_buffer:
20395b7b453SJohn Marino        "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a:b'"
20495b7b453SJohn Marino        quotearg:
20595b7b453SJohn Marino        "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a:b'"
20695b7b453SJohn Marino        quotearg_colon:
20795b7b453SJohn Marino        "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a\\:b'"
20895b7b453SJohn Marino 
20995b7b453SJohn Marino        left_quote = "(" and right_quote = ")"
21095b7b453SJohn Marino        quotearg_buffer:
21195b7b453SJohn Marino        "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a:b)"
21295b7b453SJohn Marino        quotearg:
21395b7b453SJohn Marino        "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a:b)"
21495b7b453SJohn Marino        quotearg_colon:
21595b7b453SJohn Marino        "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a\\:b)"
21695b7b453SJohn Marino 
21795b7b453SJohn Marino        left_quote = ":" and right_quote = " "
21895b7b453SJohn Marino        quotearg_buffer:
21995b7b453SJohn Marino        ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a:b "
22095b7b453SJohn Marino        quotearg:
22195b7b453SJohn Marino        ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a:b "
22295b7b453SJohn Marino        quotearg_colon:
22395b7b453SJohn Marino        ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a\\:b "
22495b7b453SJohn Marino 
22595b7b453SJohn Marino        left_quote = "\"'" and right_quote = "'\""
22695b7b453SJohn Marino        Notice that this is treated as a single level of quotes or two
22795b7b453SJohn Marino        levels where the outer quote need not be escaped within the inner
22895b7b453SJohn Marino        quotes.  For two levels where the outer quote must be escaped
22995b7b453SJohn Marino        within the inner quotes, you must use separate quotearg
23095b7b453SJohn Marino        invocations.
23195b7b453SJohn Marino        quotearg_buffer:
23295b7b453SJohn Marino        "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a:b'\""
23395b7b453SJohn Marino        quotearg:
23495b7b453SJohn Marino        "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a:b'\""
23595b7b453SJohn Marino        quotearg_colon:
23695b7b453SJohn Marino        "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a\\:b'\""
23795b7b453SJohn Marino     */
23895b7b453SJohn Marino     custom_quoting_style
23995b7b453SJohn Marino   };
24095b7b453SJohn Marino 
24195b7b453SJohn Marino /* Flags for use in set_quoting_flags.  */
24295b7b453SJohn Marino enum quoting_flags
24395b7b453SJohn Marino   {
24495b7b453SJohn Marino     /* Always elide null bytes from styles that do not quote them,
24595b7b453SJohn Marino        even when the length of the result is available to the
24695b7b453SJohn Marino        caller.  */
24795b7b453SJohn Marino     QA_ELIDE_NULL_BYTES = 0x01,
24895b7b453SJohn Marino 
24995b7b453SJohn Marino     /* Omit the surrounding quote characters if no escaped characters
25095b7b453SJohn Marino        are encountered.  Note that if no other character needs
25195b7b453SJohn Marino        escaping, then neither does the escape character.  */
25295b7b453SJohn Marino     QA_ELIDE_OUTER_QUOTES = 0x02,
25395b7b453SJohn Marino 
25495b7b453SJohn Marino     /* In the c_quoting_style and c_maybe_quoting_style, split ANSI
25595b7b453SJohn Marino        trigraph sequences into concatenated strings (for example,
25695b7b453SJohn Marino        "?""?/" rather than "??/", which could be confused with
25795b7b453SJohn Marino        "\\").  */
25895b7b453SJohn Marino     QA_SPLIT_TRIGRAPHS = 0x04
25995b7b453SJohn Marino   };
26095b7b453SJohn Marino 
26195b7b453SJohn Marino /* For now, --quoting-style=literal is the default, but this may change.  */
26295b7b453SJohn Marino # ifndef DEFAULT_QUOTING_STYLE
26395b7b453SJohn Marino #  define DEFAULT_QUOTING_STYLE literal_quoting_style
26495b7b453SJohn Marino # endif
26595b7b453SJohn Marino 
26695b7b453SJohn Marino /* Names of quoting styles and their corresponding values.  */
26795b7b453SJohn Marino extern char const *const quoting_style_args[];
26895b7b453SJohn Marino extern enum quoting_style const quoting_style_vals[];
26995b7b453SJohn Marino 
27095b7b453SJohn Marino struct quoting_options;
27195b7b453SJohn Marino 
27295b7b453SJohn Marino /* The functions listed below set and use a hidden variable
27395b7b453SJohn Marino    that contains the default quoting style options.  */
27495b7b453SJohn Marino 
27595b7b453SJohn Marino /* Allocate a new set of quoting options, with contents initially identical
27695b7b453SJohn Marino    to O if O is not null, or to the default if O is null.
27795b7b453SJohn Marino    It is the caller's responsibility to free the result.  */
27895b7b453SJohn Marino struct quoting_options *clone_quoting_options (struct quoting_options *o);
27995b7b453SJohn Marino 
28095b7b453SJohn Marino /* Get the value of O's quoting style.  If O is null, use the default.  */
281*09d4459fSDaniel Fojt enum quoting_style get_quoting_style (struct quoting_options const *o);
28295b7b453SJohn Marino 
28395b7b453SJohn Marino /* In O (or in the default if O is null),
28495b7b453SJohn Marino    set the value of the quoting style to S.  */
28595b7b453SJohn Marino void set_quoting_style (struct quoting_options *o, enum quoting_style s);
28695b7b453SJohn Marino 
28795b7b453SJohn Marino /* In O (or in the default if O is null),
28895b7b453SJohn Marino    set the value of the quoting options for character C to I.
28995b7b453SJohn Marino    Return the old value.  Currently, the only values defined for I are
29095b7b453SJohn Marino    0 (the default) and 1 (which means to quote the character even if
29195b7b453SJohn Marino    it would not otherwise be quoted).  C must never be a digit or a
29295b7b453SJohn Marino    letter that has special meaning after a backslash (for example, "\t"
29395b7b453SJohn Marino    for tab).  */
29495b7b453SJohn Marino int set_char_quoting (struct quoting_options *o, char c, int i);
29595b7b453SJohn Marino 
29695b7b453SJohn Marino /* In O (or in the default if O is null),
29795b7b453SJohn Marino    set the value of the quoting options flag to I, which can be a
29895b7b453SJohn Marino    bitwise combination of enum quoting_flags, or 0 for default
29995b7b453SJohn Marino    behavior.  Return the old value.  */
30095b7b453SJohn Marino int set_quoting_flags (struct quoting_options *o, int i);
30195b7b453SJohn Marino 
30295b7b453SJohn Marino /* In O (or in the default if O is null),
30395b7b453SJohn Marino    set the value of the quoting style to custom_quoting_style,
30495b7b453SJohn Marino    set the left quote to LEFT_QUOTE, and set the right quote to
30595b7b453SJohn Marino    RIGHT_QUOTE.  Each of LEFT_QUOTE and RIGHT_QUOTE must be
30695b7b453SJohn Marino    null-terminated and can be the empty string.  Because backslashes are
30795b7b453SJohn Marino    used for escaping, it does not make sense for RIGHT_QUOTE to contain
30895b7b453SJohn Marino    a backslash.  RIGHT_QUOTE must not begin with a digit or a letter
30995b7b453SJohn Marino    that has special meaning after a backslash (for example, "\t" for
31095b7b453SJohn Marino    tab).  */
31195b7b453SJohn Marino void set_custom_quoting (struct quoting_options *o,
31295b7b453SJohn Marino                          char const *left_quote,
31395b7b453SJohn Marino                          char const *right_quote);
31495b7b453SJohn Marino 
31595b7b453SJohn Marino /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
31695b7b453SJohn Marino    argument ARG (of size ARGSIZE), using O to control quoting.
31795b7b453SJohn Marino    If O is null, use the default.
31895b7b453SJohn Marino    Terminate the output with a null character, and return the written
31995b7b453SJohn Marino    size of the output, not counting the terminating null.
32095b7b453SJohn Marino    If BUFFERSIZE is too small to store the output string, return the
32195b7b453SJohn Marino    value that would have been returned had BUFFERSIZE been large enough.
32295b7b453SJohn Marino    If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
32395b7b453SJohn Marino    On output, BUFFER might contain embedded null bytes if ARGSIZE was
32495b7b453SJohn Marino    not -1, the style of O does not use backslash escapes, and the
32595b7b453SJohn Marino    flags of O do not request elision of null bytes.*/
32695b7b453SJohn Marino size_t quotearg_buffer (char *buffer, size_t buffersize,
32795b7b453SJohn Marino                         char const *arg, size_t argsize,
32895b7b453SJohn Marino                         struct quoting_options const *o);
32995b7b453SJohn Marino 
33095b7b453SJohn Marino /* Like quotearg_buffer, except return the result in a newly allocated
33195b7b453SJohn Marino    buffer.  It is the caller's responsibility to free the result.  The
33295b7b453SJohn Marino    result will not contain embedded null bytes.  */
33395b7b453SJohn Marino char *quotearg_alloc (char const *arg, size_t argsize,
33495b7b453SJohn Marino                       struct quoting_options const *o);
33595b7b453SJohn Marino 
33695b7b453SJohn Marino /* Like quotearg_alloc, except that the length of the result,
33795b7b453SJohn Marino    excluding the terminating null byte, is stored into SIZE if it is
33895b7b453SJohn Marino    non-NULL.  The result might contain embedded null bytes if ARGSIZE
33995b7b453SJohn Marino    was not -1, SIZE was not NULL, the style of O does not use
34095b7b453SJohn Marino    backslash escapes, and the flags of O do not request elision of
34195b7b453SJohn Marino    null bytes.*/
34295b7b453SJohn Marino char *quotearg_alloc_mem (char const *arg, size_t argsize,
34395b7b453SJohn Marino                           size_t *size, struct quoting_options const *o);
34495b7b453SJohn Marino 
34595b7b453SJohn Marino /* Use storage slot N to return a quoted version of the string ARG.
34695b7b453SJohn Marino    Use the default quoting options.
34795b7b453SJohn Marino    The returned value points to static storage that can be
34895b7b453SJohn Marino    reused by the next call to this function with the same value of N.
34995b7b453SJohn Marino    N must be nonnegative.  The output of all functions in the
35095b7b453SJohn Marino    quotearg_n family are guaranteed to not contain embedded null
35195b7b453SJohn Marino    bytes.*/
35295b7b453SJohn Marino char *quotearg_n (int n, char const *arg);
35395b7b453SJohn Marino 
35495b7b453SJohn Marino /* Equivalent to quotearg_n (0, ARG).  */
35595b7b453SJohn Marino char *quotearg (char const *arg);
35695b7b453SJohn Marino 
35795b7b453SJohn Marino /* Use storage slot N to return a quoted version of the argument ARG
35895b7b453SJohn Marino    of size ARGSIZE.  This is like quotearg_n (N, ARG), except it can
35995b7b453SJohn Marino    quote null bytes.  */
36095b7b453SJohn Marino char *quotearg_n_mem (int n, char const *arg, size_t argsize);
36195b7b453SJohn Marino 
36295b7b453SJohn Marino /* Equivalent to quotearg_n_mem (0, ARG, ARGSIZE).  */
36395b7b453SJohn Marino char *quotearg_mem (char const *arg, size_t argsize);
36495b7b453SJohn Marino 
36595b7b453SJohn Marino /* Use style S and storage slot N to return a quoted version of the string ARG.
36695b7b453SJohn Marino    This is like quotearg_n (N, ARG), except that it uses S with no other
36795b7b453SJohn Marino    options to specify the quoting method.  */
36895b7b453SJohn Marino char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
36995b7b453SJohn Marino 
37095b7b453SJohn Marino /* Use style S and storage slot N to return a quoted version of the
37195b7b453SJohn Marino    argument ARG of size ARGSIZE.  This is like quotearg_n_style
37295b7b453SJohn Marino    (N, S, ARG), except it can quote null bytes.  */
37395b7b453SJohn Marino char *quotearg_n_style_mem (int n, enum quoting_style s,
37495b7b453SJohn Marino                             char const *arg, size_t argsize);
37595b7b453SJohn Marino 
37695b7b453SJohn Marino /* Equivalent to quotearg_n_style (0, S, ARG).  */
37795b7b453SJohn Marino char *quotearg_style (enum quoting_style s, char const *arg);
37895b7b453SJohn Marino 
37995b7b453SJohn Marino /* Equivalent to quotearg_n_style_mem (0, S, ARG, ARGSIZE).  */
38095b7b453SJohn Marino char *quotearg_style_mem (enum quoting_style s,
38195b7b453SJohn Marino                           char const *arg, size_t argsize);
38295b7b453SJohn Marino 
38395b7b453SJohn Marino /* Like quotearg (ARG), except also quote any instances of CH.
38495b7b453SJohn Marino    See set_char_quoting for a description of acceptable CH values.  */
38595b7b453SJohn Marino char *quotearg_char (char const *arg, char ch);
38695b7b453SJohn Marino 
38795b7b453SJohn Marino /* Like quotearg_char (ARG, CH), except it can quote null bytes.  */
38895b7b453SJohn Marino char *quotearg_char_mem (char const *arg, size_t argsize, char ch);
38995b7b453SJohn Marino 
39095b7b453SJohn Marino /* Equivalent to quotearg_char (ARG, ':').  */
39195b7b453SJohn Marino char *quotearg_colon (char const *arg);
39295b7b453SJohn Marino 
39395b7b453SJohn Marino /* Like quotearg_colon (ARG), except it can quote null bytes.  */
39495b7b453SJohn Marino char *quotearg_colon_mem (char const *arg, size_t argsize);
39595b7b453SJohn Marino 
396*09d4459fSDaniel Fojt /* Like quotearg_n_style, except with ':' quoting enabled.  */
397*09d4459fSDaniel Fojt char *quotearg_n_style_colon (int n, enum quoting_style s, char const *arg);
398*09d4459fSDaniel Fojt 
39995b7b453SJohn Marino /* Like quotearg_n_style (N, S, ARG) but with S as custom_quoting_style
40095b7b453SJohn Marino    with left quote as LEFT_QUOTE and right quote as RIGHT_QUOTE.  See
40195b7b453SJohn Marino    set_custom_quoting for a description of acceptable LEFT_QUOTE and
40295b7b453SJohn Marino    RIGHT_QUOTE values.  */
40395b7b453SJohn Marino char *quotearg_n_custom (int n, char const *left_quote,
40495b7b453SJohn Marino                          char const *right_quote, char const *arg);
40595b7b453SJohn Marino 
40695b7b453SJohn Marino /* Like quotearg_n_custom (N, LEFT_QUOTE, RIGHT_QUOTE, ARG) except it
40795b7b453SJohn Marino    can quote null bytes.  */
40895b7b453SJohn Marino char *quotearg_n_custom_mem (int n, char const *left_quote,
40995b7b453SJohn Marino                              char const *right_quote,
41095b7b453SJohn Marino                              char const *arg, size_t argsize);
41195b7b453SJohn Marino 
41295b7b453SJohn Marino /* Equivalent to quotearg_n_custom (0, LEFT_QUOTE, RIGHT_QUOTE, ARG).  */
41395b7b453SJohn Marino char *quotearg_custom (char const *left_quote, char const *right_quote,
41495b7b453SJohn Marino                        char const *arg);
41595b7b453SJohn Marino 
41695b7b453SJohn Marino /* Equivalent to quotearg_n_custom_mem (0, LEFT_QUOTE, RIGHT_QUOTE, ARG,
41795b7b453SJohn Marino                                         ARGSIZE).  */
41895b7b453SJohn Marino char *quotearg_custom_mem (char const *left_quote,
41995b7b453SJohn Marino                            char const *right_quote,
42095b7b453SJohn Marino                            char const *arg, size_t argsize);
42195b7b453SJohn Marino 
42295b7b453SJohn Marino /* Free any dynamically allocated memory.  */
42395b7b453SJohn Marino void quotearg_free (void);
42495b7b453SJohn Marino 
42595b7b453SJohn Marino #endif /* !QUOTEARG_H_ */
426