Reimport libopt++ after changing build system.

This commit is contained in:
Laurence Withers 2006-08-02 16:31:39 +01:00
commit fce228c080
36 changed files with 1876 additions and 0 deletions

1
src/docs/.params Normal file
View file

@ -0,0 +1 @@
doxygen docs docs

146
src/docs/Doxyfile.in Normal file
View file

@ -0,0 +1,146 @@
# libopt++/src/docs/Doxyfile.in
#
# (c)2006, Laurence Withers, <l@lwithers.me.uk>.
# Released under the GNU GPLv2. See file COPYING or
# http://www.gnu.org/copyleft/gpl.html for details.
#
PROJECT_NAME = libopt++
OUTPUT_DIRECTORY =
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = YES
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = YES
DETAILS_AT_TOP = YES
INHERIT_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 4
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = NO
EXTRACT_LOCAL_METHODS = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = YES
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = NO
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = NO
SHOW_DIRECTORIES = NO
FILE_VERSION_FILTER =
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
FILE_PATTERNS =
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH = src/docs
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
VERBATIM_HEADERS = NO
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
GENERATE_LATEX = NO
GENERATE_RTF = NO
GENERATE_MAN = NO
GENERATE_XML = NO
GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = DOXYGEN
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = YES
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = NO
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = NO
INCLUDED_BY_GRAPH = NO
CALL_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = NO
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = YES
DOT_MULTI_TARGETS = YES
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
SEARCHENGINE = NO

23
src/docs/MainPage.dox Normal file
View file

@ -0,0 +1,23 @@
/* libopt++/src/docs/MainPage.dox
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
/*! \mainpage
libopt++ is a library for parsing commandline options passed to the main() function of a program.
It understands short and long style options specified as e.g. \c -x or \c --long. It is similar to
the GNU C library's getopt_long() with a few exceptions (no optional arguments, uses callbacks to
report options, etc.).
The library's main interface is through the opt::Parser class, which you override to implement
the callbacks. The header file is \c &lt;opt&gt;.
*/
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4
*/

1
src/docs/build.default Normal file
View file

@ -0,0 +1 @@
source src/docs/build.docs

43
src/docs/build.docs Normal file
View file

@ -0,0 +1,43 @@
# These are external variables, and shouldn't clash with anything else
# docs_BUILT
#
MONOLITHIC_DOC="${MONOLITHIC_DOC} $(echo src/docs/*.dox)"
build_target monolithic
if [ -z ${docs_BUILT} ]
then
echo "Building documentation with Doxygen..."
DOXYFILE=obj/Doxyfile.docs
if [ ! -e ${DOXYFILE} ]
then
do_cmd cp src/docs/Doxyfile.in ${DOXYFILE} || return 1
echo "INPUT = ${MONOLITHIC_DOC}" >> ${DOXYFILE}
echo "PROJECT_NUMBER = ${VERSION}" >> ${DOXYFILE}
fi
MODIFIED=0
for file in ${MONOLITHIC_DOC}
do
if [ ${file} -nt html/index.html ]
then
MODIFIED=1
break
fi
done
if [ ${MODIFIED} -ne 0 ]
then
do_cmd doxygen ${DOXYFILE} || return 1
print_success "Documentation built"
else
print_success "Documentation is up to date"
fi
docs_BUILT=1
fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

1
src/docs/build.install Normal file
View file

@ -0,0 +1 @@
source src/docs/build.install-docs

View file

