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