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