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