]> Creatis software - clitk.git/blob - utilities/gengetopt/gm.h
Debug RTStruct conversion with empty struc
[clitk.git] / utilities / gengetopt / gm.h
1 /**
2  * Copyright (C) 1999-2007  Free Software Foundation, Inc.
3  *
4  * This file is part of GNU gengetopt
5  *
6  * GNU gengetopt is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * GNU gengetopt is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with gengetopt; see the file COPYING. If not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef _GM_H
22 #define _GM_H
23
24 #include "skels/header.h"
25 #include "skels/c_source.h"
26
27 #include <list>
28 #include <string>
29
30 #define TAB_LEN 2
31
32 struct gengetopt_option;
33
34 typedef std::list<std::string> OptionHelpList;
35
36 class CmdlineParserCreator : public header_gen_class, public c_source_gen_class
37 {
38  protected:
39   char *parser_function_name;
40   char *filename;
41   char *args_info_name;
42   char *header_filename;
43   char *c_filename;
44   string output_dir;
45   string header_output_dir;
46   string src_output_dir;
47   string comment;
48   char *unamed_options;
49   string show_required_string;
50
51   bool long_help;
52   bool no_handle_help;
53   bool no_help;
54   bool no_handle_version;
55   bool no_version;
56   bool no_handle_error;
57   bool conf_parser;
58   bool string_parser;
59   bool gen_gengetopt_version;
60   bool gen_strdup;
61
62   unsigned int tab_indentation ; /* tab indentation level */
63
64   void inc_indent()
65     {
66       tab_indentation += TAB_LEN ;
67     }
68
69   void dec_indent()
70     {
71       tab_indentation -= TAB_LEN ;
72     }
73
74   void indent()
75     {
76       unsigned int i ;
77
78       for ( i = 1 ; i <= tab_indentation ; ++i )
79         printf (" ");
80     }
81
82   void free_option(struct gengetopt_option *opt,
83                    ostream &stream, unsigned int indent);
84
85   int generate_header_file();
86   int generate_source();
87
88   string generate_getopt_string();
89
90   // to be implemented in header_gen_class
91   virtual void generate_enum_types(ostream &stream, unsigned int indent);
92   virtual void generate_option_arg(ostream &stream, unsigned int indent);
93   virtual void generate_option_given(ostream &stream, unsigned int indent);
94   virtual void generate_option_values_decl(ostream &stream, unsigned int indent);
95
96   // to be implemented in c_source_gen_class
97   virtual void generate_clear_arg(ostream &stream, unsigned int indent);
98   virtual void generate_given_init(ostream &stream, unsigned int indent);
99   virtual void generate_option_values(ostream &stream, unsigned int indent);
100
101   virtual void generate_handle_no_short_option(ostream &stream,
102                                                unsigned int indent);
103   virtual void generate_handle_option(ostream &stream, unsigned int indent);
104   virtual void generate_handle_required(ostream &stream, unsigned int indent);
105   virtual void generate_handle_dependencies(ostream &stream, unsigned int indent);
106   virtual void generate_handle_group(ostream &stream, unsigned int indent);
107   virtual void generate_group_counters(ostream &stream, unsigned int indent);
108   virtual void generate_mode_counters(ostream &stream, unsigned int indent);
109   virtual void generate_help_option_print(ostream &stream,
110                                           unsigned int indent);
111   virtual void generate_full_help_option_print(ostream &stream,
112                                           unsigned int indent);
113   virtual void generate_detailed_help_option_print(ostream &stream,
114                                           unsigned int indent);
115   virtual void generate_long_option_struct(ostream &stream,
116                                            unsigned int indent);
117   virtual void generate_reset_groups(ostream &stream, unsigned int indent);
118
119   virtual void generate_free(ostream &stream, unsigned int indent);
120   virtual void generate_list_free(ostream &stream, unsigned int indent);
121
122   virtual void generate_file_save_loop(ostream &stream, unsigned int indent);
123   virtual void generate_init_args_info(ostream &stream, unsigned int indent);
124
125   virtual void generate_custom_getopt(ostream &stream, unsigned int indent);
126
127   void generateBreak(ostream &stream, unsigned int indent = 0);
128
129   void handle_options(ostream &, unsigned int, bool has_short);
130
131  public:
132
133   CmdlineParserCreator (char *function_name, char *struct_name,
134                         char *unamed_options,
135                         char *filename, char *header_ext, char *c_ext,
136                         bool long_help,
137                         bool no_handle_help, bool no_help,
138                         bool no_handle_version, bool no_version,
139                         bool no_handle_error, bool conf_parser, bool string_parser,
140                         bool gen_version, bool gen_getopt, bool no_options,
141                         const string &comment,
142                         const string &outdir,
143                         const string &header_outdir,
144                         const string &src_outdir,
145                         const string &show_required);
146
147   int generate();
148
149   virtual void generate_list_def(ostream &stream, unsigned int indent);
150   virtual void generate_multiple_fill_array(ostream &stream, unsigned int indent);
151   virtual void generate_update_multiple_given(ostream &stream, unsigned int indent);
152   virtual void generate_check_modes(ostream &stream, unsigned int indent);
153
154   const string generate_purpose();
155   const string generate_description();
156   const string generate_usage_string(bool use_config_package = true);
157
158   /**
159    * generate a list of option descriptions that will be printed in the
160    * help output
161    * 
162    * @param generate_hidden if true, include also the hidden options
163    * @param generate_details if true, include also the hidden options and
164    * details for options that have them.
165    */
166   OptionHelpList *generate_help_option_list(bool generate_hidden = false,
167           bool generate_details = false);
168   
169   /**
170    * generate the sharing between a list of help string, using the
171    * complete_list as the list with all the strings (both for hidden
172    * options and details, e.g.) and the smaller_list as the list
173    * with less strings
174    * 
175    * @param target_array the name of the array to copy to
176    * @param source_array the name of the array to copy from
177    */
178   void generate_help_option_print_from_lists(ostream &stream,
179           unsigned int indent, OptionHelpList *complete_list,
180           OptionHelpList *smaller_list, const std::string &target_array,
181           const std::string &source_array);
182   
183   /**
184    * Sets the has_arg_XXX by inspecting all the options types
185    */
186   void set_has_arg_types();
187 };
188
189 #endif /* _GM_H */