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:
parent
03779406b8
commit
d49dbc3deb
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user