18 using namespace genie;
36 const int buf_size = 2048*128;
39 char * argument =
new char[buf_size];
47 LOG(
"CLAP",
pDEBUG) <<
"Getting next argument in argument-list";
48 LOG(
"CLAP",
pDEBUG) <<
"Current argc = " << argc;
50 if (argv[1][0] ==
'-') {
52 <<
"Got char (argv[1][1]) following argv[1][0]='-' : " << argv[1][1];
54 if (argv[1][1] == op) {
55 LOG(
"CLAP",
pDEBUG) <<
"Input option: " << op <<
" was matched";
57 if (strlen(&argv[1][2]) ) {
58 strcpy(argument,&argv[1][2]);
60 <<
"Set opt = [" << op <<
"] to val = [" << argument <<
"]";
62 }
else if( (argc>2) &&
63 !(argv[2][0]==
'-' && isalpha(argv[2][1])) ) {
66 <<
"argc>2 and next arg not a '-' followed by an alpha char";
70 strcpy(argument,&argv[1][0]);
73 <<
"Set opt = [" << op <<
"] to val = [" << argument <<
"]";
80 LOG(
"CLAP",
pDEBUG) <<
"Next argv[1][0] = " << argv[1][0];
84 LOG(
"CLAP",
pDEBUG) <<
"CmdLnArgParser::Arg op='" << op <<
"' set=" <<
set;
96 if(argv[1][0] ==
'-') {
97 if (argv[1][1] == op)
set =
true;
108 char * argument = this->
Arg(op);
119 vector<string> tokens =
str::Split(argument, delimeter);
125 char * argument = this->
Arg(op);
126 double value = atof(argument);
137 for( ; iter != strtokens.end(); ++iter) {
139 tokens.push_back(atof(arg.c_str()));
146 char * argument = this->
Arg(op);
147 int value = atoi(argument);
158 for( ; iter != strtokens.end(); ++iter) {
160 tokens.push_back(atoi(arg.c_str()));
167 char * argument = this->
Arg(op);
168 long value = atol(argument);
179 for( ; iter != strtokens.end(); ++iter) {
181 tokens.push_back(atol(arg.c_str()));
188 const int buf_size = 2048*128;
189 char * argument =
new char[buf_size];
190 strcpy(argument,
"");
197 LOG(
"CLAP",
pDEBUG) <<
"Getting next argument in argument-list";
198 LOG(
"CLAP",
pDEBUG) <<
"Current argc = " << argc;
200 if (argv[1][0] ==
'-' && argv[1][1] ==
'-') {
202 char op_cur[buf_size];
203 strcpy(op_cur,&argv[1][2]);
205 <<
"Got string following '--' : " << op_cur;
206 if (
strcmp(op.c_str(),op_cur)==0) {
207 LOG(
"CLAP",
pDEBUG) <<
"Input option: " << op <<
" was matched";
209 if (strlen(&argv[2][0]) ) {
210 strcpy(argument,&argv[2][0]);
212 <<
"Set opt = [" << op <<
"] to val = [" << argument <<
"]";
214 }
else if( (argc>2) &&
215 !(argv[2][0]==
'-' &&argv[2][1]==
'-' && isalpha(argv[2][2])) ) {
217 <<
"argc>2 and next arg not a '--' followed by an alpha char";
221 strcpy(argument,&argv[1][0]);
223 <<
"Set opt = [" << op <<
"] to val = [" << argument <<
"]";
230 LOG(
"CLAP",
pDEBUG) <<
"Next argv[1][0] = " << argv[1][0];
239 const int buf_size = 2048*128;
246 if(argv[1][0] ==
'-' && argv[1][1] ==
'-') {
248 char op_cur[buf_size];
249 strcpy(op_cur,&argv[1][2]);
250 if (
strcmp(op.c_str(),op_cur)==0)
set =
true;
261 char * argument = this->
Arg(op);
270 char * argument = this->
Arg(op);
271 double value = atof(argument);
279 char * argument = this->
Arg(op);
280 int value = atoi(argument);
288 char * argument = this->
Arg(op);
289 long value = atol(argument);
double ArgAsDouble(char opt)
vector< string > ArgAsStringTokens(char opt, string delimeter)
string ArgAsString(char opt)
THE MAIN GENIE PROJECT NAMESPACE
vector< long > ArgAsLongTokens(char opt, string delimeter)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
vector< double > ArgAsDoubleTokens(char opt, string delimeter)
CmdLnArgParser(int argc, char **argv)
vector< string > Split(string input, string delim)
int strcmp(const String &s1, const String &s2)
bool OptionExists(char opt)
was option set?
vector< int > ArgAsIntTokens(char opt, string delimeter)
Root of GENIE utility namespaces.
char * Arg(char opt)
return argument following -`opt'