1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

working on arg parsing

This commit is contained in:
Lu Wang 2012-09-10 22:44:19 +08:00
parent 03779406b8
commit d49dbc3deb
2 changed files with 22 additions and 6 deletions

View File

@ -76,9 +76,9 @@ void ArgParser::parse(int argc, char ** argv) const
longopts.push_back({0,0,0,0});
{
opterr = 1;
int r;
int idx;
opterr = 0;
while(true)
{
r = getopt_long(argc, argv, &optstring.front(), &longopts.front(), &idx);
@ -87,9 +87,7 @@ void ArgParser::parse(int argc, char ** argv) const
assert(r != ':');
if(r == '?')
{
ostringstream sout;
assert(optopt < 256);
throw string() + ((opt_map.find(optopt) == opt_map.end()) ? "Unknown option: -" : "Missing argument for option -") + (char)optopt;
throw "";
}
auto iter = opt_map.find(r);

View File

@ -89,10 +89,24 @@ void parse_options (int argc, char **argv)
{
argparser.parse(argc, argv);
}
catch(const std::string & s)
catch(const char * s)
{
// if s == "", getopt_long would have printed the error message
if(s && s[0])
{
cerr << "Error when parsing the arguments:" << endl;
cerr << s << endl;
}
exit(EXIT_FAILURE);
}
catch(const std::string & s)
{
// if s == "", getopt_long would have printed the error message
if(s != "")
{
cerr << "Error when parsing the arguments:" << endl;
cerr << s << endl;
}
exit(EXIT_FAILURE);
}
}
@ -181,6 +195,10 @@ int main(int argc, char **argv)
finished = true;
}
catch (const char * s)
{
cerr << "Error: " << s << endl;
}
catch (const string & s)
{
cerr << "Error: " << s << endl;