[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src/px argp.hh,1.1,1.2 argp.cc,1.2,1.3
From: |
Daniel Heck <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src/px argp.hh,1.1,1.2 argp.cc,1.2,1.3 |
Date: |
Mon, 20 Oct 2003 16:15:36 +0000 |
Update of /cvsroot/enigma/enigma/src/px
In directory subversions:/tmp/cvs-serv1054/src/px
Modified Files:
argp.hh argp.cc
Log Message:
Small enhancements
Index: argp.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/px/argp.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** argp.cc 19 May 2003 12:14:36 -0000 1.2
--- argp.cc 20 Oct 2003 16:15:34 -0000 1.3
***************
*** 25,42 ****
! ArgParser::ArgParser()
! {}
!
! ArgParser::~ArgParser()
! {}
! void ArgParser::on_error (ErrorType t, const std::string &arg)
! {
cerr << "Error: " << errormsg(t, arg) << endl;
}
! void ArgParser::on_argument (const std::string &/*arg*/)
! {
}
--- 25,39 ----
! ArgParser::ArgParser() {
! }
+ ArgParser::~ArgParser(){
+ }
! void ArgParser::on_error (ErrorType t, const std::string &arg) {
cerr << "Error: " << errormsg(t, arg) << endl;
}
! void ArgParser::on_argument (const std::string &/*arg*/) {
}
***************
*** 45,57 ****
}
! void
! ArgParser::def (int id, char abbr, const std::string &name, bool takesparam)
{
m_opts.push_back (Option(id, abbr, string("--") + name, takesparam));
}
! string
! ArgParser::errormsg(ErrorType t, const std::string &arg) const
{
string errmsg;
switch (t) {
--- 42,60 ----
}
! void ArgParser::def (int id, const std::string &name,
! char abbr, bool takesparam)
{
m_opts.push_back (Option(id, abbr, string("--") + name, takesparam));
}
! void ArgParser::def (bool *boolvar, const std::string &name,
! char abbr)
{
+ Option opt(-1, abbr, string("--") + name, false);
+ opt.boolvar = boolvar;
+ m_opts.push_back(opt);
+ }
+
+ string ArgParser::errormsg(ErrorType t, const std::string &arg) const {
string errmsg;
switch (t) {
***************
*** 68,74 ****
}
! void
! ArgParser::getlongopt (const std::string &arg)
! {
string::const_iterator eqpos = find(arg.begin(), arg.end(), '=');
string optname(arg.begin(), eqpos);
--- 71,82 ----
}
! void ArgParser::process_option(Option &opt, const std::string ¶m) {
! if (opt.boolvar)
! *opt.boolvar = true;
! else
! on_option(opt.id, param);
! }
!
! void ArgParser::getlongopt (const std::string &arg) {
string::const_iterator eqpos = find(arg.begin(), arg.end(), '=');
string optname(arg.begin(), eqpos);
***************
*** 85,92 ****
else if (i->takesparam) {
if (eqpos != arg.end()) {
! on_option (i->id, string(eqpos+1, arg.end()));
}
else if (!m_arglist.empty()) {
! on_option (i->id, m_arglist.front());
m_arglist.pop_front();
}
--- 93,100 ----
else if (i->takesparam) {
if (eqpos != arg.end()) {
! process_option (*i, string(eqpos+1, arg.end()));
}
else if (!m_arglist.empty()) {
! process_option (*i, m_arglist.front());
m_arglist.pop_front();
}
***************
*** 98,107 ****
}
else
! on_option(i->id, "");
}
! void
! ArgParser::getshortopt (const std::string &arg)
! {
option_iterator i = m_opts.begin();
for (; i != m_opts.end(); ++i)
--- 106,113 ----
}
else
! process_option(*i, "");
}
! void ArgParser::getshortopt (const std::string &arg) {
option_iterator i = m_opts.begin();
for (; i != m_opts.end(); ++i)
***************
*** 120,132 ****
param = m_arglist.front();
m_arglist.pop_front();
! on_option (i->id, param);
}
else
on_error (MissingParam, option);
} else
! on_option (i->id, param);
}
else {
! on_option (i->id, "");
// The following characters can be options in their own right
--- 126,138 ----
param = m_arglist.front();
m_arglist.pop_front();
! process_option (*i, param);
}
else
on_error (MissingParam, option);
} else
! process_option (*i, param);
}
else {
! process_option (*i, "");
// The following characters can be options in their own right
***************
*** 140,149 ****
}
! void
! ArgParser::parse ()
! {
bool no_more_opts = false;
! while (!m_arglist.empty())
! {
std::string arg = m_arglist.front();
m_arglist.pop_front();
--- 146,152 ----
}
! void ArgParser::parse () {
bool no_more_opts = false;
! while (!m_arglist.empty()) {
std::string arg = m_arglist.front();
m_arglist.pop_front();
Index: argp.hh
===================================================================
RCS file: /cvsroot/enigma/enigma/src/px/argp.hh,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** argp.hh 19 Jan 2003 17:19:32 -0000 1.1
--- argp.hh 20 Oct 2003 16:15:34 -0000 1.2
***************
*** 69,74 ****
}
! /* Define a new option and return the corresponding . */
! void def (int id, char abbr, const std::string &name, bool param =
false);
/* Parse all command line arguments, calling the appropriate
--- 69,75 ----
}
! /* Define a new option. */
! void def (int id, const std::string &name, char abbr = 0, bool param
= false);
! void def (bool *boolvar, const std::string &name, char abbr = 0);
/* Parse all command line arguments, calling the appropriate
***************
*** 81,85 ****
struct Option {
Option (int id_, char s='\0', const std::string& l="", bool
param=false)
! : id(id_), shortopt(s), longopt(l), takesparam(param)
{}
--- 82,86 ----
struct Option {
Option (int id_, char s='\0', const std::string& l="", bool
param=false)
! : id(id_), shortopt(s), longopt(l), takesparam(param),
boolvar(0)
{}
***************
*** 88,91 ****
--- 89,93 ----
std::string longopt;
bool takesparam;
+ bool *boolvar;
};
***************
*** 99,102 ****
--- 101,106 ----
// Private functions.
+ void process_option(Option &opt, const std::string ¶m);
+
void getlongopt (const std::string& arg);
void getshortopt (const std::string& arg);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src/px argp.hh,1.1,1.2 argp.cc,1.2,1.3,
Daniel Heck <address@hidden> <=
- Prev by Date:
[Enigma-cvs] enigma/etc mingw32-dist.sh.in,1.1,1.2
- Next by Date:
[Enigma-cvs] enigma/src stones_simple.cc, 1.55, 1.56 objects.hh, 1.51, 1.52 main.cc, 1.22, 1.23 levels.hh, 1.1, 1.2 gui.hh, 1.14, 1.15 floors.cc, 1.1, 1.2
- Previous by thread:
[Enigma-cvs] enigma/etc mingw32-dist.sh.in,1.1,1.2
- Next by thread:
[Enigma-cvs] enigma/src stones_simple.cc, 1.55, 1.56 objects.hh, 1.51, 1.52 main.cc, 1.22, 1.23 levels.hh, 1.1, 1.2 gui.hh, 1.14, 1.15 floors.cc, 1.1, 1.2
- Index(es):