parse_format_string(): Explicitly set the result pointer to NULL on errors.
[adu.git] / adu.c
diff --git a/adu.c b/adu.c
index ee4dddb972727540efe3e95b5208226178255dbb..8ce7317cdd207719f924523a0d7aa5ca32fcf288 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -1,6 +1,8 @@
 #include "adu.h"
 #include <dirent.h> /* readdir() */
 #include <pwd.h>
+#include "format.h"
+#include "select.h"
 
 #include "gcc-compat.h"
 #include "cmdline.h"
@@ -466,18 +468,55 @@ static int check_args(void)
        return 1;
 }
 
+static int print_complete_help_and_die(void)
+{
+       const char **line;
+       select_cmdline_parser_init(&select_conf);
+
+       if (conf.help_given)
+               line = gengetopt_args_info_help;
+       else
+               line = gengetopt_args_info_detailed_help;
+
+       printf("adu command line options:\n");
+       printf("=========================\n");
+       for (; *line; line++)
+               printf("%s\n", *line);
+       if (conf.help_given)
+               line = select_args_info_help;
+       else
+               line  = select_args_info_detailed_help;
+       printf("select options:\n");
+       printf("===============\n");
+       for (; *line; line++)
+               printf("%s\n", *line);
+       printf("interactive commands:\n");
+       printf("=====================\n");
+       print_interactive_help();
+       exit(EXIT_FAILURE);
+}
+
 int main(int argc, char **argv)
 {
        int ret;
        struct cmdline_parser_params params = {
                .override = 0,
                .initialize = 1,
-               .check_required = 1,
-               .check_ambiguity = 1,
-               .print_errors = 1
+               .check_required = 0,
+               .check_ambiguity = 0,
+               .print_errors = 0
        };
+       /* ignore errors and print complete help if --help was given */
+       cmdline_parser_ext(argc, argv, &conf, &params);
+       if (conf.help_given || conf.detailed_help_given)
+               print_complete_help_and_die();
+       params.check_required = 1;
+       params.check_ambiguity = 1;
+       params.print_errors = 1;
+       ret = cmdline_parser_ext(argc, argv, &conf, &params);
+       if (ret)
+               exit(EXIT_FAILURE);
 
-       cmdline_parser_ext(argc, argv, &conf, &params); /* aborts on errors */
        ret = check_args();
        if (ret < 0)
                goto out;