]> diplodocus.org Git - nmh/blob - sbr/getarguments.c
Fix stupid accidental dependence on a bash quirk in previous
[nmh] / sbr / getarguments.c
1
2 /*
3 * getarguments.c -- Get the argument vector ready to go.
4 *
5 * $Id$
6 *
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
10 */
11
12 #include <h/mh.h>
13
14 char **
15 getarguments (char *invo_name, int argc, char **argv, int check_context)
16 {
17 char *cp, **ap, **bp, **arguments;
18 int n = 0;
19
20 /*
21 * Check if profile/context specifies any arguments
22 */
23 if (check_context && (cp = context_find (invo_name))) {
24 cp = getcpy (cp); /* make copy */
25 ap = brkstring (cp, " ", "\n"); /* split string */
26
27 /* Count number of arguments split */
28 bp = ap;
29 while (*bp++)
30 n++;
31 }
32
33 if (!(arguments = (char **) malloc ((argc + n) * sizeof(*arguments))))
34 adios (NULL, "unable to malloc argument storage");
35 bp = arguments;
36
37 /* Copy any arguments from profile/context */
38 if (n > 0) {
39 while (*ap)
40 *bp++ = *ap++;
41 }
42
43 /* Copy arguments from command line */
44 argv++;
45 while (*argv)
46 *bp++ = *argv++;
47
48 /* Now NULL terminate the array */
49 *bp = NULL;
50
51 return arguments;
52 }