2 Copyright (C) 2001-2004 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 /* Describes quoting for sh compatible shells. */
32 static struct quoting_options
*sh_quoting_options
;
34 /* Initializes the sh_quoting_options variable. */
36 init_sh_quoting_options ()
38 sh_quoting_options
= clone_quoting_options (NULL
);
39 set_quoting_style (sh_quoting_options
, shell_quoting_style
);
42 /* Returns the number of bytes needed for the quoted string. */
44 shell_quote_length (const char *string
)
46 if (sh_quoting_options
== NULL
)
47 init_sh_quoting_options ();
48 return quotearg_buffer (NULL
, 0, string
, strlen (string
),
52 /* Copies the quoted string to p and returns the incremented p.
53 There must be room for shell_quote_length (string) + 1 bytes at p. */
55 shell_quote_copy (char *p
, const char *string
)
57 if (sh_quoting_options
== NULL
)
58 init_sh_quoting_options ();
59 return p
+ quotearg_buffer (p
, (size_t)(-1), string
, strlen (string
),
63 /* Returns the freshly allocated quoted string. */
65 shell_quote (const char *string
)
67 if (sh_quoting_options
== NULL
)
68 init_sh_quoting_options ();
69 return quotearg_alloc (string
, strlen (string
), sh_quoting_options
);
72 /* Returns a freshly allocated string containing all argument strings, quoted,
73 separated through spaces. */
75 shell_quote_argv (char **argv
)
87 length
+= shell_quote_length (*argp
) + 1;
93 command
= (char *) xmalloc (length
);
98 p
= shell_quote_copy (p
, *argp
);