]>
Dogcows Code - chaz/tar/blob - lib/prepargs.c
d8ca5d0bf36fd46790bf1b4a1cf720448ce39b8f
1 /* Parse arguments from a string and prepend them to an argv.
2 Copyright 1999, 2000 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 /* Written by Paul Eggert <eggert@twinsun.com>. */
25 #include <sys/types.h>
30 /* IN_CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
31 as an argument to <ctype.h> macros like "isspace". */
33 # define IN_CTYPE_DOMAIN(c) 1
35 # define IN_CTYPE_DOMAIN(c) ((c) <= 0177)
38 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
40 /* Find the white-space-separated options specified by OPTIONS, and
41 using BUF to store copies of these options, set ARGV[0], ARGV[1],
42 etc. to the option copies. Return the number N of options found.
43 Do not set ARGV[N]. If ARGV is null, do not store ARGV[0]
44 etc. Backslash can be used to escape whitespace (and backslashes). */
46 prepend_args (char const *options
, char *buf
, char **argv
)
48 char const *o
= options
;
54 while (ISSPACE ((unsigned char) *o
))
63 if ((*b
++ = *o
++) == '\\' && *o
)
65 while (*o
&& ! ISSPACE ((unsigned char) *o
));
71 /* Prepend the whitespace-separated options in OPTIONS to the argument
72 vector of a main program with argument count *PARGC and argument
75 prepend_default_options (char const *options
, int *pargc
, char ***pargv
)
79 char *buf
= xmalloc (strlen (options
) + 1);
80 int prepended
= prepend_args (options
, buf
, (char **) 0);
82 char * const *argv
= *pargv
;
83 char **pp
= (char **) xmalloc ((prepended
+ argc
+ 1) * sizeof *pp
);
84 *pargc
= prepended
+ argc
;
87 pp
+= prepend_args (options
, buf
, pp
);
88 while ((*pp
++ = *argv
++))
This page took 0.040591 seconds and 4 git commands to generate.