@ -0,0 +1,21 @@
build_target docs
# create documentation directories
echo "Installing documentation into ${DOCSDIR}"
build_dir_tree "${DOCSDIR}/html" || return 1
# copy across the Doxygen-generated documentation
for file in html/*
do
install_file ${file} ${DOCSDIR}/html 0644 || return 1
done
# copy across the generic files
for file in COPYING README
do
install_file ${file} ${DOCSDIR} 0644 || return 1
done
print_success "Documentation installed"
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

1
src/libopt++/.params Normal file
View file

@ -0,0 +1 @@
c++ lib libopt++ opt

44
src/libopt++/BadArg.h Normal file
View file

@ -0,0 +1,44 @@
/* libopt++/src/libopt++/Parser.h
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
namespace opt {
/*! \brief Exception thrown when options cannot be parsed.
This exception is thrown whenever the options for a program cannot be parsed, meaning that either an
option is missing a required argument, or an option is not recognised at all. It is derived from
std::exception and has its what() method overloaded to print a useful description of the error.
Alternatively, you can get this from the msg member.
*/
class BadArg : public std::exception {
public:
/*! \brief Constructor.
\param msg Message explanining the error.
*/
BadArg(const std::string& msg) : msg(msg) { }
/// Destructor (does nothing special).
virtual ~BadArg() throw() { }
/// A message explaining the error.
const std::string msg;
/// Returns \a msg.
virtual const char* what() const throw() { return msg.c_str(); }
};
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

View file

