X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=pgpewrap.c;h=b3a84c01d9c8c9832739deccd97c701b6f697af8;hp=d88948382aa64088a25d0cf3aba442009c554c4c;hb=3db1eed8cb47ae930ec78a1dc6576f608363da85;hpb=6833ce8bdca2d64e14485118f2a4417b7e1cb1b1 diff --git a/pgpewrap.c b/pgpewrap.c index d889483..b3a84c0 100644 --- a/pgpewrap.c +++ b/pgpewrap.c @@ -10,44 +10,54 @@ #include #include -int main(int argc, char **argv) { - char **opts, **opt, *pfx; - int i; - - opts = malloc((2 * argc + 1) * sizeof (* opts)); /* __MEM_CHECKED__ */ - if(!opts) { - perror(argv[0]); - exit(2); - } - - if (argc < 2) - { - fprintf (stderr, - "Command line usage: %s [flags] -- prefix [recipients]\n", - argv[0]); - return 1; - } - - opt = opts; - *opt++ = argv[1]; - pfx = NULL; - - for(i = 2; i < argc; ) { - if(!strcmp(argv[i], "--")) { - i += 2; - if(i > argc) { - fprintf(stderr, "Command line usage: %s [flags] -- prefix [recipients]\n", argv[0]); - return 1; - } - pfx = argv[i-1]; - } - if(pfx) - *opt++ = pfx; - *opt++ = argv[i++]; - } - *opt = NULL; - - execvp(opts[0], opts); - perror(argv[0]); - return 2; +void print_usage (const char *progname) +{ + fprintf (stderr, "Command line usage: %s [flags] -- prefix [recipients]\n", + progname); + exit (1); +} + +int main (int argc, char **argv) +{ + char **opts, **opt, *pfx; + int i; + + if (argc <= 1) { + print_usage (argv[0]); + } + + opts = malloc ((2 * argc + 1) * sizeof (*opts)); /* __MEM_CHECKED__ */ + if (!opts) { + perror (argv[0]); + exit (2); + } + + if (argc < 2) { + fprintf (stderr, + "Command line usage: %s [flags] -- prefix [recipients]\n", + argv[0]); + return 1; + } + + opt = opts; + *opt++ = argv[1]; + pfx = NULL; + + for (i = 2; i < argc;) { + if (!strcmp (argv[i], "--")) { + i += 2; + if (i > argc) { + print_usage (argv[0]); + } + pfx = argv[i - 1]; + } + if (pfx) + *opt++ = pfx; + *opt++ = argv[i++]; + } + *opt = NULL; + + execvp (opts[0], opts); + perror (argv[0]); + return 2; }