cline.c

changeset 21
91e0890464b0
parent 20
43725438ac50
child 22
4508da679ffb
--- a/cline.c	Thu Oct 20 14:13:56 2011 +0200
+++ b/cline.c	Thu Oct 20 15:21:53 2011 +0200
@@ -14,11 +14,13 @@
 void printHelpText() {
   const char* helpText = 
     "\nUsage:"
-    "\n      cline [-hrm][-s suffix][<directory>]"
-    "\n      cline [-hrm][-S suffix][<directory>]"
+    "\n      cline [-hrmvV][-s suffix][-b level][<directory>]"
+    "\n      cline [-hrmvV][-S suffix][-b level][<directory>]"
     "\n\nCounts the line terminator characters (\\n) within all"
     " files in the specified\ndirectory."
     "\n\nOptions:"
+    "\n  -b <level>          - binary file heuristics level (default medium)"
+    "\n                        One of: ignore low medium high"
     "\n  -h, --help          - this help text"
     "\n  -m                  - print information about matching files only"
     "\n  -s <suffixes>       - only count files with these suffixes (separated"
@@ -66,7 +68,7 @@
 
   for (int t = 1 ; t < argc ; t++) {
 
-    int argflags = checkArgument(argv[t], "hsSrRmvV");
+    int argflags = checkArgument(argv[t], "hsSrRmvVb");
 
     // s, S
     if ((argflags & 6) > 0) {
@@ -109,6 +111,27 @@
       }
       settings->verbose = false;
     }
+    // b
+    if ((argflags & 256) > 0) {
+      if (registerArgument(&checked, 256)) {
+        return exit_with_help(settings, 1);
+      }
+      t++;
+      if (t >= argc) {
+        return exit_with_help(settings, 1);
+      }
+      if (stricmp(argv[t], "ignore") == 0) {
+        settings->bfileHeuristics->level = BFILE_IGNORE;
+      } else if (stricmp(argv[t], "low") == 0) {
+        settings->bfileHeuristics->level = BFILE_LOW_ACCURACY;
+      } else if (stricmp(argv[t], "medium") == 0) {
+        settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY;
+      } else if (stricmp(argv[t], "high") == 0) {
+        settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY;
+      } else {
+        return exit_with_help(settings, 1);
+      }
+    }
     // Path
     if (argflags == 0) {
       if (registerArgument(&checked, 1024)) {
@@ -137,27 +160,17 @@
     destroy_settings_t(settings);
     return 1;
   }
-  
+
   // Scan directory
   int lines = scanDirectory(dir, 0, directory, settings);
   closedir(dir);
   destroy_settings_t(settings);
 
   // Print double line and line count
-#ifdef _WIN32
-    const int columns = 79;
-#else
-    const int columns = 80;
-#endif /* _WIN32 */
-
-  for (int t = 0 ; t < columns ; t++) {
+  for (int t = 0 ; t < 79 ; t++) {
     printf("=");
   }
-#ifdef _WIN32
-    printf("\n%73d lines\n", lines);
-#else
-    printf("\n%74d lines\n", lines);
-#endif /* _WIN32 */
+  printf("\n%73d lines\n", lines);
 
   if (!settings->verbose) {
     reopen_stdout();

mercurial