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