From: Simon Rit Date: Thu, 7 Jul 2011 13:03:26 +0000 (+0200) Subject: Added FindGengetopt.cmake which compiles gengetopt if not installed. X-Git-Tag: v1.3.0~298 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=91eacd1b09351ab508c9688f1071c5ea1e2b01b8;p=clitk.git Added FindGengetopt.cmake which compiles gengetopt if not installed. Also upgraded cmake version required to 2.8 because was solving issues regarding ADD_DEFINITION with quoted strings --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ce5b58..6fe2e34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ #========================================================= # CLITK = Command Line ITK -cmake_minimum_required(VERSION 2.4) -cmake_policy(VERSION 2.4) +cmake_minimum_required(VERSION 2.8) +cmake_policy(VERSION 2.8) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) @@ -42,11 +42,9 @@ ENDIF(VTK_FOUND) #========================================================= #========================================================= -# Find gengetopt -FIND_PATH(CLITK_GENGETOPT gengetopt) -IF (CLITK_GENGETOPT STREQUAL "CLITK_GENGETOPT-NOTFOUND") - MESSAGE("gengetopt not found, please install it (see http://www.gnu.org/software/gengetopt/gengetopt.html)") -ENDIF (CLITK_GENGETOPT STREQUAL "CLITK_GENGETOPT-NOTFOUND") +# Find gengetopt, will create a target exe if not found +SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +FIND_PACKAGE(Gengetopt) #========================================================= #========================================================= diff --git a/cmake/FindGengetopt.cmake b/cmake/FindGengetopt.cmake new file mode 100644 index 0000000..aecb1fc --- /dev/null +++ b/cmake/FindGengetopt.cmake @@ -0,0 +1,34 @@ + +# Attempt to find gengetopt. If not found, compile it. +FIND_PROGRAM(GENGETOPT gengetopt) +IF (GENGETOPT STREQUAL "GENGETOPT-NOTFOUND") + ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/cmake/gengetopt) +ELSE(GENGETOPT STREQUAL "GENGETOPT-NOTFOUND") + ADD_EXECUTABLE(gengetopt IMPORTED) + SET_PROPERTY(TARGET gengetopt PROPERTY IMPORTED_LOCATION ${GENGETOPT}) +ENDIF(GENGETOPT STREQUAL "GENGETOPT-NOTFOUND") + +MACRO (WRAP_GGO GGO_SRCS) + FOREACH(GGO_FILE ${ARGN}) + GET_FILENAME_COMPONENT(GGO_BASEFILENAME ${GGO_FILE} NAME_WE) + GET_FILENAME_COMPONENT(GGO_FILE_ABS ${GGO_FILE} ABSOLUTE) + SET(GGO_H ${GGO_BASEFILENAME}_ggo.h) + SET(GGO_C ${GGO_BASEFILENAME}_ggo.c) + SET(GGO_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GGO_H} ${CMAKE_CURRENT_BINARY_DIR}/${GGO_C}) + ADD_CUSTOM_COMMAND(OUTPUT ${GGO_OUTPUT} + COMMAND gengetopt + ARGS < ${GGO_FILE_ABS} + --output-dir=${CMAKE_CURRENT_BINARY_DIR} + --arg-struct-name=args_info_${GGO_BASEFILENAME} + --func-name=cmdline_parser_${GGO_BASEFILENAME} + --file-name=${GGO_BASEFILENAME}_ggo + --unamed-opts + --conf-parser + --include-getopt + DEPENDS ${GGO_FILE_ABS} + ) + SET(${GGO_SRCS} ${${GGO_SRCS}} ${GGO_OUTPUT}) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + ENDFOREACH(GGO_FILE) + SET_SOURCE_FILES_PROPERTIES(${${GGO_SRCS}} PROPERTIES GENERATED TRUE) +ENDMACRO (WRAP_GGO) diff --git a/cmake/common.cmake b/cmake/common.cmake index eeb8755..3239e96 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -3,35 +3,8 @@ MACRO (DD in) MESSAGE(${in}=${${in}}) ENDMACRO(DD) #========================================================= -# Process ggo (gengetopt) files (http://www.gnu.org/software/gengetopt/) -MACRO (WRAP_GGO GGO_SRCS) - FOREACH(GGO_FILE ${ARGN}) - GET_FILENAME_COMPONENT(GGO_BASEFILENAME ${GGO_FILE} NAME_WE) - GET_FILENAME_COMPONENT(GGO_FILE_ABS ${GGO_FILE} ABSOLUTE) - SET(GGO_H ${GGO_BASEFILENAME}_ggo.h) - SET(GGO_C ${GGO_BASEFILENAME}_ggo.c) - SET(GGO_OUTPUT ${GGO_H} ${GGO_C}) - ADD_CUSTOM_COMMAND(OUTPUT ${GGO_OUTPUT} - COMMAND ${CLITK_GENGETOPT}/gengetopt - ARGS < ${GGO_FILE_ABS} - --output-dir=${CMAKE_CURRENT_BINARY_DIR} - --arg-struct-name=args_info_${GGO_BASEFILENAME} - --func-name=cmdline_parser_${GGO_BASEFILENAME} - --file-name=${GGO_BASEFILENAME}_ggo - --unamed-opts - --conf-parser - --include-getopt - DEPENDS ${GGO_FILE} - ) - SET(${GGO_SRCS} ${${GGO_SRCS}} ${CMAKE_CURRENT_BINARY_DIR}/${GGO_BASEFILENAME}_ggo.c) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) #For _ggo.h includes - ENDFOREACH(GGO_FILE) - SET_SOURCE_FILES_PROPERTIES(${${GGO_SRCS}} PROPERTIES GENERATED TRUE) -ENDMACRO (WRAP_GGO) -# Reproduce old mechanism with new macro for ggo files (for the time being) -FILE(GLOB ALL_GGO_FILES *.ggo) -#WRAP_GGO(ALL_GGO_SRCS ${ALL_GGO_FILES}) + #========================================================= #Set a reasonable build mode default if the user hasn't set any if (NOT CMAKE_BUILD_TYPE) diff --git a/cmake/gengetopt/CMakeLists.txt b/cmake/gengetopt/CMakeLists.txt new file mode 100644 index 0000000..84443f0 --- /dev/null +++ b/cmake/gengetopt/CMakeLists.txt @@ -0,0 +1,63 @@ +# Gengetopt: http://www.gnu.org/software/gengetopt/ + +ADD_DEFINITIONS(-DPACKAGE=\"gengetopt\") +ADD_DEFINITIONS(-DVERSION=\"2.22.4\") +ADD_DEFINITIONS(-DHAVE_SSTREAM) +ADD_DEFINITIONS(-DHAVE_NAMESPACES) + +IF(WIN32) + ADD_DEFINITIONS(-DHAVE_STRING_H) + ADD_DEFINITIONS(-DYY_NO_UNISTD_H) + ADD_DEFINITIONS(-Disatty=!) + INCLUDE_DIRECTORIES(include_cygwin) +ENDIF(WIN32) + +ADD_EXECUTABLE(gengetopt + ./cmdline.c + ./ggos.cpp + ./scanner.cc + ./skels/required_option.cc + ./skels/handle_version.cc + ./skels/generic_option.cc + ./skels/clear_arg.cc + ./skels/update_given.cc + ./skels/dependant_option.cc + ./skels/custom_getopt_gen.cc + ./skels/handle_help.cc + ./skels/given_field.cc + ./skels/init_args_info.cc + ./skels/multiple_opt_list.cc + ./skels/free_list.cc + ./skels/exit_failure.cc + ./skels/clear_given.cc + ./skels/free_multiple.cc + ./skels/enum_decl.cc + ./skels/reset_group.cc + ./skels/c_source.cc + ./skels/group_option.cc + ./skels/file_save.cc + ./skels/check_modes.cc + ./skels/copyright.cc + ./skels/option_arg.cc + ./skels/group_counter.cc + ./skels/free_string.cc + ./skels/header.cc + ./skels/print_help_string.cc + ./skels/multiple_fill_array.cc + ./skels/file_save_multiple.cc + ./fileutils.cpp + ./getopt.c + ./gm.cc + ./globals.cpp + ./yywrap.c + ./getopt1.c + ./argsdef.c + ./gm_utils.cpp + ./acceptedvalues.cpp + ./gengetopt.cc + ./yyerror.cc + ./parser.cc) + +INCLUDE_DIRECTORIES(.) +INCLUDE_DIRECTORIES(skels) +#INCLUDE_DIRECTORIES(includes) diff --git a/cmake/gengetopt/Makefile.am b/cmake/gengetopt/Makefile.am new file mode 100644 index 0000000..091008f --- /dev/null +++ b/cmake/gengetopt/Makefile.am @@ -0,0 +1,115 @@ +# Copyright (C) 1999-2009 Free Software Foundation, Inc. +# +# This file is part of GNU gengetopt +# +# GNU gengetopt is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU gengetopt is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with gengetopt; see the file COPYING. If not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +SUBDIRS = includes skels tests + +#INCLUDES = -I@top_srcdir@/src/skels + +SUFFIXES = .text .c .ggo + +.text.o: + $(TXTC) $< + +bin_PROGRAMS = gengetopt + +noinst_LTLIBRARIES = libgengetopt.la + +libgengetopt_la_SOURCES = parser.cc scanner.cc \ +globals.cpp \ +argsdef.c cmdline.ggo gm.cc \ +yyerror.cc gm_utils.cpp fileutils.cpp acceptedvalues.cpp ggos.cpp + +gengetopt_SOURCES = gengetopt.cc + +scanner.cc: $(srcdir)/scanner.ll + $(LEX) $(LFLAGS) -o $(srcdir)/scanner.cc $(srcdir)/scanner.ll + +parser.cc: $(srcdir)/parser.yy + $(YACC) -o $(srcdir)/parser.cc $(srcdir)/parser.yy --defines=$(srcdir)/parser.h + +#gengetopt_LDADD = @LIBOBJS@ @LEXLIB@ skels/libgen.a + +# these are for gnulib +AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_builddir)/gl + +libgengetopt_la_LIBADD = $(top_builddir)/gl/libgnu.la \ + @LTLIBOBJS@ \ + skels/libgen.la + +LDADD = $(top_builddir)/src/libgengetopt.la + +EXTRA_DIST = parser.h argsdef.h gengetopt.h ggos.h gm.h gnugetopt.h \ +cmdline.c cmdline.h my_sstream.h my_string.h my_map.h \ +global_opts.h \ +ggo_options.h \ +groups.h \ +parser.yy scanner.ll \ +globals.h \ +$(pkgdata_DATA) + +# version of gengetopt linked to the ElectricFence library +# don't use it anymore: use valgrind +#EXTRA_PROGRAMS = gengetopt-efence +#gengetopt_efence_SOURCES = $(gengetopt_SOURCES) +#gengetopt_efence_LDADD = -lefence $(gengetopt_LDADD) + +PROGNAME = $(top_builddir)/src/gengetopt$(EXEEXT) + +# to have flex generate a case insensitive scanner +AM_LFLAGS = -i + +# it may happen, usually if the sources have been downloaded from CVS +# repository, that cmdline.ggo is more recent than cmdline.c, but +# cmdline.c cannot be re-generated, even because gengetopt has +# to be built first. For instance if you only change spaces in cmdline.ggo +# cmdline.c will not be different, and thus it is not updated in the CVS +# repository; then when you make a checkout on another place, make +# would try to build cmdline.c, but to do this it would need gengetopt +# which is not built yet; so we simply touch cmdline.c (and this is safe) + +.ggo.c: + if test -f $(PROGNAME); then \ + $(PROGNAME) --input=$< --output-dir=$(srcdir) ; \ + else touch $(srcdir)/$@ ; fi + +cmdline.h: cmdline.c + +BUILT_SOURCES = cmdline.h cmdline.c parser.cc scanner.cc + +# automatically generate gengetopt_strdup() from the replacement function +# strdup(). +# gengetopt_strdup.text: strdup.c +# echo "/* gengetopt_strdup(): automatically generated from strdup.c. */" > $@ +# cat strdup.c | sed -e 's/^strdup (/gengetopt_&/' \ +# -e 's/^char \* *$$/&/' \ +# -e '/^#include.*$$/D' -e '/^$$/D' >> $@ + +# we distribute these files because who uses gengetopt might need them +# these are installed in $(prefix)/share/gengetopt +pkgdata_DATA = gnugetopt.h getopt.c getopt1.c + +# yywrap.c is added only if it is not found on lex (flex) lib, and will be +# added automatically by automake + +# automake (maybe due to a bug) doesn't added these files well, +# so we explicitely declare them +MAINTAINERCLEANFILES = scanner.cc parser.h parser.cc + +noinst_HEADERS = acceptedvalues.h errorcodes.h fileutils.h \ + gm_utils.h yyerror.h + diff --git a/cmake/gengetopt/acceptedvalues.cpp b/cmake/gengetopt/acceptedvalues.cpp new file mode 100644 index 0000000..ea66c0a --- /dev/null +++ b/cmake/gengetopt/acceptedvalues.cpp @@ -0,0 +1,44 @@ +// +// C++ Implementation: acceptedvalues +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "acceptedvalues.h" +#include "my_sstream.h" + +using namespace std; + +void +AcceptedValues::insert(const string &s) +{ + push_back(s); + values.insert(s); +} + +bool +AcceptedValues::contains(const string &s) const +{ + return (values.count(s) > 0); +} + +const string +AcceptedValues::toString(bool escape) const +{ + ostringstream buf; + + for (const_iterator it = begin(); it != end(); ) { + buf << (escape ? "\\\"" : "\"") << *it + << (escape ? "\\\"" : "\""); + if (++it != end()) + buf << ", "; + } + + return buf.str(); +} diff --git a/cmake/gengetopt/acceptedvalues.h b/cmake/gengetopt/acceptedvalues.h new file mode 100644 index 0000000..d6a3d08 --- /dev/null +++ b/cmake/gengetopt/acceptedvalues.h @@ -0,0 +1,40 @@ +// +// C++ Interface: acceptedvalues +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef ACCEPTEDVALUES_H +#define ACCEPTEDVALUES_H + +#include +#include +#include + +/** +the values that can be passed to an option + +@author Lorenzo Bettini +*/ +class AcceptedValues : protected std::list +{ + private: + typedef std::set value_set; + value_set values; + + public: + using std::list::const_iterator; + using std::list::begin; + using std::list::end; + + void insert(const std::string &s); + const std::string toString(bool escape = true) const; + bool contains(const std::string &s) const; +}; + +#endif diff --git a/cmake/gengetopt/argsdef.c b/cmake/gengetopt/argsdef.c new file mode 100644 index 0000000..4b9af45 --- /dev/null +++ b/cmake/gengetopt/argsdef.c @@ -0,0 +1,35 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "argsdef.h" + +const char * arg_names [] = { (const char*)0, (const char*)0, "STRING", "INT", + "SHORT", "LONG", "FLOAT", "DOUBLE", "LONGDOUBLE", "LONGLONG", "ENUM" }; + +const char * arg_type_constants [] = { "ARG_NO", "ARG_FLAG", "ARG_STRING", + "ARG_INT", "ARG_SHORT", "ARG_LONG", "ARG_FLOAT", "ARG_DOUBLE", + "ARG_LONGDOUBLE", "ARG_LONGLONG", "ARG_ENUM" }; + +const char * arg_types [] = { (const char*)0, "int", "char *", "int", "short", + "long", "float", "double", "long double", "long long int", "enum" }; + +const char * arg_types_names [] = { (const char*)0, "int", "string", "int", + "short", "long", "float", "double", "longdouble", "longlong", "int" }; + diff --git a/cmake/gengetopt/argsdef.h b/cmake/gengetopt/argsdef.h new file mode 100644 index 0000000..d296473 --- /dev/null +++ b/cmake/gengetopt/argsdef.h @@ -0,0 +1,48 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef GENGETOPT_ARGSDEF_H +#define GENGETOPT_ARGSDEF_H + +#define ARG_NO 0 +#define ARG_FLAG 1 +#define ARG_STRING 2 +#define ARG_INT 3 +#define ARG_SHORT 4 +#define ARG_LONG 5 +#define ARG_FLOAT 6 +#define ARG_DOUBLE 7 +#define ARG_LONGDOUBLE 8 +#define ARG_LONGLONG 9 +#define ARG_ENUM 10 + +/** corresponding strings for above defines */ +extern const char * arg_type_constants []; +/** symbolic names for argument types */ +extern const char * arg_names []; +/** corresponding C types */ +extern const char * arg_types []; +/** string representation of types */ +extern const char * arg_types_names []; + +#define ARGS_STRUCT "args_info" + +#endif /* GENGETOPT_ARGSDEF_H */ + diff --git a/cmake/gengetopt/cmdline.c b/cmake/gengetopt/cmdline.c new file mode 100644 index 0000000..1e7523c --- /dev/null +++ b/cmake/gengetopt/cmdline.c @@ -0,0 +1,1287 @@ +/* + File autogenerated by gengetopt version 2.22.4 + generated with the following command: + ../src/gengetopt --input=../../src/cmdline.ggo --output-dir=../../src --no-handle-version --no-handle-help --no-handle-error --string-parser + + The developers of gengetopt consider the fixed text that goes in all + gengetopt output files to be in the public domain: + we make no copyright claims on it. +*/ + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ +#endif + +#include + +#include "cmdline.h" + +const char *gengetopt_args_info_purpose = "This program generates a C function that uses getopt_long function\nto parse the command line options, validate them and fill a struct."; + +const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]..."; + +const char *gengetopt_args_info_description = ""; + +const char *gengetopt_args_info_detailed_help[] = { + " -h, --help Print help and exit", + " --detailed-help Print help, including all details and hidden \n options, and exit", + " -V, --version Print version and exit", + "\nMain options:", + "", + " -i, --input=filename input file (default std input)", + " -f, --func-name=name name of generated function \n (default=`cmdline_parser')", + " -a, --arg-struct-name=name name of generated args info struct \n (default=`gengetopt_args_info')", + " -F, --file-name=name name of generated file (default=`cmdline')", + " --output-dir=path output directory", + " \n if this option is not specified, the files are generated in the current \n directory.\n", + " --header-output-dir=path header output directory", + " --src-output-dir=path source output directory", + " -c, --c-extension=ext extension of c file (default=`c')", + " -H, --header-extension=ext extension of header file (default=`h')", + " -l, --long-help long usage line in help", + " \n The usage line will print all the options, e.g.,\n\n sample1 -iINT|--int-opt=INT [-h|--help]\n", + " --default-optional by default, an option is considered optional if \n not specified otherwise", + " -u, --unamed-opts[=STRING] accept options without names (e.g., file names) \n (default=`FILES')", + "\nThe parser generated is thought to be used to parse the command line arguments. \nHowever, you can also generate parsers for configuration files, or strings that \ncontain the arguments to parse, by using the following two options.\n", + " -C, --conf-parser generate a config file parser", + " -S, --string-parser generate a string parser (the string contains \n the command line)", + "", + "\nAdditional options:", + " -G, --include-getopt adds the code for getopt_long in the generated \n C file", + " -n, --no-handle-help do not handle --help|-h automatically", + " \n If --no-handle-help is specified, the command line option --help|-h will not \n be handled automatically, so the programmer will be able to print some other \n information; then the function for printing the standard help output can be \n used; this function is called _print_help.\n\n Notice that, although the programmer can handle --help|-h manually, the \n parser will return after finding such option: the other command line options, \n if any, will be ignored. In case you want to have full control on --help|-h, \n you should use --ho-help.\n", + " --no-help do not add --help|-h automatically", + " \n With this option you can disable the automatic addition of options --help|-h. \n The programmer will then be able to add this option in the input file and \n handle it as he sees fit. Notice that --no-help will also disable the \n automatic options --detailed-help and --full-help.\n\n The programmer can still define options with short character h as he wants, \n but he cannot define options help, unless he specifies --no-help (otherwise \n an error will be printed).\n", + " -N, --no-handle-version do not handle --version|-V automatically", + " --no-version do not add --version|-V automatically", + " \n See above the details about --no-handle-help and --no-help, respectively.\n", + " -e, --no-handle-error do not exit on errors", + " \n With this option, if the generated parser encounters an error (e.g., an \n unknown option) it does not make the main program exit; instead, the parser \n function returns a value different 0, and the main program can print a help \n message.\n", + " --show-required[=STRING] in the output of help will specify which \n options are mandatory, by using the optional \n passed string (default=`(mandatory)')", + " -g, --gen-version put gengetopt version in the generated file \n (default=on)", + " --set-package=STRING set the package name (override package defined \n in the .ggo file)", + " --set-version=STRING set the version number (override version \n defined in the .ggo file)", + " --show-help show the output of --help instead of generating \n code", + " --show-full-help show the output of --full-help (i.e., including \n hidden options) instead of generating code", + " --show-detailed-help show the output of --detailed-help (i.e., \n including details and hidden options) instead \n of generating code", + " --show-version show the output of --version instead of \n generating code", + "\nPlease refer to the info manual for further explanations.", + 0 +}; + +static void +init_help_array(void) +{ + gengetopt_args_info_help[0] = gengetopt_args_info_detailed_help[0]; + gengetopt_args_info_help[1] = gengetopt_args_info_detailed_help[1]; + gengetopt_args_info_help[2] = gengetopt_args_info_detailed_help[2]; + gengetopt_args_info_help[3] = gengetopt_args_info_detailed_help[3]; + gengetopt_args_info_help[4] = gengetopt_args_info_detailed_help[4]; + gengetopt_args_info_help[5] = gengetopt_args_info_detailed_help[5]; + gengetopt_args_info_help[6] = gengetopt_args_info_detailed_help[6]; + gengetopt_args_info_help[7] = gengetopt_args_info_detailed_help[7]; + gengetopt_args_info_help[8] = gengetopt_args_info_detailed_help[8]; + gengetopt_args_info_help[9] = gengetopt_args_info_detailed_help[9]; + gengetopt_args_info_help[10] = gengetopt_args_info_detailed_help[11]; + gengetopt_args_info_help[11] = gengetopt_args_info_detailed_help[12]; + gengetopt_args_info_help[12] = gengetopt_args_info_detailed_help[13]; + gengetopt_args_info_help[13] = gengetopt_args_info_detailed_help[14]; + gengetopt_args_info_help[14] = gengetopt_args_info_detailed_help[15]; + gengetopt_args_info_help[15] = gengetopt_args_info_detailed_help[17]; + gengetopt_args_info_help[16] = gengetopt_args_info_detailed_help[18]; + gengetopt_args_info_help[17] = gengetopt_args_info_detailed_help[19]; + gengetopt_args_info_help[18] = gengetopt_args_info_detailed_help[20]; + gengetopt_args_info_help[19] = gengetopt_args_info_detailed_help[21]; + gengetopt_args_info_help[20] = gengetopt_args_info_detailed_help[22]; + gengetopt_args_info_help[21] = gengetopt_args_info_detailed_help[23]; + gengetopt_args_info_help[22] = gengetopt_args_info_detailed_help[24]; + gengetopt_args_info_help[23] = gengetopt_args_info_detailed_help[25]; + gengetopt_args_info_help[24] = gengetopt_args_info_detailed_help[27]; + gengetopt_args_info_help[25] = gengetopt_args_info_detailed_help[29]; + gengetopt_args_info_help[26] = gengetopt_args_info_detailed_help[30]; + gengetopt_args_info_help[27] = gengetopt_args_info_detailed_help[32]; + gengetopt_args_info_help[28] = gengetopt_args_info_detailed_help[34]; + gengetopt_args_info_help[29] = gengetopt_args_info_detailed_help[35]; + gengetopt_args_info_help[30] = gengetopt_args_info_detailed_help[36]; + gengetopt_args_info_help[31] = gengetopt_args_info_detailed_help[37]; + gengetopt_args_info_help[32] = gengetopt_args_info_detailed_help[38]; + gengetopt_args_info_help[33] = gengetopt_args_info_detailed_help[39]; + gengetopt_args_info_help[34] = gengetopt_args_info_detailed_help[40]; + gengetopt_args_info_help[35] = gengetopt_args_info_detailed_help[41]; + gengetopt_args_info_help[36] = gengetopt_args_info_detailed_help[42]; + gengetopt_args_info_help[37] = 0; + +} + +const char *gengetopt_args_info_help[38]; + +typedef enum {ARG_NO + , ARG_FLAG + , ARG_STRING +} cmdline_parser_arg_type; + +static +void clear_given (struct gengetopt_args_info *args_info); +static +void clear_args (struct gengetopt_args_info *args_info); + +static int +cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error); + +struct line_list +{ + char * string_arg; + struct line_list * next; +}; + +static struct line_list *cmd_line_list = 0; +static struct line_list *cmd_line_list_tmp = 0; + +static void +free_cmd_list(void) +{ + /* free the list of a previous call */ + if (cmd_line_list) + { + while (cmd_line_list) { + cmd_line_list_tmp = cmd_line_list; + cmd_line_list = cmd_line_list->next; + free (cmd_line_list_tmp->string_arg); + free (cmd_line_list_tmp); + } + } +} + + +static char * +gengetopt_strdup (const char *s); + +static +void clear_given (struct gengetopt_args_info *args_info) +{ + args_info->help_given = 0 ; + args_info->detailed_help_given = 0 ; + args_info->version_given = 0 ; + args_info->input_given = 0 ; + args_info->func_name_given = 0 ; + args_info->arg_struct_name_given = 0 ; + args_info->file_name_given = 0 ; + args_info->output_dir_given = 0 ; + args_info->header_output_dir_given = 0 ; + args_info->src_output_dir_given = 0 ; + args_info->c_extension_given = 0 ; + args_info->header_extension_given = 0 ; + args_info->long_help_given = 0 ; + args_info->default_optional_given = 0 ; + args_info->unamed_opts_given = 0 ; + args_info->conf_parser_given = 0 ; + args_info->string_parser_given = 0 ; + args_info->include_getopt_given = 0 ; + args_info->no_handle_help_given = 0 ; + args_info->no_help_given = 0 ; + args_info->no_handle_version_given = 0 ; + args_info->no_version_given = 0 ; + args_info->no_handle_error_given = 0 ; + args_info->show_required_given = 0 ; + args_info->gen_version_given = 0 ; + args_info->set_package_given = 0 ; + args_info->set_version_given = 0 ; + args_info->show_help_given = 0 ; + args_info->show_full_help_given = 0 ; + args_info->show_detailed_help_given = 0 ; + args_info->show_version_given = 0 ; +} + +static +void clear_args (struct gengetopt_args_info *args_info) +{ + FIX_UNUSED (args_info); + args_info->input_arg = NULL; + args_info->input_orig = NULL; + args_info->func_name_arg = gengetopt_strdup ("cmdline_parser"); + args_info->func_name_orig = NULL; + args_info->arg_struct_name_arg = gengetopt_strdup ("gengetopt_args_info"); + args_info->arg_struct_name_orig = NULL; + args_info->file_name_arg = gengetopt_strdup ("cmdline"); + args_info->file_name_orig = NULL; + args_info->output_dir_arg = NULL; + args_info->output_dir_orig = NULL; + args_info->header_output_dir_arg = NULL; + args_info->header_output_dir_orig = NULL; + args_info->src_output_dir_arg = NULL; + args_info->src_output_dir_orig = NULL; + args_info->c_extension_arg = gengetopt_strdup ("c"); + args_info->c_extension_orig = NULL; + args_info->header_extension_arg = gengetopt_strdup ("h"); + args_info->header_extension_orig = NULL; + args_info->unamed_opts_arg = gengetopt_strdup ("FILES"); + args_info->unamed_opts_orig = NULL; + args_info->show_required_arg = gengetopt_strdup ("(mandatory)"); + args_info->show_required_orig = NULL; + args_info->gen_version_flag = 1; + args_info->set_package_arg = NULL; + args_info->set_package_orig = NULL; + args_info->set_version_arg = NULL; + args_info->set_version_orig = NULL; + +} + +static +void init_args_info(struct gengetopt_args_info *args_info) +{ + + init_help_array(); + args_info->help_help = gengetopt_args_info_detailed_help[0] ; + args_info->detailed_help_help = gengetopt_args_info_detailed_help[1] ; + args_info->version_help = gengetopt_args_info_detailed_help[2] ; + args_info->input_help = gengetopt_args_info_detailed_help[5] ; + args_info->func_name_help = gengetopt_args_info_detailed_help[6] ; + args_info->arg_struct_name_help = gengetopt_args_info_detailed_help[7] ; + args_info->file_name_help = gengetopt_args_info_detailed_help[8] ; + args_info->output_dir_help = gengetopt_args_info_detailed_help[9] ; + args_info->header_output_dir_help = gengetopt_args_info_detailed_help[11] ; + args_info->src_output_dir_help = gengetopt_args_info_detailed_help[12] ; + args_info->c_extension_help = gengetopt_args_info_detailed_help[13] ; + args_info->header_extension_help = gengetopt_args_info_detailed_help[14] ; + args_info->long_help_help = gengetopt_args_info_detailed_help[15] ; + args_info->default_optional_help = gengetopt_args_info_detailed_help[17] ; + args_info->unamed_opts_help = gengetopt_args_info_detailed_help[18] ; + args_info->conf_parser_help = gengetopt_args_info_detailed_help[20] ; + args_info->string_parser_help = gengetopt_args_info_detailed_help[21] ; + args_info->include_getopt_help = gengetopt_args_info_detailed_help[24] ; + args_info->no_handle_help_help = gengetopt_args_info_detailed_help[25] ; + args_info->no_help_help = gengetopt_args_info_detailed_help[27] ; + args_info->no_handle_version_help = gengetopt_args_info_detailed_help[29] ; + args_info->no_version_help = gengetopt_args_info_detailed_help[30] ; + args_info->no_handle_error_help = gengetopt_args_info_detailed_help[32] ; + args_info->show_required_help = gengetopt_args_info_detailed_help[34] ; + args_info->gen_version_help = gengetopt_args_info_detailed_help[35] ; + args_info->set_package_help = gengetopt_args_info_detailed_help[36] ; + args_info->set_version_help = gengetopt_args_info_detailed_help[37] ; + args_info->show_help_help = gengetopt_args_info_detailed_help[38] ; + args_info->show_full_help_help = gengetopt_args_info_detailed_help[39] ; + args_info->show_detailed_help_help = gengetopt_args_info_detailed_help[40] ; + args_info->show_version_help = gengetopt_args_info_detailed_help[41] ; + +} + +void +cmdline_parser_print_version (void) +{ + printf ("%s %s\n", + (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), + CMDLINE_PARSER_VERSION); +} + +static void print_help_common(void) { + cmdline_parser_print_version (); + + if (strlen(gengetopt_args_info_purpose) > 0) + printf("\n%s\n", gengetopt_args_info_purpose); + + if (strlen(gengetopt_args_info_usage) > 0) + printf("\n%s\n", gengetopt_args_info_usage); + + printf("\n"); + + if (strlen(gengetopt_args_info_description) > 0) + printf("%s\n\n", gengetopt_args_info_description); +} + +void +cmdline_parser_print_help (void) +{ + int i = 0; + print_help_common(); + while (gengetopt_args_info_help[i]) + printf("%s\n", gengetopt_args_info_help[i++]); +} + +void +cmdline_parser_print_detailed_help (void) +{ + int i = 0; + print_help_common(); + while (gengetopt_args_info_detailed_help[i]) + printf("%s\n", gengetopt_args_info_detailed_help[i++]); +} + +void +cmdline_parser_init (struct gengetopt_args_info *args_info) +{ + clear_given (args_info); + clear_args (args_info); + init_args_info (args_info); +} + +void +cmdline_parser_params_init(struct cmdline_parser_params *params) +{ + if (params) + { + params->override = 0; + params->initialize = 1; + params->check_required = 1; + params->check_ambiguity = 0; + params->print_errors = 1; + } +} + +struct cmdline_parser_params * +cmdline_parser_params_create(void) +{ + struct cmdline_parser_params *params = + (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); + cmdline_parser_params_init(params); + return params; +} + +static void +free_string_field (char **s) +{ + if (*s) + { + free (*s); + *s = 0; + } +} + + +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) +{ + + free_string_field (&(args_info->input_arg)); + free_string_field (&(args_info->input_orig)); + free_string_field (&(args_info->func_name_arg)); + free_string_field (&(args_info->func_name_orig)); + free_string_field (&(args_info->arg_struct_name_arg)); + free_string_field (&(args_info->arg_struct_name_orig)); + free_string_field (&(args_info->file_name_arg)); + free_string_field (&(args_info->file_name_orig)); + free_string_field (&(args_info->output_dir_arg)); + free_string_field (&(args_info->output_dir_orig)); + free_string_field (&(args_info->header_output_dir_arg)); + free_string_field (&(args_info->header_output_dir_orig)); + free_string_field (&(args_info->src_output_dir_arg)); + free_string_field (&(args_info->src_output_dir_orig)); + free_string_field (&(args_info->c_extension_arg)); + free_string_field (&(args_info->c_extension_orig)); + free_string_field (&(args_info->header_extension_arg)); + free_string_field (&(args_info->header_extension_orig)); + free_string_field (&(args_info->unamed_opts_arg)); + free_string_field (&(args_info->unamed_opts_orig)); + free_string_field (&(args_info->show_required_arg)); + free_string_field (&(args_info->show_required_orig)); + free_string_field (&(args_info->set_package_arg)); + free_string_field (&(args_info->set_package_orig)); + free_string_field (&(args_info->set_version_arg)); + free_string_field (&(args_info->set_version_orig)); + + + + clear_given (args_info); +} + + +static void +write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) +{ + FIX_UNUSED (values); + if (arg) { + fprintf(outfile, "%s=\"%s\"\n", opt, arg); + } else { + fprintf(outfile, "%s\n", opt); + } +} + + +int +cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) +{ + int i = 0; + + if (!outfile) + { + fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); + return EXIT_FAILURE; + } + + if (args_info->help_given) + write_into_file(outfile, "help", 0, 0 ); + if (args_info->detailed_help_given) + write_into_file(outfile, "detailed-help", 0, 0 ); + if (args_info->version_given) + write_into_file(outfile, "version", 0, 0 ); + if (args_info->input_given) + write_into_file(outfile, "input", args_info->input_orig, 0); + if (args_info->func_name_given) + write_into_file(outfile, "func-name", args_info->func_name_orig, 0); + if (args_info->arg_struct_name_given) + write_into_file(outfile, "arg-struct-name", args_info->arg_struct_name_orig, 0); + if (args_info->file_name_given) + write_into_file(outfile, "file-name", args_info->file_name_orig, 0); + if (args_info->output_dir_given) + write_into_file(outfile, "output-dir", args_info->output_dir_orig, 0); + if (args_info->header_output_dir_given) + write_into_file(outfile, "header-output-dir", args_info->header_output_dir_orig, 0); + if (args_info->src_output_dir_given) + write_into_file(outfile, "src-output-dir", args_info->src_output_dir_orig, 0); + if (args_info->c_extension_given) + write_into_file(outfile, "c-extension", args_info->c_extension_orig, 0); + if (args_info->header_extension_given) + write_into_file(outfile, "header-extension", args_info->header_extension_orig, 0); + if (args_info->long_help_given) + write_into_file(outfile, "long-help", 0, 0 ); + if (args_info->default_optional_given) + write_into_file(outfile, "default-optional", 0, 0 ); + if (args_info->unamed_opts_given) + write_into_file(outfile, "unamed-opts", args_info->unamed_opts_orig, 0); + if (args_info->conf_parser_given) + write_into_file(outfile, "conf-parser", 0, 0 ); + if (args_info->string_parser_given) + write_into_file(outfile, "string-parser", 0, 0 ); + if (args_info->include_getopt_given) + write_into_file(outfile, "include-getopt", 0, 0 ); + if (args_info->no_handle_help_given) + write_into_file(outfile, "no-handle-help", 0, 0 ); + if (args_info->no_help_given) + write_into_file(outfile, "no-help", 0, 0 ); + if (args_info->no_handle_version_given) + write_into_file(outfile, "no-handle-version", 0, 0 ); + if (args_info->no_version_given) + write_into_file(outfile, "no-version", 0, 0 ); + if (args_info->no_handle_error_given) + write_into_file(outfile, "no-handle-error", 0, 0 ); + if (args_info->show_required_given) + write_into_file(outfile, "show-required", args_info->show_required_orig, 0); + if (args_info->gen_version_given) + write_into_file(outfile, "gen-version", 0, 0 ); + if (args_info->set_package_given) + write_into_file(outfile, "set-package", args_info->set_package_orig, 0); + if (args_info->set_version_given) + write_into_file(outfile, "set-version", args_info->set_version_orig, 0); + if (args_info->show_help_given) + write_into_file(outfile, "show-help", 0, 0 ); + if (args_info->show_full_help_given) + write_into_file(outfile, "show-full-help", 0, 0 ); + if (args_info->show_detailed_help_given) + write_into_file(outfile, "show-detailed-help", 0, 0 ); + if (args_info->show_version_given) + write_into_file(outfile, "show-version", 0, 0 ); + + + i = EXIT_SUCCESS; + return i; +} + +int +cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) +{ + FILE *outfile; + int i = 0; + + outfile = fopen(filename, "w"); + + if (!outfile) + { + fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); + return EXIT_FAILURE; + } + + i = cmdline_parser_dump(outfile, args_info); + fclose (outfile); + + return i; +} + +void +cmdline_parser_free (struct gengetopt_args_info *args_info) +{ + cmdline_parser_release (args_info); +} + +/** @brief replacement of strdup, which is not standard */ +char * +gengetopt_strdup (const char *s) +{ + char *result = 0; + if (!s) + return result; + + result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; + strcpy(result, s); + return result; +} + +int +cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) +{ + return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); +} + +int +cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params) +{ + int result; + result = cmdline_parser_internal (argc, argv, args_info, params, 0); + + return result; +} + +int +cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) +{ + int result; + struct cmdline_parser_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); + + return result; +} + +int +cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) +{ + FIX_UNUSED (args_info); + FIX_UNUSED (prog_name); + return EXIT_SUCCESS; +} + + +static char *package_name = 0; + +/** + * @brief updates an option + * @param field the generic pointer to the field to update + * @param orig_field the pointer to the orig field + * @param field_given the pointer to the number of occurrence of this option + * @param prev_given the pointer to the number of occurrence already seen + * @param value the argument for this option (if null no arg was specified) + * @param possible_values the possible values for this option (if specified) + * @param default_value the default value (in case the option only accepts fixed values) + * @param arg_type the type of this option + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity + * @param override @see cmdline_parser_params.override + * @param no_free whether to free a possible previous value + * @param multiple_option whether this is a multiple option + * @param long_opt the corresponding long option + * @param short_opt the corresponding short option (or '-' if none) + * @param additional_error possible further error specification + */ +static +int update_arg(void *field, char **orig_field, + unsigned int *field_given, unsigned int *prev_given, + char *value, const char *possible_values[], + const char *default_value, + cmdline_parser_arg_type arg_type, + int check_ambiguity, int override, + int no_free, int multiple_option, + const char *long_opt, char short_opt, + const char *additional_error) +{ + char *stop_char = 0; + const char *val = value; + int found; + char **string_field; + FIX_UNUSED (field); + + stop_char = 0; + found = 0; + + if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) + { + if (short_opt != '-') + fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", + package_name, long_opt, short_opt, + (additional_error ? additional_error : "")); + else + fprintf (stderr, "%s: `--%s' option given more than once%s\n", + package_name, long_opt, + (additional_error ? additional_error : "")); + return 1; /* failure */ + } + + FIX_UNUSED (default_value); + + if (field_given && *field_given && ! override) + return 0; + if (prev_given) + (*prev_given)++; + if (field_given) + (*field_given)++; + if (possible_values) + val = possible_values[found]; + + switch(arg_type) { + case ARG_FLAG: + *((int *)field) = !*((int *)field); + break; + case ARG_STRING: + if (val) { + string_field = (char **)field; + if (!no_free && *string_field) + free (*string_field); /* free previous string */ + *string_field = gengetopt_strdup (val); + } + break; + default: + break; + }; + + + /* store the original value */ + switch(arg_type) { + case ARG_NO: + case ARG_FLAG: + break; + default: + if (value && orig_field) { + if (no_free) { + *orig_field = value; + } else { + if (*orig_field) + free (*orig_field); /* free previous string */ + *orig_field = gengetopt_strdup (value); + } + } + }; + + return 0; /* OK */ +} + + +int +cmdline_parser_internal ( + int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error) +{ + int c; /* Character of the parsed option. */ + + int error = 0; + struct gengetopt_args_info local_args_info; + + int override; + int initialize; + int check_required; + int check_ambiguity; + + package_name = argv[0]; + + override = params->override; + initialize = params->initialize; + check_required = params->check_required; + check_ambiguity = params->check_ambiguity; + + if (initialize) + cmdline_parser_init (args_info); + + cmdline_parser_init (&local_args_info); + + optarg = 0; + optind = 0; + opterr = params->print_errors; + optopt = '?'; + + while (1) + { + int option_index = 0; + + static struct option long_options[] = { + { "help", 0, NULL, 'h' }, + { "detailed-help", 0, NULL, 0 }, + { "version", 0, NULL, 'V' }, + { "input", 1, NULL, 'i' }, + { "func-name", 1, NULL, 'f' }, + { "arg-struct-name", 1, NULL, 'a' }, + { "file-name", 1, NULL, 'F' }, + { "output-dir", 1, NULL, 0 }, + { "header-output-dir", 1, NULL, 0 }, + { "src-output-dir", 1, NULL, 0 }, + { "c-extension", 1, NULL, 'c' }, + { "header-extension", 1, NULL, 'H' }, + { "long-help", 0, NULL, 'l' }, + { "default-optional", 0, NULL, 0 }, + { "unamed-opts", 2, NULL, 'u' }, + { "conf-parser", 0, NULL, 'C' }, + { "string-parser", 0, NULL, 'S' }, + { "include-getopt", 0, NULL, 'G' }, + { "no-handle-help", 0, NULL, 'n' }, + { "no-help", 0, NULL, 0 }, + { "no-handle-version", 0, NULL, 'N' }, + { "no-version", 0, NULL, 0 }, + { "no-handle-error", 0, NULL, 'e' }, + { "show-required", 2, NULL, 0 }, + { "gen-version", 0, NULL, 'g' }, + { "set-package", 1, NULL, 0 }, + { "set-version", 1, NULL, 0 }, + { "show-help", 0, NULL, 0 }, + { "show-full-help", 0, NULL, 0 }, + { "show-detailed-help", 0, NULL, 0 }, + { "show-version", 0, NULL, 0 }, + { 0, 0, 0, 0 } + }; + + c = getopt_long (argc, argv, "hVi:f:a:F:c:H:lu::CSGnNeg", long_options, &option_index); + + if (c == -1) break; /* Exit from `while (1)' loop. */ + + switch (c) + { + case 'h': /* Print help and exit. */ + + + if (update_arg( 0 , + 0 , &(args_info->help_given), + &(local_args_info.help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "help", 'h', + additional_error)) + goto failure; + cmdline_parser_free (&local_args_info); + return 0; + + break; + case 'V': /* Print version and exit. */ + + + if (update_arg( 0 , + 0 , &(args_info->version_given), + &(local_args_info.version_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "version", 'V', + additional_error)) + goto failure; + cmdline_parser_free (&local_args_info); + return 0; + + break; + case 'i': /* input file (default std input). */ + + + if (update_arg( (void *)&(args_info->input_arg), + &(args_info->input_orig), &(args_info->input_given), + &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "input", 'i', + additional_error)) + goto failure; + + break; + case 'f': /* name of generated function. */ + + + if (update_arg( (void *)&(args_info->func_name_arg), + &(args_info->func_name_orig), &(args_info->func_name_given), + &(local_args_info.func_name_given), optarg, 0, "cmdline_parser", ARG_STRING, + check_ambiguity, override, 0, 0, + "func-name", 'f', + additional_error)) + goto failure; + + break; + case 'a': /* name of generated args info struct. */ + + + if (update_arg( (void *)&(args_info->arg_struct_name_arg), + &(args_info->arg_struct_name_orig), &(args_info->arg_struct_name_given), + &(local_args_info.arg_struct_name_given), optarg, 0, "gengetopt_args_info", ARG_STRING, + check_ambiguity, override, 0, 0, + "arg-struct-name", 'a', + additional_error)) + goto failure; + + break; + case 'F': /* name of generated file. */ + + + if (update_arg( (void *)&(args_info->file_name_arg), + &(args_info->file_name_orig), &(args_info->file_name_given), + &(local_args_info.file_name_given), optarg, 0, "cmdline", ARG_STRING, + check_ambiguity, override, 0, 0, + "file-name", 'F', + additional_error)) + goto failure; + + break; + case 'c': /* extension of c file. */ + + + if (update_arg( (void *)&(args_info->c_extension_arg), + &(args_info->c_extension_orig), &(args_info->c_extension_given), + &(local_args_info.c_extension_given), optarg, 0, "c", ARG_STRING, + check_ambiguity, override, 0, 0, + "c-extension", 'c', + additional_error)) + goto failure; + + break; + case 'H': /* extension of header file. */ + + + if (update_arg( (void *)&(args_info->header_extension_arg), + &(args_info->header_extension_orig), &(args_info->header_extension_given), + &(local_args_info.header_extension_given), optarg, 0, "h", ARG_STRING, + check_ambiguity, override, 0, 0, + "header-extension", 'H', + additional_error)) + goto failure; + + break; + case 'l': /* long usage line in help. */ + + + if (update_arg( 0 , + 0 , &(args_info->long_help_given), + &(local_args_info.long_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "long-help", 'l', + additional_error)) + goto failure; + + break; + case 'u': /* accept options without names (e.g., file names). */ + + + if (update_arg( (void *)&(args_info->unamed_opts_arg), + &(args_info->unamed_opts_orig), &(args_info->unamed_opts_given), + &(local_args_info.unamed_opts_given), optarg, 0, "FILES", ARG_STRING, + check_ambiguity, override, 0, 0, + "unamed-opts", 'u', + additional_error)) + goto failure; + + break; + case 'C': /* generate a config file parser. */ + + + if (update_arg( 0 , + 0 , &(args_info->conf_parser_given), + &(local_args_info.conf_parser_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "conf-parser", 'C', + additional_error)) + goto failure; + + break; + case 'S': /* generate a string parser (the string contains the command line). */ + + + if (update_arg( 0 , + 0 , &(args_info->string_parser_given), + &(local_args_info.string_parser_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "string-parser", 'S', + additional_error)) + goto failure; + + break; + case 'G': /* adds the code for getopt_long in the generated C file. */ + + + if (update_arg( 0 , + 0 , &(args_info->include_getopt_given), + &(local_args_info.include_getopt_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "include-getopt", 'G', + additional_error)) + goto failure; + + break; + case 'n': /* do not handle --help|-h automatically. */ + + + if (update_arg( 0 , + 0 , &(args_info->no_handle_help_given), + &(local_args_info.no_handle_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "no-handle-help", 'n', + additional_error)) + goto failure; + + break; + case 'N': /* do not handle --version|-V automatically. */ + + + if (update_arg( 0 , + 0 , &(args_info->no_handle_version_given), + &(local_args_info.no_handle_version_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "no-handle-version", 'N', + additional_error)) + goto failure; + + break; + case 'e': /* do not exit on errors. */ + + + if (update_arg( 0 , + 0 , &(args_info->no_handle_error_given), + &(local_args_info.no_handle_error_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "no-handle-error", 'e', + additional_error)) + goto failure; + + break; + case 'g': /* put gengetopt version in the generated file. */ + + + if (update_arg((void *)&(args_info->gen_version_flag), 0, &(args_info->gen_version_given), + &(local_args_info.gen_version_given), optarg, 0, 0, ARG_FLAG, + check_ambiguity, override, 1, 0, "gen-version", 'g', + additional_error)) + goto failure; + + break; + + case 0: /* Long option with no short option */ + /* Print help, including all details and hidden options, and exit. */ + if (strcmp (long_options[option_index].name, "detailed-help") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->detailed_help_given), + &(local_args_info.detailed_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "detailed-help", '-', + additional_error)) + goto failure; + cmdline_parser_free (&local_args_info); + return 0; + + } + /* output directory. */ + else if (strcmp (long_options[option_index].name, "output-dir") == 0) + { + + + if (update_arg( (void *)&(args_info->output_dir_arg), + &(args_info->output_dir_orig), &(args_info->output_dir_given), + &(local_args_info.output_dir_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "output-dir", '-', + additional_error)) + goto failure; + + } + /* header output directory. */ + else if (strcmp (long_options[option_index].name, "header-output-dir") == 0) + { + + + if (update_arg( (void *)&(args_info->header_output_dir_arg), + &(args_info->header_output_dir_orig), &(args_info->header_output_dir_given), + &(local_args_info.header_output_dir_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "header-output-dir", '-', + additional_error)) + goto failure; + + } + /* source output directory. */ + else if (strcmp (long_options[option_index].name, "src-output-dir") == 0) + { + + + if (update_arg( (void *)&(args_info->src_output_dir_arg), + &(args_info->src_output_dir_orig), &(args_info->src_output_dir_given), + &(local_args_info.src_output_dir_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "src-output-dir", '-', + additional_error)) + goto failure; + + } + /* by default, an option is considered optional if not specified otherwise. */ + else if (strcmp (long_options[option_index].name, "default-optional") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->default_optional_given), + &(local_args_info.default_optional_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "default-optional", '-', + additional_error)) + goto failure; + + } + /* do not add --help|-h automatically. */ + else if (strcmp (long_options[option_index].name, "no-help") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->no_help_given), + &(local_args_info.no_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "no-help", '-', + additional_error)) + goto failure; + + } + /* do not add --version|-V automatically. */ + else if (strcmp (long_options[option_index].name, "no-version") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->no_version_given), + &(local_args_info.no_version_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "no-version", '-', + additional_error)) + goto failure; + + } + /* in the output of help will specify which options are mandatory, by using the optional passed string. */ + else if (strcmp (long_options[option_index].name, "show-required") == 0) + { + + + if (update_arg( (void *)&(args_info->show_required_arg), + &(args_info->show_required_orig), &(args_info->show_required_given), + &(local_args_info.show_required_given), optarg, 0, "(mandatory)", ARG_STRING, + check_ambiguity, override, 0, 0, + "show-required", '-', + additional_error)) + goto failure; + + } + /* set the package name (override package defined in the .ggo file). */ + else if (strcmp (long_options[option_index].name, "set-package") == 0) + { + + + if (update_arg( (void *)&(args_info->set_package_arg), + &(args_info->set_package_orig), &(args_info->set_package_given), + &(local_args_info.set_package_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "set-package", '-', + additional_error)) + goto failure; + + } + /* set the version number (override version defined in the .ggo file). */ + else if (strcmp (long_options[option_index].name, "set-version") == 0) + { + + + if (update_arg( (void *)&(args_info->set_version_arg), + &(args_info->set_version_orig), &(args_info->set_version_given), + &(local_args_info.set_version_given), optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "set-version", '-', + additional_error)) + goto failure; + + } + /* show the output of --help instead of generating code. */ + else if (strcmp (long_options[option_index].name, "show-help") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->show_help_given), + &(local_args_info.show_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "show-help", '-', + additional_error)) + goto failure; + + } + /* show the output of --full-help (i.e., including hidden options) instead of generating code. */ + else if (strcmp (long_options[option_index].name, "show-full-help") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->show_full_help_given), + &(local_args_info.show_full_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "show-full-help", '-', + additional_error)) + goto failure; + + } + /* show the output of --detailed-help (i.e., including details and hidden options) instead of generating code. */ + else if (strcmp (long_options[option_index].name, "show-detailed-help") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->show_detailed_help_given), + &(local_args_info.show_detailed_help_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "show-detailed-help", '-', + additional_error)) + goto failure; + + } + /* show the output of --version instead of generating code. */ + else if (strcmp (long_options[option_index].name, "show-version") == 0) + { + + + if (update_arg( 0 , + 0 , &(args_info->show_version_given), + &(local_args_info.show_version_given), optarg, 0, 0, ARG_NO, + check_ambiguity, override, 0, 0, + "show-version", '-', + additional_error)) + goto failure; + + } + + break; + case '?': /* Invalid option. */ + /* `getopt_long' already printed an error message. */ + goto failure; + + default: /* bug: option not considered. */ + fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); + abort (); + } /* switch */ + } /* while */ + + + + + cmdline_parser_release (&local_args_info); + + if ( error ) + return (EXIT_FAILURE); + + return 0; + +failure: + + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); +} + +static unsigned int +cmdline_parser_create_argv(const char *cmdline_, char ***argv_ptr, const char *prog_name) +{ + char *cmdline, *p; + size_t n = 0, j; + int i; + + if (prog_name) { + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup (prog_name); + + ++n; + } + + cmdline = gengetopt_strdup(cmdline_); + p = cmdline; + + while (p && strlen(p)) + { + j = strcspn(p, " \t"); + ++n; + if (j && j < strlen(p)) + { + p[j] = '\0'; + + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup (p); + + p += (j+1); + p += strspn(p, " \t"); + } + else + { + cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup (p); + + break; + } + } + + *argv_ptr = (char **) malloc((n + 1) * sizeof(char *)); + cmd_line_list_tmp = cmd_line_list; + for (i = (n-1); i >= 0; --i) + { + (*argv_ptr)[i] = cmd_line_list_tmp->string_arg; + cmd_line_list_tmp = cmd_line_list_tmp->next; + } + + (*argv_ptr)[n] = 0; + + free(cmdline); + return n; +} + +int +cmdline_parser_string(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name) +{ + return cmdline_parser_string2(cmdline, args_info, prog_name, 0, 1, 1); +} + +int +cmdline_parser_string2(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name, + int override, int initialize, int check_required) +{ + struct cmdline_parser_params params; + + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + return cmdline_parser_string_ext(cmdline, args_info, prog_name, ¶ms); +} + +int +cmdline_parser_string_ext(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name, + struct cmdline_parser_params *params) +{ + char **argv_ptr = 0; + int result; + unsigned int argc; + + argc = cmdline_parser_create_argv(cmdline, &argv_ptr, prog_name); + + result = + cmdline_parser_internal (argc, argv_ptr, args_info, params, 0); + + if (argv_ptr) + { + free (argv_ptr); + } + + free_cmd_list(); + + return result; +} + diff --git a/cmake/gengetopt/cmdline.ggo b/cmake/gengetopt/cmdline.ggo new file mode 100644 index 0000000..d80ef5a --- /dev/null +++ b/cmake/gengetopt/cmdline.ggo @@ -0,0 +1,147 @@ +# Copyright (C) 1999-2010 Free Software Foundation, Inc. +# +# This file is part of GNU gengetopt +# +# GNU gengetopt is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# GNU gengetopt is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with gengetopt; see the file COPYING. If not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +# Specification file format: +# +# This file consist in lines of sentences with the following format: +# +# package +# version +# purpose +# option +# option flag +# option +# ... # ... +# +# Where: +# +# = Double quoted string. +# = Double quoted string. +# = What the program does +# Double quoted string (even on more than one line) +# = Double quoted string with upper and lower case chars, digits, +# '-' and '.'. No spaces allowed. +# = A single upper or lower case char, or a digit. +# = String with upper and lower case chars, digits, '-', '.' and +# spaces. +# = string, int, short, long, float, double, longdouble or longlong. +# = required or optional. +# = on or off. +# Comments begins with '#' in any place of the line and ends in the +# end of line. +# The third form of option is used if the option does not take an argument; +# it must not be required. + + +# Name of our program +#package "gengetopt" # we don't use it: we're using automake +# Version of our program +#version "1.0.1" # we don't use it: we're using automake + +purpose "This program generates a C function that uses getopt_long function +to parse the command line options, validate them and fill a struct." + +# options that will be added to command line options of gengetopt +args "--no-handle-version --no-handle-help --no-handle-error --string-parser" + +# Options + +section "Main options" + +text "" + +option "input" i "input file (default std input)" string typestr="filename" optional +option "func-name" f "name of generated function" string typestr="name" default="cmdline_parser" optional +option "arg-struct-name" a "name of generated args info struct" string typestr="name" default="gengetopt_args_info" optional +option "file-name" F "name of generated file" string typestr="name" default="cmdline" optional +option "output-dir" - "output directory" string typestr="path" optional + details="\nif this option is not specified, the \ +files are generated in the current directory.\n" +option "header-output-dir" - "header output directory" string typestr="path" optional +option "src-output-dir" - "source output directory" string typestr="path" optional +option "c-extension" c "extension of c file" string typestr="ext" default="c" optional +option "header-extension" H "extension of header file" string typestr="ext" default="h" optional +option "long-help" l "long usage line in help" optional + details="\nThe usage line will print all the options, e.g., + +sample1 -iINT|--int-opt=INT [-h|--help]\n" +option "default-optional" - "by default, an option is considered optional if not specified otherwise" optional +option "unamed-opts" u "accept options without names (e.g., file names)" string default="FILES" optional argoptional + +text "\nThe parser generated is thought to be used to parse the command line arguments. " +text "However, you can also generate parsers for configuration files, or strings " +text "that contain the arguments to parse, by using the following two options.\n" + +option "conf-parser" C "generate a config file parser" optional +option "string-parser" S "generate a string parser (the string contains the command line)" optional + +text "" + +section "Additional options" + +option "include-getopt" G "adds the code for getopt_long in the generated C file" optional + +option "no-handle-help" n "do not handle --help|-h automatically" optional + details="\nIf --no-handle-help is specified, the command line option \ +--help|-h will not be handled automatically, so the programmer will be able \ +to print some \ +other information; then the function for printing the standard help \ +output can be used; this function is called \ +_print_help.\n\nNotice \ +that, although the programmer can handle --help|-h manually, the \ +parser will return after finding such option: the other command \ +line options, if any, will be ignored. In case you want to have full \ +control on --help|-h, you should use --ho-help.\n" + +option "no-help" - "do not add --help|-h automatically" optional + details="\nWith this option you can disable the \ +automatic addition of options --help|-h. The programmer \ +will then be able to add this option in \ +the input file and handle it as he sees fit. Notice that \ +--no-help will also disable the automatic options \ +--detailed-help and --full-help. + +The programmer can still \ +define options with short character h as he wants, \ +but he cannot define options help, unless he \ +specifies --no-help \ +(otherwise an error will be printed).\n" + +option "no-handle-version" N "do not handle --version|-V automatically" optional +option "no-version" - "do not add --version|-V automatically" optional + details="\nSee above the details about \ +--no-handle-help and --no-help, respectively.\n" + +option "no-handle-error" e "do not exit on errors" optional + details="\nWith this option, if the generated parser encounters an error \ +(e.g., an unknown option) it does not make the main program exit; instead, the parser \ +function returns a value different 0, and the main program can print a help message.\n" + +option "show-required" - "in the output of help will specify which options are mandatory, \ +by using the optional passed string" string default="(mandatory)" optional argoptional + +option "gen-version" g "put gengetopt version in the generated file" flag on +option "set-package" - "set the package name (override package defined in the .ggo file)" string optional +option "set-version" - "set the version number (override version defined in the .ggo file)" string optional +option "show-help" - "show the output of --help instead of generating code" optional +option "show-full-help" - "show the output of --full-help (i.e., including hidden options) instead of generating code" optional +option "show-detailed-help" - "show the output of --detailed-help (i.e., including details and hidden options) instead of generating code" optional +option "show-version" - "show the output of --version instead of generating code" optional + +text "\nPlease refer to the info manual for further explanations." diff --git a/cmake/gengetopt/cmdline.h b/cmake/gengetopt/cmdline.h new file mode 100644 index 0000000..138ea0a --- /dev/null +++ b/cmake/gengetopt/cmdline.h @@ -0,0 +1,304 @@ +/** @file cmdline.h + * @brief The header file for the command line option parser + * generated by GNU Gengetopt version 2.22.4 + * http://www.gnu.org/software/gengetopt. + * DO NOT modify this file, since it can be overwritten + * @author GNU Gengetopt by Lorenzo Bettini */ + +#ifndef CMDLINE_H +#define CMDLINE_H + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* for FILE */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef CMDLINE_PARSER_PACKAGE +/** @brief the program name (used for printing errors) */ +#define CMDLINE_PARSER_PACKAGE PACKAGE +#endif + +#ifndef CMDLINE_PARSER_PACKAGE_NAME +/** @brief the complete program name (used for help and version) */ +#ifdef PACKAGE_NAME +#define CMDLINE_PARSER_PACKAGE_NAME PACKAGE_NAME +#else +#define CMDLINE_PARSER_PACKAGE_NAME PACKAGE +#endif +#endif + +#ifndef CMDLINE_PARSER_VERSION +/** @brief the program version */ +#define CMDLINE_PARSER_VERSION VERSION +#endif + +/** @brief Where the command line options are stored */ +struct gengetopt_args_info +{ + const char *help_help; /**< @brief Print help and exit help description. */ + const char *detailed_help_help; /**< @brief Print help, including all details and hidden options, and exit help description. */ + const char *version_help; /**< @brief Print version and exit help description. */ + char * input_arg; /**< @brief input file (default std input). */ + char * input_orig; /**< @brief input file (default std input) original value given at command line. */ + const char *input_help; /**< @brief input file (default std input) help description. */ + char * func_name_arg; /**< @brief name of generated function (default='cmdline_parser'). */ + char * func_name_orig; /**< @brief name of generated function original value given at command line. */ + const char *func_name_help; /**< @brief name of generated function help description. */ + char * arg_struct_name_arg; /**< @brief name of generated args info struct (default='gengetopt_args_info'). */ + char * arg_struct_name_orig; /**< @brief name of generated args info struct original value given at command line. */ + const char *arg_struct_name_help; /**< @brief name of generated args info struct help description. */ + char * file_name_arg; /**< @brief name of generated file (default='cmdline'). */ + char * file_name_orig; /**< @brief name of generated file original value given at command line. */ + const char *file_name_help; /**< @brief name of generated file help description. */ + char * output_dir_arg; /**< @brief output directory. */ + char * output_dir_orig; /**< @brief output directory original value given at command line. */ + const char *output_dir_help; /**< @brief output directory help description. */ + char * header_output_dir_arg; /**< @brief header output directory. */ + char * header_output_dir_orig; /**< @brief header output directory original value given at command line. */ + const char *header_output_dir_help; /**< @brief header output directory help description. */ + char * src_output_dir_arg; /**< @brief source output directory. */ + char * src_output_dir_orig; /**< @brief source output directory original value given at command line. */ + const char *src_output_dir_help; /**< @brief source output directory help description. */ + char * c_extension_arg; /**< @brief extension of c file (default='c'). */ + char * c_extension_orig; /**< @brief extension of c file original value given at command line. */ + const char *c_extension_help; /**< @brief extension of c file help description. */ + char * header_extension_arg; /**< @brief extension of header file (default='h'). */ + char * header_extension_orig; /**< @brief extension of header file original value given at command line. */ + const char *header_extension_help; /**< @brief extension of header file help description. */ + const char *long_help_help; /**< @brief long usage line in help help description. */ + const char *default_optional_help; /**< @brief by default, an option is considered optional if not specified otherwise help description. */ + char * unamed_opts_arg; /**< @brief accept options without names (e.g., file names) (default='FILES'). */ + char * unamed_opts_orig; /**< @brief accept options without names (e.g., file names) original value given at command line. */ + const char *unamed_opts_help; /**< @brief accept options without names (e.g., file names) help description. */ + const char *conf_parser_help; /**< @brief generate a config file parser help description. */ + const char *string_parser_help; /**< @brief generate a string parser (the string contains the command line) help description. */ + const char *include_getopt_help; /**< @brief adds the code for getopt_long in the generated C file help description. */ + const char *no_handle_help_help; /**< @brief do not handle --help|-h automatically help description. */ + const char *no_help_help; /**< @brief do not add --help|-h automatically help description. */ + const char *no_handle_version_help; /**< @brief do not handle --version|-V automatically help description. */ + const char *no_version_help; /**< @brief do not add --version|-V automatically help description. */ + const char *no_handle_error_help; /**< @brief do not exit on errors help description. */ + char * show_required_arg; /**< @brief in the output of help will specify which options are mandatory, by using the optional passed string (default='(mandatory)'). */ + char * show_required_orig; /**< @brief in the output of help will specify which options are mandatory, by using the optional passed string original value given at command line. */ + const char *show_required_help; /**< @brief in the output of help will specify which options are mandatory, by using the optional passed string help description. */ + int gen_version_flag; /**< @brief put gengetopt version in the generated file (default=on). */ + const char *gen_version_help; /**< @brief put gengetopt version in the generated file help description. */ + char * set_package_arg; /**< @brief set the package name (override package defined in the .ggo file). */ + char * set_package_orig; /**< @brief set the package name (override package defined in the .ggo file) original value given at command line. */ + const char *set_package_help; /**< @brief set the package name (override package defined in the .ggo file) help description. */ + char * set_version_arg; /**< @brief set the version number (override version defined in the .ggo file). */ + char * set_version_orig; /**< @brief set the version number (override version defined in the .ggo file) original value given at command line. */ + const char *set_version_help; /**< @brief set the version number (override version defined in the .ggo file) help description. */ + const char *show_help_help; /**< @brief show the output of --help instead of generating code help description. */ + const char *show_full_help_help; /**< @brief show the output of --full-help (i.e., including hidden options) instead of generating code help description. */ + const char *show_detailed_help_help; /**< @brief show the output of --detailed-help (i.e., including details and hidden options) instead of generating code help description. */ + const char *show_version_help; /**< @brief show the output of --version instead of generating code help description. */ + + unsigned int help_given ; /**< @brief Whether help was given. */ + unsigned int detailed_help_given ; /**< @brief Whether detailed-help was given. */ + unsigned int version_given ; /**< @brief Whether version was given. */ + unsigned int input_given ; /**< @brief Whether input was given. */ + unsigned int func_name_given ; /**< @brief Whether func-name was given. */ + unsigned int arg_struct_name_given ; /**< @brief Whether arg-struct-name was given. */ + unsigned int file_name_given ; /**< @brief Whether file-name was given. */ + unsigned int output_dir_given ; /**< @brief Whether output-dir was given. */ + unsigned int header_output_dir_given ; /**< @brief Whether header-output-dir was given. */ + unsigned int src_output_dir_given ; /**< @brief Whether src-output-dir was given. */ + unsigned int c_extension_given ; /**< @brief Whether c-extension was given. */ + unsigned int header_extension_given ; /**< @brief Whether header-extension was given. */ + unsigned int long_help_given ; /**< @brief Whether long-help was given. */ + unsigned int default_optional_given ; /**< @brief Whether default-optional was given. */ + unsigned int unamed_opts_given ; /**< @brief Whether unamed-opts was given. */ + unsigned int conf_parser_given ; /**< @brief Whether conf-parser was given. */ + unsigned int string_parser_given ; /**< @brief Whether string-parser was given. */ + unsigned int include_getopt_given ; /**< @brief Whether include-getopt was given. */ + unsigned int no_handle_help_given ; /**< @brief Whether no-handle-help was given. */ + unsigned int no_help_given ; /**< @brief Whether no-help was given. */ + unsigned int no_handle_version_given ; /**< @brief Whether no-handle-version was given. */ + unsigned int no_version_given ; /**< @brief Whether no-version was given. */ + unsigned int no_handle_error_given ; /**< @brief Whether no-handle-error was given. */ + unsigned int show_required_given ; /**< @brief Whether show-required was given. */ + unsigned int gen_version_given ; /**< @brief Whether gen-version was given. */ + unsigned int set_package_given ; /**< @brief Whether set-package was given. */ + unsigned int set_version_given ; /**< @brief Whether set-version was given. */ + unsigned int show_help_given ; /**< @brief Whether show-help was given. */ + unsigned int show_full_help_given ; /**< @brief Whether show-full-help was given. */ + unsigned int show_detailed_help_given ; /**< @brief Whether show-detailed-help was given. */ + unsigned int show_version_given ; /**< @brief Whether show-version was given. */ + +} ; + +/** @brief The additional parameters to pass to parser functions */ +struct cmdline_parser_params +{ + int override; /**< @brief whether to override possibly already present options (default 0) */ + int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ + int check_required; /**< @brief whether to check that all required options were provided (default 1) */ + int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ + int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ +} ; + +/** @brief the purpose string of the program */ +extern const char *gengetopt_args_info_purpose; +/** @brief the usage string of the program */ +extern const char *gengetopt_args_info_usage; +/** @brief all the lines making the help output */ +extern const char *gengetopt_args_info_help[]; +/** @brief all the lines making the detailed help output (including hidden options and details) */ +extern const char *gengetopt_args_info_detailed_help[]; + +/** + * The command line parser + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser (int argc, char **argv, + struct gengetopt_args_info *args_info); + +/** + * The command line parser (version with additional parameters - deprecated) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use cmdline_parser_ext() instead + */ +int cmdline_parser2 (int argc, char **argv, + struct gengetopt_args_info *args_info, + int override, int initialize, int check_required); + +/** + * The command line parser (version with additional parameters) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_ext (int argc, char **argv, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params); + +/** + * Save the contents of the option struct into an already open FILE stream. + * @param outfile the stream where to dump options + * @param args_info the option struct to dump + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_dump(FILE *outfile, + struct gengetopt_args_info *args_info); + +/** + * Save the contents of the option struct into a (text) file. + * This file can be read by the config file parser (if generated by gengetopt) + * @param filename the file where to save + * @param args_info the option struct to save + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_file_save(const char *filename, + struct gengetopt_args_info *args_info); + +/** + * Print the help + */ +void cmdline_parser_print_help(void); +/** + * Print the detailed help (including hidden options and details) + */ +void cmdline_parser_print_detailed_help(void); +/** + * Print the version + */ +void cmdline_parser_print_version(void); + +/** + * Initializes all the fields a cmdline_parser_params structure + * to their default values + * @param params the structure to initialize + */ +void cmdline_parser_params_init(struct cmdline_parser_params *params); + +/** + * Allocates dynamically a cmdline_parser_params structure and initializes + * all its fields to their default values + * @return the created and initialized cmdline_parser_params structure + */ +struct cmdline_parser_params *cmdline_parser_params_create(void); + +/** + * Initializes the passed gengetopt_args_info structure's fields + * (also set default values for options that have a default) + * @param args_info the structure to initialize + */ +void cmdline_parser_init (struct gengetopt_args_info *args_info); +/** + * Deallocates the string fields of the gengetopt_args_info structure + * (but does not deallocate the structure itself) + * @param args_info the structure to deallocate + */ +void cmdline_parser_free (struct gengetopt_args_info *args_info); + +/** + * The string parser (interprets the passed string as a command line) + * @param cmdline the command line stirng + * @param args_info the structure where option information will be stored + * @param prog_name the name of the program that will be used to print + * possible errors + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_string (const char *cmdline, struct gengetopt_args_info *args_info, + const char *prog_name); +/** + * The string parser (version with additional parameters - deprecated) + * @param cmdline the command line stirng + * @param args_info the structure where option information will be stored + * @param prog_name the name of the program that will be used to print + * possible errors + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use cmdline_parser_string_ext() instead + */ +int cmdline_parser_string2 (const char *cmdline, struct gengetopt_args_info *args_info, + const char *prog_name, + int override, int initialize, int check_required); +/** + * The string parser (version with additional parameters) + * @param cmdline the command line stirng + * @param args_info the structure where option information will be stored + * @param prog_name the name of the program that will be used to print + * possible errors + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ +int cmdline_parser_string_ext (const char *cmdline, struct gengetopt_args_info *args_info, + const char *prog_name, + struct cmdline_parser_params *params); + +/** + * Checks that all the required options were specified + * @param args_info the structure to check + * @param prog_name the name of the program that will be used to print + * possible errors + * @return + */ +int cmdline_parser_required (struct gengetopt_args_info *args_info, + const char *prog_name); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* CMDLINE_H */ diff --git a/cmake/gengetopt/errorcodes.h b/cmake/gengetopt/errorcodes.h new file mode 100644 index 0000000..c81ded0 --- /dev/null +++ b/cmake/gengetopt/errorcodes.h @@ -0,0 +1,35 @@ +// +// C++ Interface: errorcodes +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef ERRORCODES_H +#define ERRORCODES_H + +#define NOT_ENOUGH_MEMORY 1 +#define REQ_LONG_OPTION 2 +#define REQ_SHORT_OPTION 3 +#define FOUND_BUG 4 +#define GROUP_UNDEFINED 5 +#define INVALID_DEFAULT_VALUE 6 +#define NOT_REQUESTED_TYPE 7 +#define NOT_VALID_SPECIFICATION 8 +#define SPECIFY_FLAG_STAT 9 +#define NOT_GROUP_OPTION 10 +#define SPECIFY_GROUP 11 +#define INVALID_NUMERIC_VALUE 12 +#define INVALID_ENUM_TYPE_USE 13 +#define MODE_UNDEFINED 14 +#define NOT_MODE_OPTION 15 +#define SPECIFY_MODE 16 +#define HELP_REDEFINED 17 +#define VERSION_REDEFINED 18 + +#endif diff --git a/cmake/gengetopt/fileutils.cpp b/cmake/gengetopt/fileutils.cpp new file mode 100644 index 0000000..d97782c --- /dev/null +++ b/cmake/gengetopt/fileutils.cpp @@ -0,0 +1,52 @@ +// +// C++ Implementation: fileutils +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include +#include +#include + +#include "fileutils.h" + +using namespace std; + +char * +create_filename (char *name, char *ext) +{ + char *filename ; + + filename = (char *) malloc (strlen (name) + strlen (ext) + 2); + /* 2 = 1 for the . and one for the '\0' */ + if (! filename) + { + fprintf (stderr, "Error in memory allocation! %s %d\n", + __FILE__, __LINE__); + abort (); + } + + sprintf (filename, "%s.%s", name, ext); + + return filename ; +} + +ofstream * +open_fstream (const char *filename) +{ + ofstream *fstream = new ofstream (filename); + + if ( ! (*fstream) ) + { + fprintf( stderr, "Error creating %s\n", filename ) ; + abort() ; + } + + return fstream; +} diff --git a/cmake/gengetopt/fileutils.h b/cmake/gengetopt/fileutils.h new file mode 100644 index 0000000..013b7a6 --- /dev/null +++ b/cmake/gengetopt/fileutils.h @@ -0,0 +1,23 @@ +// +// C++ Interface: fileutils +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef FILEUTILS_H +#define FILEUTILS_H + +#include + +using std::ofstream; + +char *create_filename (char *name, char *ext); +ofstream *open_fstream (const char *filename); + +#endif diff --git a/cmake/gengetopt/gengetopt.cc b/cmake/gengetopt/gengetopt.cc new file mode 100644 index 0000000..8ad790e --- /dev/null +++ b/cmake/gengetopt/gengetopt.cc @@ -0,0 +1,950 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +void gengetopt_free (void); + +/* The following one is generated by gengetopt itself */ +#include "cmdline.h" + +extern int yyparse () ; + +#include "gengetopt.h" +#include "errorcodes.h" + +#include "argsdef.h" +#include "global_opts.h" + +#include "my_sstream.h" +#include "my_string.h" + +#include "gm.h" +#include "groups.h" +#include "gm_utils.h" + +#include "skels/copyright.h" + +#include "yyerror.h" +#include "globals.h" + +char * gengetopt_package = NULL; +char * gengetopt_version = NULL; +char * gengetopt_purpose = NULL; +char * gengetopt_description = NULL; +char * gengetopt_usage = NULL; + +modes_collection_t gengetopt_modes; + +int gengetopt_count_line = 1; +char * gengetopt_input_filename = 0; +char *current_section = 0; +char *current_section_desc = 0; +char *current_text = 0; +char *current_args = 0; + +/// whether, if not specified, an option is considered optional +bool default_to_optional = false; + +int canonize_vars (void); +static void set_default_required_properties(void); + +static void print_copyright(); +static void print_reportbugs(); + +static void output_formatted_string(const string &); + +static bool check_dependencies(); + +static int gengetopt_create_option (gengetopt_option *&opt, const char * long_opt, char short_opt, + const char * desc, + int type, int flagstat, int required, + const char *default_value, + const char * group_value, + const char * mode_value, + const char * type_str, + const AcceptedValues *acceptedvalues, + int multiple = 0, + int argoptional = 0); + + +#include +#include + +using namespace std; + +/// the structure for command line arguments +struct gengetopt_args_info args_info ; + +int +main (int argc, char **argv) +{ + char *cmdline_parser_name ; /* name of the generated function */ + char *cmdline_filename ; /* name of generated file */ + char *c_ext ; /* extenstion of c file */ + char *header_ext ; /* extenstion of header file */ + string output_dir, header_output_dir, src_output_dir; /* output directory (default empty -> current dir)*/ + + int i, has_help, has_version; + FILE *input_file ; + + if (cmdline_parser (argc, argv, &args_info) != 0) { + fprintf (stderr, "Run gengetopt --help to see the list of options.\n"); + exit(1) ; + } + + if (args_info.help_given) + { + cmdline_parser_print_help (); + print_reportbugs (); + exit (0); + } + + if (args_info.detailed_help_given) + { + cmdline_parser_print_detailed_help (); + print_reportbugs (); + exit (0); + } + + if (args_info.version_given) + { + cmdline_parser_print_version (); + print_copyright (); + exit (0); + } + + if ( args_info.input_arg ) + { + gengetopt_input_filename = strdup (args_info.input_arg); + input_file = freopen (args_info.input_arg, "r", stdin) ; + if (!input_file) + { + fprintf (stderr, "Error opening input file: %s\n", + args_info.input_arg); + exit (1); + } + } /* else standard input is used */ + + if (yyparse () != 0) { + gengetopt_free (); + return 1; + } + + // check whether some options were given in the input file + bool no_options = (gengetopt_options.size() == 0); + + if (current_args) { + // parse the arguments passed in the "args" part of the input file + // by possibily overriding those given at command line + if (cmdline_parser_string2 (current_args, &args_info, "gengetopt", 1, 0, 0) != 0) { + fprintf (stderr, "Error in the args specification of the input_file.\n"); + exit(1) ; + } + } + + cmdline_parser_name = args_info.func_name_arg ; + cmdline_filename = args_info.file_name_arg ; + c_ext = args_info.c_extension_arg; + header_ext = args_info.header_extension_arg; + + default_to_optional = args_info.default_optional_given; + + // now set the default "required" property for options + set_default_required_properties(); + + if (! check_dependencies()) { + gengetopt_free(); + return 1; + } + + // insert options for help and version if not already present + gengetopt_option *opt; + + if (current_section) + free(current_section); + current_section = 0; + + has_version = gengetopt_has_option (VERSION_LONG_OPT, VERSION_SHORT_OPT); + + if (has_version != REQ_LONG_OPTION && !args_info.no_version_given) { + gengetopt_create_option (opt, VERSION_LONG_OPT, has_version ? '-' : VERSION_SHORT_OPT, + VERSION_OPT_DESCR, ARG_NO, 0, 0, 0, 0, 0, 0, 0); + gengetopt_options.push_front(opt); + } + + if (!args_info.no_help_given && has_hidden_options() && gengetopt_has_option(FULL_HELP_LONG_OPT, 0) == 0) { + gengetopt_create_option (opt, FULL_HELP_LONG_OPT, '-', + FULL_HELP_OPT_DESCR, ARG_NO, 0, 0, 0, 0, 0, 0, 0); + gengetopt_options.push_front(opt); + } + + if (!args_info.no_help_given && has_options_with_details() && gengetopt_has_option(DETAILED_HELP_LONG_OPT, 0) == 0) { + gengetopt_create_option (opt, DETAILED_HELP_LONG_OPT, '-', + DETAILED_HELP_OPT_DESCR, ARG_NO, 0, 0, 0, 0, 0, 0, 0); + gengetopt_options.push_front(opt); + } + + has_help = gengetopt_has_option(HELP_LONG_OPT, HELP_SHORT_OPT); + + if (has_help != REQ_LONG_OPTION && !args_info.no_help_given) { + gengetopt_create_option (opt, HELP_LONG_OPT, has_help ? '-' : HELP_SHORT_OPT, + HELP_OPT_DESCR, ARG_NO, 0, 0, 0, 0, 0, 0, 0); + gengetopt_options.push_front(opt); + } + + // check whether there's pending text after all options and + // in case, set it to the last option + if (current_text && gengetopt_options.size()) { + gengetopt_options.back()->text_after = current_text; + gengetopt_set_text(0); + } + + if (canonize_vars ()) { + gengetopt_free (); + return 1; + } + + if (args_info.set_package_given) { + if (gengetopt_package) + free (gengetopt_package); + gengetopt_package = args_info.set_package_arg; + } + + if (args_info.set_version_given) { + if (gengetopt_version) + free (gengetopt_version); + gengetopt_version = args_info.set_version_arg; + } + + ostringstream command_line; + for ( i = 0; i < argc ; ++i ) + command_line << argv[i] << " "; + + // add also possible args specification in the input file + if (current_args) + command_line << current_args; + + if (args_info.output_dir_given) + output_dir = args_info.output_dir_arg; + if (args_info.header_output_dir_given) + header_output_dir = args_info.header_output_dir_arg; + if (args_info.src_output_dir_given) + src_output_dir = args_info.src_output_dir_arg; + + CmdlineParserCreator cmdline_parser_creator + (cmdline_parser_name, + args_info.arg_struct_name_arg, + (args_info.unamed_opts_given ? args_info.unamed_opts_arg : 0), + cmdline_filename, + header_ext, + c_ext, + args_info.long_help_given, + args_info.no_handle_help_given, + args_info.no_help_given, + args_info.no_handle_version_given, + args_info.no_version_given, + args_info.no_handle_error_given, + args_info.conf_parser_given, + args_info.string_parser_given, + args_info.gen_version_flag, + args_info.include_getopt_given, + no_options, + command_line.str (), + output_dir, + header_output_dir, + src_output_dir, + (args_info.show_required_given ? args_info.show_required_arg : "")); + + if (! gengetopt_package && (args_info.show_version_given || args_info.show_help_given)) + { + cerr << "package not defined; please specify it with --set-package" << endl; + return 1; + } + else if (! gengetopt_version && (args_info.show_version_given || args_info.show_help_given)) + { + cerr << "version not defined; please specify it with --set-version" << endl; + return 1; + } + else if (args_info.show_version_given) + { + cout << gengetopt_package << " " << gengetopt_version << endl; + } + else if (args_info.show_help_given || + args_info.show_full_help_given || args_info.show_detailed_help_given) + { + cout << gengetopt_package << " " << gengetopt_version << "\n" << endl; + + if (gengetopt_purpose) { + output_formatted_string(cmdline_parser_creator.generate_purpose()); + cout << endl; + } + + output_formatted_string("Usage: " + + cmdline_parser_creator.generate_usage_string(false) + "\n"); + + if (gengetopt_description) { + output_formatted_string(cmdline_parser_creator.generate_description()); + cout << endl; + } + + // if --show-full-help is specified we have to generate also hidden options + OptionHelpList *option_list = + cmdline_parser_creator.generate_help_option_list(args_info.show_full_help_given, args_info.show_detailed_help_given); + + std::for_each(option_list->begin(), option_list->end(), + output_formatted_string); + + delete option_list; + } + else if (cmdline_parser_creator.generate ()) + { + gengetopt_free (); + return 1; + } + + gengetopt_free (); + + return 0; +} + +void +output_formatted_string(const string &s) +{ + for (string::const_iterator it = s.begin(); it != s.end(); ++it) + { + if (*it == '\\' && ((it+1) != s.end()) && *(it+1) == 'n') { + cout << "\n"; + ++it; + } else if (*it == '\\' && ((it+1) != s.end()) && *(it+1) == '"') { + cout << "\""; + ++it; + } else + cout << *it; + } + + cout << endl; +} + +/* ************* */ + +int +gengetopt_define_package (char * s) +{ + gengetopt_package = strdup (s); + if (gengetopt_package == NULL) + return 1; + return 0; +} + +int +gengetopt_define_version (char * s) +{ + gengetopt_version = strdup (s); + if (gengetopt_version == NULL) + return 1; + return 0; +} + +int +gengetopt_define_purpose (char * s) +{ + gengetopt_purpose = strdup (s); + if (gengetopt_purpose == NULL) + return 1; + return 0; +} + +int +gengetopt_define_description (char * s) +{ + gengetopt_description = strdup (s); + if (gengetopt_description == NULL) + return 1; + return 0; +} + +int gengetopt_define_usage (char * s) +{ + gengetopt_usage = strdup (s); + if (gengetopt_usage == NULL) + return 1; + return 0; +} + +int +gengetopt_add_group (const char *s, const char *desc, int required) +{ + string group_desc; + if (desc) + group_desc = desc; + if ( !gengetopt_groups.insert + (make_pair(string(s),Group (group_desc, required != 0))).second ) + return 1; + else + return 0; +} + +int +gengetopt_add_mode (const char *s, const char *desc) +{ + string mode_desc; + if (desc) + mode_desc = desc; + if ( !gengetopt_modes.insert + (make_pair(string(s),Mode (mode_desc))).second ) + return 1; + else + return 0; +} + +void +gengetopt_set_section (const char * s, const char *desc) +{ + if (current_section) + free (current_section); + if (current_section_desc) + free (current_section_desc); + current_section = strdup (s); + if (desc) + current_section_desc = strdup (desc); + else + current_section_desc = 0; +} + +void +gengetopt_set_text (const char * desc) +{ + /* + no need to free it, since it will be then owned by the + option only + + if (current_text) + free (current_text); + */ + + // the current text is reset + if (!desc) { + current_text = 0; + return; + } + + if (current_text) { + // a previous text was collected, so we append the new text + // to the current one. + string buffer = current_text; + buffer += desc; + current_text = strdup(buffer.c_str()); + return; + } + + // otherwise simply copy the passed text + current_text = strdup (desc); +} + +void gengetopt_set_args(const char *a) +{ + if (current_args) + free(current_args); + + if (a) + current_args = strdup(a); + else + current_args = 0; +} + +int +gengetopt_has_option (const char * long_opt, char short_opt) +{ + gengetopt_option * n; + + for (gengetopt_option_list::const_iterator it = gengetopt_options.begin(); + it != gengetopt_options.end(); ++it) + { + n = *it; + if (!strcmp (n->long_opt, long_opt)) return REQ_LONG_OPTION; + if (short_opt && n->short_opt == short_opt) + return REQ_SHORT_OPTION; + } + + return 0; +} + +bool check_numeric_validity(const char *val, int opt_type) +{ + char *end_of_string, *expected_eos; + + expected_eos = (char *) (val + strlen(val)); + + switch ( opt_type ) + { + case ARG_INT : + case ARG_SHORT : + case ARG_LONG : + case ARG_LONGLONG : + (void) strtol(val, &end_of_string, 0); + break; + + case ARG_FLOAT: + case ARG_DOUBLE: + case ARG_LONGDOUBLE: + (void) strtod(val, &end_of_string); + break; + + default : + // This will allow us to factorise as a single line the + // test for correctness of the default value + end_of_string = expected_eos; + break; + } + return ( end_of_string == expected_eos ); +} + +bool +check_values(const AcceptedValues *acceptedvalues, int opt_type) +{ + for (AcceptedValues::const_iterator it = acceptedvalues->begin(); + it != acceptedvalues->end(); ++it) { + if (!check_numeric_validity((*it).c_str(), opt_type)) + return false; + } + + return true; +} + +int +gengetopt_create_option (gengetopt_option *&n, const char * long_opt, char short_opt, + const char * desc, + int type, int flagstat, int required, + const char * default_value, + const char * group_value, + const char * mode_value, + const char * type_str, + const AcceptedValues *acceptedvalues, + int multiple, + int argoptional) +{ + if ((long_opt == NULL) || + (long_opt[0] == 0) || + (desc == NULL)) + return FOUND_BUG; + + n = new gengetopt_option; + if (n == NULL) + return NOT_ENOUGH_MEMORY; + + // here we will set required anyway + n->required_set = true; + + n->long_opt = strdup (long_opt); + if (n->long_opt == NULL) + { + free (n); + return NOT_ENOUGH_MEMORY; + } + + n->desc = strdup (desc); + if (n->desc == NULL) + { + free (n->long_opt); + free (n); + return NOT_ENOUGH_MEMORY; + } + + n->short_opt = ((short_opt == '-') ? 0 : short_opt); + n->type = type; + n->flagstat = flagstat; + n->required = required; + n->multiple = (multiple != 0); + n->arg_is_optional = (argoptional != 0); + + if (type_str != 0) + n->type_str = strdup(type_str); + else + n->type_str = NULL; + + n->section = 0; + n->section_desc = 0; + if (current_section) + n->section = strdup (current_section); + if (current_section_desc) + n->section_desc = strdup (current_section_desc); + + if (group_value != 0) + { + n->group_value = strdup(group_value); + n->required = 0; + groups_collection_t::const_iterator it = + gengetopt_groups.find(string(n->group_value)); + if (it == gengetopt_groups.end()) + return GROUP_UNDEFINED; + n->group_desc = strdup (it->second.desc.c_str ()); + } + else + { + n->group_value = 0; + } + + if (mode_value != 0) { + n->mode_value = strdup(mode_value); + modes_collection_t::const_iterator it = + gengetopt_modes.find(string(n->mode_value)); + if (it == gengetopt_modes.end()) + return MODE_UNDEFINED; + n->mode_desc = strdup (it->second.desc.c_str ()); + } else { + n->mode_value = 0; + } + + if (n->group_value && n->mode_value) + return FOUND_BUG; + + + n->acceptedvalues = acceptedvalues; + + // if (acceptedvalues && type != ARG_NO) + // return NOT_REQUESTED_TYPE; + + if (acceptedvalues && ! (n->type)) + n->type = ARG_STRING; + + n->default_string = 0; + n->default_given = (default_value != 0); + if (n->default_given) + { + n->default_string = strdup (default_value); + if ( ! check_numeric_validity(default_value, n->type) ) + { + free (n); + return INVALID_DEFAULT_VALUE; + } + + if (acceptedvalues) + { + if (! acceptedvalues->contains(n->default_string)) + return INVALID_DEFAULT_VALUE; + } + } + + if (acceptedvalues) { + if (!check_values(acceptedvalues, n->type)) + return INVALID_NUMERIC_VALUE; + } + + n->var_arg = NULL; + + return 0; +} + +int +gengetopt_check_option (gengetopt_option *n, bool groupoption, bool modeoption) +{ + if ((n->long_opt == NULL) || + (n->long_opt[0] == 0) || + (n->desc == NULL)) + return FOUND_BUG; + + if (strcmp(n->long_opt, HELP_LONG_OPT) == 0 && !args_info.no_help_given) + return HELP_REDEFINED; + + if (strcmp(n->long_opt, VERSION_LONG_OPT) == 0 && !args_info.no_version_given) + return VERSION_REDEFINED; + + n->section = 0; + n->section_desc = 0; + if (current_section) + n->section = strdup (current_section); + if (current_section_desc) + n->section_desc = strdup (current_section_desc); + + n->text_before = current_text; + // reset the description + gengetopt_set_text(0); + + if (n->group_value != 0) + { + if (! groupoption) + return NOT_GROUP_OPTION; + + n->required = 0; + n->required_set = true; + + groups_collection_t::const_iterator it = + gengetopt_groups.find(string(n->group_value)); + if (it == gengetopt_groups.end()) + return GROUP_UNDEFINED; + n->group_desc = strdup (it->second.desc.c_str ()); + } + else + { + if (groupoption) + return SPECIFY_GROUP; + } + + if (n->mode_value != 0) + { + if (! modeoption) + return NOT_MODE_OPTION; + + modes_collection_t::const_iterator it = + gengetopt_modes.find(string(n->mode_value)); + if (it == gengetopt_modes.end()) + return MODE_UNDEFINED; + n->mode_desc = strdup (it->second.desc.c_str ()); + } + else + { + if (modeoption) + return SPECIFY_MODE; + } + + if (n->group_value && n->mode_value) + return FOUND_BUG; + + // now we have to check for flag options + if (n->type == ARG_FLAG) + { + if (n->flagstat < 0) + return SPECIFY_FLAG_STAT; + + if (n->default_string || n->multiple || n->arg_is_optional + || n->type_str || n->acceptedvalues || n->required_set) + return NOT_VALID_SPECIFICATION; + + n->required = 0; + n->required_set = true; + } + else + { + if (n->flagstat >= 0) + return NOT_VALID_SPECIFICATION; + } + + // enum type can only be specified with options with values + if (n->type == ARG_ENUM && !(n->acceptedvalues)) { + return INVALID_ENUM_TYPE_USE; + } + + // if (acceptedvalues && type != ARG_NO) + // return NOT_REQUESTED_TYPE; + + if (n->acceptedvalues && ! (n->type)) + n->type = ARG_STRING; + + n->default_given = (n->default_string != 0); + if (n->default_given) + { + if ( !check_numeric_validity(n->default_string, n->type) ) + { + return INVALID_DEFAULT_VALUE; + } + + if (n->acceptedvalues) + { + if (! n->acceptedvalues->contains(n->default_string)) + return INVALID_DEFAULT_VALUE; + } + } + + if (n->acceptedvalues) { + if (!check_values(n->acceptedvalues, n->type)) + return INVALID_NUMERIC_VALUE; + } + + n->var_arg = NULL; + + return 0; +} + +int +gengetopt_add_option (const char * long_opt, char short_opt, + const char * desc, + int type, int flagstat, int required, + const char * default_value, + const char * group_value, + const char * mode_value, + const char * type_str, + const AcceptedValues *acceptedvalues, + int multiple, + int argoptional) +{ + gengetopt_option * n; + + /* search for collisions */ + int res = gengetopt_has_option(long_opt, short_opt); + if (res != 0) + return res; + + res = gengetopt_create_option(n, long_opt, short_opt, + desc, type, flagstat, required, default_value, group_value, mode_value, + type_str, acceptedvalues, multiple, argoptional); + if (res != 0) + return res; + + gengetopt_options.push_back(n); + + return 0; +} + +int +gengetopt_add_option (gengetopt_option * n) +{ + /* search for collisions */ + int res = gengetopt_has_option(n); + if (res != 0) + return res; + + gengetopt_options.push_back(n); + + return 0; +} + +int +gengetopt_has_option (gengetopt_option * opt) +{ + gengetopt_option * n; + + for (gengetopt_option_list::const_iterator it = gengetopt_options.begin(); + it != gengetopt_options.end(); ++it) + { + n = *it; + if (!strcmp (n->long_opt, opt->long_opt)) + return REQ_LONG_OPTION; + if (opt->short_opt && n->short_opt == opt->short_opt) + return REQ_SHORT_OPTION; + } + + return 0; +} + +bool +check_dependencies() +{ + gengetopt_option * n; + bool result = true; + + for (gengetopt_option_list::const_iterator it = gengetopt_options.begin(); + it != gengetopt_options.end(); ++it) + { + n = *it; + if (n->dependon) { + if (strcmp(n->dependon, n->long_opt) == 0) { + yyerror(n, "option depends on itself"); + result = false; + continue; + } + + bool found = false; + for (gengetopt_option_list::const_iterator it2 = gengetopt_options.begin(); + it2 != gengetopt_options.end(); ++it2) + { + if (strcmp(n->dependon, (*it2)->long_opt) == 0) { + found = true; + break; + } + } + + if (! found) { + yyerror (n, "option depends on undefined option"); + result = false; + } + } + } + + return result; +} + +void +gengetopt_free (void) +{ + gengetopt_option *p; + + if (gengetopt_package != NULL) + free (gengetopt_package); + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it != gengetopt_options.end(); ++it) + { + p = *it; + if (p->long_opt != NULL) free (p->long_opt); + if (p->desc != NULL) free (p->desc); + if (p->var_arg != NULL) free (p->var_arg); + if (p->acceptedvalues) delete p->acceptedvalues; + delete p; + } +} + +static void +canonize_var (gengetopt_option *p) +{ + char *pvar; + + p->var_arg = strdup (p->long_opt); + if (p->var_arg == NULL) { + printf ("gengetopt: not enough memory to canonize vars\n"); + abort(); + } + + for (pvar = p->var_arg; *pvar; pvar++) + if (*pvar == '.' || *pvar == '-') *pvar = '_'; +} + +int +canonize_vars (void) +{ + for_each(gengetopt_options.begin(), gengetopt_options.end(), canonize_var); + + return 0; +} + +static void +set_default_required_prop (gengetopt_option *p) +{ + if (!p->required_set) + p->required = (default_to_optional ? 0 : 1); +} + +static void set_default_required_properties(void) +{ + for_each(gengetopt_options.begin(), gengetopt_options.end(), set_default_required_prop); +} + +void +print_copyright() +{ + copyright_gen_class copyright_g; + + copyright_g.set_year ("1999-2009"); + copyright_g.generate_copyright (cout); +} + +void +print_reportbugs() +{ + cout << endl; + cout << "Maintained by Lorenzo Bettini " << endl; + cout << "Report bugs to " << endl; +} diff --git a/cmake/gengetopt/gengetopt.h b/cmake/gengetopt/gengetopt.h new file mode 100644 index 0000000..c464ea2 --- /dev/null +++ b/cmake/gengetopt/gengetopt.h @@ -0,0 +1,75 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _GENGETOPT_H +#define _GENGETOPT_H + +#include "acceptedvalues.h" +#include "ggos.h" + +int gengetopt_define_package (char * s) ; +int gengetopt_define_version (char * s) ; +int gengetopt_define_purpose (char * s) ; +int gengetopt_define_description (char * s) ; +int gengetopt_define_usage (char * s) ; + +/** + * Sets the "global" section specification that will be then set + * in the following options + * @param s The section + * @param sd The section description + */ +void gengetopt_set_section (const char * s, const char *sd) ; + +/** + * Sets the "global" text string that will be inserted in + * a specific field of the next option + * @param desc The text string + */ +void gengetopt_set_text (const char * desc) ; + +/** + * Sets the "global" text string containing the arguments + * that complement the command line arguments of gengetopt. + * @param args + */ +void gengetopt_set_args (const char *args); + +int gengetopt_add_group (const char * s, const char *desc, int required) ; +int gengetopt_add_mode (const char * s, const char *desc) ; + +int gengetopt_has_option (const char * long_opt, char short_opt); +int gengetopt_add_option (const char * long_opt, char short_opt, + const char * desc, + int type, int flagstat, int required, + const char *default_value, + const char * group_value, + const char * mode_value, + const char * type_str, + const AcceptedValues *acceptedvalues, + int multiple = 0, + int argoptional = 0); + +int gengetopt_has_option (gengetopt_option *opt); +int gengetopt_check_option (gengetopt_option *opt, + bool groupoption = false, bool modeoption = false); +int gengetopt_add_option (gengetopt_option *opt); + +#endif /* _GENGETOPT_H */ diff --git a/cmake/gengetopt/getopt.c b/cmake/gengetopt/getopt.c new file mode 100644 index 0000000..9fb69b1 --- /dev/null +++ b/cmake/gengetopt/getopt.c @@ -0,0 +1,1055 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to drepper@gnu.org + before changing it! + Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This tells Alpha OSF/1 not to define a getopt prototype in . + Ditto for AIX 3.2 and . */ +#ifndef _NO_PROTO +# define _NO_PROTO +#endif + +#ifdef HAVE_CONFIG_H +# include +#endif + +#if !defined __STDC__ || !__STDC__ +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +# ifndef const +# define const +# endif +#endif + +#include + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#define GETOPT_INTERFACE_VERSION 2 +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 +# include +# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION +# define ELIDE_CODE +# endif +#endif + +#ifndef ELIDE_CODE + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +/* Don't include stdlib.h for non-GNU C libraries because some of them + contain conflicting prototypes for getopt. */ +# include +# include +#endif /* GNU C library. */ + +#ifdef VMS +# include +# if HAVE_STRING_H - 0 +# include +# endif +#endif + +#ifndef _ +/* This is for other GNU distributions with internationalized messages. */ +# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC +# include +# ifndef _ +# define _(msgid) gettext (msgid) +# endif +# else +# define _(msgid) (msgid) +# endif +#endif + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* Formerly, initialization of getopt depended on optind==0, which + causes problems with re-calling getopt as programs generally don't + know that. */ + +int __getopt_initialized; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return -1 with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; + +#ifdef __GNU_LIBRARY__ +/* We want to avoid inclusion of string.h with non-GNU libraries + because there are many ways it can cause trouble. + On some systems, it contains special magic macros that don't work + in GCC. */ +# include +# define my_index strchr +#else + +# if HAVE_STRING_H +# include +# else +# include +# endif + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +#ifndef getenv +extern char *getenv (); +#endif + +static char * +my_index (str, chr) + const char *str; + int chr; +{ + while (*str) + { + if (*str == chr) + return (char *) str; + str++; + } + return 0; +} + +/* If using GCC, we can safely declare strlen this way. + If not using GCC, it is ok not to declare it. */ +#ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ +# if (!defined __STDC__ || !__STDC__) && !defined strlen +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); +# endif /* not __STDC__ */ +#endif /* __GNUC__ */ + +#endif /* not __GNU_LIBRARY__ */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +#ifdef _LIBC +/* Stored original parameters. + XXX This is no good solution. We should rather copy the args so + that we can compare them later. But we must not use malloc(3). */ +extern int __libc_argc; +extern char **__libc_argv; + +/* Bash 2.0 gives us an environment variable containing flags + indicating ARGV elements that should not be considered arguments. */ + +# ifdef USE_NONOPTION_FLAGS +/* Defined in getopt_init.c */ +extern char *__getopt_nonoption_flags; + +static int nonoption_flags_max_len; +static int nonoption_flags_len; +# endif + +# ifdef USE_NONOPTION_FLAGS +# define SWAP_FLAGS(ch1, ch2) \ + if (nonoption_flags_len > 0) \ + { \ + char __tmp = __getopt_nonoption_flags[ch1]; \ + __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ + __getopt_nonoption_flags[ch2] = __tmp; \ + } +# else +# define SWAP_FLAGS(ch1, ch2) +# endif +#else /* !_LIBC */ +# define SWAP_FLAGS(ch1, ch2) +#endif /* _LIBC */ + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +#if defined __STDC__ && __STDC__ +static void exchange (char **); +#endif + +static void +exchange (argv) + char **argv; +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + /* First make sure the handling of the `__getopt_nonoption_flags' + string can work normally. Our top argument must be in the range + of the string. */ + if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) + { + /* We must extend the array. The user plays games with us and + presents new arguments. */ + char *new_str = malloc (top + 1); + if (new_str == NULL) + nonoption_flags_len = nonoption_flags_max_len = 0; + else + { + memset (__mempcpy (new_str, __getopt_nonoption_flags, + nonoption_flags_max_len), + '\0', top + 1 - nonoption_flags_max_len); + nonoption_flags_max_len = top + 1; + __getopt_nonoption_flags = new_str; + } + } +#endif + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + SWAP_FLAGS (bottom + i, middle + i); + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Initialize the internal data when the first call is made. */ + +#if defined __STDC__ && __STDC__ +static const char *_getopt_initialize (int, char *const *, const char *); +#endif +static const char * +_getopt_initialize (argc, argv, optstring) + int argc; + char *const *argv; + const char *optstring; +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + first_nonopt = last_nonopt = optind; + + nextchar = NULL; + + posixly_correct = getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + if (posixly_correct == NULL + && argc == __libc_argc && argv == __libc_argv) + { + if (nonoption_flags_max_len == 0) + { + if (__getopt_nonoption_flags == NULL + || __getopt_nonoption_flags[0] == '\0') + nonoption_flags_max_len = -1; + else + { + const char *orig_str = __getopt_nonoption_flags; + int len = nonoption_flags_max_len = strlen (orig_str); + if (nonoption_flags_max_len < argc) + nonoption_flags_max_len = argc; + __getopt_nonoption_flags = + (char *) malloc (nonoption_flags_max_len); + if (__getopt_nonoption_flags == NULL) + nonoption_flags_max_len = -1; + else + memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), + '\0', nonoption_flags_max_len - len); + } + } + nonoption_flags_len = nonoption_flags_max_len; + } + else + nonoption_flags_len = 0; +#endif + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns -1. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (argc, argv, optstring, longopts, longind, long_only) + int argc; + char *const *argv; + const char *optstring; + const struct option *longopts; + int *longind; + int long_only; +{ + int print_errors = opterr; + if (optstring[0] == ':') + print_errors = 0; + + if (argc < 1) + return -1; + + optarg = NULL; + + if (optind == 0 || !__getopt_initialized) + { + if (optind == 0) + optind = 1; /* Don't scan ARGV[0], the program name. */ + optstring = _getopt_initialize (argc, argv, optstring); + __getopt_initialized = 1; + } + + /* Test whether ARGV[optind] points to a non-option argument. + Either it does not have option syntax, or there is an environment flag + from the shell indicating it is not an option. The later information + is only used when the used in the GNU libc. */ +#if defined _LIBC && defined USE_NONOPTION_FLAGS +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ + || (optind < nonoption_flags_len \ + && __getopt_nonoption_flags[optind] == '1')) +#else +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') +#endif + + if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been + moved back by the user (who may also have changed the arguments). */ + if (last_nonopt > optind) + last_nonopt = optind; + if (first_nonopt > optind) + first_nonopt = optind; + + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc && NONOPTION_P) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return -1; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if (NONOPTION_P) + { + if (ordering == REQUIRE_ORDER) + return -1; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = -1; + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) + == (unsigned int) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else if (long_only + || pfound->has_arg != p->has_arg + || pfound->flag != p->flag + || pfound->val != p->val) + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (print_errors) + fprintf (stderr, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + optopt = 0; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (print_errors) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + _("%s: option `--%s' doesn't allow an argument\n"), + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + _("%s: option `%c%s' doesn't allow an argument\n"), + argv[0], argv[optind - 1][0], pfound->name); + } + + nextchar += strlen (nextchar); + + optopt = pfound->val; + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (print_errors) + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + optopt = pfound->val; + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || my_index (optstring, *nextchar) == NULL) + { + if (print_errors) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, _("%s: unrecognized option `--%s'\n"), + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + optopt = 0; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (print_errors) + { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: illegal option -- %c\n"), + argv[0], c); + else + fprintf (stderr, _("%s: invalid option -- %c\n"), + argv[0], c); + } + optopt = c; + return '?'; + } + /* Convenience. Treat POSIX -W foo same as long option --foo */ + if (temp[0] == 'W' && temp[1] == ';') + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (print_errors) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + return c; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + + /* optarg is now the argument, see if it's in the + table of longopts. */ + + for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) + { + if (print_errors) + fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + if (pfound != NULL) + { + option_index = indfound; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (print_errors) + fprintf (stderr, _("\ +%s: option `-W %s' doesn't allow an argument\n"), + argv[0], pfound->name); + + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (print_errors) + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + nextchar = NULL; + return 'W'; /* Let the application handle it. */ + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (print_errors) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, + _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (argc, argv, optstring) + int argc; + char *const *argv; + const char *optstring; +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#endif /* Not ELIDE_CODE. */ + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == -1) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/cmake/gengetopt/getopt1.c b/cmake/gengetopt/getopt1.c new file mode 100644 index 0000000..22a7efb --- /dev/null +++ b/cmake/gengetopt/getopt1.c @@ -0,0 +1,188 @@ +/* getopt_long and getopt_long_only entry points for GNU getopt. + Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "getopt.h" + +#if !defined __STDC__ || !__STDC__ +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +#ifndef const +#define const +#endif +#endif + +#include + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#define GETOPT_INTERFACE_VERSION 2 +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 +#include +#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION +#define ELIDE_CODE +#endif +#endif + +#ifndef ELIDE_CODE + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +#include +#endif + +#ifndef NULL +#define NULL 0 +#endif + +int +getopt_long (argc, argv, options, long_options, opt_index) + int argc; + char *const *argv; + const char *options; + const struct option *long_options; + int *opt_index; +{ + return _getopt_internal (argc, argv, options, long_options, opt_index, 0); +} + +/* Like getopt_long, but '-' as well as '--' can indicate a long option. + If an option that starts with '-' (not '--') doesn't match a long option, + but does match a short option, it is parsed as a short option + instead. */ + +int +getopt_long_only (argc, argv, options, long_options, opt_index) + int argc; + char *const *argv; + const char *options; + const struct option *long_options; + int *opt_index; +{ + return _getopt_internal (argc, argv, options, long_options, opt_index, 1); +} + + +#endif /* Not ELIDE_CODE. */ + +#ifdef TEST + +#include + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static struct option long_options[] = + { + {"add", 1, 0, 0}, + {"append", 0, 0, 0}, + {"delete", 1, 0, 0}, + {"verbose", 0, 0, 0}, + {"create", 0, 0, 0}, + {"file", 1, 0, 0}, + {0, 0, 0, 0} + }; + + c = getopt_long (argc, argv, "abc:d:0123456789", + long_options, &option_index); + if (c == -1) + break; + + switch (c) + { + case 0: + printf ("option %s", long_options[option_index].name); + if (optarg) + printf (" with arg %s", optarg); + printf ("\n"); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case 'd': + printf ("option d with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/cmake/gengetopt/ggo_options.h b/cmake/gengetopt/ggo_options.h new file mode 100644 index 0000000..f3b218e --- /dev/null +++ b/cmake/gengetopt/ggo_options.h @@ -0,0 +1,12 @@ +#ifndef GGO_OPTIONS_H +#define GGO_OPTIONS_H + +#include "ggos.h" + +extern gengetopt_option_list gengetopt_options; + +#define foropt for (gengetopt_option_list::iterator it = gengetopt_options.begin(); \ + it != gengetopt_options.end() && (opt = *it); \ + ++it) + +#endif /* GGO_OPTIONS_H */ diff --git a/cmake/gengetopt/ggos.cpp b/cmake/gengetopt/ggos.cpp new file mode 100644 index 0000000..11e92a3 --- /dev/null +++ b/cmake/gengetopt/ggos.cpp @@ -0,0 +1,35 @@ +// +// C++ Implementation: ggos +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2005-2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "ggos.h" + +using namespace std; + +gengetopt_option::gengetopt_option() : + short_opt(0), long_opt(0), desc(0), type(ARG_NO), flagstat(-1), + required(1), required_set(false), var_arg(0), default_string(0), + group_value(0), group_desc(0), + mode_value(0), mode_desc(0), + multiple(false), + arg_is_optional(false), hidden(false), type_str(0), + acceptedvalues(0), section(0), section_desc(0), dependon(0), + text_before(0), text_after(0), details(0), filename(0), linenum(0) { +} + +ostream & operator <<(std::ostream &s, gengetopt_option &opt) { + s << "long: " << opt.long_opt << ", short: " << opt.short_opt << "\n" + << "desc: " << opt.desc; + + s << endl; + + return s; +} diff --git a/cmake/gengetopt/ggos.h b/cmake/gengetopt/ggos.h new file mode 100644 index 0000000..e2c96f5 --- /dev/null +++ b/cmake/gengetopt/ggos.h @@ -0,0 +1,69 @@ +/* +This file is licensed to you under the license specified in the included file +`LICENSE'. Look there for further details. +*/ + + +#ifndef _GENGETOPT_GGOS_H +#define _GENGETOPT_GGOS_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "acceptedvalues.h" +#include "argsdef.h" + +/** + * The structure for storing an option specified in the .ggo file + */ +struct gengetopt_option +{ + char short_opt; /**< the short option specification (one char) */ + char * long_opt; /**< the short option specification */ + char * desc; /**< the option description */ + int type; /**< the type of the option (possible values in `argsdef.h') */ + int flagstat ; /**< if the option is of type flag, this indicates its state (on/off) */ + int required; /**< whether the option required */ + bool required_set; /**< whether the required property was set */ + char * var_arg; /**< canonized long_opt + "_arg" = argument var */ + int default_given ; /**< if a default is given */ + char * default_string ; /**< default value for this option, if string */ + char * group_value; /**< group name, if it's part of an option group */ + char * group_desc; /**< group description, if it's part of an option group */ + char * mode_value; /**< mode name, if it's part of an option mode */ + char * mode_desc; /**< mode description, if it's part of an option mode */ + bool multiple; /**< whether this option can be given more than once */ + char * multiple_min; /**< minimum occurrences of a multiple option (-1: not specified) */ + char * multiple_max; /**< maximum occurrences of a multiple option (-1: not specified) */ + bool arg_is_optional; /**< whether the argument is optional */ + bool hidden; /**< whether this option will be hidden from the help output */ + char *type_str; /**< Alternative name for type, + e.g. "URL" or "SECONDS" */ + const AcceptedValues *acceptedvalues; /**< values that can be passed to this option */ + char *section; /**< the section of this option */ + char *section_desc; /**< the description associated with the possible section */ + char *dependon; /**< the name of the option this one depends on */ + + char *text_before; /**< a possible text specified before this option */ + char *text_after; /**< a possible text specified after this option */ + + char *details; /**< possible further details for this option that will be + printed only if --detailed-help is specified */ + + /**< parser information */ + char *filename; /**< source file */ + int linenum; /**< line number */ + + gengetopt_option(); +}; + +/** the list storing gengetopt options */ +typedef std::list gengetopt_option_list; + +std::ostream & operator <<(std::ostream &s, gengetopt_option &opt); + +#endif /* _GENGETOPT_GGOS_H */ diff --git a/cmake/gengetopt/global_opts.h b/cmake/gengetopt/global_opts.h new file mode 100644 index 0000000..8332c69 --- /dev/null +++ b/cmake/gengetopt/global_opts.h @@ -0,0 +1,42 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef GLOBAL_OPTS_H +#define GLOBAL_OPTS_H + +#define HELP_LONG_OPT "help" +#define HELP_SHORT_OPT 'h' +#define HELP_SHORT_OPT_STR "h" +#define HELP_OPT_DESCR "Print help and exit" + +#define FULL_HELP_LONG_OPT "full-help" +#define FULL_HELP_LONG_OPT_FIELD "full_help" +#define FULL_HELP_OPT_DESCR "Print help, including hidden options, and exit" + +#define DETAILED_HELP_LONG_OPT "detailed-help" +#define DETAILED_HELP_LONG_OPT_FIELD "detailed_help" +#define DETAILED_HELP_OPT_DESCR "Print help, including all details and hidden options, and exit" + +#define VERSION_LONG_OPT "version" +#define VERSION_SHORT_OPT 'V' +#define VERSION_SHORT_OPT_STR "V" +#define VERSION_OPT_DESCR "Print version and exit" + +#endif /* GLOBAL_OPTS_H */ diff --git a/cmake/gengetopt/globals.cpp b/cmake/gengetopt/globals.cpp new file mode 100644 index 0000000..6057d5d --- /dev/null +++ b/cmake/gengetopt/globals.cpp @@ -0,0 +1,25 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "globals.h" + +gengetopt_option_list gengetopt_options; + +groups_collection_t gengetopt_groups; diff --git a/cmake/gengetopt/globals.h b/cmake/gengetopt/globals.h new file mode 100644 index 0000000..ce7cba1 --- /dev/null +++ b/cmake/gengetopt/globals.h @@ -0,0 +1,31 @@ +/** + * Copyright (C) 1999-2010 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef GLOBALS_H_ +#define GLOBALS_H_ + +#include "ggos.h" +#include "groups.h" + +extern gengetopt_option_list gengetopt_options; + +extern groups_collection_t gengetopt_groups; + +#endif /* GLOBALS_H_ */ diff --git a/cmake/gengetopt/gm.cc b/cmake/gengetopt/gm.cc new file mode 100644 index 0000000..0e7b70a --- /dev/null +++ b/cmake/gengetopt/gm.cc @@ -0,0 +1,2042 @@ +/** + * Copyright (C) 1999-2010 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include // for pair + +#include + +extern "C" +{ +#include "argsdef.h" +#include "global_opts.h" +}; + +#include "ggo_options.h" + +#include "gm.h" +#include "my_sstream.h" + +#include "groups.h" +#include "skels/option_arg.h" +#include "skels/required_option.h" +#include "skels/dependant_option.h" +#include "skels/generic_option.h" +#include "skels/group_option.h" +#include "skels/group_counter.h" +#include "skels/handle_help.h" +#include "skels/handle_version.h" +#include "skels/print_help_string.h" +#include "skels/multiple_opt_list.h" +#include "skels/multiple_fill_array.h" +#include "skels/free_string.h" +#include "skels/free_multiple.h" +#include "skels/reset_group.h" +#include "skels/exit_failure.h" +#include "skels/update_given.h" +#include "skels/given_field.h" +#include "skels/clear_given.h" +#include "skels/clear_arg.h" +#include "skels/free_list.h" +#include "skels/file_save.h" +#include "skels/file_save_multiple.h" +#include "skels/init_args_info.h" +#include "skels/custom_getopt_gen.h" +#include "skels/check_modes.h" +#include "skels/enum_decl.h" +#include "gm_utils.h" +#include "fileutils.h" + +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) +#endif // FIX_UNUSED + +#define MAX_STARTING_COLUMN 32 + +#define EXE_NAME "argv[0]" + +#define PARSER_NAME_PREFIX (c_source_gen_class::parser_name + "_") +#define OPTION_VALUES_NAME(n) (PARSER_NAME_PREFIX + n + "_values") + +using std::endl; +using std::set; + +extern char * gengetopt_package; +extern char * gengetopt_version; +extern char * gengetopt_purpose; +extern char * gengetopt_description; +extern char * gengetopt_usage; +extern char * gengetopt_input_filename; + +extern groups_collection_t gengetopt_groups; +extern modes_collection_t gengetopt_modes; + +// a map where for each mode we store the corresponding given field names +// and the options +typedef std::pair OptionValueElem; +typedef std::list ModeOptions; +typedef std::map ModeOptionMap; + +static ModeOptionMap modeOptionMap; + +static const ModeOptionMap &getModeOptionMap() { + if (modeOptionMap.size() == 0) { + // it's the first time, so we build it + struct gengetopt_option * opt; + foropt { + if (opt->mode_value) { + modeOptionMap[opt->mode_value].push_back + (std::make_pair("args_info->" + string(opt->var_arg) + "_given", + string("\"--") + opt->long_opt + "\"")); + } + } + } + + return modeOptionMap; +} + +// a map associating to a mode the list of gengetopt_options +typedef std::map ModeOptMap; + +static ModeOptMap modeOptMap; + +static const ModeOptMap &getModeOptMap() { + if (modeOptMap.size() == 0) { + // it's the first time, so we build it + struct gengetopt_option * opt; + foropt { + if (opt->mode_value) { + modeOptMap[opt->mode_value].push_back(opt); + } + } + } + + return modeOptMap; +} + +static void _generate_option_arg(ostream &stream, + unsigned int indent, + struct gengetopt_option * opt); + +static void +generate_help_desc_print(ostream &stream, + unsigned int desc_column, + const char *descript, const char *defval, + const string &values, + const string &show_required_string); + +CmdlineParserCreator::CmdlineParserCreator (char *function_name, + char *struct_name, + char *unamed_options_, + char *filename_, + char *header_ext, char *c_ext, + bool long_help_, + bool no_handle_help_, + bool no_help_, + bool no_handle_version_, + bool no_version_, + bool no_handle_error_, + bool conf_parser_, + bool string_parser_, + bool gen_version, + bool gen_getopt, + bool no_options_, + const string &comment_, + const string &outdir, + const string &header_outdir, + const string &src_outdir, + const string &show_required) : + filename (filename_), + args_info_name (struct_name), + output_dir (outdir), + header_output_dir (header_outdir), + src_output_dir (src_outdir), + comment (comment_), + unamed_options (unamed_options_), + show_required_string (show_required), + long_help (long_help_), no_handle_help (no_handle_help_), + no_help (no_help_), + no_handle_version (no_handle_version_), + no_version (no_version_), + no_handle_error (no_handle_error_), + conf_parser (conf_parser_), string_parser (string_parser_), + gen_gengetopt_version (gen_version), + tab_indentation (0) +{ + parser_function_name = canonize_names (function_name); + c_filename = create_filename (filename, c_ext); + header_filename = create_filename (filename, header_ext); + + // header_gen_class + const string stripped_header_file_name = strip_path (filename); + set_header_file_name (stripped_header_file_name); + header_gen_class::set_header_file_ext (header_ext); + c_source_gen_class::set_header_file_ext (header_ext); + if (gen_gengetopt_version) + header_gen_class::set_generator_version + ("version " VERSION); + const string my_ifndefname = + to_upper (strip_path (stripped_header_file_name)); + set_ifndefname (canonize_names (my_ifndefname.c_str ())); + header_gen_class::set_parser_name (parser_function_name); + const string my_package_var_name = + to_upper (parser_function_name) + "_PACKAGE"; + const string my_version_var_name = + to_upper (parser_function_name) + "_VERSION"; + header_gen_class::set_package_var_name (my_package_var_name); + c_source_gen_class::set_package_var_name (my_package_var_name); + header_gen_class::set_version_var_name (my_version_var_name); + c_source_gen_class::set_version_var_name (my_version_var_name); + header_gen_class::set_args_info (args_info_name); + c_source_gen_class::set_args_info (args_info_name); + const string uppersand = "\""; + + // if no_options then we don't need to generate update_arg, + // but if we need to handle help or version we still need to generate it + set_no_options (no_options_ && !no_handle_help && !no_handle_version); + + if (gengetopt_package) + set_package_var_val + (uppersand + gengetopt_package + uppersand); + else + set_package_var_val ("PACKAGE"); + + if (gengetopt_version) + set_version_var_val + (uppersand + gengetopt_version + uppersand); + else + set_version_var_val ("VERSION"); + + header_gen_class::set_generate_config_parser (conf_parser); + + header_gen_class::set_generate_string_parser (string_parser); + c_source_gen_class::set_generate_string_parser (string_parser); + + // c_source_gen_class + set_command_line (comment); + if (gen_gengetopt_version) + c_source_gen_class::set_generator_version + ("version " VERSION); + c_source_gen_class::set_parser_name (parser_function_name); + set_source_name (filename); + + ostringstream exit_failure_str; + exit_failure_gen_class exit_gen; + exit_gen.set_parser_name (c_source_gen_class::parser_name); + exit_gen.set_handle_error (! no_handle_error); + exit_gen.generate_exit_failure (exit_failure_str); + set_final_exit (exit_failure_str.str ()); + + set_conf_parser (conf_parser); + set_cmd_list (conf_parser || string_parser); + set_include_getopt (gen_getopt); + + struct gengetopt_option * opt; + gen_strdup = (unamed_options != 0 || conf_parser || string_parser); + + if (! gen_strdup) + { + foropt + if (opt->type != ARG_FLAG || opt->type != ARG_NO) { + gen_strdup = true; + break; + } + } + + set_do_generate_strdup(gen_strdup); + set_check_possible_values(has_values()); + set_multiple_token_functions(has_multiple_options_with_type()); + set_multiple_options_with_default(has_multiple_options_with_default()); + set_multiple_options(has_multiple_options()); + set_multiple_options_string(has_multiple_options_string()); + set_multiple_options_all_string(has_multiple_options_all_string()); + set_has_typed_options(has_options_with_type()); + set_has_modes(has_options_with_mode()); + set_handle_unamed(unamed_options); + set_check_required_options(has_required() || has_dependencies() || has_multiple_options()); + set_purpose(generate_purpose()); + set_description(generate_description()); + set_no_package((gengetopt_package == 0)); + c_source_gen_class::set_has_hidden(has_hidden_options()); + header_gen_class::set_has_hidden(c_source_gen_class::has_hidden); + c_source_gen_class::set_has_details(has_options_with_details()); + header_gen_class::set_has_details(c_source_gen_class::has_details); + + set_has_arg_types(); +} + +void CmdlineParserCreator::set_has_arg_types() { + struct gengetopt_option * opt; + + set_has_arg_flag(false); + set_has_arg_string(false); + set_has_arg_int(false); + set_has_arg_short(false); + set_has_arg_long(false); + set_has_arg_float(false); + set_has_arg_double(false); + set_has_arg_longdouble(false); + set_has_arg_longlong(false); + + foropt + { + switch (opt->type) { + case ARG_NO: + break; + case ARG_FLAG: + set_has_arg_flag(true); + break; + case ARG_STRING: + set_has_arg_string(true); + break; + case ARG_INT: + set_has_arg_int(true); + break; + case ARG_SHORT: + set_has_arg_short(true); + break; + case ARG_LONG: + set_has_arg_long(true); + break; + case ARG_FLOAT: + set_has_arg_float(true); + break; + case ARG_DOUBLE: + set_has_arg_double(true); + break; + case ARG_LONGDOUBLE: + set_has_arg_longdouble(true); + break; + case ARG_LONGLONG: + set_has_arg_longlong(true); + break; + case ARG_ENUM: + set_has_arg_enum(true); + break; + default: + fprintf (stderr, "gengetopt: bug found in %s:%d!!\n", + __FILE__, __LINE__); + abort (); + } + } + +} + +void +CmdlineParserCreator::generateBreak(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + + stream << endl; + stream << indent_str; + stream << "break;"; +} + +int +CmdlineParserCreator::generate () +{ + int head_result; + + head_result = generate_header_file (); + if (head_result) + return head_result; + + return generate_source (); +} + +int +CmdlineParserCreator::generate_header_file () +{ + if (! gengetopt_options.size()) + { + fprintf (stderr, "gengetopt: none option given\n"); + return 1; + } + + /* ****************************************************** */ + /* HEADER FILE******************************************* */ + /* ****************************************************** */ + + string header_file = header_filename; + if (header_output_dir.size()) + header_file = header_output_dir + "/" + header_file; + else if (output_dir.size()) + header_file = output_dir + "/" + header_file; + + ofstream *output_file = open_fstream + (header_file.c_str()); + generate_header (*output_file); + output_file->close (); + delete output_file; + + return 0; +} + +/** + * generate the enum value from a given option + * @param name the (canonized) name of the option + * @param val the value of the option + * @return the enum value string + */ +static const string from_value_to_enum(const string &name, const string &val) { + return name + "_arg_" + canonize_enum(val); +} + +void +CmdlineParserCreator::generate_enum_types(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + FIX_UNUSED (indent); + + if (has_arg_enum) + stream << endl; + + foropt { + // if type is enum then it should also have values (checked during parsing) + // but it's better to check it + if (opt->type == ARG_ENUM) { + if (! (opt->acceptedvalues)) { + fprintf (stderr, "gengetopt: bug found in %s:%d!!\n", + __FILE__, __LINE__); + abort (); + } + ostringstream enum_values; + enum_decl_gen_class enum_gen; + enum_gen.set_var_arg(opt->var_arg); + for (AcceptedValues::const_iterator it = opt->acceptedvalues->begin(); + it != opt->acceptedvalues->end(); ++it) { + enum_values << ", "; + // the first enum element is set to 0 + enum_values << from_value_to_enum(opt->var_arg, *it); + if (it == opt->acceptedvalues->begin()) + enum_values << " = 0"; + + } + enum_gen.set_enum_values(enum_values.str()); + enum_gen.generate_enum_decl(stream); + } + } +} + +void +CmdlineParserCreator::generate_option_arg(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + + foropt { + _generate_option_arg (stream, indent, opt); + } +} + +void +_generate_option_arg(ostream &stream, + unsigned int indent, + struct gengetopt_option *opt) +{ + option_arg_gen_class option_arg_gen; + + string type = ""; + if (opt->type) + type = arg_types[opt->type]; + string origtype = "char *"; + + if (opt->multiple) { + type += "*"; + origtype += "*"; + option_arg_gen.set_multiple(true); + } else { + option_arg_gen.set_multiple(false); + } + + option_arg_gen.set_type(type); + option_arg_gen.set_origtype(origtype); + option_arg_gen.set_flag_arg((opt->type == ARG_FLAG)); + option_arg_gen.set_desc(opt->desc); + option_arg_gen.set_name(opt->var_arg); + option_arg_gen.set_has_arg(opt->type != ARG_NO); + option_arg_gen.set_has_enum(opt->type == ARG_ENUM); + + if (opt->default_given) + { + option_arg_gen.set_has_default(true); + option_arg_gen.set_default_value(opt->default_string); + } + + if (opt->type == ARG_FLAG) + { + option_arg_gen.set_default_on(opt->flagstat); + } + + if (opt->type == ARG_LONGLONG) + { + // the fallback type in case longlong is not supported by the compiler + string longtype = arg_types[ARG_LONG]; + if (opt->multiple) + longtype += "*"; + + option_arg_gen.set_long_long_arg(true); + option_arg_gen.set_longtype(longtype); + } + + option_arg_gen.generate_option_arg(stream, indent); +} + +void +CmdlineParserCreator::generate_option_given(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + string indent_str (indent, ' '); + bool first = true; + given_field_gen_class given_gen; + + foropt + { + switch (opt->type) { + case ARG_NO: + case ARG_FLAG: + case ARG_STRING: + case ARG_INT: + case ARG_SHORT: + case ARG_LONG: + case ARG_FLOAT: + case ARG_DOUBLE: + case ARG_LONGDOUBLE: + case ARG_LONGLONG: + case ARG_ENUM: + break; + default: + fprintf (stderr, "gengetopt: bug found in %s:%d!!\n", + __FILE__, __LINE__); + abort (); + } + if (! first) + stream << indent_str; + else + first = false; + + given_gen.set_arg_name (opt->var_arg); + given_gen.set_long_opt (opt->long_opt); + given_gen.set_group (opt->multiple && opt->group_value); + given_gen.generate_given_field (stream); + } + + if (unamed_options) + { + stream << endl; + stream << indent_str; + stream << "char **inputs ; /**< @brief unamed options (options without names) */\n" ; + stream << indent_str; + stream << "unsigned inputs_num ; /**< @brief unamed options number */" ; + } +} + +void +CmdlineParserCreator::generate_option_values_decl(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + bool first = true; + FIX_UNUSED (indent); + + foropt + { + if (opt->acceptedvalues) { + if (first) { + first = false; + } + + stream << "extern const char *" << OPTION_VALUES_NAME(opt->var_arg) << + "[]; /**< @brief Possible values for " << opt->long_opt << ". */\n"; + } + } + + if (! first) + stream << "\n"; +} + +void +CmdlineParserCreator::generate_option_values(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + bool first = true; + FIX_UNUSED (indent); + + foropt + { + if (opt->acceptedvalues) { + if (first) { + first = false; + } + + stream << "const char *" << OPTION_VALUES_NAME(opt->var_arg) << + "[] = {" << opt->acceptedvalues->toString(false) << + ", 0}; /*< Possible values for " << opt->long_opt << ". */\n"; + } + } + + if (! first) + stream << "\n"; +} + +static void generate_option_usage_string(gengetopt_option * opt, ostream &usage) { + const char *type_str; + + usage << " "; + + if (!opt->required) + usage << "["; + + switch (opt->type) { + case ARG_NO: + case ARG_FLAG: + if (opt->short_opt) + usage << "-" << opt->short_opt << "|"; + usage << "--" << opt->long_opt; + break; + case ARG_INT: + case ARG_SHORT: + case ARG_LONG: + case ARG_FLOAT: + case ARG_DOUBLE: + case ARG_LONGDOUBLE: + case ARG_LONGLONG: + case ARG_STRING: + case ARG_ENUM: + if (opt->type_str) + type_str = opt->type_str; + else + type_str = arg_names[opt->type]; + + if (opt->short_opt) + usage << "-" << opt->short_opt << type_str << "|"; + usage << "--" << opt->long_opt << "=" << type_str; + + break; + default: fprintf (stderr, "gengetopt: bug found in %s:%d!!\n", + __FILE__, __LINE__); + abort (); + } + + if (!opt->required) + usage << "]"; +} + +const string +CmdlineParserCreator::generate_usage_string(bool use_config_package) +{ + FIX_UNUSED (use_config_package); + // if specified by the programmer, the usage string has the precedence + if (gengetopt_usage) { + return gengetopt_usage; + } + + struct gengetopt_option * opt; + ostringstream usage; + + // otherwise the config.h package constant will be used + if (gengetopt_package) + usage << gengetopt_package; + + if ( long_help ) { + // we first generate usage strings of required options + // handle mode options separately + foropt + if (opt->required && !opt->hidden && !opt->mode_value) { + generate_option_usage_string(opt, usage); + } + + foropt + if (!opt->required && !opt->hidden && !opt->mode_value) { + generate_option_usage_string(opt, usage); + } + } else { /* if not long help we generate it as GNU standards */ + usage << " [OPTIONS]..."; + } + + string wrapped; + + if ( unamed_options ) + usage << " [" << unamed_options << "]..."; + + wrap_cstr ( wrapped, strlen("Usage: "), 2, usage.str() ); + + // now deal with modes + if (has_modes && long_help) { + const ModeOptMap &modeOptMap = getModeOptMap(); + + for (ModeOptMap::const_iterator map_it = modeOptMap.begin(); map_it != modeOptMap.end(); ++map_it) { + string mode_line; // a mode alternative in the usage string + gengetopt_option_list::const_iterator opt_it; + usage.str(""); // reset the usage string buffer + + for (opt_it = map_it->second.begin(); opt_it != map_it->second.end(); ++opt_it) { + if (((*opt_it)->required) && !((*opt_it)->hidden)) { + generate_option_usage_string(*opt_it, usage); + } + } + + for (opt_it = map_it->second.begin(); opt_it != map_it->second.end(); ++opt_it) { + if (!((*opt_it)->required) && !((*opt_it)->hidden)) { + generate_option_usage_string(*opt_it, usage); + } + } + + wrap_cstr ( mode_line, strlen(" or : "), 2, gengetopt_package + usage.str() ); + wrapped += "\\n or : "; + wrapped += mode_line; + } + } + + return wrapped; +} + +static void +generate_help_desc_print(ostream &stream, + unsigned int desc_column, + const char *descript, const char *defval, + const string &values, + const string &show_required_string) +{ + string desc; + string desc_with_default = descript; + + if (defval || values.size()) { + desc_with_default += " ("; + + if (values.size()) { + desc_with_default += "possible values="; + desc_with_default += values; + if (defval) + desc_with_default += " "; + } + + if (defval) { + desc_with_default += "default="; + desc_with_default += defval; + } + + desc_with_default += ")"; + } + + if (show_required_string != "") + desc_with_default += " " + show_required_string; + + wrap_cstr ( desc, desc_column, 2, desc_with_default ); + + stream << desc; +} + + +void +CmdlineParserCreator::generate_help_option_print_from_lists(ostream &stream, + unsigned int indent, OptionHelpList *full_option_list, + OptionHelpList *option_list, const std::string &target_array, + const std::string &source_array) { + print_help_string_gen_class print_gen; + + // the index into the help arrays + int i = 0, full_i = 0; + // num of help strings + int help_num = 0; + + print_gen.set_target(target_array); + print_gen.set_from(source_array); + print_gen.set_shared(true); + print_gen.set_last(false); + + OptionHelpList::const_iterator it = option_list->begin(); + OptionHelpList::const_iterator it2 = full_option_list->begin(); + // the second list is surely longer so we scan that one + for (; it != option_list->end() && it2 != full_option_list->end(); ++it2) + { + if (*it == *it2) { + // when the two strings are the same it means that's a non-hidden + // option, so we share it with the full help array + ostringstream converted_int; + converted_int << i; + + // the index into the help array + print_gen.set_index(converted_int.str()); + + converted_int.str(""); + converted_int << full_i; + + // the index into the full help array + print_gen.set_full_index(converted_int.str()); + print_gen.generate_print_help_string(stream, indent); + + ++help_num; + ++i; + ++it; + } + ++full_i; + } + + ostringstream converted_int; + converted_int << help_num; + + // the final 0 + print_gen.set_last(true); + print_gen.set_index(converted_int.str()); + print_gen.generate_print_help_string(stream, indent); + + // we increment it to store the final 0 + converted_int.str(""); + converted_int << ++help_num; + + set_help_string_num(converted_int.str()); + +} + +void +CmdlineParserCreator::generate_help_option_print(ostream &stream, + unsigned int indent) +{ + OptionHelpList *option_list = generate_help_option_list(); + + if (!c_source_gen_class::has_hidden && !c_source_gen_class::has_details) { + print_help_string_gen_class print_gen; + print_gen.set_shared(false); + + // simple help generation + for (OptionHelpList::const_iterator it = option_list->begin(); + it != option_list->end(); ++it) + { + print_gen.set_helpstring(*it); + print_gen.generate_print_help_string(stream, indent); + } + } else { + // in order to avoid generating the same help string twice, and thus + // to save memory, in case of hidden options (or details), we try to share most + // of the strings with the full help array + OptionHelpList *full_option_list = generate_help_option_list(true, true); + + generate_help_option_print_from_lists + (stream, indent, full_option_list, option_list, + c_source_gen_class::args_info + "_help", + (c_source_gen_class::has_details ? + c_source_gen_class::args_info + "_detailed_help" : + c_source_gen_class::args_info + "_full_help")); + + delete full_option_list; + } + + delete option_list; +} + +void +CmdlineParserCreator::generate_full_help_option_print(ostream &stream, + unsigned int indent) +{ + // generate also hidden options + OptionHelpList *option_list = generate_help_option_list(true); + + if (!c_source_gen_class::has_details) { + print_help_string_gen_class print_gen; + print_gen.set_shared(false); + + for (OptionHelpList::const_iterator it = option_list->begin(); + it != option_list->end(); ++it) + { + print_gen.set_helpstring(*it); + print_gen.generate_print_help_string(stream, indent); + } + } else { + // in order to avoid generating the same help string twice, and thus + // to save memory, in case of options with details, we try to share most + // of the strings with the full help array + OptionHelpList *full_option_list = generate_help_option_list(true, true); + + generate_help_option_print_from_lists + (stream, indent, full_option_list, option_list, + c_source_gen_class::args_info + "_full_help", + c_source_gen_class::args_info + "_detailed_help"); + + delete full_option_list; + } + + delete option_list; +} + +void +CmdlineParserCreator::generate_detailed_help_option_print(ostream &stream, + unsigned int indent) +{ + // generate also hidden options and details + OptionHelpList *option_list = generate_help_option_list(true, true); + + print_help_string_gen_class print_gen; + print_gen.set_shared(false); + + for (OptionHelpList::const_iterator it = option_list->begin(); + it != option_list->end(); ++it) + { + print_gen.set_helpstring(*it); + print_gen.generate_print_help_string(stream, indent); + } + + delete option_list; +} + +void +CmdlineParserCreator::generate_init_args_info(ostream &stream, unsigned int indent) +{ + struct gengetopt_option * opt; + init_args_info_gen_class init_args_info_gen; + int i = 0; + ostringstream index; + + string help_string = c_source_gen_class::args_info; + + if (c_source_gen_class::has_details) { + help_string += "_detailed_help"; + } else if (c_source_gen_class::has_hidden) { + help_string += "_full_help"; + } else { + help_string += "_help"; + } + init_args_info_gen.set_help_strings(help_string); + + const char *current_section = 0, *current_group = 0, *current_mode = 0; + + // we have to skip section description references (that appear in the help vector) + foropt { + index.str(""); + + if (opt->section) { + if (!current_section || (strcmp(current_section, opt->section) != 0)) { + // a different section reference, skip it + current_section = opt->section; + ++i; + + if (opt->section_desc) { + // section description takes another line, thus we have to skip this too + ++i; + } + } + } + + // skip group desc + if (opt->group_value) { + if (!current_group || strcmp(current_group, opt->group_value) != 0) { + current_group = opt->group_value; + ++i; + } + } + + // skip mode desc + if (opt->mode_value) { + if (!current_mode || strcmp(current_mode, opt->mode_value) != 0) { + current_mode = opt->mode_value; + ++i; + } + } + + // also skip the text before + if (opt->text_before) + ++i; + + index << i++; + + init_args_info_gen.set_var_arg(opt->var_arg); + init_args_info_gen.set_num(index.str()); + + if (opt->multiple) { + init_args_info_gen.set_multiple(true); + init_args_info_gen.set_min(opt->multiple_min); + init_args_info_gen.set_max(opt->multiple_max); + } else { + init_args_info_gen.set_multiple(false); + } + + init_args_info_gen.generate_init_args_info(stream, indent); + + // skip the details + if (opt->details) + ++i; + + // skip the text after + if (opt->text_after) + ++i; + + } +} + +void CmdlineParserCreator::generate_custom_getopt(ostream &stream, unsigned int indent) +{ + custom_getopt_gen_gen_class custom_getopt; + + custom_getopt.generate_custom_getopt_gen (stream, indent); +} + +const string +CmdlineParserCreator::generate_purpose() +{ + string wrapped_purpose; + + if (gengetopt_purpose != NULL) + { + wrap_cstr(wrapped_purpose, 0, 0, gengetopt_purpose); + } + + return wrapped_purpose; +} + +const string +CmdlineParserCreator::generate_description() +{ + string wrapped_description; + + if (gengetopt_description != NULL) + { + wrap_cstr(wrapped_description, 0, 0, gengetopt_description); + } + + return wrapped_description; +} + + +OptionHelpList * +CmdlineParserCreator::generate_help_option_list(bool generate_hidden, bool generate_details) +{ + OptionHelpList *option_list = new OptionHelpList; + + unsigned long desc_col; + struct gengetopt_option * opt; + + int type_len; + const char *type_str; + ostringstream stream; + + // if we want to generate details then we will also generate hidden options + if (generate_details) + generate_hidden = true; + + /* calculate columns */ + desc_col = 0; + foropt { + // if (opt->hidden && !generate_hidden) + // continue; + // when computing columns, we also consider hidden_options, so that + // the --help and --full-help will be aligned just the same + // IMPORTANT: this is also crucial due to how the help string array + // is built starting from the full-help string array: + // we iterate over the two lists of options and check whether the + // corresponding strings are the same; thus, the help strings must + // have the same space alignments, otherwise they're not equal + + unsigned int width = 2 + 4 + 2; // ws + "-a, " + ws + + width += strlen (opt->long_opt) + 2; // "--" + + if ((opt->type != ARG_FLAG) && + (opt->type != ARG_NO)) + { + if (opt->type_str) + type_str = opt->type_str; + else + type_str = arg_names[opt->type]; + type_len = strlen(type_str); + + width += type_len + 1; // "=" + + if (opt->arg_is_optional) + width += 2; // "[" and "]" + } + + if (width > desc_col) + desc_col = width; + } + + if (desc_col > MAX_STARTING_COLUMN) + desc_col = MAX_STARTING_COLUMN; + + /* print justified options */ + char *prev_group = 0; + char *prev_mode = 0; + char *curr_section = 0; + bool first_option = true; + + foropt + { + // if the option is hidden, avoid to print a section containing only + // hidden options + if (opt->section && + (!curr_section || strcmp (curr_section, opt->section)) && + (!opt->hidden || generate_hidden)) + { + curr_section = opt->section; + + ostringstream sec_string; + + if (! first_option) + sec_string << "\\n"; + + sec_string << opt->section << ":" ; + + string wrapped_def; + wrap_cstr(wrapped_def, 0, 0, sec_string.str()); + option_list->push_back(wrapped_def); + + if (opt->section_desc) + { + string wrapped_desc ( 2, ' '); + wrap_cstr ( wrapped_desc, 2, 0, opt->section_desc ); + + option_list->push_back(wrapped_desc); + } + } + + if (opt->group_value && + (! prev_group || strcmp (opt->group_value, prev_group) != 0)) + { + string group_string = "\\n Group: "; + string wrapped_desc; + + if (opt->group_desc && strlen (opt->group_desc)) + { + wrapped_desc = "\\n "; + wrap_cstr (wrapped_desc, 2, 0, opt->group_desc); + } + + group_string += opt->group_value + wrapped_desc; + + option_list->push_back (group_string); + + prev_group = opt->group_value; + } + + if (opt->mode_value && + (! prev_mode || strcmp (opt->mode_value, prev_mode) != 0)) + { + string mode_string = "\\n Mode: "; + string wrapped_desc; + + if (opt->mode_desc && strlen (opt->mode_desc)) + { + wrapped_desc = "\\n "; + wrap_cstr (wrapped_desc, 2, 0, opt->mode_desc); + } + + mode_string += opt->mode_value + wrapped_desc; + + option_list->push_back (mode_string); + + prev_mode = opt->mode_value; + } + + // a possible description to be printed before this option + if (opt->text_before) + { + string wrapped_desc; + wrap_cstr ( wrapped_desc, 0, 0, opt->text_before); + + option_list->push_back(wrapped_desc); + } + + if (!opt->hidden || generate_hidden) { + first_option = false; + const char * def_val = NULL; + string def_str = "`"; + + ostringstream option_stream; + + if (opt->type == ARG_FLAG || opt->type == ARG_NO) + { + def_val = NULL; + + if (opt->short_opt) + option_stream << " -" << opt->short_opt << ", "; + else + option_stream << " "; + + option_stream << "--" << opt->long_opt; + + if (opt->type == ARG_FLAG) + def_val = opt->flagstat ? "on" : "off"; + } + else + { + def_val = NULL; + + if (opt->type_str) + type_str = opt->type_str; + else + type_str = arg_names[opt->type]; + + type_len = strlen(type_str); + + if (opt->short_opt) + { + option_stream << " -" << opt->short_opt << ", "; + } + else + { + option_stream << " "; + } + + bool arg_optional = opt->arg_is_optional; + option_stream << "--" << opt->long_opt + << (arg_optional ? "[" : "") + << "=" << type_str + << (arg_optional ? "]" : ""); + + if (opt->default_string) + { + def_str += opt->default_string; + def_str += "'"; + def_val = def_str.c_str(); + } + } + + const string &option_string = option_stream.str(); + stream << option_string; + const char *opt_desc = opt->desc; + + if ((option_string.size() >= MAX_STARTING_COLUMN) || + (desc_col <= option_string.size())) + { + string indent (MAX_STARTING_COLUMN, ' '); + stream << "\\n" << indent; + } + else + { + string indent (desc_col - option_string.size(), ' '); + stream << indent; + } + + generate_help_desc_print(stream, desc_col, opt_desc, def_val, + (opt->acceptedvalues ? opt->acceptedvalues->toString() : ""), + (opt->required && show_required_string != "" ? show_required_string : "")); + + option_list->push_back(stream.str()); + stream.str(""); + } + + // before the text after we generate details if we need to + if (opt->details && generate_details) { + string wrapped_desc ( 2, ' '); + // details are indented + wrap_cstr ( wrapped_desc, 2, 0, opt->details); + + option_list->push_back(wrapped_desc); + } + + // a possible description to be printed after this option + if (opt->text_after) + { + string wrapped_desc; + wrap_cstr ( wrapped_desc, 0, 0, opt->text_after); + + option_list->push_back(wrapped_desc); + } + } + + return option_list; +} + +template +void generate_counter_init(const Collection &collection, const string &name, ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + typename Collection::const_iterator end = collection.end(); + + for ( typename Collection::const_iterator idx = collection.begin(); idx != end; ++idx) + { + stream << indent_str; + stream << ARGS_STRUCT << "->" << canonize_name (idx->first) << "_" << + name << "_counter = 0 ;"; + stream << endl; + } +} + +void +CmdlineParserCreator::generate_given_init(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + string indent_str (indent, ' '); + clear_given_gen_class clear_given; + clear_given.set_arg_struct(ARGS_STRUCT); + + /* now we initialize "given" fields */ + foropt + { + stream << indent_str; + clear_given.set_var_arg(opt->var_arg); + clear_given.set_group(opt->multiple && opt->group_value); + clear_given.generate_clear_given(stream); + } + + // for group counter initialization + generate_counter_init(gengetopt_groups, "group", stream, indent); + + // for mode counter initialization + generate_counter_init(gengetopt_modes, "mode", stream, indent); +} + +void +CmdlineParserCreator::generate_reset_groups(ostream &stream, unsigned int indent) +{ + struct gengetopt_option * opt; + string indent_str (indent, ' '); + ostringstream body; + reset_group_gen_class reset_group; + clear_given_gen_class clear_given; + clear_given.set_arg_struct(ARGS_STRUCT); + + reset_group.set_args_info (c_source_gen_class::args_info); + + groups_collection_t::const_iterator end = gengetopt_groups.end(); + for ( groups_collection_t::const_iterator idx = gengetopt_groups.begin(); + idx != end; ++idx) + { + body.str (""); + bool found_option = false; + bool multiple_arg = false; + + foropt + { + if (opt->group_value && strcmp(opt->group_value, idx->first.c_str()) == 0) + { + /* now we reset "given" fields */ + stream << indent_str; + clear_given.set_var_arg(opt->var_arg); + if (opt->multiple && opt->group_value) + multiple_arg = true; + clear_given.set_group(opt->multiple && opt->group_value); + clear_given.generate_clear_given(body); + + free_option (opt, body, indent); + found_option = true; + } + } + + if (found_option) + { + reset_group.set_name (canonize_name (idx->first)); + reset_group.set_body (body.str ()); + reset_group.generate_reset_group (stream); + } + } +} + +void +CmdlineParserCreator::free_option(struct gengetopt_option *opt, + ostream &stream, unsigned int indent) +{ + if (opt->type == ARG_NO) + return; + + if (opt->type != ARG_FLAG) + { + if (opt->multiple) + { + free_multiple_gen_class free_multiple; + free_multiple.set_has_string_type(opt->type == ARG_STRING); + free_multiple.set_structure (ARGS_STRUCT); + + free_multiple.set_opt_var (opt->var_arg); + free_multiple.generate_free_multiple + (stream, indent); + } + else + { + free_string_gen_class free_string; + free_string.set_has_string_type(opt->type == ARG_STRING); + free_string.set_structure (ARGS_STRUCT); + + free_string.set_opt_var (opt->var_arg); + free_string.generate_free_string (stream, indent); + } + } +} + +void +CmdlineParserCreator::generate_list_def(ostream &stream, unsigned int indent) +{ + struct gengetopt_option * opt; + string indent_str (indent, ' '); + multiple_opt_list_gen_class multiple_opt_list; + + /* define linked-list structs for multiple options */ + foropt + { + if (opt->multiple) + { + if (opt->type) + { + stream << indent_str; + multiple_opt_list.set_arg_name (opt->var_arg); + multiple_opt_list.generate_multiple_opt_list (stream, indent); + stream << endl; + } + } + } +} + +void +CmdlineParserCreator::generate_multiple_fill_array(ostream &stream, unsigned int indent) +{ + struct gengetopt_option * opt; + string indent_str (indent, ' '); + multiple_fill_array_gen_class filler; + + /* copy linked list into the array */ + foropt + { + if (opt->multiple && opt->type) + { + stream << indent_str; + filler.set_option_var_name (opt->var_arg); + filler.set_arg_type(arg_type_constants[opt->type]); + filler.set_type (arg_types_names[opt->type]); + string default_string = "0"; + if (opt->default_string) { + if (opt->type == ARG_STRING) + default_string = string("\"") + opt->default_string + "\""; + else if (opt->type == ARG_ENUM) + default_string = from_value_to_enum(opt->var_arg, opt->default_string); + else + default_string = opt->default_string; + } + filler.set_default_value (default_string); + + filler.generate_multiple_fill_array (stream, indent); + + stream << endl; + } + } +} + +void +CmdlineParserCreator::generate_update_multiple_given(ostream &stream, unsigned int indent) +{ + if (! has_multiple_options()) + return; + + string indent_str (indent, ' '); + + stream << endl; + stream << indent_str; + + update_given_gen_class update_given_gen; + struct gengetopt_option * opt; + + foropt + { + if (opt->multiple) + { + update_given_gen.set_option_var_name (opt->var_arg); + update_given_gen.generate_update_given (stream, indent); + } + } +} + +void +CmdlineParserCreator::generate_check_modes(ostream &stream, unsigned int indent) +{ + // no need to check for conflict if there's only one mode + if (gengetopt_modes.size() < 2) + return; + + string indent_str (indent, ' '); + + stream << endl; + stream << indent_str; + + const ModeOptionMap &modeOptionMap = getModeOptionMap(); + + check_modes_gen_class check_modes_gen; + + // now we check each mode options against every other mode options: + // the first one with the other n-1, the second one with the other n-2, etc. + ModeOptionMap::const_iterator map_it1, map_it2; + for (ModeOptionMap::const_iterator map_it = modeOptionMap.begin(); map_it != modeOptionMap.end(); ++map_it) { + map_it1 = map_it; + ++map_it; + if (map_it == modeOptionMap.end()) + break; + for (map_it2 = map_it; map_it2 != modeOptionMap.end(); ++map_it2) { + const string mode1 = canonize_name(map_it1->first); + const string mode2 = canonize_name(map_it2->first); + + check_modes_gen.set_mode1_name(mode1); + check_modes_gen.set_mode2_name(mode2); + + ostringstream mode1_given, mode2_given, mode1_options, mode2_options; + + std::for_each(map_it1->second.begin(), map_it1->second.end(), pair_print_f(mode1_given, mode1_options)); + std::for_each(map_it2->second.begin(), map_it2->second.end(), pair_print_f(mode2_given, mode2_options)); + + check_modes_gen.set_mode1_given_fields(mode1_given.str()); + check_modes_gen.set_mode1_options(mode1_options.str()); + check_modes_gen.set_mode2_given_fields(mode2_given.str()); + check_modes_gen.set_mode2_options(mode2_options.str()); + + check_modes_gen.generate_check_modes(stream, indent); + } + map_it = map_it1; + } +} + +void +CmdlineParserCreator::generate_clear_arg(ostream &stream, unsigned int indent) +{ + struct gengetopt_option * opt; + clear_arg_gen_class clear_arg; + + /* now we initialize value fields */ + foropt + { + if (opt->type == ARG_NO) + continue; + + clear_arg.set_name(opt->var_arg); + clear_arg.set_suffix("arg"); + clear_arg.set_value("NULL"); + clear_arg.set_has_orig(opt->type != ARG_FLAG); + clear_arg.set_has_arg(false); + + if (opt->multiple && opt->type) + { + clear_arg.set_has_arg(true); + } + else if (opt->type == ARG_STRING) + { + clear_arg.set_has_arg(true); + if (opt->default_given) + clear_arg.set_value + ("gengetopt_strdup (\"" + string(opt->default_string) + + "\")"); + } + else if (opt->type == ARG_FLAG) + { + clear_arg.set_has_arg(true); + clear_arg.set_suffix("flag"); + clear_arg.set_value(opt->flagstat ? "1" : "0"); + } + else if (opt->type == ARG_ENUM) + { + // initialize enum arguments to -1 (unless they have a default) + clear_arg.set_has_arg(true); + if (opt->default_given) + clear_arg.set_value(from_value_to_enum(opt->var_arg, opt->default_string)); + else + clear_arg.set_value(string(opt->var_arg) + "__NULL"); + } + else if (opt->default_given) + { + clear_arg.set_has_arg(true); + clear_arg.set_value(opt->default_string); + } + + clear_arg.generate_clear_arg(stream, indent); + } +} + +void +CmdlineParserCreator::generate_long_option_struct(ostream &stream, + unsigned int indent) +{ + string indent_str (indent, ' '); + struct gengetopt_option * opt; + + foropt + { + stream << indent_str; + + stream << "{ \"" << opt->long_opt << "\",\t" + << (opt->type == ARG_NO || opt->type == ARG_FLAG ? 0 : + (opt->arg_is_optional ? 2 : 1)) + << ", NULL, "; + + if (opt->short_opt) + stream << "\'" << opt->short_opt << "\'"; + else + stream << "0"; + + stream << " }," << endl; + } +} + +string +CmdlineParserCreator::generate_getopt_string() +{ + struct gengetopt_option * opt; + ostringstream built_getopt_string; + + foropt + if (opt->short_opt) + { + built_getopt_string << opt->short_opt << + (opt->type == ARG_NO || opt->type == ARG_FLAG ? "" : ":"); + built_getopt_string << + (opt->arg_is_optional ? ":" : ""); + } + + return built_getopt_string.str (); +} + +void +CmdlineParserCreator::generate_handle_no_short_option(ostream &stream, + unsigned int indent) +{ + handle_options(stream, indent, false); +} + +void +CmdlineParserCreator::generate_handle_option(ostream &stream, + unsigned int indent) +{ + handle_options(stream, indent, true); +} + +void +CmdlineParserCreator::handle_options(ostream &stream, unsigned int indent, bool has_short) +{ + struct gengetopt_option * opt; + generic_option_gen_class option_gen; + string indent_str (indent, ' '); + bool first = true; + + option_gen.set_has_short_option (has_short); + + // by default we handle '?' case in the switch + // unless the user defined a short option as ? + set_handle_question_mark(true); + + foropt + { + if (opt->short_opt == '?') + set_handle_question_mark(false); + + if ((has_short && opt->short_opt) || (!has_short && !opt->short_opt)) + { + if (has_short || first) + stream << indent_str; + + option_gen.set_option_comment (opt->desc); + option_gen.set_long_option (opt->long_opt); + option_gen.set_short_option(opt->short_opt ? string (1, opt->short_opt) : "-"); + option_gen.set_option_var_name (opt->var_arg); + option_gen.set_final_instructions(""); + + if (!no_help && ((opt->short_opt == HELP_SHORT_OPT && + strcmp(opt->long_opt, HELP_LONG_OPT) == 0) + || strcmp(opt->long_opt, HELP_LONG_OPT) == 0 + || strcmp(opt->long_opt, FULL_HELP_LONG_OPT) == 0 + || strcmp(opt->long_opt, DETAILED_HELP_LONG_OPT) == 0)) { + bool full_help = (strcmp(opt->long_opt, FULL_HELP_LONG_OPT) == 0); + bool detailed_help = (strcmp(opt->long_opt, DETAILED_HELP_LONG_OPT) == 0); + if (no_handle_help) { + // we use the final_instructions parameter to call the free function + // and to return 0 + const string final_instructions = + parser_function_name + + string("_free (&local_args_info);\nreturn 0;"); + + option_gen.set_final_instructions(final_instructions); + + if (full_help) { + option_gen.set_long_option (FULL_HELP_LONG_OPT); + option_gen.set_option_comment (FULL_HELP_OPT_DESCR); + } else if (detailed_help) { + option_gen.set_long_option (DETAILED_HELP_LONG_OPT); + option_gen.set_option_comment (DETAILED_HELP_OPT_DESCR); + } else { + option_gen.set_long_option (HELP_LONG_OPT); + option_gen.set_short_option (HELP_SHORT_OPT_STR); + option_gen.set_option_comment (HELP_OPT_DESCR); + } + //option_gen.set_has_short_option (!full_help); + } else { + handle_help_gen_class help_gen; + help_gen.set_parser_name (parser_function_name); + help_gen.set_full_help(full_help); + help_gen.set_detailed_help(detailed_help); + help_gen.set_short_opt(opt->short_opt == HELP_SHORT_OPT); + help_gen.generate_handle_help (stream, indent); + stream << endl; + stream << endl; + continue; + } + } + + if (!no_version && ((opt->short_opt == VERSION_SHORT_OPT && strcmp(opt->long_opt, VERSION_LONG_OPT) == 0) + || strcmp(opt->long_opt, VERSION_LONG_OPT) == 0)) { + if (no_handle_version) { + option_gen.set_long_option (VERSION_LONG_OPT); + option_gen.set_short_option (VERSION_SHORT_OPT_STR); + option_gen.set_option_comment (VERSION_OPT_DESCR); + //option_gen.set_has_short_option (true); + + // we use the final_instrauctions parameter to call the free function + // and to return 0 + const string final_instructions = + parser_function_name + + string("_free (&local_args_info);\nreturn 0;"); + + option_gen.set_final_instructions(final_instructions); + } else { + handle_version_gen_class version_gen; + version_gen.set_parser_name (parser_function_name); + version_gen.set_short_opt (opt->short_opt == VERSION_SHORT_OPT); + version_gen.generate_handle_version (stream, indent); + stream << endl; + stream << endl; + continue; + } + } + + if (opt->acceptedvalues != 0) + option_gen.set_possible_values (OPTION_VALUES_NAME(opt->var_arg)); + else + option_gen.set_possible_values ("0"); + + string default_string = "0"; + if (opt->default_string) + default_string = string("\"") + opt->default_string + "\""; + option_gen.set_default_value (default_string); + + option_gen.set_arg_type(arg_type_constants[opt->type]); + + if (opt->group_value) { + option_gen.set_group_var_name (canonize_name (opt->group_value)); + option_gen.set_option_has_group(true); + } else + option_gen.set_option_has_group(false); + + if (opt->mode_value) { + // we reuse the variable group_var_name also for modes + option_gen.set_group_var_name (canonize_name (opt->mode_value)); + option_gen.set_option_has_mode(true); + } else + option_gen.set_option_has_mode(false); + + option_gen.set_option_has_type(opt->type != 0); + + if (opt->multiple) { + option_gen.set_multiple(true); + option_gen.set_structure (string (opt->var_arg) + "_list"); + } else { + option_gen.set_multiple(false); + option_gen.set_structure (ARGS_STRUCT); + } + + option_gen.generate_generic_option (stream, indent); + + if (has_short) + { + stream << endl; + } + + if (first && !has_short) + { + first = false; + option_gen.set_gen_else ("else "); + } + } + } + + if (! first && !has_short) // something has been generated + { + generateBreak(stream, indent); + stream << endl; + } +} + +#define GROUP_REQUIRED_COMPARISON "!=" +#define GROUP_NOT_REQUIRED_COMPARISON ">" +#define GROUP_REQUIRED_MESSAGE "One" +#define GROUP_NOT_REQUIRED_MESSAGE "At most one" + +void +CmdlineParserCreator::generate_handle_group(ostream &stream, + unsigned int indent) +{ + group_option_gen_class opt_gen; + string indent_str (indent, ' '); + opt_gen.set_package_var_name (EXE_NAME); + + opt_gen.set_Comparison_rule(GROUP_NOT_REQUIRED_COMPARISON " 1"); + + groups_collection_t::const_iterator end = gengetopt_groups.end(); + for ( groups_collection_t::const_iterator idx = gengetopt_groups.begin(); + idx != end; ++idx) + { + stream << indent_str; + opt_gen.set_group_name (idx->first); + opt_gen.set_group_var_name (canonize_name (idx->first)); + if (idx->second.required) + { + opt_gen.set_number_required(GROUP_REQUIRED_MESSAGE); + } + else + { + opt_gen.set_number_required(GROUP_NOT_REQUIRED_MESSAGE); + } + + opt_gen.generate_group_option (stream, indent); + stream << endl; + } +} + +void +CmdlineParserCreator::generate_handle_required(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + required_option_gen_class opt_gen; + opt_gen.set_package_var_name ("prog_name"); + + /* write test for required options or for multiple options + (occurrence number check) */ + foropt + if ( opt->required || opt->multiple ) + { + if (opt->mode_value) { + opt_gen.set_mode_condition("args_info->" + + canonize_name(opt->mode_value) + "_mode_counter && "); + } else { + opt_gen.set_mode_condition(""); + } + + // build the option command line representation + ostringstream req_opt; + req_opt << "'--" << opt->long_opt << "'"; + if (opt->short_opt) + req_opt << " ('-" << opt->short_opt << "')"; + + opt_gen.set_option_var_name (opt->var_arg); + opt_gen.set_option_descr (req_opt.str ()); + + // if the option is required this is the standard check + if (opt->required) { + opt_gen.set_checkrange(false); + + opt_gen.generate_required_option (stream, indent); + } + + // if the option is multiple we generate also the + // occurrence range check + if (opt->multiple) { + opt_gen.set_checkrange(true); + + opt_gen.generate_required_option (stream, indent); + } + + // notice that the above ifs are not mutual exclusive: + // a multiple option can have a range check without being + // required. + } + + // now generate the checks for required group options + group_option_gen_class group_opt_gen; + group_opt_gen.set_package_var_name ("prog_name"); + + group_opt_gen.set_Comparison_rule("== 0"); + group_opt_gen.set_number_required(GROUP_REQUIRED_MESSAGE); + + groups_collection_t::const_iterator end = gengetopt_groups.end(); + for ( groups_collection_t::const_iterator idx = gengetopt_groups.begin(); + idx != end; ++idx) + { + if (idx->second.required) + { + group_opt_gen.set_group_name (idx->first); + group_opt_gen.set_group_var_name (canonize_name (idx->first)); + + group_opt_gen.generate_group_option (stream, indent); + stream << endl; + } + } +} + +void +CmdlineParserCreator::generate_handle_dependencies(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + dependant_option_gen_class opt_gen; + opt_gen.set_package_var_name ("prog_name"); + string indent_str (indent, ' '); + + /* write test for required options */ + foropt + if ( opt->dependon ) + { + stream << indent_str; + + ostringstream req_opt; + req_opt << "'--" << opt->long_opt << "'"; + if (opt->short_opt) + req_opt << " ('-" << opt->short_opt << "')"; + + opt_gen.set_option_var_name (opt->var_arg); + opt_gen.set_dep_option (canonize_name(opt->dependon)); + opt_gen.set_option_descr (req_opt.str ()); + opt_gen.set_dep_option_descr (opt->dependon); + + opt_gen.generate_dependant_option (stream, indent); + + stream << endl; + } +} + +template +void generate_counters(const Collection &collection, const string &name, ostream &stream, unsigned int indent) +{ + group_counter_gen_class counter_gen; + string indent_str (indent, ' '); + + counter_gen.set_name(name); + + typename Collection::const_iterator end = collection.end(); + for ( typename Collection::const_iterator idx = collection.begin(); idx != end; ++idx) { + stream << indent_str; + counter_gen.set_group_name (canonize_name (idx->first)); + counter_gen.generate_group_counter (stream, indent); + stream << endl; + } +} + +void +CmdlineParserCreator::generate_group_counters(ostream &stream, + unsigned int indent) +{ + generate_counters(gengetopt_groups, "group", stream, indent); +} + +void +CmdlineParserCreator::generate_mode_counters(ostream &stream, + unsigned int indent) +{ + // we can reuse group counter gen class also for modes + generate_counters(gengetopt_modes, "mode", stream, indent); +} + +int +CmdlineParserCreator::generate_source () +{ + /* ****************************************************** */ + /* ********************************************** C FILE */ + /* ****************************************************** */ + + set_usage_string (generate_usage_string ()); + set_getopt_string (generate_getopt_string ()); + + string output_source = c_filename; + + if (src_output_dir.size()) + output_source = src_output_dir + "/" + output_source; + else if (output_dir.size()) + output_source = output_dir + "/" + output_source; + + ofstream *output_file = open_fstream (output_source.c_str()); + generate_c_source (*output_file); + output_file->close (); + delete output_file; + + return 0; +} + +void +CmdlineParserCreator::generate_free(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + + foropt + { + free_option (opt, stream, indent); + } +} + +void +CmdlineParserCreator::generate_list_free(ostream &stream, + unsigned int indent) +{ + struct gengetopt_option * opt; + + if (! has_multiple_options()) + return; + + free_list_gen_class free_list; + + foropt + { + if (opt->multiple && opt->type) { + free_list.set_list_name(opt->var_arg); + free_list.set_string_list(opt->type == ARG_STRING); + free_list.generate_free_list(stream, indent); + } + } +} + +void +CmdlineParserCreator::generate_file_save_loop(ostream &stream, unsigned int indent) +{ + struct gengetopt_option * opt; + + file_save_multiple_gen_class file_save_multiple; + file_save_gen_class file_save; + + const string suffix = "_orig"; + const string suffix_given = "_given"; + + foropt { + if (opt->multiple) { + file_save_multiple.set_has_arg(opt->type != ARG_NO); + file_save_multiple.set_opt_var(opt->var_arg); + file_save_multiple.set_opt_name(opt->long_opt); + file_save_multiple.set_values + ((opt->acceptedvalues ? OPTION_VALUES_NAME(opt->var_arg) : "0")); + + file_save_multiple.generate_file_save_multiple(stream, indent); + } else { + file_save.set_opt_name(opt->long_opt); + file_save.set_given(opt->var_arg + suffix_given); + file_save.set_values + ((opt->acceptedvalues ? OPTION_VALUES_NAME(opt->var_arg) : "0")); + + if (opt->type != ARG_NO && opt->type != ARG_FLAG) { + file_save.set_arg(opt->var_arg + suffix + (opt->multiple ? " [i]" : "")); + } else { + file_save.set_arg(""); + } + file_save.generate_file_save(stream, indent); + } + } +} + + diff --git a/cmake/gengetopt/gm.h b/cmake/gengetopt/gm.h new file mode 100644 index 0000000..ffd25db --- /dev/null +++ b/cmake/gengetopt/gm.h @@ -0,0 +1,189 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _GM_H +#define _GM_H + +#include "skels/header.h" +#include "skels/c_source.h" + +#include +#include + +#define TAB_LEN 2 + +struct gengetopt_option; + +typedef std::list OptionHelpList; + +class CmdlineParserCreator : public header_gen_class, public c_source_gen_class +{ + protected: + char *parser_function_name; + char *filename; + char *args_info_name; + char *header_filename; + char *c_filename; + string output_dir; + string header_output_dir; + string src_output_dir; + string comment; + char *unamed_options; + string show_required_string; + + bool long_help; + bool no_handle_help; + bool no_help; + bool no_handle_version; + bool no_version; + bool no_handle_error; + bool conf_parser; + bool string_parser; + bool gen_gengetopt_version; + bool gen_strdup; + + unsigned int tab_indentation ; /* tab indentation level */ + + void inc_indent() + { + tab_indentation += TAB_LEN ; + } + + void dec_indent() + { + tab_indentation -= TAB_LEN ; + } + + void indent() + { + unsigned int i ; + + for ( i = 1 ; i <= tab_indentation ; ++i ) + printf (" "); + } + + void free_option(struct gengetopt_option *opt, + ostream &stream, unsigned int indent); + + int generate_header_file(); + int generate_source(); + + string generate_getopt_string(); + + // to be implemented in header_gen_class + virtual void generate_enum_types(ostream &stream, unsigned int indent); + virtual void generate_option_arg(ostream &stream, unsigned int indent); + virtual void generate_option_given(ostream &stream, unsigned int indent); + virtual void generate_option_values_decl(ostream &stream, unsigned int indent); + + // to be implemented in c_source_gen_class + virtual void generate_clear_arg(ostream &stream, unsigned int indent); + virtual void generate_given_init(ostream &stream, unsigned int indent); + virtual void generate_option_values(ostream &stream, unsigned int indent); + + virtual void generate_handle_no_short_option(ostream &stream, + unsigned int indent); + virtual void generate_handle_option(ostream &stream, unsigned int indent); + virtual void generate_handle_required(ostream &stream, unsigned int indent); + virtual void generate_handle_dependencies(ostream &stream, unsigned int indent); + virtual void generate_handle_group(ostream &stream, unsigned int indent); + virtual void generate_group_counters(ostream &stream, unsigned int indent); + virtual void generate_mode_counters(ostream &stream, unsigned int indent); + virtual void generate_help_option_print(ostream &stream, + unsigned int indent); + virtual void generate_full_help_option_print(ostream &stream, + unsigned int indent); + virtual void generate_detailed_help_option_print(ostream &stream, + unsigned int indent); + virtual void generate_long_option_struct(ostream &stream, + unsigned int indent); + virtual void generate_reset_groups(ostream &stream, unsigned int indent); + + virtual void generate_free(ostream &stream, unsigned int indent); + virtual void generate_list_free(ostream &stream, unsigned int indent); + + virtual void generate_file_save_loop(ostream &stream, unsigned int indent); + virtual void generate_init_args_info(ostream &stream, unsigned int indent); + + virtual void generate_custom_getopt(ostream &stream, unsigned int indent); + + void generateBreak(ostream &stream, unsigned int indent = 0); + + void handle_options(ostream &, unsigned int, bool has_short); + + public: + + CmdlineParserCreator (char *function_name, char *struct_name, + char *unamed_options, + char *filename, char *header_ext, char *c_ext, + bool long_help, + bool no_handle_help, bool no_help, + bool no_handle_version, bool no_version, + bool no_handle_error, bool conf_parser, bool string_parser, + bool gen_version, bool gen_getopt, bool no_options, + const string &comment, + const string &outdir, + const string &header_outdir, + const string &src_outdir, + const string &show_required); + + int generate(); + + virtual void generate_list_def(ostream &stream, unsigned int indent); + virtual void generate_multiple_fill_array(ostream &stream, unsigned int indent); + virtual void generate_update_multiple_given(ostream &stream, unsigned int indent); + virtual void generate_check_modes(ostream &stream, unsigned int indent); + + const string generate_purpose(); + const string generate_description(); + const string generate_usage_string(bool use_config_package = true); + + /** + * generate a list of option descriptions that will be printed in the + * help output + * + * @param generate_hidden if true, include also the hidden options + * @param generate_details if true, include also the hidden options and + * details for options that have them. + */ + OptionHelpList *generate_help_option_list(bool generate_hidden = false, + bool generate_details = false); + + /** + * generate the sharing between a list of help string, using the + * complete_list as the list with all the strings (both for hidden + * options and details, e.g.) and the smaller_list as the list + * with less strings + * + * @param target_array the name of the array to copy to + * @param source_array the name of the array to copy from + */ + void generate_help_option_print_from_lists(ostream &stream, + unsigned int indent, OptionHelpList *complete_list, + OptionHelpList *smaller_list, const std::string &target_array, + const std::string &source_array); + + /** + * Sets the has_arg_XXX by inspecting all the options types + */ + void set_has_arg_types(); +}; + +#endif /* _GM_H */ diff --git a/cmake/gengetopt/gm_utils.cpp b/cmake/gengetopt/gm_utils.cpp new file mode 100644 index 0000000..229a00c --- /dev/null +++ b/cmake/gengetopt/gm_utils.cpp @@ -0,0 +1,335 @@ +// +// C++ Implementation: gm_utils +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "gm_utils.h" +#include "my_sstream.h" +#include "ggo_options.h" +#include "argsdef.h" +#include "groups.h" + +extern groups_collection_t gengetopt_groups; + +char * +canonize_names(const char *name) { + char *pvar; + char *p; + + pvar = strdup(name); + + for (p = pvar; *p; ++p) + if (*p == '.' || *p == '-') + *p = '_'; + + return pvar; +} + +// remove the path from the file name +const string strip_path(const string &s) { + string::size_type pos_of_sep; + + pos_of_sep = s.rfind("/"); + if (pos_of_sep == string::npos) + pos_of_sep = s.rfind("\\"); // try also with DOS path sep + + if (pos_of_sep == string::npos) + return s; // no path + + return s.substr(pos_of_sep + 1); +} + +const string to_upper(const string &old) { + string upper = old; + + for (string::iterator s = upper.begin(); s != upper.end(); ++s) + *s = toupper(*s); + + return upper; +} + +const string canonize_name(const string &old) { + string canonized = old; + + for (string::iterator s = canonized.begin(); s != canonized.end(); ++s) + if (*s == '.' || *s == '-' || *s == ' ') + *s = '_'; + + return canonized; +} + +const string canonize_enum(const string &old) { + string canonized; + + for (string::const_iterator s = old.begin(); s != old.end(); ++s) + if (*s == '-') + canonized += "MINUS_"; + else if (*s == '+') + canonized += "PLUS_"; + else + canonized += *s; + + return canonized; +} + +bool has_multiple_options_all_string() { + if (!has_multiple_options()) + return false; + + struct gengetopt_option * opt = 0; + + foropt { + if (opt->multiple && (opt->type && opt->type != ARG_STRING)) + return false; + } + + return true; +} + +bool has_multiple_options_string() { + if (!has_multiple_options()) + return false; + + struct gengetopt_option * opt = 0; + + foropt { + if (opt->multiple && opt->type == ARG_STRING) + return true; + } + + return false; +} + +bool has_multiple_options() { + struct gengetopt_option * opt = 0; + + foropt { + if (opt->multiple) + return true; + } + + return false; +} + +bool has_multiple_options_with_type() { + gengetopt_option * opt = 0; + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it + != gengetopt_options.end() && (opt = *it); ++it) + if (opt->multiple && opt->type) + return true; + + return false; +} + +bool has_multiple_options_with_default() { + gengetopt_option * opt = 0; + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it + != gengetopt_options.end() && (opt = *it); ++it) + if (opt->multiple && opt->default_given) + return true; + + return false; +} + +bool has_options_with_details() { + gengetopt_option * opt = 0; + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it + != gengetopt_options.end() && (opt = *it); ++it) + if (opt->details) + return true; + + return false; +} + +bool has_options_with_type() { + gengetopt_option * opt = 0; + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it + != gengetopt_options.end() && (opt = *it); ++it) + if (opt->type && opt->type != ARG_FLAG) + return true; + + return false; +} + +bool has_options_with_mode() { + gengetopt_option * opt = 0; + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it + != gengetopt_options.end() && (opt = *it); ++it) + if (opt->mode_value) + return true; + + return false; +} + +bool has_required() { + struct gengetopt_option * opt = 0; + + foropt { + if (opt->required) + return true; + } + + groups_collection_t::const_iterator end = gengetopt_groups.end(); + for (groups_collection_t::const_iterator idx = gengetopt_groups.begin(); idx + != end; ++idx) { + if (idx->second.required) { + return true; + } + } + + return false; +} + +bool has_dependencies() { + struct gengetopt_option * opt = 0; + + foropt { + if (opt->dependon) + return true; + } + + return false; +} + +bool has_options() { + struct gengetopt_option * opt = 0; + + foropt { + if (opt->short_opt) { + if (opt->short_opt != 'h' && opt->short_opt != 'V') + return true; + } + } + + return false; +} + +bool has_hidden_options() { + struct gengetopt_option * opt = 0; + + foropt { + if (opt->hidden) { + return true; + } + } + + return false; +} + +bool has_values() { + struct gengetopt_option * opt = 0; + + for (gengetopt_option_list::iterator it = gengetopt_options.begin(); it + != gengetopt_options.end(); ++it) { + opt = *it; + if (opt->acceptedvalues) { + return true; + } + } + + return false; +} + +int not_newlines(const string &buf, int &num_of_newlines) { + num_of_newlines = 0; + // searches for the first non newline char + string::size_type notnewline = buf.find_first_not_of("\r\n"); + + if (notnewline == string::npos) { + // a string made only of newlines + num_of_newlines = buf.size(); + return num_of_newlines; + } + + if (notnewline) { + // everything before the non newline char is a newline + num_of_newlines = notnewline; + return notnewline; + } + + return 0; +} + +void wrap_cstr(string& wrapped, unsigned int from_column, + unsigned int second_indent, const string &orig) { + int next_space = from_column; + string next_word; + const char * out_buf = orig.c_str(); + ostringstream stream; + const unsigned int second_line_column = from_column + second_indent; + string indent(second_line_column, ' '); + int newline_chars = 0; + int num_of_newlines = 0; + + while (*out_buf) { + // check for a new line + if (*out_buf) { + if ((newline_chars = not_newlines(out_buf, num_of_newlines))) { + for (int i = 1; i <= num_of_newlines; ++i) + stream << "\\n"; + + out_buf += newline_chars; + + if (*out_buf) { + stream << indent; + next_space = second_line_column; + continue; + } else + break; + } else { + stream << *out_buf++; + next_space++; + } + } + // search next whitespace, i.e., next word + while ((*out_buf) && (*out_buf != ' ') && + !not_newlines(out_buf, num_of_newlines)) { + next_word += *out_buf++; + next_space++; + } + + // wrap line if it's too long + if (next_space > 79) { + stream << "\\n" << indent << next_word; + next_space = second_line_column + next_word.size(); + } else + stream << next_word; // simply write word + + next_word = ""; + } + + wrapped += stream.str(); +} + +bool is_numeric(const gengetopt_option *opt) { + switch (opt->type) { + case ARG_INT: + case ARG_SHORT: + case ARG_LONG: + case ARG_FLOAT: + case ARG_DOUBLE: + case ARG_LONGDOUBLE: + case ARG_LONGLONG: + return true; + default: + return false; + } +} diff --git a/cmake/gengetopt/gm_utils.h b/cmake/gengetopt/gm_utils.h new file mode 100644 index 0000000..3f1c71b --- /dev/null +++ b/cmake/gengetopt/gm_utils.h @@ -0,0 +1,131 @@ +// +// C++ Interface: gm_utils +// +// Description: +// +// +// Author: Lorenzo Bettini , (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef GM_UTILS_H +#define GM_UTILS_H + +#include +#include + +#include "ggos.h" + +using std::string; + +/** + * @param name + * @return a copy of the string passed after canonizing it (i.e. '-' and + * '.' are transformed in '_'). + */ +char *canonize_names(const char * name); + +/** + * @param name + * @return a copy of the string passed after canonizing it (i.e. '-' and + * '.' are transformed in '_'). + */ +const string canonize_name(const string &name); + +/** + * @param s the string representing an enum value + * @return a copy of the string passed after canonizing it (i.e. '-' and + * becomes _MINUS_, '+' becomes _PLUS_) + */ +const string canonize_enum(const string &s); + +const string strip_path(const string &); +const string to_upper(const string &); + +/** + * All multiple options are of type string + * @return All multiple options are of type string + */ +bool has_multiple_options_all_string(); + +/** + * Has multiple options and at least one is of type string + * @return Has multiple options and at least one is of type string + */ +bool has_multiple_options_string(); + +/** + * Has multiple options and at least one has a default value + * @return Has multiple options and at least one has a default value + */ +bool has_multiple_options_with_default(); + +bool has_multiple_options(); +bool has_multiple_options_with_type(); +bool has_required(); +bool has_dependencies(); +bool has_options_with_type(); +bool has_options_with_mode(); +bool has_options(); +bool has_hidden_options(); +bool has_options_with_details(); +bool has_values(); + +/** + * Whether the specified option deals with number + * + * @param opt + * @return + */ +bool is_numeric(const gengetopt_option *opt); + +/** + * Performs word wrapping on the passed string (and return the result in the first + * parameter). + * + * @param wrapped the output parameter + * @param from_column the string start from this column + * @param second_indent an additional indentation for lines after the + * first one + * @param orig the original string that must be wrapped + */ +void wrap_cstr (string &wrapped, unsigned int from_column, unsigned int second_indent, const string &orig); + +/** + * Searches for characters which are not newlines. + * + * @param buf where to search for new characters + * @param num_of_newlines where the number of newlines + * before the first non newline char will be stored + * @return the position in the string after the (possible) new line char + */ +int not_newlines(const string &buf, int &num_of_newlines); + +/** + * Function object to print something into a stream (to be used with for_each) + */ +template +struct print_f : public std::unary_function +{ + print_f(std::ostream& out, const string &s = ", ") : os(out), sep(s) {} + void operator() (T x) { os << x << sep; } + std::ostream& os; + const string &sep; +}; + +/** + * Function object to print a pair into two streams (to be used with for_each) + */ +template +struct pair_print_f : public std::unary_function +{ + pair_print_f(std::ostream& out1, std::ostream& out2, const string &s = ", ") : + os1(out1), os2(out2), sep(s) {} + void operator() (T x) { os1 << x.first << sep; os2 << x.second << sep;} + std::ostream &os1, &os2; + const string &sep; +}; + +#endif diff --git a/cmake/gengetopt/gnugetopt.h b/cmake/gengetopt/gnugetopt.h new file mode 100644 index 0000000..a1b8dd6 --- /dev/null +++ b/cmake/gengetopt/gnugetopt.h @@ -0,0 +1,180 @@ +/* Declarations for getopt. + Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _GETOPT_H + +#ifndef __need_getopt +# define _GETOPT_H 1 +#endif + +/* If __GNU_LIBRARY__ is not already defined, either we are being used + standalone, or this is the first header included in the source file. + If we are being used with glibc, we need to include , but + that does not exist if we are standalone. So: if __GNU_LIBRARY__ is + not defined, include , which will pull in for us + if it's from glibc. (Why ctype.h? It's guaranteed to exist and it + doesn't flood the namespace with stuff the way some other headers do.) */ +#if !defined __GNU_LIBRARY__ +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + +#ifndef __need_getopt +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ +# if (defined __STDC__ && __STDC__) || defined __cplusplus + const char *name; +# else + char *name; +# endif + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +# define no_argument 0 +# define required_argument 1 +# define optional_argument 2 +#endif /* need getopt */ + + +/* Get definitions and prototypes for functions to process the + arguments in ARGV (ARGC of them, minus the program name) for + options given in OPTS. + + Return the option character from OPTS just read. Return -1 when + there are no more options. For unrecognized options, or options + missing arguments, `optopt' is set to the option letter, and '?' is + returned. + + The OPTS string is a list of characters which are recognized option + letters, optionally followed by colons, specifying that that letter + takes an argument, to be placed in `optarg'. + + If a letter in OPTS is followed by two colons, its argument is + optional. This behavior is specific to the GNU `getopt'. + + The argument `--' causes premature termination of argument + scanning, explicitly telling `getopt' that there are no more + options. + + If OPTS begins with `--', then non-option arguments are treated as + arguments to the option '\0'. This behavior is specific to the GNU + `getopt'. */ + +#if (defined __STDC__ && __STDC__) || defined __cplusplus +# ifdef __GNU_LIBRARY__ +/* Many other libraries have conflicting prototypes for getopt, with + differences in the consts, in stdlib.h. To avoid compilation + errors, only prototype getopt for the GNU C library. */ +extern int getopt (int __argc, char *const *__argv, const char *__shortopts); +# else /* not __GNU_LIBRARY__ */ +extern int getopt (); +# endif /* __GNU_LIBRARY__ */ + +# ifndef __need_getopt +extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, + const struct option *__longopts, int *__longind); +extern int getopt_long_only (int __argc, char *const *__argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); + +/* Internal only. Users should not call this directly. */ +extern int _getopt_internal (int __argc, char *const *__argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only); +# endif +#else /* not __STDC__ */ +extern int getopt (); +# ifndef __need_getopt +extern int getopt_long (); +extern int getopt_long_only (); + +extern int _getopt_internal (); +# endif +#endif /* __STDC__ */ + +#ifdef __cplusplus +} +#endif + +/* Make sure we later can get all the definitions and declarations. */ +#undef __need_getopt + +#endif /* getopt.h */ diff --git a/cmake/gengetopt/groups.h b/cmake/gengetopt/groups.h new file mode 100644 index 0000000..2b02b24 --- /dev/null +++ b/cmake/gengetopt/groups.h @@ -0,0 +1,52 @@ +/** + * Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef GGO_GROUPS_H +#define GGO_GROUPS_H + +#include "my_string.h" +#include "my_map.h" + +/** + * Represents a group of options + */ +struct Group +{ + string desc; + bool required; + + Group(const string &s, bool r) : desc (s), required (r) {} +}; + +typedef map groups_collection_t; + +/** + * Represents a mode of options + */ +struct Mode +{ + string desc; + + Mode(const string &s) : desc (s) {} +}; + +typedef map modes_collection_t; + +#endif // GROUPS_H diff --git a/cmake/gengetopt/include_cygwin/getopt.h b/cmake/gengetopt/include_cygwin/getopt.h new file mode 100644 index 0000000..0c1c8c9 --- /dev/null +++ b/cmake/gengetopt/include_cygwin/getopt.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 1987, 1993, 1994, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef _COMPILING_NEWLIB +#include_next "getopt.h" +#else +#ifndef __GETOPT_H__ +#define __GETOPT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __INSIDE_CYGWIN__ +extern int __declspec(dllimport) opterr; /* if error message should be printed */ +extern int __declspec(dllimport) optind; /* index into parent argv vector */ +extern int __declspec(dllimport) optopt; /* character checked for validity */ +extern int __declspec(dllimport) optreset; /* reset getopt */ +extern char __declspec(dllimport) *optarg; /* argument associated with option */ +#endif + +int getopt (int, char * const *, const char *); + +#ifdef __cplusplus +} +#endif + +#endif /* __GETOPT_H__ */ + +#ifndef __UNISTD_GETOPT__ +#ifndef __GETOPT_LONG_H__ +#define __GETOPT_LONG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct option { + const char *name; + int has_arg; + int *flag; + int val; +}; + +int getopt_long (int, char *const *, const char *, const struct option *, int *); +int getopt_long_only (int, char *const *, const char *, const struct option *, int *); + +#ifndef HAVE_DECL_GETOPT +#define HAVE_DECL_GETOPT 1 +#endif + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +#ifdef __cplusplus +} +#endif + +#endif /* __GETOPT_LONG_H__ */ +#endif /* __UNISTD_GETOPT__ */ +#endif /*_INSIDE_NEWLIB*/ diff --git a/cmake/gengetopt/my_map.h b/cmake/gengetopt/my_map.h new file mode 100644 index 0000000..8da8507 --- /dev/null +++ b/cmake/gengetopt/my_map.h @@ -0,0 +1,17 @@ +// handle namespaces + +#ifndef _MY_MAP_H +#define _MY_MAP_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#ifdef HAVE_NAMESPACES +using std::map; +using std::make_pair; +#endif + +#endif // _MY_MAP_H diff --git a/cmake/gengetopt/my_sstream.h b/cmake/gengetopt/my_sstream.h new file mode 100644 index 0000000..ace2bdd --- /dev/null +++ b/cmake/gengetopt/my_sstream.h @@ -0,0 +1,15 @@ +// deal with namespace problems + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif // HAVE_CONFIG_H + +#ifdef HAVE_SSTREAM +#include +#else +#include "includes/sstream" +#endif + +#ifdef HAVE_NAMESPACES +using std::ostringstream; +#endif diff --git a/cmake/gengetopt/my_string.h b/cmake/gengetopt/my_string.h new file mode 100644 index 0000000..e22d2c7 --- /dev/null +++ b/cmake/gengetopt/my_string.h @@ -0,0 +1,11 @@ +// deal with namespace problems + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif // HAVE_CONFIG_H + +#include + +#ifdef HAVE_NAMESPACES +using std::string; +#endif diff --git a/cmake/gengetopt/parser.cc b/cmake/gengetopt/parser.cc new file mode 100644 index 0000000..8c1bc53 --- /dev/null +++ b/cmake/gengetopt/parser.cc @@ -0,0 +1,2432 @@ + +/* A Bison parser, made by GNU Bison 2.4.1. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.4.1" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + + + +/* Copy the first part of user declarations. */ + +/* Line 189 of yacc.c */ +#line 22 "../../src/parser.yy" + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#include "my_sstream.h" + +#include "acceptedvalues.h" + +#include "argsdef.h" + +#include "gengetopt.h" +#include "errorcodes.h" +#include "ggos.h" +#include "yyerror.h" + +extern int gengetopt_count_line; +extern char * gengetopt_input_filename; + +static int gengetopt_package_given = 0; +static int gengetopt_version_given = 0; +static int gengetopt_purpose_given = 0; +static int gengetopt_usage_given = 0; +static int gengetopt_description_given = 0; + +/// the last option parsed +static gengetopt_option *current_option = 0; + +extern int yylex (void) ; + +//#define YYERROR_VERBOSE 1 + +void check_result(int o, gengetopt_option *opt) +{ + if (o) + { + ostringstream err; + + switch (o) + { + case NOT_ENOUGH_MEMORY: + yyerror (opt, "not enough memory"); + break; + case REQ_LONG_OPTION: + err << "long option redefined \'" << opt->long_opt << "\'"; + yyerror (opt, err.str().c_str()); + break; + case REQ_SHORT_OPTION: + err << "short option redefined \'" << opt->short_opt << "\'"; + yyerror (opt, err.str().c_str()); + break; + case FOUND_BUG: + yyerror (opt, "bug found!!"); + break; + case GROUP_UNDEFINED: + yyerror (opt, "group undefined"); + break; + case MODE_UNDEFINED: + yyerror (opt, "mode undefined"); + break; + case INVALID_DEFAULT_VALUE: + yyerror (opt, "invalid default value"); + break; + case NOT_REQUESTED_TYPE: + yyerror (opt, "type specification not requested"); + break; + case NOT_VALID_SPECIFICATION: + yyerror (opt, "invalid specification for this kind of option"); + break; + case SPECIFY_FLAG_STAT: + yyerror (opt, "you must specify the default flag status"); + break; + case NOT_GROUP_OPTION: + yyerror (opt, "group specification for a non group option"); + break; + case NOT_MODE_OPTION: + yyerror (opt, "mode specification for an option not belonging to a mode"); + break; + case SPECIFY_GROUP: + yyerror (opt, "missing group specification"); + break; + case SPECIFY_MODE: + yyerror (opt, "missing mode specification"); + break; + case INVALID_NUMERIC_VALUE: + yyerror (opt, "invalid numeric value"); + break; + case INVALID_ENUM_TYPE_USE: + yyerror (opt, "enum type can only be specified for options with values"); + break; + case HELP_REDEFINED: + yyerror (opt, "if you want to redefine --help, please use option --no-help"); + break; + case VERSION_REDEFINED: + yyerror (opt, "if you want to redefine --version, please use option --no-version"); + break; + } + } +} + +/* the number of allowed occurrences of a multiple option */ +struct multiple_size +{ + /* these strings are allocated dynamically and NOT + automatically freed upon destruction */ + char *min; + char *max; + + /* if no limit is specified then initialized to 0. + if the same size is specified for min and max, it means that an exact + number of occurrences is required*/ + multiple_size(const char *m = "0", const char *M = "0") : + min(strdup(m)), max(strdup(M)) + {} +}; + +#define check_error if (o) YYERROR; + + + +/* Line 189 of yacc.c */ +#line 200 "../../src/parser.cc" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TOK_PACKAGE = 258, + TOK_VERSION = 259, + TOK_OPTION = 260, + TOK_DEFGROUP = 261, + TOK_GROUPOPTION = 262, + TOK_DEFMODE = 263, + TOK_MODEOPTION = 264, + TOK_YES = 265, + TOK_NO = 266, + TOK_ON = 267, + TOK_OFF = 268, + TOK_FLAG = 269, + TOK_PURPOSE = 270, + TOK_DESCRIPTION = 271, + TOK_USAGE = 272, + TOK_DEFAULT = 273, + TOK_GROUP = 274, + TOK_GROUPDESC = 275, + TOK_MODE = 276, + TOK_MODEDESC = 277, + TOK_MULTIPLE = 278, + TOK_ARGOPTIONAL = 279, + TOK_TYPESTR = 280, + TOK_SECTION = 281, + TOK_DETAILS = 282, + TOK_SECTIONDESC = 283, + TOK_TEXT = 284, + TOK_ARGS = 285, + TOK_VALUES = 286, + TOK_HIDDEN = 287, + TOK_DEPENDON = 288, + TOK_STRING = 289, + TOK_CHAR = 290, + TOK_ARGTYPE = 291, + TOK_SIZE = 292 + }; +#endif +/* Tokens. */ +#define TOK_PACKAGE 258 +#define TOK_VERSION 259 +#define TOK_OPTION 260 +#define TOK_DEFGROUP 261 +#define TOK_GROUPOPTION 262 +#define TOK_DEFMODE 263 +#define TOK_MODEOPTION 264 +#define TOK_YES 265 +#define TOK_NO 266 +#define TOK_ON 267 +#define TOK_OFF 268 +#define TOK_FLAG 269 +#define TOK_PURPOSE 270 +#define TOK_DESCRIPTION 271 +#define TOK_USAGE 272 +#define TOK_DEFAULT 273 +#define TOK_GROUP 274 +#define TOK_GROUPDESC 275 +#define TOK_MODE 276 +#define TOK_MODEDESC 277 +#define TOK_MULTIPLE 278 +#define TOK_ARGOPTIONAL 279 +#define TOK_TYPESTR 280 +#define TOK_SECTION 281 +#define TOK_DETAILS 282 +#define TOK_SECTIONDESC 283 +#define TOK_TEXT 284 +#define TOK_ARGS 285 +#define TOK_VALUES 286 +#define TOK_HIDDEN 287 +#define TOK_DEPENDON 288 +#define TOK_STRING 289 +#define TOK_CHAR 290 +#define TOK_ARGTYPE 291 +#define TOK_SIZE 292 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 214 of yacc.c */ +#line 148 "../../src/parser.yy" + + char *str; + char chr; + int argtype; + int boolean; + class AcceptedValues *ValueList; + struct gengetopt_option *gengetopt_option; + struct multiple_size *multiple_size; + + + +/* Line 214 of yacc.c */ +#line 322 "../../src/parser.cc" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 264 of yacc.c */ +#line 347 "../../src/parser.cc" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 43 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 92 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 43 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 27 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 66 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 116 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 292 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 40, 41, 2, 2, 39, 42, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 38, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint8 yyprhs[] = +{ + 0, 0, 3, 4, 7, 9, 11, 13, 15, 17, + 19, 21, 23, 25, 27, 29, 31, 33, 36, 39, + 42, 45, 48, 52, 55, 58, 63, 67, 73, 79, + 85, 87, 90, 93, 98, 103, 108, 113, 118, 123, + 128, 131, 135, 138, 141, 144, 145, 147, 149, 150, + 152, 154, 156, 158, 159, 163, 164, 168, 169, 173, + 175, 179, 181, 182, 186, 191, 196 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = +{ + 44, 0, -1, -1, 45, 44, -1, 46, -1, 47, + -1, 53, -1, 48, -1, 49, -1, 50, -1, 51, + -1, 56, -1, 52, -1, 57, -1, 54, -1, 58, + -1, 55, -1, 3, 34, -1, 4, 34, -1, 15, + 59, -1, 16, 59, -1, 17, 59, -1, 26, 59, + 66, -1, 29, 59, -1, 30, 34, -1, 6, 34, + 64, 62, -1, 8, 34, 65, -1, 5, 34, 35, + 59, 60, -1, 7, 34, 35, 59, 60, -1, 9, + 34, 35, 59, 60, -1, 34, -1, 60, 63, -1, + 60, 36, -1, 60, 25, 38, 34, -1, 60, 27, + 38, 59, -1, 60, 31, 38, 67, -1, 60, 18, + 38, 34, -1, 60, 19, 38, 34, -1, 60, 21, + 38, 34, -1, 60, 33, 38, 34, -1, 60, 24, + -1, 60, 23, 69, -1, 60, 14, -1, 60, 32, + -1, 60, 61, -1, -1, 12, -1, 13, -1, -1, + 10, -1, 11, -1, 10, -1, 11, -1, -1, 20, + 38, 34, -1, -1, 22, 38, 34, -1, -1, 28, + 38, 34, -1, 68, -1, 67, 39, 68, -1, 34, + -1, -1, 40, 37, 41, -1, 40, 37, 42, 41, + -1, 40, 42, 37, 41, -1, 40, 37, 42, 37, + 41, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 209, 209, 211, 216, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 233, 253, 273, + 293, 313, 334, 341, 358, 365, 376, 387, 407, 426, + 448, 451, 457, 462, 467, 472, 477, 482, 487, 492, + 497, 502, 510, 515, 520, 525, 529, 530, 534, 535, + 536, 540, 541, 545, 546, 550, 551, 555, 556, 560, + 561, 565, 569, 570, 571, 572, 573 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "\"package\"", "\"version\"", + "\"option\"", "\"defgroup\"", "\"groupoption\"", "\"defmode\"", + "\"modeoption\"", "\"yes\"", "\"no\"", "\"on\"", "\"off\"", "\"flag\"", + "\"purpose\"", "\"description\"", "\"usage\"", "\"default\"", + "\"group\"", "\"groupdesc\"", "\"mode\"", "\"modedesc\"", "\"multiple\"", + "\"argoptional\"", "\"typestr\"", "\"section\"", "\"details\"", + "\"sectiondesc\"", "\"text\"", "\"args\"", "\"values\"", "\"hidden\"", + "\"dependon\"", "TOK_STRING", "TOK_CHAR", "TOK_ARGTYPE", "TOK_SIZE", + "'='", "','", "'('", "')'", "'-'", "$accept", "input", "statement", + "package", "version", "purpose", "description", "usage", "sectiondef", + "text", "args", "groupdef", "modedef", "option", "groupoption", + "modeoption", "quoted_string", "option_parts", "req_onoff", + "optional_yesno", "opt_yesno", "opt_groupdesc", "opt_modedesc", + "opt_sectiondesc", "listofvalues", "acceptedvalue", "multiple_size", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 61, 44, + 40, 41, 45 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 43, 44, 44, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 61, 61, 62, 62, + 62, 63, 63, 64, 64, 65, 65, 66, 66, 67, + 67, 68, 69, 69, 69, 69, 69 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 3, 2, 2, 4, 3, 5, 5, 5, + 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, + 2, 3, 2, 2, 2, 0, 1, 1, 0, 1, + 1, 1, 1, 0, 3, 0, 3, 0, 3, 1, + 3, 1, 0, 3, 4, 4, 5 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2, 4, 5, 7, 8, + 9, 10, 12, 6, 14, 16, 11, 13, 15, 17, + 18, 0, 53, 0, 55, 0, 30, 19, 20, 21, + 57, 23, 24, 1, 3, 0, 0, 48, 0, 0, + 26, 0, 0, 22, 45, 0, 49, 50, 25, 45, + 0, 45, 0, 27, 54, 28, 56, 29, 58, 51, + 52, 46, 47, 42, 0, 0, 0, 62, 40, 0, + 0, 0, 43, 0, 32, 44, 31, 0, 0, 0, + 0, 41, 0, 0, 0, 0, 36, 37, 38, 0, + 0, 33, 34, 61, 35, 59, 39, 63, 0, 0, + 0, 0, 64, 65, 60, 66 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 37, 63, 85, 58, + 86, 47, 50, 53, 104, 105, 91 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -40 +static const yytype_int8 yypact[] = +{ + 1, -13, -8, -6, -5, -2, -1, 0, 3, 3, + 3, 3, 3, 4, 25, 1, -40, -40, -40, -40, + -40, -40, -40, -40, -40, -40, -40, -40, -40, -40, + -40, 5, 15, 6, 26, 14, -40, -40, -40, -40, + 22, -40, -40, -40, -40, 3, 17, 2, 3, 21, + -40, 3, 23, -40, -40, 19, -40, -40, -40, -40, + 28, -40, 29, 33, -40, 33, -40, 33, -40, -40, + -40, -40, -40, -40, 30, 32, 34, 27, -40, 35, + 36, 37, -40, 38, -40, -40, -40, 43, 44, 45, + -23, -40, 46, 3, 47, 48, -40, -40, -40, -18, + 49, -40, -40, -40, 50, -40, -40, -40, -26, 42, + 47, 51, -40, -40, -40, -40 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -40, 56, -40, -40, -40, -40, -40, -40, -40, -40, + -40, -40, -40, -40, -40, -40, -9, -39, -40, -40, + -40, -40, -40, -40, -40, -25, -40 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint8 yytable[] = +{ + 38, 39, 40, 41, 1, 2, 3, 4, 5, 6, + 7, 111, 56, 57, 99, 112, 8, 9, 10, 100, + 65, 29, 67, 107, 108, 43, 30, 11, 31, 32, + 12, 13, 33, 34, 35, 46, 54, 36, 42, 59, + 45, 48, 61, 69, 70, 71, 72, 73, 49, 51, + 52, 74, 75, 64, 76, 55, 77, 78, 79, 60, + 80, 62, 66, 68, 81, 82, 83, 90, 87, 84, + 88, 44, 89, 92, 93, 94, 95, 96, 97, 98, + 101, 103, 106, 113, 102, 114, 109, 0, 0, 110, + 0, 0, 115 +}; + +static const yytype_int8 yycheck[] = +{ + 9, 10, 11, 12, 3, 4, 5, 6, 7, 8, + 9, 37, 10, 11, 37, 41, 15, 16, 17, 42, + 59, 34, 61, 41, 42, 0, 34, 26, 34, 34, + 29, 30, 34, 34, 34, 20, 45, 34, 34, 48, + 35, 35, 51, 10, 11, 12, 13, 14, 22, 35, + 28, 18, 19, 34, 21, 38, 23, 24, 25, 38, + 27, 38, 34, 34, 31, 32, 33, 40, 38, 36, + 38, 15, 38, 38, 38, 38, 38, 34, 34, 34, + 34, 34, 34, 41, 93, 110, 37, -1, -1, 39, + -1, -1, 41 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 3, 4, 5, 6, 7, 8, 9, 15, 16, + 17, 26, 29, 30, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 34, + 34, 34, 34, 34, 34, 34, 34, 59, 59, 59, + 59, 59, 34, 0, 44, 35, 20, 64, 35, 22, + 65, 35, 28, 66, 59, 38, 10, 11, 62, 59, + 38, 59, 38, 60, 34, 60, 34, 60, 34, 10, + 11, 12, 13, 14, 18, 19, 21, 23, 24, 25, + 27, 31, 32, 33, 36, 61, 63, 38, 38, 38, + 40, 69, 38, 38, 38, 38, 34, 34, 34, 37, + 42, 34, 59, 34, 67, 68, 34, 41, 42, 37, + 39, 37, 41, 41, 68, 41 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value, Location); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; +#endif +{ + if (!yyvaluep) + return; + YYUSE (yylocationp); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) +#else +static void +yy_reduce_print (yyvsp, yylsp, yyrule) + YYSTYPE *yyvsp; + YYLTYPE *yylsp; + int yyrule; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , &(yylsp[(yyi + 1) - (yynrhs)]) ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, yylsp, Rule); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, yylocationp) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; +#endif +{ + YYUSE (yyvaluep); + YYUSE (yylocationp); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + + + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls; + YYLTYPE *yylsp; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[2]; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + YYLTYPE yyloc; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; + +#if YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 1; +#endif + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + *++yylsp = yylloc; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 17: + +/* Line 1455 of yacc.c */ +#line 234 "../../src/parser.yy" + { + if (gengetopt_package_given) + { + yyerror ("package redefined"); + YYERROR; + } + else + { + gengetopt_package_given = 1; + if (gengetopt_define_package ((yyvsp[(2) - (2)].str))) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + break; + + case 18: + +/* Line 1455 of yacc.c */ +#line 254 "../../src/parser.yy" + { + if (gengetopt_version_given) + { + yyerror ("version redefined"); + YYERROR; + } + else + { + gengetopt_version_given = 1; + if (gengetopt_define_version ((yyvsp[(2) - (2)].str))) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + break; + + case 19: + +/* Line 1455 of yacc.c */ +#line 274 "../../src/parser.yy" + { + if (gengetopt_purpose_given) + { + yyerror ("purpose redefined"); + YYERROR; + } + else + { + gengetopt_purpose_given = 1; + if (gengetopt_define_purpose ((yyvsp[(2) - (2)].str))) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + break; + + case 20: + +/* Line 1455 of yacc.c */ +#line 294 "../../src/parser.yy" + { + if (gengetopt_description_given) + { + yyerror ("description redefined"); + YYERROR; + } + else + { + gengetopt_description_given = 1; + if (gengetopt_define_description ((yyvsp[(2) - (2)].str))) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + break; + + case 21: + +/* Line 1455 of yacc.c */ +#line 314 "../../src/parser.yy" + { + if (gengetopt_usage_given) + { + yyerror ("usage redefined"); + YYERROR; + } + else + { + gengetopt_usage_given = 1; + if (gengetopt_define_usage ((yyvsp[(2) - (2)].str))) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + break; + + case 22: + +/* Line 1455 of yacc.c */ +#line 335 "../../src/parser.yy" + { + gengetopt_set_section ((yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].str)); + } + break; + + case 23: + +/* Line 1455 of yacc.c */ +#line 342 "../../src/parser.yy" + { + if (current_option) { + std::string current_option_text; + if (current_option->text_after) { + current_option_text = std::string(current_option->text_after) + (yyvsp[(2) - (2)].str); + current_option->text_after = strdup(current_option_text.c_str()); + } else { + current_option->text_after = strdup((yyvsp[(2) - (2)].str)); + } + } else { + gengetopt_set_text((yyvsp[(2) - (2)].str)); + } + } + break; + + case 24: + +/* Line 1455 of yacc.c */ +#line 359 "../../src/parser.yy" + { + gengetopt_set_args((yyvsp[(2) - (2)].str)); + } + break; + + case 25: + +/* Line 1455 of yacc.c */ +#line 366 "../../src/parser.yy" + { + if (gengetopt_add_group ((yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].str), (yyvsp[(4) - (4)].boolean))) + { + yyerror ("group redefined"); + YYERROR; + } + } + break; + + case 26: + +/* Line 1455 of yacc.c */ +#line 377 "../../src/parser.yy" + { + if (gengetopt_add_mode ((yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].str))) + { + yyerror ("mode redefined"); + YYERROR; + } + } + break; + + case 27: + +/* Line 1455 of yacc.c */ +#line 389 "../../src/parser.yy" + { + (yyvsp[(5) - (5)].gengetopt_option)->filename = gengetopt_input_filename; + (yyvsp[(5) - (5)].gengetopt_option)->linenum = (yylsp[(1) - (5)]).first_line; + (yyvsp[(5) - (5)].gengetopt_option)->long_opt = strdup((yyvsp[(2) - (5)].str)); + if ((yyvsp[(3) - (5)].chr) != '-') + (yyvsp[(5) - (5)].gengetopt_option)->short_opt = (yyvsp[(3) - (5)].chr); + (yyvsp[(5) - (5)].gengetopt_option)->desc = strdup((yyvsp[(4) - (5)].str)); + int o = gengetopt_check_option ((yyvsp[(5) - (5)].gengetopt_option), false); + check_result(o, (yyvsp[(5) - (5)].gengetopt_option)); + check_error; + o = gengetopt_add_option ((yyvsp[(5) - (5)].gengetopt_option)); + check_result(o, (yyvsp[(5) - (5)].gengetopt_option)); + check_error; + current_option = (yyvsp[(5) - (5)].gengetopt_option); + } + break; + + case 28: + +/* Line 1455 of yacc.c */ +#line 409 "../../src/parser.yy" + { + (yyvsp[(5) - (5)].gengetopt_option)->filename = gengetopt_input_filename; + (yyvsp[(5) - (5)].gengetopt_option)->linenum = (yylsp[(1) - (5)]).first_line; + (yyvsp[(5) - (5)].gengetopt_option)->long_opt = strdup((yyvsp[(2) - (5)].str)); + if ((yyvsp[(3) - (5)].chr) != '-') + (yyvsp[(5) - (5)].gengetopt_option)->short_opt = (yyvsp[(3) - (5)].chr); + (yyvsp[(5) - (5)].gengetopt_option)->desc = strdup((yyvsp[(4) - (5)].str)); + int o = gengetopt_check_option ((yyvsp[(5) - (5)].gengetopt_option), true); + check_result(o, (yyvsp[(5) - (5)].gengetopt_option)); + check_error; + o = gengetopt_add_option ((yyvsp[(5) - (5)].gengetopt_option)); + check_result(o, (yyvsp[(5) - (5)].gengetopt_option)); + check_error; + } + break; + + case 29: + +/* Line 1455 of yacc.c */ +#line 428 "../../src/parser.yy" + { + (yyvsp[(5) - (5)].gengetopt_option)->filename = gengetopt_input_filename; + (yyvsp[(5) - (5)].gengetopt_option)->linenum = (yylsp[(1) - (5)]).first_line; + (yyvsp[(5) - (5)].gengetopt_option)->long_opt = strdup((yyvsp[(2) - (5)].str)); + if ((yyvsp[(3) - (5)].chr) != '-') + (yyvsp[(5) - (5)].gengetopt_option)->short_opt = (yyvsp[(3) - (5)].chr); + (yyvsp[(5) - (5)].gengetopt_option)->desc = strdup((yyvsp[(4) - (5)].str)); + int o = gengetopt_check_option ((yyvsp[(5) - (5)].gengetopt_option), false, true); + check_result(o, (yyvsp[(5) - (5)].gengetopt_option)); + check_error; + o = gengetopt_add_option ((yyvsp[(5) - (5)].gengetopt_option)); + check_result(o, (yyvsp[(5) - (5)].gengetopt_option)); + check_error; + } + break; + + case 31: + +/* Line 1455 of yacc.c */ +#line 452 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (2)].gengetopt_option); + (yyval.gengetopt_option)->required = (yyvsp[(2) - (2)].boolean); + (yyval.gengetopt_option)->required_set = true; + } + break; + + case 32: + +/* Line 1455 of yacc.c */ +#line 458 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (2)].gengetopt_option); + (yyval.gengetopt_option)->type = (yyvsp[(2) - (2)].argtype); + } + break; + + case 33: + +/* Line 1455 of yacc.c */ +#line 463 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->type_str = strdup((yyvsp[(4) - (4)].str)); + } + break; + + case 34: + +/* Line 1455 of yacc.c */ +#line 468 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->details = strdup((yyvsp[(4) - (4)].str)); + } + break; + + case 35: + +/* Line 1455 of yacc.c */ +#line 473 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->acceptedvalues = (yyvsp[(4) - (4)].ValueList); + } + break; + + case 36: + +/* Line 1455 of yacc.c */ +#line 478 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->default_string = strdup((yyvsp[(4) - (4)].str)); + } + break; + + case 37: + +/* Line 1455 of yacc.c */ +#line 483 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->group_value = strdup((yyvsp[(4) - (4)].str)); + } + break; + + case 38: + +/* Line 1455 of yacc.c */ +#line 488 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->mode_value = strdup((yyvsp[(4) - (4)].str)); + } + break; + + case 39: + +/* Line 1455 of yacc.c */ +#line 493 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (4)].gengetopt_option); + (yyval.gengetopt_option)->dependon = strdup((yyvsp[(4) - (4)].str)); + } + break; + + case 40: + +/* Line 1455 of yacc.c */ +#line 498 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (2)].gengetopt_option); + (yyval.gengetopt_option)->arg_is_optional = true; + } + break; + + case 41: + +/* Line 1455 of yacc.c */ +#line 503 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (3)].gengetopt_option); + (yyval.gengetopt_option)->multiple = true; + (yyval.gengetopt_option)->multiple_min = (yyvsp[(3) - (3)].multiple_size)->min; + (yyval.gengetopt_option)->multiple_max = (yyvsp[(3) - (3)].multiple_size)->max; + delete (yyvsp[(3) - (3)].multiple_size); + } + break; + + case 42: + +/* Line 1455 of yacc.c */ +#line 511 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (2)].gengetopt_option); + (yyval.gengetopt_option)->type = ARG_FLAG; + } + break; + + case 43: + +/* Line 1455 of yacc.c */ +#line 516 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (2)].gengetopt_option); + (yyval.gengetopt_option)->hidden = true; + } + break; + + case 44: + +/* Line 1455 of yacc.c */ +#line 521 "../../src/parser.yy" + { + (yyval.gengetopt_option) = (yyvsp[(1) - (2)].gengetopt_option); + (yyval.gengetopt_option)->flagstat = (yyvsp[(2) - (2)].boolean); + } + break; + + case 45: + +/* Line 1455 of yacc.c */ +#line 525 "../../src/parser.yy" + { (yyval.gengetopt_option) = new gengetopt_option; } + break; + + case 46: + +/* Line 1455 of yacc.c */ +#line 529 "../../src/parser.yy" + { (yyval.boolean) = 1; } + break; + + case 47: + +/* Line 1455 of yacc.c */ +#line 530 "../../src/parser.yy" + { (yyval.boolean) = 0; } + break; + + case 48: + +/* Line 1455 of yacc.c */ +#line 534 "../../src/parser.yy" + { (yyval.boolean) = 0; } + break; + + case 49: + +/* Line 1455 of yacc.c */ +#line 535 "../../src/parser.yy" + { (yyval.boolean) = 1; } + break; + + case 50: + +/* Line 1455 of yacc.c */ +#line 536 "../../src/parser.yy" + { (yyval.boolean) = 0; } + break; + + case 51: + +/* Line 1455 of yacc.c */ +#line 540 "../../src/parser.yy" + { (yyval.boolean) = 1; } + break; + + case 52: + +/* Line 1455 of yacc.c */ +#line 541 "../../src/parser.yy" + { (yyval.boolean) = 0; } + break; + + case 53: + +/* Line 1455 of yacc.c */ +#line 545 "../../src/parser.yy" + { (yyval.str) = 0; } + break; + + case 54: + +/* Line 1455 of yacc.c */ +#line 546 "../../src/parser.yy" + { (yyval.str) = (yyvsp[(3) - (3)].str); } + break; + + case 55: + +/* Line 1455 of yacc.c */ +#line 550 "../../src/parser.yy" + { (yyval.str) = 0; } + break; + + case 56: + +/* Line 1455 of yacc.c */ +#line 551 "../../src/parser.yy" + { (yyval.str) = (yyvsp[(3) - (3)].str); } + break; + + case 57: + +/* Line 1455 of yacc.c */ +#line 555 "../../src/parser.yy" + { (yyval.str) = 0; } + break; + + case 58: + +/* Line 1455 of yacc.c */ +#line 556 "../../src/parser.yy" + { (yyval.str) = (yyvsp[(3) - (3)].str); } + break; + + case 59: + +/* Line 1455 of yacc.c */ +#line 560 "../../src/parser.yy" + { (yyval.ValueList) = new AcceptedValues; (yyval.ValueList)->insert((yyvsp[(1) - (1)].str)); } + break; + + case 60: + +/* Line 1455 of yacc.c */ +#line 561 "../../src/parser.yy" + { (yyvsp[(1) - (3)].ValueList)->insert((yyvsp[(3) - (3)].str)); (yyval.ValueList) = (yyvsp[(1) - (3)].ValueList); } + break; + + case 61: + +/* Line 1455 of yacc.c */ +#line 565 "../../src/parser.yy" + { (yyval.str) = (yyvsp[(1) - (1)].str); } + break; + + case 62: + +/* Line 1455 of yacc.c */ +#line 569 "../../src/parser.yy" + { (yyval.multiple_size) = new multiple_size; } + break; + + case 63: + +/* Line 1455 of yacc.c */ +#line 570 "../../src/parser.yy" + { (yyval.multiple_size) = new multiple_size((yyvsp[(2) - (3)].str), (yyvsp[(2) - (3)].str)); } + break; + + case 64: + +/* Line 1455 of yacc.c */ +#line 571 "../../src/parser.yy" + { (yyval.multiple_size) = new multiple_size((yyvsp[(2) - (4)].str), "0"); free((yyvsp[(2) - (4)].str)); } + break; + + case 65: + +/* Line 1455 of yacc.c */ +#line 572 "../../src/parser.yy" + { (yyval.multiple_size) = new multiple_size("0", (yyvsp[(3) - (4)].str)); free((yyvsp[(3) - (4)].str)); } + break; + + case 66: + +/* Line 1455 of yacc.c */ +#line 573 "../../src/parser.yy" + { (yyval.multiple_size) = new multiple_size((yyvsp[(2) - (5)].str), (yyvsp[(4) - (5)].str)); free((yyvsp[(2) - (5)].str)); free((yyvsp[(4) - (5)].str)); } + break; + + + +/* Line 1455 of yacc.c */ +#line 2212 "../../src/parser.cc" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + *++yylsp = yyloc; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (yymsg); + } + else + { + yyerror (YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } + } +#endif + } + + yyerror_range[0] = yylloc; + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + yyerror_range[0] = yylsp[1-yylen]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + yyerror_range[0] = *yylsp; + yydestruct ("Error: popping", + yystos[yystate], yyvsp, yylsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + yyerror_range[1] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the lookahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + *++yylsp = yyloc; + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, yylsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + +/* Line 1675 of yacc.c */ +#line 576 "../../src/parser.yy" + + diff --git a/cmake/gengetopt/parser.h b/cmake/gengetopt/parser.h new file mode 100644 index 0000000..40cd85f --- /dev/null +++ b/cmake/gengetopt/parser.h @@ -0,0 +1,160 @@ + +/* A Bison parser, made by GNU Bison 2.4.1. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TOK_PACKAGE = 258, + TOK_VERSION = 259, + TOK_OPTION = 260, + TOK_DEFGROUP = 261, + TOK_GROUPOPTION = 262, + TOK_DEFMODE = 263, + TOK_MODEOPTION = 264, + TOK_YES = 265, + TOK_NO = 266, + TOK_ON = 267, + TOK_OFF = 268, + TOK_FLAG = 269, + TOK_PURPOSE = 270, + TOK_DESCRIPTION = 271, + TOK_USAGE = 272, + TOK_DEFAULT = 273, + TOK_GROUP = 274, + TOK_GROUPDESC = 275, + TOK_MODE = 276, + TOK_MODEDESC = 277, + TOK_MULTIPLE = 278, + TOK_ARGOPTIONAL = 279, + TOK_TYPESTR = 280, + TOK_SECTION = 281, + TOK_DETAILS = 282, + TOK_SECTIONDESC = 283, + TOK_TEXT = 284, + TOK_ARGS = 285, + TOK_VALUES = 286, + TOK_HIDDEN = 287, + TOK_DEPENDON = 288, + TOK_STRING = 289, + TOK_CHAR = 290, + TOK_ARGTYPE = 291, + TOK_SIZE = 292 + }; +#endif +/* Tokens. */ +#define TOK_PACKAGE 258 +#define TOK_VERSION 259 +#define TOK_OPTION 260 +#define TOK_DEFGROUP 261 +#define TOK_GROUPOPTION 262 +#define TOK_DEFMODE 263 +#define TOK_MODEOPTION 264 +#define TOK_YES 265 +#define TOK_NO 266 +#define TOK_ON 267 +#define TOK_OFF 268 +#define TOK_FLAG 269 +#define TOK_PURPOSE 270 +#define TOK_DESCRIPTION 271 +#define TOK_USAGE 272 +#define TOK_DEFAULT 273 +#define TOK_GROUP 274 +#define TOK_GROUPDESC 275 +#define TOK_MODE 276 +#define TOK_MODEDESC 277 +#define TOK_MULTIPLE 278 +#define TOK_ARGOPTIONAL 279 +#define TOK_TYPESTR 280 +#define TOK_SECTION 281 +#define TOK_DETAILS 282 +#define TOK_SECTIONDESC 283 +#define TOK_TEXT 284 +#define TOK_ARGS 285 +#define TOK_VALUES 286 +#define TOK_HIDDEN 287 +#define TOK_DEPENDON 288 +#define TOK_STRING 289 +#define TOK_CHAR 290 +#define TOK_ARGTYPE 291 +#define TOK_SIZE 292 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 1676 of yacc.c */ +#line 148 "../../src/parser.yy" + + char *str; + char chr; + int argtype; + int boolean; + class AcceptedValues *ValueList; + struct gengetopt_option *gengetopt_option; + struct multiple_size *multiple_size; + + + +/* Line 1676 of yacc.c */ +#line 138 "../../src/parser.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +extern YYSTYPE yylval; + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + +extern YYLTYPE yylloc; + diff --git a/cmake/gengetopt/parser.yy b/cmake/gengetopt/parser.yy new file mode 100644 index 0000000..d0a60e0 --- /dev/null +++ b/cmake/gengetopt/parser.yy @@ -0,0 +1,576 @@ +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +%{ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#include "my_sstream.h" + +#include "acceptedvalues.h" + +#include "argsdef.h" + +#include "gengetopt.h" +#include "errorcodes.h" +#include "ggos.h" +#include "yyerror.h" + +extern int gengetopt_count_line; +extern char * gengetopt_input_filename; + +static int gengetopt_package_given = 0; +static int gengetopt_version_given = 0; +static int gengetopt_purpose_given = 0; +static int gengetopt_usage_given = 0; +static int gengetopt_description_given = 0; + +/// the last option parsed +static gengetopt_option *current_option = 0; + +extern int yylex (void) ; + +//#define YYERROR_VERBOSE 1 + +void check_result(int o, gengetopt_option *opt) +{ + if (o) + { + ostringstream err; + + switch (o) + { + case NOT_ENOUGH_MEMORY: + yyerror (opt, "not enough memory"); + break; + case REQ_LONG_OPTION: + err << "long option redefined \'" << opt->long_opt << "\'"; + yyerror (opt, err.str().c_str()); + break; + case REQ_SHORT_OPTION: + err << "short option redefined \'" << opt->short_opt << "\'"; + yyerror (opt, err.str().c_str()); + break; + case FOUND_BUG: + yyerror (opt, "bug found!!"); + break; + case GROUP_UNDEFINED: + yyerror (opt, "group undefined"); + break; + case MODE_UNDEFINED: + yyerror (opt, "mode undefined"); + break; + case INVALID_DEFAULT_VALUE: + yyerror (opt, "invalid default value"); + break; + case NOT_REQUESTED_TYPE: + yyerror (opt, "type specification not requested"); + break; + case NOT_VALID_SPECIFICATION: + yyerror (opt, "invalid specification for this kind of option"); + break; + case SPECIFY_FLAG_STAT: + yyerror (opt, "you must specify the default flag status"); + break; + case NOT_GROUP_OPTION: + yyerror (opt, "group specification for a non group option"); + break; + case NOT_MODE_OPTION: + yyerror (opt, "mode specification for an option not belonging to a mode"); + break; + case SPECIFY_GROUP: + yyerror (opt, "missing group specification"); + break; + case SPECIFY_MODE: + yyerror (opt, "missing mode specification"); + break; + case INVALID_NUMERIC_VALUE: + yyerror (opt, "invalid numeric value"); + break; + case INVALID_ENUM_TYPE_USE: + yyerror (opt, "enum type can only be specified for options with values"); + break; + case HELP_REDEFINED: + yyerror (opt, "if you want to redefine --help, please use option --no-help"); + break; + case VERSION_REDEFINED: + yyerror (opt, "if you want to redefine --version, please use option --no-version"); + break; + } + } +} + +/* the number of allowed occurrences of a multiple option */ +struct multiple_size +{ + /* these strings are allocated dynamically and NOT + automatically freed upon destruction */ + char *min; + char *max; + + /* if no limit is specified then initialized to 0. + if the same size is specified for min and max, it means that an exact + number of occurrences is required*/ + multiple_size(const char *m = "0", const char *M = "0") : + min(strdup(m)), max(strdup(M)) + {} +}; + +#define check_error if (o) YYERROR; + +%} + +%union { + char *str; + char chr; + int argtype; + int boolean; + class AcceptedValues *ValueList; + struct gengetopt_option *gengetopt_option; + struct multiple_size *multiple_size; +} + +%token TOK_PACKAGE "package" +%token TOK_VERSION "version" +%token TOK_OPTION "option" +%token TOK_DEFGROUP "defgroup" +%token TOK_GROUPOPTION "groupoption" +%token TOK_DEFMODE "defmode" +%token TOK_MODEOPTION "modeoption" +%token TOK_YES "yes" +%token TOK_NO "no" +%token TOK_ON "on" +%token TOK_OFF "off" +%token TOK_FLAG "flag" +%token TOK_PURPOSE "purpose" +%token TOK_DESCRIPTION "description" +%token TOK_USAGE "usage" +%token TOK_DEFAULT "default" +%token TOK_GROUP "group" +%token TOK_GROUPDESC "groupdesc" +%token TOK_MODE "mode" +%token TOK_MODEDESC "modedesc" +%token TOK_MULTIPLE "multiple" +%token TOK_ARGOPTIONAL "argoptional" +%token TOK_TYPESTR "typestr" +%token TOK_SECTION "section" +%token TOK_DETAILS "details" +%token TOK_SECTIONDESC "sectiondesc" +%token TOK_TEXT "text" +%token TOK_ARGS "args" +%token TOK_VALUES "values" +%token TOK_HIDDEN "hidden" +%token TOK_DEPENDON "dependon" +%token TOK_STRING +%token TOK_CHAR +%token TOK_ARGTYPE +%token TOK_SIZE + +%type req_onoff +%type opt_yesno optional_yesno +%type quoted_string +%type opt_groupdesc +%type opt_sectiondesc +%type opt_modedesc +%type listofvalues +%type acceptedvalue +%type option_parts +%type multiple_size + + +%% /* ====================================================================== */ + + +input + : /* empty */ + | statement input + ; + + +statement + : package + | version + | args + | purpose + | description + | usage + | sectiondef + | option + | text + | groupoption + | groupdef + | modeoption + | modedef + ; + + +package + : TOK_PACKAGE TOK_STRING + { + if (gengetopt_package_given) + { + yyerror ("package redefined"); + YYERROR; + } + else + { + gengetopt_package_given = 1; + if (gengetopt_define_package ($2)) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + ; + +version + : TOK_VERSION TOK_STRING + { + if (gengetopt_version_given) + { + yyerror ("version redefined"); + YYERROR; + } + else + { + gengetopt_version_given = 1; + if (gengetopt_define_version ($2)) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + ; + +purpose + : TOK_PURPOSE quoted_string + { + if (gengetopt_purpose_given) + { + yyerror ("purpose redefined"); + YYERROR; + } + else + { + gengetopt_purpose_given = 1; + if (gengetopt_define_purpose ($2)) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + ; + +description + : TOK_DESCRIPTION quoted_string + { + if (gengetopt_description_given) + { + yyerror ("description redefined"); + YYERROR; + } + else + { + gengetopt_description_given = 1; + if (gengetopt_define_description ($2)) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + ; + +usage + : TOK_USAGE quoted_string + { + if (gengetopt_usage_given) + { + yyerror ("usage redefined"); + YYERROR; + } + else + { + gengetopt_usage_given = 1; + if (gengetopt_define_usage ($2)) + { + yyerror ("not enough memory"); + YYERROR; + } + } + } + ; + + +sectiondef + : TOK_SECTION quoted_string opt_sectiondesc + { + gengetopt_set_section ($2, $3); + } + ; + +text + : TOK_TEXT quoted_string + { + if (current_option) { + std::string current_option_text; + if (current_option->text_after) { + current_option_text = std::string(current_option->text_after) + $2; + current_option->text_after = strdup(current_option_text.c_str()); + } else { + current_option->text_after = strdup($2); + } + } else { + gengetopt_set_text($2); + } + } + ; + +args + : TOK_ARGS TOK_STRING + { + gengetopt_set_args($2); + } + ; + +groupdef + : TOK_DEFGROUP TOK_STRING opt_groupdesc optional_yesno + { + if (gengetopt_add_group ($2, $3, $4)) + { + yyerror ("group redefined"); + YYERROR; + } + } + ; + +modedef + : TOK_DEFMODE TOK_STRING opt_modedesc + { + if (gengetopt_add_mode ($2, $3)) + { + yyerror ("mode redefined"); + YYERROR; + } + } + ; + +option + : TOK_OPTION TOK_STRING TOK_CHAR quoted_string + option_parts + { + $5->filename = gengetopt_input_filename; + $5->linenum = @1.first_line; + $5->long_opt = strdup($2); + if ($3 != '-') + $5->short_opt = $3; + $5->desc = strdup($4); + int o = gengetopt_check_option ($5, false); + check_result(o, $5); + check_error; + o = gengetopt_add_option ($5); + check_result(o, $5); + check_error; + current_option = $5; + } + ; + +groupoption + : TOK_GROUPOPTION TOK_STRING TOK_CHAR quoted_string + option_parts + { + $5->filename = gengetopt_input_filename; + $5->linenum = @1.first_line; + $5->long_opt = strdup($2); + if ($3 != '-') + $5->short_opt = $3; + $5->desc = strdup($4); + int o = gengetopt_check_option ($5, true); + check_result(o, $5); + check_error; + o = gengetopt_add_option ($5); + check_result(o, $5); + check_error; + } + ; + +modeoption + : TOK_MODEOPTION TOK_STRING TOK_CHAR quoted_string + option_parts + { + $5->filename = gengetopt_input_filename; + $5->linenum = @1.first_line; + $5->long_opt = strdup($2); + if ($3 != '-') + $5->short_opt = $3; + $5->desc = strdup($4); + int o = gengetopt_check_option ($5, false, true); + check_result(o, $5); + check_error; + o = gengetopt_add_option ($5); + check_result(o, $5); + check_error; + } + ; + + +/* ---------------------------------------------------------------------- */ + +quoted_string + : TOK_STRING + ; + +option_parts: option_parts opt_yesno + { + $$ = $1; + $$->required = $2; + $$->required_set = true; + } + | option_parts TOK_ARGTYPE + { + $$ = $1; + $$->type = $2; + } + | option_parts TOK_TYPESTR '=' TOK_STRING + { + $$ = $1; + $$->type_str = strdup($4); + } + | option_parts TOK_DETAILS '=' quoted_string + { + $$ = $1; + $$->details = strdup($4); + } + | option_parts TOK_VALUES '=' listofvalues + { + $$ = $1; + $$->acceptedvalues = $4; + } + | option_parts TOK_DEFAULT '=' TOK_STRING + { + $$ = $1; + $$->default_string = strdup($4); + } + | option_parts TOK_GROUP '=' TOK_STRING + { + $$ = $1; + $$->group_value = strdup($4); + } + | option_parts TOK_MODE '=' TOK_STRING + { + $$ = $1; + $$->mode_value = strdup($4); + } + | option_parts TOK_DEPENDON '=' TOK_STRING + { + $$ = $1; + $$->dependon = strdup($4); + } + | option_parts TOK_ARGOPTIONAL + { + $$ = $1; + $$->arg_is_optional = true; + } + | option_parts TOK_MULTIPLE multiple_size + { + $$ = $1; + $$->multiple = true; + $$->multiple_min = $3->min; + $$->multiple_max = $3->max; + delete $3; + } + | option_parts TOK_FLAG + { + $$ = $1; + $$->type = ARG_FLAG; + } + | option_parts TOK_HIDDEN + { + $$ = $1; + $$->hidden = true; + } + | option_parts req_onoff + { + $$ = $1; + $$->flagstat = $2; + } + | { $$ = new gengetopt_option; } + ; + +req_onoff + : TOK_ON { $$ = 1; } + | TOK_OFF { $$ = 0; } + ; + +optional_yesno + : /* empty */ { $$ = 0; } + | TOK_YES { $$ = 1; } + | TOK_NO { $$ = 0; } + ; + +opt_yesno + : TOK_YES { $$ = 1; } + | TOK_NO { $$ = 0; } + ; + +opt_groupdesc + : /* empty */ { $$ = 0; } + | TOK_GROUPDESC '=' TOK_STRING { $$ = $3; } + ; + +opt_modedesc + : /* empty */ { $$ = 0; } + | TOK_MODEDESC '=' TOK_STRING { $$ = $3; } + ; + +opt_sectiondesc + : /* empty */ { $$ = 0; } + | TOK_SECTIONDESC '=' TOK_STRING { $$ = $3; } + ; + +listofvalues + : acceptedvalue { $$ = new AcceptedValues; $$->insert($1); } + | listofvalues ',' acceptedvalue { $1->insert($3); $$ = $1; } + ; + +acceptedvalue + : TOK_STRING { $$ = $1; } + ; + +multiple_size + : { $$ = new multiple_size; } + | '(' TOK_SIZE ')' { $$ = new multiple_size($2, $2); } + | '(' TOK_SIZE '-' ')' { $$ = new multiple_size($2, "0"); free($2); } + | '(' '-' TOK_SIZE ')' { $$ = new multiple_size("0", $3); free($3); } + | '(' TOK_SIZE '-' TOK_SIZE ')' { $$ = new multiple_size($2, $4); free($2); free($4); } + ; + +%% diff --git a/cmake/gengetopt/scanner.cc b/cmake/gengetopt/scanner.cc new file mode 100644 index 0000000..06ee13e --- /dev/null +++ b/cmake/gengetopt/scanner.cc @@ -0,0 +1,2364 @@ +#line 2 "../../src/scanner.cc" + +#line 4 "../../src/scanner.cc" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires + * access to the local variable yy_act. Since yyless() is a macro, it would break + * existing scanners that call yyless() from OUTSIDE yylex. + * One obvious solution it to make yy_act a global. I tried that, and saw + * a 5% performance hit in a non-yylineno scanner, because yy_act is + * normally declared as a register variable-- so it is not worth it. + */ + #define YY_LESS_LINENO(n) \ + do { \ + int yyl;\ + for ( yyl = n; yyl < yyleng; ++yyl )\ + if ( yytext[yyl] == '\n' )\ + --yylineno;\ + }while(0) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define yywrap(n) 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 62 +#define YY_END_OF_BUFFER 63 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[246] = + { 0, + 0, 0, 0, 0, 0, 0, 63, 61, 57, 59, + 60, 56, 48, 58, 43, 42, 47, 41, 47, 47, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 47, 47, 47, 47, 47, 62, 46, 44, 45, + 55, 51, 55, 54, 55, 57, 59, 56, 58, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 15, 0, 18, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 45, 51, 52, 0, + 53, 0, 50, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, 19, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 14, 49, 0, 40, 0, 0, 0, 0, 0, + 0, 0, 9, 17, 0, 0, 0, 4, 28, 0, + 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 25, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3, 0, 0, 22, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 6, 0, 0, 36, + 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, + 1, 0, 35, 0, 0, 23, 0, 30, 0, 0, + + 38, 0, 0, 0, 0, 0, 0, 0, 0, 10, + 20, 0, 34, 24, 11, 0, 27, 37, 0, 0, + 0, 0, 8, 29, 0, 31, 0, 0, 0, 26, + 0, 0, 0, 0, 0, 0, 0, 7, 13, 0, + 32, 21, 12, 33, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 5, 1, 6, 7, 1, 1, 1, 1, 8, + 9, 1, 1, 10, 11, 1, 1, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, + 13, 1, 14, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 1, 16, 1, 1, 1, 1, 17, 18, 19, 20, + + 21, 22, 23, 24, 25, 15, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 15, 38, + 39, 15, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[40] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int16_t yy_base[250] = + { 0, + 0, 0, 37, 47, 39, 57, 271, 272, 268, 0, + 272, 264, 272, 0, 272, 272, 272, 272, 235, 32, + 238, 239, 232, 239, 234, 232, 34, 231, 43, 30, + 239, 47, 36, 225, 59, 237, 272, 272, 272, 245, + 272, 253, 272, 272, 78, 253, 0, 249, 0, 230, + 55, 216, 215, 61, 220, 229, 213, 218, 226, 218, + 272, 222, 272, 208, 223, 208, 208, 220, 208, 204, + 198, 204, 217, 206, 199, 197, 218, 226, 272, 64, + 272, 199, 272, 58, 70, 206, 207, 208, 206, 195, + 199, 204, 184, 199, 272, 195, 196, 181, 272, 190, + + 188, 182, 176, 176, 177, 184, 173, 186, 183, 169, + 170, 272, 272, 172, 272, 166, 168, 170, 170, 165, + 172, 169, 272, 272, 160, 163, 172, 75, 76, 167, + 161, 173, 159, 163, 162, 151, 156, 272, 150, 162, + 161, 156, 145, 152, 148, 157, 156, 150, 147, 152, + 272, 79, 143, 141, 140, 148, 137, 136, 137, 142, + 130, 130, 132, 272, 138, 125, 272, 125, 128, 132, + 121, 119, 133, 123, 121, 117, 272, 129, 118, 272, + 112, 118, 112, 110, 117, 126, 121, 120, 119, 110, + 272, 105, 272, 108, 106, 272, 104, 272, 105, 98, + + 272, 98, 96, 112, 106, 109, 102, 105, 98, 272, + 272, 104, 103, 272, 272, 93, 272, 272, 96, 101, + 94, 91, 272, 272, 87, 272, 95, 98, 84, 272, + 78, 84, 75, 69, 74, 71, 68, 272, 272, 66, + 272, 272, 272, 272, 272, 109, 111, 78, 51 + } ; + +static yyconst flex_int16_t yy_def[250] = + { 0, + 245, 1, 246, 246, 247, 247, 245, 245, 245, 248, + 245, 245, 245, 249, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 248, 245, 249, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 0, 245, 245, 245, 245 + } ; + +static yyconst flex_int16_t yy_nxt[312] = + { 0, + 8, 9, 10, 11, 12, 13, 14, 15, 8, 16, + 17, 17, 18, 17, 17, 8, 19, 17, 17, 20, + 21, 22, 23, 24, 25, 17, 26, 27, 28, 29, + 30, 17, 31, 32, 33, 34, 35, 17, 36, 37, + 11, 42, 43, 14, 44, 38, 65, 39, 40, 37, + 11, 49, 51, 14, 45, 38, 71, 39, 40, 42, + 43, 52, 44, 59, 62, 66, 79, 68, 80, 60, + 69, 63, 45, 64, 72, 74, 85, 91, 47, 75, + 79, 70, 80, 81, 244, 86, 116, 114, 87, 88, + 92, 115, 117, 82, 154, 156, 243, 118, 178, 242, + + 241, 155, 240, 239, 238, 157, 83, 237, 179, 8, + 8, 41, 41, 236, 235, 234, 233, 232, 231, 230, + 229, 228, 227, 112, 61, 226, 225, 224, 223, 222, + 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, + 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, + 201, 200, 199, 198, 197, 196, 195, 194, 193, 192, + 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, + 181, 180, 177, 176, 175, 174, 173, 172, 171, 170, + 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, + 159, 158, 153, 152, 151, 150, 149, 148, 147, 146, + + 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, + 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, + 125, 124, 123, 122, 121, 120, 119, 113, 78, 77, + 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, + 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, + 90, 89, 84, 48, 46, 78, 77, 76, 73, 67, + 61, 58, 57, 56, 55, 54, 53, 50, 48, 46, + 245, 7, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245 + } ; + +static yyconst flex_int16_t yy_chk[312] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, + 3, 5, 5, 3, 5, 3, 30, 3, 3, 4, + 4, 249, 20, 4, 5, 4, 33, 4, 4, 6, + 6, 20, 6, 27, 29, 30, 80, 32, 80, 27, + 32, 29, 6, 29, 33, 35, 51, 54, 248, 35, + 45, 32, 45, 45, 240, 51, 85, 84, 51, 51, + 54, 84, 85, 45, 128, 129, 237, 85, 152, 236, + + 235, 128, 234, 233, 232, 129, 45, 231, 152, 246, + 246, 247, 247, 229, 228, 227, 225, 222, 221, 220, + 219, 216, 213, 212, 209, 208, 207, 206, 205, 204, + 203, 202, 200, 199, 197, 195, 194, 192, 190, 189, + 188, 187, 186, 185, 184, 183, 182, 181, 179, 178, + 176, 175, 174, 173, 172, 171, 170, 169, 168, 166, + 165, 163, 162, 161, 160, 159, 158, 157, 156, 155, + 154, 153, 150, 149, 148, 147, 146, 145, 144, 143, + 142, 141, 140, 139, 137, 136, 135, 134, 133, 132, + 131, 130, 127, 126, 125, 122, 121, 120, 119, 118, + + 117, 116, 114, 111, 110, 109, 108, 107, 106, 105, + 104, 103, 102, 101, 100, 98, 97, 96, 94, 93, + 92, 91, 90, 89, 88, 87, 86, 82, 78, 77, + 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, + 66, 65, 64, 62, 60, 59, 58, 57, 56, 55, + 53, 52, 50, 48, 46, 42, 40, 36, 34, 31, + 28, 26, 25, 24, 23, 22, 21, 19, 12, 9, + 7, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + + 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, + 245 + } ; + +/* Table of booleans, true if rule could match eol. */ +static yyconst flex_int32_t yy_rule_can_match_eol[63] = + { 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, }; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "../../src/scanner.ll" +/** + * Copyright (C) 1999-2007 Free Software Foundation, Inc. + * + * This file is part of GNU gengetopt + * + * GNU gengetopt is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU gengetopt is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with gengetopt; see the file COPYING. If not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#line 23 "../../src/scanner.ll" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "argsdef.h" +#include "parser.h" +extern int gengetopt_count_line; + +#include "my_sstream.h" + +static void update_count_line (char *str); +static void updateTokenInfo (int pos); + +// the buffer for strings (possibly spanning more lines) +static std::ostringstream buff; + +static void buffer(const char *s); +static char *flush_buffer(); + +#define LINEBUF_LEN 1024 + +#define PUSH(s) yy_push_state(s); +#define POP() yy_pop_state(); + +int tokenpos = 0; +char linebuf[LINEBUF_LEN] ; /* current line */ + +//#define DEBUG_SCANNER +#ifdef DEBUG_SCANNER +#include // for debug +#define DEB(s) std::cerr << s << std::endl; +#define DEB2(s,s2) std::cerr << s << ": " << s2 << std::endl; +#else +#define DEB(s) +#define DEB2(s,s2) +#endif + + +#line 692 "../../src/scanner.cc" + +#define INITIAL 0 +#define SIZE_STATE 1 +#define STRING_STATE 2 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +int yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + + static int yy_start_stack_ptr = 0; + static int yy_start_stack_depth = 0; + static int *yy_start_stack = NULL; + + static void yy_push_state (int new_state ); + + static void yy_pop_state (void ); + + static int yy_top_state (void ); + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 71 "../../src/scanner.ll" + + + +#line 893 "../../src/scanner.cc" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 246 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 272 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) + { + int yyl; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + + yylineno++; +; + } + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 74 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_STRING; return TOK_ARGTYPE; + YY_BREAK +case 2: +YY_RULE_SETUP +#line 75 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_INT; return TOK_ARGTYPE; + YY_BREAK +case 3: +YY_RULE_SETUP +#line 76 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_SHORT; return TOK_ARGTYPE; + YY_BREAK +case 4: +YY_RULE_SETUP +#line 77 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_LONG; return TOK_ARGTYPE; + YY_BREAK +case 5: +YY_RULE_SETUP +#line 78 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_FLOAT; return TOK_ARGTYPE; + YY_BREAK +case 6: +YY_RULE_SETUP +#line 79 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_DOUBLE; return TOK_ARGTYPE; + YY_BREAK +case 7: +YY_RULE_SETUP +#line 80 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_LONGDOUBLE; return TOK_ARGTYPE; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 81 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_LONGLONG; return TOK_ARGTYPE; + YY_BREAK +case 9: +YY_RULE_SETUP +#line 82 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.argtype = ARG_ENUM; return TOK_ARGTYPE; + YY_BREAK +case 10: +YY_RULE_SETUP +#line 84 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_PACKAGE; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 85 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_VERSION; + YY_BREAK +case 12: +YY_RULE_SETUP +#line 86 "../../src/scanner.ll" +updateTokenInfo (-1); yylloc.first_line = gengetopt_count_line; return TOK_GROUPOPTION; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 87 "../../src/scanner.ll" +updateTokenInfo (-1); yylloc.first_line = gengetopt_count_line; return TOK_MODEOPTION; + YY_BREAK +case 14: +YY_RULE_SETUP +#line 88 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_YES; + YY_BREAK +case 15: +YY_RULE_SETUP +#line 89 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_NO; + YY_BREAK +case 16: +YY_RULE_SETUP +#line 90 "../../src/scanner.ll" +updateTokenInfo (-1); yylloc.first_line = gengetopt_count_line; return TOK_OPTION; + YY_BREAK +case 17: +YY_RULE_SETUP +#line 91 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_FLAG; + YY_BREAK +case 18: +YY_RULE_SETUP +#line 92 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_ON; + YY_BREAK +case 19: +YY_RULE_SETUP +#line 93 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_OFF; + YY_BREAK +case 20: +YY_RULE_SETUP +#line 94 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_PURPOSE; + YY_BREAK +case 21: +YY_RULE_SETUP +#line 95 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_DESCRIPTION; + YY_BREAK +case 22: +YY_RULE_SETUP +#line 96 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_USAGE; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 97 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_DEFAULT; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 98 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_TYPESTR; + YY_BREAK +case 25: +YY_RULE_SETUP +#line 99 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_GROUP; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 100 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_GROUPDESC; + YY_BREAK +case 27: +YY_RULE_SETUP +#line 101 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_DEFGROUP; + YY_BREAK +case 28: +YY_RULE_SETUP +#line 102 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_MODE; + YY_BREAK +case 29: +YY_RULE_SETUP +#line 103 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_MODEDESC; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 104 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_DEFMODE; + YY_BREAK +case 31: +YY_RULE_SETUP +#line 105 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_MULTIPLE; + YY_BREAK +case 32: +YY_RULE_SETUP +#line 106 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_ARGOPTIONAL; + YY_BREAK +case 33: +YY_RULE_SETUP +#line 107 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_SECTIONDESC; + YY_BREAK +case 34: +YY_RULE_SETUP +#line 108 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_SECTION; + YY_BREAK +case 35: +YY_RULE_SETUP +#line 109 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_VALUES; + YY_BREAK +case 36: +YY_RULE_SETUP +#line 110 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_HIDDEN; + YY_BREAK +case 37: +YY_RULE_SETUP +#line 111 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_DEPENDON; + YY_BREAK +case 38: +YY_RULE_SETUP +#line 112 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_DETAILS; + YY_BREAK +case 39: +YY_RULE_SETUP +#line 113 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_TEXT; + YY_BREAK +case 40: +YY_RULE_SETUP +#line 114 "../../src/scanner.ll" +updateTokenInfo (-1); return TOK_ARGS; + YY_BREAK +case 41: +YY_RULE_SETUP +#line 116 "../../src/scanner.ll" +{ updateTokenInfo (-1); return '='; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 117 "../../src/scanner.ll" +{ updateTokenInfo (-1); return ','; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 119 "../../src/scanner.ll" +{ PUSH(SIZE_STATE); updateTokenInfo (-1); return '('; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 120 "../../src/scanner.ll" +{ updateTokenInfo (-1); return '-'; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 121 "../../src/scanner.ll" +{ updateTokenInfo (-1); yylval.str = strdup(yytext); return TOK_SIZE; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 122 "../../src/scanner.ll" +{ POP(); updateTokenInfo (-1); return ')'; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 124 "../../src/scanner.ll" +updateTokenInfo (-1); yylval.chr = yytext[0]; return TOK_CHAR; + YY_BREAK +case 48: +YY_RULE_SETUP +#line 126 "../../src/scanner.ll" +{ updateTokenInfo (-1); DEB("start string"); PUSH(STRING_STATE) ; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 127 "../../src/scanner.ll" +{ updateTokenInfo (2); buffer("\\\\n"); } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 128 "../../src/scanner.ll" +{ updateTokenInfo (1); buffer("\n"); } + YY_BREAK +case 51: +/* rule 51 can match eol */ +YY_RULE_SETUP +#line 129 "../../src/scanner.ll" +{ update_count_line (yytext); buffer( yytext ) ; } + YY_BREAK +case 52: +/* rule 52 can match eol */ +YY_RULE_SETUP +#line 130 "../../src/scanner.ll" +{ update_count_line (yytext); /* a line break */ } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 131 "../../src/scanner.ll" +{ updateTokenInfo (-1); buffer(yytext); } + YY_BREAK +case 54: +YY_RULE_SETUP +#line 132 "../../src/scanner.ll" +{ updateTokenInfo (-1); DEB("end string"); POP() ; yylval.str = flush_buffer(); return TOK_STRING; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 133 "../../src/scanner.ll" +{ updateTokenInfo (-1); buffer( yytext ) ; } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 135 "../../src/scanner.ll" +updateTokenInfo (-1); + YY_BREAK +case 57: +YY_RULE_SETUP +#line 136 "../../src/scanner.ll" +updateTokenInfo (8*yyleng); + YY_BREAK +case 58: +YY_RULE_SETUP +#line 138 "../../src/scanner.ll" +/* comments begin with # in any place (but strings) */ + YY_BREAK +case 59: +/* rule 59 can match eol */ +YY_RULE_SETUP +#line 139 "../../src/scanner.ll" +update_count_line (0); yyless(1) ; /* give back all but the \n to rescan */ + YY_BREAK +case 60: +YY_RULE_SETUP +#line 141 "../../src/scanner.ll" +{} + YY_BREAK +case 61: +YY_RULE_SETUP +#line 143 "../../src/scanner.ll" +{ + return 1000; /* little hack to produce a parse error too. */ +} + YY_BREAK +case 62: +YY_RULE_SETUP +#line 147 "../../src/scanner.ll" +ECHO; + YY_BREAK +#line 1301 "../../src/scanner.cc" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(SIZE_STATE): +case YY_STATE_EOF(STRING_STATE): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 246 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 246 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 245); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + if ( c == '\n' ) + + yylineno++; +; + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + + static void yy_push_state (int new_state ) +{ + if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) + { + yy_size_t new_size; + + (yy_start_stack_depth) += YY_START_STACK_INCR; + new_size = (yy_start_stack_depth) * sizeof( int ); + + if ( ! (yy_start_stack) ) + (yy_start_stack) = (int *) yyalloc(new_size ); + + else + (yy_start_stack) = (int *) yyrealloc((void *) (yy_start_stack),new_size ); + + if ( ! (yy_start_stack) ) + YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); + } + + (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; + + BEGIN(new_state); +} + + static void yy_pop_state (void) +{ + if ( --(yy_start_stack_ptr) < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); +} + + static int yy_top_state (void) +{ + return (yy_start_stack)[(yy_start_stack_ptr) - 1]; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + /* We do not touch yylineno unless the option is enabled. */ + yylineno = 1; + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + + (yy_start_stack_ptr) = 0; + (yy_start_stack_depth) = 0; + (yy_start_stack) = NULL; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Destroy the start condition stack. */ + yyfree((yy_start_stack) ); + (yy_start_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 147 "../../src/scanner.ll" + + + +/* + Otherwise '\n' within a TOK_MLSTRING would not be counted +*/ +void +update_count_line (char *str) +{ + if (str) + { + char *p; + for (p = str; *p; ++p) + if (*p == '\n') { + ++gengetopt_count_line; + tokenpos = 0 ; /* reset token position */ + strncpy (linebuf, ( (p+1) ? p+1 : ""), LINEBUF_LEN - 1); + } + } + else + { + ++gengetopt_count_line; + tokenpos = 0 ; /* reset token position */ + strncpy (linebuf, yytext+1, LINEBUF_LEN - 1); /* save the next line */ + } +} + +void +updateTokenInfo( int pos ) +{ + if ( pos >= 0 ) + tokenpos += pos ; + else + tokenpos += yyleng ; +} + +void buffer(const char *s) +{ + buff << s; +} + +char *flush_buffer() +{ + char *ret = strdup(buff.str().c_str()); + buff.str(""); + return ret; +} + diff --git a/cmake/gengetopt/skels/Makefile.am b/cmake/gengetopt/skels/Makefile.am new file mode 100644 index 0000000..3b98eed --- /dev/null +++ b/cmake/gengetopt/skels/Makefile.am @@ -0,0 +1,90 @@ +# Copyright (C) 1999-2008 Free Software Foundation, Inc. +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# if gengen is not installed we simply ignore the changes + +SUFFIXES = .h_skel + +if NO_GENGEN +#.h_skel.cc: +# echo "Not regenerating $@ since gengen is not installed" +# better not to use touch, otherwise we will create an empty file in +# the build directory +# touch $@ + +else +GENERATE = $(GENGEN) + +.h_skel.cc: + name="`echo $* | sed 's/^.*\///g'`"; \ + echo "$$name"; \ + $(GENERATE) -i $< -F $*.h -f $$name --separate-files --expand-tabs --output-dir=$(srcdir) --force +endif + +INCLUDES = -I@top_srcdir@/src + +noinst_LTLIBRARIES = libgen.la + +libgen_la_SOURCES = $(BUILT_SOURCES) + +BUILT_SOURCES = header.h header.cc c_source.h c_source.cc \ +handle_help.h handle_version.h handle_help.cc handle_version.cc \ +generic_option.h required_option.h dependant_option.h \ +generic_option.cc required_option.cc dependant_option.cc \ +group_counter.h group_option.h \ +group_counter.cc group_option.cc \ +print_help_string.h print_help_string.cc \ +multiple_opt_list.cc multiple_opt_list.h \ +multiple_fill_array.cc multiple_fill_array.h \ +copyright.cc copyright.h \ +free_string.cc free_string.h \ +free_multiple.cc free_multiple.h \ +reset_group.cc reset_group.h \ +exit_failure.cc exit_failure.h \ +update_given.cc update_given.h \ +option_arg.cc option_arg.h \ +given_field.cc given_field.h \ +clear_given.cc clear_given.h \ +clear_arg.cc clear_arg.h \ +free_list.cc free_list.h \ +file_save.cc file_save.h \ +file_save_multiple.cc file_save_multiple.h \ +init_args_info.cc init_args_info.h \ +custom_getopt_gen.cc custom_getopt_gen.h \ +check_modes.cc check_modes.h \ +enum_decl.cc enum_decl.h + +EXTRA_DIST = header.h_skel c_source.h_skel handle_help.h_skel \ +handle_version.h_skel generic_option.h_skel \ +required_option.h_skel dependant_option.h_skel \ +group_counter.h_skel group_option.h_skel \ +print_help_string.h_skel \ +multiple_opt_list.h_skel \ +multiple_fill_array.h_skel \ +copyright.h_skel free_string.h_skel \ +free_multiple.h_skel \ +reset_group.h_skel \ +exit_failure.h_skel \ +update_given.h_skel \ +option_arg.h_skel \ +given_field.h_skel \ +clear_given.h_skel \ +clear_arg.h_skel \ +free_list.h_skel \ +file_save.h_skel \ +file_save_multiple.h_skel \ +init_args_info.h_skel \ +custom_getopt_gen.h_skel \ +check_modes.h_skel \ +enum_decl.h_skel \ +$(BUILT_SOURCES) + +built-clean: + cd @srcdir@ && rm -f $(BUILT_SOURCES) \ No newline at end of file diff --git a/cmake/gengetopt/skels/c_source.cc b/cmake/gengetopt/skels/c_source.cc new file mode 100644 index 0000000..5120083 --- /dev/null +++ b/cmake/gengetopt/skels/c_source.cc @@ -0,0 +1,5079 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "c_source.h" + +void +c_source_gen_class::generate_c_source(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " File autogenerated by gengetopt "; + generate_string (generator_version, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << " generated with the following command:"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (command_line, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " The developers of gengetopt consider the fixed text that goes in all"; + stream << "\n"; + stream << indent_str; + stream << " gengetopt output files to be in the public domain:"; + stream << "\n"; + stream << indent_str; + stream << " we make no copyright claims on it."; + stream << "\n"; + stream << indent_str; + stream << "*/"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* If we use autoconf. */"; + stream << "\n"; + stream << indent_str; + stream << "#ifdef HAVE_CONFIG_H"; + stream << "\n"; + stream << indent_str; + stream << "#include \"config.h\""; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#include "; + stream << "\n"; + stream << indent_str; + stream << "#include "; + stream << "\n"; + stream << indent_str; + stream << "#include "; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef FIX_UNUSED"; + stream << "\n"; + stream << indent_str; + stream << "#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (( ! include_getopt )) + { + stream << "#include "; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "#include \""; + generate_string (source_name, stream, indent + indent_str.length ()); + stream << "."; + generate_string (header_file_ext, stream, indent + indent_str.length ()); + stream << "\""; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_purpose = \""; + generate_string (purpose, stream, indent + indent_str.length ()); + stream << "\";"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_usage = \"Usage: "; + if (no_package) + { + stream << "\" "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << " \""; + } + generate_string (usage_string, stream, indent + indent_str.length ()); + stream << "\";"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_description = \""; + generate_string (description, stream, indent + indent_str.length ()); + stream << "\";"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (( has_hidden || has_details )) + { + if (has_details) + { + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_detailed_help[] = {"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (detailed_help_option_print.size () > 0) + generate_string (detailed_help_option_print, stream, indent + indent_str.length ()); + else + generate_detailed_help_option_print (stream, indent + indent_str.length ()); + stream << " 0"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + if (has_hidden) + { + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "init_full_help_array(void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (full_help_option_print.size () > 0) + generate_string (full_help_option_print, stream, indent + indent_str.length ()); + else + generate_full_help_option_print (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_full_help["; + generate_string (help_string_num, stream, indent + indent_str.length ()); + stream << "];"; + stream << "\n"; + stream << indent_str; + } + } + else + { + if (has_hidden) + { + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_full_help[] = {"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (full_help_option_print.size () > 0) + generate_string (full_help_option_print, stream, indent + indent_str.length ()); + else + generate_full_help_option_print (stream, indent + indent_str.length ()); + stream << " 0"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + } + } + stream << "\n"; + stream << indent_str; + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "init_help_array(void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (help_option_print.size () > 0) + generate_string (help_option_print, stream, indent + indent_str.length ()); + else + generate_help_option_print (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_help["; + generate_string (help_string_num, stream, indent + indent_str.length ()); + stream << "];"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << "const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_help[] = {"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (help_option_print.size () > 0) + generate_string (help_option_print, stream, indent + indent_str.length ()); + else + generate_help_option_print (stream, indent + indent_str.length ()); + stream << " 0"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "typedef enum {ARG_NO"; + stream << "\n"; + stream << indent_str; + if (has_arg_flag) + { + stream << " , ARG_FLAG"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_string) + { + stream << " , ARG_STRING"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_int) + { + stream << " , ARG_INT"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " , ARG_SHORT"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " , ARG_LONG"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " , ARG_FLOAT"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " , ARG_DOUBLE"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " , ARG_LONGDOUBLE"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << " , ARG_LONGLONG"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_enum) + { + stream << " , ARG_ENUM"; + stream << "\n"; + stream << indent_str; + } + stream << "} "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_arg_type;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void clear_given (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void clear_args (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_internal (int argc, char **argv, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params, const char *additional_error);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (check_required_options) + { + stream << "static int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_required2 (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, const char *prog_name, const char *additional_error);"; + stream << "\n"; + stream << indent_str; + } + if (cmd_list) + { + stream << "struct line_list"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char * string_arg;"; + stream << "\n"; + stream << indent_str; + stream << " struct line_list * next;"; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static struct line_list *cmd_line_list = 0;"; + stream << "\n"; + stream << indent_str; + stream << "static struct line_list *cmd_line_list_tmp = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "free_cmd_list(void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " /* free the list of a previous call */"; + stream << "\n"; + stream << indent_str; + stream << " if (cmd_line_list)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " while (cmd_line_list) {"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list = cmd_line_list->next;"; + stream << "\n"; + stream << indent_str; + stream << " free (cmd_line_list_tmp->string_arg);"; + stream << "\n"; + stream << indent_str; + stream << " free (cmd_line_list_tmp);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + if (option_values.size () > 0) + generate_string (option_values, stream, indent + indent_str.length ()); + else + generate_option_values (stream, indent + indent_str.length ()); + stream << indent_str; + if (do_generate_strdup) + { + stream << "static char *"; + stream << "\n"; + stream << indent_str; + stream << "gengetopt_strdup (const char *s);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void clear_given (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + indent = 2; + if (given_init.size () > 0) + generate_string (given_init, stream, indent + indent_str.length ()); + else + generate_given_init (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void clear_args (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " FIX_UNUSED (args_info);"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (clear_arg.size () > 0) + generate_string (clear_arg, stream, indent + indent_str.length ()); + else + generate_clear_arg (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void init_args_info(struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + if (( has_hidden && has_details )) + { + stream << " init_full_help_array(); "; + } + stream << "\n"; + stream << indent_str; + if (( has_hidden || has_details )) + { + stream << " init_help_array(); "; + } + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (init_args_info.size () > 0) + generate_string (init_args_info, stream, indent + indent_str.length ()); + else + generate_init_args_info (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_version (void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " printf (\"%s %s\\n\","; + stream << "\n"; + stream << indent_str; + stream << " (strlen("; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "_NAME) ? "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "_NAME : "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "),"; + stream << "\n"; + stream << indent_str; + indent = 5; + stream << " "; + generate_string (version_var_name, stream, indent + indent_str.length ()); + stream << ");"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static void print_help_common(void) {"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_version ();"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (strlen("; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_purpose) > 0)"; + stream << "\n"; + stream << indent_str; + stream << " printf(\"\\n%s\\n\", "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_purpose);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (strlen("; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_usage) > 0)"; + stream << "\n"; + stream << indent_str; + stream << " printf(\"\\n%s\\n\", "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_usage);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " printf(\"\\n\");"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (strlen("; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_description) > 0)"; + stream << "\n"; + stream << indent_str; + stream << " printf(\"%s\\n\\n\", "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_description);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_help (void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0;"; + stream << "\n"; + stream << indent_str; + stream << " print_help_common();"; + stream << "\n"; + stream << indent_str; + stream << " while ("; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_help[i])"; + stream << "\n"; + stream << indent_str; + stream << " printf(\"%s\\n\", "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_help[i++]);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (has_hidden) + { + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_full_help (void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0;"; + stream << "\n"; + stream << indent_str; + stream << " print_help_common();"; + stream << "\n"; + stream << indent_str; + stream << " while ("; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_full_help[i])"; + stream << "\n"; + stream << indent_str; + stream << " printf(\"%s\\n\", "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_full_help[i++]);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + if (has_details) + { + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_detailed_help (void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0;"; + stream << "\n"; + stream << indent_str; + stream << " print_help_common();"; + stream << "\n"; + stream << indent_str; + stream << " while ("; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_detailed_help[i])"; + stream << "\n"; + stream << indent_str; + stream << " printf(\"%s\\n\", "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_detailed_help[i++]);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_init (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " clear_given (args_info);"; + stream << "\n"; + stream << indent_str; + stream << " clear_args (args_info);"; + stream << "\n"; + stream << indent_str; + stream << " init_args_info (args_info);"; + stream << "\n"; + stream << indent_str; + if (handle_unamed) + { + stream << "\n"; + stream << indent_str; + stream << " args_info->inputs = 0;"; + stream << "\n"; + stream << indent_str; + stream << " args_info->inputs_num = 0;"; + stream << "\n"; + stream << indent_str; + } + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params_init(struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " if (params)"; + stream << "\n"; + stream << indent_str; + stream << " { "; + stream << "\n"; + stream << indent_str; + stream << " params->override = 0;"; + stream << "\n"; + stream << indent_str; + stream << " params->initialize = 1;"; + stream << "\n"; + stream << indent_str; + stream << " params->check_required = 1;"; + stream << "\n"; + stream << indent_str; + stream << " params->check_ambiguity = 0;"; + stream << "\n"; + stream << indent_str; + stream << " params->print_errors = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params_create(void)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params = "; + stream << "\n"; + stream << indent_str; + stream << " (struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *)malloc(sizeof(struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params));"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params_init(params); "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " return params;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (has_typed_options) + { + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "free_string_field (char **s)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " if (*s)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " free (*s);"; + stream << "\n"; + stream << indent_str; + stream << " *s = 0;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + if (multiple_token_functions) + { + stream << "/** "; + stream << "@"; + stream << "brief generic value variable */"; + stream << "\n"; + stream << indent_str; + stream << "union generic_value {"; + stream << "\n"; + stream << indent_str; + if (( has_arg_int || has_arg_enum )) + { + stream << " int int_arg;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " short short_arg;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " long long_arg;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " float float_arg;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " double double_arg;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " long double longdouble_arg;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << "#ifdef HAVE_LONG_LONG"; + stream << "\n"; + stream << indent_str; + stream << " long long int longlong_arg;"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + stream << " long longlong_arg;"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + } + stream << " char *string_arg;"; + stream << "\n"; + stream << indent_str; + stream << " const char *default_string_arg;"; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief holds temporary values for multiple options */"; + stream << "\n"; + stream << indent_str; + stream << "struct generic_list"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " union generic_value arg;"; + stream << "\n"; + stream << indent_str; + stream << " char *orig;"; + stream << "\n"; + stream << indent_str; + stream << " struct generic_list *next;"; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "brief add a node at the head of the list "; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static void add_node(struct generic_list **list) {"; + stream << "\n"; + stream << indent_str; + stream << " struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));"; + stream << "\n"; + stream << indent_str; + stream << " new_node->next = *list;"; + stream << "\n"; + stream << indent_str; + stream << " *list = new_node;"; + stream << "\n"; + stream << indent_str; + stream << " new_node->arg.string_arg = 0;"; + stream << "\n"; + stream << indent_str; + stream << " new_node->orig = 0;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (( ( ! multiple_options_all_string ) && multiple_token_functions )) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The passed arg parameter is NOT set to 0 from this function"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "free_multiple_field(unsigned int len, void *arg, char ***orig)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " unsigned int i;"; + stream << "\n"; + stream << indent_str; + stream << " if (arg) {"; + stream << "\n"; + stream << indent_str; + stream << " for (i = 0; i < len; ++i)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " free_string_field(&((*orig)[i]));"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " free (arg);"; + stream << "\n"; + stream << indent_str; + stream << " free (*orig);"; + stream << "\n"; + stream << indent_str; + stream << " *orig = 0;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + if (multiple_options_string) + { + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "free_multiple_string_field(unsigned int len, char ***arg, char ***orig)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " unsigned int i;"; + stream << "\n"; + stream << indent_str; + stream << " if (*arg) {"; + stream << "\n"; + stream << indent_str; + stream << " for (i = 0; i < len; ++i)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " free_string_field(&((*arg)[i]));"; + stream << "\n"; + stream << indent_str; + stream << " free_string_field(&((*orig)[i]));"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " free_string_field(&((*arg)[0])); /* free default string */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " free (*arg);"; + stream << "\n"; + stream << indent_str; + stream << " *arg = 0;"; + stream << "\n"; + stream << indent_str; + stream << " free (*orig);"; + stream << "\n"; + stream << indent_str; + stream << " *orig = 0;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + } + stream << "\n"; + stream << indent_str; + stream << "static void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_release (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + if (handle_unamed) + { + stream << " unsigned int i;"; + } + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (free.size () > 0) + generate_string (free, stream, indent + indent_str.length ()); + else + generate_free (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + if (handle_unamed) + { + stream << " for (i = 0; i < args_info->inputs_num; ++i)"; + stream << "\n"; + stream << indent_str; + stream << " free (args_info->inputs [i]);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (args_info->inputs_num)"; + stream << "\n"; + stream << indent_str; + stream << " free (args_info->inputs);"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << " clear_given (args_info);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (check_possible_values) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param val the value to check"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param values the possible values"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return the index of the matched value:"; + stream << "\n"; + stream << indent_str; + stream << " * -1 if no value matched,"; + stream << "\n"; + stream << indent_str; + stream << " * -2 if more than one value has matched"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static int"; + stream << "\n"; + stream << indent_str; + stream << "check_possible_values(const char *val, const char *values[])"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i, found, last;"; + stream << "\n"; + stream << indent_str; + stream << " size_t len;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (!val) /* otherwise strlen() crashes below */"; + stream << "\n"; + stream << indent_str; + stream << " return -1; /* -1 means no argument for the option */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " found = last = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " for (i = 0, len = strlen(val); values[i]; ++i)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (strncmp(val, values[i], len) == 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " ++found;"; + stream << "\n"; + stream << indent_str; + stream << " last = i;"; + stream << "\n"; + stream << indent_str; + stream << " if (strlen(values[i]) == len)"; + stream << "\n"; + stream << indent_str; + stream << " return i; /* exact macth no need to check more */"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (found == 1) /* one match: OK */"; + stream << "\n"; + stream << indent_str; + stream << " return last;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return (found ? -2 : -1); /* return many values or none matched */"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + if (check_possible_values) + { + stream << " int found = -1;"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " FIX_UNUSED (values);"; + stream << "\n"; + stream << indent_str; + } + stream << " if (arg) {"; + stream << "\n"; + stream << indent_str; + if (check_possible_values) + { + stream << " if (values) {"; + stream << "\n"; + stream << indent_str; + stream << " found = check_possible_values(arg, values); "; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (found >= 0)"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(outfile, \"%s=\\\"%s\\\" # %s\\n\", opt, arg, values[found]);"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(outfile, \"%s=\\\"%s\\\"\\n\", opt, arg);"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " fprintf(outfile, \"%s=\\\"%s\\\"\\n\", opt, arg);"; + stream << "\n"; + stream << indent_str; + } + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(outfile, \"%s\\n\", opt);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (multiple_options) + { + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[])"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " for (i = 0; i < len; ++i)"; + stream << "\n"; + stream << indent_str; + stream << " write_into_file(outfile, opt, (arg ? arg[i] : 0), values);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_dump(FILE *outfile, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (!outfile)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: cannot dump options to stream\\n\", "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ");"; + stream << "\n"; + stream << indent_str; + stream << " return EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (file_save_loop.size () > 0) + generate_string (file_save_loop, stream, indent + indent_str.length ()); + else + generate_file_save_loop (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " i = EXIT_SUCCESS;"; + stream << "\n"; + stream << indent_str; + stream << " return i;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_file_save(const char *filename, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " FILE *outfile;"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " outfile = fopen(filename, \"w\");"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (!outfile)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: cannot open file for writing: %s\\n\", "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", filename);"; + stream << "\n"; + stream << indent_str; + stream << " return EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " i = "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_dump(outfile, args_info);"; + stream << "\n"; + stream << indent_str; + stream << " fclose (outfile);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return i;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "void"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_free (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_release (args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (do_generate_strdup) + { + stream << "/** "; + stream << "@"; + stream << "brief replacement of strdup, which is not standard */"; + stream << "\n"; + stream << indent_str; + stream << "char *"; + stream << "\n"; + stream << indent_str; + stream << "gengetopt_strdup (const char *s)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char *result = 0;"; + stream << "\n"; + stream << indent_str; + stream << " if (!s)"; + stream << "\n"; + stream << indent_str; + stream << " return result;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " result = (char*)malloc(strlen(s) + 1);"; + stream << "\n"; + stream << indent_str; + stream << " if (result == (char*)0)"; + stream << "\n"; + stream << indent_str; + stream << " return (char*)0;"; + stream << "\n"; + stream << indent_str; + stream << " strcpy(result, s);"; + stream << "\n"; + stream << indent_str; + stream << " return result;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + if (multiple_token_functions) + { + stream << "static char *"; + stream << "\n"; + stream << indent_str; + stream << "get_multiple_arg_token(const char *arg)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " const char *tok;"; + stream << "\n"; + stream << indent_str; + stream << " char *ret;"; + stream << "\n"; + stream << indent_str; + stream << " size_t len, num_of_escape, i, j;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (!arg)"; + stream << "\n"; + stream << indent_str; + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " tok = strchr (arg, ',');"; + stream << "\n"; + stream << indent_str; + stream << " num_of_escape = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* make sure it is not escaped */"; + stream << "\n"; + stream << indent_str; + stream << " while (tok)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (*(tok-1) == '\\\\')"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " /* find the next one */"; + stream << "\n"; + stream << indent_str; + stream << " tok = strchr (tok+1, ',');"; + stream << "\n"; + stream << indent_str; + stream << " ++num_of_escape;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (tok)"; + stream << "\n"; + stream << indent_str; + stream << " len = (size_t)(tok - arg + 1);"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " len = strlen (arg) + 1;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " len -= num_of_escape;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " ret = (char *) malloc (len);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " i = 0;"; + stream << "\n"; + stream << indent_str; + stream << " j = 0;"; + stream << "\n"; + stream << indent_str; + stream << " while (arg[i] && (j < len-1))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (arg[i] == '\\\\' && "; + stream << "\n"; + stream << indent_str; + stream << " arg[ i + 1 ] && "; + stream << "\n"; + stream << indent_str; + stream << " arg[ i + 1 ] == ',')"; + stream << "\n"; + stream << indent_str; + stream << " ++i;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " ret[j++] = arg[i++];"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " ret[len-1] = '\\0';"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return ret;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static const char *"; + stream << "\n"; + stream << indent_str; + stream << "get_multiple_arg_token_next(const char *arg)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " const char *tok;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (!arg)"; + stream << "\n"; + stream << indent_str; + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " tok = strchr (arg, ',');"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* make sure it is not escaped */"; + stream << "\n"; + stream << indent_str; + stream << " while (tok)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (*(tok-1) == '\\\\')"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " /* find the next one */"; + stream << "\n"; + stream << indent_str; + stream << " tok = strchr (tok+1, ',');"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (! tok || strlen(tok) == 1)"; + stream << "\n"; + stream << indent_str; + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return tok+1;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + if (multiple_options) + { + stream << "static int"; + stream << "\n"; + stream << indent_str; + stream << "check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + stream << "check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int error = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (option_given && (min > 0 || max > 0))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (min > 0 && max > 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (min == max)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " /* specific occurrences */"; + stream << "\n"; + stream << indent_str; + stream << " if (option_given != (unsigned int) min)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %s option occurrences must be %d\\n\","; + stream << "\n"; + stream << indent_str; + stream << " prog_name, option_desc, min);"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else if (option_given < (unsigned int) min"; + stream << "\n"; + stream << indent_str; + stream << " || option_given > (unsigned int) max)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " /* range occurrences */"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %s option occurrences must be between %d and %d\\n\","; + stream << "\n"; + stream << indent_str; + stream << " prog_name, option_desc, min, max);"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else if (min > 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " /* at least check */"; + stream << "\n"; + stream << indent_str; + stream << " if (option_given < min)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %s option occurrences must be at least %d\\n\","; + stream << "\n"; + stream << indent_str; + stream << " prog_name, option_desc, min);"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else if (max > 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " /* at most check */"; + stream << "\n"; + stream << indent_str; + stream << " if (option_given > max)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %s option occurrences must be at most %d\\n\","; + stream << "\n"; + stream << indent_str; + stream << " prog_name, option_desc, max);"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + indent = 4; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " return error;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + if (reset_groups.size () > 0) + generate_string (reset_groups, stream, indent + indent_str.length ()); + else + generate_reset_groups (stream, indent + indent_str.length ()); + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << " (int argc, char **argv, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " return "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "2 (argc, argv, args_info, 0, 1, 1);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_ext (int argc, char **argv, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int result;"; + stream << "\n"; + stream << indent_str; + stream << " result = "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_internal (argc, argv, args_info, params, 0);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (final_exit, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "2 (int argc, char **argv, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, int override, int initialize, int check_required)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int result;"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params params;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " params.override = override;"; + stream << "\n"; + stream << indent_str; + stream << " params.initialize = initialize;"; + stream << "\n"; + stream << indent_str; + stream << " params.check_required = check_required;"; + stream << "\n"; + stream << indent_str; + stream << " params.check_ambiguity = 0;"; + stream << "\n"; + stream << indent_str; + stream << " params.print_errors = 1;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " result = "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_internal (argc, argv, args_info, ¶ms, 0);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (final_exit, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_required (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, const char *prog_name)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + if (check_required_options) + { + stream << " int result = EXIT_SUCCESS;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if ("; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_required2(args_info, prog_name, 0) > 0)"; + stream << "\n"; + stream << indent_str; + stream << " result = EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (final_exit, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " FIX_UNUSED (args_info);"; + stream << "\n"; + stream << indent_str; + stream << " FIX_UNUSED (prog_name);"; + stream << "\n"; + stream << indent_str; + stream << " return EXIT_SUCCESS;"; + stream << "\n"; + stream << indent_str; + } + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (check_required_options) + { + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_required2 (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, const char *prog_name, const char *additional_error)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int error = 0;"; + stream << "\n"; + stream << indent_str; + stream << " FIX_UNUSED (additional_error);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* checks for required options */"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (handle_required.size () > 0) + generate_string (handle_required, stream, indent + indent_str.length ()); + else + generate_handle_required (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " /* checks for dependences among options */"; + stream << "\n"; + stream << indent_str; + indent = 2; + if (handle_dependencies.size () > 0) + generate_string (handle_dependencies, stream, indent + indent_str.length ()); + else + generate_handle_dependencies (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return error;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + if (include_getopt) + { + if (custom_getopt.size () > 0) + generate_string (custom_getopt, stream, indent + indent_str.length ()); + else + generate_custom_getopt (stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "static char *package_name = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (( ! no_options )) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "brief updates an option"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param field the generic pointer to the field to update"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param orig_field the pointer to the orig field"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param field_given the pointer to the number of occurrence of this option"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param prev_given the pointer to the number of occurrence already seen"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param value the argument for this option (if null no arg was specified)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param possible_values the possible values for this option (if specified)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param default_value the default value (in case the option only accepts fixed values)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param arg_type the type of this option"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param check_ambiguity "; + stream << "@"; + stream << "see "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params.check_ambiguity"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param override "; + stream << "@"; + stream << "see "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params.override"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param no_free whether to free a possible previous value"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param multiple_option whether this is a multiple option"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param long_opt the corresponding long option"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param short_opt the corresponding short option (or '-' if none)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param additional_error possible further error specification"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "int update_arg(void *field, char **orig_field,"; + stream << "\n"; + stream << indent_str; + stream << " unsigned int *field_given, unsigned int *prev_given, "; + stream << "\n"; + stream << indent_str; + stream << " char *value, const char *possible_values[],"; + stream << "\n"; + stream << indent_str; + stream << " const char *default_value,"; + stream << "\n"; + stream << indent_str; + indent = 15; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_arg_type arg_type,"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " int check_ambiguity, int override,"; + stream << "\n"; + stream << indent_str; + stream << " int no_free, int multiple_option,"; + stream << "\n"; + stream << indent_str; + stream << " const char *long_opt, char short_opt,"; + stream << "\n"; + stream << indent_str; + stream << " const char *additional_error)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char *stop_char = 0;"; + stream << "\n"; + stream << indent_str; + stream << " const char *val = value;"; + stream << "\n"; + stream << indent_str; + stream << " int found;"; + stream << "\n"; + stream << indent_str; + if (has_arg_string) + { + stream << " char **string_field;"; + stream << "\n"; + stream << indent_str; + } + stream << " FIX_UNUSED (field);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " stop_char = 0;"; + stream << "\n"; + stream << indent_str; + stream << " found = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (short_opt != '-')"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: `--%s' (`-%c') option given more than once%s\\n\", "; + stream << "\n"; + stream << indent_str; + stream << " package_name, long_opt, short_opt,"; + stream << "\n"; + stream << indent_str; + stream << " (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: `--%s' option given more than once%s\\n\", "; + stream << "\n"; + stream << indent_str; + stream << " package_name, long_opt,"; + stream << "\n"; + stream << indent_str; + stream << " (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " return 1; /* failure */"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (check_possible_values) + { + stream << " if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " if (short_opt != '-')"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %s argument, \\\"%s\\\", for option `--%s' (`-%c')%s\\n\", "; + stream << "\n"; + stream << indent_str; + stream << " package_name, (found == -2) ? \"ambiguous\" : \"invalid\", value, long_opt, short_opt,"; + stream << "\n"; + stream << indent_str; + stream << " (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %s argument, \\\"%s\\\", for option `--%s'%s\\n\", "; + stream << "\n"; + stream << indent_str; + stream << " package_name, (found == -2) ? \"ambiguous\" : \"invalid\", value, long_opt,"; + stream << "\n"; + stream << indent_str; + stream << " (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " return 1; /* failure */"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " FIX_UNUSED (default_value);"; + stream << "\n"; + stream << indent_str; + } + stream << " "; + stream << "\n"; + stream << indent_str; + stream << " if (field_given && *field_given && ! override)"; + stream << "\n"; + stream << indent_str; + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << " if (prev_given)"; + stream << "\n"; + stream << indent_str; + stream << " (*prev_given)++;"; + stream << "\n"; + stream << indent_str; + stream << " if (field_given)"; + stream << "\n"; + stream << indent_str; + stream << " (*field_given)++;"; + stream << "\n"; + stream << indent_str; + stream << " if (possible_values)"; + stream << "\n"; + stream << indent_str; + stream << " val = possible_values[found];"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " switch(arg_type) {"; + stream << "\n"; + stream << indent_str; + if (has_arg_flag) + { + stream << " case ARG_FLAG:"; + stream << "\n"; + stream << indent_str; + stream << " *((int *)field) = !*((int *)field);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_int) + { + stream << " case ARG_INT:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((int *)field) = strtol (val, &stop_char, 0);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " case ARG_SHORT:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((short *)field) = (short)strtol (val, &stop_char, 0);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " case ARG_LONG:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " case ARG_FLOAT:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((float *)field) = (float)strtod (val, &stop_char);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " case ARG_DOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((double *)field) = strtod (val, &stop_char);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " case ARG_LONGDOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((long double *)field) = (long double)strtod (val, &stop_char);"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << " case ARG_LONGLONG:"; + stream << "\n"; + stream << indent_str; + stream << "#ifdef HAVE_LONG_LONG"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((long long int*)field) = (long long int) strtol (val, &stop_char, 0);"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_enum) + { + stream << " case ARG_ENUM:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) *((int *)field) = found;"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_string) + { + stream << " case ARG_STRING:"; + stream << "\n"; + stream << indent_str; + stream << " if (val) {"; + stream << "\n"; + stream << indent_str; + stream << " string_field = (char **)field;"; + stream << "\n"; + stream << indent_str; + stream << " if (!no_free && *string_field)"; + stream << "\n"; + stream << indent_str; + stream << " free (*string_field); /* free previous string */"; + stream << "\n"; + stream << indent_str; + stream << " *string_field = gengetopt_strdup (val);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + stream << " default:"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " };"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (( ( ( ( ( ( has_arg_int || has_arg_short ) || has_arg_long ) || has_arg_float ) || has_arg_double ) || has_arg_longdouble ) || has_arg_longlong )) + { + stream << " /* check numeric conversion */"; + stream << "\n"; + stream << indent_str; + stream << " switch(arg_type) {"; + stream << "\n"; + stream << indent_str; + if (has_arg_int) + { + stream << " case ARG_INT:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " case ARG_SHORT:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " case ARG_LONG:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " case ARG_FLOAT:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " case ARG_DOUBLE:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " case ARG_LONGDOUBLE:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << " case ARG_LONGLONG:"; + stream << "\n"; + stream << indent_str; + } + stream << " if (val && !(stop_char && *stop_char == '\\0')) {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr, \"%s: invalid numeric value: %s\\n\", package_name, val);"; + stream << "\n"; + stream << indent_str; + stream << " return 1; /* failure */"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " default:"; + stream << "\n"; + stream << indent_str; + stream << " ;"; + stream << "\n"; + stream << indent_str; + stream << " };"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << " /* store the original value */"; + stream << "\n"; + stream << indent_str; + stream << " switch(arg_type) {"; + stream << "\n"; + stream << indent_str; + stream << " case ARG_NO:"; + stream << "\n"; + stream << indent_str; + if (has_arg_flag) + { + stream << " case ARG_FLAG:"; + stream << "\n"; + stream << indent_str; + } + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " default:"; + stream << "\n"; + stream << indent_str; + stream << " if (value && orig_field) {"; + stream << "\n"; + stream << indent_str; + stream << " if (no_free) {"; + stream << "\n"; + stream << indent_str; + stream << " *orig_field = value;"; + stream << "\n"; + stream << indent_str; + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " if (*orig_field)"; + stream << "\n"; + stream << indent_str; + stream << " free (*orig_field); /* free previous string */"; + stream << "\n"; + stream << indent_str; + stream << " *orig_field = gengetopt_strdup (value);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " };"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return 0; /* OK */"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + if (multiple_token_functions) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "brief store information about a multiple option in a temporary list"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param list where to (temporarily) store multiple options"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "int update_multiple_arg_temp(struct generic_list **list,"; + stream << "\n"; + stream << indent_str; + stream << " unsigned int *prev_given, const char *val,"; + stream << "\n"; + stream << indent_str; + stream << " const char *possible_values[], const char *default_value,"; + stream << "\n"; + stream << indent_str; + indent = 15; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_arg_type arg_type,"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " const char *long_opt, char short_opt,"; + stream << "\n"; + stream << indent_str; + stream << " const char *additional_error)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " /* store single arguments */"; + stream << "\n"; + stream << indent_str; + stream << " char *multi_token;"; + stream << "\n"; + stream << indent_str; + stream << " const char *multi_next;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (arg_type == ARG_NO) {"; + stream << "\n"; + stream << indent_str; + stream << " (*prev_given)++;"; + stream << "\n"; + stream << indent_str; + stream << " return 0; /* OK */"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " multi_token = get_multiple_arg_token(val);"; + stream << "\n"; + stream << indent_str; + stream << " multi_next = get_multiple_arg_token_next (val);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " while (1)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " add_node (list);"; + stream << "\n"; + stream << indent_str; + stream << " if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,"; + stream << "\n"; + stream << indent_str; + stream << " prev_given, multi_token, possible_values, default_value, "; + stream << "\n"; + stream << indent_str; + stream << " arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {"; + stream << "\n"; + stream << indent_str; + stream << " if (multi_token) free(multi_token);"; + stream << "\n"; + stream << indent_str; + stream << " return 1; /* failure */"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (multi_next)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " multi_token = get_multiple_arg_token(multi_next);"; + stream << "\n"; + stream << indent_str; + stream << " multi_next = get_multiple_arg_token_next (multi_next);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return 0; /* OK */"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "brief free the passed list (including possible string argument)"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void free_list(struct generic_list *list, short string_arg)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " if (list) {"; + stream << "\n"; + stream << indent_str; + stream << " struct generic_list *tmp;"; + stream << "\n"; + stream << indent_str; + stream << " while (list)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " tmp = list;"; + stream << "\n"; + stream << indent_str; + stream << " if (string_arg && list->arg.string_arg)"; + stream << "\n"; + stream << indent_str; + stream << " free (list->arg.string_arg);"; + stream << "\n"; + stream << indent_str; + stream << " if (list->orig)"; + stream << "\n"; + stream << indent_str; + stream << " free (list->orig);"; + stream << "\n"; + stream << indent_str; + stream << " list = list->next;"; + stream << "\n"; + stream << indent_str; + stream << " free (tmp);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "brief updates a multiple option starting from the passed list"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static"; + stream << "\n"; + stream << indent_str; + stream << "void update_multiple_arg(void *field, char ***orig_field,"; + stream << "\n"; + stream << indent_str; + stream << " unsigned int field_given, unsigned int prev_given, union generic_value *default_value,"; + stream << "\n"; + stream << indent_str; + indent = 15; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_arg_type arg_type,"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " struct generic_list *list)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i;"; + stream << "\n"; + stream << indent_str; + stream << " struct generic_list *tmp;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (prev_given && list) {"; + stream << "\n"; + stream << indent_str; + stream << " *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " switch(arg_type) {"; + stream << "\n"; + stream << indent_str; + if (( has_arg_int || has_arg_enum )) + { + if (has_arg_int) + { + stream << " case ARG_INT:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_enum) + { + stream << " case ARG_ENUM:"; + stream << "\n"; + stream << indent_str; + } + stream << " *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " case ARG_SHORT:"; + stream << "\n"; + stream << indent_str; + stream << " *((short **)field) = (short *)realloc (*((short **)field), (field_given + prev_given) * sizeof (short)); break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " case ARG_LONG:"; + stream << "\n"; + stream << indent_str; + stream << " *((long **)field) = (long *)realloc (*((long **)field), (field_given + prev_given) * sizeof (long)); break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " case ARG_FLOAT:"; + stream << "\n"; + stream << indent_str; + stream << " *((float **)field) = (float *)realloc (*((float **)field), (field_given + prev_given) * sizeof (float)); break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " case ARG_DOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " case ARG_LONGDOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " *((long double **)field) = (long double *)realloc (*((long double **)field), (field_given + prev_given) * sizeof (long double)); break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << " case ARG_LONGLONG:"; + stream << "\n"; + stream << indent_str; + stream << "#ifdef HAVE_LONG_LONG"; + stream << "\n"; + stream << indent_str; + stream << " *((long long int **)field) = (long long int *)realloc (*((long long int **)field), (field_given + prev_given) * sizeof (long long int)); break;"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + stream << " *((long **)field) = (long *)realloc (*((long **)field), (field_given + prev_given) * sizeof (long)); break;"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_string) + { + stream << " case ARG_STRING:"; + stream << "\n"; + stream << indent_str; + stream << " *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;"; + stream << "\n"; + stream << indent_str; + } + stream << " default:"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " };"; + stream << "\n"; + stream << indent_str; + indent = 4; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " for (i = (prev_given - 1); i >= 0; --i)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " tmp = list;"; + stream << "\n"; + stream << indent_str; + indent = 8; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " switch(arg_type) {"; + stream << "\n"; + stream << indent_str; + if (has_arg_int) + { + stream << " case ARG_INT:"; + stream << "\n"; + stream << indent_str; + stream << " (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " case ARG_SHORT:"; + stream << "\n"; + stream << indent_str; + stream << " (*((short **)field))[i + field_given] = tmp->arg.short_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " case ARG_LONG:"; + stream << "\n"; + stream << indent_str; + stream << " (*((long **)field))[i + field_given] = tmp->arg.long_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " case ARG_FLOAT:"; + stream << "\n"; + stream << indent_str; + stream << " (*((float **)field))[i + field_given] = tmp->arg.float_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " case ARG_DOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " case ARG_LONGDOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " (*((long double **)field))[i + field_given] = tmp->arg.longdouble_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << " case ARG_LONGLONG:"; + stream << "\n"; + stream << indent_str; + stream << "#ifdef HAVE_LONG_LONG"; + stream << "\n"; + stream << indent_str; + stream << " (*((long long int **)field))[i + field_given] = tmp->arg.longlong_arg; break;"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + stream << " (*((long **)field))[i + field_given] = tmp->arg.longlong_arg; break;"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_enum) + { + stream << " case ARG_ENUM:"; + stream << "\n"; + stream << indent_str; + stream << " (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_string) + { + stream << " case ARG_STRING:"; + stream << "\n"; + stream << indent_str; + stream << " (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;"; + stream << "\n"; + stream << indent_str; + } + stream << " default:"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " } "; + stream << "\n"; + stream << indent_str; + stream << " (*orig_field) [i + field_given] = list->orig;"; + stream << "\n"; + stream << indent_str; + stream << " list = list->next;"; + stream << "\n"; + stream << indent_str; + stream << " free (tmp);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " } else { /* set the default value */"; + stream << "\n"; + stream << indent_str; + stream << " if (default_value && ! field_given) {"; + stream << "\n"; + stream << indent_str; + stream << " switch(arg_type) {"; + stream << "\n"; + stream << indent_str; + if (( has_arg_int || has_arg_enum )) + { + if (has_arg_int) + { + stream << " case ARG_INT:"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_enum) + { + stream << " case ARG_ENUM:"; + stream << "\n"; + stream << indent_str; + } + stream << " if (! *((int **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((int **)field) = (int *)malloc (sizeof (int));"; + stream << "\n"; + stream << indent_str; + stream << " (*((int **)field))[0] = default_value->int_arg; "; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_short) + { + stream << " case ARG_SHORT:"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((short **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((short **)field) = (short *)malloc (sizeof (short));"; + stream << "\n"; + stream << indent_str; + stream << " (*((short **)field))[0] = default_value->short_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_long) + { + stream << " case ARG_LONG:"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((long **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((long **)field) = (long *)malloc (sizeof (long));"; + stream << "\n"; + stream << indent_str; + stream << " (*((long **)field))[0] = default_value->long_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_float) + { + stream << " case ARG_FLOAT:"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((float **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((float **)field) = (float *)malloc (sizeof (float));"; + stream << "\n"; + stream << indent_str; + stream << " (*((float **)field))[0] = default_value->float_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_double) + { + stream << " case ARG_DOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((double **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((double **)field) = (double *)malloc (sizeof (double));"; + stream << "\n"; + stream << indent_str; + stream << " (*((double **)field))[0] = default_value->double_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longdouble) + { + stream << " case ARG_LONGDOUBLE:"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((long double **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((long double **)field) = (long double *)malloc (sizeof (long double));"; + stream << "\n"; + stream << indent_str; + stream << " (*((long double **)field))[0] = default_value->longdouble_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_longlong) + { + stream << " case ARG_LONGLONG:"; + stream << "\n"; + stream << indent_str; + stream << "#ifdef HAVE_LONG_LONG"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((long long int **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((long long int **)field) = (long long int *)malloc (sizeof (long long int));"; + stream << "\n"; + stream << indent_str; + stream << " (*((long long int **)field))[0] = default_value->longlong_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((long **)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((long **)field) = (long *)malloc (sizeof (long));"; + stream << "\n"; + stream << indent_str; + stream << " (*((long **)field))[0] = default_value->longlong_arg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + if (has_arg_string) + { + stream << " case ARG_STRING:"; + stream << "\n"; + stream << indent_str; + stream << " if (! *((char ***)field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *((char ***)field) = (char **)malloc (sizeof (char *));"; + stream << "\n"; + stream << indent_str; + stream << " (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + } + stream << " default: break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (!(*orig_field)) {"; + stream << "\n"; + stream << indent_str; + stream << " *orig_field = (char **) malloc (sizeof (char *));"; + stream << "\n"; + stream << indent_str; + stream << " (*orig_field)[0] = 0;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + if (has_modes) + { + stream << "\n"; + stream << indent_str; + stream << "static int check_modes("; + stream << "\n"; + stream << indent_str; + stream << " int given1[], const char *options1[],"; + stream << "\n"; + stream << indent_str; + stream << " int given2[], const char *options2[])"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0, j = 0, errors = 0;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " while (given1[i] >= 0) {"; + stream << "\n"; + stream << indent_str; + stream << " if (given1[i]) {"; + stream << "\n"; + stream << indent_str; + stream << " while (given2[j] >= 0) {"; + stream << "\n"; + stream << indent_str; + stream << " if (given2[j]) {"; + stream << "\n"; + stream << indent_str; + stream << " ++errors;"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr, \"%s: option %s conflicts with option %s\\n\","; + stream << "\n"; + stream << indent_str; + stream << " package_name, options1[i], options2[j]);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " ++j;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " ++i;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " return errors;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_internal ("; + stream << "\n"; + stream << indent_str; + stream << " int argc, char **argv, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params, const char *additional_error)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int c; /* Character of the parsed option. */"; + stream << "\n"; + stream << indent_str; + if (multiple_options_with_default) + { + stream << " union generic_value multiple_default_value;"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + indent = 2; + if (list_def.size () > 0) + generate_string (list_def, stream, indent + indent_str.length ()); + else + generate_list_def (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << " int error = 0;"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " local_args_info;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " int override;"; + stream << "\n"; + stream << indent_str; + stream << " int initialize;"; + stream << "\n"; + stream << indent_str; + stream << " int check_required;"; + stream << "\n"; + stream << indent_str; + stream << " int check_ambiguity;"; + stream << "\n"; + stream << indent_str; + if (include_getopt) + { + stream << "\n"; + stream << indent_str; + stream << " char *optarg;"; + stream << "\n"; + stream << indent_str; + stream << " int optind;"; + stream << "\n"; + stream << indent_str; + stream << " int opterr;"; + stream << "\n"; + stream << indent_str; + stream << " int optopt;"; + stream << "\n"; + stream << indent_str; + } + stream << " "; + stream << "\n"; + stream << indent_str; + stream << " package_name = argv[0];"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " override = params->override;"; + stream << "\n"; + stream << indent_str; + stream << " initialize = params->initialize;"; + stream << "\n"; + stream << indent_str; + stream << " check_required = params->check_required;"; + stream << "\n"; + stream << indent_str; + stream << " check_ambiguity = params->check_ambiguity;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (initialize)"; + stream << "\n"; + stream << indent_str; + indent = 4; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_init (args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_init (&local_args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " optarg = 0;"; + stream << "\n"; + stream << indent_str; + stream << " optind = 0;"; + stream << "\n"; + stream << indent_str; + stream << " opterr = params->print_errors;"; + stream << "\n"; + stream << indent_str; + stream << " optopt = '?';"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " while (1)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " int option_index = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " static struct option long_options[] = {"; + stream << "\n"; + stream << indent_str; + indent = 8; + if (long_option_struct.size () > 0) + generate_string (long_option_struct, stream, indent + indent_str.length ()); + else + generate_long_option_struct (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << " { 0, 0, 0, 0 }"; + stream << "\n"; + stream << indent_str; + stream << " };"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (include_getopt) + { + stream << " custom_optarg = optarg;"; + stream << "\n"; + stream << indent_str; + stream << " custom_optind = optind;"; + stream << "\n"; + stream << indent_str; + stream << " custom_opterr = opterr;"; + stream << "\n"; + stream << indent_str; + stream << " custom_optopt = optopt;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " c = custom_getopt_long (argc, argv, \""; + generate_string (getopt_string, stream, indent + indent_str.length ()); + stream << "\", long_options, &option_index);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " optarg = custom_optarg;"; + stream << "\n"; + stream << indent_str; + stream << " optind = custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " opterr = custom_opterr;"; + stream << "\n"; + stream << indent_str; + stream << " optopt = custom_optopt;"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " c = getopt_long (argc, argv, \""; + generate_string (getopt_string, stream, indent + indent_str.length ()); + stream << "\", long_options, &option_index);"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << " if (c == -1) break; /* Exit from `while (1)' loop. */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " switch (c)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + indent = 8; + if (handle_option.size () > 0) + generate_string (handle_option, stream, indent + indent_str.length ()); + else + generate_handle_option (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " case 0: /* Long option with no short option */"; + stream << "\n"; + stream << indent_str; + indent = 10; + if (handle_no_short_option.size () > 0) + generate_string (handle_no_short_option, stream, indent + indent_str.length ()); + else + generate_handle_no_short_option (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + if (handle_question_mark) + { + stream << " case '?': /* Invalid option. */"; + stream << "\n"; + stream << indent_str; + stream << " /* `getopt_long' already printed an error message. */"; + stream << "\n"; + stream << indent_str; + stream << " goto failure;"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << " default: /* bug: option not considered. */"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: option unknown: %c%s\\n\", "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", c, (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " abort ();"; + stream << "\n"; + stream << indent_str; + stream << " } /* switch */"; + stream << "\n"; + stream << indent_str; + stream << " } /* while */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + if (handle_group.size () > 0) + generate_string (handle_group, stream, indent + indent_str.length ()); + else + generate_handle_group (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << "\n"; + stream << indent_str; + indent = 2; + if (multiple_fill_array.size () > 0) + generate_string (multiple_fill_array, stream, indent + indent_str.length ()); + else + generate_multiple_fill_array (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + indent = 2; + if (update_multiple_given.size () > 0) + generate_string (update_multiple_given, stream, indent + indent_str.length ()); + else + generate_update_multiple_given (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + indent = 2; + if (check_modes.size () > 0) + generate_string (check_modes, stream, indent + indent_str.length ()); + else + generate_check_modes (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (check_required_options) + { + stream << " if (check_required)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " error += "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_required2 (args_info, argv[0], additional_error);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_release (&local_args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if ( error )"; + stream << "\n"; + stream << indent_str; + stream << " return (EXIT_FAILURE);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (handle_unamed) + { + stream << " if (optind < argc)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " int i = 0 ;"; + stream << "\n"; + stream << indent_str; + stream << " int found_prog_name = 0;"; + stream << "\n"; + stream << indent_str; + stream << " /* whether program name, i.e., argv[0], is in the remaining args"; + stream << "\n"; + stream << indent_str; + stream << " (this may happen with some implementations of getopt,"; + stream << "\n"; + stream << indent_str; + stream << " but surely not with the one included by gengetopt) */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (include_getopt) + { + + + } + else + { + stream << " i = optind;"; + stream << "\n"; + stream << indent_str; + stream << " while (i < argc)"; + stream << "\n"; + stream << indent_str; + stream << " if (argv[i++] == argv[0]) {"; + stream << "\n"; + stream << indent_str; + stream << " found_prog_name = 1;"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " i = 0;"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << " args_info->inputs_num = argc - optind - found_prog_name;"; + stream << "\n"; + stream << indent_str; + stream << " args_info->inputs ="; + stream << "\n"; + stream << indent_str; + stream << " (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;"; + stream << "\n"; + stream << indent_str; + stream << " while (optind < argc)"; + stream << "\n"; + stream << indent_str; + if (include_getopt) + { + stream << " args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " if (argv[optind++] != argv[0])"; + stream << "\n"; + stream << indent_str; + stream << " args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;"; + stream << "\n"; + stream << indent_str; + } + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "failure:"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (list_free.size () > 0) + generate_string (list_free, stream, indent + indent_str.length ()); + else + generate_list_free (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_release (&local_args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " return (EXIT_FAILURE);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + if (conf_parser) + { + stream << "\n"; + stream << indent_str; + stream << "#ifndef CONFIG_FILE_LINE_SIZE"; + stream << "\n"; + stream << indent_str; + stream << "#define CONFIG_FILE_LINE_SIZE 2048"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "#define ADDITIONAL_ERROR \" in configuration file \""; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)"; + stream << "\n"; + stream << indent_str; + stream << "/* 3 is for \"--\" and \"=\" */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static int"; + stream << "\n"; + stream << indent_str; + stream << "_"; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_configfile (const char *filename, int *my_argc)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " FILE* file;"; + stream << "\n"; + stream << indent_str; + stream << " char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];"; + stream << "\n"; + stream << indent_str; + stream << " char linebuf[CONFIG_FILE_LINE_SIZE];"; + stream << "\n"; + stream << indent_str; + stream << " int line_num = 0;"; + stream << "\n"; + stream << indent_str; + stream << " int result = 0, equal;"; + stream << "\n"; + stream << indent_str; + stream << " char *fopt, *farg;"; + stream << "\n"; + stream << indent_str; + stream << " char *str_index;"; + stream << "\n"; + stream << indent_str; + stream << " size_t len, next_token;"; + stream << "\n"; + stream << indent_str; + stream << " char delimiter;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if ((file = fopen(filename, \"r\")) == 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: Error opening configuration file '%s'\\n\","; + stream << "\n"; + stream << indent_str; + indent = 15; + stream << " "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", filename);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " return EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " ++line_num;"; + stream << "\n"; + stream << indent_str; + stream << " my_argv[0] = '\\0';"; + stream << "\n"; + stream << indent_str; + stream << " len = strlen(linebuf);"; + stream << "\n"; + stream << indent_str; + stream << " if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s:%s:%d: Line too long in configuration file\\n\","; + stream << "\n"; + stream << indent_str; + indent = 19; + stream << " "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", filename, line_num);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " result = EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* find first non-whitespace character in the line */"; + stream << "\n"; + stream << indent_str; + stream << " next_token = strspn (linebuf, \" \\t\\r\\n\");"; + stream << "\n"; + stream << indent_str; + stream << " str_index = linebuf + next_token;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if ( str_index[0] == '\\0' || str_index[0] == '#')"; + stream << "\n"; + stream << indent_str; + stream << " continue; /* empty line or comment line is skipped */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " fopt = str_index;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* truncate fopt at the end of the first non-valid character */"; + stream << "\n"; + stream << indent_str; + stream << " next_token = strcspn (fopt, \" \\t\\r\\n=\");"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (fopt[next_token] == '\\0') /* the line is over */"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " farg = 0;"; + stream << "\n"; + stream << indent_str; + stream << " equal = 0;"; + stream << "\n"; + stream << indent_str; + stream << " goto noarg;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* remember if equal sign is present */"; + stream << "\n"; + stream << indent_str; + stream << " equal = (fopt[next_token] == '=');"; + stream << "\n"; + stream << indent_str; + stream << " fopt[next_token++] = '\\0';"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* advance pointers to the next token after the end of fopt */"; + stream << "\n"; + stream << indent_str; + stream << " next_token += strspn (fopt + next_token, \" \\t\\r\\n\");"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* check for the presence of equal sign, and if so, skip it */"; + stream << "\n"; + stream << indent_str; + stream << " if ( !equal )"; + stream << "\n"; + stream << indent_str; + stream << " if ((equal = (fopt[next_token] == '=')))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " next_token++;"; + stream << "\n"; + stream << indent_str; + stream << " next_token += strspn (fopt + next_token, \" \\t\\r\\n\");"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " str_index += next_token;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* find argument */"; + stream << "\n"; + stream << indent_str; + stream << " farg = str_index;"; + stream << "\n"; + stream << indent_str; + stream << " if ( farg[0] == '\\\"' || farg[0] == '\\'' )"; + stream << "\n"; + stream << indent_str; + stream << " { /* quoted argument */"; + stream << "\n"; + stream << indent_str; + stream << " str_index = strchr (++farg, str_index[0] ); /* skip opening quote */"; + stream << "\n"; + stream << indent_str; + stream << " if (! str_index)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf"; + stream << "\n"; + stream << indent_str; + stream << " (stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s:%s:%d: unterminated string in configuration file\\n\","; + stream << "\n"; + stream << indent_str; + indent = 17; + stream << " "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", filename, line_num);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " result = EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " { /* read up the remaining part up to a delimiter */"; + stream << "\n"; + stream << indent_str; + stream << " next_token = strcspn (farg, \" \\t\\r\\n#\\'\\\"\");"; + stream << "\n"; + stream << indent_str; + stream << " str_index += next_token;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* truncate farg at the delimiter and store it for further check */"; + stream << "\n"; + stream << indent_str; + stream << " delimiter = *str_index, *str_index++ = '\\0';"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* everything but comment is illegal at the end of line */"; + stream << "\n"; + stream << indent_str; + stream << " if (delimiter != '\\0' && delimiter != '#')"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " str_index += strspn(str_index, \" \\t\\r\\n\");"; + stream << "\n"; + stream << indent_str; + stream << " if (*str_index != '\\0' && *str_index != '#')"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf"; + stream << "\n"; + stream << indent_str; + stream << " (stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s:%s:%d: malformed string in configuration file\\n\","; + stream << "\n"; + stream << indent_str; + indent = 17; + stream << " "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", filename, line_num);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " result = EXIT_FAILURE;"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " noarg:"; + stream << "\n"; + stream << indent_str; + stream << " if (!strcmp(fopt,\"include\")) {"; + stream << "\n"; + stream << indent_str; + stream << " if (farg && *farg) {"; + stream << "\n"; + stream << indent_str; + stream << " result = _"; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_configfile(farg, my_argc);"; + stream << "\n"; + stream << indent_str; + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr, \"%s:%s:%d: include requires a filename argument.\\n\","; + stream << "\n"; + stream << indent_str; + indent = 18; + stream << " "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", filename, line_num);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " continue;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " len = strlen(fopt);"; + stream << "\n"; + stream << indent_str; + stream << " strcat (my_argv, len > 1 ? \"--\" : \"-\");"; + stream << "\n"; + stream << indent_str; + stream << " strcat (my_argv, fopt);"; + stream << "\n"; + stream << indent_str; + stream << " if (len > 1 && ((farg && *farg) || equal))"; + stream << "\n"; + stream << indent_str; + stream << " strcat (my_argv, \"=\");"; + stream << "\n"; + stream << indent_str; + stream << " if (farg && *farg)"; + stream << "\n"; + stream << indent_str; + stream << " strcat (my_argv, farg);"; + stream << "\n"; + stream << indent_str; + stream << " ++(*my_argc);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp->next = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list = cmd_line_list_tmp;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list->string_arg = gengetopt_strdup(my_argv);"; + stream << "\n"; + stream << indent_str; + stream << " } /* while */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (file)"; + stream << "\n"; + stream << indent_str; + stream << " fclose(file);"; + stream << "\n"; + stream << indent_str; + stream << " return result;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_configfile ("; + stream << "\n"; + stream << indent_str; + stream << " const char *filename,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " int override, int initialize, int check_required)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params params;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " params.override = override;"; + stream << "\n"; + stream << indent_str; + stream << " params.initialize = initialize;"; + stream << "\n"; + stream << indent_str; + stream << " params.check_required = check_required;"; + stream << "\n"; + stream << indent_str; + stream << " params.check_ambiguity = 0;"; + stream << "\n"; + stream << indent_str; + stream << " params.print_errors = 1;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " return "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_config_file (filename, args_info, ¶ms);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_config_file (const char *filename,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int i, result;"; + stream << "\n"; + stream << indent_str; + stream << " int my_argc = 1;"; + stream << "\n"; + stream << indent_str; + stream << " char **my_argv_arg;"; + stream << "\n"; + stream << indent_str; + stream << " char *additional_error;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* store the program name */"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp->next = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list = cmd_line_list_tmp;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list->string_arg = gengetopt_strdup ("; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ");"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " result = _"; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_configfile(filename, &my_argc);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (result != EXIT_FAILURE) {"; + stream << "\n"; + stream << indent_str; + stream << " my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " for (i = my_argc - 1; i >= 0; --i) {"; + stream << "\n"; + stream << indent_str; + stream << " my_argv_arg[i] = cmd_line_list_tmp->string_arg;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = cmd_line_list_tmp->next;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " my_argv_arg[my_argc] = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);"; + stream << "\n"; + stream << indent_str; + stream << " strcpy (additional_error, ADDITIONAL_ERROR);"; + stream << "\n"; + stream << indent_str; + stream << " strcat (additional_error, filename);"; + stream << "\n"; + stream << indent_str; + stream << " result ="; + stream << "\n"; + stream << indent_str; + indent = 6; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_internal (my_argc, my_argv_arg, args_info,"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " params,"; + stream << "\n"; + stream << indent_str; + stream << " additional_error);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " free (additional_error);"; + stream << "\n"; + stream << indent_str; + stream << " free (my_argv_arg);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " free_cmd_list();"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (final_exit, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } + if (generate_string_parser) + { + stream << "\n"; + stream << indent_str; + stream << "static unsigned int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_create_argv(const char *cmdline_, char ***argv_ptr, const char *prog_name)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char *cmdline, *p;"; + stream << "\n"; + stream << indent_str; + stream << " size_t n = 0, j;"; + stream << "\n"; + stream << indent_str; + stream << " int i;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (prog_name) {"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp->next = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list = cmd_line_list_tmp;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list->string_arg = gengetopt_strdup (prog_name);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " ++n;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " cmdline = gengetopt_strdup(cmdline_);"; + stream << "\n"; + stream << indent_str; + stream << " p = cmdline;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " while (p && strlen(p))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " j = strcspn(p, \" \\t\");"; + stream << "\n"; + stream << indent_str; + stream << " ++n;"; + stream << "\n"; + stream << indent_str; + stream << " if (j && j < strlen(p))"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " p[j] = '\\0';"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp->next = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list = cmd_line_list_tmp;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list->string_arg = gengetopt_strdup (p);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " p += (j+1);"; + stream << "\n"; + stream << indent_str; + stream << " p += strspn(p, \" \\t\");"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp->next = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list = cmd_line_list_tmp;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list->string_arg = gengetopt_strdup (p);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " *argv_ptr = (char **) malloc((n + 1) * sizeof(char *));"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = cmd_line_list;"; + stream << "\n"; + stream << indent_str; + stream << " for (i = (n-1); i >= 0; --i)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " (*argv_ptr)[i] = cmd_line_list_tmp->string_arg;"; + stream << "\n"; + stream << indent_str; + stream << " cmd_line_list_tmp = cmd_line_list_tmp->next;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " (*argv_ptr)[n] = 0;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " free(cmdline);"; + stream << "\n"; + stream << indent_str; + stream << " return n;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string(const char *cmdline, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, const char *prog_name)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " return "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string2(cmdline, args_info, prog_name, 0, 1, 1);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string2(const char *cmdline, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, const char *prog_name,"; + stream << "\n"; + stream << indent_str; + stream << " int override, int initialize, int check_required)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params params;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " params.override = override;"; + stream << "\n"; + stream << indent_str; + stream << " params.initialize = initialize;"; + stream << "\n"; + stream << indent_str; + stream << " params.check_required = check_required;"; + stream << "\n"; + stream << indent_str; + stream << " params.check_ambiguity = 0;"; + stream << "\n"; + stream << indent_str; + stream << " params.print_errors = 1;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " return "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string_ext(cmdline, args_info, prog_name, ¶ms);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "int"; + stream << "\n"; + stream << indent_str; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string_ext(const char *cmdline, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info, const char *prog_name,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char **argv_ptr = 0;"; + stream << "\n"; + stream << indent_str; + stream << " int result;"; + stream << "\n"; + stream << indent_str; + stream << " unsigned int argc;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " argc = "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_create_argv(cmdline, &argv_ptr, prog_name);"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " result ="; + stream << "\n"; + stream << indent_str; + indent = 4; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_internal (argc, argv_ptr, args_info, params, 0);"; + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " if (argv_ptr)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " free (argv_ptr);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " free_cmd_list();"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (final_exit, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/c_source.h b/cmake/gengetopt/skels/c_source.h new file mode 100644 index 0000000..abeb115 --- /dev/null +++ b/cmake/gengetopt/skels/c_source.h @@ -0,0 +1,502 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef C_SOURCE_GEN_CLASS_H +#define C_SOURCE_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class c_source_gen_class +{ + protected: + string args_info; + string check_modes; + bool check_possible_values; + bool check_required_options; + string clear_arg; + bool cmd_list; + string command_line; + bool conf_parser; + string custom_getopt; + string description; + string detailed_help_option_print; + bool do_generate_strdup; + string file_save_loop; + string final_exit; + string free; + string full_help_option_print; + bool generate_string_parser; + string generator_version; + string getopt_string; + string given_init; + string handle_dependencies; + string handle_group; + string handle_no_short_option; + string handle_option; + bool handle_question_mark; + string handle_required; + bool handle_unamed; + bool has_arg_double; + bool has_arg_enum; + bool has_arg_flag; + bool has_arg_float; + bool has_arg_int; + bool has_arg_long; + bool has_arg_longdouble; + bool has_arg_longlong; + bool has_arg_short; + bool has_arg_string; + bool has_details; + bool has_hidden; + bool has_modes; + bool has_typed_options; + string header_file_ext; + string help_option_print; + string help_string_num; + bool include_getopt; + string init_args_info; + string list_def; + string list_free; + string long_option_struct; + string multiple_fill_array; + bool multiple_options; + bool multiple_options_all_string; + bool multiple_options_string; + bool multiple_options_with_default; + bool multiple_token_functions; + bool no_options; + bool no_package; + string option_values; + string package_var_name; + string parser_name; + string purpose; + string reset_groups; + string source_name; + string update_multiple_given; + string usage_string; + string version_var_name; + + public: + c_source_gen_class() : + check_possible_values (false), check_required_options (false), cmd_list (false), conf_parser (false), do_generate_strdup (false), generate_string_parser (false), handle_question_mark (false), handle_unamed (false), has_arg_double (false), has_arg_enum (false), has_arg_flag (false), has_arg_float (false), has_arg_int (false), has_arg_long (false), has_arg_longdouble (false), has_arg_longlong (false), has_arg_short (false), has_arg_string (false), has_details (false), has_hidden (false), has_modes (false), has_typed_options (false), include_getopt (false), multiple_options (false), multiple_options_all_string (false), multiple_options_string (false), multiple_options_with_default (false), multiple_token_functions (false), no_options (false), no_package (false) + { + } + + c_source_gen_class(const string &_args_info, const string &_check_modes, bool _check_possible_values, bool _check_required_options, const string &_clear_arg, bool _cmd_list, const string &_command_line, bool _conf_parser, const string &_custom_getopt, const string &_description, const string &_detailed_help_option_print, bool _do_generate_strdup, const string &_file_save_loop, const string &_final_exit, const string &_free, const string &_full_help_option_print, bool _generate_string_parser, const string &_generator_version, const string &_getopt_string, const string &_given_init, const string &_handle_dependencies, const string &_handle_group, const string &_handle_no_short_option, const string &_handle_option, bool _handle_question_mark, const string &_handle_required, bool _handle_unamed, bool _has_arg_double, bool _has_arg_enum, bool _has_arg_flag, bool _has_arg_float, bool _has_arg_int, bool _has_arg_long, bool _has_arg_longdouble, bool _has_arg_longlong, bool _has_arg_short, bool _has_arg_string, bool _has_details, bool _has_hidden, bool _has_modes, bool _has_typed_options, const string &_header_file_ext, const string &_help_option_print, const string &_help_string_num, bool _include_getopt, const string &_init_args_info, const string &_list_def, const string &_list_free, const string &_long_option_struct, const string &_multiple_fill_array, bool _multiple_options, bool _multiple_options_all_string, bool _multiple_options_string, bool _multiple_options_with_default, bool _multiple_token_functions, bool _no_options, bool _no_package, const string &_option_values, const string &_package_var_name, const string &_parser_name, const string &_purpose, const string &_reset_groups, const string &_source_name, const string &_update_multiple_given, const string &_usage_string, const string &_version_var_name) : + args_info (_args_info), check_modes (_check_modes), check_possible_values (_check_possible_values), check_required_options (_check_required_options), clear_arg (_clear_arg), cmd_list (_cmd_list), command_line (_command_line), conf_parser (_conf_parser), custom_getopt (_custom_getopt), description (_description), detailed_help_option_print (_detailed_help_option_print), do_generate_strdup (_do_generate_strdup), file_save_loop (_file_save_loop), final_exit (_final_exit), free (_free), full_help_option_print (_full_help_option_print), generate_string_parser (_generate_string_parser), generator_version (_generator_version), getopt_string (_getopt_string), given_init (_given_init), handle_dependencies (_handle_dependencies), handle_group (_handle_group), handle_no_short_option (_handle_no_short_option), handle_option (_handle_option), handle_question_mark (_handle_question_mark), handle_required (_handle_required), handle_unamed (_handle_unamed), has_arg_double (_has_arg_double), has_arg_enum (_has_arg_enum), has_arg_flag (_has_arg_flag), has_arg_float (_has_arg_float), has_arg_int (_has_arg_int), has_arg_long (_has_arg_long), has_arg_longdouble (_has_arg_longdouble), has_arg_longlong (_has_arg_longlong), has_arg_short (_has_arg_short), has_arg_string (_has_arg_string), has_details (_has_details), has_hidden (_has_hidden), has_modes (_has_modes), has_typed_options (_has_typed_options), header_file_ext (_header_file_ext), help_option_print (_help_option_print), help_string_num (_help_string_num), include_getopt (_include_getopt), init_args_info (_init_args_info), list_def (_list_def), list_free (_list_free), long_option_struct (_long_option_struct), multiple_fill_array (_multiple_fill_array), multiple_options (_multiple_options), multiple_options_all_string (_multiple_options_all_string), multiple_options_string (_multiple_options_string), multiple_options_with_default (_multiple_options_with_default), multiple_token_functions (_multiple_token_functions), no_options (_no_options), no_package (_no_package), option_values (_option_values), package_var_name (_package_var_name), parser_name (_parser_name), purpose (_purpose), reset_groups (_reset_groups), source_name (_source_name), update_multiple_given (_update_multiple_given), usage_string (_usage_string), version_var_name (_version_var_name) + { + } + + virtual ~c_source_gen_class() + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_args_info(const string &_args_info) + { + args_info = _args_info; + } + + virtual void generate_check_modes(ostream &stream, unsigned int indent) = 0; + + void set_check_modes(const string &_check_modes) + { + check_modes = _check_modes; + } + + void set_check_possible_values(bool _check_possible_values) + { + check_possible_values = _check_possible_values; + } + + void set_check_required_options(bool _check_required_options) + { + check_required_options = _check_required_options; + } + + virtual void generate_clear_arg(ostream &stream, unsigned int indent) = 0; + + void set_clear_arg(const string &_clear_arg) + { + clear_arg = _clear_arg; + } + + void set_cmd_list(bool _cmd_list) + { + cmd_list = _cmd_list; + } + + void set_command_line(const string &_command_line) + { + command_line = _command_line; + } + + void set_conf_parser(bool _conf_parser) + { + conf_parser = _conf_parser; + } + + virtual void generate_custom_getopt(ostream &stream, unsigned int indent) = 0; + + void set_custom_getopt(const string &_custom_getopt) + { + custom_getopt = _custom_getopt; + } + + void set_description(const string &_description) + { + description = _description; + } + + virtual void generate_detailed_help_option_print(ostream &stream, unsigned int indent) = 0; + + void set_detailed_help_option_print(const string &_detailed_help_option_print) + { + detailed_help_option_print = _detailed_help_option_print; + } + + void set_do_generate_strdup(bool _do_generate_strdup) + { + do_generate_strdup = _do_generate_strdup; + } + + virtual void generate_file_save_loop(ostream &stream, unsigned int indent) = 0; + + void set_file_save_loop(const string &_file_save_loop) + { + file_save_loop = _file_save_loop; + } + + void set_final_exit(const string &_final_exit) + { + final_exit = _final_exit; + } + + virtual void generate_free(ostream &stream, unsigned int indent) = 0; + + void set_free(const string &_free) + { + free = _free; + } + + virtual void generate_full_help_option_print(ostream &stream, unsigned int indent) = 0; + + void set_full_help_option_print(const string &_full_help_option_print) + { + full_help_option_print = _full_help_option_print; + } + + void set_generate_string_parser(bool _generate_string_parser) + { + generate_string_parser = _generate_string_parser; + } + + void set_generator_version(const string &_generator_version) + { + generator_version = _generator_version; + } + + void set_getopt_string(const string &_getopt_string) + { + getopt_string = _getopt_string; + } + + virtual void generate_given_init(ostream &stream, unsigned int indent) = 0; + + void set_given_init(const string &_given_init) + { + given_init = _given_init; + } + + virtual void generate_handle_dependencies(ostream &stream, unsigned int indent) = 0; + + void set_handle_dependencies(const string &_handle_dependencies) + { + handle_dependencies = _handle_dependencies; + } + + virtual void generate_handle_group(ostream &stream, unsigned int indent) = 0; + + void set_handle_group(const string &_handle_group) + { + handle_group = _handle_group; + } + + virtual void generate_handle_no_short_option(ostream &stream, unsigned int indent) = 0; + + void set_handle_no_short_option(const string &_handle_no_short_option) + { + handle_no_short_option = _handle_no_short_option; + } + + virtual void generate_handle_option(ostream &stream, unsigned int indent) = 0; + + void set_handle_option(const string &_handle_option) + { + handle_option = _handle_option; + } + + void set_handle_question_mark(bool _handle_question_mark) + { + handle_question_mark = _handle_question_mark; + } + + virtual void generate_handle_required(ostream &stream, unsigned int indent) = 0; + + void set_handle_required(const string &_handle_required) + { + handle_required = _handle_required; + } + + void set_handle_unamed(bool _handle_unamed) + { + handle_unamed = _handle_unamed; + } + + void set_has_arg_double(bool _has_arg_double) + { + has_arg_double = _has_arg_double; + } + + void set_has_arg_enum(bool _has_arg_enum) + { + has_arg_enum = _has_arg_enum; + } + + void set_has_arg_flag(bool _has_arg_flag) + { + has_arg_flag = _has_arg_flag; + } + + void set_has_arg_float(bool _has_arg_float) + { + has_arg_float = _has_arg_float; + } + + void set_has_arg_int(bool _has_arg_int) + { + has_arg_int = _has_arg_int; + } + + void set_has_arg_long(bool _has_arg_long) + { + has_arg_long = _has_arg_long; + } + + void set_has_arg_longdouble(bool _has_arg_longdouble) + { + has_arg_longdouble = _has_arg_longdouble; + } + + void set_has_arg_longlong(bool _has_arg_longlong) + { + has_arg_longlong = _has_arg_longlong; + } + + void set_has_arg_short(bool _has_arg_short) + { + has_arg_short = _has_arg_short; + } + + void set_has_arg_string(bool _has_arg_string) + { + has_arg_string = _has_arg_string; + } + + void set_has_details(bool _has_details) + { + has_details = _has_details; + } + + void set_has_hidden(bool _has_hidden) + { + has_hidden = _has_hidden; + } + + void set_has_modes(bool _has_modes) + { + has_modes = _has_modes; + } + + void set_has_typed_options(bool _has_typed_options) + { + has_typed_options = _has_typed_options; + } + + void set_header_file_ext(const string &_header_file_ext) + { + header_file_ext = _header_file_ext; + } + + virtual void generate_help_option_print(ostream &stream, unsigned int indent) = 0; + + void set_help_option_print(const string &_help_option_print) + { + help_option_print = _help_option_print; + } + + void set_help_string_num(const string &_help_string_num) + { + help_string_num = _help_string_num; + } + + void set_include_getopt(bool _include_getopt) + { + include_getopt = _include_getopt; + } + + virtual void generate_init_args_info(ostream &stream, unsigned int indent) = 0; + + void set_init_args_info(const string &_init_args_info) + { + init_args_info = _init_args_info; + } + + virtual void generate_list_def(ostream &stream, unsigned int indent) = 0; + + void set_list_def(const string &_list_def) + { + list_def = _list_def; + } + + virtual void generate_list_free(ostream &stream, unsigned int indent) = 0; + + void set_list_free(const string &_list_free) + { + list_free = _list_free; + } + + virtual void generate_long_option_struct(ostream &stream, unsigned int indent) = 0; + + void set_long_option_struct(const string &_long_option_struct) + { + long_option_struct = _long_option_struct; + } + + virtual void generate_multiple_fill_array(ostream &stream, unsigned int indent) = 0; + + void set_multiple_fill_array(const string &_multiple_fill_array) + { + multiple_fill_array = _multiple_fill_array; + } + + void set_multiple_options(bool _multiple_options) + { + multiple_options = _multiple_options; + } + + void set_multiple_options_all_string(bool _multiple_options_all_string) + { + multiple_options_all_string = _multiple_options_all_string; + } + + void set_multiple_options_string(bool _multiple_options_string) + { + multiple_options_string = _multiple_options_string; + } + + void set_multiple_options_with_default(bool _multiple_options_with_default) + { + multiple_options_with_default = _multiple_options_with_default; + } + + void set_multiple_token_functions(bool _multiple_token_functions) + { + multiple_token_functions = _multiple_token_functions; + } + + void set_no_options(bool _no_options) + { + no_options = _no_options; + } + + void set_no_package(bool _no_package) + { + no_package = _no_package; + } + + virtual void generate_option_values(ostream &stream, unsigned int indent) = 0; + + void set_option_values(const string &_option_values) + { + option_values = _option_values; + } + + void set_package_var_name(const string &_package_var_name) + { + package_var_name = _package_var_name; + } + + void set_parser_name(const string &_parser_name) + { + parser_name = _parser_name; + } + + void set_purpose(const string &_purpose) + { + purpose = _purpose; + } + + virtual void generate_reset_groups(ostream &stream, unsigned int indent) = 0; + + void set_reset_groups(const string &_reset_groups) + { + reset_groups = _reset_groups; + } + + void set_source_name(const string &_source_name) + { + source_name = _source_name; + } + + virtual void generate_update_multiple_given(ostream &stream, unsigned int indent) = 0; + + void set_update_multiple_given(const string &_update_multiple_given) + { + update_multiple_given = _update_multiple_given; + } + + void set_usage_string(const string &_usage_string) + { + usage_string = _usage_string; + } + + void set_version_var_name(const string &_version_var_name) + { + version_var_name = _version_var_name; + } + + void generate_c_source(ostream &stream, unsigned int indent = 0); + +}; + +#endif // C_SOURCE_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/check_modes.cc b/cmake/gengetopt/skels/check_modes.cc new file mode 100644 index 0000000..fd197cd --- /dev/null +++ b/cmake/gengetopt/skels/check_modes.cc @@ -0,0 +1,64 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "check_modes.h" + +void +check_modes_gen_class::generate_check_modes(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "if (args_info->"; + generate_string (mode1_name, stream, indent + indent_str.length ()); + stream << "_mode_counter && args_info->"; + generate_string (mode2_name, stream, indent + indent_str.length ()); + stream << "_mode_counter) {"; + stream << "\n"; + stream << indent_str; + stream << " int "; + generate_string (mode1_name, stream, indent + indent_str.length ()); + stream << "_given[] = {"; + generate_string (mode1_given_fields, stream, indent + indent_str.length ()); + stream << " -1};"; + stream << "\n"; + stream << indent_str; + stream << " const char *"; + generate_string (mode1_name, stream, indent + indent_str.length ()); + stream << "_desc[] = {"; + generate_string (mode1_options, stream, indent + indent_str.length ()); + stream << " 0};"; + stream << "\n"; + stream << indent_str; + stream << " int "; + generate_string (mode2_name, stream, indent + indent_str.length ()); + stream << "_given[] = {"; + generate_string (mode2_given_fields, stream, indent + indent_str.length ()); + stream << " -1};"; + stream << "\n"; + stream << indent_str; + stream << " const char *"; + generate_string (mode2_name, stream, indent + indent_str.length ()); + stream << "_desc[] = {"; + generate_string (mode2_options, stream, indent + indent_str.length ()); + stream << " 0};"; + stream << "\n"; + stream << indent_str; + stream << " error += check_modes("; + generate_string (mode1_name, stream, indent + indent_str.length ()); + stream << "_given, "; + generate_string (mode1_name, stream, indent + indent_str.length ()); + stream << "_desc, "; + generate_string (mode2_name, stream, indent + indent_str.length ()); + stream << "_given, "; + generate_string (mode2_name, stream, indent + indent_str.length ()); + stream << "_desc);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/check_modes.h b/cmake/gengetopt/skels/check_modes.h new file mode 100644 index 0000000..1ac5449 --- /dev/null +++ b/cmake/gengetopt/skels/check_modes.h @@ -0,0 +1,93 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef CHECK_MODES_GEN_CLASS_H +#define CHECK_MODES_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class check_modes_gen_class +{ + protected: + string mode1_given_fields; + string mode1_name; + string mode1_options; + string mode2_given_fields; + string mode2_name; + string mode2_options; + + public: + check_modes_gen_class() + { + } + + check_modes_gen_class(const string &_mode1_given_fields, const string &_mode1_name, const string &_mode1_options, const string &_mode2_given_fields, const string &_mode2_name, const string &_mode2_options) : + mode1_given_fields (_mode1_given_fields), mode1_name (_mode1_name), mode1_options (_mode1_options), mode2_given_fields (_mode2_given_fields), mode2_name (_mode2_name), mode2_options (_mode2_options) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_mode1_given_fields(const string &_mode1_given_fields) + { + mode1_given_fields = _mode1_given_fields; + } + + void set_mode1_name(const string &_mode1_name) + { + mode1_name = _mode1_name; + } + + void set_mode1_options(const string &_mode1_options) + { + mode1_options = _mode1_options; + } + + void set_mode2_given_fields(const string &_mode2_given_fields) + { + mode2_given_fields = _mode2_given_fields; + } + + void set_mode2_name(const string &_mode2_name) + { + mode2_name = _mode2_name; + } + + void set_mode2_options(const string &_mode2_options) + { + mode2_options = _mode2_options; + } + + void generate_check_modes(ostream &stream, unsigned int indent = 0); + +}; + +#endif // CHECK_MODES_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/clear_arg.cc b/cmake/gengetopt/skels/clear_arg.cc new file mode 100644 index 0000000..43324d3 --- /dev/null +++ b/cmake/gengetopt/skels/clear_arg.cc @@ -0,0 +1,35 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "clear_arg.h" + +void +clear_arg_gen_class::generate_clear_arg(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (has_arg) + { + stream << "args_info->"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_"; + generate_string (suffix, stream, indent + indent_str.length ()); + stream << " = "; + generate_string (value, stream, indent + indent_str.length ()); + stream << ";"; + stream << "\n"; + stream << indent_str; + } + if (has_orig) + { + stream << "args_info->"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_orig = NULL;"; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/clear_arg.h b/cmake/gengetopt/skels/clear_arg.h new file mode 100644 index 0000000..bf4bb14 --- /dev/null +++ b/cmake/gengetopt/skels/clear_arg.h @@ -0,0 +1,88 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef CLEAR_ARG_GEN_CLASS_H +#define CLEAR_ARG_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class clear_arg_gen_class +{ + protected: + bool has_arg; + bool has_orig; + string name; + string suffix; + string value; + + public: + clear_arg_gen_class() : + has_arg (false), has_orig (false) + { + } + + clear_arg_gen_class(bool _has_arg, bool _has_orig, const string &_name, const string &_suffix, const string &_value) : + has_arg (_has_arg), has_orig (_has_orig), name (_name), suffix (_suffix), value (_value) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_has_arg(bool _has_arg) + { + has_arg = _has_arg; + } + + void set_has_orig(bool _has_orig) + { + has_orig = _has_orig; + } + + void set_name(const string &_name) + { + name = _name; + } + + void set_suffix(const string &_suffix) + { + suffix = _suffix; + } + + void set_value(const string &_value) + { + value = _value; + } + + void generate_clear_arg(ostream &stream, unsigned int indent = 0); + +}; + +#endif // CLEAR_ARG_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/clear_given.cc b/cmake/gengetopt/skels/clear_given.cc new file mode 100644 index 0000000..3e15732 --- /dev/null +++ b/cmake/gengetopt/skels/clear_given.cc @@ -0,0 +1,30 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "clear_given.h" + +void +clear_given_gen_class::generate_clear_given(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + generate_string (arg_struct, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << "_given = 0 ;"; + if (group) + { + indent = 1; + stream << " "; + generate_string (arg_struct, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << "_group = 0 ;"; + } + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/clear_given.h b/cmake/gengetopt/skels/clear_given.h new file mode 100644 index 0000000..6853b25 --- /dev/null +++ b/cmake/gengetopt/skels/clear_given.h @@ -0,0 +1,76 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef CLEAR_GIVEN_GEN_CLASS_H +#define CLEAR_GIVEN_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class clear_given_gen_class +{ + protected: + string arg_struct; + bool group; + string var_arg; + + public: + clear_given_gen_class() : + group (false) + { + } + + clear_given_gen_class(const string &_arg_struct, bool _group, const string &_var_arg) : + arg_struct (_arg_struct), group (_group), var_arg (_var_arg) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_arg_struct(const string &_arg_struct) + { + arg_struct = _arg_struct; + } + + void set_group(bool _group) + { + group = _group; + } + + void set_var_arg(const string &_var_arg) + { + var_arg = _var_arg; + } + + void generate_clear_given(ostream &stream, unsigned int indent = 0); + +}; + +#endif // CLEAR_GIVEN_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/copyright.cc b/cmake/gengetopt/skels/copyright.cc new file mode 100644 index 0000000..f0f726b --- /dev/null +++ b/cmake/gengetopt/skels/copyright.cc @@ -0,0 +1,35 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "copyright.h" + +void +copyright_gen_class::generate_copyright(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "Copyright (C) "; + generate_string (year, stream, indent + indent_str.length ()); + stream << " Free Software Foundation Inc."; + stream << "\n"; + stream << indent_str; + stream << "This program comes with ABSOLUTELY NO WARRANTY; for details"; + stream << "\n"; + stream << indent_str; + stream << "please see the file 'COPYING' supplied with the source code."; + stream << "\n"; + stream << indent_str; + stream << "This is free software, and you are welcome to redistribute it"; + stream << "\n"; + stream << indent_str; + stream << "under certain conditions; again, see 'COPYING' for details."; + stream << "\n"; + stream << indent_str; + stream << "This program is released under the GNU General Public License."; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/copyright.h b/cmake/gengetopt/skels/copyright.h new file mode 100644 index 0000000..3b07bc8 --- /dev/null +++ b/cmake/gengetopt/skels/copyright.h @@ -0,0 +1,63 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef COPYRIGHT_GEN_CLASS_H +#define COPYRIGHT_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class copyright_gen_class +{ + protected: + string year; + + public: + copyright_gen_class() + { + } + + copyright_gen_class(const string &_year) : + year (_year) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_year(const string &_year) + { + year = _year; + } + + void generate_copyright(ostream &stream, unsigned int indent = 0); + +}; + +#endif // COPYRIGHT_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/custom_getopt_gen.cc b/cmake/gengetopt/skels/custom_getopt_gen.cc new file mode 100644 index 0000000..d0ff3ff --- /dev/null +++ b/cmake/gengetopt/skels/custom_getopt_gen.cc @@ -0,0 +1,1750 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "custom_getopt_gen.h" + +void +custom_getopt_gen_gen_class::generate_custom_getopt_gen(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Extracted from the glibc source tree, version 2.3.6"; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Licensed under the GPL as per the whole glibc source tree."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * This file was modified so that getopt_long can be called"; + stream << "\n"; + stream << indent_str; + stream << " * many times without risking previous memory to be spoiled."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Modified by Andre Noll and Lorenzo Bettini for use in"; + stream << "\n"; + stream << indent_str; + stream << " * GNU gengetopt generated files."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* "; + stream << "\n"; + stream << indent_str; + stream << " * we must include anything we need since this file is not thought to be"; + stream << "\n"; + stream << indent_str; + stream << " * inserted in a file already using getopt.h"; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Lorenzo"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "struct option"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " const char *name;"; + stream << "\n"; + stream << indent_str; + stream << " /* has_arg can't be an enum because some compilers complain about"; + stream << "\n"; + stream << indent_str; + stream << " type mismatches in all the code that assumes it is an int. */"; + stream << "\n"; + stream << indent_str; + stream << " int has_arg;"; + stream << "\n"; + stream << indent_str; + stream << " int *flag;"; + stream << "\n"; + stream << indent_str; + stream << " int val;"; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* This version of `getopt' appears to the caller like standard Unix `getopt'"; + stream << "\n"; + stream << indent_str; + stream << " but it behaves differently for the user, since it allows the user"; + stream << "\n"; + stream << indent_str; + stream << " to intersperse the options with the other arguments."; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " As `getopt' works, it permutes the elements of ARGV so that,"; + stream << "\n"; + stream << indent_str; + stream << " when it is done, all the options precede everything else. Thus"; + stream << "\n"; + stream << indent_str; + stream << " all application programs are extended to handle flexible argument order."; + stream << "\n"; + stream << indent_str; + stream << "*/"; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " If the field `flag' is not NULL, it points to a variable that is set"; + stream << "\n"; + stream << indent_str; + stream << " to the value given in the field `val' when the option is found, but"; + stream << "\n"; + stream << indent_str; + stream << " left unchanged if the option is not found."; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " To have a long-named option do something other than set an `int' to"; + stream << "\n"; + stream << indent_str; + stream << " a compiled-in constant, such as set a value from `custom_optarg', set the"; + stream << "\n"; + stream << indent_str; + stream << " option's `flag' field to zero and its `val' field to a nonzero"; + stream << "\n"; + stream << indent_str; + stream << " value (the equivalent single-letter option character, if there is"; + stream << "\n"; + stream << indent_str; + stream << " one). For long options that have a zero `flag' field, `getopt'"; + stream << "\n"; + stream << indent_str; + stream << " returns the contents of the `val' field. */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* Names for the values of the `has_arg' field of `struct option'. */"; + stream << "\n"; + stream << indent_str; + stream << "#ifndef no_argument"; + stream << "\n"; + stream << indent_str; + stream << "#define no_argument 0"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef required_argument"; + stream << "\n"; + stream << indent_str; + stream << "#define required_argument 1"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef optional_argument"; + stream << "\n"; + stream << indent_str; + stream << "#define optional_argument 2"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "struct custom_getopt_data {"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * These have exactly the same meaning as the corresponding global variables,"; + stream << "\n"; + stream << indent_str; + stream << " * except that they are used for the reentrant versions of getopt."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " int custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " int custom_opterr;"; + stream << "\n"; + stream << indent_str; + stream << " int custom_optopt;"; + stream << "\n"; + stream << indent_str; + stream << " char *custom_optarg;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* True if the internal members have been initialized. */"; + stream << "\n"; + stream << indent_str; + stream << " int initialized;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * The next char to be scanned in the option-element in which the last option"; + stream << "\n"; + stream << indent_str; + stream << " * character we returned was found. This allows us to pick up the scan where"; + stream << "\n"; + stream << indent_str; + stream << " * we left off. If this is zero, or a null string, it means resume the scan by"; + stream << "\n"; + stream << indent_str; + stream << " * advancing to the next ARGV-element."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " char *nextchar;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Describe the part of ARGV that contains non-options that have been skipped."; + stream << "\n"; + stream << indent_str; + stream << " * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is"; + stream << "\n"; + stream << indent_str; + stream << " * the index after the last of them."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " int first_nonopt;"; + stream << "\n"; + stream << indent_str; + stream << " int last_nonopt;"; + stream << "\n"; + stream << indent_str; + stream << "};"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * the variables optarg, optind, opterr and optopt are renamed with"; + stream << "\n"; + stream << indent_str; + stream << " * the custom_ prefix so that they don't interfere with getopt ones."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Moreover they're static so they are visible only from within the"; + stream << "\n"; + stream << indent_str; + stream << " * file where this very file will be included."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an"; + stream << "\n"; + stream << indent_str; + stream << " * option that takes an argument, the argument value is returned here."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static char *custom_optarg;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Index in ARGV of the next element to be scanned. This is used for"; + stream << "\n"; + stream << indent_str; + stream << " * communication to and from the caller and for communication between"; + stream << "\n"; + stream << indent_str; + stream << " * successive calls to `custom_getopt'."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * On entry to `custom_getopt', 1 means this is the first call; initialize."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * When `custom_getopt' returns -1, this is the index of the first of the non-option"; + stream << "\n"; + stream << indent_str; + stream << " * elements that the caller should itself scan."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV"; + stream << "\n"; + stream << indent_str; + stream << " * has been scanned so far."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * 1003.2 says this must be 1 before any call."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static int custom_optind = 1;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Callers store zero here to inhibit the error message for unrecognized"; + stream << "\n"; + stream << indent_str; + stream << " * options."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static int custom_opterr = 1;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Set to an option character which was unrecognized. This must be initialized"; + stream << "\n"; + stream << indent_str; + stream << " * on some systems to avoid linking in the system's own getopt implementation."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static int custom_optopt = '?';"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Exchange two adjacent subsequences of ARGV. One subsequence is elements"; + stream << "\n"; + stream << indent_str; + stream << " * [first_nonopt,last_nonopt) which contains all the non-options that have been"; + stream << "\n"; + stream << indent_str; + stream << " * skipped so far. The other is elements [last_nonopt,custom_optind), which contains"; + stream << "\n"; + stream << indent_str; + stream << " * all the options processed since those non-options were skipped."; + stream << "\n"; + stream << indent_str; + stream << " * `first_nonopt' and `last_nonopt' are relocated so that they describe the new"; + stream << "\n"; + stream << indent_str; + stream << " * indices of the non-options in ARGV after they are moved."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static void exchange(char **argv, struct custom_getopt_data *d)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int bottom = d->first_nonopt;"; + stream << "\n"; + stream << indent_str; + stream << " int middle = d->last_nonopt;"; + stream << "\n"; + stream << indent_str; + stream << " int top = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " char *tem;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Exchange the shorter segment with the far end of the longer segment."; + stream << "\n"; + stream << indent_str; + stream << " * That puts the shorter segment into the right place. It leaves the"; + stream << "\n"; + stream << indent_str; + stream << " * longer segment in the right place overall, but it consists of two"; + stream << "\n"; + stream << indent_str; + stream << " * parts that need to be swapped next."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " while (top > middle && middle > bottom) {"; + stream << "\n"; + stream << indent_str; + stream << " if (top - middle > middle - bottom) {"; + stream << "\n"; + stream << indent_str; + stream << " /* Bottom segment is the short one. */"; + stream << "\n"; + stream << indent_str; + stream << " int len = middle - bottom;"; + stream << "\n"; + stream << indent_str; + stream << " int i;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* Swap it with the top part of the top segment. */"; + stream << "\n"; + stream << indent_str; + stream << " for (i = 0; i < len; i++) {"; + stream << "\n"; + stream << indent_str; + stream << " tem = argv[bottom + i];"; + stream << "\n"; + stream << indent_str; + stream << " argv[bottom + i] ="; + stream << "\n"; + stream << indent_str; + stream << " argv[top - (middle - bottom) + i];"; + stream << "\n"; + stream << indent_str; + stream << " argv[top - (middle - bottom) + i] = tem;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /* Exclude the moved bottom segment from further swapping. */"; + stream << "\n"; + stream << indent_str; + stream << " top -= len;"; + stream << "\n"; + stream << indent_str; + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " /* Top segment is the short one. */"; + stream << "\n"; + stream << indent_str; + stream << " int len = top - middle;"; + stream << "\n"; + stream << indent_str; + stream << " int i;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* Swap it with the bottom part of the bottom segment. */"; + stream << "\n"; + stream << indent_str; + stream << " for (i = 0; i < len; i++) {"; + stream << "\n"; + stream << indent_str; + stream << " tem = argv[bottom + i];"; + stream << "\n"; + stream << indent_str; + stream << " argv[bottom + i] = argv[middle + i];"; + stream << "\n"; + stream << indent_str; + stream << " argv[middle + i] = tem;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /* Exclude the moved top segment from further swapping. */"; + stream << "\n"; + stream << indent_str; + stream << " bottom += len;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /* Update records for the slots the non-options now occupy. */"; + stream << "\n"; + stream << indent_str; + stream << " d->first_nonopt += (d->custom_optind - d->last_nonopt);"; + stream << "\n"; + stream << indent_str; + stream << " d->last_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* Initialize the internal data when the first call is made. */"; + stream << "\n"; + stream << indent_str; + stream << "static void custom_getopt_initialize(struct custom_getopt_data *d)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Start processing options with ARGV-element 1 (since ARGV-element 0"; + stream << "\n"; + stream << indent_str; + stream << " * is the program name); the sequence of previously skipped non-option"; + stream << "\n"; + stream << indent_str; + stream << " * ARGV-elements is empty."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " d->first_nonopt = d->last_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar = NULL;"; + stream << "\n"; + stream << indent_str; + stream << " d->initialized = 1;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\\0')"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* return: zero: continue, nonzero: return given value to user */"; + stream << "\n"; + stream << indent_str; + stream << "static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,"; + stream << "\n"; + stream << indent_str; + stream << " struct custom_getopt_data *d)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been"; + stream << "\n"; + stream << indent_str; + stream << " * moved back by the user (who may also have changed the arguments)."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (d->last_nonopt > d->custom_optind)"; + stream << "\n"; + stream << indent_str; + stream << " d->last_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " if (d->first_nonopt > d->custom_optind)"; + stream << "\n"; + stream << indent_str; + stream << " d->first_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * If we have just processed some options following some"; + stream << "\n"; + stream << indent_str; + stream << " * non-options, exchange them so that the options come first."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (d->first_nonopt != d->last_nonopt &&"; + stream << "\n"; + stream << indent_str; + stream << " d->last_nonopt != d->custom_optind)"; + stream << "\n"; + stream << indent_str; + stream << " exchange((char **) argv, d);"; + stream << "\n"; + stream << indent_str; + stream << " else if (d->last_nonopt != d->custom_optind)"; + stream << "\n"; + stream << indent_str; + stream << " d->first_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Skip any additional non-options and extend the range of"; + stream << "\n"; + stream << indent_str; + stream << " * non-options previously skipped."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " while (d->custom_optind < argc && NONOPTION_P)"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " d->last_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * The special ARGV-element `--' means premature end of options. Skip"; + stream << "\n"; + stream << indent_str; + stream << " * it like a null option, then exchange with previous non-options as if"; + stream << "\n"; + stream << indent_str; + stream << " * it were an option, then skip everything else like a non-option."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], \"--\")) {"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " if (d->first_nonopt != d->last_nonopt"; + stream << "\n"; + stream << indent_str; + stream << " && d->last_nonopt != d->custom_optind)"; + stream << "\n"; + stream << indent_str; + stream << " exchange((char **) argv, d);"; + stream << "\n"; + stream << indent_str; + stream << " else if (d->first_nonopt == d->last_nonopt)"; + stream << "\n"; + stream << indent_str; + stream << " d->first_nonopt = d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " d->last_nonopt = argc;"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind = argc;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * If we have done all the ARGV-elements, stop the scan and back over"; + stream << "\n"; + stream << indent_str; + stream << " * any non-options that we skipped and permuted."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (d->custom_optind == argc) {"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Set the next-arg-index to point at the non-options that we"; + stream << "\n"; + stream << indent_str; + stream << " * previously skipped, so the caller will digest them."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (d->first_nonopt != d->last_nonopt)"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind = d->first_nonopt;"; + stream << "\n"; + stream << indent_str; + stream << " return -1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * If we have come to a non-option and did not permute it, either stop"; + stream << "\n"; + stream << indent_str; + stream << " * the scan or describe it to the caller and pass it by."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (NONOPTION_P) {"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = argv[d->custom_optind++];"; + stream << "\n"; + stream << indent_str; + stream << " return 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * We have found another option-ARGV-element. Skip the initial"; + stream << "\n"; + stream << indent_str; + stream << " * punctuation."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));"; + stream << "\n"; + stream << indent_str; + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Check whether the ARGV-element is a long option."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If there's a long option \"fubar\" and the ARGV-element is \"-fu\", consider"; + stream << "\n"; + stream << indent_str; + stream << " * that an abbreviation of the long option, just like \"--fu\", and not \"-f\" with"; + stream << "\n"; + stream << indent_str; + stream << " * arg \"u\"."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * This distinction seems to be the most useful approach."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "static int check_long_opt(int argc, char *const *argv, const char *optstring,"; + stream << "\n"; + stream << indent_str; + stream << " const struct option *longopts, int *longind,"; + stream << "\n"; + stream << indent_str; + stream << " int print_errors, struct custom_getopt_data *d)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char *nameend;"; + stream << "\n"; + stream << indent_str; + stream << " const struct option *p;"; + stream << "\n"; + stream << indent_str; + stream << " const struct option *pfound = NULL;"; + stream << "\n"; + stream << indent_str; + stream << " int exact = 0;"; + stream << "\n"; + stream << indent_str; + stream << " int ambig = 0;"; + stream << "\n"; + stream << indent_str; + stream << " int indfound = -1;"; + stream << "\n"; + stream << indent_str; + stream << " int option_index;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)"; + stream << "\n"; + stream << indent_str; + stream << " /* Do nothing. */ ;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* Test all long options for either exact match or abbreviated matches */"; + stream << "\n"; + stream << indent_str; + stream << " for (p = longopts, option_index = 0; p->name; p++, option_index++)"; + stream << "\n"; + stream << indent_str; + stream << " if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {"; + stream << "\n"; + stream << indent_str; + stream << " if ((unsigned int) (nameend - d->nextchar)"; + stream << "\n"; + stream << indent_str; + stream << " == (unsigned int) strlen(p->name)) {"; + stream << "\n"; + stream << indent_str; + stream << " /* Exact match found. */"; + stream << "\n"; + stream << indent_str; + stream << " pfound = p;"; + stream << "\n"; + stream << indent_str; + stream << " indfound = option_index;"; + stream << "\n"; + stream << indent_str; + stream << " exact = 1;"; + stream << "\n"; + stream << indent_str; + stream << " break;"; + stream << "\n"; + stream << indent_str; + stream << " } else if (pfound == NULL) {"; + stream << "\n"; + stream << indent_str; + stream << " /* First nonexact match found. */"; + stream << "\n"; + stream << indent_str; + stream << " pfound = p;"; + stream << "\n"; + stream << indent_str; + stream << " indfound = option_index;"; + stream << "\n"; + stream << indent_str; + stream << " } else if (pfound->has_arg != p->has_arg"; + stream << "\n"; + stream << indent_str; + stream << " || pfound->flag != p->flag"; + stream << "\n"; + stream << indent_str; + stream << " || pfound->val != p->val)"; + stream << "\n"; + stream << indent_str; + stream << " /* Second or later nonexact match found. */"; + stream << "\n"; + stream << indent_str; + stream << " ambig = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (ambig && !exact) {"; + stream << "\n"; + stream << indent_str; + stream << " if (print_errors) {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s: option `%s' is ambiguous\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0], argv[d->custom_optind]);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar += strlen(d->nextchar);"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optopt = 0;"; + stream << "\n"; + stream << indent_str; + stream << " return '?';"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (pfound) {"; + stream << "\n"; + stream << indent_str; + stream << " option_index = indfound;"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " if (*nameend) {"; + stream << "\n"; + stream << indent_str; + stream << " if (pfound->has_arg != no_argument)"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = nameend + 1;"; + stream << "\n"; + stream << indent_str; + stream << " else {"; + stream << "\n"; + stream << indent_str; + stream << " if (print_errors) {"; + stream << "\n"; + stream << indent_str; + stream << " if (argv[d->custom_optind - 1][1] == '-') {"; + stream << "\n"; + stream << indent_str; + stream << " /* --option */"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr, \"%s: option `--%s' doesn't allow an argument\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0], pfound->name);"; + stream << "\n"; + stream << indent_str; + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " /* +option or -option */"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr, \"%s: option `%c%s' doesn't allow an argument\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0], argv[d->custom_optind - 1][0], pfound->name);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar += strlen(d->nextchar);"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optopt = pfound->val;"; + stream << "\n"; + stream << indent_str; + stream << " return '?';"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " } else if (pfound->has_arg == required_argument) {"; + stream << "\n"; + stream << indent_str; + stream << " if (d->custom_optind < argc)"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = argv[d->custom_optind++];"; + stream << "\n"; + stream << indent_str; + stream << " else {"; + stream << "\n"; + stream << indent_str; + stream << " if (print_errors) {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s: option `%s' requires an argument\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0],"; + stream << "\n"; + stream << indent_str; + stream << " argv[d->custom_optind - 1]);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar += strlen(d->nextchar);"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optopt = pfound->val;"; + stream << "\n"; + stream << indent_str; + stream << " return optstring[0] == ':' ? ':' : '?';"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar += strlen(d->nextchar);"; + stream << "\n"; + stream << indent_str; + stream << " if (longind != NULL)"; + stream << "\n"; + stream << indent_str; + stream << " *longind = option_index;"; + stream << "\n"; + stream << indent_str; + stream << " if (pfound->flag) {"; + stream << "\n"; + stream << indent_str; + stream << " *(pfound->flag) = pfound->val;"; + stream << "\n"; + stream << indent_str; + stream << " return 0;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " return pfound->val;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * Can't find it as a long option. If this is not getopt_long_only, or"; + stream << "\n"; + stream << indent_str; + stream << " * the option starts with '--' or is not a valid short option, then"; + stream << "\n"; + stream << indent_str; + stream << " * it's an error. Otherwise interpret it as a short option."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (print_errors) {"; + stream << "\n"; + stream << indent_str; + stream << " if (argv[d->custom_optind][1] == '-') {"; + stream << "\n"; + stream << indent_str; + stream << " /* --option */"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s: unrecognized option `--%s'\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0], d->nextchar);"; + stream << "\n"; + stream << indent_str; + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " /* +option or -option */"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s: unrecognized option `%c%s'\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0], argv[d->custom_optind][0],"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar = (char *) \"\";"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optopt = 0;"; + stream << "\n"; + stream << indent_str; + stream << " return '?';"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static int check_short_opt(int argc, char *const *argv, const char *optstring,"; + stream << "\n"; + stream << indent_str; + stream << " int print_errors, struct custom_getopt_data *d)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " char c = *d->nextchar++;"; + stream << "\n"; + stream << indent_str; + stream << " const char *temp = strchr(optstring, c);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* Increment `custom_optind' when we start to process its last character. */"; + stream << "\n"; + stream << indent_str; + stream << " if (*d->nextchar == '\\0')"; + stream << "\n"; + stream << indent_str; + stream << " ++d->custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " if (!temp || c == ':') {"; + stream << "\n"; + stream << indent_str; + stream << " if (print_errors)"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr, \"%s: invalid option -- %c\\n\", argv[0], c);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optopt = c;"; + stream << "\n"; + stream << indent_str; + stream << " return '?';"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (temp[1] == ':') {"; + stream << "\n"; + stream << indent_str; + stream << " if (temp[2] == ':') {"; + stream << "\n"; + stream << indent_str; + stream << " /* This is an option that accepts an argument optionally. */"; + stream << "\n"; + stream << indent_str; + stream << " if (*d->nextchar != '\\0') {"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = d->nextchar;"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " } else"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = NULL;"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar = NULL;"; + stream << "\n"; + stream << indent_str; + stream << " } else {"; + stream << "\n"; + stream << indent_str; + stream << " /* This is an option that requires an argument. */"; + stream << "\n"; + stream << indent_str; + stream << " if (*d->nextchar != '\\0') {"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = d->nextchar;"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * If we end this ARGV-element by taking the"; + stream << "\n"; + stream << indent_str; + stream << " * rest as an arg, we must advance to the next"; + stream << "\n"; + stream << indent_str; + stream << " * element now."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind++;"; + stream << "\n"; + stream << indent_str; + stream << " } else if (d->custom_optind == argc) {"; + stream << "\n"; + stream << indent_str; + stream << " if (print_errors) {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf(stderr,"; + stream << "\n"; + stream << indent_str; + stream << " \"%s: option requires an argument -- %c\\n\","; + stream << "\n"; + stream << indent_str; + stream << " argv[0], c);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optopt = c;"; + stream << "\n"; + stream << indent_str; + stream << " if (optstring[0] == ':')"; + stream << "\n"; + stream << indent_str; + stream << " c = ':';"; + stream << "\n"; + stream << indent_str; + stream << " else"; + stream << "\n"; + stream << indent_str; + stream << " c = '?';"; + stream << "\n"; + stream << indent_str; + stream << " } else"; + stream << "\n"; + stream << indent_str; + stream << " /*"; + stream << "\n"; + stream << indent_str; + stream << " * We already incremented `custom_optind' once;"; + stream << "\n"; + stream << indent_str; + stream << " * increment it again when taking next ARGV-elt"; + stream << "\n"; + stream << indent_str; + stream << " * as argument."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = argv[d->custom_optind++];"; + stream << "\n"; + stream << indent_str; + stream << " d->nextchar = NULL;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " return c;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/*"; + stream << "\n"; + stream << indent_str; + stream << " * Scan elements of ARGV for option characters given in OPTSTRING."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If an element of ARGV starts with '-', and is not exactly \"-\" or \"--\","; + stream << "\n"; + stream << indent_str; + stream << " * then it is an option element. The characters of this element"; + stream << "\n"; + stream << indent_str; + stream << " * (aside from the initial '-') are option characters. If `getopt'"; + stream << "\n"; + stream << indent_str; + stream << " * is called repeatedly, it returns successively each of the option characters"; + stream << "\n"; + stream << indent_str; + stream << " * from each of the option elements."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If `getopt' finds another option character, it returns that character,"; + stream << "\n"; + stream << indent_str; + stream << " * updating `custom_optind' and `nextchar' so that the next call to `getopt' can"; + stream << "\n"; + stream << indent_str; + stream << " * resume the scan with the following option character or ARGV-element."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If there are no more option characters, `getopt' returns -1."; + stream << "\n"; + stream << indent_str; + stream << " * Then `custom_optind' is the index in ARGV of the first ARGV-element"; + stream << "\n"; + stream << indent_str; + stream << " * that is not an option. (The ARGV-elements have been permuted"; + stream << "\n"; + stream << indent_str; + stream << " * so that those that are not options now come last.)"; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * OPTSTRING is a string containing the legitimate option characters."; + stream << "\n"; + stream << indent_str; + stream << " * If an option character is seen that is not listed in OPTSTRING,"; + stream << "\n"; + stream << indent_str; + stream << " * return '?' after printing an error message. If you set `custom_opterr' to"; + stream << "\n"; + stream << indent_str; + stream << " * zero, the error message is suppressed but we still return '?'."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If a char in OPTSTRING is followed by a colon, that means it wants an arg,"; + stream << "\n"; + stream << indent_str; + stream << " * so the following text in the same ARGV-element, or the text of the following"; + stream << "\n"; + stream << indent_str; + stream << " * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that"; + stream << "\n"; + stream << indent_str; + stream << " * wants an optional arg; if there is text in the current ARGV-element,"; + stream << "\n"; + stream << indent_str; + stream << " * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If OPTSTRING starts with `-' or `+', it requests different methods of"; + stream << "\n"; + stream << indent_str; + stream << " * handling the non-option ARGV-elements."; + stream << "\n"; + stream << indent_str; + stream << " * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Long-named options begin with `--' instead of `-'."; + stream << "\n"; + stream << indent_str; + stream << " * Their names may be abbreviated as long as the abbreviation is unique"; + stream << "\n"; + stream << indent_str; + stream << " * or is an exact match for some defined option. If they have an"; + stream << "\n"; + stream << indent_str; + stream << " * argument, it follows the option name in the same ARGV-element, separated"; + stream << "\n"; + stream << indent_str; + stream << " * from the option name by a `=', or else the in next ARGV-element."; + stream << "\n"; + stream << indent_str; + stream << " * When `getopt' finds a long-named option, it returns 0 if that option's"; + stream << "\n"; + stream << indent_str; + stream << " * `flag' field is nonzero, the value of the option's `val' field"; + stream << "\n"; + stream << indent_str; + stream << " * if the `flag' field is zero."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * The elements of ARGV aren't really const, because we permute them."; + stream << "\n"; + stream << indent_str; + stream << " * But we pretend they're const in the prototype to be compatible"; + stream << "\n"; + stream << indent_str; + stream << " * with other systems."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * LONGOPTS is a vector of `struct option' terminated by an"; + stream << "\n"; + stream << indent_str; + stream << " * element containing a name which is zero."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * LONGIND returns the index in LONGOPT of the long-named option found."; + stream << "\n"; + stream << indent_str; + stream << " * It is only valid when a long-named option has been found by the most"; + stream << "\n"; + stream << indent_str; + stream << " * recent call."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * Return the option character from OPTS just read. Return -1 when there are"; + stream << "\n"; + stream << indent_str; + stream << " * no more options. For unrecognized options, or options missing arguments,"; + stream << "\n"; + stream << indent_str; + stream << " * `custom_optopt' is set to the option letter, and '?' is returned."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * The OPTS string is a list of characters which are recognized option letters,"; + stream << "\n"; + stream << indent_str; + stream << " * optionally followed by colons, specifying that that letter takes an"; + stream << "\n"; + stream << indent_str; + stream << " * argument, to be placed in `custom_optarg'."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * If a letter in OPTS is followed by two colons, its argument is optional."; + stream << "\n"; + stream << indent_str; + stream << " * This behavior is specific to the GNU `getopt'."; + stream << "\n"; + stream << indent_str; + stream << " *"; + stream << "\n"; + stream << indent_str; + stream << " * The argument `--' causes premature termination of argument scanning,"; + stream << "\n"; + stream << indent_str; + stream << " * explicitly telling `getopt' that there are no more options. If OPTS begins"; + stream << "\n"; + stream << indent_str; + stream << " * with `--', then non-option arguments are treated as arguments to the option"; + stream << "\n"; + stream << indent_str; + stream << " * '\\0'. This behavior is specific to the GNU `getopt'."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static int getopt_internal_r(int argc, char *const *argv, const char *optstring,"; + stream << "\n"; + stream << indent_str; + stream << " const struct option *longopts, int *longind,"; + stream << "\n"; + stream << indent_str; + stream << " struct custom_getopt_data *d)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int ret, print_errors = d->custom_opterr;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " if (optstring[0] == ':')"; + stream << "\n"; + stream << indent_str; + stream << " print_errors = 0;"; + stream << "\n"; + stream << indent_str; + stream << " if (argc < 1)"; + stream << "\n"; + stream << indent_str; + stream << " return -1;"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optarg = NULL;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " /* "; + stream << "\n"; + stream << indent_str; + stream << " * This is a big difference with GNU getopt, since optind == 0"; + stream << "\n"; + stream << indent_str; + stream << " * means initialization while here 1 means first call."; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << " if (d->custom_optind == 0 || !d->initialized) {"; + stream << "\n"; + stream << indent_str; + stream << " if (d->custom_optind == 0)"; + stream << "\n"; + stream << indent_str; + stream << " d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */"; + stream << "\n"; + stream << indent_str; + stream << " custom_getopt_initialize(d);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (d->nextchar == NULL || *d->nextchar == '\\0') {"; + stream << "\n"; + stream << indent_str; + stream << " ret = shuffle_argv(argc, argv, longopts, d);"; + stream << "\n"; + stream << indent_str; + stream << " if (ret)"; + stream << "\n"; + stream << indent_str; + stream << " return ret;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << " if (longopts && (argv[d->custom_optind][1] == '-' ))"; + stream << "\n"; + stream << indent_str; + stream << " return check_long_opt(argc, argv, optstring, longopts,"; + stream << "\n"; + stream << indent_str; + stream << " longind, print_errors, d);"; + stream << "\n"; + stream << indent_str; + stream << " return check_short_opt(argc, argv, optstring, print_errors, d);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,"; + stream << "\n"; + stream << indent_str; + stream << " const struct option *longopts, int *longind)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int result;"; + stream << "\n"; + stream << indent_str; + stream << " /* Keep a global copy of all internal members of d */"; + stream << "\n"; + stream << indent_str; + stream << " static struct custom_getopt_data d;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << " d.custom_optind = custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " d.custom_opterr = custom_opterr;"; + stream << "\n"; + stream << indent_str; + stream << " result = getopt_internal_r(argc, argv, optstring, longopts,"; + stream << "\n"; + stream << indent_str; + stream << " longind, &d);"; + stream << "\n"; + stream << indent_str; + stream << " custom_optind = d.custom_optind;"; + stream << "\n"; + stream << indent_str; + stream << " custom_optarg = d.custom_optarg;"; + stream << "\n"; + stream << indent_str; + stream << " custom_optopt = d.custom_optopt;"; + stream << "\n"; + stream << indent_str; + stream << " return result;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "static int custom_getopt_long (int argc, char *const *argv, const char *options,"; + stream << "\n"; + stream << indent_str; + stream << " const struct option *long_options, int *opt_index)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " return custom_getopt_internal(argc, argv, options, long_options,"; + stream << "\n"; + stream << indent_str; + stream << " opt_index);"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/custom_getopt_gen.h b/cmake/gengetopt/skels/custom_getopt_gen.h new file mode 100644 index 0000000..0f24834 --- /dev/null +++ b/cmake/gengetopt/skels/custom_getopt_gen.h @@ -0,0 +1,30 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef CUSTOM_GETOPT_GEN_GEN_CLASS_H +#define CUSTOM_GETOPT_GEN_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class custom_getopt_gen_gen_class +{ + protected: + + public: + custom_getopt_gen_gen_class() + { + } + + + void generate_custom_getopt_gen(ostream &stream, unsigned int indent = 0); + +}; + +#endif // CUSTOM_GETOPT_GEN_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/dependant_option.cc b/cmake/gengetopt/skels/dependant_option.cc new file mode 100644 index 0000000..f9396a1 --- /dev/null +++ b/cmake/gengetopt/skels/dependant_option.cc @@ -0,0 +1,38 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "dependant_option.h" + +void +dependant_option_gen_class::generate_dependant_option(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "if (args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given && ! args_info->"; + generate_string (dep_option, stream, indent + indent_str.length ()); + stream << "_given)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: "; + generate_string (option_descr, stream, indent + indent_str.length ()); + stream << " option depends on option '"; + generate_string (dep_option_descr, stream, indent + indent_str.length ()); + stream << "'%s\\n\", "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; +} diff --git a/cmake/gengetopt/skels/dependant_option.h b/cmake/gengetopt/skels/dependant_option.h new file mode 100644 index 0000000..4a10656 --- /dev/null +++ b/cmake/gengetopt/skels/dependant_option.h @@ -0,0 +1,87 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef DEPENDANT_OPTION_GEN_CLASS_H +#define DEPENDANT_OPTION_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class dependant_option_gen_class +{ + protected: + string dep_option; + string dep_option_descr; + string option_descr; + string option_var_name; + string package_var_name; + + public: + dependant_option_gen_class() + { + } + + dependant_option_gen_class(const string &_dep_option, const string &_dep_option_descr, const string &_option_descr, const string &_option_var_name, const string &_package_var_name) : + dep_option (_dep_option), dep_option_descr (_dep_option_descr), option_descr (_option_descr), option_var_name (_option_var_name), package_var_name (_package_var_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_dep_option(const string &_dep_option) + { + dep_option = _dep_option; + } + + void set_dep_option_descr(const string &_dep_option_descr) + { + dep_option_descr = _dep_option_descr; + } + + void set_option_descr(const string &_option_descr) + { + option_descr = _option_descr; + } + + void set_option_var_name(const string &_option_var_name) + { + option_var_name = _option_var_name; + } + + void set_package_var_name(const string &_package_var_name) + { + package_var_name = _package_var_name; + } + + void generate_dependant_option(ostream &stream, unsigned int indent = 0); + +}; + +#endif // DEPENDANT_OPTION_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/enum_decl.cc b/cmake/gengetopt/skels/enum_decl.cc new file mode 100644 index 0000000..00c9408 --- /dev/null +++ b/cmake/gengetopt/skels/enum_decl.cc @@ -0,0 +1,24 @@ +/* + * File automatically generated by + * gengen 1.4.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "enum_decl.h" + +void +enum_decl_gen_class::generate_enum_decl(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "enum enum_"; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << " { "; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << "__NULL = -1"; + generate_string (enum_values, stream, indent + indent_str.length ()); + stream << " };"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/enum_decl.h b/cmake/gengetopt/skels/enum_decl.h new file mode 100644 index 0000000..566f296 --- /dev/null +++ b/cmake/gengetopt/skels/enum_decl.h @@ -0,0 +1,69 @@ +/* + * File automatically generated by + * gengen 1.4.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef ENUM_DECL_GEN_CLASS_H +#define ENUM_DECL_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class enum_decl_gen_class +{ + protected: + string enum_values; + string var_arg; + + public: + enum_decl_gen_class() + { + } + + enum_decl_gen_class(const string &_enum_values, const string &_var_arg) : + enum_values (_enum_values), var_arg (_var_arg) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_enum_values(const string &_enum_values) + { + enum_values = _enum_values; + } + + void set_var_arg(const string &_var_arg) + { + var_arg = _var_arg; + } + + void generate_enum_decl(ostream &stream, unsigned int indent = 0); + +}; + +#endif // ENUM_DECL_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/exit_failure.cc b/cmake/gengetopt/skels/exit_failure.cc new file mode 100644 index 0000000..705ea34 --- /dev/null +++ b/cmake/gengetopt/skels/exit_failure.cc @@ -0,0 +1,40 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "exit_failure.h" + +void +exit_failure_gen_class::generate_exit_failure(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (handle_error) + { + stream << "if (result == EXIT_FAILURE)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + indent = 4; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_free (args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " exit (EXIT_FAILURE);"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << "return result;"; +} diff --git a/cmake/gengetopt/skels/exit_failure.h b/cmake/gengetopt/skels/exit_failure.h new file mode 100644 index 0000000..42bf53c --- /dev/null +++ b/cmake/gengetopt/skels/exit_failure.h @@ -0,0 +1,70 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef EXIT_FAILURE_GEN_CLASS_H +#define EXIT_FAILURE_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class exit_failure_gen_class +{ + protected: + bool handle_error; + string parser_name; + + public: + exit_failure_gen_class() : + handle_error (false) + { + } + + exit_failure_gen_class(bool _handle_error, const string &_parser_name) : + handle_error (_handle_error), parser_name (_parser_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_handle_error(bool _handle_error) + { + handle_error = _handle_error; + } + + void set_parser_name(const string &_parser_name) + { + parser_name = _parser_name; + } + + void generate_exit_failure(ostream &stream, unsigned int indent = 0); + +}; + +#endif // EXIT_FAILURE_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/file_save.cc b/cmake/gengetopt/skels/file_save.cc new file mode 100644 index 0000000..44888e6 --- /dev/null +++ b/cmake/gengetopt/skels/file_save.cc @@ -0,0 +1,37 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "file_save.h" + +void +file_save_gen_class::generate_file_save(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "if (args_info->"; + generate_string (given, stream, indent + indent_str.length ()); + stream << ")"; + stream << "\n"; + stream << indent_str; + stream << " write_into_file(outfile, \""; + generate_string (opt_name, stream, indent + indent_str.length ()); + stream << "\", "; + if (( arg == "" )) + { + stream << "0, 0 "; + } + else + { + stream << "args_info->"; + generate_string (arg, stream, indent + indent_str.length ()); + stream << ", "; + generate_string (values, stream, indent + indent_str.length ()); + } + stream << ");"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/file_save.h b/cmake/gengetopt/skels/file_save.h new file mode 100644 index 0000000..81d59e6 --- /dev/null +++ b/cmake/gengetopt/skels/file_save.h @@ -0,0 +1,81 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef FILE_SAVE_GEN_CLASS_H +#define FILE_SAVE_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class file_save_gen_class +{ + protected: + string arg; + string given; + string opt_name; + string values; + + public: + file_save_gen_class() + { + } + + file_save_gen_class(const string &_arg, const string &_given, const string &_opt_name, const string &_values) : + arg (_arg), given (_given), opt_name (_opt_name), values (_values) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_arg(const string &_arg) + { + arg = _arg; + } + + void set_given(const string &_given) + { + given = _given; + } + + void set_opt_name(const string &_opt_name) + { + opt_name = _opt_name; + } + + void set_values(const string &_values) + { + values = _values; + } + + void generate_file_save(ostream &stream, unsigned int indent = 0); + +}; + +#endif // FILE_SAVE_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/file_save_multiple.cc b/cmake/gengetopt/skels/file_save_multiple.cc new file mode 100644 index 0000000..405be31 --- /dev/null +++ b/cmake/gengetopt/skels/file_save_multiple.cc @@ -0,0 +1,39 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "file_save_multiple.h" + +void +file_save_multiple_gen_class::generate_file_save_multiple(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (has_arg) + { + stream << "write_multiple_into_file(outfile, args_info->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_given, \""; + generate_string (opt_name, stream, indent + indent_str.length ()); + stream << "\", args_info->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_orig, "; + generate_string (values, stream, indent + indent_str.length ()); + stream << ");"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << "write_multiple_into_file(outfile, args_info->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_given, \""; + generate_string (opt_name, stream, indent + indent_str.length ()); + stream << "\", 0, 0);"; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/file_save_multiple.h b/cmake/gengetopt/skels/file_save_multiple.h new file mode 100644 index 0000000..36a8aba --- /dev/null +++ b/cmake/gengetopt/skels/file_save_multiple.h @@ -0,0 +1,82 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef FILE_SAVE_MULTIPLE_GEN_CLASS_H +#define FILE_SAVE_MULTIPLE_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class file_save_multiple_gen_class +{ + protected: + bool has_arg; + string opt_name; + string opt_var; + string values; + + public: + file_save_multiple_gen_class() : + has_arg (false) + { + } + + file_save_multiple_gen_class(bool _has_arg, const string &_opt_name, const string &_opt_var, const string &_values) : + has_arg (_has_arg), opt_name (_opt_name), opt_var (_opt_var), values (_values) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_has_arg(bool _has_arg) + { + has_arg = _has_arg; + } + + void set_opt_name(const string &_opt_name) + { + opt_name = _opt_name; + } + + void set_opt_var(const string &_opt_var) + { + opt_var = _opt_var; + } + + void set_values(const string &_values) + { + values = _values; + } + + void generate_file_save_multiple(ostream &stream, unsigned int indent = 0); + +}; + +#endif // FILE_SAVE_MULTIPLE_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/free_list.cc b/cmake/gengetopt/skels/free_list.cc new file mode 100644 index 0000000..fef4555 --- /dev/null +++ b/cmake/gengetopt/skels/free_list.cc @@ -0,0 +1,29 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "free_list.h" + +void +free_list_gen_class::generate_free_list(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "free_list ("; + generate_string (list_name, stream, indent + indent_str.length ()); + stream << "_list, "; + if (string_list) + { + stream << "1 "; + } + else + { + stream << "0 "; + } + stream << ");"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/free_list.h b/cmake/gengetopt/skels/free_list.h new file mode 100644 index 0000000..82f5159 --- /dev/null +++ b/cmake/gengetopt/skels/free_list.h @@ -0,0 +1,70 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef FREE_LIST_GEN_CLASS_H +#define FREE_LIST_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class free_list_gen_class +{ + protected: + string list_name; + bool string_list; + + public: + free_list_gen_class() : + string_list (false) + { + } + + free_list_gen_class(const string &_list_name, bool _string_list) : + list_name (_list_name), string_list (_string_list) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_list_name(const string &_list_name) + { + list_name = _list_name; + } + + void set_string_list(bool _string_list) + { + string_list = _string_list; + } + + void generate_free_list(ostream &stream, unsigned int indent = 0); + +}; + +#endif // FREE_LIST_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/free_multiple.cc b/cmake/gengetopt/skels/free_multiple.cc new file mode 100644 index 0000000..e9403b2 --- /dev/null +++ b/cmake/gengetopt/skels/free_multiple.cc @@ -0,0 +1,57 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "free_multiple.h" + +void +free_multiple_gen_class::generate_free_multiple(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (has_string_type) + { + stream << "free_multiple_string_field ("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_given, &("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_arg), &("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_orig));"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << "free_multiple_field ("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_given, (void *)("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_arg), &("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_orig));"; + stream << "\n"; + stream << indent_str; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_arg = 0;"; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/free_multiple.h b/cmake/gengetopt/skels/free_multiple.h new file mode 100644 index 0000000..64fe58c --- /dev/null +++ b/cmake/gengetopt/skels/free_multiple.h @@ -0,0 +1,76 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef FREE_MULTIPLE_GEN_CLASS_H +#define FREE_MULTIPLE_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class free_multiple_gen_class +{ + protected: + bool has_string_type; + string opt_var; + string structure; + + public: + free_multiple_gen_class() : + has_string_type (false) + { + } + + free_multiple_gen_class(bool _has_string_type, const string &_opt_var, const string &_structure) : + has_string_type (_has_string_type), opt_var (_opt_var), structure (_structure) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_has_string_type(bool _has_string_type) + { + has_string_type = _has_string_type; + } + + void set_opt_var(const string &_opt_var) + { + opt_var = _opt_var; + } + + void set_structure(const string &_structure) + { + structure = _structure; + } + + void generate_free_multiple(ostream &stream, unsigned int indent = 0); + +}; + +#endif // FREE_MULTIPLE_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/free_string.cc b/cmake/gengetopt/skels/free_string.cc new file mode 100644 index 0000000..6946f8f --- /dev/null +++ b/cmake/gengetopt/skels/free_string.cc @@ -0,0 +1,32 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "free_string.h" + +void +free_string_gen_class::generate_free_string(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (has_string_type) + { + stream << "free_string_field (&("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_arg));"; + stream << "\n"; + stream << indent_str; + } + stream << "free_string_field (&("; + generate_string (structure, stream, indent + indent_str.length ()); + stream << "->"; + generate_string (opt_var, stream, indent + indent_str.length ()); + stream << "_orig));"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/free_string.h b/cmake/gengetopt/skels/free_string.h new file mode 100644 index 0000000..7622617 --- /dev/null +++ b/cmake/gengetopt/skels/free_string.h @@ -0,0 +1,76 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef FREE_STRING_GEN_CLASS_H +#define FREE_STRING_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class free_string_gen_class +{ + protected: + bool has_string_type; + string opt_var; + string structure; + + public: + free_string_gen_class() : + has_string_type (false) + { + } + + free_string_gen_class(bool _has_string_type, const string &_opt_var, const string &_structure) : + has_string_type (_has_string_type), opt_var (_opt_var), structure (_structure) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_has_string_type(bool _has_string_type) + { + has_string_type = _has_string_type; + } + + void set_opt_var(const string &_opt_var) + { + opt_var = _opt_var; + } + + void set_structure(const string &_structure) + { + structure = _structure; + } + + void generate_free_string(ostream &stream, unsigned int indent = 0); + +}; + +#endif // FREE_STRING_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/generic_option.cc b/cmake/gengetopt/skels/generic_option.cc new file mode 100644 index 0000000..36166f7 --- /dev/null +++ b/cmake/gengetopt/skels/generic_option.cc @@ -0,0 +1,268 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "generic_option.h" + +void +generic_option_gen_class::generate_generic_option(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (has_short_option) + { + stream << "case '"; + generate_string (short_option, stream, indent + indent_str.length ()); + stream << "': /* "; + generate_string (option_comment, stream, indent + indent_str.length ()); + stream << ". */"; + stream << "\n"; + stream << indent_str; + if (( short_option == "?" )) + { + stream << "\n"; + stream << indent_str; + stream << " if (optopt) /* '?' represents an unrecognized option */"; + stream << "\n"; + stream << indent_str; + stream << " goto failure;"; + stream << "\n"; + stream << indent_str; + } + } + else + { + stream << "/* "; + generate_string (option_comment, stream, indent + indent_str.length ()); + stream << ". */"; + stream << "\n"; + stream << indent_str; + generate_string (gen_else, stream, indent + indent_str.length ()); + stream << "if (strcmp (long_options[option_index].name, \""; + generate_string (long_option, stream, indent + indent_str.length ()); + stream << "\") == 0)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + } + if (option_has_mode) + { + stream << " args_info->"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << "_mode_counter += 1;"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + if (multiple) + { + if (option_has_type) + { + stream << " if (update_multiple_arg_temp(&"; + generate_string (structure, stream, indent + indent_str.length ()); + stream << ", "; + stream << "\n"; + stream << indent_str; + stream << " &(local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given), optarg, "; + generate_string (possible_values, stream, indent + indent_str.length ()); + stream << ", "; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << ", "; + generate_string (arg_type, stream, indent + indent_str.length ()); + stream << ","; + stream << "\n"; + stream << indent_str; + stream << " \""; + generate_string (long_option, stream, indent + indent_str.length ()); + stream << "\", '"; + generate_string (short_option, stream, indent + indent_str.length ()); + stream << "',"; + stream << "\n"; + stream << indent_str; + stream << " additional_error))"; + stream << "\n"; + stream << indent_str; + stream << " goto failure;"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given++;"; + stream << "\n"; + stream << indent_str; + } + if (option_has_group) + { + stream << " if (!args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_group)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_group = 1;"; + stream << "\n"; + stream << indent_str; + stream << " args_info->"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << "_group_counter += 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + } + } + else + { + if (option_has_group) + { + stream << " if (args_info->"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << "_group_counter && override)"; + stream << "\n"; + stream << indent_str; + stream << " reset_group_"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << " (args_info);"; + stream << "\n"; + stream << indent_str; + stream << " args_info->"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << "_group_counter += 1;"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + if (( arg_type == "ARG_FLAG" )) + { + stream << " if (update_arg((void *)&(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_flag), 0, &(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given),"; + stream << "\n"; + stream << indent_str; + stream << " &(local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given), optarg, 0, 0, "; + generate_string (arg_type, stream, indent + indent_str.length ()); + stream << ","; + stream << "\n"; + stream << indent_str; + stream << " check_ambiguity, override, 1, 0, \""; + generate_string (long_option, stream, indent + indent_str.length ()); + stream << "\", '"; + generate_string (short_option, stream, indent + indent_str.length ()); + stream << "',"; + stream << "\n"; + stream << indent_str; + stream << " additional_error))"; + stream << "\n"; + stream << indent_str; + stream << " goto failure;"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << " if (update_arg("; + if (( arg_type == "ARG_NO" )) + { + stream << " 0 "; + } + else + { + stream << " (void *)&(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_arg)"; + } + stream << ", "; + stream << "\n"; + stream << indent_str; + indent = 6; + stream << " "; + if (( arg_type == "ARG_NO" )) + { + stream << " 0 "; + } + else + { + stream << " &(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_orig)"; + } + stream << ", &(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given),"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " &(local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given), optarg, "; + generate_string (possible_values, stream, indent + indent_str.length ()); + stream << ", "; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << ", "; + generate_string (arg_type, stream, indent + indent_str.length ()); + stream << ","; + stream << "\n"; + stream << indent_str; + stream << " check_ambiguity, override, 0, 0,"; + stream << "\n"; + stream << indent_str; + stream << " \""; + generate_string (long_option, stream, indent + indent_str.length ()); + stream << "\", '"; + generate_string (short_option, stream, indent + indent_str.length ()); + stream << "',"; + stream << "\n"; + stream << indent_str; + stream << " additional_error))"; + stream << "\n"; + stream << indent_str; + stream << " goto failure;"; + stream << "\n"; + stream << indent_str; + } + if (( final_instructions != "" )) + { + indent = 2; + stream << " "; + generate_string (final_instructions, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + } + } + if (has_short_option) + { + stream << "\n"; + stream << indent_str; + stream << " break;"; + } + else + { + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/generic_option.h b/cmake/gengetopt/skels/generic_option.h new file mode 100644 index 0000000..feeed55 --- /dev/null +++ b/cmake/gengetopt/skels/generic_option.h @@ -0,0 +1,154 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef GENERIC_OPTION_GEN_CLASS_H +#define GENERIC_OPTION_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class generic_option_gen_class +{ + protected: + string arg_type; + string default_value; + string final_instructions; + string gen_else; + string group_var_name; + bool has_short_option; + string long_option; + bool multiple; + string option_comment; + bool option_has_group; + bool option_has_mode; + bool option_has_type; + string option_var_name; + string possible_values; + string short_option; + string structure; + + public: + generic_option_gen_class() : + has_short_option (false), multiple (false), option_has_group (false), option_has_mode (false), option_has_type (false) + { + } + + generic_option_gen_class(const string &_arg_type, const string &_default_value, const string &_final_instructions, const string &_gen_else, const string &_group_var_name, bool _has_short_option, const string &_long_option, bool _multiple, const string &_option_comment, bool _option_has_group, bool _option_has_mode, bool _option_has_type, const string &_option_var_name, const string &_possible_values, const string &_short_option, const string &_structure) : + arg_type (_arg_type), default_value (_default_value), final_instructions (_final_instructions), gen_else (_gen_else), group_var_name (_group_var_name), has_short_option (_has_short_option), long_option (_long_option), multiple (_multiple), option_comment (_option_comment), option_has_group (_option_has_group), option_has_mode (_option_has_mode), option_has_type (_option_has_type), option_var_name (_option_var_name), possible_values (_possible_values), short_option (_short_option), structure (_structure) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_arg_type(const string &_arg_type) + { + arg_type = _arg_type; + } + + void set_default_value(const string &_default_value) + { + default_value = _default_value; + } + + void set_final_instructions(const string &_final_instructions) + { + final_instructions = _final_instructions; + } + + void set_gen_else(const string &_gen_else) + { + gen_else = _gen_else; + } + + void set_group_var_name(const string &_group_var_name) + { + group_var_name = _group_var_name; + } + + void set_has_short_option(bool _has_short_option) + { + has_short_option = _has_short_option; + } + + void set_long_option(const string &_long_option) + { + long_option = _long_option; + } + + void set_multiple(bool _multiple) + { + multiple = _multiple; + } + + void set_option_comment(const string &_option_comment) + { + option_comment = _option_comment; + } + + void set_option_has_group(bool _option_has_group) + { + option_has_group = _option_has_group; + } + + void set_option_has_mode(bool _option_has_mode) + { + option_has_mode = _option_has_mode; + } + + void set_option_has_type(bool _option_has_type) + { + option_has_type = _option_has_type; + } + + void set_option_var_name(const string &_option_var_name) + { + option_var_name = _option_var_name; + } + + void set_possible_values(const string &_possible_values) + { + possible_values = _possible_values; + } + + void set_short_option(const string &_short_option) + { + short_option = _short_option; + } + + void set_structure(const string &_structure) + { + structure = _structure; + } + + void generate_generic_option(ostream &stream, unsigned int indent = 0); + +}; + +#endif // GENERIC_OPTION_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/given_field.cc b/cmake/gengetopt/skels/given_field.cc new file mode 100644 index 0000000..d53b61b --- /dev/null +++ b/cmake/gengetopt/skels/given_field.cc @@ -0,0 +1,36 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "given_field.h" + +void +given_field_gen_class::generate_given_field(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "unsigned int "; + generate_string (arg_name, stream, indent + indent_str.length ()); + stream << "_given ; /**< "; + stream << "@"; + stream << "brief Whether "; + generate_string (long_opt, stream, indent + indent_str.length ()); + stream << " was given. */"; + stream << "\n"; + stream << indent_str; + if (group) + { + stream << " int "; + generate_string (arg_name, stream, indent + indent_str.length ()); + stream << "_group ; /**< "; + stream << "@"; + stream << "brief Whether "; + generate_string (long_opt, stream, indent + indent_str.length ()); + stream << "'s was updated. */"; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/given_field.h b/cmake/gengetopt/skels/given_field.h new file mode 100644 index 0000000..e964db6 --- /dev/null +++ b/cmake/gengetopt/skels/given_field.h @@ -0,0 +1,76 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef GIVEN_FIELD_GEN_CLASS_H +#define GIVEN_FIELD_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class given_field_gen_class +{ + protected: + string arg_name; + bool group; + string long_opt; + + public: + given_field_gen_class() : + group (false) + { + } + + given_field_gen_class(const string &_arg_name, bool _group, const string &_long_opt) : + arg_name (_arg_name), group (_group), long_opt (_long_opt) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_arg_name(const string &_arg_name) + { + arg_name = _arg_name; + } + + void set_group(bool _group) + { + group = _group; + } + + void set_long_opt(const string &_long_opt) + { + long_opt = _long_opt; + } + + void generate_given_field(ostream &stream, unsigned int indent = 0); + +}; + +#endif // GIVEN_FIELD_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/group_counter.cc b/cmake/gengetopt/skels/group_counter.cc new file mode 100644 index 0000000..4c42adb --- /dev/null +++ b/cmake/gengetopt/skels/group_counter.cc @@ -0,0 +1,26 @@ +/* + * File automatically generated by + * gengen 1.3 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "group_counter.h" + +void +group_counter_gen_class::generate_group_counter(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "int "; + generate_string (group_name, stream, indent + indent_str.length ()); + stream << "_"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_counter; /**< "; + stream << "@"; + stream << "brief Counter for "; + generate_string (name, stream, indent + indent_str.length ()); + stream << " "; + generate_string (group_name, stream, indent + indent_str.length ()); + stream << " */"; +} diff --git a/cmake/gengetopt/skels/group_counter.h b/cmake/gengetopt/skels/group_counter.h new file mode 100644 index 0000000..5cd8f8c --- /dev/null +++ b/cmake/gengetopt/skels/group_counter.h @@ -0,0 +1,69 @@ +/* + * File automatically generated by + * gengen 1.3 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef GROUP_COUNTER_GEN_CLASS_H +#define GROUP_COUNTER_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class group_counter_gen_class +{ + protected: + string group_name; + string name; + + public: + group_counter_gen_class() + { + } + + group_counter_gen_class(const string &_group_name, const string &_name) : + group_name (_group_name), name (_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_group_name(const string &_group_name) + { + group_name = _group_name; + } + + void set_name(const string &_name) + { + name = _name; + } + + void generate_group_counter(ostream &stream, unsigned int indent = 0); + +}; + +#endif // GROUP_COUNTER_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/group_option.cc b/cmake/gengetopt/skels/group_option.cc new file mode 100644 index 0000000..714aa01 --- /dev/null +++ b/cmake/gengetopt/skels/group_option.cc @@ -0,0 +1,42 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "group_option.h" + +void +group_option_gen_class::generate_group_option(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "if (args_info->"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << "_group_counter "; + generate_string (Comparison_rule, stream, indent + indent_str.length ()); + stream << ")"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: %d options of group "; + generate_string (group_name, stream, indent + indent_str.length ()); + stream << " were given. "; + generate_string (number_required, stream, indent + indent_str.length ()); + stream << " is required%s.\\n\", "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", args_info->"; + generate_string (group_var_name, stream, indent + indent_str.length ()); + stream << "_group_counter, (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/group_option.h b/cmake/gengetopt/skels/group_option.h new file mode 100644 index 0000000..2f0bd01 --- /dev/null +++ b/cmake/gengetopt/skels/group_option.h @@ -0,0 +1,87 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef GROUP_OPTION_GEN_CLASS_H +#define GROUP_OPTION_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class group_option_gen_class +{ + protected: + string Comparison_rule; + string group_name; + string group_var_name; + string number_required; + string package_var_name; + + public: + group_option_gen_class() + { + } + + group_option_gen_class(const string &_Comparison_rule, const string &_group_name, const string &_group_var_name, const string &_number_required, const string &_package_var_name) : + Comparison_rule (_Comparison_rule), group_name (_group_name), group_var_name (_group_var_name), number_required (_number_required), package_var_name (_package_var_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_Comparison_rule(const string &_Comparison_rule) + { + Comparison_rule = _Comparison_rule; + } + + void set_group_name(const string &_group_name) + { + group_name = _group_name; + } + + void set_group_var_name(const string &_group_var_name) + { + group_var_name = _group_var_name; + } + + void set_number_required(const string &_number_required) + { + number_required = _number_required; + } + + void set_package_var_name(const string &_package_var_name) + { + package_var_name = _package_var_name; + } + + void generate_group_option(ostream &stream, unsigned int indent = 0); + +}; + +#endif // GROUP_OPTION_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/handle_help.cc b/cmake/gengetopt/skels/handle_help.cc new file mode 100644 index 0000000..0f9d2cd --- /dev/null +++ b/cmake/gengetopt/skels/handle_help.cc @@ -0,0 +1,76 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "handle_help.h" + +void +handle_help_gen_class::generate_handle_help(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (detailed_help) + { + stream << "if (strcmp (long_options[option_index].name, \"detailed-help\") == 0) {"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_detailed_help ();"; + indent = 0; + stream << "\n"; + stream << indent_str; + } + else + { + if (full_help) + { + stream << "if (strcmp (long_options[option_index].name, \"full-help\") == 0) {"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_full_help ();"; + indent = 0; + stream << "\n"; + stream << indent_str; + } + else + { + if (short_opt) + { + stream << "case 'h': /* Print help and exit. */"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << "if (strcmp (long_options[option_index].name, \"help\") == 0) {"; + stream << "\n"; + stream << indent_str; + } + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_help ();"; + stream << "\n"; + stream << indent_str; + } + } + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_free (&local_args_info);"; + stream << "\n"; + stream << indent_str; + stream << " exit (EXIT_SUCCESS);"; + if (( full_help || ( ! short_opt ) )) + { + stream << "\n"; + stream << indent_str; + stream << "}"; + } +} diff --git a/cmake/gengetopt/skels/handle_help.h b/cmake/gengetopt/skels/handle_help.h new file mode 100644 index 0000000..1759c9f --- /dev/null +++ b/cmake/gengetopt/skels/handle_help.h @@ -0,0 +1,82 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef HANDLE_HELP_GEN_CLASS_H +#define HANDLE_HELP_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class handle_help_gen_class +{ + protected: + bool detailed_help; + bool full_help; + string parser_name; + bool short_opt; + + public: + handle_help_gen_class() : + detailed_help (false), full_help (false), short_opt (false) + { + } + + handle_help_gen_class(bool _detailed_help, bool _full_help, const string &_parser_name, bool _short_opt) : + detailed_help (_detailed_help), full_help (_full_help), parser_name (_parser_name), short_opt (_short_opt) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_detailed_help(bool _detailed_help) + { + detailed_help = _detailed_help; + } + + void set_full_help(bool _full_help) + { + full_help = _full_help; + } + + void set_parser_name(const string &_parser_name) + { + parser_name = _parser_name; + } + + void set_short_opt(bool _short_opt) + { + short_opt = _short_opt; + } + + void generate_handle_help(ostream &stream, unsigned int indent = 0); + +}; + +#endif // HANDLE_HELP_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/handle_version.cc b/cmake/gengetopt/skels/handle_version.cc new file mode 100644 index 0000000..1e61456 --- /dev/null +++ b/cmake/gengetopt/skels/handle_version.cc @@ -0,0 +1,46 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "handle_version.h" + +void +handle_version_gen_class::generate_handle_version(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (short_opt) + { + stream << "case 'V': /* Print version and exit. */"; + stream << "\n"; + stream << indent_str; + } + else + { + stream << "if (strcmp (long_options[option_index].name, \"version\") == 0) {"; + stream << "\n"; + stream << indent_str; + } + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_version ();"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_free (&local_args_info);"; + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " exit (EXIT_SUCCESS);"; + if (( ! short_opt )) + { + stream << "\n"; + stream << indent_str; + stream << "}"; + } +} diff --git a/cmake/gengetopt/skels/handle_version.h b/cmake/gengetopt/skels/handle_version.h new file mode 100644 index 0000000..c7b2e6d --- /dev/null +++ b/cmake/gengetopt/skels/handle_version.h @@ -0,0 +1,70 @@ +/* + * File automatically generated by + * gengen 1.4.1 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef HANDLE_VERSION_GEN_CLASS_H +#define HANDLE_VERSION_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class handle_version_gen_class +{ + protected: + string parser_name; + bool short_opt; + + public: + handle_version_gen_class() : + short_opt (false) + { + } + + handle_version_gen_class(const string &_parser_name, bool _short_opt) : + parser_name (_parser_name), short_opt (_short_opt) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_parser_name(const string &_parser_name) + { + parser_name = _parser_name; + } + + void set_short_opt(bool _short_opt) + { + short_opt = _short_opt; + } + + void generate_handle_version(ostream &stream, unsigned int indent = 0); + +}; + +#endif // HANDLE_VERSION_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/header.cc b/cmake/gengetopt/skels/header.cc new file mode 100644 index 0000000..92c3d52 --- /dev/null +++ b/cmake/gengetopt/skels/header.cc @@ -0,0 +1,1077 @@ +/* + * File automatically generated by + * gengen 1.4 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "header.h" + +void +header_gen_class::generate_header(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "/** "; + stream << "@"; + stream << "file "; + generate_string (header_file_name, stream, indent + indent_str.length ()); + stream << "."; + generate_string (header_file_ext, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "brief The header file for the command line option parser"; + stream << "\n"; + stream << indent_str; + stream << " * generated by GNU Gengetopt "; + generate_string (generator_version, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << " * http://www.gnu.org/software/gengetopt."; + stream << "\n"; + stream << indent_str; + stream << " * DO NOT modify this file, since it can be overwritten"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "author GNU Gengetopt by Lorenzo Bettini */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef "; + generate_string (ifndefname, stream, indent + indent_str.length ()); + stream << "_H"; + stream << "\n"; + stream << indent_str; + stream << "#define "; + generate_string (ifndefname, stream, indent + indent_str.length ()); + stream << "_H"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/* If we use autoconf. */"; + stream << "\n"; + stream << indent_str; + stream << "#ifdef HAVE_CONFIG_H"; + stream << "\n"; + stream << indent_str; + stream << "#include \"config.h\""; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#include /* for FILE */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifdef __cplusplus"; + stream << "\n"; + stream << indent_str; + stream << "extern \"C\" {"; + stream << "\n"; + stream << indent_str; + stream << "#endif /* __cplusplus */"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief the program name (used for printing errors) */"; + stream << "\n"; + stream << indent_str; + stream << "#define "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << " "; + generate_string (package_var_val, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "_NAME"; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief the complete program name (used for help and version) */"; + stream << "\n"; + stream << indent_str; + if (( package_var_val != "PACKAGE" )) + { + stream << "#define "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "_NAME "; + generate_string (package_var_val, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + } + else + { + stream << "#ifdef PACKAGE_NAME"; + stream << "\n"; + stream << indent_str; + stream << "#define "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "_NAME PACKAGE_NAME"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + stream << "#define "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << "_NAME PACKAGE"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + } + stream << "#endif"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifndef "; + generate_string (version_var_name, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief the program version */"; + stream << "\n"; + stream << indent_str; + stream << "#define "; + generate_string (version_var_name, stream, indent + indent_str.length ()); + stream << " "; + generate_string (version_var_val, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + if (enum_types.size () > 0) + generate_string (enum_types, stream, indent + indent_str.length ()); + else + generate_enum_types (stream, indent + indent_str.length ()); + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief Where the command line options are stored */"; + stream << "\n"; + stream << indent_str; + stream << "struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (option_arg.size () > 0) + generate_string (option_arg, stream, indent + indent_str.length ()); + else + generate_option_arg (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + if (option_given.size () > 0) + generate_string (option_given, stream, indent + indent_str.length ()); + else + generate_option_given (stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + if (group_counters.size () > 0) + generate_string (group_counters, stream, indent + indent_str.length ()); + else + generate_group_counters (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + indent = 2; + if (mode_counters.size () > 0) + generate_string (mode_counters, stream, indent + indent_str.length ()); + else + generate_mode_counters (stream, indent + indent_str.length ()); + indent = 0; + stream << indent_str; + stream << "} ;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief The additional parameters to pass to parser functions */"; + stream << "\n"; + stream << indent_str; + stream << "struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " int override; /**< "; + stream << "@"; + stream << "brief whether to override possibly already present options (default 0) */"; + stream << "\n"; + stream << indent_str; + stream << " int initialize; /**< "; + stream << "@"; + stream << "brief whether to initialize the option structure "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " (default 1) */"; + stream << "\n"; + stream << indent_str; + stream << " int check_required; /**< "; + stream << "@"; + stream << "brief whether to check that all required options were provided (default 1) */"; + stream << "\n"; + stream << indent_str; + stream << " int check_ambiguity; /**< "; + stream << "@"; + stream << "brief whether to check for options already specified in the option structure "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " (default 0) */"; + stream << "\n"; + stream << indent_str; + stream << " int print_errors; /**< "; + stream << "@"; + stream << "brief whether getopt_long should print an error message for a bad option (default 1) */"; + stream << "\n"; + stream << indent_str; + stream << "} ;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief the purpose string of the program */"; + stream << "\n"; + stream << indent_str; + stream << "extern const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_purpose;"; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief the usage string of the program */"; + stream << "\n"; + stream << indent_str; + stream << "extern const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_usage;"; + stream << "\n"; + stream << indent_str; + stream << "/** "; + stream << "@"; + stream << "brief all the lines making the help output */"; + stream << "\n"; + stream << indent_str; + stream << "extern const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_help[];"; + stream << "\n"; + stream << indent_str; + if (has_hidden) + { + stream << "/** "; + stream << "@"; + stream << "brief all the lines making the full help output (including hidden options) */"; + stream << "\n"; + stream << indent_str; + stream << "extern const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_full_help[];"; + stream << "\n"; + stream << indent_str; + } + if (has_details) + { + stream << "/** "; + stream << "@"; + stream << "brief all the lines making the detailed help output (including hidden options and details) */"; + stream << "\n"; + stream << indent_str; + stream << "extern const char *"; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << "_detailed_help[];"; + stream << "\n"; + stream << indent_str; + } + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The command line parser"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param argc the number of command line options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param argv the command line options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << " (int argc, char **argv,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The command line parser (version with additional parameters - deprecated)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param argc the number of command line options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param argv the command line options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param override whether to override possibly already present options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param initialize whether to initialize the option structure my_args_info"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param check_required whether to check that all required options were provided"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "deprecated use "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_ext() instead"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "2 (int argc, char **argv,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " int override, int initialize, int check_required);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The command line parser (version with additional parameters)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param argc the number of command line options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param argv the command line options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param params additional parameters for the parser"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_ext (int argc, char **argv,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Save the contents of the option struct into an already open FILE stream."; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param outfile the stream where to dump options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the option struct to dump"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_dump(FILE *outfile,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Save the contents of the option struct into a (text) file."; + stream << "\n"; + stream << indent_str; + stream << " * This file can be read by the config file parser (if generated by gengetopt)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param filename the file where to save"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the option struct to save"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_file_save(const char *filename,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Print the help"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_help(void);"; + stream << "\n"; + stream << indent_str; + if (has_hidden) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Print the full help (including hidden options)"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_full_help(void);"; + stream << "\n"; + stream << indent_str; + } + if (has_details) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Print the detailed help (including hidden options and details)"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_detailed_help(void);"; + stream << "\n"; + stream << indent_str; + } + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Print the version"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_print_version(void);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Initializes all the fields a "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params structure "; + stream << "\n"; + stream << indent_str; + stream << " * to their default values"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param params the structure to initialize"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params_init(struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Allocates dynamically a "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params structure and initializes"; + stream << "\n"; + stream << indent_str; + stream << " * all its fields to their default values"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return the created and initialized "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params structure"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *"; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params_create(void);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Initializes the passed "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " structure's fields"; + stream << "\n"; + stream << indent_str; + stream << " * (also set default values for options that have a default)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure to initialize"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_init (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Deallocates the string fields of the "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " structure"; + stream << "\n"; + stream << indent_str; + stream << " * (but does not deallocate the structure itself)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure to deallocate"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "void "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_free (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (generate_config_parser) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The config file parser (deprecated version)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param filename the name of the config file"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param override whether to override possibly already present options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param initialize whether to initialize the option structure my_args_info"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param check_required whether to check that all required options were provided"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "deprecated use "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_config_file() instead"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_configfile (const char *filename,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " int override, int initialize, int check_required);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The config file parser"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param filename the name of the config file"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param params additional parameters for the parser"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_config_file (const char *filename,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + if (generate_string_parser) + { + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The string parser (interprets the passed string as a command line)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param cmdline the command line stirng"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param prog_name the name of the program that will be used to print"; + stream << "\n"; + stream << indent_str; + stream << " * possible errors"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string (const char *cmdline, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " const char *prog_name);"; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The string parser (version with additional parameters - deprecated)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param cmdline the command line stirng"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param prog_name the name of the program that will be used to print"; + stream << "\n"; + stream << indent_str; + stream << " * possible errors"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param override whether to override possibly already present options"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param initialize whether to initialize the option structure my_args_info"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param check_required whether to check that all required options were provided"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "deprecated use "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string_ext() instead"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string2 (const char *cmdline, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " const char *prog_name,"; + stream << "\n"; + stream << indent_str; + stream << " int override, int initialize, int check_required);"; + stream << "\n"; + stream << indent_str; + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * The string parser (version with additional parameters)"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param cmdline the command line stirng"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure where option information will be stored"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param prog_name the name of the program that will be used to print"; + stream << "\n"; + stream << indent_str; + stream << " * possible errors"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param params additional parameters for the parser"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return 0 if everything went fine, NON 0 if an error took place"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_string_ext (const char *cmdline, struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " const char *prog_name,"; + stream << "\n"; + stream << indent_str; + stream << " struct "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_params *params);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + stream << "/**"; + stream << "\n"; + stream << indent_str; + stream << " * Checks that all the required options were specified"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param args_info the structure to check"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "param prog_name the name of the program that will be used to print"; + stream << "\n"; + stream << indent_str; + stream << " * possible errors"; + stream << "\n"; + stream << indent_str; + stream << " * "; + stream << "@"; + stream << "return"; + stream << "\n"; + stream << indent_str; + stream << " */"; + stream << "\n"; + stream << indent_str; + stream << "int "; + generate_string (parser_name, stream, indent + indent_str.length ()); + stream << "_required (struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info,"; + stream << "\n"; + stream << indent_str; + stream << " const char *prog_name);"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + if (option_values_decl.size () > 0) + generate_string (option_values_decl, stream, indent + indent_str.length ()); + else + generate_option_values_decl (stream, indent + indent_str.length ()); + stream << indent_str; + stream << "\n"; + stream << indent_str; + stream << "#ifdef __cplusplus"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "#endif /* __cplusplus */"; + stream << "\n"; + stream << indent_str; + stream << "#endif /* "; + generate_string (ifndefname, stream, indent + indent_str.length ()); + stream << "_H */"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/header.h b/cmake/gengetopt/skels/header.h new file mode 100644 index 0000000..19c725a --- /dev/null +++ b/cmake/gengetopt/skels/header.h @@ -0,0 +1,194 @@ +/* + * File automatically generated by + * gengen 1.4 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef HEADER_GEN_CLASS_H +#define HEADER_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class header_gen_class +{ + protected: + string args_info; + string enum_types; + bool generate_config_parser; + bool generate_string_parser; + string generator_version; + string group_counters; + bool has_details; + bool has_hidden; + string header_file_ext; + string header_file_name; + string ifndefname; + string mode_counters; + string option_arg; + string option_given; + string option_values_decl; + string package_var_name; + string package_var_val; + string parser_name; + string version_var_name; + string version_var_val; + + public: + header_gen_class() : + generate_config_parser (false), generate_string_parser (false), has_details (false), has_hidden (false) + { + } + + header_gen_class(const string &_args_info, const string &_enum_types, bool _generate_config_parser, bool _generate_string_parser, const string &_generator_version, const string &_group_counters, bool _has_details, bool _has_hidden, const string &_header_file_ext, const string &_header_file_name, const string &_ifndefname, const string &_mode_counters, const string &_option_arg, const string &_option_given, const string &_option_values_decl, const string &_package_var_name, const string &_package_var_val, const string &_parser_name, const string &_version_var_name, const string &_version_var_val) : + args_info (_args_info), enum_types (_enum_types), generate_config_parser (_generate_config_parser), generate_string_parser (_generate_string_parser), generator_version (_generator_version), group_counters (_group_counters), has_details (_has_details), has_hidden (_has_hidden), header_file_ext (_header_file_ext), header_file_name (_header_file_name), ifndefname (_ifndefname), mode_counters (_mode_counters), option_arg (_option_arg), option_given (_option_given), option_values_decl (_option_values_decl), package_var_name (_package_var_name), package_var_val (_package_var_val), parser_name (_parser_name), version_var_name (_version_var_name), version_var_val (_version_var_val) + { + } + + virtual ~header_gen_class() + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_args_info(const string &_args_info) + { + args_info = _args_info; + } + + virtual void generate_enum_types(ostream &stream, unsigned int indent) = 0; + + void set_enum_types(const string &_enum_types) + { + enum_types = _enum_types; + } + + void set_generate_config_parser(bool _generate_config_parser) + { + generate_config_parser = _generate_config_parser; + } + + void set_generate_string_parser(bool _generate_string_parser) + { + generate_string_parser = _generate_string_parser; + } + + void set_generator_version(const string &_generator_version) + { + generator_version = _generator_version; + } + + virtual void generate_group_counters(ostream &stream, unsigned int indent) = 0; + + void set_group_counters(const string &_group_counters) + { + group_counters = _group_counters; + } + + void set_has_details(bool _has_details) + { + has_details = _has_details; + } + + void set_has_hidden(bool _has_hidden) + { + has_hidden = _has_hidden; + } + + void set_header_file_ext(const string &_header_file_ext) + { + header_file_ext = _header_file_ext; + } + + void set_header_file_name(const string &_header_file_name) + { + header_file_name = _header_file_name; + } + + void set_ifndefname(const string &_ifndefname) + { + ifndefname = _ifndefname; + } + + virtual void generate_mode_counters(ostream &stream, unsigned int indent) = 0; + + void set_mode_counters(const string &_mode_counters) + { + mode_counters = _mode_counters; + } + + virtual void generate_option_arg(ostream &stream, unsigned int indent) = 0; + + void set_option_arg(const string &_option_arg) + { + option_arg = _option_arg; + } + + virtual void generate_option_given(ostream &stream, unsigned int indent) = 0; + + void set_option_given(const string &_option_given) + { + option_given = _option_given; + } + + virtual void generate_option_values_decl(ostream &stream, unsigned int indent) = 0; + + void set_option_values_decl(const string &_option_values_decl) + { + option_values_decl = _option_values_decl; + } + + void set_package_var_name(const string &_package_var_name) + { + package_var_name = _package_var_name; + } + + void set_package_var_val(const string &_package_var_val) + { + package_var_val = _package_var_val; + } + + void set_parser_name(const string &_parser_name) + { + parser_name = _parser_name; + } + + void set_version_var_name(const string &_version_var_name) + { + version_var_name = _version_var_name; + } + + void set_version_var_val(const string &_version_var_val) + { + version_var_val = _version_var_val; + } + + void generate_header(ostream &stream, unsigned int indent = 0); + +}; + +#endif // HEADER_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/init_args_info.cc b/cmake/gengetopt/skels/init_args_info.cc new file mode 100644 index 0000000..1b59bed --- /dev/null +++ b/cmake/gengetopt/skels/init_args_info.cc @@ -0,0 +1,41 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "init_args_info.h" + +void +init_args_info_gen_class::generate_init_args_info(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "args_info->"; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << "_help = "; + generate_string (help_strings, stream, indent + indent_str.length ()); + stream << "["; + generate_string (num, stream, indent + indent_str.length ()); + stream << "] ;"; + stream << "\n"; + stream << indent_str; + if (multiple) + { + stream << "args_info->"; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << "_min = "; + generate_string (min, stream, indent + indent_str.length ()); + stream << ";"; + stream << "\n"; + stream << indent_str; + stream << "args_info->"; + generate_string (var_arg, stream, indent + indent_str.length ()); + stream << "_max = "; + generate_string (max, stream, indent + indent_str.length ()); + stream << ";"; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/init_args_info.h b/cmake/gengetopt/skels/init_args_info.h new file mode 100644 index 0000000..d4fdcce --- /dev/null +++ b/cmake/gengetopt/skels/init_args_info.h @@ -0,0 +1,94 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef INIT_ARGS_INFO_GEN_CLASS_H +#define INIT_ARGS_INFO_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class init_args_info_gen_class +{ + protected: + string help_strings; + string max; + string min; + bool multiple; + string num; + string var_arg; + + public: + init_args_info_gen_class() : + multiple (false) + { + } + + init_args_info_gen_class(const string &_help_strings, const string &_max, const string &_min, bool _multiple, const string &_num, const string &_var_arg) : + help_strings (_help_strings), max (_max), min (_min), multiple (_multiple), num (_num), var_arg (_var_arg) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_help_strings(const string &_help_strings) + { + help_strings = _help_strings; + } + + void set_max(const string &_max) + { + max = _max; + } + + void set_min(const string &_min) + { + min = _min; + } + + void set_multiple(bool _multiple) + { + multiple = _multiple; + } + + void set_num(const string &_num) + { + num = _num; + } + + void set_var_arg(const string &_var_arg) + { + var_arg = _var_arg; + } + + void generate_init_args_info(ostream &stream, unsigned int indent = 0); + +}; + +#endif // INIT_ARGS_INFO_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/multiple_fill_array.cc b/cmake/gengetopt/skels/multiple_fill_array.cc new file mode 100644 index 0000000..ab5f06f --- /dev/null +++ b/cmake/gengetopt/skels/multiple_fill_array.cc @@ -0,0 +1,61 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "multiple_fill_array.h" + +void +multiple_fill_array_gen_class::generate_multiple_fill_array(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (( default_value != "0" )) + { + stream << "multiple_default_value."; + if (( arg_type == "ARG_STRING" )) + { + stream << "default_"; + } + generate_string (type, stream, indent + indent_str.length ()); + stream << "_arg = "; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << ";"; + stream << "\n"; + stream << indent_str; + } + stream << "update_multiple_arg((void *)&(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_arg),"; + stream << "\n"; + stream << indent_str; + stream << " &(args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_orig), args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given,"; + stream << "\n"; + stream << indent_str; + stream << " local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given, "; + if (( default_value != "0" )) + { + stream << "&multiple_default_value"; + } + else + { + stream << "0"; + } + stream << ","; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (arg_type, stream, indent + indent_str.length ()); + stream << ", "; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_list);"; +} diff --git a/cmake/gengetopt/skels/multiple_fill_array.h b/cmake/gengetopt/skels/multiple_fill_array.h new file mode 100644 index 0000000..9249fd5 --- /dev/null +++ b/cmake/gengetopt/skels/multiple_fill_array.h @@ -0,0 +1,81 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef MULTIPLE_FILL_ARRAY_GEN_CLASS_H +#define MULTIPLE_FILL_ARRAY_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class multiple_fill_array_gen_class +{ + protected: + string arg_type; + string default_value; + string option_var_name; + string type; + + public: + multiple_fill_array_gen_class() + { + } + + multiple_fill_array_gen_class(const string &_arg_type, const string &_default_value, const string &_option_var_name, const string &_type) : + arg_type (_arg_type), default_value (_default_value), option_var_name (_option_var_name), type (_type) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_arg_type(const string &_arg_type) + { + arg_type = _arg_type; + } + + void set_default_value(const string &_default_value) + { + default_value = _default_value; + } + + void set_option_var_name(const string &_option_var_name) + { + option_var_name = _option_var_name; + } + + void set_type(const string &_type) + { + type = _type; + } + + void generate_multiple_fill_array(ostream &stream, unsigned int indent = 0); + +}; + +#endif // MULTIPLE_FILL_ARRAY_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/multiple_opt_list.cc b/cmake/gengetopt/skels/multiple_opt_list.cc new file mode 100644 index 0000000..f8b6acd --- /dev/null +++ b/cmake/gengetopt/skels/multiple_opt_list.cc @@ -0,0 +1,18 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "multiple_opt_list.h" + +void +multiple_opt_list_gen_class::generate_multiple_opt_list(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "struct generic_list * "; + generate_string (arg_name, stream, indent + indent_str.length ()); + stream << "_list = NULL;"; +} diff --git a/cmake/gengetopt/skels/multiple_opt_list.h b/cmake/gengetopt/skels/multiple_opt_list.h new file mode 100644 index 0000000..ee0e214 --- /dev/null +++ b/cmake/gengetopt/skels/multiple_opt_list.h @@ -0,0 +1,63 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef MULTIPLE_OPT_LIST_GEN_CLASS_H +#define MULTIPLE_OPT_LIST_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class multiple_opt_list_gen_class +{ + protected: + string arg_name; + + public: + multiple_opt_list_gen_class() + { + } + + multiple_opt_list_gen_class(const string &_arg_name) : + arg_name (_arg_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_arg_name(const string &_arg_name) + { + arg_name = _arg_name; + } + + void generate_multiple_opt_list(ostream &stream, unsigned int indent = 0); + +}; + +#endif // MULTIPLE_OPT_LIST_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/option_arg.cc b/cmake/gengetopt/skels/option_arg.cc new file mode 100644 index 0000000..5b02e04 --- /dev/null +++ b/cmake/gengetopt/skels/option_arg.cc @@ -0,0 +1,183 @@ +/* + * File automatically generated by + * gengen 1.3 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "option_arg.h" + +void +option_arg_gen_class::generate_option_arg(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (long_long_arg) + { + stream << "#ifdef HAVE_LONG_LONG"; + stream << "\n"; + stream << indent_str; + generate_string (type, stream, indent + indent_str.length ()); + stream << " "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_arg; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + if (has_default) + { + stream << " (default="; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << ")"; + } + stream << ". */"; + stream << "\n"; + stream << indent_str; + stream << "#else"; + stream << "\n"; + stream << indent_str; + generate_string (longtype, stream, indent + indent_str.length ()); + stream << " "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_arg; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + if (has_default) + { + stream << " (default="; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << ")"; + } + stream << ". */"; + stream << "\n"; + stream << indent_str; + stream << "#endif"; + stream << "\n"; + stream << indent_str; + generate_string (origtype, stream, indent + indent_str.length ()); + stream << " "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_orig; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + stream << " original value given at command line. */"; + stream << "\n"; + stream << indent_str; + } + else + { + if (flag_arg) + { + generate_string (type, stream, indent + indent_str.length ()); + stream << " "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_flag; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + stream << " (default="; + if (default_on) + { + stream << "on"; + } + else + { + stream << "off"; + } + stream << "). */"; + stream << "\n"; + stream << indent_str; + } + else + { + if (has_arg) + { + if (has_enum) + { + stream << "enum enum_"; + generate_string (name, stream, indent + indent_str.length ()); + stream << " "; + if (multiple) + { + stream << "*"; + } + generate_string (name, stream, indent + indent_str.length ()); + stream << "_arg; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + if (has_default) + { + stream << " (default='"; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << "')"; + } + stream << ". */"; + stream << "\n"; + stream << indent_str; + } + else + { + generate_string (type, stream, indent + indent_str.length ()); + stream << " "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_arg; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + if (has_default) + { + stream << " (default='"; + generate_string (default_value, stream, indent + indent_str.length ()); + stream << "')"; + } + stream << ". */"; + stream << "\n"; + stream << indent_str; + } + generate_string (origtype, stream, indent + indent_str.length ()); + stream << " "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_orig; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + stream << " original value given at command line. */"; + stream << "\n"; + stream << indent_str; + } + } + } + if (multiple) + { + stream << "unsigned int "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_min; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + stream << "'s minimum occurreces */"; + stream << "\n"; + stream << indent_str; + stream << "unsigned int "; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_max; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + stream << "'s maximum occurreces */"; + stream << "\n"; + stream << indent_str; + } + stream << "const char *"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_help; /**< "; + stream << "@"; + stream << "brief "; + generate_string (desc, stream, indent + indent_str.length ()); + stream << " help description. */"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/option_arg.h b/cmake/gengetopt/skels/option_arg.h new file mode 100644 index 0000000..e443b79 --- /dev/null +++ b/cmake/gengetopt/skels/option_arg.h @@ -0,0 +1,136 @@ +/* + * File automatically generated by + * gengen 1.3 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef OPTION_ARG_GEN_CLASS_H +#define OPTION_ARG_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class option_arg_gen_class +{ + protected: + bool default_on; + string default_value; + string desc; + bool flag_arg; + bool has_arg; + bool has_default; + bool has_enum; + bool long_long_arg; + string longtype; + bool multiple; + string name; + string origtype; + string type; + + public: + option_arg_gen_class() : + default_on (false), flag_arg (false), has_arg (false), has_default (false), has_enum (false), long_long_arg (false), multiple (false) + { + } + + option_arg_gen_class(bool _default_on, const string &_default_value, const string &_desc, bool _flag_arg, bool _has_arg, bool _has_default, bool _has_enum, bool _long_long_arg, const string &_longtype, bool _multiple, const string &_name, const string &_origtype, const string &_type) : + default_on (_default_on), default_value (_default_value), desc (_desc), flag_arg (_flag_arg), has_arg (_has_arg), has_default (_has_default), has_enum (_has_enum), long_long_arg (_long_long_arg), longtype (_longtype), multiple (_multiple), name (_name), origtype (_origtype), type (_type) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_default_on(bool _default_on) + { + default_on = _default_on; + } + + void set_default_value(const string &_default_value) + { + default_value = _default_value; + } + + void set_desc(const string &_desc) + { + desc = _desc; + } + + void set_flag_arg(bool _flag_arg) + { + flag_arg = _flag_arg; + } + + void set_has_arg(bool _has_arg) + { + has_arg = _has_arg; + } + + void set_has_default(bool _has_default) + { + has_default = _has_default; + } + + void set_has_enum(bool _has_enum) + { + has_enum = _has_enum; + } + + void set_long_long_arg(bool _long_long_arg) + { + long_long_arg = _long_long_arg; + } + + void set_longtype(const string &_longtype) + { + longtype = _longtype; + } + + void set_multiple(bool _multiple) + { + multiple = _multiple; + } + + void set_name(const string &_name) + { + name = _name; + } + + void set_origtype(const string &_origtype) + { + origtype = _origtype; + } + + void set_type(const string &_type) + { + type = _type; + } + + void generate_option_arg(ostream &stream, unsigned int indent = 0); + +}; + +#endif // OPTION_ARG_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/print_help_string.cc b/cmake/gengetopt/skels/print_help_string.cc new file mode 100644 index 0000000..9eaa514 --- /dev/null +++ b/cmake/gengetopt/skels/print_help_string.cc @@ -0,0 +1,43 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "print_help_string.h" + +void +print_help_string_gen_class::generate_print_help_string(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (shared) + { + generate_string (target, stream, indent + indent_str.length ()); + stream << "["; + generate_string (index, stream, indent + indent_str.length ()); + stream << "] = "; + if (last) + { + stream << "0; "; + } + else + { + generate_string (from, stream, indent + indent_str.length ()); + stream << "["; + generate_string (full_index, stream, indent + indent_str.length ()); + stream << "];"; + } + stream << "\n"; + stream << indent_str; + } + else + { + stream << "\""; + generate_string (helpstring, stream, indent + indent_str.length ()); + stream << "\","; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/print_help_string.h b/cmake/gengetopt/skels/print_help_string.h new file mode 100644 index 0000000..5179816 --- /dev/null +++ b/cmake/gengetopt/skels/print_help_string.h @@ -0,0 +1,100 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef PRINT_HELP_STRING_GEN_CLASS_H +#define PRINT_HELP_STRING_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class print_help_string_gen_class +{ + protected: + string from; + string full_index; + string helpstring; + string index; + bool last; + bool shared; + string target; + + public: + print_help_string_gen_class() : + last (false), shared (false) + { + } + + print_help_string_gen_class(const string &_from, const string &_full_index, const string &_helpstring, const string &_index, bool _last, bool _shared, const string &_target) : + from (_from), full_index (_full_index), helpstring (_helpstring), index (_index), last (_last), shared (_shared), target (_target) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_from(const string &_from) + { + from = _from; + } + + void set_full_index(const string &_full_index) + { + full_index = _full_index; + } + + void set_helpstring(const string &_helpstring) + { + helpstring = _helpstring; + } + + void set_index(const string &_index) + { + index = _index; + } + + void set_last(bool _last) + { + last = _last; + } + + void set_shared(bool _shared) + { + shared = _shared; + } + + void set_target(const string &_target) + { + target = _target; + } + + void generate_print_help_string(ostream &stream, unsigned int indent = 0); + +}; + +#endif // PRINT_HELP_STRING_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/required_option.cc b/cmake/gengetopt/skels/required_option.cc new file mode 100644 index 0000000..864a9e1 --- /dev/null +++ b/cmake/gengetopt/skels/required_option.cc @@ -0,0 +1,66 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "required_option.h" + +void +required_option_gen_class::generate_required_option(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + if (checkrange) + { + stream << "if ("; + generate_string (mode_condition, stream, indent + indent_str.length ()); + stream << "check_multiple_option_occurrences("; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given, args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_min, args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_max, \""; + generate_string (option_descr, stream, indent + indent_str.length ()); + stream << "\"))"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } + else + { + stream << "if ("; + generate_string (mode_condition, stream, indent + indent_str.length ()); + stream << "! args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given)"; + stream << "\n"; + stream << indent_str; + stream << " {"; + stream << "\n"; + stream << indent_str; + stream << " fprintf (stderr, \"%s: "; + generate_string (option_descr, stream, indent + indent_str.length ()); + stream << " option required%s\\n\", "; + generate_string (package_var_name, stream, indent + indent_str.length ()); + stream << ", (additional_error ? additional_error : \"\"));"; + stream << "\n"; + stream << indent_str; + stream << " error = 1;"; + stream << "\n"; + stream << indent_str; + stream << " }"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; + } +} diff --git a/cmake/gengetopt/skels/required_option.h b/cmake/gengetopt/skels/required_option.h new file mode 100644 index 0000000..9a27551 --- /dev/null +++ b/cmake/gengetopt/skels/required_option.h @@ -0,0 +1,88 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef REQUIRED_OPTION_GEN_CLASS_H +#define REQUIRED_OPTION_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class required_option_gen_class +{ + protected: + bool checkrange; + string mode_condition; + string option_descr; + string option_var_name; + string package_var_name; + + public: + required_option_gen_class() : + checkrange (false) + { + } + + required_option_gen_class(bool _checkrange, const string &_mode_condition, const string &_option_descr, const string &_option_var_name, const string &_package_var_name) : + checkrange (_checkrange), mode_condition (_mode_condition), option_descr (_option_descr), option_var_name (_option_var_name), package_var_name (_package_var_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_checkrange(bool _checkrange) + { + checkrange = _checkrange; + } + + void set_mode_condition(const string &_mode_condition) + { + mode_condition = _mode_condition; + } + + void set_option_descr(const string &_option_descr) + { + option_descr = _option_descr; + } + + void set_option_var_name(const string &_option_var_name) + { + option_var_name = _option_var_name; + } + + void set_package_var_name(const string &_package_var_name) + { + package_var_name = _package_var_name; + } + + void generate_required_option(ostream &stream, unsigned int indent = 0); + +}; + +#endif // REQUIRED_OPTION_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/reset_group.cc b/cmake/gengetopt/skels/reset_group.cc new file mode 100644 index 0000000..84497d7 --- /dev/null +++ b/cmake/gengetopt/skels/reset_group.cc @@ -0,0 +1,57 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "reset_group.h" + +void +reset_group_gen_class::generate_reset_group(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "static void"; + stream << "\n"; + stream << indent_str; + stream << "reset_group_"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "(struct "; + generate_string (args_info, stream, indent + indent_str.length ()); + stream << " *args_info)"; + stream << "\n"; + stream << indent_str; + stream << "{"; + stream << "\n"; + stream << indent_str; + stream << " if (! args_info->"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_group_counter)"; + stream << "\n"; + stream << indent_str; + stream << " return;"; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + indent = 0; + stream << "\n"; + stream << indent_str; + indent = 2; + stream << " "; + generate_string (body, stream, indent + indent_str.length ()); + indent = 0; + stream << "\n"; + stream << indent_str; + stream << " args_info->"; + generate_string (name, stream, indent + indent_str.length ()); + stream << "_group_counter = 0;"; + stream << "\n"; + stream << indent_str; + stream << "}"; + stream << "\n"; + stream << indent_str; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/reset_group.h b/cmake/gengetopt/skels/reset_group.h new file mode 100644 index 0000000..bf51661 --- /dev/null +++ b/cmake/gengetopt/skels/reset_group.h @@ -0,0 +1,75 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef RESET_GROUP_GEN_CLASS_H +#define RESET_GROUP_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class reset_group_gen_class +{ + protected: + string args_info; + string body; + string name; + + public: + reset_group_gen_class() + { + } + + reset_group_gen_class(const string &_args_info, const string &_body, const string &_name) : + args_info (_args_info), body (_body), name (_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_args_info(const string &_args_info) + { + args_info = _args_info; + } + + void set_body(const string &_body) + { + body = _body; + } + + void set_name(const string &_name) + { + name = _name; + } + + void generate_reset_group(ostream &stream, unsigned int indent = 0); + +}; + +#endif // RESET_GROUP_GEN_CLASS_H diff --git a/cmake/gengetopt/skels/update_given.cc b/cmake/gengetopt/skels/update_given.cc new file mode 100644 index 0000000..ed52b43 --- /dev/null +++ b/cmake/gengetopt/skels/update_given.cc @@ -0,0 +1,27 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#include "update_given.h" + +void +update_given_gen_class::generate_update_given(ostream &stream, unsigned int indent) +{ + string indent_str (indent, ' '); + indent = 0; + + stream << "args_info->"; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given += local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given;"; + stream << "\n"; + stream << indent_str; + stream << "local_args_info."; + generate_string (option_var_name, stream, indent + indent_str.length ()); + stream << "_given = 0;"; + stream << "\n"; + stream << indent_str; +} diff --git a/cmake/gengetopt/skels/update_given.h b/cmake/gengetopt/skels/update_given.h new file mode 100644 index 0000000..29f5c8d --- /dev/null +++ b/cmake/gengetopt/skels/update_given.h @@ -0,0 +1,63 @@ +/* + * File automatically generated by + * gengen 1.2 by Lorenzo Bettini + * http://www.gnu.org/software/gengen + */ + +#ifndef UPDATE_GIVEN_GEN_CLASS_H +#define UPDATE_GIVEN_GEN_CLASS_H + +#include +#include + +using std::string; +using std::ostream; + +class update_given_gen_class +{ + protected: + string option_var_name; + + public: + update_given_gen_class() + { + } + + update_given_gen_class(const string &_option_var_name) : + option_var_name (_option_var_name) + { + } + + static void + generate_string(const string &s, ostream &stream, unsigned int indent) + { + if (!indent || s.find('\n') == string::npos) + { + stream << s; + return; + } + + string::size_type pos; + string::size_type start = 0; + string ind (indent, ' '); + while ( (pos=s.find('\n', start)) != string::npos) + { + stream << s.substr (start, (pos+1)-start); + start = pos+1; + if (start+1 <= s.size ()) + stream << ind; + } + if (start+1 <= s.size ()) + stream << s.substr (start); + } + + void set_option_var_name(const string &_option_var_name) + { + option_var_name = _option_var_name; + } + + void generate_update_given(ostream &stream, unsigned int indent = 0); + +}; + +#endif // UPDATE_GIVEN_GEN_CLASS_H diff --git a/cmake/gengetopt/yyerror.cc b/cmake/gengetopt/yyerror.cc new file mode 100644 index 0000000..ca06a2e --- /dev/null +++ b/cmake/gengetopt/yyerror.cc @@ -0,0 +1,49 @@ +/* +This file is licensed to you under the license specified in the included file +`LICENSE'. Look there for further details. +*/ + + +/* + Called by yyparse on error. + */ + +#include "yyerror.h" + +#include +#include +#include + +extern int gengetopt_count_line; +extern char * gengetopt_input_filename; + +extern int tokenpos; +extern char linebuf[]; +extern char *yytext; + +using namespace std; + +void +yyerror (const char *s) +{ + const char *source = + (gengetopt_input_filename ? gengetopt_input_filename : "gengetopt"); + + fprintf (stderr, "%s:%d: %s %s\n", source, gengetopt_count_line, s, yytext); + + if (/*!linebuf || */!strlen(linebuf)) + return; + + fprintf (stderr, "%s:%d: %s\n", source, gengetopt_count_line, linebuf); + fprintf (stderr, "%s:%d: %*s\n", source, gengetopt_count_line, + tokenpos + 1, "^"); +} + +void +yyerror (gengetopt_option *opt, const char *s) +{ + const char *source = + (opt->filename ? opt->filename : "gengetopt"); + + cerr << source << ":" << opt->linenum << ": " << s << endl; +} diff --git a/cmake/gengetopt/yyerror.h b/cmake/gengetopt/yyerror.h new file mode 100644 index 0000000..a97d414 --- /dev/null +++ b/cmake/gengetopt/yyerror.h @@ -0,0 +1,12 @@ +#ifndef YYERROR_H_ +#define YYERROR_H_ + +#include "ggos.h" + +void +yyerror (const char *s); + +void +yyerror (gengetopt_option *opt, const char *s); + +#endif /*YYERROR_H_*/ diff --git a/cmake/gengetopt/yywrap.c b/cmake/gengetopt/yywrap.c new file mode 100644 index 0000000..9e561d3 --- /dev/null +++ b/cmake/gengetopt/yywrap.c @@ -0,0 +1,18 @@ +/* +This file is licensed to you under the license specified in the included file +`LICENSE'. Look there for further details. +*/ + + +/* + This function is called when found EOF. + */ +#include + +int +yywrap () +{ + /* fprintf (stderr, "yywrap() called.\n"); */ + return 1; +} +