Ignore:
Timestamp:
05/24/11 17:36:00 (13 years ago)
Author:
tbretz
Message:
Added PrintVersion directly to avoid clashes with exceptions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Configuration.cc

    r10707 r10796  
    290290#include <boost/bind.hpp>
    291291#include <boost/regex.hpp>
    292 //#include <boost/filesystem.hpp>
     292#include <boost/filesystem.hpp>
    293293#include <boost/program_options.hpp>
    294294
     
    473473    po::options_description generic("Generic options");
    474474    generic.add_options()
     475        ("version,V",           "Print version information.")
    475476        ("help",                "Print available commandline options.")
    476477        ("help-environment",    "Print available environment variables.")
    477478        ("help-database",       "Print available options retreived from the database.")
    478479        ("help-config",         "Print available configuration file options.")
    479         ("version,V",           "Print version information.")
    480480        ("print-all",           "Print all options as parsed from all the different sources.")
    481481        ("print",               "Print options as parsed from the commandline.")
     
    732732{
    733733    fPrintUsage = boost::bind(&Configuration::PrintUsage, this);
     734}
     735
     736void Configuration::SetPrintVersion(const boost::function<void(const string&)> &func)
     737{
     738    fPrintVersion = func;
     739}
     740
     741void Configuration::SetPrintVersion()
     742{
     743    fPrintVersion = boost::function<void(const string&)>();
    734744}
    735745
     
    848858    po::store(parsed_commandline, getfiles);
    849859
     860    if (getfiles.count("version"))
     861        PrintVersion();
    850862    if (getfiles.count("help"))
    851863    {
     
    987999
    9881000    // ------------------------ (13) -------------------------
    989 
    9901001    po::variables_map result;
    9911002    po::store(parsed_commandline,  result);
     
    10211032    return fVariables;
    10221033}
     1034
     1035// --------------------------------------------------------------------------
     1036//
     1037//! Print version information about the program and package.
     1038//!
     1039//! The program name is taken from fName. If a leading "lt-" is found,
     1040//! it is removed. This is useful if the program was build and run
     1041//! using libtool.
     1042//!
     1043//! The package name is taken from the define PACKAGE_STRING. If it is
     1044//! not defined (like automatically done by autoconf) no package information
     1045//! is printed. The same is true for PACKAGE_URL and PACKAGE_BUGREPORT.
     1046//!
     1047//! From help2man:
     1048//!
     1049//! The first line of the --version information is assumed to be in one
     1050//! of the following formats:
     1051//!
     1052//! \verbatim
     1053//!  - <version>
     1054//!  - <program> <version>
     1055//!  - {GNU,Free} <program> <version>
     1056//!  - <program> ({GNU,Free} <package>) <version>
     1057//!  - <program> - {GNU,Free} <package> <version>
     1058//! \endverbatim
     1059//!
     1060//!  and separated from any copyright/author details by a blank line.
     1061//!
     1062//! Handle multi-line bug reporting sections of the form:
     1063//!
     1064//! \verbatim
     1065//!  - Report <program> bugs to <addr>
     1066//!  - GNU <package> home page: <url>
     1067//!  - ...
     1068//! \endverbatim
     1069//!
     1070//! @param name
     1071//!     name of the program (usually argv[0]). A possible leading "lt-"
     1072//!     is removed.
     1073//!
     1074void Configuration::PrintVersion() const
     1075{
     1076#ifndef PACKAGE_STRING
     1077#define PACKAGE_STRING ""
     1078#endif
     1079
     1080#ifndef PACKAGE_URL
     1081#define PACKAGE_URL ""
     1082#endif
     1083
     1084#ifndef PACKAGE_BUGREPORT
     1085#define PACKAGE_BUGREPORT ""
     1086#endif
     1087
     1088    if (!fPrintVersion.empty())
     1089    {
     1090        fPrintVersion(fName);
     1091        return;
     1092    }
     1093
     1094    std::string n = boost::filesystem::basename(fName);
     1095    if (n.substr(0, 3)=="lt-")
     1096        n = n.substr(3);
     1097
     1098    const string name = PACKAGE_STRING;
     1099    const string bugs = PACKAGE_BUGREPORT;
     1100    const string url  = PACKAGE_URL;
     1101
     1102    cout << n;
     1103    if (!name.empty())
     1104        cout << " - " << name;
     1105    cout <<
     1106        "\n\n"
     1107        "Written by Thomas Bretz et al.\n"
     1108        "\n";
     1109    if (!bugs.empty())
     1110        cout << "Report bugs to <" << bugs << ">\n";
     1111    if (!url.empty())
     1112        cout << "Home page: " << url << "\n";
     1113    cout <<
     1114        "\n"
     1115        "Copyright (C) 2011 by the FACT Collaboration.\n"
     1116        "This is free software; see the source for copying conditions.\n"
     1117        << std::endl;
     1118}
Note: See TracChangeset for help on using the changeset viewer.