From 9852b855db2a65ea6eb5e877411634820214ddf0 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sat, 16 Mar 2024 11:21:23 -0700 Subject: initial setup --- src/Getopt.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Getopt.cxx (limited to 'src/Getopt.cxx') diff --git a/src/Getopt.cxx b/src/Getopt.cxx new file mode 100644 index 0000000..49673bc --- /dev/null +++ b/src/Getopt.cxx @@ -0,0 +1,31 @@ +////////////////////////////////////////////////////////////////////// +// Provide a C++ interface to getopt. +// Calculate things that can be calculated, to ensure consistency, +// and so the programmer doesn't need to duplicate effort. + +using namespace std; + +#include /* needed by some compilers */ +#include "Getopt.h" +#include +#include + +int getopt_long(int argc, char * const argv[], + const struct option *longopts, int *longindex){ + + string optstring; + const struct option * pp; + for (pp = longopts; pp->name; pp++){ + if (pp->val < 0 || pp->val > 255) { + cerr << "Cannot handle val " << pp->val + << " for option '" << pp->name << "'" << endl; + } else { +// cerr << pp->name << "'" << char(pp->val) << "'" << endl; + optstring += char(pp->val); + if (pp->has_arg == 1) optstring += ':'; + if (pp->has_arg == 2) optstring += "::"; + } + } +// cerr << optstring << endl; + return getopt_long(argc, argv, optstring.c_str(), longopts, longindex); +} -- cgit v1.2.3