>From de1ce0b365d037906dedf970a47a4bcfffd1cbd2 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Fri, 6 Jul 2012 18:15:25 +0200 Subject: [PATCH] Add --help option to john (prints usage summary) --- src/john.c | 14 ++++++++++++-- src/options.c | 4 ++-- src/options.h | 2 +- src/recovery.c | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/john.c b/src/john.c index 80440b8..fa74789 100644 --- a/src/john.c +++ b/src/john.c @@ -548,6 +548,7 @@ static void john_list_method_names() static void john_init(char *name, int argc, char **argv) { + int show_usage = 0; int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; @@ -555,9 +556,16 @@ static void john_init(char *name, int argc, char **argv) CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); - if (argc < 2) + if (argc < 2 || + (argc == 2 && + (!strcasecmp(argv[1], "--help") || + !strcasecmp(argv[1], "-h") || + !strcasecmp(argv[1], "-help")))) + { john_register_all(); /* for printing by opt_init() */ - opt_init(name, argc, argv); + show_usage = 1; + } + opt_init(name, argc, argv, show_usage); /* * --list=? needs to be supported, because it has been supported in the released @@ -594,6 +602,8 @@ static void john_init(char *name, int argc, char **argv) } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { + puts("--help print usage summary, just like running the command"); + puts(" without any parameters"); puts("--subformat=FORMAT pick a benchmark format for --format=crypt"); puts("--mkpc=N force a lower max. keys per crypt"); puts("--length=N force a lower max. length"); diff --git a/src/options.c b/src/options.c index 13a81d9..624d83c 100644 --- a/src/options.c +++ b/src/options.c @@ -284,9 +284,9 @@ static void print_usage(char *name) exit(0); } -void opt_init(char *name, int argc, char **argv) +void opt_init(char *name, int argc, char **argv, int show_usage) { - if (argc < 2) + if (show_usage) print_usage(name); memset(&options, 0, sizeof(options)); diff --git a/src/options.h b/src/options.h index c9d0b73..1adf359 100644 --- a/src/options.h +++ b/src/options.h @@ -218,6 +218,6 @@ extern struct options_main options; /* * Initializes the options structure. */ -extern void opt_init(char *name, int argc, char **argv); +extern void opt_init(char *name, int argc, char **argv, int show_usage); #endif diff --git a/src/recovery.c b/src/recovery.c index 1cf77d2..4898731 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -264,7 +264,7 @@ void rec_restore_args(int lock) argv[argc] = NULL; save_rec_name = rec_name; - opt_init(argv[0], argc, argv); + opt_init(argv[0], argc, argv, 0); rec_name = save_rec_name; rec_name_completed = 1; -- 1.7.7.6