cline.c

changeset 21
91e0890464b0
parent 20
43725438ac50
child 22
4508da679ffb
     1.1 --- a/cline.c	Thu Oct 20 14:13:56 2011 +0200
     1.2 +++ b/cline.c	Thu Oct 20 15:21:53 2011 +0200
     1.3 @@ -14,11 +14,13 @@
     1.4  void printHelpText() {
     1.5    const char* helpText = 
     1.6      "\nUsage:"
     1.7 -    "\n      cline [-hrm][-s suffix][<directory>]"
     1.8 -    "\n      cline [-hrm][-S suffix][<directory>]"
     1.9 +    "\n      cline [-hrmvV][-s suffix][-b level][<directory>]"
    1.10 +    "\n      cline [-hrmvV][-S suffix][-b level][<directory>]"
    1.11      "\n\nCounts the line terminator characters (\\n) within all"
    1.12      " files in the specified\ndirectory."
    1.13      "\n\nOptions:"
    1.14 +    "\n  -b <level>          - binary file heuristics level (default medium)"
    1.15 +    "\n                        One of: ignore low medium high"
    1.16      "\n  -h, --help          - this help text"
    1.17      "\n  -m                  - print information about matching files only"
    1.18      "\n  -s <suffixes>       - only count files with these suffixes (separated"
    1.19 @@ -66,7 +68,7 @@
    1.20  
    1.21    for (int t = 1 ; t < argc ; t++) {
    1.22  
    1.23 -    int argflags = checkArgument(argv[t], "hsSrRmvV");
    1.24 +    int argflags = checkArgument(argv[t], "hsSrRmvVb");
    1.25  
    1.26      // s, S
    1.27      if ((argflags & 6) > 0) {
    1.28 @@ -109,6 +111,27 @@
    1.29        }
    1.30        settings->verbose = false;
    1.31      }
    1.32 +    // b
    1.33 +    if ((argflags & 256) > 0) {
    1.34 +      if (registerArgument(&checked, 256)) {
    1.35 +        return exit_with_help(settings, 1);
    1.36 +      }
    1.37 +      t++;
    1.38 +      if (t >= argc) {
    1.39 +        return exit_with_help(settings, 1);
    1.40 +      }
    1.41 +      if (stricmp(argv[t], "ignore") == 0) {
    1.42 +        settings->bfileHeuristics->level = BFILE_IGNORE;
    1.43 +      } else if (stricmp(argv[t], "low") == 0) {
    1.44 +        settings->bfileHeuristics->level = BFILE_LOW_ACCURACY;
    1.45 +      } else if (stricmp(argv[t], "medium") == 0) {
    1.46 +        settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY;
    1.47 +      } else if (stricmp(argv[t], "high") == 0) {
    1.48 +        settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY;
    1.49 +      } else {
    1.50 +        return exit_with_help(settings, 1);
    1.51 +      }
    1.52 +    }
    1.53      // Path
    1.54      if (argflags == 0) {
    1.55        if (registerArgument(&checked, 1024)) {
    1.56 @@ -137,27 +160,17 @@
    1.57      destroy_settings_t(settings);
    1.58      return 1;
    1.59    }
    1.60 -  
    1.61 +
    1.62    // Scan directory
    1.63    int lines = scanDirectory(dir, 0, directory, settings);
    1.64    closedir(dir);
    1.65    destroy_settings_t(settings);
    1.66  
    1.67    // Print double line and line count
    1.68 -#ifdef _WIN32
    1.69 -    const int columns = 79;
    1.70 -#else
    1.71 -    const int columns = 80;
    1.72 -#endif /* _WIN32 */
    1.73 -
    1.74 -  for (int t = 0 ; t < columns ; t++) {
    1.75 +  for (int t = 0 ; t < 79 ; t++) {
    1.76      printf("=");
    1.77    }
    1.78 -#ifdef _WIN32
    1.79 -    printf("\n%73d lines\n", lines);
    1.80 -#else
    1.81 -    printf("\n%74d lines\n", lines);
    1.82 -#endif /* _WIN32 */
    1.83 +  printf("\n%73d lines\n", lines);
    1.84  
    1.85    if (!settings->verbose) {
    1.86      reopen_stdout();

mercurial