From: Francois Fleuret Date: Tue, 17 Mar 2009 07:02:53 +0000 (+0100) Subject: Changed the handling of the argument errors and short help printing. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=10836361b425af2fd602d4fe6adb12c8037f99d9;p=selector.git Changed the handling of the argument errors and short help printing. --- diff --git a/selector.cc b/selector.cc index e9b4f64..d36c836 100644 --- a/selector.cc +++ b/selector.cc @@ -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, ""); @@ -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 " - << endl - << argv[0] - << " [-h]" - << " [-v]" - << " [-m]" - << " [-d]" - << " [-e]" - << " [-z]" - << " [-i]" - << " [-c ]" - << " [-o ]" - << " [-s ]" - << " [-l ]" - << " -f " - << 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 " + << endl + << argv[0] + << " [-h]" + << " [-v]" + << " [-m]" + << " [-d]" + << " [-e]" + << " [-z]" + << " [-i]" + << " [-c ]" + << " [-o ]" + << " [-s ]" + << " [-l ]" + << " -f " + << endl; + + exit(error); + } + char **lines = new char *[nb_lines_max]; if(!input_filename[0]) {