>From 8edf4090ecfeac42abff9448db81b0fa2b3f0654 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Mon, 2 Jul 2012 18:47:09 +0200 Subject: [PATCH] Make --list= a little bit more user friendly Allow invalid values like --list=help or --list=WHAT to produce the same list as --list=?, but exit(1) instead of exit(0) in this case --- src/john.c | 45 ++++++++++++++++++++++++++++++--------------- src/options.c | 2 +- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/john.c b/src/john.c index 471a165..2c30d62 100644 --- a/src/john.c +++ b/src/john.c @@ -566,7 +566,28 @@ static void CPU_detect_or_fallback(char **argv, int make_check) #else #define CPU_detect_or_fallback(argv, make_check) #endif - +static void john_list_options() +{ + /* + * Should this list be sorted alphabetically? + * Sould we add --list=help, providing a more detailed list than --list=? + * (including a description similar to information currently only available + * in doc/OPTIONS)? + */ + puts("subformats, inc-modes, rules, externals, ext-filters, ext-filters-only,"); + puts("ext-modes, build-info, hidden-options, encodings, formats, format-details,"); + printf("format-all-details, "); +#ifdef CL_VERSION_1_0 + printf("opencl-devices, "); +#endif +#ifdef HAVE_CUDA + printf("cuda-devices, "); +#endif + /* NOTE: The following must end the list. Anything listed + will be ignored by current + bash completion scripts. */ + puts(""); +} static void john_init(char *name, int argc, char **argv) { int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); @@ -582,19 +603,7 @@ static void john_init(char *name, int argc, char **argv) if (options.listconf && !strcasecmp(options.listconf, "?")) { - puts("subformats, inc-modes, rules, externals, ext-filters, ext-filters-only,"); - puts("ext-modes, build-info, hidden-options, encodings, formats, format-details,"); - printf("format-all-details, "); -#ifdef CL_VERSION_1_0 - printf("opencl-devices, "); -#endif -#ifdef HAVE_CUDA - printf("cuda-devices, "); -#endif - /* NOTE: The following must end the list. Anything listed - after will be ignored by current - bash completion scripts. */ - puts(""); + john_list_options(); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) @@ -861,8 +870,14 @@ static void john_init(char *name, int argc, char **argv) //printf("Subsections of [%s]:\n", options.listconf); if (cfg_print_subsections(options.listconf, NULL, NULL, 1)) exit(0); - else + else { + /* Just in case the user specified an invalid value + * like help or list... + * print the same list as with --list=?, but exit(1) + */ + john_list_options(); exit(1); + } } common_init(); diff --git a/src/options.c b/src/options.c index 7370b4d..e82550d 100644 --- a/src/options.c +++ b/src/options.c @@ -198,7 +198,7 @@ static struct opt_entry opt_list[] = { " " // formats are prepended with a space #define JOHN_USAGE_TAIL \ -"--list=WHAT list capabilities, see doc/OPTIONS or --list=?\n" \ +"--list=WHAT list capabilities, see --list=? or doc/OPTIONS\n" \ "--save-memory=LEVEL enable memory saving, at LEVEL 1..3\n" \ "--mem-file-size=SIZE size threshold for wordlist preload (default 5 MB)\n" \ "--nolog disables creation and writing to john.log file\n" \ -- 1.7.7.6