Print

Print


Commit in slic/src on MAIN
CmdManager.cc+26-31.17 -> 1.18
Fix SLIC-51.  Validate number of CL arguments to each switch.

slic/src
CmdManager.cc 1.17 -> 1.18
diff -u -r1.17 -r1.18
--- CmdManager.cc	16 Sep 2005 23:04:39 -0000	1.17
+++ CmdManager.cc	21 Sep 2005 19:07:09 -0000	1.18
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/CmdManager.cc,v 1.17 2005/09/16 23:04:39 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/CmdManager.cc,v 1.18 2005/09/21 19:07:09 jeremy Exp $
 #include "CmdManager.hh"
 
 #include "G4Application.hh"
@@ -37,7 +37,10 @@
     std::string curr_g4_cmd;
     std::string curr_tok;
     int n_args = 0;
+    int nArgsMin = 0;
+    int nArgsMax = 0;
     bool first_time = true;
+    CmdLineOpt* lineOpt = 0;
 
     for (CmdArgs::TokVecType::const_iterator iter = m_args.getTokensBegin();
 	 iter != m_args.getTokensEnd();
@@ -52,9 +55,14 @@
       // is it a command name?
       bool is_name = isCmdName( curr_tok );
 
-      // handle a command
+      // handle an option
       if ( is_opt || is_name) {
 
+	/* Check for not enough args to previous switch. */
+	if ( n_args < nArgsMin ) {
+	  G4Exception("Not enough arguments to switch -" + lineOpt->getOpt() );
+	}
+
 	// add current cmd to queue if not first time
 	if ( first_time == false ) {
 
@@ -78,6 +86,7 @@
 
 	  // find cmd by opt
 	  curr_g4_cmd = m_cmdRegistry.findG4CmdStrByOpt( curr_tok );
+	  lineOpt = m_cmdRegistry.findCmdLineOptByOpt( curr_tok );
 
 	  if ( curr_g4_cmd == std::string("") ) {
 	    G4Exception("Command option not found: " + curr_tok );
@@ -91,13 +100,17 @@
 
 	  // find cmd by name
 	  curr_g4_cmd = m_cmdRegistry.findG4CmdStrByName( curr_tok );
+	  lineOpt = m_cmdRegistry.findCmdLineOptByName( curr_tok );
 
 	  if ( curr_g4_cmd == std::string("") ) {
 	    G4Exception("Command name not found: --" + curr_tok);
 	  }
 	}
+
+	nArgsMin = lineOpt->getMinArgs();
+	nArgsMax = lineOpt->getMaxArgs();
       }
-      // arg to command or macro only
+      // handle arg to command or single macro filename
       else {
 	// try a single macro arg
 	if ( first_time ) {
@@ -118,10 +131,20 @@
 	else {
 	  curr_g4_cmd += ' ' + curr_tok;
 	  n_args++;
+
+	  /* Check for too many args */
+	  if ( n_args > nArgsMax ) {
+	    G4Exception("Too many arguments to switch -" + lineOpt->getOpt() );
+	  }
 	}
       }
     }
 
+    /* Check for not enough args to last switch */
+    if ( n_args < nArgsMin ) {
+      G4Exception("Not enough arguments to switch -" + lineOpt->getOpt() );
+    }
+
     // add last cmd
     m_cmdQueue.addCmd( curr_g4_cmd );
   }
CVSspam 0.2.8