13 optMap[
"LOG_VERBOSITY"].arg = 0;
14 optMap[
"LOG_VERBOSITY"].help =
"Controls General Log Verbosity.";
15 optMap[
"LOG_VERBOSITY"].name =
"Log Verbosity";
16 optMap[
"LOG_VERBOSITY"].type = 0;
17 optMap[
"LOG_VERBOSITY"].ctgr =
"verbosity";
24 QDomDocument domDocument;
26 cout <<
" >> Parsing " << file <<
" for options: \n";
28 QFile gcard(file.c_str());
32 cout <<
" >> gcard: " << file <<
" not found. Exiting." << endl;
37 if(!domDocument.setContent(&gcard))
40 cout <<
" >> gcard format for file <" << file <<
"> is wrong - check XML syntax. Exiting." << endl;
49 optMap[
"gcard"].args = file;
52 QDomElement docElem = domDocument.documentElement();
55 map<string, int> count;
56 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
57 count[itm->first] = 0;
60 n = docElem.firstChild();
63 QDomElement e = n.toElement();
65 if(e.tagName().toStdString() ==
"option")
68 for(map<string, aopt>::iterator itm =
optMap.begin();itm !=
optMap.end(); itm++)
72 if(e.attributeNode(
"name").value().toStdString() == itm->first )
76 count[itm->first] += 1;
79 if(count[itm->first] == 1)
81 itm->second.args = e.attributeNode(
"value").value().toStdString();
82 itm->second.arg =
stringToDouble(e.attributeNode(
"value").value().toStdString());
84 itm->second.printSetting();
89 string new_opt = itm->first +
"__REPETITION__" +
stringify(count[itm->first] - 1);
90 optMap[new_opt].args = e.attributeNode(
"value").value().toStdString();
92 optMap[new_opt].name = itm->second.name;
93 optMap[new_opt].help = itm->second.help;
94 optMap[new_opt].type = itm->second.type;
95 optMap[new_opt].ctgr = itm->second.ctgr;
96 optMap[new_opt].repe = count[itm->first];
97 optMap[new_opt].printSetting();
104 cout <<
" !! Error: The option in the gcard file " 105 << e.attributeNode(
"name").value().toStdString()
106 <<
" is not known to this system. Please check your spelling." << endl;
112 QDomNode nn= e.firstChild();
113 while( !nn.isNull() && e.tagName().toStdString() ==
"option")
115 QDomElement ee = nn.toElement();
117 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
119 if(ee.tagName().toStdString() == itm->first )
121 itm->second.args= ee.attributeNode(
"value").value().toStdString();
122 itm->second.arg =
stringToDouble(ee.attributeNode(
"value").value().toStdString());
123 itm->second.printSetting();
129 cout <<
" !! Error: The option in the gcard file " 130 << e.attributeNode(
"name").value().toStdString()
131 <<
" is not known to this system. Please check your spelling." << endl;
134 nn = nn.nextSibling();
152 for(
int i=1;i<argc;i++)
154 string arg = argv[i];
155 pos = arg.find(
"gcard=");
156 if(pos != string::npos)
163 for(
int i=1;i<argc;i++)
165 string arg = argv[i];
166 pos = arg.find(
".gcard");
167 if(pos != string::npos)
169 ifstream my_file(argv[i]);
178 set<string> category;
180 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
181 if(category.find(itm->second.ctgr) == category.end()) category.insert(itm->second.ctgr);
186 for(
int i=1; i<argc; i++)
188 string arg = argv[i];
189 string com =
"-help-all";
192 cout <<
" Usage: -Option=<option>" << endl << endl;
193 cout <<
" Options:" << endl << endl ;
195 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
196 cout <<
" > Option " << itm->first <<
": " << itm->second.help << endl;
198 cout << endl << endl;
205 for(
int i=1; i<argc; i++)
207 string arg = argv[i];
208 string com1 =
"-help";
210 if(arg == com1 || arg == com2)
212 cout << endl << endl;
213 cout <<
" Help Options:" << endl << endl ;
214 cout <<
" > -help-all: all available options. " << endl << endl;
215 for(set<string>::iterator itcat = category.begin(); itcat != category.end(); itcat++)
217 cout <<
" > -help-" << *itcat <<
" ";
219 cout << *itcat <<
" options." << endl;
221 cout << endl << endl;
228 for(
int i=1; i<argc; i++)
230 string arg = argv[i];
231 for(set<string>::iterator itcat = category.begin(); itcat != category.end(); itcat++)
233 string com =
"-help-" + *itcat;
236 cout << endl << endl <<
" ## " << *itcat <<
" ## " << endl << endl;
237 cout <<
" Usage: -Option=<option>" << endl << endl;
238 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
239 if(itm->second.ctgr == *itcat)
240 cout <<
" > " << itm->first <<
": " << itm->second.help << endl;
241 cout << endl << endl;
249 for(
int i=1; i<argc; i++)
251 string arg = argv[i];
252 for(set<string>::iterator itcat = category.begin(); itcat != category.end(); itcat++)
254 string com =
"-help-html";
258 hf.open(
"options.html");
259 hf <<
"<html>" << endl;
260 hf <<
" <STYLE TYPE=\"text/css\">" << endl;
261 hf <<
"<!--" << endl;
262 hf <<
".pretty-table" << endl;
264 hf <<
" padding: 0;" << endl;
265 hf <<
" margin: 0;" << endl;
266 hf <<
" border-collapse: collapse;" << endl;
267 hf <<
" border: 1px solid #333;" << endl;
268 hf <<
" font-family: \"Trebuchet MS\", Verdana, Arial, Helvetica, sans-serif;" << endl;
269 hf <<
" font-size: 0.8em;" << endl;
270 hf <<
" color: #000;" << endl;
271 hf <<
" background: #bcd0e4;" << endl;
273 hf <<
".pretty-table caption" << endl;
275 hf <<
" caption-side: bottom;" << endl;
276 hf <<
" font-size: 0.9em;" << endl;
277 hf <<
" font-style: italic;" << endl;
278 hf <<
" text-align: right;" << endl;
279 hf <<
" padding: 0.5em 0;" << endl;
281 hf <<
".pretty-table th, .pretty-table td" << endl;
283 hf <<
" border: 1px dotted #666;" << endl;
284 hf <<
" padding: 0.5em;" << endl;
285 hf <<
" text-align: left;" << endl;
286 hf <<
" color: #632a39;" << endl;
288 hf <<
".pretty-table th[scope=col]" << endl;
290 hf <<
" color: #000;" << endl;
291 hf <<
" background-color: #8fadcc;" << endl;
292 hf <<
" text-transform: uppercase;" << endl;
293 hf <<
" font-size: 0.9em;" << endl;
294 hf <<
" border-bottom: 2px solid #333;" << endl;
295 hf <<
" border-right: 2px solid #333;" << endl;
297 hf <<
".pretty-table th+th[scope=col]" << endl;
299 hf <<
" color: #009;" << endl;
300 hf <<
" background-color: #7d98b3;" << endl;
301 hf <<
" border-right: 1px dotted #666;" << endl;
303 hf <<
".pretty-table th[scope=row]" << endl;
305 hf <<
" background-color: #b8cfe5;" << endl;
306 hf <<
" border-right: 2px solid #333;" << endl;
308 hf <<
"pre{font-family:Helvetica;font-size:12pt}" << endl;
310 hf <<
"--->" << endl;
311 hf <<
"</STYLE>" << endl;
312 hf <<
"</head>" << endl;
313 hf <<
"<body>" << endl;
314 hf <<
"<br><br>" << endl;
315 hf <<
"<center>" << endl;
316 hf <<
"<h1> GEMC options</h1>" << endl;
317 hf <<
"</center>" << endl;
318 hf <<
"<br><br><br>" << endl;
319 hf <<
"<table cellsize=20>" << endl;
320 hf <<
"<tr><td>" << endl;
321 hf <<
"<table class=\"pretty-table\">" << endl;
322 hf <<
"<caption>options. This table is produced with the option: -help-html </caption>" << endl;
323 hf <<
"<tr><th scope=\"col\" >Category</th>" << endl;
324 hf <<
" <th scope=\"col\" >Option</th>" << endl;
325 hf <<
" <th scope=\"col\" >Help</th></tr>" << endl;
326 for(set<string>::iterator itcat = category.begin(); itcat != category.end(); itcat++)
327 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
328 if(itm->second.ctgr == *itcat)
330 hf <<
"<tr><th scope=\"row\">";
335 hf <<
"</td><td><pre>" << endl;
336 hf << itm->second.help;
337 hf <<
"</pre></td></tr>" << endl;
340 hf <<
"</table>" << endl;
341 hf <<
"</td>" << endl;
342 hf <<
"<td>" << endl;
343 hf <<
"</table>" << endl;
344 hf <<
" </body></html>";
354 map<string, int> count;
355 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
357 if(itm->second.repe == 0)
358 count[itm->first] = 0;
360 count[itm->first] = itm->second.repe;
363 for(
int i=1; i<argc; i++)
365 string arg = argv[i];
367 for(map<string, aopt>::iterator itm =
optMap.begin(); itm !=
optMap.end(); itm++)
369 string com =
"-" + itm->first +
"=";
372 comp.assign(arg, 0, arg.find(
"=") + 1);
375 ifstream my_file(argv[i]);
382 count[itm->first] += 1;
385 opts.assign(arg, com.size(), arg.size()-com.size());
388 if(count[itm->first] == 1)
390 itm->second.args = opts;
392 itm->second.printSetting();
396 if(count[itm->first]>1)
398 string new_opt = itm->first +
"__REPETITION__" +
stringify(count[itm->first]-1);
399 optMap[new_opt].args = opts;
401 optMap[new_opt].name = itm->second.name;
402 optMap[new_opt].help = itm->second.help;
403 optMap[new_opt].type = itm->second.type;
404 optMap[new_opt].ctgr = itm->second.ctgr;
405 optMap[new_opt].repe = count[itm->first];
406 optMap[new_opt].printSetting();
415 if( found == 0 && strncmp(argv[i],
"-psn_", 4) !=0 &&
ignoreNotFound == 0)
417 cout <<
" The argument " << argv[i] <<
" is not known to this system / or file not found. Continuing anyway.\n\n";
430 map<string, int> count;
431 for(map<string, aopt>::iterator itm =
optMap.begin();itm !=
optMap.end(); itm++)
433 if(itm->first.find(opt) != string::npos)
435 options.push_back(itm->second);
446 map<string, string> optmap;
448 for(map<string, aopt>::iterator it =
optMap.begin(); it !=
optMap.end(); it++)
450 string key =
"option " + it->first;
451 if(it->second.type == 0) optmap[key] =
stringify(it->second.arg);
452 else optmap[key] = it->second.args;
464 if(name.find(
"gemc card file") != string::npos)
return;
467 cout <<
" > " << name <<
" set to: ";
468 if(type) cout << args;
map< string, string > getOptMap()
Returns a map<string, string> with all options and values.
vector< aopt > getArgs(string)
get a vector of arguments matching a string
int setOptMap(int argc, char **args)
Sets map from command line arguments.
string stringify(double x)
map< string, aopt > optMap
Options map.
double stringToDouble(string v)
void scanGcard(string file)
Scan option file for options.