@ -0,0 +1,11 @@
/* libopt++/src/libopt++/BottomHeader.h
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
#endif
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

158
src/libopt++/Parser.cpp Normal file
View file

@ -0,0 +1,158 @@
/* libopt++/src/libopt++/Parser.cpp
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
namespace opt {
Parser::Parser()
: progName(_progName), progPath(_progPath), progDir(_progDir), args(_args)
{
}
void Parser::addOption(int callbackResult, bool arg, const std::string& opt, char shopt,
const std::string& help)
{
if(!opt.size() && !shopt) throw std::invalid_argument("opt, shopt");
opts.push_back(Opt(callbackResult, arg, opt, shopt, help));
}
void Parser::parse(int argc, const char* const* argv)
{
bool parseopts = true, expectingArg = false;
int whichOpt = -1;
std::string opt;
if(argc < 1 || !argv) throw std::invalid_argument("argc/argv[]");
// get program name
if(!argv[0]) throw std::invalid_argument("argv[0]");
_progPath = argv[0];
std::string::size_type pos = _progPath.rfind('/');
if(pos != std::string::npos) {
_progName = _progPath.substr(pos + 1, std::string::npos);
_progDir = _progPath.substr(0, pos ?: 1);
} else {
_progName = _progPath;
}
// interpret remaining arguments / options
for(int i = 1; i < argc; ++i) {
const char* arg = argv[i];
if(!arg) throw std::invalid_argument("argv[]");
if(parseopts && arg[0] && arg[0] == '-' && arg[1]) {
if(expectingArg) goto missingArg;
if(arg[1] == '-') {
// long option
if(!arg[2]) parseopts = false; // -- switches off option parsing
else {
opt = arg;
whichOpt = findOpt(opt);
if(opts.at(whichOpt).arg) expectingArg = true;
else option(opts.at(whichOpt).result, opt);
}
} else {
// short option[s]
for(const char* p = arg + 1; *p; ++p) {
if(expectingArg) goto missingArg;
opt = "-x";
opt[1] = *p;
whichOpt = findOpt(opt);
if(opts.at(whichOpt).arg) expectingArg = true;
else option(opts.at(whichOpt).result, opt);
}
}
} else {
if(expectingArg) {
// option argument
expectingArg = false;
option(opts.at(whichOpt).result, opt, arg);
} else {
// program argument
_args.push_back(arg);
}
}
}
if(!expectingArg) return;
missingArg:
std::ostringstream str;
str << "Option '" << opt << "' is missing an argument.";
throw BadArg(str.str());
}
void Parser::showHelp(std::ostream& str) const
{
const uint end = opts.size();
std::string::size_type max = 0;
char oldfill = str.fill(' ');
std::ios_base::fmtflags oldfmt = str.setf(std::ios_base::left, std::ios_base::adjustfield);
for(uint i = 0; i < end; ++i) {
if(!opts[i].opt.size()) continue;
max = std::max(max, opts[i].opt.size() + (opts[i].arg ? 6 : 0));
}
for(uint i = 0, end = opts.size(); i < end; ++i) {
str << " ";
if(opts[i].shopt) {
str << '-' << opts[i].shopt;
if(opts[i].opt.size()) {
str << ", --" << std::setw(max - (opts[i].arg ? 6 : 0)) << opts[i].opt;
if(opts[i].arg) str << " <arg>";
} else {
if(opts[i].arg) str << " <arg> " << std::setw(max - 6) << ' ';
else str << std::setw(max) << ' ';
}
} else {
str << " --" << std::setw(max - (opts[i].arg ? 6 : 0)) << opts[i].opt;
if(opts[i].arg) str << " <arg>";
}
str << " " << opts[i].help << '\n';
}
str << " Short options without arguments may be combined. Pass -- to\n"
" stop processing options.\n";
str.fill(oldfill);
str.setf(oldfmt, std::ios_base::adjustfield);
}
uint Parser::findOpt(const std::string& opt)
{
const uint end = opts.size();
if(opt[1] == '-') {
std::string opt2 = opt.substr(2, std::string::npos);
for(uint pos = 0; pos < end; ++pos) if(opts[pos].opt == opt2) return pos;
} else {
for(uint pos = 0; pos < end; ++pos) if(opts[pos].shopt == opt[1]) return pos;
}
std::ostringstream str;
str << "Unrecognsied option '" << opt << "'.";
throw BadArg(str.str());
}
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

141
src/libopt++/Parser.h Normal file
View file

@ -0,0 +1,141 @@
/* libopt++/src/libopt++/Parser.h
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
namespace opt {
/*! \brief Main option parser.
This class is responsible for parsing commandline options. It is an abstract base class; you must
derive from it and overload the option() functions. These specify the behaviour on encountering
options.
To use the class, you must first instantiate it and then call addOption() for each option your
program understands. Once this is complete, you can call parse() with the argc/argv that were passed
to your program's main().
parse() will set \ref progName, \ref progPath and \ref progDir appropriately, and will call option()
for each valid option it encounters. It will store any non-option arguments in the \ref args vector.
*/
class Parser {
public:
/// Constructor (does nothing special).
Parser();
/// Destructor (does nothing special).
virtual ~Parser() throw() { }
/*! \brief Registers an option that the program understands.
\param callbackResult This is what is passed to option() as the \a result argument.
\param arg \a true if the option requires an argument, \a false if not.
\param opt The options long name, excluding leading \c --. May be empty.
\param shopt The short option character (used in e.g. \c -v). May be 0 (no short option).
\param help A string displayed when showHelp() is called. May be empty.
\throws std::invalid_argument if \a opt is empty and \a shopt is 0.
This registers an option that the program understands with the parser engine. Each option has
a corresponding code, \a callbackResult, that is used to uniquely identify it. This is parsed
to the option() callback as the first argument, \a result. An option may have both short and
long forms.
*/
void addOption(int callbackResult, bool arg, const std::string& opt, char shopt = 0,
const std::string& help = "");
/*! \brief Parse commandline options.
\param argc argc from main(), the argument count.
\param argv argv from main(), the argument vector.
\throws std::invalid_argument if argc or argv are invalid in some way (this won't happen if you
pass them directly from main).
\throws Opt::BadArg if an option is unrecognised or missing an argument.
*/
void parse(int argc, const char* const* argv);
/*! \brief Display help.
\param ostr The output stream to display help onto (typically \a std::cout).
This function displays a nicely-formatted list of options to be used as part of a help screen.
It uses the \a help string passed to addOption() to display information about each option.
*/
void showHelp(std::ostream& ostr) const;
/// The program name (filename only, no path).
const std::string& progName;
/// The program path (full filename and path, i.e. argv[0]).
const std::string& progPath;
/// The program directory (relative, without filename).
const std::string& progDir;
/// A list of the arguments (non-option items on the commandline).
const std::vector<std::string>& args;
/*! \brief Option callback.
\param result The result code given as \a callbackResult in addOption().
\param opt The formatted option name (i.e. "-x" or "--long").
This function is the callback for options encountered in parse(). This version does not take
any arguments.
*/
virtual void option(int result, const std::string& opt) = 0;
/*! \brief Option callback.
\param result The result code given as \a callbackResult in addOption().
\param opt The formatted option name (i.e. "-x" or "--long").
\param arg The argument following the option.
This function is the callback for options encountered in parse(). This version takes a
mandatory argument.
*/
virtual void option(int result, const std::string& opt, const std::string& arg) = 0;
private:
std::string _progName, _progPath, _progDir;
std::vector<std::string> _args;
struct Opt {
int result;
bool arg;
std::string opt;
char shopt;
std::string help;
Opt(int result, bool arg, const std::string& opt, char shopt, const std::string& help)
: result(result), arg(arg), opt(opt), shopt(shopt), help(help)
{ }
};
std::vector<Opt> opts;
uint findOpt(const std::string& opt);
};
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

