32 std::ostringstream msg;
42 msg <<
"--" << std::setiosflags (std::ios::left)
46 msg << std::setiosflags (std::ios::left) << std::setw (14) <<
" ";
53 msg << std::setiosflags (std::ios::left) << std::setw(7) <<
"string";
54 msg <<
"] = '" << *(
string*)
m_val <<
"'";
58 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"int";
59 msg <<
"] = " << *(
int*)
m_val;
63 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"u_int";
64 msg <<
"] = " << *(
int*)
m_val;
68 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"long";
69 msg <<
"] = " << *(
long*)
m_val;
73 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"u_long";
74 msg <<
"] = " << *(
long*)
m_val;
78 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"double";
79 msg <<
"] = " << *(
double*)
m_val;
83 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"float";
84 msg <<
"] = " << *(
float*)
m_val;
88 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"bool";
89 msg <<
"] = " << *(
bool*)
m_val ?
"true" :
"false";
93 msg << std::setiosflags(std::ios::left)
94 << std::setw(7) <<
"function ()";
99 msg << std::setiosflags(std::ios::left)
100 << std::setw(7) <<
"function (opt)";
105 msg << std::setiosflags(std::ios::left) << std::setw(7) <<
"none";
110 msg << std::setiosflags(std::ios::left)
111 << std::setw(7) <<
"--undef--";
137 default: ret =
"--undef--";
150 OptionSet::const_iterator i;
153 if (sopt_ ==
'\0' && lopt_.empty ()) {
154 m_error =
"Ignore empty option";
157 else if (sopt_ !=
'\0' && i->m_short_name == sopt_) {
158 m_error =
"Ignored multiple option '-";
159 m_error += sopt_ + string (
"'");
162 else if (!lopt_.empty () && i->m_long_name == lopt_) {
163 m_error =
"Ignore multiple option '--";
164 m_error += lopt_ + string (
"'");
177 OptionSet::iterator i;
181 if (i->m_long_name == str_) {
194 OptionSet::iterator i;
198 if (i->m_short_name == letter_)
220 add_opt (
const char sopt_,
const string& lopt_,
string* v_)
234 add_opt (
const char sopt_,
const string& lopt_,
int* v_)
248 add_opt (
const char sopt_,
const string& lopt_,
unsigned int* v_)
262 add_opt (
const char sopt_,
const string& lopt_,
long* v_)
276 add_opt (
const char sopt_,
const string& lopt_,
unsigned long* v_)
290 add_opt (
const char sopt_,
const string& lopt_,
double* v_)
304 add_opt (
const char sopt_,
const string& lopt_,
float* v_)
318 add_opt (
const char sopt_,
const string& lopt_, OPTS_FUNC v_)
332 add_opt (
const char sopt_,
const string& lopt_, OPTS_FUNC_ONE v_)
346 rm_opt (
const char sopt_,
const string& lopt_)
350 OptionSet::iterator i;
354 if (i->m_short_name == sopt_ || i->m_long_name == lopt_)
369 register int skip = 1;
370 bool pos_args_started =
false;
376 for (argv_++; argv_[0]; argv_ += skip) {
383 if (pos_args_started) {
386 if (token[0] ==
'-' && token.size () != 1) {
387 m_error =
"Invalid order of arguments: '";
396 if (token[0] ==
'-' && token.size () > 1 && token[1] !=
'-') {
397 if (token.size () == 1 && !pos_args_started) {
399 pos_args_started =
true;
404 if (token.size () > 2) {
412 param = token.substr (2);
418 if (token.size () > 1 && token[1] ==
'-') {
419 string op = token.substr (2);
422 if ((pos = op.find (
"=")) != (
size_t)-1) {
423 param = op.substr (pos+1, op.length ());
424 op.replace (pos, op.length() - pos,
"");
430 pos_args_started =
true;
436 m_error =
"Invalid option '" + token +
"'.";
443 if (param.empty ()) {
445 m_error =
"Expecting parameter after '"
446 + string (argv_[0]) +
"'.";
460 if (param.empty ()) {
461 if (!
assign (node, argv_[1])) {
466 const char* str = param.c_str ();
467 if (!
assign (node, str)) {
475 return !
m_error.empty () ? false :
true;
496 unsigned int count = 0;
499 string optsect_name (
"options");
500 OptionSet::iterator pos =
m_opts_set.begin ();
504 optsect_name =
"Options";
507 optsect_name =
"OPTIONS";
510 m_error =
"Missing [options] section in INI file!";
517 if (pos->m_long_name.size ()) {
518 s = pos->m_long_name;
521 v = inifile_.
get_value (optsect_name, s);
523 if (
assign (&(*pos), v.c_str ())) {
560 *(
string*) node_->
m_val = op_;
566 l = strtol (op_, NULL, 0);
569 m_error =
"Error: '" + string (strerror (errno)) +
"',";
570 m_error +=
" in converting to integer from '";
571 m_error += string (op_) +
"'.";
576 *(
int*) node_->
m_val = int (l);
579 *(
long*) node_->
m_val = l;
586 l = strtol (op_, NULL, 0);
589 m_error =
"Error: '" + string (strerror (errno)) +
"',";
590 m_error +=
" in converting to unsigned integer from '";
591 m_error += string (op_) +
"'.";
596 *(
unsigned int*) node_->
m_val = int (l);
599 *(
unsigned long*) node_->
m_val = l;
606 d = strtod (op_, NULL);
609 m_error =
"Error: '" + string (strerror (errno)) +
"',";
610 m_error +=
" in converting to double/float from '";
611 m_error += string (op_) +
"'.";
616 *(
double*) node_->
m_val = d;
619 *(
float*) node_->
m_val = float (d);
624 *(
bool*) node_->
m_val =
true;
637 m_error =
"Undefined type for option '"+string (op_)+
"'.";
648 OptionSet::const_iterator i;
665 std::vector<string> vs;
666 std::istringstream input (src_);
669 while (input >> token) {
670 vs.push_back (token);
677 argv_ =
new char* [vs.size() + 1];
678 std::vector<string>::iterator it;
680 for (it = vs.begin (); it != vs.end (); it++, i++) {
681 p =
new char [it->size() + 1];
682 strcpy (p, it->c_str ());
683 p[it->size()] =
'\0';
704 for (
int i = 0; argv_[i]; i++) {