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