39 #include "CommandLineParser.hh"
42 using namespace G4DNAPARSER;
45 G4String Command::fNoOption =
"NoOption";
49 inline bool MATCH(
const char *
a,
const char *
b)
51 return strcmp(a, b) == 0;
56 CommandLineParser::CommandLineParser()
60 fOptionsWereSetup =
false;
62 fMaxOptionNameLength = 0;
63 AddCommand(
"--help", Command::WithoutOption,
"Print this help");
64 AddCommand(
"-h", Command::WithoutOption,
"Print this help");
65 AddCommand(
"&", Command::WithoutOption);
80 CommandLineParser::~CommandLineParser()
82 std::map<G4String, Command*>::iterator
it = fCommandMap.begin();
83 for (; it != fCommandMap.end(); it++)
85 if (it->second)
delete it->second;
91 void CommandLineParser::DeleteInstance()
106 fDescription = description;
110 CommandWithOption::CommandWithOption(
Command::Type commandType,
114 Command(commandType, description)
116 fDefaultOption = defaultOption;
117 fOptionName = optionName;
126 static char null[1] = {
"" };
127 int firstArgc = argc;
129 for (
int i = 1; i < firstArgc; i++)
132 if (command == 0)
continue;
141 if (strcmp(argv[i],
"-h") != 0 && strcmp(argv[i],
"--help") != 0)
150 if(i+1 > firstArgc || argv[i+1]==0 || argv[i+1][0]==
'-')
152 G4cerr <<
"An command line option is missing for "
157 command->
SetOption( (
const char*) strdup(argv[i+1]) );
170 if(buffer.empty() ==
false)
172 if(buffer.at(0) !=
'-'
173 && buffer.at(0) !=
'&'
174 && buffer.at(0) !=
'>'
175 && buffer.at(0) !=
'|')
179 G4cout <<
"facultative option is : " << buffer <<
G4endl;
182 command->
SetOption( (
const char*) strdup(argv[i+1]) );
202 G4cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" <<
G4endl;
214 std::map<G4String, Command*>::iterator
it;
233 else if (toPrint ==
"-h")
continue;
234 else if (toPrint ==
"--help")
257 for (
int i = 0; i < argc; i++)
259 if (strcmp(argv[i],
""))
282 command =
new Command(type, description);
291 fMaxOptionNameLength = defaultOption.length();
330 std::map<G4String, Command*>::iterator it =
fCommandMap.find(marker);
359 description <<
"You try to retrieve a command that was not registered : "
361 G4Exception(
"CommandLineParser::GetCommandIfActive",
376 for (
G4int i = 1; i < argc; i++)
378 if (strcmp(argv[i],
""))
381 G4cerr <<
"Unknown argument : " << argv[i] <<
"\n";
386 G4cerr <<
"The option " << argv[0]
387 <<
" is not handled this programme."
389 G4cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" <<
G4endl;