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