40 #include "CommandLineParser.hh"
43 using namespace G4DNAPARSER;
46 G4String Command::fNoOption =
"NoOption";
50 inline bool MATCH(
const char *
a,
const char *
b)
52 return strcmp(a, b) == 0;
57 CommandLineParser::CommandLineParser()
61 fOptionsWereSetup =
false;
63 fMaxOptionNameLength = 0;
64 AddCommand(
"--help", Command::WithoutOption,
"Print this help");
65 AddCommand(
"-h", Command::WithoutOption,
"Print this help");
66 AddCommand(
"&", Command::WithoutOption);
81 CommandLineParser::~CommandLineParser()
83 std::map<G4String, Command*>::iterator
it = fCommandMap.begin();
84 for (; it != fCommandMap.end(); it++)
86 if (it->second)
delete it->second;
92 void CommandLineParser::DeleteInstance()
107 fDescription = description;
111 CommandWithOption::CommandWithOption(
Command::Type commandType,
115 Command(commandType, description)
117 fDefaultOption = defaultOption;
118 fOptionName = optionName;
127 static char null[1] = {
"" };
128 int firstArgc = argc;
130 for (
int i = 1; i < firstArgc; i++)
133 if (command == 0)
continue;
142 if (strcmp(argv[i],
"-h") != 0 && strcmp(argv[i],
"--help") != 0)
151 if(i+1 > firstArgc || argv[i+1]==0 || argv[i+1][0]==
'-')
153 G4cerr <<
"An command line option is missing for "
158 command->
SetOption( (
const char*) strdup(argv[i+1]) );
171 if(buffer.empty() ==
false)
173 if(buffer.at(0) !=
'-'
174 && buffer.at(0) !=
'&'
175 && buffer.at(0) !=
'>'
176 && buffer.at(0) !=
'|')
180 G4cout <<
"facultative option is : " << buffer <<
G4endl;
183 command->
SetOption( (
const char*) strdup(argv[i+1]) );
203 G4cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" <<
G4endl;
215 std::map<G4String, Command*>::iterator
it;
234 else if (toPrint ==
"-h")
continue;
235 else if (toPrint ==
"--help")
258 for (
int i = 0; i < argc; i++)
260 if (strcmp(argv[i],
""))
283 command =
new Command(type, description);
292 fMaxOptionNameLength = defaultOption.length();
331 std::map<G4String, Command*>::iterator it =
fCommandMap.find(marker);
360 description <<
"You try to retrieve a command that was not registered : "
362 G4Exception(
"CommandLineParser::GetCommandIfActive",
377 for (
G4int i = 1; i < argc; i++)
379 if (strcmp(argv[i],
""))
382 G4cerr <<
"Unknown argument : " << argv[i] <<
"\n";
387 G4cerr <<
"The option " << argv[0]
388 <<
" is not handled this programme." <<
G4endl;
389 G4cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" <<
G4endl;