cline.c

changeset 12
902cb8d2053c
parent 11
06cbd0ec003d
child 14
ee9333c91dda
     1.1 --- a/cline.c	Thu Sep 15 13:38:03 2011 +0200
     1.2 +++ b/cline.c	Fri Sep 16 09:14:59 2011 +0200
     1.3 @@ -8,13 +8,14 @@
     1.4  #include "cline.h"
     1.5  #include "scanner.h"
     1.6  #include "settings.h"
     1.7 +#include "arguments.h"
     1.8  
     1.9 -void printHelpText(const char* prgName) {
    1.10 +void printHelpText() {
    1.11    // Help text
    1.12    const char* helpText = 
    1.13      "\nUsage:"
    1.14 -    "\n      %s [-hrm][-s suffix][<directory>]"
    1.15 -    "\n      %s [-hrm][-S suffix][<directory>]"
    1.16 +    "\n      cline [-hrm][-s suffix][<directory>]"
    1.17 +    "\n      cline [-hrm][-S suffix][<directory>]"
    1.18      "\n\nCounts the line terminator characters (\\n) within all"
    1.19      " files in the specified\ndirectory."
    1.20      "\n\nOptions:"
    1.21 @@ -27,16 +28,16 @@
    1.22      "\n  -r, -R              - includes subdirectories"
    1.23      "\n\n"
    1.24      "The default call without any options is:"    
    1.25 -    "\n  %s ./\n"
    1.26 +    "\n  cline ./\n"
    1.27      "So each file in the working directory is counted. If you want to count C"
    1.28      "\nsource code in your working directory and its subdirectories, type:"
    1.29 -    "\n  %s -rs .c\n";
    1.30 +    "\n  cline -rs .c\n";
    1.31      
    1.32 -  printf(helpText, prgName, prgName, prgName, prgName);
    1.33 +  printf(helpText);
    1.34  }
    1.35  
    1.36 -int exit_with_help(char* prgName, settings_t* settings, int code) {
    1.37 -  printHelpText(prgName);
    1.38 +int exit_with_help(settings_t* settings, int code) {
    1.39 +  printHelpText();
    1.40    destroy_settings_t(settings);
    1.41    return code;
    1.42  }
    1.43 @@ -50,15 +51,6 @@
    1.44      return 1;
    1.45    }
    1.46  
    1.47 -  // Program name
    1.48 -  char* prgName = strrchr(argv[0], settings->fileSeparator);
    1.49 -  
    1.50 -  if (prgName == NULL) {
    1.51 -    prgName = argv[0];
    1.52 -  } else {
    1.53 -    prgName++;
    1.54 -  }
    1.55 -
    1.56    // Get arguments
    1.57    char* directory = "./";
    1.58    char* suffix = " ";
    1.59 @@ -72,49 +64,49 @@
    1.60      // s
    1.61      if ((argflags & 2) > 0) {
    1.62        if (registerArgument(&checked, 6)) {
    1.63 -        return exit_with_help(prgName, settings, 1);
    1.64 +        return exit_with_help(settings, 1);
    1.65        }
    1.66        settings->includeSuffixes = true;
    1.67        t++;
    1.68        if (t >= argc) {
    1.69 -        return exit_with_help(prgName, settings, 1);
    1.70 +        return exit_with_help(settings, 1);
    1.71        }
    1.72        suffix = argv[t]; 
    1.73      }
    1.74      // S
    1.75      if ((argflags & 4) > 0) {
    1.76        if (registerArgument(&checked, 6)) {
    1.77 -        return exit_with_help(prgName, settings, 1);
    1.78 +        return exit_with_help(settings, 1);
    1.79        }
    1.80        settings->includeSuffixes = false;
    1.81        t++;
    1.82        if (t >= argc) {
    1.83 -        return exit_with_help(prgName, settings, 1);
    1.84 +        return exit_with_help(settings, 1);
    1.85        }
    1.86        suffix = argv[t];
    1.87      }
    1.88      // h
    1.89      if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
    1.90 -      return exit_with_help(prgName, settings, 1);
    1.91 +      return exit_with_help(settings, 1);
    1.92      }
    1.93      // r, R
    1.94      if ((argflags & 24) > 0) {
    1.95        if (registerArgument(&checked, 24)) {
    1.96 -        return exit_with_help(prgName, settings, 1);
    1.97 +        return exit_with_help(settings, 1);
    1.98        }
    1.99        settings->recursive = true;
   1.100      }
   1.101      // m
   1.102      if ((argflags & 32) > 0) {
   1.103        if (registerArgument(&checked, 32)) {
   1.104 -        return exit_with_help(prgName, settings, 1);
   1.105 +        return exit_with_help(settings, 1);
   1.106        }
   1.107        settings->matchesOnly = true;
   1.108      }
   1.109      // Path
   1.110      if (argflags == 0) {
   1.111        if (registerArgument(&checked, 1024)) {
   1.112 -        return exit_with_help(prgName, settings, 1);
   1.113 +        return exit_with_help(settings, 1);
   1.114        }
   1.115        directory = argv[t];
   1.116      }

mercurial