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