/*********************************************************************** OPTARGPM - a header-only library for decoding PROJ.4 style command line options Thomas Knudsen, 2017-09-10 ************************************************************************ For PROJ.4 command line programs, we have a somewhat complex option decoding situation, since we have to navigate in a cocktail of classic single letter style options, prefixed by "-", GNU style long options prefixed by "--", transformation specification elements prefixed by "+", and input file names prefixed by "" (i.e. nothing). Hence, classic getopt.h style decoding does not cut the mustard, so this is an attempt to catch up and chop the ketchup. Since optargpm (for "optarg plus minus") does not belong, in any obvious way, in any systems development library, it is provided as a "header only" library. While this is conventional in C++, it is frowned at in plain C. But frown away - "header only" has its places, and this is one of them. By convention, we expect a command line to consist of the following elements: [short ("-")/long ("--") options} [operator ("+") specs] [operands/input files] or less verbose: [options] [operator specs] [operands] or less abstract: proj -I --output=foo +proj=utm +zone=32 +ellps=GRS80 bar baz... Where Operator is proj Options are -I --output=foo Operator specs are +proj=utm +zone=32 +ellps=GRS80 Operands are bar baz While neither claiming to save the world, nor to hint at the "shape of jazz to come", at least optargpm has shown useful in constructing cs2cs style transformation filters. Supporting a wide range of option syntax, the getoptpm API is somewhat quirky, but also compact, consisting of one data type, 3(+2) functions, and one enumeration: OPTARGS Housekeeping data type. An instance of OPTARGS is conventionally called o or opt opt_parse (opt, argc, argv ...): The work horse: Define supported options; Split (argc, argv) into groups (options, op specs, operands); Parse option arguments. opt_given (o, option): The number of times