1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include "prepargs.h"
- #include <sys/types.h>
- #include <xalloc.h>
- #if HAVE_STRING_H
- # include <string.h>
- #endif
- #include <ctype.h>
- #ifdef STDC_HEADERS
- # define IN_CTYPE_DOMAIN(c) 1
- #else
- # define IN_CTYPE_DOMAIN(c) ((c) <= 0177)
- #endif
- #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
- static int
- prepend_args (char const *options, char *buf, char **argv)
- {
- char const *o = options;
- char *b = buf;
- int n = 0;
- for (;;)
- {
- while (ISSPACE ((unsigned char) *o))
- o++;
- if (!*o)
- return n;
- if (argv)
- argv[n] = b;
- n++;
- do
- if ((*b++ = *o++) == '\\' && *o)
- b[-1] = *o++;
- while (*o && ! ISSPACE ((unsigned char) *o));
- *b++ = '\0';
- }
- }
- void
- prepend_default_options (char const *options, int *pargc, char ***pargv)
- {
- if (options)
- {
- char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) 0);
- int argc = *pargc;
- char * const *argv = *pargv;
- char **pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp);
- *pargc = prepended + argc;
- *pargv = pp;
- *pp++ = *argv++;
- pp += prepend_args (options, buf, pp);
- while ((*pp++ = *argv++))
- continue;
- }
- }
|