/* Copyright (C) 2000 Daniel Heck dheck@ix.urz.uni-heidelberg.de */ #include #include #include #include #include "argp.hh" enum EOptions { OPT_Argument, OPT_Help, OPT_Version, OPT_Verbose, OPT_Output, OPT_Error }; int main(int argc, char *argv[]) { argp ap(OPT_Argument, OPT_Error); ap.def(OPT_Help, 'h', "help"); ap.def(OPT_Verbose, 'v', "verbose"); ap.def(OPT_Version, 0, "version"); ap.def(OPT_Output, 'o', "output", true); ap.feed(argv + 1, argv + argc); bool show_help = false; bool verbose_flag = false; bool show_version = false; list ofiles; list ifiles; argp::option opt; while (ap.getopt(opt)) { switch (opt.id) { case OPT_Argument: ifiles.push_back(opt.param); break; case OPT_Help: show_help = true; break; case OPT_Verbose: verbose_flag = true; break; case OPT_Version: show_version = true; break; case OPT_Output: ofiles.push_back(opt.param); break; case OPT_Error: if (ap.invalidparam()) cout << "Invalid parameter for option `" << opt.param << "'.\n"; else if (ap.ambiguousopt()) cout << "Ambiguous command line option `" << opt.param << "'.\n"; else if (ap.unknownopt()) cout << "Unknown command line option `" << opt.param << "'.\n"; else if (ap.missingparam()) cout << "Missing parameter for option `" << opt.param << "'.\n"; break; } } cout << "show_help : " << show_help << endl; cout << "show_version: " << show_version << endl; cout << "verbose_flag: " << verbose_flag << endl; cout << "output_file: "; copy(ofiles.begin(), ofiles.end(), ostream_iterator(cout, " ")); cout << endl; cout << "input files: "; copy(ifiles.begin(), ifiles.end(), ostream_iterator(cout, " ")); cout << endl; }