release commit
[lilypond.git] / flower / include / getopt-long.hh
bloba909326d4cc455c06d1c8cf1661bcb1e4a4dafb2
1 #ifndef GETOPT_LONG_HH
2 #define GETOPT_LONG_HH
5 #include "string.hh"
7 /**
8 a struct this for initialising the commandline options.
9 */
10 struct Long_option_init {
11 char const * take_arg_str0_;
12 char const * longname_str0_;
13 char shortname_char_;
15 char const * help_str0_;
17 String to_string () const;
18 String str_for_help () const;
19 // NO constructor!
21 static int compare (Long_option_init const&,Long_option_init const&);
22 static String table_string (Long_option_init *);
26 /** C++ for version of long_getopt. For processing GNU style command
27 line arguments. No pointer (return values, arguments) contents are
28 copied.
30 TODO: handle
31 command - , and command --
33 argument reordering
35 class Getopt_long {
37 /// the option info.
38 const Long_option_init *option_a_;
39 int table_len_;
41 /// if doing short option, arg_value_char_a_a_[optind][optindind] is processed next.
42 int argument_index_;
44 /// the option found
45 const Long_option_init *found_option_;
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 } ;
54 /// argument. Set to 0 if not present
55 char const * optional_argument_str0_;
57 /// current error status
58 Errorcod error_;
60 /// arg_value_char_a_a_[array_index_] will be processed next.
61 int array_index_;
63 /// the arguments
64 char **arg_value_char_a_a_;
66 /// the arg. count
67 int argument_count_;
69 FILE *error_out_;
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;
79 /// report an error and abort
80 void report (Errorcod c);
83 /// return an integer (with err. detect)
84 long get_argument_index ();
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#
93 void seterror (FILE *os);
95 /// construct: pass arguments and option info.
96 Getopt_long (int c, char **v, Long_option_init *lo);
98 /** get the next option.
99 @return pointer to next option found.
100 0 if error occurred, or next argument is no option.
102 const Long_option_init *operator () ();
104 char const *current_arg ();
105 char const * get_next_arg ();
108 #endif // GETOPT_LONG_HH