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