[libticcutils] 01/03: Imported Upstream version 0.7
Joost van Baal
joostvb at moszumanska.debian.org
Thu Oct 30 07:05:19 UTC 2014
This is an automated email from the git hooks/post-receive script.
joostvb pushed a commit to branch master
in repository libticcutils.
commit c0d300f5dc07c4087f7925ed176fc63d563dc78a
Author: Joost van Baal-Ilić <joostvb at nusku.mdcc.cx>
Date: Thu Oct 30 07:53:11 2014 +0100
Imported Upstream version 0.7
---
ChangeLog | 122 +++++++++
NEWS | 12 +
configure | 20 +-
configure.ac | 4 +-
include/ticcutils/CommandLine.h | 62 ++++-
include/ticcutils/Configuration.h | 8 +-
include/ticcutils/FileUtils.h | 3 +-
include/ticcutils/LogStream.h | 4 +-
include/ticcutils/StringOps.h | 5 +-
src/CommandLine.cxx | 547 ++++++++++++++++++++++++++------------
src/Configuration.cxx | 35 +--
src/LogStream.cxx | 4 +-
src/StringOps.cxx | 18 +-
src/runtest.cxx | 167 ++++++++++--
tests/Makefile.am | 4 +-
tests/Makefile.in | 4 +-
tests/testconfig.cfg | 5 +
17 files changed, 782 insertions(+), 242 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9c236bc..7462b04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,125 @@
+2014-09-16 14:30 sloot
+
+ * [r17678] NEWS, src/runtest.cxx, tests/Makefile.am: fixed 'make
+ distcheck'
+ updated NEWS
+
+2014-09-11 14:43 mvgompel
+
+ * [r17645] src/LogStream.cxx: fix
+
+2014-09-09 15:54 sloot
+
+ * [r17635] src/runtest.cxx: added an extra test
+
+2014-09-08 10:53 sloot
+
+ * [r17622] src/CommandLine.cxx, src/runtest.cxx: fixed problem with
+ '='/
+ added test
+
+2014-09-08 10:24 mvgompel
+
+ * [r17621] include/ticcutils/LogStream.h: solved ambiguity because
+ of default first argument
+
+2014-09-08 08:46 sloot
+
+ * [r17617] include/ticcutils/Configuration.h,
+ src/Configuration.cxx: better solution for previous fix
+
+2014-09-07 19:16 mvgompel
+
+ * [r17615] include/ticcutils/Configuration.h: fix for missing /
+ after path problem, getConfigDir always returns trailing slash,
+ fixed frog bug (Ko, verify?)
+
+2014-09-01 13:52 sloot
+
+ * [r17579] include/ticcutils/CommandLine.h: more backward stuff
+
+2014-09-01 13:48 sloot
+
+ * [r17578] include/ticcutils/CommandLine.h,
+ include/ticcutils/FileUtils.h: add backward compatibility stuff
+
+2014-08-28 14:34 sloot
+
+ * [r17575] include/ticcutils/CommandLine.h,
+ include/ticcutils/StringOps.h, src/CommandLine.cxx,
+ src/Configuration.cxx, src/StringOps.cxx, src/runtest.cxx: added
+ functions and tests
+
+2014-08-26 14:27 sloot
+
+ * [r17573] src/CommandLine.cxx, src/runtest.cxx: fix and added
+ tests to prove
+
+2014-08-26 13:40 sloot
+
+ * [r17569] include/ticcutils/CommandLine.h, src/CommandLine.cxx,
+ src/Configuration.cxx, src/runtest.cxx, tests/testconfig.cfg:
+ Configuration now correctly handles attribute-values with
+ embedded '='
+ Added Configuration tests to runtest
+
+2014-08-25 10:53 sloot
+
+ * [r17554] include/ticcutils/CommandLine.h, src/CommandLine.cxx:
+ added set)debug()
+
+2014-08-25 09:45 sloot
+
+ * [r17547] configure.ac, include/ticcutils/CommandLine.h,
+ src/CommandLine.cxx, src/runtest.cxx: fixed problems.
+ added testcase.
+ bumped version bacause of API/ABI breaches
+
+2014-08-21 15:22 sloot
+
+ * [r17543] include/ticcutils/CommandLine.h, src/CommandLine.cxx,
+ src/runtest.cxx: added support for options with optional
+ arguments
+
+2014-08-21 14:16 sloot
+
+ * [r17542] include/ticcutils/CommandLine.h, src/CommandLine.cxx,
+ src/runtest.cxx: a lot of rework on CommandLine. added more tests
+ too
+
+2014-08-20 16:14 sloot
+
+ * [r17541] src/runtest.cxx: added a test for classic mode
+
+2014-08-20 16:13 sloot
+
+ * [r17540] src/CommandLine.cxx: allow duplicates in the mas
+ options. Be sure to preserver order too!
+
+2014-08-20 14:05 sloot
+
+ * [r17538] include/ticcutils/CommandLine.h, src/CommandLine.cxx,
+ src/runtest.cxx: added a 'classic' mode to CommandLine: this
+ allows for options like:
+ '--sett true'. Normally we demand '--sett=true' (Timbl like
+ options).
+
+2014-08-08 11:45 sloot
+
+ * [r17496] configure.ac, include/ticcutils/Tar.h,
+ include/ticcutils/UnitTest.h, src/Tar.cxx, src/runtest.cxx,
+ src/zipper.cxx: now builds stubs when libtar-dev or libbz2-dev ar
+ not installed.
+ improved UnitTest.h
+
+2014-07-16 15:14 sloot
+
+ * [r17458] src/Configuration.cxx: formatting
+
+2014-06-11 11:52 sloot
+
+ * [r17326] NEWS: News!
+
2014-06-11 11:45 sloot
* [r17325] m4/ax_boost_regex.m4, src/Makefile.am, src/runtest.cxx,
diff --git a/NEWS b/NEWS
index 1ea388c..785506f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,15 @@
+23 sept 2014 0.7
+[Ko vd Sloot]
+- release
+
+16 sept 2014 0.6
+[Ko vd Sloot]
+- small bug fixes in LogStream, FileUtils
+- improved UnitTest
+- better 'make check' and 'make distcheck'
+- reworked CommandLine stuff
+- added basename() and dirname()to StringOps
+
11 june 2014 0.5
- added CommandLine stuff
- added FileUtils
diff --git a/configure b/configure
index 71cfef3..bbfbaef 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for ticcutils 0.5.
+# Generated by GNU Autoconf 2.69 for ticcutils 0.7.
#
# Report bugs to <timbl at uvt.nl>.
#
@@ -589,8 +589,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='ticcutils'
PACKAGE_TARNAME='ticcutils'
-PACKAGE_VERSION='0.5'
-PACKAGE_STRING='ticcutils 0.5'
+PACKAGE_VERSION='0.7'
+PACKAGE_STRING='ticcutils 0.7'
PACKAGE_BUGREPORT='timbl at uvt.nl'
PACKAGE_URL=''
@@ -1341,7 +1341,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures ticcutils 0.5 to adapt to many kinds of systems.
+\`configure' configures ticcutils 0.7 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1411,7 +1411,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of ticcutils 0.5:";;
+ short | recursive ) echo "Configuration of ticcutils 0.7:";;
esac
cat <<\_ACEOF
@@ -1539,7 +1539,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-ticcutils configure 0.5
+ticcutils configure 0.7
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2192,7 +2192,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by ticcutils $as_me 0.5, which was
+It was created by ticcutils $as_me 0.7, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -3055,7 +3055,7 @@ fi
# Define the identity of the package.
PACKAGE='ticcutils'
- VERSION='0.5'
+ VERSION='0.7'
cat >>confdefs.h <<_ACEOF
@@ -17474,7 +17474,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by ticcutils $as_me 0.5, which was
+This file was extended by ticcutils $as_me 0.7, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -17540,7 +17540,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-ticcutils config.status 0.5
+ticcutils config.status 0.7
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
diff --git a/configure.ac b/configure.ac
index 86a070b..fb8bf9e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,10 +1,10 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-# $Id: configure.ac 17496 2014-08-08 11:45:40Z sloot $
+# $Id: configure.ac 17547 2014-08-25 09:45:20Z sloot $
# $URL $
AC_PREREQ(2.61)
-AC_INIT([ticcutils],[0.5],[timbl at uvt.nl])
+AC_INIT([ticcutils],[0.7],[timbl at uvt.nl])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([.])
AC_CONFIG_MACRO_DIR([m4])
diff --git a/include/ticcutils/CommandLine.h b/include/ticcutils/CommandLine.h
index 1d54d56..c9425e6 100644
--- a/include/ticcutils/CommandLine.h
+++ b/include/ticcutils/CommandLine.h
@@ -62,6 +62,7 @@ namespace TiCC {
const std::string& Option() const { return option; };
bool isLong() const { return longOpt; };
bool getMood() const { return mood; };
+ std::string toString( ) const;
private:
std::string opt_word;
std::string option;
@@ -76,31 +77,80 @@ namespace TiCC {
CL_Options( const int, const char * const *,
const std::string& = "", const std::string& = "" );
~CL_Options();
+ typedef std::vector<CL_item>::const_iterator const_iterator;
+ const_iterator begin() const { return Opts.begin(); };
+ const_iterator end() const { return Opts.end(); };
bool init( const int, const char * const * );
bool init( const std::string& );
void set_short_options( const std::string& s );
void set_long_options( const std::string& s );
- bool find( const char, std::string&, bool& ) const;
- bool find( const std::string&, std::string& ) const;
- bool pull( const char, std::string&, bool& );
- bool pull( const std::string&, std::string& );
+ std::string prog_name() const { return _prog_name; };
+ std::string get_short_options() const;
+ std::string get_long_options() const;
+ bool is_present( const char, std::string&, bool& ) const;
+ bool find( const char c, std::string& s, bool& b ) const {
+ return is_present( c, s, b );
+ }
+ bool is_present( const char c, std::string& s ) const {
+ bool b;
+ return is_present( c, s, b );
+ }
+ bool is_present( const char c ) const {
+ bool b;
+ std::string v;
+ return is_present( c, v, b );
+ }
+ bool is_present( const std::string&, std::string& ) const;
+ bool find( const std::string& w, std::string& s ) const {
+ return is_present( w, s );
+ }
+ bool is_present( const std::string& s ) const {
+ std::string v;
+ return is_present( s, v );
+ }
+ bool extract( const char, std::string&, bool& );
+ bool pull( const char c, std::string& s, bool& b){
+ return extract( c, s, b ); };
+ bool extract( const char c, std::string& s ){
+ bool b;
+ return extract( c, s, b );
+ };
+ bool extract( const char c ){
+ bool b;
+ std::string v;
+ return extract( c, v, b );
+ };
+ bool extract( const std::string&, std::string& );
+ bool pull( const std::string& w, std::string& s) {
+ return extract( w, s ); };
+ bool extract( const std::string& s ){
+ std::string v;
+ return extract( s, v );
+ }
bool remove( const char, bool = false );
- bool remove( const std::string& );
+ bool remove( const std::string&, bool = false );
void insert( const char, const std::string&, bool );
void insert( const std::string&, const std::string& );
bool empty() const { return Opts.empty(); };
+ void set_debug( bool b ) { debug = b; };
+ std::string toString() const;
+ std::ostream& dump( std::ostream& );
const std::vector<std::string>& getMassOpts() const { return MassOpts; };
private:
- bool Split_Command_Line( const int, const char * const * );
+ bool Parse_Command_Line( const int, const char * const * );
std::vector<CL_item> Opts;
std::vector<std::string> MassOpts;
CL_Options( const CL_Options& );
CL_Options& operator=( const CL_Options& );
std::set<char> valid_chars;
std::set<char> valid_chars_par;
+ std::set<char> valid_chars_opt;
std::set<std::string> valid_long;
std::set<std::string> valid_long_par;
+ std::set<std::string> valid_long_opt;
+ std::string _prog_name;
bool is_init;
+ bool debug;
};
class OptionError: public std::runtime_error {
diff --git a/include/ticcutils/Configuration.h b/include/ticcutils/Configuration.h
index d1c8bf5..b14e978 100644
--- a/include/ticcutils/Configuration.h
+++ b/include/ticcutils/Configuration.h
@@ -1,5 +1,5 @@
/*
- $Id: Configuration.h 16425 2013-08-13 13:08:41Z sloot $
+ $Id: Configuration.h 17617 2014-09-08 08:46:52Z sloot $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/include/ticcutils/Configuration.h $
Copyright (c) 2006 - 2013
@@ -14,7 +14,7 @@
ticcutils 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
+ 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
@@ -46,8 +46,8 @@ namespace TiCC {
std::string lookUp( const std::string&, const std::string& = "" ) const;
ssMap lookUpAll( const std::string& ) const;
std::set<std::string> lookUpSections() const;
- std::string setatt( const std::string&,
- const std::string&,
+ std::string setatt( const std::string&,
+ const std::string&,
const std::string& = "" );
void dump( std::ostream& ) const;
std::string configDir() const { return cdir; };
diff --git a/include/ticcutils/FileUtils.h b/include/ticcutils/FileUtils.h
index 5bc751e..dcdbca5 100644
--- a/include/ticcutils/FileUtils.h
+++ b/include/ticcutils/FileUtils.h
@@ -1,5 +1,5 @@
/*
- $Id: FileUtils.h 17075 2014-03-31 10:54:22Z sloot $
+ $Id: FileUtils.h 17578 2014-09-01 13:48:32Z sloot $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/include/ticcutils/FileUtils.h $
Copyright (c) 1998 - 2014
@@ -31,7 +31,6 @@
#ifndef TICC_FILE_UTILS_H
#define TICC_FILE_UTILS_H
-#include "config.h"
namespace TiCC {
std::vector<std::string> glob( const std::string&);
diff --git a/include/ticcutils/LogStream.h b/include/ticcutils/LogStream.h
index 6989120..e8b9650 100644
--- a/include/ticcutils/LogStream.h
+++ b/include/ticcutils/LogStream.h
@@ -1,5 +1,5 @@
/*
- $Id: LogStream.h 16817 2014-01-06 10:07:03Z sloot $
+ $Id: LogStream.h 17621 2014-09-08 10:24:50Z mvgompel $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/include/ticcutils/LogStream.h $
Copyright (c) 1998 - 2014
@@ -76,7 +76,7 @@ namespace TiCC {
public:
LogStream();
LogStream( int );
- LogStream( const std::string& ="", LogFlag = StampBoth );
+ LogStream( const std::string&, LogFlag = StampBoth );
LogStream( std::ostream&, const std::string& = "",
LogFlag = StampBoth );
LogStream( const LogStream&, const std::string&, LogFlag );
diff --git a/include/ticcutils/StringOps.h b/include/ticcutils/StringOps.h
index 39a290b..8bca6e1 100644
--- a/include/ticcutils/StringOps.h
+++ b/include/ticcutils/StringOps.h
@@ -1,5 +1,5 @@
/*
- $Id: StringOps.h 16817 2014-01-06 10:07:03Z sloot $
+ $Id: StringOps.h 17575 2014-08-28 14:34:22Z sloot $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/include/ticcutils/StringOps.h $
Copyright (c) 1998 - 2014
@@ -116,6 +116,9 @@ namespace TiCC {
return dummy.str();
}
+ std::string basename( const std::string& );
+ std::string dirname( const std::string& );
+
}
#endif
diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx
index 210b5a0..a4359e6 100644
--- a/src/CommandLine.cxx
+++ b/src/CommandLine.cxx
@@ -30,6 +30,7 @@
#include <cassert>
#include <string>
#include <vector>
+#include <map>
#include <ostream>
#include <iostream>
@@ -43,6 +44,7 @@ namespace TiCC {
CL_Options::CL_Options( const string& short_o, const string& long_o ){
is_init = false;
+ debug = false;
set_short_options( short_o );
set_long_options( long_o );
}
@@ -50,6 +52,7 @@ namespace TiCC {
CL_Options::CL_Options( const int argc, const char * const *argv,
const string& valid_s, const string& valid_l ){
is_init = false;
+ debug = false;
set_short_options( valid_s );
set_long_options( valid_l );
init( argc, argv );
@@ -62,7 +65,7 @@ namespace TiCC {
if ( is_init ){
throw OptionError( "cannot init() an options object twice" );
}
- if ( Split_Command_Line( argc, argv ) )
+ if ( Parse_Command_Line( argc, argv ) )
is_init = true;
return is_init;
}
@@ -72,59 +75,62 @@ namespace TiCC {
throw OptionError( "cannot init() an options object twice" );
}
const char *argstr = args.c_str();
- if ( Split_Command_Line( 0, &argstr ) )
+ if ( Parse_Command_Line( 0, &argstr ) )
is_init = true;
return is_init;
}
ostream& operator<<( ostream& os, const CL_item& it ){
- if ( it.longOpt ){
- os << "--" << it.opt_word;
- if ( !it.option.empty() )
- os << "=" << it.option;
+ os << it.toString();
+ return os;
+ }
+
+ string CL_item::toString( ) const {
+ string result;
+ if ( longOpt ){
+ result = "--" + opt_word;
+ if ( !option.empty() ){
+ result += "=";
+ }
+ result += option;
}
else
- os << (it.mood ? "+": "-" ) << it.opt_word << it.option;
- return os;
+ result += (mood ? "+": "-" ) + opt_word + option;
+ return result;
}
ostream& operator<<( ostream& os, const CL_Options& cl ){
- vector<CL_item>::const_iterator pos = cl.Opts.begin();
- while ( pos != cl.Opts.end() ){
- os << *pos << " ";
- ++pos;
- }
+ os << cl.toString() << " ";
for ( size_t i=0; i < cl.MassOpts.size(); ++i ){
os << cl.MassOpts[i] << " ";
}
- if ( !cl.valid_chars.empty() ){
+ return os;
+ }
+
+ string CL_Options::toString() const {
+ string result;
+ vector<CL_item>::const_iterator pos = Opts.begin();
+ while ( pos != Opts.end() ){
+ result += pos->toString() + " ";
+ ++pos;
+ }
+ return result;
+ }
+
+ ostream& CL_Options::dump( ostream& os ) {
+ os << *this;
+ if ( !valid_chars.empty() ){
os << endl;
- os << "Valid short options: ";
- set<char>::const_iterator it = cl.valid_chars.begin();
- while ( it != cl.valid_chars.end() ){
- os << *it;
- if ( cl.valid_chars_par.find( *it ) != cl.valid_chars_par.end() )
- os << ":";
- ++it;
- }
+ os << "Valid short options: " << get_short_options();
}
- if ( !cl.valid_long.empty() ){
+ if ( !valid_long.empty() ){
os << endl;
- os << "Valid long options: ";
- set<string>::const_iterator it = cl.valid_long.begin();
- while ( it != cl.valid_long.end() ){
- os << *it;
- if ( cl.valid_long_par.find( *it ) != cl.valid_long_par.end() )
- os << ":";
- ++it;
- if ( it != cl.valid_long.end() )
- os << ",";
- }
+ os << "Valid long options: " << get_long_options();
}
return os;
}
- bool CL_Options::find( const char c, string &opt, bool& mood ) const {
+ bool CL_Options::is_present( const char c, string &opt, bool& mood ) const {
vector<CL_item>::const_iterator pos;
for ( pos = Opts.begin(); pos != Opts.end(); ++pos ){
if ( pos->isLong() )
@@ -132,32 +138,71 @@ namespace TiCC {
if ( pos->OptChar() == c ){
opt = pos->Option();
mood = pos->Mood();
+ if ( debug ){
+ cerr << "is_present '" << c << "' ==> '" << opt << "'" << endl;
+ }
return true;
}
}
+ if ( debug ){
+ cerr << "is_present '" << c << "' FAILS " << endl;
+ }
return false;
}
- bool CL_Options::find( const string& w, string &opt ) const {
+ bool CL_Options::is_present( const string& w, string &opt ) const {
vector<CL_item>::const_iterator pos;
for ( pos = Opts.begin(); pos != Opts.end(); ++pos ){
if ( pos->OptWord() == w ){
opt = pos->Option();
+ if ( debug ){
+ cerr << "is_present '" << w << "' ==> '" << opt << "'" << endl;
+ }
return true;
}
}
+ if ( debug ){
+ cerr << "is_present '" << w << "' FAILS " << endl;
+ }
return false;
}
- bool CL_Options::pull( const char c, string &opt, bool& mood ) {
- if ( find( c, opt, mood ) )
- return remove( c );
+ bool CL_Options::extract( const char c, string &opt, bool& mood ) {
+ vector<CL_item>::iterator pos;
+ for ( pos = Opts.begin(); pos != Opts.end(); ++pos ){
+ if ( !pos->isLong() ){
+ if ( pos->OptChar() == c ){
+ opt = pos->Option();
+ mood = pos->Mood();
+ Opts.erase(pos);
+ if ( debug ){
+ cerr << "extract '" << c << "' ==> '" << opt << "'" << endl;
+ }
+ return true;
+ }
+ }
+ }
+ if ( debug ){
+ cerr << "extract '" << c << "' FAILS " << endl;
+ }
return false;
}
- bool CL_Options::pull( const string& w, string &opt ) {
- if ( find( w, opt ) )
- return remove( w );
+ bool CL_Options::extract( const string& w, string &opt ) {
+ vector<CL_item>::iterator pos;
+ for ( pos = Opts.begin(); pos != Opts.end(); ++pos ){
+ if ( pos->OptWord() == w ){
+ opt = pos->Option();
+ Opts.erase(pos);
+ if ( debug ){
+ cerr << "extract '" << w << "' ==> '" << opt << "'" << endl;
+ }
+ return true;
+ }
+ }
+ if ( debug ){
+ cerr << "extract '" << w << "' FAILS " << endl;
+ }
return false;
}
@@ -169,17 +214,23 @@ namespace TiCC {
if ( !all )
return true;
}
- ++pos;
+ else {
+ ++pos;
+ }
}
return false;
}
- bool CL_Options::remove( const string& w ){
+ bool CL_Options::remove( const string& w, bool all ){
vector<CL_item>::iterator pos;
- for ( pos = Opts.begin(); pos != Opts.end(); ++pos ){
+ for ( pos = Opts.begin(); pos != Opts.end(); ){
if ( pos->OptWord() == w ){
- Opts.erase(pos);
- return true;
+ pos = Opts.erase(pos);
+ if ( !all )
+ return true;
+ }
+ else {
+ ++pos;
}
}
return false;
@@ -195,9 +246,45 @@ namespace TiCC {
Opts.push_back( cl );
}
- //#define DEBUG
+ enum argstat { PLUS, MIN, LONG, UNKNOWN };
+ struct arg {
+ arg(): stat(UNKNOWN),c(0){};
+ argstat stat;
+ char c;
+ string s;
+ string val;
+ };
+
+ ostream& operator<<( ostream& os, const arg& a ){
+ switch ( a.stat ){
+ case UNKNOWN:
+ os << "?";
+ os << a.s;
+ os << "=" << a.val;
+ break;
+ case PLUS:
+ os << "+";
+ os << a.c;
+ os << a.s;
+ os << "=" << a.val;
+ break;
+ case MIN:
+ os << "-";
+ os << a.c;
+ os << a.s;
+ os << "=" << a.val;
+ break;
+ case LONG:
+ os << "--";
+ os << a.s;
+ os << "=" << a.val;
+ break;
+ }
+ return os;
+ }
- bool CL_Options::Split_Command_Line( const int Argc,
+
+ bool CL_Options::Parse_Command_Line( const int Argc,
const char * const *Argv ){
Opts.clear();
vector<string> local_argv;
@@ -209,45 +296,47 @@ namespace TiCC {
else
return false;
else {
+ _prog_name = basename(Argv[0]);
for( int i=1; i < Argc; ++i ){
// start at 1 to skip the program name
local_argv.push_back( Argv[i] );
}
}
-#ifdef DEBUG
- cerr << "Option vector: " << local_argv << endl;
-#endif
+ if ( debug ){
+ cerr << "Parse_CommandLine: Option vector: " << local_argv << endl;
+ }
vector<string> cleaned;
for ( size_t i=0; i < local_argv.size(); ++i ){
string Option = local_argv[i];
-#ifdef DEBUG
- cerr << "bekijk Option = " << Option << endl;
-#endif
+ if ( debug ){
+ cerr << "examine potential option = " << Option << endl;
+ }
if ( Option.size() == 1 ){
- string msg = "stray '";
- msg += Option[0];
- msg += "'. (maybe it belongs to another option?)";
- throw OptionError( msg );
+ cleaned.push_back( Option );
+ continue;
}
char first = Option[0];
switch ( first ){
case '+':
case '-':
- if ( Option.size() <= 2 ){
+ if ( (Option.size() <= 2 || Option[1] == '-' )
+ && Option.find("=") == string::npos ) {
if ( i < local_argv.size()-1 ){
string Option2 = local_argv[i+1];
-#ifdef DEBUG
- cerr << "bekijk Option2 = " << Option2 << endl;
-#endif
+ if ( debug ){
+ cerr << "examine potential extra option: " << Option2 << endl;
+ }
if ( Option2[0] != '+' && Option2[0] != '-' ){
- Option += Option2;
+ if ( Option[1] == '-' ){
+ Option += "=" + Option2;
+ }
+ else {
+ Option += Option2;
+ }
++i;
}
}
}
-#ifdef DEBUG
- cerr << "PUSH " << Option << endl;
-#endif
cleaned.push_back( Option );
break;
case '=':
@@ -260,30 +349,26 @@ namespace TiCC {
cleaned.push_back( Option );
}
}
-#ifdef DEBUG
- cerr << "Cleaned vector: " << cleaned << endl;
-#endif
-
- map<char,string> min_shortMap;
- map<char,string> plus_shortMap;
- map<string,string> longMap;
- set<string> extra;
-
+ if ( debug ){
+ cerr << "Cleaned vector: " << cleaned << endl;
+ }
+ vector<arg> arguments;
for ( size_t i=0; i < cleaned.size(); ++i ){
- char OptChar;
- string Optword;
- string OptValue;
string Option = cleaned[i];
char first = Option[0];
+ arg argument;
switch ( first ){
case '+':
- OptChar = Option[1];
- OptValue = Option.substr(2);
- plus_shortMap[OptChar] = OptValue;
+ argument.stat = PLUS;
+ argument.c = Option[1];
+ argument.val = Option.substr(2);
+ arguments.push_back(argument);
break;
case '-':
if ( Option[1] == '-' ){
if ( Option.size() > 2 ){
+ string Optword;
+ string OptValue;
string::size_type pos = Option.find( "=" );
if ( pos == string::npos ) {
Optword = Option.substr( 2 );
@@ -292,24 +377,29 @@ namespace TiCC {
Optword = Option.substr( 2, pos-2 );
OptValue = Option.substr( pos+1 );
}
- longMap[Optword] = OptValue;
+ argument.stat = LONG;
+ argument.s = Optword;
+ argument.val = OptValue;
+ arguments.push_back(argument);
}
else {
// special: '--'
- OptChar = '-';
- min_shortMap[OptChar] = OptValue;
+ argument.stat = MIN;
+ argument.c = '-';
+ arguments.push_back(argument);
}
}
else {
- OptChar = Option[1];
- OptValue = Option.substr(2);
- min_shortMap[OptChar] = OptValue;
+ argument.stat = MIN;
+ argument.c = Option[1];
+ argument.val = Option.substr(2);
+ arguments.push_back(argument);
}
break;
case '?':
- OptChar = Option[0];
- OptValue = Option.substr(1);
- extra.insert( OptValue );
+ argument.stat = UNKNOWN;
+ argument.val = Option.substr(1);
+ arguments.push_back(argument);
break;
default:
//
@@ -317,92 +407,161 @@ namespace TiCC {
}
}
-
-#ifdef DEBUG
- cerr << "plus:: " << plus_shortMap << endl;
- cerr << "min:: " << min_shortMap << endl;
- cerr << "long: " << longMap << endl;
- cerr << "extra: " << extra << endl;
-
- cerr << "Valid chars are: " << valid_chars << endl;
- cerr << "Valid long are: " << valid_long << endl;
-#endif
- // there are some options to check?
- bool doCheck = !( valid_long.empty() && valid_chars.empty() );
+ // are there some options to check?
+ bool doCheck = !valid_long.empty() || !valid_chars.empty();
if ( doCheck ){
- map<char,string>::const_iterator it=plus_shortMap.begin();
- while ( it != plus_shortMap.end() ){
- if ( valid_chars.find( it->first ) == valid_chars.end() ){
- string msg = "illegal option '";
- msg += it->first;
- msg += "'";
- throw OptionError( msg );
- }
- else {
- if ( valid_chars_par.find( it->first ) == valid_chars_par.end() ){
- if ( !it->second.empty() ){
- string msg = "option '";
- msg += it->first;
- msg += "' may not have a value";
- throw OptionError( msg );
+ if ( debug ){
+ cerr << "check ARGUMENTS: " << arguments << endl;
+ }
+ vector<arg>::iterator it = arguments.begin();
+ while ( it != arguments.end() ){
+ if ( it->stat == LONG ){
+ if ( valid_long.find( it->s ) == valid_long.end() ){
+ throw OptionError( "invalid option '" + it->s + "'" );
+ }
+ bool has_par = valid_long_par.find( it->s ) != valid_long_par.end();
+ bool has_opt = valid_long_opt.find( it->s ) != valid_long_opt.end();
+ if ( debug ){
+ if ( has_par )
+ cerr << it->s << " must have a parameter." << endl;
+ else if ( has_opt )
+ cerr << it->s << " may have a parameter!" << endl;
+ else
+ cerr << it->s << " does'n take a parameter." << endl;
+ }
+ if ( it->val.empty() ){
+ if ( !has_par ){
+ ++it;
+ continue;
+ }
+ else {
+ vector<arg>::iterator it2 = it;
+ if ( ++it2 != arguments.end() ){
+ if ( it2->stat == UNKNOWN ){
+ it->val = it2->val;
+ arguments.erase(it2);
+ ++it;
+ continue;
+ }
+ else if ( !has_opt ){
+ throw OptionError( "missing value for long option: '"
+ + it->s + "'" );
+ }
+ else {
+ ++it;
+ continue;
+ }
+ }
+ else if ( !has_opt ){
+ throw OptionError( "missing value for long option: '"
+ + it->s + "'" );
+ ++it;
+ continue;
+ }
}
}
- // else if ( it->second.empty() ){
- // string msg = "option '";
- // msg += it->first;
- // msg += "' is missing a value";
- // throw OptionError( msg );
- // }
- }
- CL_item cl( it->first, it->second, true );
- Opts.push_back( cl );
- ++it;
- }
-
- it = min_shortMap.begin();
- while ( it != min_shortMap.end() ){
- if ( valid_chars.find( it->first ) == valid_chars.end() ){
- string msg = "illegal option '";
- msg += it->first;
- msg += "'";
- throw OptionError( msg );
+ else if ( has_par || has_opt){
+ ++it;
+ continue;
+ }
+ else {
+ MassOpts.push_back( it->val );
+ it->val.clear();
+ ++it;
+ }
}
- else {
- if ( valid_chars_par.find( it->first ) == valid_chars_par.end() ){
- if ( !it->second.empty() ){
- extra.insert( it->second );
- CL_item cl( it->first, "", false );
- Opts.push_back( cl );
+ else if ( it->stat == MIN || it->stat == PLUS ){
+ if ( valid_chars.find( it->c ) == valid_chars.end() ){
+ throw OptionError( string("invalid option '") + it->c + "'" );
+ }
+ bool has_par = valid_chars_par.find( it->c ) != valid_chars_par.end();
+ bool has_opt = valid_chars_opt.find( it->c ) != valid_chars_opt.end();
+ if ( debug ){
+ if ( has_par )
+ cerr << it->c << " must have a parameter." << endl;
+ else if ( has_opt )
+ cerr << it->c << " may have a parameter." << endl;
+ else
+ cerr << it->c << " does't take a parameter." << endl;
+ }
+ if ( it->val.empty() ){
+ if ( !has_par ){
++it;
continue;
}
+ else {
+ if ( debug ){
+ cerr << "search a parameter " << endl;
+ }
+ vector<arg>::iterator it2 = it;
+ if ( ++it2 != arguments.end() ){
+ if ( it2->stat == UNKNOWN ){
+ it->val = it2->val;
+ arguments.erase(it2);
+ ++it;
+ continue;
+ }
+ else if ( !has_opt ){
+ throw OptionError( string("missing value for option '")
+ + it->c + "'" );
+ }
+ else {
+ ++it;
+ continue;
+ }
+ }
+ else if ( !has_opt ){
+ throw OptionError( string("missing value for option ''")
+ + it->c + "'" );
+ }
+ else {
+ ++it;
+ continue;
+ }
+ }
+ }
+ else if ( has_par || has_opt ){
+ ++it;
+ continue;
+ }
+ else {
+ MassOpts.push_back( it->val );
+ it->val.clear();
+ ++it;
}
- // else if ( it->second.empty() ){
- // string msg = "option '";
- // msg += it->first;
- // msg += "' is missing a value";
- // throw OptionError( msg );
- // }
}
- CL_item cl( it->first, it->second, false );
- Opts.push_back( cl );
- ++it;
+ else if ( it->stat == UNKNOWN ){
+ MassOpts.push_back( it->val );
+ it = arguments.erase(it);
+ }
+ }
+ if ( debug ){
+ cerr << "arguments after check: " << arguments << endl;
}
- map<string,string>::const_iterator lit = longMap.begin();
- while ( lit != longMap.end() ){
- if ( valid_long.find( lit->first ) == valid_long.end() ){
- throw OptionError( "illegal option '" + string(lit->first) + "'" );
+ it = arguments.begin();
+ while ( it != arguments.end() ){
+ if ( it->stat == LONG ){
+ CL_item cl( it->s, it->val );
+ Opts.push_back( cl );
}
- CL_item cl( lit->first, lit->second );
- Opts.push_back( cl );
- ++lit;
+ else if ( it->stat == PLUS || it->stat == MIN ){
+ CL_item cl( it->c, it->val, (it->stat == PLUS) );
+ Opts.push_back( cl );
+ }
+ else {
+ MassOpts.push_back( it->val );
+ }
+ ++it;
}
}
+ if ( debug ){
+ cerr << "mass opts: " << MassOpts << endl;
+ }
- set<string>::const_iterator sit = extra.begin();
- while( sit != extra.end() ){
- MassOpts.push_back( *sit );
- ++sit;
+ if ( debug ){
+ cerr << "CL_options after Parse " << endl;
+ dump(cerr);
+ cerr << endl;
}
return true;
}
@@ -411,7 +570,12 @@ namespace TiCC {
char last = '\0';
for ( size_t i=0; i < s.size(); ++i ){
if ( s[i] == ':' && last != '\0' ){
- valid_chars_par.insert( last );
+ if ( i < s.size()-1 && s[i+1] == ':' ){
+ valid_chars_opt.insert( last );
+ ++i;
+ }
+ else
+ valid_chars_par.insert( last );
}
else {
valid_chars.insert( s[i] );
@@ -420,24 +584,65 @@ namespace TiCC {
}
}
+ string CL_Options::get_short_options() const {
+ string result;
+ set<char>::const_iterator it = valid_chars.begin();
+ while ( it != valid_chars.end() ){
+ result += *it;
+ if ( valid_chars_par.find( *it ) != valid_chars_par.end() )
+ result += ":";
+ else if ( valid_chars_opt.find( *it ) != valid_chars_opt.end() )
+ result += "::";
+ ++it;
+ }
+ return result;
+ }
+
void CL_Options::set_long_options( const string& s ){
vector<string> parts;
TiCC::split_at( s, parts, "," );
for ( size_t i=0; i < parts.size(); ++i ){
string value = parts[i];
string::size_type pos = value.find( ':' );
- if ( pos != string::npos && pos != value.size()-1){
- throw OptionError( "':' may only be present at the end of a long option ("
- + value + ")" );
- }
- if ( value[value.size()-1] == ':' ){
- value = value.substr(0,value.size()-1);
- valid_long_par.insert( value );
+ if ( pos != string::npos ){
+ if ( pos == value.size()-2){
+ if ( value[value.size()-1] == ':' ){
+ value = value.substr(0,value.size()-2);
+ valid_long_opt.insert( value );
+ }
+ else {
+ throw OptionError( "':' may only be present at the end of a long option ("
+ + value + ")" );
+ }
+ }
+ else if ( pos == value.size()-1){
+ value = value.substr(0,value.size()-1);
+ valid_long_par.insert( value );
+ }
+ else {
+ throw OptionError( "':' may only be present at the end of a long option ("
+ + value + ")" );
+ }
}
valid_long.insert( value );
}
}
-}
+ string CL_Options::get_long_options() const {
+ string result;
+ set<string>::const_iterator it = valid_long.begin();
+ while ( it != valid_long.end() ){
+ result += *it;
+ if ( valid_long_par.find( *it ) != valid_long_par.end() )
+ result += ":";
+ else if ( valid_long_opt.find( *it ) != valid_long_opt.end() )
+ result += "::";
+ ++it;
+ if ( it != valid_long.end() )
+ result += ",";
+ }
+ return result;
+ }
+}
diff --git a/src/Configuration.cxx b/src/Configuration.cxx
index db6feeb..bd72070 100644
--- a/src/Configuration.cxx
+++ b/src/Configuration.cxx
@@ -1,5 +1,5 @@
/*
- $Id: Configuration.cxx 17458 2014-07-16 15:14:19Z sloot $
+ $Id: Configuration.cxx 17617 2014-09-08 08:46:52Z sloot $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/src/Configuration.cxx $
Copyright (c) 2006 - 2014
Tilburg University
@@ -41,15 +41,6 @@ namespace TiCC {
myMap["global"] = ssMap();
}
- string dirname( const string& f ){
- string::size_type pos = f.find_last_of("/");
- if ( pos != string::npos ){
- return f.substr( 0, pos+1 );
- }
- else
- return ".";
- }
-
string fixControl( const string& s, char c ){
string sString;
string rString;
@@ -97,7 +88,7 @@ namespace TiCC {
}
bool Configuration::fill( const string& fileName ){
- cdir = dirname( fileName );
+ cdir = dirname( fileName ) + "/";
// cerr << "dirname= " << cdir << endl;
ifstream is( fileName.c_str() );
if ( !is ){
@@ -123,16 +114,16 @@ namespace TiCC {
return false;
}
else {
- vector<string> parts;
- int num = TiCC::split_at( line, parts, "=" );
- if ( num == 2 ){
- string val = parts[1];
+ string::size_type pos = line.find("=");
+ if ( pos != string::npos ){
+ string att = line.substr(0,pos);
+ string val = line.substr(pos+1);
if ( val[0] == '"' && val[val.length()-1] == '"' )
val = val.substr(1, val.length()-2);
val = fixControls( val );
- myMap[section][parts[0]] = val;
+ myMap[section][att] = val;
if ( section == "global"
- && parts[0] == "configDir" )
+ && att == "configDir" )
cdir = val;
}
else {
@@ -172,13 +163,13 @@ namespace TiCC {
}
else if ( localsection == section ){
found = true;
- vector<string> parts;
- int num = TiCC::split_at( line, parts, "=" );
- if ( num == 2 ){
- string val = parts[1];
+ string::size_type pos = line.find("=");
+ if ( pos != string::npos ){
+ string att = line.substr(0,pos);
+ string val = line.substr(pos+1);
if ( val[0] == '"' && val[val.length()-1] == '"' )
val = val.substr(1, val.length()-2);
- myMap[section][parts[0]] = val;
+ myMap[section][att] = val;
}
else {
cerr << "invalid attribute value pair in line '" << line << "'" << endl;
diff --git a/src/LogStream.cxx b/src/LogStream.cxx
index 7577f27..64762de 100755
--- a/src/LogStream.cxx
+++ b/src/LogStream.cxx
@@ -1,5 +1,5 @@
/*
- $Id: LogStream.cxx 16817 2014-01-06 10:07:03Z sloot $
+ $Id: LogStream.cxx 17645 2014-09-11 14:43:41Z mvgompel $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/src/LogStream.cxx $
Copyright (c) 1998 - 2014
@@ -60,7 +60,7 @@ namespace TiCC {
LogStream::LogStream() :
ostream( &buf ),
- buf( cerr, NULL, StampBoth ),
+ buf( cerr, "", StampBoth ),
single_threaded_mode(false) {
}
diff --git a/src/StringOps.cxx b/src/StringOps.cxx
index f65e4fc..2f89cc1 100644
--- a/src/StringOps.cxx
+++ b/src/StringOps.cxx
@@ -1,5 +1,5 @@
/*
- $Id: StringOps.cxx 17075 2014-03-31 10:54:22Z sloot $
+ $Id: StringOps.cxx 17575 2014-08-28 14:34:22Z sloot $
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/src/StringOps.cxx $
Copyright (c) 1998 - 2014
@@ -186,4 +186,20 @@ namespace TiCC {
return os.str();
}
+ std::string basename( const std::string& path ){
+ string::size_type pos = path.rfind( "/" );
+ if ( pos != string::npos )
+ return path.substr(pos+1);
+ else
+ return path;
+ }
+
+ std::string dirname( const std::string& path ){
+ string::size_type pos = path.rfind( "/" );
+ if ( pos != string::npos )
+ return path.substr(0,pos);
+ else
+ return ".";
+ }
+
} // namespace TiCC
diff --git a/src/runtest.cxx b/src/runtest.cxx
index ebe22d5..a2c40c9 100644
--- a/src/runtest.cxx
+++ b/src/runtest.cxx
@@ -12,6 +12,7 @@
#include "ticcutils/UnitTest.h"
#include "ticcutils/FileUtils.h"
#include "ticcutils/CommandLine.h"
+#include "ticcutils/Configuration.h"
using namespace std;
using namespace TiCC;
@@ -30,26 +31,129 @@ void test_nothrow(){
assertThrow( helper(), runtime_error );
}
+void test_opts_basic(){
+ startTestSerie( "we testen basic commandline opties." );
+ CL_Options opts1( "t:f" );
+ // -t mist een optie
+ assertThrow( opts1.init( "-t -f"), OptionError );
+ // onbekende optie
+ assertThrow( opts1.init( "-a"), OptionError );
+ // -f heeft optie --> massOpts.
+ assertNoThrow( opts1.init( "-t1 -f bla") );
+ CL_Options opts2( "", "true:,false" );
+ // --true mist een optie
+ assertThrow( opts2.init( "--true --false"), OptionError );
+ // --false heeft optie --> massOpts.
+ assertNoThrow( opts2.init( "--true=1 --false 2") );
+ CL_Options opts3( "", "true:,false" );
+ // - te weinig
+ assertThrow( opts3.init( "-true=false"), OptionError );
+ // onbekende optie
+ assertThrow( opts3.init( "--magniet"), OptionError );
+ CL_Options opts4( "", "true:,false" );
+ // --true heeft optie, OK en
+ // --false heeft geen optie --> massOpts.
+ assertNoThrow( opts4.init( "--true 1 --false 2") );
+ string value;
+ opts4.is_present( "true", value );
+ assertEqual( value, "1" );
+ CL_Options opts5( "", "false:,true::" );
+ // --true heeft optionele optie,
+ // --false heeft optie
+ assertNoThrow( opts5.init( "--true --false 2") );
+ opts5.is_present( "true", value );
+ assertEqual( value, "" );
+ string lo6 = "false:,true::";
+ CL_Options opts6( "", lo6 );
+ assertEqual( opts6.get_long_options(), lo6 );
+ // --true heeft optionele optie,
+ // --false heeft optie
+ assertNoThrow( opts6.init( "--true ok --false=6") );
+ opts6.is_present( "true", value );
+ assertEqual( value, "ok" );
+ opts6.is_present( "false", value );
+ assertEqual( value, "6" );
+ string so7 = "f:t::";
+ CL_Options opts7( so7 );
+ assertEqual( opts7.get_short_options(), so7 );
+ // -t heeft optionele optie,
+ // -f heeft optie
+ assertNoThrow( opts7.init( "-t ok -f6") );
+ bool mood;
+ opts7.is_present( 't', value, mood );
+ assertEqual( value, "ok" );
+ opts7.is_present( 'f', value, mood );
+ assertEqual( value, "6" );
+ CL_Options opts8( "t::,f:" );
+ // -t heeft optionele optie,
+ // -f heeft optie
+ assertNoThrow( opts8.init( "-t -f6") );
+ opts8.is_present( 't', value, mood );
+ assertEqual( value, "" );
+ opts8.is_present( 'f', value, mood );
+ assertEqual( value, "6" );
+ CL_Options opts9( "t::q" );
+ // -t heeft optionele optie. q is een stoorzender
+ assertNoThrow( opts9.init( "-t 1 -t2 -t3 -q -t -t4 ") );
+ vector<string> ts;
+ while ( opts9.extract( 't', value, mood ) ){
+ ts.push_back( value );
+ }
+ assertEqual( ts.size() , 5 );
+ assertEqual( ts[0], "1" );
+ assertEqual( ts[1], "2" );
+ assertEqual( ts[2], "3" );
+ assertEqual( ts[3], "" );
+ assertEqual( ts[4], "4" );
+ assertTrue( opts9.is_present('q') );
+ assertTrue( opts9.extract('q') );
+ assertFalse( opts9.extract('q') );
+ CL_Options opts10( "", "test::,qed" );
+ // opts10.set_debug(true);
+ // --test heeft optionele optie. qed is een stoorzender
+ assertNoThrow( opts10.init( "--test 1 --test=2 --qed --test --test=3 ") );
+ ts.clear();
+ while ( opts10.extract( "test", value ) ){
+ ts.push_back( value );
+ }
+ assertEqual( ts.size() , 4 );
+ assertEqual( ts[0], "1" );
+ assertEqual( ts[1], "2" );
+ assertEqual( ts[2], "" );
+ assertEqual( ts[3], "3" );
+ assertTrue( opts10.is_present("qed") );
+ assertTrue( opts10.extract("qed") );
+ assertFalse( opts10.extract("q") );
+ CL_Options opts11( "", "test:" );
+ opts11.init( "--test=test/a arg1" );
+ string ex;
+ opts11.extract( "test", ex );
+ assertEqual( ex, "test/a" );
+}
+
void test_opts( CL_Options& opts ){
- startTestSerie( "we testen commandline opties." );
+ startTestSerie( "we testen nog meer commandline opties." );
+ // opts.dump(cerr);
+ // cerr << endl;
string value;
bool pol;
- opts.find( 't', value, pol );
+ opts.is_present( 't', value, pol );
assertEqual( value, "true" );
assertEqual( pol, true );
- opts.find( 'f', value, pol );
+ opts.is_present( 'f', value, pol );
assertEqual( value, "false" );
assertEqual( pol, false );
- opts.find( 'd', value, pol );
+ opts.is_present( 'd', value, pol );
assertTrue( value != "" );
- opts.find( "test", value );
+ opts.is_present( "test", value );
assertEqual( value, "test" );
- opts.find( "raar", value );
+ opts.is_present( "raar", value );
assertEqual( value, "" );
vector<string> mo = opts.getMassOpts();
assertTrue( mo.size() == 3 );
- assertTrue( mo[1] == "arg2" );
- assertTrue( mo[2] == "blaat" );
+ assertEqual( mo[0], "blaat" );
+ assertEqual( mo[1], "arg1" );
+ assertEqual( mo[2], "arg2" );
}
void test_subtests_fail(){
@@ -156,6 +260,19 @@ void test_lowercase(){
assertEqual( res, "een camelcapped zin." );
}
+void test_base_dir(){
+ assertEqual( basename("/foo/bar" ), "bar" );
+ assertEqual( dirname("/foo/bar" ), "/foo" );
+ assertEqual( basename("foo/bar" ), "bar" );
+ assertEqual( dirname("foo/bar" ), "foo" );
+ assertEqual( basename("foobar" ), "foobar" );
+ assertEqual( dirname("foobar" ), "." );
+ assertEqual( basename("/" ), "/" );
+ assertEqual( dirname("/" ), "/" );
+ assertEqual( basename("." ), "." );
+ assertEqual( dirname("." ), "." );
+}
+
void test_bz2compression( const string& path ){
assertTrue( bz2Compress( path + "small.txt", "bzout.bz2" ) );
assertTrue( bz2Decompress( "bzout.bz2", "bzout.txt" ) );
@@ -239,17 +356,36 @@ void test_fileutils( const string& path ){
#endif
}
+void test_configuration( const string& path ){
+ Configuration c;
+ assertTrue( c.fill( path + "testconfig.cfg" ) );
+ assertTrue( c.hasSection("test") );
+ string att = c.lookUp( "jan" );
+ assertEqual( att, "gek" );
+ att = c.lookUp( "piet" );
+ assertEqual( att, "" );
+ att = c.lookUp( "piet", "test" );
+ assertEqual( att, "ook gek" );
+ att = c.lookUp( "kees", "test" );
+ assertEqual( att, "een jongen" );
+ att = c.lookUp( "klara", "test" );
+ assertEqual( att, "speciaal=raar" );
+}
+
int main( const int argc, const char* argv[] ){
cerr << BuildInfo() << endl;
- CL_Options opts;
- opts.set_short_options( "t:qf:d:" );
- opts.set_long_options( "test:,raar" );
- opts.init( argc, argv );
- cerr << opts << endl;
- test_opts( opts );
+ test_opts_basic();
+ CL_Options opts1;
+ opts1.set_short_options( "t:qf:d:" );
+ opts1.set_long_options( "test:,raar" );
+ opts1.init( argc, argv );
+ test_opts( opts1 );
CL_Options opts2( "t:qf:d:", "test:,raar" );
opts2.init( "-ffalse +t true --test=test --raar blaat -d iets arg1 -q arg2" );
test_opts( opts2 );
+ CL_Options opts3( "t:qf:d:", "test:,raar" );
+ opts3.init( "-ffalse +t true --test=test --raar blaat -d iets arg1 -q arg2" );
+ test_opts( opts3 );
test_subtests_fail();
test_subtests_ok();
test_throw();
@@ -269,10 +405,11 @@ int main( const int argc, const char* argv[] ){
test_lowercase();
string testdir;
bool dummy;
- opts.find( 'd', testdir, dummy );
+ opts1.is_present( 'd', testdir, dummy );
test_bz2compression( testdir );
test_gzcompression( testdir );
test_tar( testdir );
test_fileutils( testdir );
+ test_configuration( testdir );
summarize_tests(3);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 347693b..39e7f95 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,5 @@
-# $Id: Makefile.am 17325 2014-06-11 11:45:54Z sloot $
+# $Id: Makefile.am 17678 2014-09-16 14:30:48Z sloot $
# $URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/tests/Makefile.am $
SUBDIRS = sub1
-EXTRA_DIST = small.txt test.tar
+EXTRA_DIST = small.txt test.tar testconfig.cfg
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 2c0d5df..1389726 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -14,7 +14,7 @@
@SET_MAKE@
-# $Id: Makefile.am 17325 2014-06-11 11:45:54Z sloot $
+# $Id: Makefile.am 17678 2014-09-16 14:30:48Z sloot $
# $URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/tests/Makefile.am $
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
@@ -310,7 +310,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = sub1
-EXTRA_DIST = small.txt test.tar
+EXTRA_DIST = small.txt test.tar testconfig.cfg
all: all-recursive
.SUFFIXES:
diff --git a/tests/testconfig.cfg b/tests/testconfig.cfg
new file mode 100644
index 0000000..e154441
--- /dev/null
+++ b/tests/testconfig.cfg
@@ -0,0 +1,5 @@
+jan=gek
+[[test]]
+piet=ook gek
+kees="een jongen"
+klara=speciaal=raar
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/libticcutils.git
More information about the debian-science-commits
mailing list