flower-1.0.27
[lilypond.git] / flower / lgetopt.hh
blob31fb2c55ebe609b4d9e778f45b417f450577d83f
1 #ifndef LGETOPT_HH
2 #define LGETOPT_HH
4 #include <string.h>
7 class ostream;
9 struct long_option_init {
10 bool take_arg;
11 const char* longname;
12 char shortname;
14 ostream &printon(ostream &errorout);
18 /** C++ for version of long_getopt. For processing GNU style command
19 line arguments. No pointer (return values, arguments) contents are
20 copied. */
21 class Getopt_long {
22 public:
23 /** errorcodes: no error, argument expected, no argument expected,
24 unknown option, illegal argument (eg. int expected). */
25 enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
26 E_ILLEGALARG } ;
29 private:
31 /// the option info.
32 long_option_init *the_opts;
33 int table_len;
35 /// if doing short option, argv[optind][optindind] is processed next.
36 int optindind;
38 /// the option found
39 long_option_init *beet;
41 /// get ready for processing next error.
42 bool next();
43 long_option_init *parselong();
44 long_option_init *parseshort();
46 ostream *errorout;
48 /// report an error and abort
49 void report(Errorcod c);
50 public:
51 /** what to do with errors.
52 report messages on #*os#, and abort.
53 if #os# is null, then do not report nor abort, just set #error#
56 void seterror(ostream *os);
57 /// argument. Set to 0 if not present
58 char* optarg;
61 /// return an integer (with err. detect)
62 long intarg();
63 /// argv[optind] will be processed next.
64 int optind;
66 /// the arguments
67 char **argv;
69 /// the arg. count
70 int argc;
72 /// construct: pass arguments and option info.
73 Getopt_long(int c, char **v, long_option_init *lo);
75 /** get the next option.
76 @return pointer to next option found.
77 0 if error occurred, or next argument is no option.
79 long_option_init *operator()();
81 char *current_arg();
82 char * get_next_arg();
83 Errorcod error;
85 #endif