2 * Copyright (C) 1999-2007 Free Software Foundation, Inc.
4 * This file is part of GNU gengetopt
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)
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.
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.
24 #include "skels/header.h"
25 #include "skels/c_source.h"
32 struct gengetopt_option;
34 typedef std::list<std::string> OptionHelpList;
36 class CmdlineParserCreator : public header_gen_class, public c_source_gen_class
39 char *parser_function_name;
42 char *header_filename;
45 string header_output_dir;
46 string src_output_dir;
49 string show_required_string;
54 bool no_handle_version;
59 bool gen_gengetopt_version;
62 unsigned int tab_indentation ; /* tab indentation level */
66 tab_indentation += TAB_LEN ;
71 tab_indentation -= TAB_LEN ;
78 for ( i = 1 ; i <= tab_indentation ; ++i )
82 void free_option(struct gengetopt_option *opt,
83 ostream &stream, unsigned int indent);
85 int generate_header_file();
86 int generate_source();
88 string generate_getopt_string();
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);
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);
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);
119 virtual void generate_free(ostream &stream, unsigned int indent);
120 virtual void generate_list_free(ostream &stream, unsigned int indent);
122 virtual void generate_file_save_loop(ostream &stream, unsigned int indent);
123 virtual void generate_init_args_info(ostream &stream, unsigned int indent);
125 virtual void generate_custom_getopt(ostream &stream, unsigned int indent);
127 void generateBreak(ostream &stream, unsigned int indent = 0);
129 void handle_options(ostream &, unsigned int, bool has_short);
133 CmdlineParserCreator (char *function_name, char *struct_name,
134 char *unamed_options,
135 char *filename, char *header_ext, char *c_ext,
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);
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);
154 const string generate_purpose();
155 const string generate_description();
156 const string generate_usage_string(bool use_config_package = true);
159 * generate a list of option descriptions that will be printed in the
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.
166 OptionHelpList *generate_help_option_list(bool generate_hidden = false,
167 bool generate_details = false);
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
175 * @param target_array the name of the array to copy to
176 * @param source_array the name of the array to copy from
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);
184 * Sets the has_arg_XXX by inspecting all the options types
186 void set_has_arg_types();