27
src/libopt++/TopHeader.h Normal file
View file

@ -0,0 +1,27 @@
/* libopt++/src/libopt++/TopHeader.h
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
#ifndef HEADER_liboptpp
#define HEADER_liboptpp
// standard includes, or includes needed for type declarations
#include <string>
#include <vector>
#include <ios>
#include <stdexcept>
/*! \brief libopt++ namespace
*
* Contains classes used to parse commandline options (argc, argv). Like getopt, only for C++.
* The main class is Opt::Parser, which is an abstract base class (override its option() methods).
* There is also an exception class, BadArg, derived from std::exception.
*
* */
namespace opt { }
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

View file

@ -0,0 +1,16 @@
/* libopt++/src/libopt++/TopSource.cpp
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
#include "opt"
// Below are all the includes used throughout the library.
#include <ostream>
#include <iomanip>
#include <sstream>
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

View file

@ -0,0 +1 @@
source src/libopt++/build.lib

View file

@ -0,0 +1 @@
source src/libopt++/build.install-lib

View file

@ -0,0 +1,36 @@
build_target libopt++
# make paths (this is for Gentoo in particular)
build_dir_tree "${LIBDIR}" || return 1
build_dir_tree "${PKGCONFDIR}" || return 1
build_dir_tree "${INCLUDEDIR}" || return 1
# install library
echo "Installing libraries into '${LIBDIR}'"
install_file ${liboptpp} ${LIBDIR} 0755 || return 1
BASE="${liboptpp_BASE}.so"
MAJOR="${BASE}.${SOMAJOR}"
MINOR="${MAJOR}.${SOMINOR}"
MICRO="${MINOR}.${SOMICRO}"
install_symlink "${MINOR}" "${MICRO}" "${LIBDIR}"
install_symlink "${MAJOR}" "${MINOR}" "${LIBDIR}"
install_symlink "${BASE}" "${MAJOR}" "${LIBDIR}"
# install header
echo "Installing header file '${liboptpp_HEADER}' into ${INCLUDEDIR}"
install_header ${liboptpp_HEADER} ${INCLUDEDIR} 0644 || return 1
# install pkgconfig file
echo "Installing package config file into ${PKGCONFDIR}"
PKGCONFFILE=${PKGCONFDIR}/libopt++.pc
do_cmd rm -f ${PKGCONFFILE}
do_cmd_redir ${PKGCONFFILE} sed \
-e "s,@VERSION@,${VERSION}," \
-e "s,@LIBDIR@,${FINALLIBDIR}," \
-e "s,@INCLUDEDIR@,${FINALINCLUDEDIR}," \
src/libopt++/pkgconf.in
do_cmd chmod 0644 ${PKGCONFFILE}
print_success "Done"
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

51
src/libopt++/build.lib Normal file
View file

@ -0,0 +1,51 @@
# These are external variables, and shouldn't clash with anything else
# liboptpp
# liboptpp_BUILT
# liboptpp_HEADER
# liboptpp_BASE
if [ -z ${liboptpp_BUILT} ]
then
liboptpp_BASE=libopt++
source src/libopt++/soversion
liboptpp="obj/${liboptpp_BASE}.so.${SOMAJOR}.${SOMINOR}.${SOMICRO}"
SO_EXTRA="-lstdc++ -lc"
echo "Building library ${liboptpp}..."
do_cmd source src/libopt++/build.monolithic || return 1
MODIFIED=0
for test in ${MONOLITHIC_TESTS} ${HDR} ${SRC}
do
if [ ${test} -nt ${liboptpp} ]
then
MODIFIED=1
break
fi
done
if [ ${MODIFIED} -ne 0 ]
then
echo " Compiling"
SONAME="${liboptpp_BASE}.so.${SOMAJOR}.${SOMINOR}"
do_cmd ${CXX} ${CFLAGS} -shared -fpic -o "${liboptpp}" \
-Wl,-soname,${SONAME} \
${SRC} ${SO_EXTRA} || return 1
# make tests work
do_cmd ln -sf $(basename ${liboptpp}) obj/${SONAME} || return 1
print_success "Library built"
else
print_success "Library up to date"
fi
liboptpp_BUILT=1
liboptpp_HEADER=${HDR}
fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

View file

@ -0,0 +1,21 @@
# These are external variables, and shouldn't clash with anything else
# liboptpp_MONOLITHIC
SRC="obj/libopt++.cpp"
HDR="obj/opt"
MONOLITHIC_TESTS="src/libopt++/build.lib src/libopt++/build.monolithic"
if [ -z "${liboptpp_MONOLITHIC}" ]
then
MONOLITHIC_SOURCE="$(echo src/libopt++/{TopHeader,BadArg,Parser,BottomHeader}.h)"
make_monolithic ${HDR} C || return 1
MONOLITHIC_SOURCE="$(echo src/libopt++/{TopSource,Parser}.cpp)"
make_monolithic ${SRC} C || return 1
liboptpp_MONOLITHIC=1
MONOLITHIC_DOC="${MONOLITHIC_DOC} ${HDR}"
fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

21
src/libopt++/pkgconf.in Normal file
View file

@ -0,0 +1,21 @@
# libopt++/src/lib/libopt++/pkgconf.in
#
# Metadata file for pkg-config
# ( http://www.freedesktop.org/software/pkgconfig/ )
#
# (c)2006, Laurence Withers, <l@lwithers.me.uk>.
# Released under the GNU GPLv2. See file COPYING or
# http://www.gnu.org/copyleft/gpl.html for details.
#
# Name, description
Name: libopt++
Description: C++ library for parsing commandline options (getopt replacement).
Version: @VERSION@
# Requirements
Requires:
# Compilation information
Libs: -L@LIBDIR@ -lopt++
Cflags: -I@INCLUDEDIR@

17
src/libopt++/soversion Normal file
View file

@ -0,0 +1,17 @@
# libopt++/src/libopt++/soversion
#
# (c)2006, Laurence Withers, <l@lwithers.me.uk>.
# Released under the GNU GPLv2. See file COPYING or
# http://www.gnu.org/copyleft/gpl.html for details.
#
# SOMAJOR and SOMINOR are included in the library's soname. They need to
# be bumped on a binary-incompatible release. They are both single
# integers.
SOMAJOR=0
SOMINOR=0
# SOMICRO is bumped every time there is a binary-compatible release.
SOMICRO=0

1
src/tests/.params Normal file
View file

@ -0,0 +1 @@
c++ tests tests libopt++

3
src/tests/build.default Normal file
View file

@ -0,0 +1,3 @@
source src/tests/build.tests
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

43
src/tests/build.tests Normal file
View file

@ -0,0 +1,43 @@
# These are external variables, and shouldn't clash with anything else
# tests_BUILT
#
build_target libopt++ || return 1
if [ -z ${tests_BUILT} ]
then
LIBS="${liboptpp}"
EXTRAS=""
echo "Building test programs..."
do_cmd mkdir -p obj/tests || return 1
for SRC in src/tests/*.cpp
do
TEST="obj/tests/$(basename ${SRC} | sed -e 's,.cpp$,,')"
MODIFIED=0
for file in ${LIBS} ${SRC} src/tests/build.tests
do
if [ ${file} -nt ${TEST} ]
then
MODIFIED=1
break
fi
done
if [ ${MODIFIED} -ne 0 ]
then
do_cmd ${CXX} -Iobj ${CFLAGS} -o ${TEST} ${SRC} ${LIBS} ${EXTRAS} || return 1
print_success "Built ${TEST}"
else
print_success "${TEST} is up to date"
fi
done
print_success "All tests built"
tests_BUILT=1
fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

98
src/tests/simple.cpp Normal file
View file

@ -0,0 +1,98 @@
/* libopt++/src/tests/simple.cpp
*
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
* COPYING for more information / terms of license.
*/
#include "opt"
#include <iostream>
class Opt : private opt::Parser {
public:
Opt(int argc, const char* const* argv)
: quiet(false)
{
addOption(OptSummary, false, "print-summary", 0, "Displays a one-line summary of usage.");
addOption(OptHelp, false, "help", 'h', "Displays options and usage.");
addOption(OptPrint, true, "print", 'p', "Prints a string.");
addOption(OptPrint, true, "", 'P', "As -p.");
parse(argc, argv);
}
virtual ~Opt() throw() { }
void displayArgs()
{
if(quiet) return;
std::cout << "\nprogName = " << progName
<< "\nprogPath = " << progPath
<< "\nprogDir = " << progDir
<< "\n";
for(uint i = 0, end = args.size(); i != end; ++i) std::cout << "Argument: " << args[i] << "\n";
}
private:
enum { OptSummary, OptHelp, OptPrint };
bool quiet;
virtual void option(int result, const std::string& opt)
{
switch(result) {
case OptSummary:
std::cout << "A simple example program with a couple of options.\n";
quiet = true;
break;
case OptHelp:
std::cout << "Usage:\n\n "
<< progName << " [options] args\n\n";
showHelp(std::cout);
break;
default:
std::cerr << "Unrecognised option " << result << " (" << opt <<
") -- this is a program bug.\n";
}
}
virtual void option(int result, const std::string& opt, const std::string& arg)
{
switch(result) {
case OptPrint:
std::cout << opt << ": " << arg << "\n";
break;
default:
std::cerr << "Unrecognised option " << result << " (" << opt << ' ' << arg <<
") -- this is a program bug.\n";
}
}
};
int main(int argc, char* argv[])
{
int ret = 0;
try {
Opt o(argc, argv);
o.displayArgs();
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
ret = 1;
}
catch(...) {
std::cerr << "Unknown exception caught." << std::endl;
ret = 1;
}
return ret;
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
*/

43
src/tests/template Normal file
View file

@ -0,0 +1,43 @@
/* libopt++/src/tests/???.cpp
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
#include "opt"
#include <iostream>
int main(int argc, char* argv[])
{
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
std::cout << "One line summary.\n";
return 0;
}
if(argc == 1) {
// empty argument list
}
int ret = 0;
try {
// TODO
}
catch(std::exception& e) {
std::cerr << e.what() << std::endl;
ret = 1;
}
catch(...) {
std::cerr << "Unknown exception caught." << std::endl;
ret = 1;
}
return ret;
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4
*/