1
/* Shell command argument quoting.
2
Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2, or (at your option)
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; see the file COPYING.
16
If not, write to the Free Software Foundation,
17
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
/* Written by Paul Eggert <eggert@twinsun.com> */
25
#include <sys/types.h>
28
/* Place into QUOTED a quoted version of ARG suitable for `system'.
29
Return the length of the resulting string (which is not null-terminated).
30
If QUOTED is null, return the length without any side effects. */
33
quote_system_arg (quoted, arg)
40
/* Scan ARG, copying it to QUOTED if QUOTED is not null,
41
looking for shell metacharacters. */
49
/* ARG has no shell metacharacters. */
56
case '\t': case '\n': case ' ':
57
case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
58
case '(': case ')': case '*': case ';':
59
case '<': case '>': case '?': case '[': case '\\':
60
case '^': case '`': case '|': case '~':
62
/* ARG has a shell metacharacter.
63
Start over, quoting it this time. */
68
/* If ARG is an option, quote just its argument.
69
This is not necessary, but it looks nicer. */
70
if (c == '-' && arg < a)
105
quoted[len + 1] = '\\';
106
quoted[len + 2] = '\'';