3 /* Shell command argument quoting.
4 Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
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)
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING.
18 If not, write to the Free Software Foundation,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Written by Paul Eggert <eggert@twinsun.com> */
27 #include <sys/types.h>
30 /* Place into QUOTED a quoted version of ARG suitable for `system'.
31 Return the length of the resulting string (which is not null-terminated).
32 If QUOTED is null, return the length without any side effects. */
35 quote_system_arg (quoted
, arg
)
42 /* Scan ARG, copying it to QUOTED if QUOTED is not null,
43 looking for shell metacharacters. */
51 /* ARG has no shell metacharacters. */
58 case '\t': case '\n': case ' ':
59 case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
60 case '(': case ')': case '*': case ';':
61 case '<': case '>': case '?': case '[': case '\\':
62 case '^': case '`': case '|': case '~':
64 /* ARG has a shell metacharacter.
65 Start over, quoting it this time. */
70 /* If ARG is an option, quote just its argument.
71 This is not necessary, but it looks nicer. */
72 if (c
== '-' && arg
< a
)
100 for (; c
; c
= *arg
++)
107 quoted
[len
+ 1] = '\\';
108 quoted
[len
+ 2] = '\'';