| 1 | /* quotearg.h - quote arguments for output
|
|---|
| 2 |
|
|---|
| 3 | Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free
|
|---|
| 4 | Software Foundation, Inc.
|
|---|
| 5 |
|
|---|
| 6 | This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 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
|
|---|
| 17 | along with this program; if not, write to the Free Software Foundation,
|
|---|
| 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
|---|
| 19 |
|
|---|
| 20 | /* Written by Paul Eggert <[email protected]> */
|
|---|
| 21 |
|
|---|
| 22 | #ifndef QUOTEARG_H_
|
|---|
| 23 | # define QUOTEARG_H_ 1
|
|---|
| 24 |
|
|---|
| 25 | # include <stddef.h>
|
|---|
| 26 |
|
|---|
| 27 | /* Basic quoting styles. */
|
|---|
| 28 | enum quoting_style
|
|---|
| 29 | {
|
|---|
| 30 | /* Output names as-is (ls --quoting-style=literal). */
|
|---|
| 31 | literal_quoting_style,
|
|---|
| 32 |
|
|---|
| 33 | /* Quote names for the shell if they contain shell metacharacters
|
|---|
| 34 | or would cause ambiguous output (ls --quoting-style=shell). */
|
|---|
| 35 | shell_quoting_style,
|
|---|
| 36 |
|
|---|
| 37 | /* Quote names for the shell, even if they would normally not
|
|---|
| 38 | require quoting (ls --quoting-style=shell-always). */
|
|---|
| 39 | shell_always_quoting_style,
|
|---|
| 40 |
|
|---|
| 41 | /* Quote names as for a C language string (ls --quoting-style=c). */
|
|---|
| 42 | c_quoting_style,
|
|---|
| 43 |
|
|---|
| 44 | /* Like c_quoting_style except omit the surrounding double-quote
|
|---|
| 45 | characters (ls --quoting-style=escape). */
|
|---|
| 46 | escape_quoting_style,
|
|---|
| 47 |
|
|---|
| 48 | /* Like clocale_quoting_style, but quote `like this' instead of
|
|---|
| 49 | "like this" in the default C locale (ls --quoting-style=locale). */
|
|---|
| 50 | locale_quoting_style,
|
|---|
| 51 |
|
|---|
| 52 | /* Like c_quoting_style except use quotation marks appropriate for
|
|---|
| 53 | the locale (ls --quoting-style=clocale). */
|
|---|
| 54 | clocale_quoting_style
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | /* For now, --quoting-style=literal is the default, but this may change. */
|
|---|
| 58 | # ifndef DEFAULT_QUOTING_STYLE
|
|---|
| 59 | # define DEFAULT_QUOTING_STYLE literal_quoting_style
|
|---|
| 60 | # endif
|
|---|
| 61 |
|
|---|
| 62 | /* Names of quoting styles and their corresponding values. */
|
|---|
| 63 | extern char const *const quoting_style_args[];
|
|---|
| 64 | extern enum quoting_style const quoting_style_vals[];
|
|---|
| 65 |
|
|---|
| 66 | struct quoting_options;
|
|---|
| 67 |
|
|---|
| 68 | /* The functions listed below set and use a hidden variable
|
|---|
| 69 | that contains the default quoting style options. */
|
|---|
| 70 |
|
|---|
| 71 | /* Allocate a new set of quoting options, with contents initially identical
|
|---|
| 72 | to O if O is not null, or to the default if O is null.
|
|---|
| 73 | It is the caller's responsibility to free the result. */
|
|---|
| 74 | struct quoting_options *clone_quoting_options (struct quoting_options *o);
|
|---|
| 75 |
|
|---|
| 76 | /* Get the value of O's quoting style. If O is null, use the default. */
|
|---|
| 77 | enum quoting_style get_quoting_style (struct quoting_options *o);
|
|---|
| 78 |
|
|---|
| 79 | /* In O (or in the default if O is null),
|
|---|
| 80 | set the value of the quoting style to S. */
|
|---|
| 81 | void set_quoting_style (struct quoting_options *o, enum quoting_style s);
|
|---|
| 82 |
|
|---|
| 83 | /* In O (or in the default if O is null),
|
|---|
| 84 | set the value of the quoting options for character C to I.
|
|---|
| 85 | Return the old value. Currently, the only values defined for I are
|
|---|
| 86 | 0 (the default) and 1 (which means to quote the character even if
|
|---|
| 87 | it would not otherwise be quoted). */
|
|---|
| 88 | int set_char_quoting (struct quoting_options *o, char c, int i);
|
|---|
| 89 |
|
|---|
| 90 | /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
|---|
| 91 | argument ARG (of size ARGSIZE), using O to control quoting.
|
|---|
| 92 | If O is null, use the default.
|
|---|
| 93 | Terminate the output with a null character, and return the written
|
|---|
| 94 | size of the output, not counting the terminating null.
|
|---|
| 95 | If BUFFERSIZE is too small to store the output string, return the
|
|---|
| 96 | value that would have been returned had BUFFERSIZE been large enough.
|
|---|
| 97 | If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
|
|---|
| 98 | size_t quotearg_buffer (char *buffer, size_t buffersize,
|
|---|
| 99 | char const *arg, size_t argsize,
|
|---|
| 100 | struct quoting_options const *o);
|
|---|
| 101 |
|
|---|
| 102 | /* Like quotearg_buffer, except return the result in a newly allocated
|
|---|
| 103 | buffer. It is the caller's responsibility to free the result. */
|
|---|
| 104 | char *quotearg_alloc (char const *arg, size_t argsize,
|
|---|
| 105 | struct quoting_options const *o);
|
|---|
| 106 |
|
|---|
| 107 | /* Use storage slot N to return a quoted version of the string ARG.
|
|---|
| 108 | Use the default quoting options.
|
|---|
| 109 | The returned value points to static storage that can be
|
|---|
| 110 | reused by the next call to this function with the same value of N.
|
|---|
| 111 | N must be nonnegative. */
|
|---|
| 112 | char *quotearg_n (int n, char const *arg);
|
|---|
| 113 |
|
|---|
| 114 | /* Equivalent to quotearg_n (0, ARG). */
|
|---|
| 115 | char *quotearg (char const *arg);
|
|---|
| 116 |
|
|---|
| 117 | /* Use style S and storage slot N to return a quoted version of the string ARG.
|
|---|
| 118 | This is like quotearg_n (N, ARG), except that it uses S with no other
|
|---|
| 119 | options to specify the quoting method. */
|
|---|
| 120 | char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
|
|---|
| 121 |
|
|---|
| 122 | /* Use style S and storage slot N to return a quoted version of the
|
|---|
| 123 | argument ARG of size ARGSIZE. This is like quotearg_n_style
|
|---|
| 124 | (N, S, ARG), except it can quote null bytes. */
|
|---|
| 125 | char *quotearg_n_style_mem (int n, enum quoting_style s,
|
|---|
| 126 | char const *arg, size_t argsize);
|
|---|
| 127 |
|
|---|
| 128 | /* Equivalent to quotearg_n_style (0, S, ARG). */
|
|---|
| 129 | char *quotearg_style (enum quoting_style s, char const *arg);
|
|---|
| 130 |
|
|---|
| 131 | /* Like quotearg (ARG), except also quote any instances of CH. */
|
|---|
| 132 | char *quotearg_char (char const *arg, char ch);
|
|---|
| 133 |
|
|---|
| 134 | /* Equivalent to quotearg_char (ARG, ':'). */
|
|---|
| 135 | char *quotearg_colon (char const *arg);
|
|---|
| 136 |
|
|---|
| 137 | /* Free any dynamically allocated memory. */
|
|---|
| 138 | void quotearg_free (void);
|
|---|
| 139 |
|
|---|
| 140 | #endif /* !QUOTEARG_H_ */
|
|---|