slic/src
diff -u -r1.3 -r1.4
--- CommandLineProcessor.cc 2 Dec 2006 00:27:14 -0000 1.3
+++ CommandLineProcessor.cc 15 Dec 2006 05:32:46 -0000 1.4
@@ -1,4 +1,4 @@
-// $Id: CommandLineProcessor.cc,v 1.3 2006/12/02 00:27:14 jeremy Exp $
+// $Id: CommandLineProcessor.cc,v 1.4 2006/12/15 05:32:46 jeremy Exp $
#include "CommandLineProcessor.hh"
@@ -67,7 +67,7 @@
optstr,
long_options,
&option_index);
-
+
// Done.
if ( c == -1 )
break;
@@ -99,25 +99,56 @@
string theopt = ostr.str();
if ( optarg ) {
- m_commandline.push_back(OptionsPair(theopt, optarg));
+ m_commandline.push_back( OptionsPair( theopt, optarg ) );
}
else {
- m_commandline.push_back(OptionsPair(theopt, ""));
+ m_commandline.push_back( OptionsPair( theopt, "" ) );
}
break;
}
}
+ //
+ // The processing flow...
+ //
+ // 1) If version flag is set, print version and exit.
+ //
+ // 2) If usage flag is set or no arguments were received,
+ // print the usage and exit.
+ //
+ // 3) If a single non-option command was received, treat
+ // it as a macro to execute.
+ //
+ // 4) If no options were received or the number of options
+ // is less than the number of arguments, print usage
+ // and exit (syntax incorrect).
+ //
+ // 5) Finally, process the options in order if the syntax
+ // appears to be okay.
+ //
+
// Print the version information and abort.
- if (m_version_flag) {
- printVersion(std::cout);
+ if ( m_version_flag ) {
+ printVersion( std::cout );
abort();
}
- // Print the usage and abort if the help flag was
- // passed or if there were no commandline arguments.
- else if (m_help_flag || m_commandline.size() == 0 ) {
- printUsage(std::cout);
+ // Print the usage and abort if the help flag is set
+ // or no arguments were received.
+ else if ( m_help_flag || argc == 1 ) {
+ printUsage( std::cout );
+ abort();
+ }
+ // Single macro to execute, if got 1 argument that is a non-option.
+ else if ( argc == 2 && optind < argc ) {
+ stringstream str;
+ str << "/control/execute ";
+ str << argv[1];
+ m_g4q.add( str.str() );
+ }
+ // Probably extra arguments or no options.
+ else if ( optind == 1 || optind < argc ) {
+ printUsage( std::cout );
abort();
}
// Default is process all the options and build the CommandQueue.
@@ -494,6 +525,11 @@
if ( opt->getMinArgs() ) {
m_getoptOptions += ":";
}
+ else if ( opt->getMaxArgs() ) {
+ m_getoptOptions += "::";
+ }
}
+
+ //std::cout << "options=" << m_getoptOptions << std::endl;
}
} // namespace slic