mutt stable branch with some hacks
1/*
2 * C version by Wessel Dankers <wsl@fruit.eu.org>
3 *
4 * This code is in the public domain.
5 *
6 */
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <string.h>
15
16void print_usage(const char *progname)
17{
18 fprintf(stderr, "Command line usage: %s [flags] -- prefix [recipients]\n", progname);
19 exit(1);
20}
21
22int main(int argc, char **argv)
23{
24 char **opts, **opt, *pfx;
25 int i;
26
27 if (argc <= 1)
28 {
29 print_usage(argv[0]);
30 }
31
32 opts = malloc((2 * argc + 1) * sizeof (* opts)); /* __MEM_CHECKED__ */
33 if (!opts)
34 {
35 perror(argv[0]);
36 exit(2);
37 }
38
39 if (argc < 2)
40 {
41 fprintf (stderr,
42 "Command line usage: %s [flags] -- prefix [recipients]\n",
43 argv[0]);
44 return 1;
45 }
46
47 opt = opts;
48 *opt++ = argv[1];
49 pfx = NULL;
50
51 for (i = 2; i < argc; )
52 {
53 if (!strcmp(argv[i], "--"))
54 {
55 i += 2;
56 if (i > argc)
57 {
58 print_usage(argv[0]);
59 }
60 pfx = argv[i-1];
61 }
62 if (pfx)
63 *opt++ = pfx;
64 *opt++ = argv[i++];
65 }
66 *opt = NULL;
67
68 execvp(opts[0], opts);
69 perror(argv[0]);
70 return 2;
71}