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