Initial import of mutt-ng.
[apps/madmutt.git] / pgpewrap.c
1 /*
2  * C version by Wessel Dankers <wsl@fruit.eu.org>
3  *
4  * This code is in the public domain.
5  *
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <string.h>
12
13 int main(int argc, char **argv) {
14         char **opts, **opt, *pfx;
15         int i;
16
17         opts = malloc((2 * argc + 1) * sizeof (* opts));        /* __MEM_CHECKED__ */
18         if(!opts) {
19                 perror(argv[0]);
20                 exit(2);
21         }
22
23         if (argc < 2)
24         {
25           fprintf (stderr,
26                    "Command line usage: %s [flags] -- prefix [recipients]\n",
27                    argv[0]);
28           return 1;
29         }
30
31         opt = opts;
32         *opt++ = argv[1];
33         pfx = NULL;
34
35         for(i = 2; i < argc; ) {
36                 if(!strcmp(argv[i], "--")) {
37                         i += 2;
38                         if(i > argc) {
39                                 fprintf(stderr, "Command line usage: %s [flags] -- prefix [recipients]\n", argv[0]);
40                                 return 1;
41                         }
42                         pfx = argv[i-1];
43                 }
44                 if(pfx)
45                         *opt++ = pfx;
46                 *opt++ = argv[i++];
47         }
48         *opt = NULL;
49
50         execvp(opts[0], opts);
51         perror(argv[0]);
52         return 2;
53 }