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
19 /* $FreeBSD: src/gnu/usr.bin/cvs/cvs/prepend_args.c,v 1.3.2.2 2002/12/19 21:18:01 peter Exp $ */
20 /* $DragonFly: src/gnu/usr.bin/cvs/cvs/prepend_args.c,v 1.2 2003/06/17 04:25:45 dillon Exp $ */
27 #include "prepend_args.h"
30 /* Find the white-space-separated options specified by OPTIONS, and
31 using BUF to store copies of these options, set ARGV[0], ARGV[1],
32 etc. to the option copies. Return the number N of options found.
33 Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
34 etc. Backslash can be used to escape whitespace (and backslashes). */
36 prepend_args (options, buf, argv)
41 char const *o = options;
47 while (isspace ((unsigned char) *o))
56 if ((*b++ = *o++) == '\\' && *o)
58 while (*o && ! isspace ((unsigned char) *o));
64 /* Prepend the whitespace-separated options in OPTIONS to the argument
65 vector of a main program with argument count *PARGC and argument
68 prepend_default_options (options, pargc, pargv)
75 char *buf = xmalloc (strlen (options) + 1);
76 int prepended = prepend_args (options, buf, (char **) NULL);
78 char * const *argv = *pargv;
79 char **pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp);
80 *pargc = prepended + argc;
83 pp += prepend_args (options, buf, pp);
84 while ((*pp++ = *argv++))