1131554Stjr/* quotearg.h - quote arguments for output
2131554Stjr   Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
3131554Stjr
4131554Stjr   This program is free software; you can redistribute it and/or modify
5131554Stjr   it under the terms of the GNU General Public License as published by
6131554Stjr   the Free Software Foundation; either version 2, or (at your option)
7131554Stjr   any later version.
8131554Stjr
9131554Stjr   This program is distributed in the hope that it will be useful,
10131554Stjr   but WITHOUT ANY WARRANTY; without even the implied warranty of
11131554Stjr   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12131554Stjr   GNU General Public License for more details.
13131554Stjr
14131554Stjr   You should have received a copy of the GNU General Public License
15131554Stjr   along with this program; if not, write to the Free Software Foundation,
16131554Stjr   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17131554Stjr
18131554Stjr/* Written by Paul Eggert <eggert@twinsun.com> */
19131554Stjr
20131554Stjr/* Basic quoting styles.  */
21131554Stjrenum quoting_style
22131554Stjr  {
23131554Stjr    literal_quoting_style,	/* --quoting-style=literal */
24131554Stjr    shell_quoting_style,	/* --quoting-style=shell */
25131554Stjr    shell_always_quoting_style,	/* --quoting-style=shell-always */
26131554Stjr    c_quoting_style,		/* --quoting-style=c */
27131554Stjr    escape_quoting_style,	/* --quoting-style=escape */
28131554Stjr    locale_quoting_style,	/* --quoting-style=locale */
29131554Stjr    clocale_quoting_style	/* --quoting-style=clocale */
30131554Stjr  };
31131554Stjr
32131554Stjr/* For now, --quoting-style=literal is the default, but this may change.  */
33131554Stjr#ifndef DEFAULT_QUOTING_STYLE
34131554Stjr# define DEFAULT_QUOTING_STYLE literal_quoting_style
35131554Stjr#endif
36131554Stjr
37131554Stjr/* Names of quoting styles and their corresponding values.  */
38131554Stjrextern char const *const quoting_style_args[];
39131554Stjrextern enum quoting_style const quoting_style_vals[];
40131554Stjr
41131554Stjrstruct quoting_options;
42131554Stjr
43131554Stjr#ifndef PARAMS
44131554Stjr# if defined PROTOTYPES || defined __STDC__
45131554Stjr#  define PARAMS(Args) Args
46131554Stjr# else
47131554Stjr#  define PARAMS(Args) ()
48131554Stjr# endif
49131554Stjr#endif
50131554Stjr
51131554Stjr/* The functions listed below set and use a hidden variable
52131554Stjr   that contains the default quoting style options.  */
53131554Stjr
54131554Stjr/* Allocate a new set of quoting options, with contents initially identical
55131554Stjr   to O if O is not null, or to the default if O is null.
56131554Stjr   It is the caller's responsibility to free the result.  */
57131554Stjrstruct quoting_options *clone_quoting_options
58131554Stjr   PARAMS ((struct quoting_options *o));
59131554Stjr
60131554Stjr/* Get the value of O's quoting style.  If O is null, use the default.  */
61131554Stjrenum quoting_style get_quoting_style PARAMS ((struct quoting_options *o));
62131554Stjr
63131554Stjr/* In O (or in the default if O is null),
64131554Stjr   set the value of the quoting style to S.  */
65131554Stjrvoid set_quoting_style PARAMS ((struct quoting_options *o,
66131554Stjr				enum quoting_style s));
67131554Stjr
68131554Stjr/* In O (or in the default if O is null),
69131554Stjr   set the value of the quoting options for character C to I.
70131554Stjr   Return the old value.  Currently, the only values defined for I are
71131554Stjr   0 (the default) and 1 (which means to quote the character even if
72131554Stjr   it would not otherwise be quoted).  */
73131554Stjrint set_char_quoting PARAMS ((struct quoting_options *o, char c, int i));
74131554Stjr
75131554Stjr/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
76131554Stjr   argument ARG (of size ARGSIZE), using O to control quoting.
77131554Stjr   If O is null, use the default.
78131554Stjr   Terminate the output with a null character, and return the written
79131554Stjr   size of the output, not counting the terminating null.
80131554Stjr   If BUFFERSIZE is too small to store the output string, return the
81131554Stjr   value that would have been returned had BUFFERSIZE been large enough.
82131554Stjr   If ARGSIZE is -1, use the string length of the argument for ARGSIZE.  */
83131554Stjrsize_t quotearg_buffer PARAMS ((char *buffer, size_t buffersize,
84131554Stjr				char const *arg, size_t argsize,
85131554Stjr				struct quoting_options const *o));
86131554Stjr
87131554Stjr/* Use storage slot N to return a quoted version of the string ARG.
88131554Stjr   Use the default quoting options.
89131554Stjr   The returned value points to static storage that can be
90131554Stjr   reused by the next call to this function with the same value of N.
91131554Stjr   N must be nonnegative.  */
92131554Stjrchar *quotearg_n PARAMS ((unsigned int n, char const *arg));
93131554Stjr
94131554Stjr/* Equivalent to quotearg_n (0, ARG).  */
95131554Stjrchar *quotearg PARAMS ((char const *arg));
96131554Stjr
97131554Stjr/* Use style S and storage slot N to return a quoted version of the string ARG.
98131554Stjr   This is like quotearg_n (N, ARG), except that it uses S with no other
99131554Stjr   options to specify the quoting method.  */
100131554Stjrchar *quotearg_n_style PARAMS ((unsigned int n, enum quoting_style s,
101131554Stjr				char const *arg));
102131554Stjr
103131554Stjr/* Equivalent to quotearg_n_style (0, S, ARG).  */
104131554Stjrchar *quotearg_style PARAMS ((enum quoting_style s, char const *arg));
105131554Stjr
106131554Stjr/* Like quotearg (ARG), except also quote any instances of CH.  */
107131554Stjrchar *quotearg_char PARAMS ((char const *arg, char ch));
108131554Stjr
109131554Stjr/* Equivalent to quotearg_char (ARG, ':').  */
110131554Stjrchar *quotearg_colon PARAMS ((char const *arg));
111