cline.c

changeset 14
ee9333c91dda
parent 12
902cb8d2053c
child 16
bc9a0fefd892
     1.1 --- a/cline.c	Fri Sep 16 09:59:20 2011 +0200
     1.2 +++ b/cline.c	Fri Sep 16 10:36:45 2011 +0200
     1.3 @@ -11,7 +11,6 @@
     1.4  #include "arguments.h"
     1.5  
     1.6  void printHelpText() {
     1.7 -  // Help text
     1.8    const char* helpText = 
     1.9      "\nUsage:"
    1.10      "\n      cline [-hrm][-s suffix][<directory>]"
    1.11 @@ -26,6 +25,7 @@
    1.12      "\n  -S <suffixes>       - count any file except those with these suffixes"
    1.13      "\n                        (separated by commas)"
    1.14      "\n  -r, -R              - includes subdirectories"
    1.15 +    "\n  -v, --version       - print out version information"
    1.16      "\n\n"
    1.17      "The default call without any options is:"    
    1.18      "\n  cline ./\n"
    1.19 @@ -36,6 +36,12 @@
    1.20    printf(helpText);
    1.21  }
    1.22  
    1.23 +int exit_with_version(settings_t* settings) {
    1.24 +  printf("cline - Version: %s", VERSION);
    1.25 +  destroy_settings_t(settings);
    1.26 +  return 0;
    1.27 +}
    1.28 +
    1.29  int exit_with_help(settings_t* settings, int code) {
    1.30    printHelpText();
    1.31    destroy_settings_t(settings);
    1.32 @@ -54,40 +60,27 @@
    1.33    // Get arguments
    1.34    char* directory = "./";
    1.35    char* suffix = " ";
    1.36 -  bool showHelp = false;
    1.37    int checked = 0;
    1.38  
    1.39    for (int t = 1 ; t < argc ; t++) {
    1.40  
    1.41 -    int argflags = checkArgument(argv[t], "hsSrRm");
    1.42 +    int argflags = checkArgument(argv[t], "hsSrRmv");
    1.43  
    1.44 -    // s
    1.45 -    if ((argflags & 2) > 0) {
    1.46 +    // s, S
    1.47 +    if ((argflags & 6) > 0) {
    1.48        if (registerArgument(&checked, 6)) {
    1.49          return exit_with_help(settings, 1);
    1.50        }
    1.51 -      settings->includeSuffixes = true;
    1.52 +      settings->includeSuffixes = (argflags & 2) > 0;
    1.53        t++;
    1.54        if (t >= argc) {
    1.55          return exit_with_help(settings, 1);
    1.56        }
    1.57        suffix = argv[t]; 
    1.58      }
    1.59 -    // S
    1.60 -    if ((argflags & 4) > 0) {
    1.61 -      if (registerArgument(&checked, 6)) {
    1.62 -        return exit_with_help(settings, 1);
    1.63 -      }
    1.64 -      settings->includeSuffixes = false;
    1.65 -      t++;
    1.66 -      if (t >= argc) {
    1.67 -        return exit_with_help(settings, 1);
    1.68 -      }
    1.69 -      suffix = argv[t];
    1.70 -    }
    1.71      // h
    1.72      if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
    1.73 -      return exit_with_help(settings, 1);
    1.74 +      return exit_with_help(settings, 0);
    1.75      }
    1.76      // r, R
    1.77      if ((argflags & 24) > 0) {
    1.78 @@ -103,6 +96,10 @@
    1.79        }
    1.80        settings->matchesOnly = true;
    1.81      }
    1.82 +    // v
    1.83 +    if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) {
    1.84 +      return exit_with_version(settings);
    1.85 +    }
    1.86      // Path
    1.87      if (argflags == 0) {
    1.88        if (registerArgument(&checked, 1024)) {

mercurial