Print

Print


Commit in slic/src on MAIN
CmdArgs.cc+46-131.6 -> 1.7
Fix SLIC-19: Handle multiple options on the same '-' char.

slic/src
CmdArgs.cc 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- CmdArgs.cc	18 May 2005 02:43:33 -0000	1.6
+++ CmdArgs.cc	7 Sep 2005 18:20:56 -0000	1.7
@@ -1,7 +1,11 @@
-// $Header: /cvs/lcd/slic/src/CmdArgs.cc,v 1.6 2005/05/18 02:43:33 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/CmdArgs.cc,v 1.7 2005/09/07 18:20:56 jeremy Exp $
 
 #include "CmdArgs.hh"
 
+#include "globals.hh"
+
+using std::string;
+
 namespace slic
 {
 
@@ -13,24 +17,53 @@
   CmdArgs::~CmdArgs()
   {}
 
-  void CmdArgs::fillFromCmdLine(int argc, char** argv) 
+  void CmdArgs::fillFromCmdLine(int argc, char** argv)
   {
     m_tokens.clear();
 
     size_t arg_count = (size_t) argc;
 
     if ( arg_count > 1 ) {
-      // disgard arg1 = name of exec
+
+      /* Loop over input char*, disregarding arg[0]. */
       for ( size_t i = 1; i < arg_count; i++ ) {
-	
+
 	const char* this_arg_char = (const char*) ( argv[i] );
-	
-	std::string this_tok = this_arg_char;
-		
-	this->addToken( this_tok );
+
+	string this_tok = this_arg_char;
+
+	string::size_type idx = this_tok.find('-');
+
+	/*
+	 * Check if the string has a "-" in position 0, indicating a command
+	 * switch (or possibly a group of them), and no "--".
+	 */
+	if ( (idx == 0) && (this_tok.find("--") == string::npos) ) {
+
+	  bool addedTok = false;
+
+	  /*
+	   * Add the switches, converting groups to individual tokens, e.g. the
+	   * input "-xyz" is changed to the tokens "-x","-y", and "-z".
+	   */
+	  for(idx+=1; idx < this_tok.length(); idx++) {
+	    std::string this_switch = "-" + this_tok.substr(idx, 1);
+	    this->addToken( this_switch );
+	    addedTok = true;
+	  }
+
+	  /* This probably means that the user entered a "-" without a char after it. */
+	  if ( !addedTok ) {
+	    G4Exception("FATAL ERROR: Bad command line argument format.");
+	  }
+	}
+	/* Just push the token. */
+	else {
+	  this->addToken( this_tok );
+	}
       }
-    }   
-  }   
+    }
+  }
 
   const CmdArgs::TokVecType& CmdArgs::getTokens()
   {
@@ -42,12 +75,12 @@
     return m_tokens.size();
   }
 
-  void CmdArgs::addToken(const std::string& str)
+  void CmdArgs::addToken(const string& str)
   {
     m_tokens.push_back( str );
   }
 
-  const std::string& CmdArgs::getToken(SizeType idx)
+  const string& CmdArgs::getToken(SizeType idx)
   {
     assert( idx < ( getNumTokens() - 1 ) );
 
@@ -71,7 +104,7 @@
     size_t cntr = 0;
     for ( TokVecType::const_iterator iter = getTokensBegin();
 	  iter != getTokensEnd();
-	  iter++ ) {     
+	  iter++ ) {
       os << "idx <" << cntr << ">, token <" << *iter << ">" << std::endl;
       ++cntr;
     }
CVSspam 0.2.8