Changed the handling of the argument errors and short help printing.
authorFrancois Fleuret <francois@fleuret.org>
Tue, 17 Mar 2009 07:02:53 +0000 (08:02 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Tue, 17 Mar 2009 07:02:53 +0000 (08:02 +0100)
selector.cc

index e9b4f64..d36c836 100644 (file)
@@ -401,7 +401,9 @@ int main(int argc, char **argv) {
   strcpy(output_filename, "");
 
   int i = 1;
-  while(i < argc) {
+  int error = 0, show_help = 0;
+
+  while(!error && !show_help && i < argc) {
 
     if(strcmp(argv[i], "-o") == 0) {
       check_opt(argc, argv, i, 1, "<output filename>");
@@ -471,33 +473,40 @@ int main(int argc, char **argv) {
       i += 5;
     }
 
+    else if(strcmp(argv[i], "-h") == 0) {
+      show_help = 1;
+      i++;
+    }
+
     else {
-      cerr << "Selector version " << VERSION << "-R" << REVISION_NUMBER
-           << endl
-           << "Written by Francois Fleuret <francois@fleuret.org>"
-           << endl
-           << argv[0]
-           << " [-h]"
-           << " [-v]"
-           << " [-m]"
-           << " [-d]"
-           << " [-e]"
-           << " [-z]"
-           << " [-i]"
-           << " [-c <fg modeline> <bg modeline> <fg highlight> <bg highlight>]"
-           << " [-o <output filename>]"
-           << " [-s <pattern separator>]"
-           << " [-l <max number of lines>]"
-           << " -f <input filename>"
-           << endl;
-      if(strcmp(argv[i], "-h") == 0) {
-        exit(0);
-      } else {
-        exit(1);
-      }
+      cerr << "Unknown argument " << argv[i] << "." << endl;
+      error = 1;
     }
   }
 
+  if(show_help || error) {
+    cerr << "Selector version " << VERSION << "-R" << REVISION_NUMBER
+         << endl
+         << "Written by Francois Fleuret <francois@fleuret.org>"
+         << endl
+         << argv[0]
+         << " [-h]"
+         << " [-v]"
+         << " [-m]"
+         << " [-d]"
+         << " [-e]"
+         << " [-z]"
+         << " [-i]"
+         << " [-c <fg modeline> <bg modeline> <fg highlight> <bg highlight>]"
+         << " [-o <output filename>]"
+         << " [-s <pattern separator>]"
+         << " [-l <max number of lines>]"
+         << " -f <input filename>"
+         << endl;
+
+    exit(error);
+  }
+
   char **lines = new char *[nb_lines_max];
 
   if(!input_filename[0]) {