]> diplodocus.org Git - nmh/blob - sbr/getarguments.c
sendsbr.c: Move interface to own file.
[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 "getarguments.h"
10 #include "context_find.h"
11 #include "brkstring.h"
12 #include "h/utils.h"
13
14 char **
15 getarguments (char *invo_name, int argc, char **argv, int check_context)
16 {
17 char *cp = NULL, **ap = NULL, **bp = NULL, **arguments = NULL;
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 = mh_xstrdup(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 arguments = mh_xmalloc ((argc + n) * sizeof(*arguments));
34 bp = arguments;
35
36 /* Copy any arguments from profile/context */
37 if (ap != NULL && n > 0) {
38 while (*ap)
39 *bp++ = *ap++;
40 }
41
42 /* Copy arguments from command line */
43 argv++;
44 while (*argv)
45 *bp++ = *argv++;
46
47 /* Now NULL terminate the array */
48 *bp = NULL;
49
50 return arguments;
51 }