41#include    <libutf8/libutf8.h> 
   46#include    <libexcept/file_inheritance.h> 
   51#include    <snapdev/not_reached.h> 
   52#include    <snapdev/trim_string.h> 
   57#include    <boost/preprocessor/stringize.hpp> 
   69#include    <snapdev/poison.h> 
  108    "/etc/advgetopt/build-file-of-options.conf",
 
 
  116#pragma GCC diagnostic ignored "-Wpedantic" 
  120    .f_group_name = 
nullptr,
 
  122    .f_options_files_directory = 
nullptr,
 
  124    .f_environment_variable_intro = 
nullptr,
 
  125    .f_section_variables_name = 
nullptr,
 
  127    .f_configuration_filename = 
nullptr,
 
  128    .f_configuration_directories = 
nullptr,
 
  130    .f_help_header = 
"Usage: %p [-<opt>] <configuration file>\n" 
  131                     "where -<opt> is one or more of:",
 
  132    .f_help_footer = 
"%c",
 
  134    .f_license = 
nullptr,
 
  135    .f_copyright = 
"Copyright (c) 2019-" BOOST_PP_STRINGIZE(UTC_BUILD_YEAR) 
"  Made to Order Software Corporation",
 
  136    .f_build_date = UTC_BUILD_DATE,
 
  137    .f_build_time = UTC_BUILD_TIME
 
 
  152    int                             read_conf(std::string 
const & filename);
 
  153    void                            append_flag(std::string & flags, std::string 
const & name);
 
  156    std::ifstream                   f_in = std::ifstream();
 
 
  184    for(std::size_t idx(0); idx < max; ++idx)
 
 
  203            << 
"error: could not open file \"" 
  214    for(++line; 
f_in; ++line)
 
  219            l = snapdev::trim_string(l);
 
  230            l = snapdev::trim_string(l);
 
  243            std::string::size_type 
const pos(l.find(
'='));
 
  246            if(pos != std::string::npos)
 
  251                name = snapdev::trim_string(l.substr(1, pos - 1));
 
  252                params = snapdev::trim_string(l.substr(pos + 1));
 
  254            std::string::size_type 
const space(name.find(
' '));
 
  255            std::string::size_type 
const colon(name.find(
':'));
 
  257            && space == std::string::npos
 
  258            && colon == std::string::npos)
 
  261                std::string::size_type 
const has_alias(name.find(
'|'));
 
  262                if(has_alias != std::string::npos)
 
  264                    alias = name.substr(has_alias + 1);
 
  265                    name = name.substr(0, has_alias);
 
  268                std::string short_name;
 
  269                if(params.back() == 
')')
 
  271                    std::string::size_type 
const start_short_name(params.rfind(
'('));
 
  272                    short_name = params.substr(start_short_name + 1, params.length() - start_short_name - 2);
 
  273                    params = snapdev::trim_string(params.substr(0, start_short_name));
 
  274                    if(libutf8::u8length(short_name) != 1)
 
  276                        std::cerr << 
"error:" 
  280                            << 
": a short name specification must be exactly one character; \"" 
  282                            << 
"\" is not valid.\n";
 
  292                std::string default_value;
 
  293                for(++line; 
f_in; ++line)
 
  296                    l = snapdev::trim_string(l);
 
  300                        l = snapdev::trim_string(l.substr(1));
 
  301                        if(l.length() >= 
sizeof(
"Default:")
 
  311                            default_value = snapdev::trim_string(l.substr(8));
 
  319                std::string::size_type 
const dot(help.find(
'.'));
 
  320                if(dot != std::string::npos)
 
  322                    help = snapdev::trim_string(help.substr(0, dot + 1), 
true, 
true, 
true);
 
  327                    << 
"    advgetopt::define_option(\n" 
  328                    << 
"          advgetopt::Name(\"" << name << 
"\")\n";
 
  330                if(!short_name.empty())
 
  333                        << 
"        , advgetopt::ShortName(U'" << short_name << 
"')\n";
 
  338                    if(params.front() != 
'[' || params.back() != 
']')
 
  342                    if((params.front() == 
'{' && params.back() == 
'}')
 
  343                    || params.find(
"...") != std::string::npos)
 
  348                        << 
"        , advgetopt::Args(\"" << params << 
"\")\n";
 
  354                        << 
"        , advgetopt::Help(\"" << help << 
"\")\n";
 
  360                        << 
"        , advgetopt::Flags(" 
  364                std::cout << 
"    ),\n";
 
  372                        << 
"    advgetopt::define_option(\n" 
  373                        << 
"          advgetopt::Name(\"" << alias << 
"\")\n";
 
  382                        << 
"        , advgetopt::Help(\"" << name << 
"\")\n";
 
  387                            << 
"        , advgetopt::Flags(" 
  391                    std::cout << 
"    ),\n";
 
 
  411    flags += 
"advgetopt::GETOPT_FLAG_";
 
 
 
  423int main(
int argc, 
char * argv[])
 
  425    libexcept::verify_inherited_files();
 
  429        build_file session(argc, argv);
 
  430        return session.run();
 
  436            std::cerr << 
"error: " << e.what() << std::endl;
 
  440    catch(std::exception 
const & e)
 
  442        std::cerr << 
"error: exception caught: " << e.what() << std::endl;
 
  445    snapdev::NOT_REACHED();
 
 
Definitions of the advanced getopt class.
int main(int argc, char *argv[])
Class used to parse command line options.
std::string get_string(std::string const &name, int idx=0, bool raw=false) const
Get the content of an option as a string.
std::size_t size(std::string const &name) const
Retrieve the number of arguments.
bool is_defined(std::string const &name) const
Check whether a parameter is defined.
void append_flag(std::string &flags, std::string const &name)
int read_conf(std::string const &filename)
build_file(int argc, char *argv[])
Definitions of the advanced getopt exceptions.
constexpr option define_option(ARGS ...args)
constexpr flag_t command_flags()
constexpr option end_options()
constexpr flag_t GETOPT_ENVIRONMENT_FLAG_PROCESS_SYSTEM_PARAMETERS
static constexpr flag_t GETOPT_FLAG_DEFAULT_OPTION
static constexpr flag_t GETOPT_FLAG_MULTIPLE
static constexpr flag_t GETOPT_FLAG_REQUIRED
advgetopt::options_environment const g_options_environment
constexpr char const  *const g_configuration_files[]
The tool looks for this configuration file.
advgetopt::option const g_options[]
Command line options.
Structure representing an option.
char const  * f_environment_variable_name
char const  * f_project_name
Definitions of the advanced getopt class version.
#define LIBADVGETOPT_VERSION_STRING