cline.c

changeset 16
bc9a0fefd892
parent 14
ee9333c91dda
child 19
8bac9fd0629d
--- a/cline.c	Mon Sep 19 08:11:08 2011 +0200
+++ b/cline.c	Tue Sep 20 15:19:28 2011 +0200
@@ -9,6 +9,7 @@
 #include "scanner.h"
 #include "settings.h"
 #include "arguments.h"
+#include "stream.h"
 
 void printHelpText() {
   const char* helpText = 
@@ -26,6 +27,7 @@
     "\n                        (separated by commas)"
     "\n  -r, -R              - includes subdirectories"
     "\n  -v, --version       - print out version information"
+    "\n  -V                  - turn verbose output off, print the result only"
     "\n\n"
     "The default call without any options is:"    
     "\n  cline ./\n"
@@ -37,7 +39,7 @@
 }
 
 int exit_with_version(settings_t* settings) {
-  printf("cline - Version: %s", VERSION);
+  printf("cline - Revision: %s", VERSION);
   destroy_settings_t(settings);
   return 0;
 }
@@ -64,7 +66,7 @@
 
   for (int t = 1 ; t < argc ; t++) {
 
-    int argflags = checkArgument(argv[t], "hsSrRmv");
+    int argflags = checkArgument(argv[t], "hsSrRmvV");
 
     // s, S
     if ((argflags & 6) > 0) {
@@ -100,6 +102,13 @@
     if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) {
       return exit_with_version(settings);
     }
+    // V
+    if ((argflags & 128) > 0) {
+      if (registerArgument(&checked, 128)) {
+        return exit_with_help(settings, 1);
+      }
+      settings->verbose = false;
+    }
     // Path
     if (argflags == 0) {
       if (registerArgument(&checked, 1024)) {
@@ -109,6 +118,11 @@
     }
   }
 
+  // Configure output
+  if (!settings->verbose) {
+    close_stdout();
+  }
+
   // Find tokens
   char* finder = strtok(suffix, ",");
   while (finder != NULL) {
@@ -130,20 +144,26 @@
   destroy_settings_t(settings);
 
   // Print double line and line count
-  #ifdef _WIN32
+#ifdef _WIN32
     const int columns = 79;
-  #else
+#else
     const int columns = 80;
-  #endif /* _WIN32 */
+#endif /* _WIN32 */
 
   for (int t = 0 ; t < columns ; t++) {
     printf("=");
   }
-  #ifdef _WIN32
+#ifdef _WIN32
     printf("\n%73d lines\n", lines);
-  #else
+#else
     printf("\n%74d lines\n", lines);
-  #endif /* _WIN32 */
+#endif /* _WIN32 */
 
+  if (!settings->verbose) {
+    reopen_stdout();
+    printf("%d", lines);
+  }
+
+  fflush(stdout);
   return 0;
 }

mercurial