diff -r 51b1ba3776b1 -r ee9333c91dda cline.c --- a/cline.c Fri Sep 16 09:59:20 2011 +0200 +++ b/cline.c Fri Sep 16 10:36:45 2011 +0200 @@ -11,7 +11,6 @@ #include "arguments.h" void printHelpText() { - // Help text const char* helpText = "\nUsage:" "\n cline [-hrm][-s suffix][]" @@ -26,6 +25,7 @@ "\n -S - count any file except those with these suffixes" "\n (separated by commas)" "\n -r, -R - includes subdirectories" + "\n -v, --version - print out version information" "\n\n" "The default call without any options is:" "\n cline ./\n" @@ -36,6 +36,12 @@ printf(helpText); } +int exit_with_version(settings_t* settings) { + printf("cline - Version: %s", VERSION); + destroy_settings_t(settings); + return 0; +} + int exit_with_help(settings_t* settings, int code) { printHelpText(); destroy_settings_t(settings); @@ -54,40 +60,27 @@ // Get arguments char* directory = "./"; char* suffix = " "; - bool showHelp = false; int checked = 0; for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRm"); + int argflags = checkArgument(argv[t], "hsSrRmv"); - // s - if ((argflags & 2) > 0) { + // s, S + if ((argflags & 6) > 0) { if (registerArgument(&checked, 6)) { return exit_with_help(settings, 1); } - settings->includeSuffixes = true; + settings->includeSuffixes = (argflags & 2) > 0; t++; if (t >= argc) { return exit_with_help(settings, 1); } suffix = argv[t]; } - // S - if ((argflags & 4) > 0) { - if (registerArgument(&checked, 6)) { - return exit_with_help(settings, 1); - } - settings->includeSuffixes = false; - t++; - if (t >= argc) { - return exit_with_help(settings, 1); - } - suffix = argv[t]; - } // h if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { - return exit_with_help(settings, 1); + return exit_with_help(settings, 0); } // r, R if ((argflags & 24) > 0) { @@ -103,6 +96,10 @@ } settings->matchesOnly = true; } + // v + if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { + return exit_with_version(settings); + } // Path if (argflags == 0) { if (registerArgument(&checked, 1024)) {