]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/lgetopt.hh
release: 0.0.42.pre3
[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 class Getopt_long {
25 public:
26     /** errorcodes: no error, argument expected, no argument expected,
27       unknown option, illegal argument (eg. int expected).  */
28     enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
29                 E_ILLEGALARG } ;
30
31
32 private:
33
34     /// the option info.
35     Long_option_init *the_opts;
36     int table_len;
37     
38     /// if doing short option, argv[optind][optindind] is processed next.
39     int optindind;
40
41     /// the option found
42     Long_option_init *beet;
43
44     /// get ready for processing next error.
45     bool next();
46     Long_option_init *parselong();
47     Long_option_init *parseshort();
48     
49     ostream *errorout;
50
51     /// report an error and abort
52     void report(Errorcod c);
53 public:
54
55     /// argument. Set to 0 if not present
56     char* optarg;
57
58     /// current error status
59     Errorcod error;
60
61     /// return an integer (with err. detect)
62     long intarg();
63     /// argv[optind] will be processed next.
64     int optind;
65
66     /// the arguments
67     char **argv;
68
69     /// the arg. count
70     int argc;
71     
72     /* *************** */
73     
74     /**
75       What to do with  errors. 
76        report messages on  #*os#, and abort.
77        if #os# is null, then do not report nor abort, just set #error#
78       */
79        
80     void seterror(ostream *os);
81
82     /// construct: pass arguments and option info.
83     Getopt_long(int c,  char **v, Long_option_init *lo);
84
85     /**  get the next option. 
86       @return pointer to next option found.
87       0 if error occurred, or next argument is no option.
88       */
89     Long_option_init *operator()();
90
91     char *current_arg();
92     char * get_next_arg();
93 };
94 #endif