1 /* prepend_args.c - utilility programs for manpiulating argv[]
2 Copyright (C) 1999 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; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "prepend_args.h"
29 /* Find the white-space-separated options specified by OPTIONS, and
30 using BUF to store copies of these options, set ARGV[0], ARGV[1],
31 etc. to the option copies. Return the number N of options found.
32 Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
33 etc. Backslash can be used to escape whitespace (and backslashes). */
35 prepend_args (options, buf, argv)
40 char const *o = options;
46 while (ISSPACE ((unsigned char) *o))
55 if ((*b++ = *o++) == '\\' && *o)
57 while (*o && ! ISSPACE ((unsigned char) *o));
63 /* Prepend the whitespace-separated options in OPTIONS to the argument
64 vector of a main program with argument count *PARGC and argument
67 prepend_default_options (options, pargc, pargv)
74 char *buf = xmalloc (strlen (options) + 1);
75 int prepended = prepend_args (options, buf, (char **) NULL);
77 char * const *argv = *pargv;
78 char **pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp);
79 *pargc = prepended + argc;
82 pp += prepend_args (options, buf, pp);
83 while ((*pp++ = *argv++))