]> git.donarmstrong.com Git - lilypond.git/blob - flower/lgetopt.hh
67deb700bc703fd24e17ed14849ee75d2c3c08ba
[lilypond.git] / flower / lgetopt.hh
1 #ifndef LGETOPT_HH
2 #define LGETOPT_HH
3
4 #include <string.h>
5
6
7 class ostream;
8
9 struct long_option_init {
10     bool take_arg;
11     const char* longname;
12     char        shortname;
13
14     ostream &printon(ostream &errorout);
15 };
16
17
18 ///  C++ for version of long_getopt.
19 /** For processing GNU style command line arguments.  No pointer
20   (return values, arguments) contents are 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 } ;
27
28
29 private:
30
31     /// the option info.
32     long_option_init *the_opts;
33     int table_len;
34     
35     /// if doing short option, argv[optind][optindind] is processed next.
36     int optindind;
37
38     /// the option found
39     long_option_init *beet;
40
41     /// get ready for processing next error.
42     bool next();
43     long_option_init *parselong();
44     long_option_init *parseshort();
45     
46     ostream *errorout;
47
48     /// report an error and abort
49     void report(Errorcod c);
50 public:
51     /// what to do with  errors
52     /**
53        report messages on  #*os#, and abort.
54        if #os# is null, then do not report nor abort, just set #error#
55       */
56        
57     void seterror(ostream *os);
58     /// argument. Set to 0 if not present
59     char* optarg;
60
61
62     /// return an integer (with err. detect)
63     long intarg();
64     /// argv[optind] will be processed next.
65     int optind;
66
67     /// the arguments
68     char **argv;
69
70     /// the arg. count
71     int argc;
72     
73     /// construct: pass arguments and option info.
74     Getopt_long(int c,  char **v, long_option_init *lo);
75
76     /// get the next option
77     /**
78       @return pointer to next option found.
79       0 if error occurred, or next argument is no option.
80       */
81     long_option_init *operator()();
82
83     char *current_arg();
84     char * get_next_arg();
85     Errorcod error;
86 };
87 #endif