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