]> git.llucax.com Git - software/mutt-debian.git/blob - pgpewrap.c
Move Mutt with NNTP support to mutt-nntp package
[software/mutt-debian.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 #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
16 void print_usage(const char *progname) {
17         fprintf(stderr, "Command line usage: %s [flags] -- prefix [recipients]\n", progname);
18         exit(1);
19 }
20
21 int main(int argc, char **argv) {
22         char **opts, **opt, *pfx;
23         int i;
24
25         if (argc <= 1) {
26                 print_usage(argv[0]);
27         }
28
29         opts = malloc((2 * argc + 1) * sizeof (* opts));        /* __MEM_CHECKED__ */
30         if(!opts) {
31                 perror(argv[0]);
32                 exit(2);
33         }
34
35         if (argc < 2)
36         {
37           fprintf (stderr,
38                    "Command line usage: %s [flags] -- prefix [recipients]\n",
39                    argv[0]);
40           return 1;
41         }
42
43         opt = opts;
44         *opt++ = argv[1];
45         pfx = NULL;
46
47         for(i = 2; i < argc; ) {
48                 if(!strcmp(argv[i], "--")) {
49                         i += 2;
50                         if(i > argc) {
51                                 print_usage(argv[0]);
52                         }
53                         pfx = argv[i-1];
54                 }
55                 if(pfx)
56                         *opt++ = pfx;
57                 *opt++ = argv[i++];
58         }
59         *opt = NULL;
60
61         execvp(opts[0], opts);
62         perror(argv[0]);
63         return 2;
64 }