complement-svn Mailing List for Complement (Page 5)
Status: Pre-Alpha
Brought to you by:
complement
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(61) |
Nov
(76) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(33) |
Feb
(41) |
Mar
(16) |
Apr
|
May
(22) |
Jun
(14) |
Jul
(64) |
Aug
(60) |
Sep
(35) |
Oct
(34) |
Nov
(10) |
Dec
(5) |
2008 |
Jan
(4) |
Feb
(24) |
Mar
(10) |
Apr
(30) |
May
(15) |
Jun
(50) |
Jul
(20) |
Aug
(7) |
Sep
(8) |
Oct
(10) |
Nov
|
Dec
|
From: <com...@us...> - 2008-05-21 08:37:24
|
Revision: 1878 http://complement.svn.sourceforge.net/complement/?rev=1878&view=rev Author: complement Date: 2008-05-21 01:37:08 -0700 (Wed, 21 May 2008) Log Message: ----------- separate unit tests for type_traits and options; partially fixed exceptions usage; sample how to use generic container (options storage) Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/misc_test_suite.h trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/unit_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-05-16 15:18:52 UTC (rev 1877) +++ trunk/complement/explore/include/misc/opts.h 2008-05-21 08:37:08 UTC (rev 1878) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/05/01 12:02:26 ptr> +// -*- C++ -*- Time-stamp: <08/05/21 12:17:39 yeti> #ifndef __OPTS_H__ #define __OPTS_H__ @@ -76,46 +76,44 @@ std::string get_author() const; std::string get_copyright() const; - struct error : public std::logic_error - { - error(const std::string& what) : - std::logic_error(what) - { } - }; - // error handling - struct invalid_opt : public error + struct unknown_option : + public std::invalid_argument { - invalid_opt(const std::string& _optname) : - error(std::string("invalid opt: ").append(_optname)) + unknown_option( const std::string& _optname ) : + std::invalid_argument( std::string("unknown option ").append(_optname) ) { } }; - struct missing_arg : public error + struct missing_arg : + public std::invalid_argument { - missing_arg( const std::string& _optname) : - error(std::string("missing argument for option ").append(_optname)) + missing_arg( const std::string& _optname ) : + std::invalid_argument( std::string("missing argument for option ").append(_optname) ) { } }; - struct invalid_arg : public error + struct invalid_arg : + public std::invalid_argument { invalid_arg( const std::string& _optname, const std::string& _argname) : - error(std::string("invalid argument [").append(_argname).append("] for option ").append(_optname)) + std::invalid_argument(std::string("invalid argument [").append(_argname).append("] for option ").append(_optname)) { } }; - struct bad_usage : public error + struct bad_usage : + public std::invalid_argument { - bad_usage( const std::string& what) : - error(what) - { } + bad_usage( const std::string& descr ) : + std::invalid_argument( descr ) + { } }; //std::vector< std::string > args; private: // data - std::vector< Opt > storage; + typedef std::vector< Opt > options_container_type; + options_container_type storage; std::string pname; std::string brief; @@ -142,30 +140,30 @@ template <class T> T Opts::get( char _shortname ) { - int i; + options_container_type::const_iterator i; T res; - for (i = 0;i < storage.size();i++) - if (storage[i].shortname == _shortname) - { - if (!storage[i].has_arg) + for ( i = storage.begin(); i != storage.end(); ++i ) { + if ( i->shortname == _shortname ) { + if ( !i->has_arg ) { throw bad_usage("using Opts::get for option without arguments"); + } std::stringstream ss; - if (!storage[i].args.empty()) - ss << storage[i].args[0]; - else - ss << storage[i].default_v; - + ss << (i->args.empty() ? i->default_v : i->args[0]); ss >> res; - if (ss.fail()) - throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].args[0]); + if (ss.fail()) { + throw invalid_arg(std::string("-") + std::string(1,_shortname), i->args[0]); + } break; } + } - if (i == storage.size()) - throw invalid_opt(std::string("-") + std::string(1,_shortname)); + if ( i == storage.end() ) { + throw unknown_option( std::string("-") + _shortname ); + } + return res; } @@ -192,7 +190,7 @@ } if (i == storage.size()) - throw invalid_opt(std::string("-") + std::string(1,_shortname)); + throw unknown_option(std::string("-") + std::string(1,_shortname)); return res; } @@ -222,7 +220,7 @@ } if (i == storage.size()) - throw invalid_opt(std::string("--") + _longname); + throw unknown_option(std::string("--") + _longname); return res; } @@ -248,7 +246,7 @@ } if (i == storage.size()) - throw invalid_opt(std::string("--") + _longname); + throw unknown_option(std::string("--") + _longname); return res; } @@ -290,7 +288,7 @@ } if (i == storage.size()) - throw invalid_opt(std::string("-") + std::string(1,_shortname)); + throw unknown_option(std::string("-") + std::string(1,_shortname)); } template <class BackInsertIterator> @@ -331,7 +329,7 @@ } if (i == storage.size()) - throw invalid_opt(std::string("-") + _longname); + throw unknown_option(std::string("-") + _longname); } #endif Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-05-16 15:18:52 UTC (rev 1877) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-21 08:37:08 UTC (rev 1878) @@ -166,7 +166,7 @@ int p = get_opt_index(opt); if (p == storage.size()) - throw invalid_opt(opt); + throw unknown_option(opt); else { storage[p].is_set = true; @@ -194,7 +194,7 @@ { int p = get_opt_index(string("-") + optgroup[j]); if (p == storage.size()) - throw invalid_opt( "-" + string(1,optgroup[j]) ); + throw unknown_option( "-" + string(1,optgroup[j]) ); else { storage[p].is_set = true; Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-16 15:18:52 UTC (rev 1877) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-21 08:37:08 UTC (rev 1878) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/05/01 15:18:28 ptr> +// -*- C++ -*- Time-stamp: <08/05/21 12:30:07 yeti> /* * Copyright (c) 2007, 2008 @@ -16,7 +16,7 @@ int EXAM_IMPL(misc_test_suite) { - exam::test_suite t( "libmisc? test" ); + exam::test_suite t( "libmisc type_traits test" ); misc_test test; exam::test_suite::test_case_type tc[10]; @@ -55,8 +55,13 @@ t.add( &misc_test::type_traits_is_pod, test, "is_pod", tc[0] ); t.add( &misc_test::type_traits_is_empty, test, "is_empty", tc[0] ); + return t.girdle(); +} +int EXAM_IMPL(options_test_suite) +{ // test for options parsing + exam::test_suite t( "libmisc, options test" ); opts_test opts; @@ -94,4 +99,4 @@ t.add( &opts_test::multiple_args, opts,"multiple_args"); return t.girdle(); -}; +} Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.h =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.h 2008-05-16 15:18:52 UTC (rev 1877) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.h 2008-05-21 08:37:08 UTC (rev 1878) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/07/16 22:08:39 ptr> +// -*- C++ -*- Time-stamp: <08/05/21 12:31:01 yeti> /* - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -14,5 +14,6 @@ #include <exam/suite.h> int EXAM_DECL(misc_test_suite); +int EXAM_DECL(options_test_suite); #endif // __MISC_TEST_SUITE_H Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-16 15:18:52 UTC (rev 1877) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-21 08:37:08 UTC (rev 1878) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/05/01 15:16:10 ptr> +// -*- C++ -*- Time-stamp: <08/05/21 12:20:14 yeti> /* * Copyright (c) 2008 @@ -32,7 +32,7 @@ EXAM_CHECK( opts.is_set( 'h' ) ); } - catch ( const Opts::invalid_opt& e ) { + catch ( const Opts::unknown_option& e ) { } catch ( const Opts::invalid_arg& e ) { } @@ -54,7 +54,7 @@ EXAM_CHECK( opts.is_set( 'h' ) ); } - catch ( const Opts::invalid_opt& e ) { + catch ( const Opts::unknown_option& e ) { } catch ( const Opts::invalid_arg& e ) { } @@ -78,7 +78,7 @@ EXAM_CHECK( opts.is_set( 'p' ) ); EXAM_CHECK( opts.get<int>( 'p' ) == 80 ); } - catch ( const Opts::invalid_opt& e ) { + catch ( const Opts::unknown_option& e ) { } catch ( const Opts::invalid_arg& e ) { } @@ -102,7 +102,7 @@ EXAM_CHECK( opts.is_set( 'p' ) ); EXAM_CHECK( opts.get<int>( 'p' ) == 80 ); } - catch ( const Opts::invalid_opt& e ) { + catch ( const Opts::unknown_option& e ) { } catch ( const Opts::invalid_arg& e ) { } @@ -126,7 +126,7 @@ EXAM_CHECK( !opts.is_set( 'p' ) ); EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); } - catch ( const Opts::invalid_opt& e ) { + catch ( const Opts::unknown_option& e ) { } catch ( const Opts::invalid_arg& e ) { } @@ -150,7 +150,7 @@ EXAM_ERROR( "exception expected" ); } - catch ( const Opts::invalid_opt& e ) { + catch ( const Opts::unknown_option& e ) { exception_happens = true; } catch ( const Opts::invalid_arg& e ) { @@ -491,7 +491,7 @@ { opts.parse( argc, argv ); } - catch(const Opts::invalid_opt& e) + catch(const Opts::unknown_option& e) { exception_happens = true; } Modified: trunk/complement/explore/lib/misc/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/unit_test.cc 2008-05-16 15:18:52 UTC (rev 1877) +++ trunk/complement/explore/lib/misc/ut/unit_test.cc 2008-05-21 08:37:08 UTC (rev 1878) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/16 22:12:10 ptr> +// -*- C++ -*- Time-stamp: <08/05/21 12:33:01 yeti> /* * Copyright (c) 2007 @@ -15,5 +15,9 @@ int main( int, char ** ) { - return misc_test_suite(0); + int res1 = misc_test_suite(0); + + int res2 = options_test_suite(0); + + return res1 || res2; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Dmi...@us...> - 2008-05-16 15:19:14
|
Revision: 1877 http://complement.svn.sourceforge.net/complement/?rev=1877&view=rev Author: DmitryOsmakov Date: 2008-05-16 08:18:52 -0700 (Fri, 16 May 2008) Log Message: ----------- fixed lib Opts : bad argument recognition is improved , get_default is added , unit test added and updated Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/opts_test.h Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-05-15 15:22:47 UTC (rev 1876) +++ trunk/complement/explore/include/misc/opts.h 2008-05-16 15:18:52 UTC (rev 1877) @@ -20,7 +20,7 @@ std::string longname; std::string desc; std::vector< std::string > args; - std::string v; + std::string default_v; bool has_arg; bool is_set; @@ -38,7 +38,7 @@ // adding option / flag template <class T> - void add( char _shortname,T default_value,const std::string& _longname = "", const std::string& _desc = "" ); + void add( char _shortname,T _default_value,const std::string& _longname = "", const std::string& _desc = "" ); void addflag( char _shortname,const std::string& _longname = "",const std::string& _desc = "" ); // getting option @@ -47,10 +47,19 @@ template <class T> T get( const std::string& _longname ); - + + template <class T> + T get_default( char _shorname ); + + template <class T> + T get_default( const std::string& _longname ); + template <class BackInsertIterator> void getemall(char _shortname,BackInsertIterator bi); + template <class BackInsertIterator> + void getemall(const std::string& _longname,BackInsertIterator bi); + bool is_set( char _shortname ); bool is_set( const std::string& _longname ); @@ -67,36 +76,42 @@ std::string get_author() const; std::string get_copyright() const; + struct error : public std::logic_error + { + error(const std::string& what) : + std::logic_error(what) + { } + }; + // error handling - struct invalid_opt : public std::logic_error + struct invalid_opt : public error { invalid_opt(const std::string& _optname) : - std::logic_error(std::string("invalid opt: ").append(_optname)) + error(std::string("invalid opt: ").append(_optname)) { } }; - struct missing_arg : public std::logic_error + struct missing_arg : public error { missing_arg( const std::string& _optname) : - std::logic_error(std::string("missing argument for option ").append(_optname)) + error(std::string("missing argument for option ").append(_optname)) { } }; - struct invalid_arg : public std::logic_error + struct invalid_arg : public error { invalid_arg( const std::string& _optname, const std::string& _argname) : - std::logic_error(std::string("invalid argument [").append(_argname).append("] for option ").append(_optname)) + error(std::string("invalid argument [").append(_argname).append("] for option ").append(_optname)) { } }; - struct bad_usage : public std::runtime_error + struct bad_usage : public error { bad_usage( const std::string& what) : - std::runtime_error(what) + error(what) { } }; - //std::vector< std::string > args; private: // data @@ -120,7 +135,7 @@ addflag(_shortname,_longname,_desc); std::stringstream ss; ss << _default_value; - storage[storage.size() - 1].v = ss.str(); + storage[storage.size() - 1].default_v = ss.str(); storage[storage.size() - 1].has_arg = true; } @@ -135,18 +150,16 @@ if (!storage[i].has_arg) throw bad_usage("using Opts::get for option without arguments"); + std::stringstream ss; if (!storage[i].args.empty()) - storage[i].v = storage[i].args[0]; + ss << storage[i].args[0]; + else + ss << storage[i].default_v; - try - { - std::stringstream ss(storage[i].v); - ss >> res; - } - catch(...) - { - throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].v); - } + ss >> res; + + if (ss.fail()) + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].args[0]); break; } @@ -156,8 +169,33 @@ return res; } +template <class T> +T Opts::get_default( char _shortname ) +{ + int i; + T res; + for (i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + { + if (!storage[i].has_arg) + throw bad_usage("using Opts::get for option without arguments"); + + std::stringstream ss; + ss << storage[i].default_v; + ss >> res; + if (ss.fail()) + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].default_v); + + break; + } + + if (i == storage.size()) + throw invalid_opt(std::string("-") + std::string(1,_shortname)); + return res; +} + template <class T> T Opts::get( const std::string& _longname ) { @@ -169,19 +207,17 @@ if (!storage[i].has_arg) throw bad_usage("using Opts::get for option without arguments"); + std::stringstream ss; if (!storage[i].args.empty()) - storage[i].v = storage[i].args[0]; + ss << storage[i].args[0]; + else + ss << storage[i].default_v; - try - { - std::stringstream ss(storage[i].v); - ss >> res; - } - catch(...) - { - throw invalid_arg(std::string("--") + _longname,storage[i].v); - } + ss >> res; + if (ss.fail()) // need to recover stream? + throw invalid_arg(std::string("--") + _longname,storage[i].args[0]); + break; } @@ -190,6 +226,32 @@ return res; } +template <class T> +T Opts::get_default( const std::string& _longname ) +{ + int i; + T res; + for (i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + { + if (!storage[i].has_arg) + throw bad_usage("using Opts::get for option without arguments"); + + std::stringstream ss(storage[i].default_v); + + ss >> res; + + if (ss.fail()) // need to recover stream? + throw invalid_arg(std::string("--") + _longname,storage[i].default_v); + + break; + } + + if (i == storage.size()) + throw invalid_opt(std::string("--") + _longname); + return res; +} + template <class BackInsertIterator> void Opts::getemall( char _shortname , BackInsertIterator bi) { @@ -200,24 +262,28 @@ if (!storage[i].has_arg) throw bad_usage("using Opts::getemall for option without arguments"); - if (!storage[i].v.empty()) + if (!storage[i].default_v.empty()) { - std::stringstream ss(storage[i].v); + std::stringstream ss(storage[i].default_v); ss >> *bi++; } if (!storage[i].args.empty()) for (int j = 0;j < storage[i].args.size();j++) { + + std::stringstream ss(storage[i].args[j]); try { - std::stringstream ss(storage[i].args[j]); ss >> *bi++; } catch(...) { - throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].v); + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].args[j]); } + + if (ss.fail()) + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].args[j]); } break; @@ -227,5 +293,45 @@ throw invalid_opt(std::string("-") + std::string(1,_shortname)); } +template <class BackInsertIterator> +void Opts::getemall( const std::string& _longname , BackInsertIterator bi) +{ + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + { + if (!storage[i].has_arg) + throw bad_usage("using Opts::getemall for option without arguments"); + + if (!storage[i].default_v.empty()) + { + std::stringstream ss(storage[i].default_v); + ss >> *bi++; + } + if (!storage[i].args.empty()) + for (int j = 0;j < storage[i].args.size();j++) + { + + std::stringstream ss(storage[i].args[j]); + try + { + ss >> *bi++; + } + catch(...) + { + throw invalid_arg(std::string("--") + _longname,storage[i].args[j]); + } + + if (ss.fail()) + throw invalid_arg(std::string("-") + _longname,storage[i].args[j]); + } + + break; + } + + if (i == storage.size()) + throw invalid_opt(std::string("-") + _longname); +} + #endif Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-05-15 15:22:47 UTC (rev 1876) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-16 15:18:52 UTC (rev 1877) @@ -19,7 +19,7 @@ bool Opts::is_opt_name(const string& s) { - return (s.size() > 0) && (s[0] == '-') && !is_flag_group(s); + return (s.size() > 1) && (s[0] == '-') && !is_flag_group(s); } bool Opts::is_substr(const string& small,const string& big) @@ -95,7 +95,7 @@ out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; out << "available options:" << endl; for (int i = 0;i < storage.size();i++) - out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "] [" << storage[i].v << "]\t-\t" << storage[i].desc << endl; + out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "] [" << storage[i].default_v << "]\t-\t" << storage[i].desc << endl; } void Opts::addflag(char _shortname,const string& _longname,const string& _desc) Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-15 15:22:47 UTC (rev 1876) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-16 15:18:52 UTC (rev 1877) @@ -71,12 +71,17 @@ t.add( &opts_test::bad_option, opts, "bad option" ); t.add( &opts_test::bad_argument, opts, "bad argument" ); + t.add( &opts_test::unexpected_argument, opts, "unexpected_argument" ); + t.add( &opts_test::missing_argument, opts, "missing argument" ); + t.add( &opts_test::user_defined, opts, "user-defined type" ); t.add( &opts_test::compound, opts, "compound" ); t.add( &opts_test::multiple, opts,"multiple"); + + t.add( &opts_test::multiple_compound, opts,"multiple_compound"); t.add( &opts_test::args, opts,"args"); @@ -84,6 +89,7 @@ // check whether autocomplement works t.add( &opts_test::autocomplement, opts,"autocomplement"); + t.add( &opts_test::autocomplement_failure, opts,"autocomplement_failure"); t.add( &opts_test::multiple_args, opts,"multiple_args"); Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-15 15:22:47 UTC (rev 1876) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-16 15:18:52 UTC (rev 1877) @@ -168,12 +168,12 @@ Opts opts; - opts.add( 'p', "port", "listen tcp port" ); + opts.add( 'p', 10, "port", "listen tcp port" ); bool exception_happens = false; + + opts.parse( argc, argv ); - opts.parse( argc, argv ); - try { int t = opts.get<int>('p'); @@ -184,10 +184,61 @@ } EXAM_CHECK( exception_happens ); + EXAM_CHECK ( opts.get_default<int>('p') == 10 ); return EXAM_RESULT; } +int EXAM_IMPL(opts_test::unexpected_argument) +{ + const char* argv[] = { "name", "--help=10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.addflag('h',"help"); + + bool exception_happens = false; + + try + { + opts.parse( argc, argv ); + } + catch(const Opts::invalid_arg& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::missing_argument) +{ + const char* argv[] = { "name", "-n" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add('n',10,"num"); + + bool exception_happens = false; + + try + { + opts.parse( argc, argv ); + } + catch(const Opts::missing_arg& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + + return EXAM_RESULT; +} + int EXAM_IMPL(opts_test::multiple) { { @@ -232,6 +283,7 @@ return EXAM_RESULT; } + int EXAM_IMPL(opts_test::compound) { { @@ -253,6 +305,39 @@ return EXAM_RESULT; } +int EXAM_IMPL(opts_test::multiple_compound) +{ + { + const char* argv[] = { "name", "-xf","--flag", "-f", "-p=second" ,"--pa","third" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.addflag( 'x', "x-option", "option x" ); + opts.addflag( 'f', "flag", "option f" ); + + opts.add('p',"first","path","some path"); + + opts.parse( argc, argv ); + + EXAM_CHECK(opts.is_set('x')); + EXAM_CHECK(opts.is_set("flag")); + EXAM_CHECK(opts.is_set('p')); + EXAM_CHECK(opts.get_cnt("flag") == 3 && opts.get_cnt('f') == 3); + vector<string> vs(3); + + opts.getemall("path",vs.begin()); + EXAM_CHECK( vs[0] == "first" ); + EXAM_CHECK( vs[1] == "second" ); + EXAM_CHECK( vs[2] == "third" ); + } + + + return EXAM_RESULT; +} + + + int EXAM_IMPL(opts_test::args) { { @@ -389,6 +474,34 @@ return EXAM_RESULT; } +int EXAM_IMPL(opts_test::autocomplement_failure) +{ + { + const char* argv[] = { "name" , "--proc" , "4"}; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add('p',1,"proc_num","process number" ); + opts.add('t',string("standart"),"proc_type","process type"); + + bool exception_happens = false; + + try + { + opts.parse( argc, argv ); + } + catch(const Opts::invalid_opt& e) + { + exception_happens = true; + } + + EXAM_CHECK( exception_happens ); + } + + return EXAM_RESULT; +} + int EXAM_IMPL(opts_test::multiple_args) { { Modified: trunk/complement/explore/lib/misc/ut/opts_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-15 15:22:47 UTC (rev 1876) +++ trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-16 15:18:52 UTC (rev 1877) @@ -26,12 +26,16 @@ int EXAM_DECL(defaults); int EXAM_DECL(bad_option); int EXAM_DECL(bad_argument); + int EXAM_DECL(unexpected_argument); + int EXAM_DECL(missing_argument); int EXAM_DECL(multiple); int EXAM_DECL(compound); + int EXAM_DECL(multiple_compound); int EXAM_DECL(args); int EXAM_DECL(stop); int EXAM_DECL(user_defined); int EXAM_DECL(autocomplement); + int EXAM_DECL(autocomplement_failure); int EXAM_DECL(multiple_args); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Dmi...@us...> - 2008-05-15 15:23:21
|
Revision: 1876 http://complement.svn.sourceforge.net/complement/?rev=1876&view=rev Author: DmitryOsmakov Date: 2008-05-15 08:22:47 -0700 (Thu, 15 May 2008) Log Message: ----------- fixed lib Opts : default values are enabled (by cost of some overhead in runtime and different usage of function get) , error handling updated (more standart way) , function to get access to all arguments of specified option is added Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/opts_test.h Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-05-15 08:35:35 UTC (rev 1875) +++ trunk/complement/explore/include/misc/opts.h 2008-05-15 15:22:47 UTC (rev 1876) @@ -9,6 +9,8 @@ #include <sstream> #include <typeinfo> #include <cctype> +#include <exception> +#include <stdexcept> class Opt { @@ -18,6 +20,7 @@ std::string longname; std::string desc; std::vector< std::string > args; + std::string v; bool has_arg; bool is_set; @@ -33,16 +36,21 @@ copyright(_copyright) { } - // adding option - void add( char _shortname, const std::string& _longname = "", const std::string& _desc = "", bool has_arg = false ); + // adding option / flag + template <class T> + void add( char _shortname,T default_value,const std::string& _longname = "", const std::string& _desc = "" ); + void addflag( char _shortname,const std::string& _longname = "",const std::string& _desc = "" ); // getting option template <class T> - T get( char _shortname, T& dest ); + T get( char _shortname ); template <class T> - T get( const std::string& _longname, T& dest ); + T get( const std::string& _longname ); + template <class BackInsertIterator> + void getemall(char _shortname,BackInsertIterator bi); + bool is_set( char _shortname ); bool is_set( const std::string& _longname ); @@ -60,34 +68,33 @@ std::string get_copyright() const; // error handling - struct invalid_opt + struct invalid_opt : public std::logic_error { - std::string optname; - invalid_opt(const std::string& _optname) : - optname(_optname) + std::logic_error(std::string("invalid opt: ").append(_optname)) { } }; - - struct missing_arg + + struct missing_arg : public std::logic_error { - std::string optname; - missing_arg( const std::string& _optname) : - optname(_optname) + std::logic_error(std::string("missing argument for option ").append(_optname)) { } }; - struct invalid_arg + struct invalid_arg : public std::logic_error { - std::string optname; - std::string argname; - invalid_arg( const std::string& _optname, const std::string& _argname) : - optname(_optname), - argname(_argname) + std::logic_error(std::string("invalid argument [").append(_argname).append("] for option ").append(_optname)) { } }; + + struct bad_usage : public std::runtime_error + { + bad_usage( const std::string& what) : + std::runtime_error(what) + { } + }; //std::vector< std::string > args; @@ -108,58 +115,117 @@ }; template <class T> -T Opts::get( char _shortname, T& res ) +void Opts::add(char _shortname,T _default_value,const std::string& _longname,const std::string& _desc) { + addflag(_shortname,_longname,_desc); + std::stringstream ss; + ss << _default_value; + storage[storage.size() - 1].v = ss.str(); + storage[storage.size() - 1].has_arg = true; +} + +template <class T> +T Opts::get( char _shortname ) +{ int i; - for (i = 0;i < storage.size();i++) { + T res; + for (i = 0;i < storage.size();i++) if (storage[i].shortname == _shortname) { - if (storage[i].is_set && storage[i].has_arg) - if (!storage[i].args.empty()) - { - try - { - std::stringstream ss(storage[i].args[0]); - ss >> res; - } - catch(...) - { - throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].args[0]); - } - } + if (!storage[i].has_arg) + throw bad_usage("using Opts::get for option without arguments"); + + if (!storage[i].args.empty()) + storage[i].v = storage[i].args[0]; + + try + { + std::stringstream ss(storage[i].v); + ss >> res; + } + catch(...) + { + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].v); + } + break; } - } + if (i == storage.size()) throw invalid_opt(std::string("-") + std::string(1,_shortname)); return res; } + + template <class T> -T Opts::get(const std::string& _longname,T& res) +T Opts::get( const std::string& _longname ) { int i; + T res; for (i = 0;i < storage.size();i++) if (storage[i].longname == _longname) { - if (storage[i].is_set && storage[i].has_arg) - if (!storage[i].args.empty()) + if (!storage[i].has_arg) + throw bad_usage("using Opts::get for option without arguments"); + + if (!storage[i].args.empty()) + storage[i].v = storage[i].args[0]; + + try + { + std::stringstream ss(storage[i].v); + ss >> res; + } + catch(...) + { + throw invalid_arg(std::string("--") + _longname,storage[i].v); + } + + break; + } + + if (i == storage.size()) + throw invalid_opt(std::string("--") + _longname); + return res; +} + +template <class BackInsertIterator> +void Opts::getemall( char _shortname , BackInsertIterator bi) +{ + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + { + if (!storage[i].has_arg) + throw bad_usage("using Opts::getemall for option without arguments"); + + if (!storage[i].v.empty()) + { + std::stringstream ss(storage[i].v); + ss >> *bi++; + } + + if (!storage[i].args.empty()) + for (int j = 0;j < storage[i].args.size();j++) { try { - std::stringstream ss(storage[i].args[0]); - ss >> res; + std::stringstream ss(storage[i].args[j]); + ss >> *bi++; } catch(...) { - throw invalid_arg(_longname,storage[i].args[0]); + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].v); } } + break; - } + } + if (i == storage.size()) - throw invalid_opt(_longname); - return res; + throw invalid_opt(std::string("-") + std::string(1,_shortname)); } + #endif Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-05-15 08:35:35 UTC (rev 1875) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-15 15:22:47 UTC (rev 1876) @@ -95,16 +95,16 @@ out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; out << "available options:" << endl; for (int i = 0;i < storage.size();i++) - out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "]\t-\t" << storage[i].desc << endl; + out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "] [" << storage[i].v << "]\t-\t" << storage[i].desc << endl; } -void Opts::add(char _shortname,const string& _longname,const string& _desc,bool has_arg ) +void Opts::addflag(char _shortname,const string& _longname,const string& _desc) { Opt opt; opt.shortname = _shortname; opt.longname = _longname; opt.desc = _desc; - opt.has_arg = has_arg; + opt.has_arg = false; opt.is_set = false; storage.push_back(opt); } Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-15 08:35:35 UTC (rev 1875) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-15 15:22:47 UTC (rev 1876) @@ -66,9 +66,12 @@ t.add( &opts_test::int_option_long, opts, "option with int parameter, long", t.add( &opts_test::int_option, opts, "option with int parameter" ) ); + t.add( &opts_test::defaults, opts, "defaults" ); + + t.add( &opts_test::bad_option, opts, "bad option" ); t.add( &opts_test::bad_argument, opts, "bad argument" ); - + t.add( &opts_test::user_defined, opts, "user-defined type" ); t.add( &opts_test::compound, opts, "compound" ); @@ -78,8 +81,11 @@ t.add( &opts_test::args, opts,"args"); t.add( &opts_test::stop, opts,"stop"); + + // check whether autocomplement works + t.add( &opts_test::autocomplement, opts,"autocomplement"); - t.add( &opts_test::reduction, opts,"reduction"); + t.add( &opts_test::multiple_args, opts,"multiple_args"); return t.girdle(); }; Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-15 08:35:35 UTC (rev 1875) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-15 15:22:47 UTC (rev 1876) @@ -11,6 +11,8 @@ #include "opts_test.h" #include <misc/opts.h> +#include <set> +#include <vector> // #include <iostream> @@ -23,7 +25,7 @@ Opts opts; - opts.add( 'h', "help", "print this help message" ); + opts.addflag( 'h', "help", "print this help message" ); try { opts.parse( argc, argv ); @@ -45,7 +47,7 @@ Opts opts; - opts.add( 'h', "help", "print this help message" ); + opts.addflag( 'h', "help", "print this help message" ); try { opts.parse( argc, argv ); @@ -68,15 +70,13 @@ Opts opts; - opts.add( 'p', "port", "listen tcp port" , true); + opts.add( 'p', 0,"port", "listen tcp port"); try { opts.parse( argc, argv ); - int port = 0; - EXAM_CHECK( opts.is_set( 'p' ) ); - EXAM_CHECK( opts.get( 'p', port ) == 80 ); + EXAM_CHECK( opts.get<int>( 'p' ) == 80 ); } catch ( const Opts::invalid_opt& e ) { } @@ -93,15 +93,14 @@ Opts opts; - opts.add( 'p', "port", "listen tcp port" , true ); + opts.add( 'p', 0, "port", "listen tcp port"); try { opts.parse( argc, argv ); - int port = 0; EXAM_CHECK( opts.is_set( 'p' ) ); - EXAM_CHECK( opts.get( 'p', port ) == 80 ); + EXAM_CHECK( opts.get<int>( 'p' ) == 80 ); } catch ( const Opts::invalid_opt& e ) { } @@ -111,6 +110,30 @@ return EXAM_RESULT; } +int EXAM_IMPL(opts_test::defaults) +{ + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'p', 0, "port", "listen tcp port"); + + try { + opts.parse( argc, argv ); + + + EXAM_CHECK( !opts.is_set( 'p' ) ); + EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + } + catch ( const Opts::invalid_opt& e ) { + } + catch ( const Opts::invalid_arg& e ) { + } + + return EXAM_RESULT; +} + int EXAM_IMPL(opts_test::bad_option) { const char* argv[] = { "name", "-v" }; @@ -118,7 +141,7 @@ Opts opts; - opts.add( 'h', "help", "print this help message" ); + opts.addflag( 'h', "help", "print this help message" ); bool exception_happens = false; @@ -129,7 +152,6 @@ } catch ( const Opts::invalid_opt& e ) { exception_happens = true; - EXAM_CHECK( e.optname == "-v" ); } catch ( const Opts::invalid_arg& e ) { } @@ -150,17 +172,15 @@ bool exception_happens = false; - try { - opts.parse( argc, argv ); - - EXAM_ERROR( "exception expected" ); + opts.parse( argc, argv ); + + try + { + int t = opts.get<int>('p'); } - catch ( const Opts::invalid_opt& e ) { - } - catch ( const Opts::invalid_arg& e ) { + catch(const Opts::invalid_arg& e) + { exception_happens = true; - EXAM_CHECK( e.optname == "--port" ); - EXAM_CHECK( e.argname == "www" ); } EXAM_CHECK( exception_happens ); @@ -176,7 +196,7 @@ Opts opts; - opts.add( 'v', "verbose", "more trace messages" ); + opts.addflag( 'v', "verbose", "more trace messages" ); opts.parse( argc, argv ); @@ -189,7 +209,7 @@ Opts opts; - opts.add( 'v', "verbose", "more trace messages" ); + opts.addflag( 'v', "verbose", "more trace messages" ); opts.parse( argc, argv ); @@ -202,7 +222,7 @@ Opts opts; - opts.add( 'v', "verbose", "more trace messages" ); + opts.addflag( 'v', "verbose", "more trace messages" ); opts.parse( argc, argv ); @@ -220,9 +240,9 @@ Opts opts; - opts.add( 'a', "a-option", "option a" ); - opts.add( 'b', "b-option", "option b" ); - opts.add( 'c', "c-option", "option c" ); + opts.addflag( 'a', "a-option", "option a" ); + opts.addflag( 'b', "b-option", "option b" ); + opts.addflag( 'c', "c-option", "option c" ); opts.parse( argc, argv ); @@ -241,7 +261,7 @@ Opts opts; - opts.add( 'f', "config", "configuration file",true ); + opts.add( 'f',string("default.conf"), "config", "configuration file"); opts.parse( argc, argv ); @@ -257,7 +277,7 @@ Opts opts; - opts.add( 'f', "config", "configuration file",true ); + opts.add( 'f', string("default.conf"), "config", "configuration file" ); opts.parse( argc, argv ); @@ -273,7 +293,7 @@ Opts opts; - opts.add( 'f', "config", "configuration file",true ); + opts.add( 'f', string("default.conf"), "config", "configuration file" ); opts.parse( argc, argv ); @@ -294,7 +314,7 @@ Opts opts; - opts.add( 'a', "a-option", "option a" ); + opts.addflag( 'a', "a-option", "option a" ); opts.parse( argc, argv ); @@ -338,21 +358,20 @@ Opts opts; - opts.add( 's', "start-point", "start point", true ); + opts.add( 's', point(1,1) ,"start-point", "start point"); opts.parse( argc, argv ); - point p( 1, 1 ); + point p = opts.get<point>( 's' ); - opts.get( 's', p ); - - EXAM_CHECK( (p.x == 1) && (p.y = 2) ); + EXAM_CHECK( (p.x == 1) && (p.y == 2) ); } return EXAM_RESULT; } -int EXAM_IMPL(opts_test::reduction) +// check whether autocomplement works +int EXAM_IMPL(opts_test::autocomplement) { { const char* argv[] = { "name" , "--num" , "4"}; @@ -360,14 +379,37 @@ Opts opts; - opts.add('n',"number_of_processors","number of processors",true ); + opts.add('n',1,"number_of_processors","number of processors" ); opts.parse( argc, argv ); - int n; - opts.get('n',n); - EXAM_CHECK( n == 4 ); + EXAM_CHECK( opts.get<int>('n') == 4 ); } return EXAM_RESULT; } + +int EXAM_IMPL(opts_test::multiple_args) +{ + { + const char* argv[] = { "name" , "-I" , "first","-I","second","-I","third"}; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add('I',"/usr/include","include","include paths" ); + + opts.parse( argc, argv ); + + vector<string> vs(10); + + opts.getemall('I',vs.begin()); + + EXAM_CHECK( vs[0] == "/usr/include" ); + EXAM_CHECK( vs[1] == "first" ); + EXAM_CHECK( vs[2] == "second" ); + EXAM_CHECK( vs[3] == "third" ); + } + + return EXAM_RESULT; +} Modified: trunk/complement/explore/lib/misc/ut/opts_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-15 08:35:35 UTC (rev 1875) +++ trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-15 15:22:47 UTC (rev 1876) @@ -23,6 +23,7 @@ int EXAM_DECL(bool_option_long); int EXAM_DECL(int_option); int EXAM_DECL(int_option_long); + int EXAM_DECL(defaults); int EXAM_DECL(bad_option); int EXAM_DECL(bad_argument); int EXAM_DECL(multiple); @@ -30,7 +31,8 @@ int EXAM_DECL(args); int EXAM_DECL(stop); int EXAM_DECL(user_defined); - int EXAM_DECL(reduction); + int EXAM_DECL(autocomplement); + int EXAM_DECL(multiple_args); }; #endif // __MISC_TEST_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-05-15 08:36:12
|
Revision: 1875 http://complement.svn.sourceforge.net/complement/?rev=1875&view=rev Author: okechina Date: 2008-05-15 01:35:35 -0700 (Thu, 15 May 2008) Log Message: ----------- A new class "session" is created. All the server methods are collected in the class. Server checks if there is data available. Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-05-14 08:53:23 UTC (rev 1874) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-05-15 08:35:35 UTC (rev 1875) @@ -9,8 +9,15 @@ using namespace std; -command setCom( const string& str ) +session::session ( std::basic_istream<char>& is, std::basic_ostream<char>& os ) : + in(is), + out(os) { + st = connect; +}; + +command session::setCom( const string& str ) +{ string Str; for ( string::const_iterator i = str.begin(); i != str.end(); ++i ) { @@ -64,8 +71,9 @@ return none; } -void change( state& st, const command& com, const string& param, string& stout ) +void session::changeSt( const string& str, const string& param, std::string& stout ) { + com = session::setCom( str ); switch ( com ) { case helo: if (st == connect) { @@ -178,34 +186,35 @@ } } - -int ServerWork() +int session::checkData () { - state st = connect; - command com; - string param, message, stout; - - while ( st != disconnect ) { - if ( st != letter ) { - string str; - cin >> str; - getline(cin, param); - com = setCom(str); - change(st, com, param, stout); - cout << stout; + string str, param, stout; + if ( st != letter ) { + in >> str; + if ( str.empty() ) + return -1; + getline( in, param ); + changeSt( str, param, stout ); + out << stout << endl; + } else { + getline( in, param ); + if ( param.empty() ) + return -1; + if ( param != "." ) { + message += param + "\n"; } else { - getline( cin, param ); - if ( param != "." ) { - message += param + "\n"; - } else { - st = hello; - cout << message; - message = ""; - } + st = hello; +// cerr << message; + message = ""; } } - return 0; } + +state session::getState () +{ + return st; +} + } // namespace smtp Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-05-14 08:53:23 UTC (rev 1874) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-05-15 08:35:35 UTC (rev 1875) @@ -4,6 +4,7 @@ #define __SMPT_SERVER_H #include <string> +#include <iostream> namespace smtp { @@ -33,12 +34,28 @@ none }; -int ServerWork(); +class session +{ + private: + state st; + command com; + std::string message; -command setCom( const std::string& str ); + std::basic_istream<char>& in; + std::basic_ostream<char>& out; -void change( state& st, const command& com, const std::string& param, std::string& stout ); + command setCom ( const std::string& str ); + void changeSt ( const std::string& str, const std::string& param, std::string& stout ); + public: + session ( std::basic_istream<char>& is, std::basic_ostream<char>& os ); + ~session () + { }; + int checkData (); + + state getState (); +}; + } // namespace smtp #endif // __SMPT_SERVER_H Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-14 08:53:23 UTC (rev 1874) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-15 08:35:35 UTC (rev 1875) @@ -80,32 +80,11 @@ basic_ostream<char> out( &_out_buf ); #endif - state st = connect; - command com; - string param, message, stout; + smtp::session ss (in, out); - while ( st != disconnect ) { - if ( st != letter ) { - string str; - in >> str; - if ( str.empty() ) - break; - getline( in, param ); - com = setCom( str ); - change( st, com, param, stout ); - out << stout << endl; - } else { - getline( in, param ); - if ( param.empty() ) - break; - if ( param != "." ) { - message += param + "\n"; - } else { - st = hello; -// cerr << message; - message = ""; - } - } + while ( ss.getState() != disconnect ) { + int t = ss.checkData(); + if ( t < 0 ) break; } close(fd2[0]); @@ -142,14 +121,14 @@ getline( in_tst, s ); if ( !s.empty() ) { out << s << endl; -// cerr << s << endl; + cerr << s << endl; do { getline (in, result); -// cerr << result << endl; + cerr << result << endl; } while ( result[3] == '-' ); } } - + close(fd2[1]); close(fd1[0]); t.join(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Dmi...@us...> - 2008-05-14 08:53:25
|
Revision: 1874 http://complement.svn.sourceforge.net/complement/?rev=1874&view=rev Author: DmitryOsmakov Date: 2008-05-14 01:53:23 -0700 (Wed, 14 May 2008) Log Message: ----------- fixed lib Opts : unit tests was corrected, reduction test was added, field "option cnt" in opt class was added, operands is now returned in argv , argc is modified Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/opts_test.h Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-05-06 09:05:14 UTC (rev 1873) +++ trunk/complement/explore/include/misc/opts.h 2008-05-14 08:53:23 UTC (rev 1874) @@ -13,6 +13,7 @@ class Opt { public: + Opt() { cnt = 0; } char shortname; std::string longname; std::string desc; @@ -20,6 +21,7 @@ bool has_arg; bool is_set; + int cnt; // number of times this option was encounterd in command line }; class Opts @@ -44,8 +46,11 @@ bool is_set( char _shortname ); bool is_set( const std::string& _longname ); + int get_cnt( char _shortname ) const; + int get_cnt( const std::string& _longname ) const; + // parse - void parse(int ac, const char** av); + void parse(int& ac, const char** av); // stuff void help(std::ostream& out); @@ -85,7 +90,7 @@ }; - std::vector< std::string > args; + //std::vector< std::string > args; private: // data std::vector< Opt > storage; Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-05-06 09:05:14 UTC (rev 1873) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-14 08:53:23 UTC (rev 1874) @@ -126,11 +126,28 @@ return false; } -void Opts::parse(int ac,const char** av) +int Opts::get_cnt(char _shortname) const { + for (int i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + return storage[i].cnt; + return 0; +} + +int Opts::get_cnt(const string& _longname) const +{ + for (int i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + return storage[i].cnt; + return 0; +} + +void Opts::parse(int& ac,const char** av) +{ pname = av[0]; int i = 1; + int j = 1; while (i < ac && !isterm(av[i])) { if (is_opt_name(av[i])) @@ -152,28 +169,21 @@ throw invalid_opt(opt); else { + storage[p].is_set = true; + storage[p].cnt++; if (storage[p].has_arg) { if (!arg.empty()) - { - storage[p].is_set = true; storage[p].args.push_back(arg); - } else if (i + 1 < ac) - { - storage[p].is_set = true; storage[p].args.push_back(av[++i]); - } else throw missing_arg(opt); } else - { - storage[p].is_set = true; - if (!arg.empty()) + if (!arg.empty()) //unexpected arg throw invalid_arg(opt,arg); - } } } else @@ -188,18 +198,23 @@ else { storage[p].is_set = true; + storage[p].cnt++; if (storage[p].has_arg) throw missing_arg( "-" + string(1,optgroup[j]) ); } } } else - args.push_back(av[i]); + { + av[j++] = av[i]; + //args.push_back(av[i]); + } i++; } i += (i < ac && isterm(av[i])); while (i < ac) - args.push_back(av[i++]); + av[j++] = av[i++]; //args.push_back(av[i++]); + ac = j; } Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-06 09:05:14 UTC (rev 1873) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-14 08:53:23 UTC (rev 1874) @@ -71,5 +71,15 @@ t.add( &opts_test::user_defined, opts, "user-defined type" ); + t.add( &opts_test::compound, opts, "compound" ); + + t.add( &opts_test::multiple, opts,"multiple"); + + t.add( &opts_test::args, opts,"args"); + + t.add( &opts_test::stop, opts,"stop"); + + t.add( &opts_test::reduction, opts,"reduction"); + return t.girdle(); }; Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-06 09:05:14 UTC (rev 1873) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-14 08:53:23 UTC (rev 1874) @@ -68,7 +68,7 @@ Opts opts; - opts.add( 'p', "port", "listen tcp port" ); + opts.add( 'p', "port", "listen tcp port" , true); try { opts.parse( argc, argv ); @@ -93,7 +93,7 @@ Opts opts; - opts.add( 'p', "port", "listen tcp port" ); + opts.add( 'p', "port", "listen tcp port" , true ); try { opts.parse( argc, argv ); @@ -179,6 +179,8 @@ opts.add( 'v', "verbose", "more trace messages" ); opts.parse( argc, argv ); + + EXAM_CHECK( opts.get_cnt('v') == 3 ); } { @@ -190,6 +192,8 @@ opts.add( 'v', "verbose", "more trace messages" ); opts.parse( argc, argv ); + + EXAM_CHECK( opts.get_cnt('v') == 3 ); } { @@ -201,6 +205,8 @@ opts.add( 'v', "verbose", "more trace messages" ); opts.parse( argc, argv ); + + EXAM_CHECK( opts.get_cnt('v') == 3 ); } return EXAM_RESULT; @@ -219,8 +225,11 @@ opts.add( 'c', "c-option", "option c" ); opts.parse( argc, argv ); + + EXAM_CHECK(opts.is_set('a') && opts.is_set('b') && opts.is_set('c')); } + return EXAM_RESULT; } @@ -232,7 +241,7 @@ Opts opts; - opts.add( 'f', "config", "configuration file" ); + opts.add( 'f', "config", "configuration file",true ); opts.parse( argc, argv ); @@ -248,7 +257,7 @@ Opts opts; - opts.add( 'f', "config", "configuration file" ); + opts.add( 'f', "config", "configuration file",true ); opts.parse( argc, argv ); @@ -264,7 +273,7 @@ Opts opts; - opts.add( 'f', "config", "configuration file" ); + opts.add( 'f', "config", "configuration file",true ); opts.parse( argc, argv ); @@ -342,3 +351,23 @@ return EXAM_RESULT; } + +int EXAM_IMPL(opts_test::reduction) +{ + { + const char* argv[] = { "name" , "--num" , "4"}; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add('n',"number_of_processors","number of processors",true ); + + opts.parse( argc, argv ); + + int n; + opts.get('n',n); + EXAM_CHECK( n == 4 ); + } + + return EXAM_RESULT; +} Modified: trunk/complement/explore/lib/misc/ut/opts_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-06 09:05:14 UTC (rev 1873) +++ trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-14 08:53:23 UTC (rev 1874) @@ -30,6 +30,7 @@ int EXAM_DECL(args); int EXAM_DECL(stop); int EXAM_DECL(user_defined); + int EXAM_DECL(reduction); }; #endif // __MISC_TEST_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-05-06 09:05:21
|
Revision: 1873 http://complement.svn.sourceforge.net/complement/?rev=1873&view=rev Author: okechina Date: 2008-05-06 02:05:14 -0700 (Tue, 06 May 2008) Log Message: ----------- Client requests and server answers are written and read using streams only. Client can get multi string answer from server. Server terminates after client's disconnection. Server does not return \n at the end of answer. Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-05-05 14:18:45 UTC (rev 1872) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-05-06 09:05:14 UTC (rev 1873) @@ -69,10 +69,10 @@ switch ( com ) { case helo: if (st == connect) { - stout = "250 localhost Hello localhost, pleased to meet you\n"; + stout = "250 localhost Hello localhost, pleased to meet you"; st = hello; } else { - stout = "503 localhost Duplicate HELO/EHLO\n"; + stout = "503 localhost Duplicate HELO/EHLO"; } return; @@ -81,27 +81,27 @@ stout = "250-localhost Hello localhost, pleased to meet you\n"; stout += "250-8BITMIME\n"; stout += "250-SIZE 8000000\n"; - stout += "250 HELP\n"; + stout += "250 HELP"; st = hello; } else { - stout = "503 localhost Duplicate HELO/EHLO\n"; + stout = "503 localhost Duplicate HELO/EHLO"; } return; case mail: switch (st) { case connect: - stout = "503 Polite people say HELO first\n"; + stout = "503 Polite people say HELO first"; return; case hello: - stout = "250 " + param + "... Sender ok\n"; + stout = "250 " + param + "... Sender ok"; st = sender; return; case sender: - stout = "503 Sender already specified\n"; + stout = "503 Sender already specified"; return; case recipient: - stout = "503 Sender already specified\n"; + stout = "503 Sender already specified"; return; } break; @@ -109,17 +109,17 @@ case rcpt: switch (st) { case connect: - stout = "503 Need MAIL before RCPT\n"; + stout = "503 Need MAIL before RCPT"; return; case hello: - stout = "503 Need MAIL before RCPT\n"; + stout = "503 Need MAIL before RCPT"; return; case sender: - stout = "250 " + param + "... Recipient ok\n"; + stout = "250 " + param + "... Recipient ok"; st = recipient; return; case recipient: - stout = "250 " + param + "... Recipient ok\n"; + stout = "250 " + param + "... Recipient ok"; return; } break; @@ -127,53 +127,53 @@ case data: switch (st) { case connect: - stout = "503 Need MAIL command\n"; + stout = "503 Need MAIL command"; return; case hello: - stout = "503 Need MAIL command\n"; + stout = "503 Need MAIL command"; return; case sender: - stout = "503 Need RCPT (recipient)\n"; + stout = "503 Need RCPT (recipient)"; return; case recipient: - stout = "354 Enter mail, end with '.' on a line by itself\n"; + stout = "354 Enter mail, end with '.' on a line by itself"; st = letter; return; } break; case rset: - stout = "250 Reset state\n"; + stout = "250 Reset state"; if ( st != connect ) { st = hello; } return; case vrfy: - stout = "502 Command not implemented\n"; + stout = "502 Command not implemented"; return; case expn: - stout = "502 Command not implemented\n"; + stout = "502 Command not implemented"; return; case help: stout = "214-This is SMTP_Server\n"; - stout += "214 End of HELP info\n"; + stout += "214 End of HELP info"; return; case noop: - stout = "250 OK\n"; + stout = "250 OK"; return; case quit: - stout = "221 localhost closing connection\n"; - stout += "Connection closed by foreign host.\n"; + stout = "221 localhost closing connection; "; + stout += "Connection closed by foreign host."; st = disconnect; return; case none: - stout = "500 Command unrecognized\n"; + stout = "500 Command unrecognized"; return; } } Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:18:45 UTC (rev 1872) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-06 09:05:14 UTC (rev 1873) @@ -2,7 +2,6 @@ #include "my_test.h" - #include "SMTP_Server.h" #include <mt/thread> @@ -39,22 +38,7 @@ "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", // "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" }; - -//possible commands -// helo -// ehlo -// mail -// rcpt -// data -// rset -// vrfy -// expn -// help -// noop -// quit -// none - - + const string set_command[] = { "helo mail.ru", "ehlo mail.ru", @@ -71,31 +55,19 @@ }; const int set_result[][sizeof(set_command)/sizeof(set_command[0])] = { -// {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, - // {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, -// {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} }; -const int buf_size = 1024; -const int com_length = 4; -const int test_num = 0; - static int fd1[2], fd2[2]; typedef list<string> tests_container_type; static tests_container_type tests; -bool active; - void server_thread() { - char buffer[buf_size]; - state st = connect; - command com; #ifdef STLPORT ifstream in( fd2[0] ); @@ -107,100 +79,41 @@ __gnu_cxx::stdio_filebuf<char> _out_buf( fd1[1], std::ios_base::out ); basic_ostream<char> out( &_out_buf ); #endif - - + + state st = connect; + command com; string param, message, stout; + while ( st != disconnect ) { if ( st != letter ) { string str; in >> str; - getline(in, param); - com = setCom(str); - change(st, com, param, stout); - write( fd1[1], stout.data(), stout.length() ); -// out << stout; + if ( str.empty() ) + break; + getline( in, param ); + com = setCom( str ); + change( st, com, param, stout ); + out << stout << endl; } else { getline( in, param ); + if ( param.empty() ) + break; if ( param != "." ) { message += param + "\n"; } else { st = hello; -// out << message; +// cerr << message; message = ""; } } } - - -/* while ( st != disconnect ) { - if ( st != letter ) { - bool full = false; - stringstream st_stream; - while (!full) { - int n = read( fd2[0], buffer, sizeof(buffer) ); - if ( n < 0 ) { - cerr << "Reading error\n"; - break; - } else if ( n == 0 ) { - break; - } else { - buffer[n] = '\0'; - cerr << ">> " << buffer; - st_stream << buffer; - full = full || (buffer[n-1] == '\n'); - } - }; - if (full) { - while (st_stream.good()) { - string str; - string param, stout; - st_stream >> str; - if (str != "") { - getline (st_stream, param); -// param.assign( str, com_length, str.size() ); -// str.erase( com_length, str.size() - com_length + 1 ); - com = setCom( str ); - change( st, com, param, stout ); - write( fd1[1], stout.data(), stout.length() ); - } - } - } else { //error appeared while reading a command - break; - }; - } else { - string message, s; - int n = read( fd2[0], buffer, sizeof(buffer) ); - if ( n < 0 ) { - cerr << "Reading error\n"; - break; - } else if ( n == 0 ) { - cerr << "Empty\n"; - break; - } else { - buffer[n] = '\0'; - s.assign (buffer, 0, n); - if ( s != "." ) { - message += s + "\n"; - } else { - st = hello; - // cout << message; - message = ""; - } - } - } - } -*/ close(fd2[0]); close(fd1[1]); - active = false; - // cerr << "Server's loop may be here" << endl; } int EXAM_IMPL(my_test::thread_call) { - active = false; - string s; string expected; string result; @@ -219,74 +132,34 @@ __gnu_cxx::stdio_filebuf<char> _out_buf( fd2[1], std::ios_base::out ); basic_ostream<char> out( &_out_buf ); #endif - char r_buffer[buf_size], w_buffer[buf_size]; std::tr2::basic_thread<0,0> t( server_thread ); - active = true; istringstream in_tst( *i ); - getline( in_tst, expected ); while ( in_tst.good() ){ getline( in_tst, s ); if ( !s.empty() ) { - out << s << endl; // write( fd2[1], s.data(), s.length() ); - // write( fd2[1], "\n", 1 ); -/* int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); - if ( n < 0 ) { - cerr << "Reading error\n"; - break; - } else if ( n == 0 ) { - cerr << "Empty string\n"; - break; - } else { - r_buffer[n] = '\0'; - cerr << "<< " << r_buffer; - } - out << s << "\n"; -*/ cerr << s << "\n"; -// do { + out << s << endl; +// cerr << s << endl; + do { getline (in, result); - cerr << result; -// } while (!result.empty()); -// if (result.empty()) cerr << "Empty"; +// cerr << result << endl; + } while ( result[3] == '-' ); } } -// string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); -// write( fd2[1], str.data(), str.length() ); - close(fd2[1]); close(fd1[0]); - t.join(); -// string result(r_buffer); if ( expected.compare(0, 3, result, 0, 3) != 0 ) { cerr << expected << "!=" << result << " at " << *i << endl; } EXAM_CHECK( expected.compare(0, 3, result, 0, 3) == 0 ); } -/* strcpy (w_buffer, "help"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; - - strcpy (w_buffer, "quit"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; - - cerr << "Client's text may be here" << endl; -*/ - // EXAM_CHECK( val == 1 ); - // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); - // t2.join(); - // EXAM_CHECK( val == 2 ); - // val = 0; - return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-05-05 14:18:47
|
Revision: 1872 http://complement.svn.sourceforge.net/complement/?rev=1872&view=rev Author: complement Date: 2008-05-05 07:18:45 -0700 (Mon, 05 May 2008) Log Message: ----------- flush for output stream, in endl manipulator Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:11:27 UTC (rev 1871) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:18:45 UTC (rev 1872) @@ -231,8 +231,8 @@ while ( in_tst.good() ){ getline( in_tst, s ); if ( !s.empty() ) { - write( fd2[1], s.data(), s.length() ); - write( fd2[1], "\n", 1 ); + out << s << endl; // write( fd2[1], s.data(), s.length() ); + // write( fd2[1], "\n", 1 ); /* int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-05-05 14:11:37
|
Revision: 1871 http://complement.svn.sourceforge.net/complement/?rev=1871&view=rev Author: okechina Date: 2008-05-05 07:11:27 -0700 (Mon, 05 May 2008) Log Message: ----------- Creating client-server dialog using streams for input/output Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-03 05:38:59 UTC (rev 1870) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-05 14:11:27 UTC (rev 1871) @@ -101,15 +101,39 @@ ifstream in( fd2[0] ); ofstream out( fd1[1] ); #elif defined( __GNUC__ ) - __gnu_cxx::stdio_filebuf _in_buf( fd2[0], std::ios_base::in ); + __gnu_cxx::stdio_filebuf<char> _in_buf( fd2[0], std::ios_base::in ); basic_istream<char> in( &_in_buf ); - __gnu_cxx::stdio_filebuf _out_buf( fd1[1], std::ios_base::out ); - basic_istream<char> in( &_out_buf ); + __gnu_cxx::stdio_filebuf<char> _out_buf( fd1[1], std::ios_base::out ); + basic_ostream<char> out( &_out_buf ); #endif + + string param, message, stout; while ( st != disconnect ) { if ( st != letter ) { + string str; + in >> str; + getline(in, param); + com = setCom(str); + change(st, com, param, stout); + write( fd1[1], stout.data(), stout.length() ); +// out << stout; + } else { + getline( in, param ); + if ( param != "." ) { + message += param + "\n"; + } else { + st = hello; +// out << message; + message = ""; + } + } + } + + +/* while ( st != disconnect ) { + if ( st != letter ) { bool full = false; stringstream st_stream; while (!full) { @@ -127,14 +151,12 @@ } }; if (full) { - cerr << st_stream.str(); while (st_stream.good()) { string str; string param, stout; st_stream >> str; if (str != "") { getline (st_stream, param); - cerr << param; // param.assign( str, com_length, str.size() ); // str.erase( com_length, str.size() - com_length + 1 ); com = setCom( str ); @@ -167,9 +189,10 @@ } } } +*/ + close(fd2[0]); close(fd1[1]); - active = false; // cerr << "Server's loop may be here" << endl; } @@ -180,7 +203,8 @@ string s; string expected; - + string result; + for ( tests_container_type::const_iterator i = tests.begin(); i != tests.end(); ++i ) { pipe( fd1 ); pipe( fd2 ); @@ -189,11 +213,11 @@ ifstream in( fd1[0] ); ofstream out( fd2[1] ); #elif defined( __GNUC__ ) - __gnu_cxx::stdio_filebuf _in_buf( fd1[0], std::ios_base::in ); + __gnu_cxx::stdio_filebuf<char> _in_buf( fd1[0], std::ios_base::in ); basic_istream<char> in( &_in_buf ); - __gnu_cxx::stdio_filebuf _out_buf( fd2[1], std::ios_base::out ); - basic_istream<char> in( &_out_buf ); + __gnu_cxx::stdio_filebuf<char> _out_buf( fd2[1], std::ios_base::out ); + basic_ostream<char> out( &_out_buf ); #endif char r_buffer[buf_size], w_buffer[buf_size]; @@ -204,12 +228,12 @@ getline( in_tst, expected ); - while ( in.good() ){ + while ( in_tst.good() ){ getline( in_tst, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); write( fd2[1], "\n", 1 ); - int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); +/* int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; break; @@ -220,24 +244,31 @@ r_buffer[n] = '\0'; cerr << "<< " << r_buffer; } + out << s << "\n"; +*/ cerr << s << "\n"; +// do { + getline (in, result); + cerr << result; +// } while (!result.empty()); +// if (result.empty()) cerr << "Empty"; } } - string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); - write( fd2[1], str.data(), str.length() ); +// string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); +// write( fd2[1], str.data(), str.length() ); close(fd2[1]); close(fd1[0]); t.join(); - string result(r_buffer); +// string result(r_buffer); if ( expected.compare(0, 3, result, 0, 3) != 0 ) { cerr << expected << "!=" << result << " at " << *i << endl; } EXAM_CHECK( expected.compare(0, 3, result, 0, 3) == 0 ); - + } /* strcpy (w_buffer, "help"); write (fd2[1], w_buffer, sizeof(w_buffer)); read (fd1[0], r_buffer, sizeof(r_buffer)); @@ -250,7 +281,6 @@ cerr << "Client's text may be here" << endl; */ - } // EXAM_CHECK( val == 1 ); // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); // t2.join(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-05-03 05:39:02
|
Revision: 1870 http://complement.svn.sourceforge.net/complement/?rev=1870&view=rev Author: complement Date: 2008-05-02 22:38:59 -0700 (Fri, 02 May 2008) Log Message: ----------- Use container with strings for tests instead of files; Sample: how to use istream instead of raw io; not finished, just suggestion. Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Removed Paths: ------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/aux/ Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-01 11:24:15 UTC (rev 1869) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-03 05:38:59 UTC (rev 1870) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/25 15:23:35 yeti> +// -*- C++ -*- Time-stamp: <08/05/03 09:31:01 ptr> #include "my_test.h" @@ -13,6 +13,9 @@ #include <iostream> #include <fstream> +#ifndef STLPORT +# include <ext/stdio_filebuf.h> +#endif #include <sstream> #include <unistd.h> @@ -83,6 +86,9 @@ static int fd1[2], fd2[2]; +typedef list<string> tests_container_type; +static tests_container_type tests; + bool active; void server_thread() @@ -90,6 +96,18 @@ char buffer[buf_size]; state st = connect; command com; + +#ifdef STLPORT + ifstream in( fd2[0] ); + ofstream out( fd1[1] ); +#elif defined( __GNUC__ ) + __gnu_cxx::stdio_filebuf _in_buf( fd2[0], std::ios_base::in ); + basic_istream<char> in( &_in_buf ); + + __gnu_cxx::stdio_filebuf _out_buf( fd1[1], std::ios_base::out ); + basic_istream<char> in( &_out_buf ); +#endif + while ( st != disconnect ) { if ( st != letter ) { bool full = false; @@ -157,29 +175,37 @@ } int EXAM_IMPL(my_test::thread_call) -{ - pipe (fd1); - pipe (fd2); - +{ active = false; string s; string expected; - for ( int i = 0; i <= test_num; ++i ) { + + for ( tests_container_type::const_iterator i = tests.begin(); i != tests.end(); ++i ) { + pipe( fd1 ); + pipe( fd2 ); + +#ifdef STLPORT + ifstream in( fd1[0] ); + ofstream out( fd2[1] ); +#elif defined( __GNUC__ ) + __gnu_cxx::stdio_filebuf _in_buf( fd1[0], std::ios_base::in ); + basic_istream<char> in( &_in_buf ); + + __gnu_cxx::stdio_filebuf _out_buf( fd2[1], std::ios_base::out ); + basic_istream<char> in( &_out_buf ); +#endif char r_buffer[buf_size], w_buffer[buf_size]; std::tr2::basic_thread<0,0> t( server_thread ); active = true; - ostringstream st; - st << "aux/test_" << i; + istringstream in_tst( *i ); - ifstream in( st.str().c_str() ); + getline( in_tst, expected ); - getline( in, expected ); - while ( in.good() ){ - getline( in, s ); + getline( in_tst, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); write( fd2[1], "\n", 1 ); @@ -197,17 +223,17 @@ } } -// string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); + string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); write( fd2[1], str.data(), str.length() ); close(fd2[1]); close(fd1[0]); - in.close(); + t.join(); string result(r_buffer); if ( expected.compare(0, 3, result, 0, 3) != 0 ) { - cerr << expected << "!=" << result << " at " << i << endl; + cerr << expected << "!=" << result << " at " << *i << endl; } EXAM_CHECK( expected.compare(0, 3, result, 0, 3) == 0 ); @@ -237,17 +263,15 @@ int EXAM_IMPL(my_test::test_gen) { - int num = 1; + tests.push_back( string( "221\nhelo ya.ru\nhelp\nquit\n" ) ); // aka test_0 for ( int i = 0; i < sizeof(set_state)/sizeof(set_state[0]); ++i ) { for ( int j = 0; j < sizeof(set_command)/sizeof(set_command[0]); ++j ) { - ostringstream st; - st << "aux/test_" << num++; + stringstream os; - ofstream os( st.str().c_str() ); + os << set_result[i][j] << "\n" << set_state[i] << set_command[j]; - os << set_result[i][j] << "\n" - << set_state[i] << set_command[j]; + tests.push_back( os.str() ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-05-01 11:24:33
|
Revision: 1869 http://complement.svn.sourceforge.net/complement/?rev=1869&view=rev Author: complement Date: 2008-05-01 04:24:15 -0700 (Thu, 01 May 2008) Log Message: ----------- clean code; remove 'use namespace std' from header; push functionality demonstration/development/debugging into unit tests Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/ut/Makefile.inc trunk/complement/explore/lib/misc/ut/misc_test_suite.cc Added Paths: ----------- trunk/complement/explore/lib/misc/ut/opts_test.cc trunk/complement/explore/lib/misc/ut/opts_test.h Removed Paths: ------------- trunk/complement/explore/lib/misc/opts_usage.cpp Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-04-30 13:02:36 UTC (rev 1868) +++ trunk/complement/explore/include/misc/opts.h 2008-05-01 11:24:15 UTC (rev 1869) @@ -1,3 +1,5 @@ +// -*- C++ -*- Time-stamp: <08/05/01 12:02:26 ptr> + #ifndef __OPTS_H__ #define __OPTS_H__ @@ -8,77 +10,103 @@ #include <typeinfo> #include <cctype> -using namespace std; - class Opt { -public: - char shortname; - string longname; - string desc; - vector< string > args; + public: + char shortname; + std::string longname; + std::string desc; + std::vector< std::string > args; - bool has_arg; - bool is_set; + bool has_arg; + bool is_set; }; class Opts { -public: -// construct - Opts(const string& _brief = "",const string& _author = "",const string& _copyright = "") : brief(_brief) , author(_author) , copyright(_copyright) {}; + public: + Opts( const std::string& _brief = "", const std::string& _author = "", const std::string& _copyright = "") : + brief(_brief), + author(_author), + copyright(_copyright) + { } -// adding option - void add(char _shortname,const string& _longname = "",const string& _desc = "",bool has_arg = false); + // adding option + void add( char _shortname, const std::string& _longname = "", const std::string& _desc = "", bool has_arg = false ); -// getting option - template <class T> - T get(char _shortname,T& dest); - template <class T> - T get(const string& _longname,T& dest); + // getting option + template <class T> + T get( char _shortname, T& dest ); + + template <class T> + T get( const std::string& _longname, T& dest ); - bool is_set(char _shortname); - bool is_set(const string& _longname); + bool is_set( char _shortname ); + bool is_set( const std::string& _longname ); + // parse + void parse(int ac, const char** av); -// parse - void parse(int ac,char** av); + // stuff + void help(std::ostream& out); + std::string get_pname() const; + std::string get_brief() const; + std::string get_author() const; + std::string get_copyright() const; -// stuff - void help(ostream& out); - string get_pname() const; - string get_brief() const; - string get_author() const; - string get_copyright() const; + // error handling + struct invalid_opt + { + std::string optname; -// error handling - struct invalid_opt { string optname; invalid_opt(const string& _optname) : optname(_optname) {}; }; - struct missing_arg { string optname; missing_arg(const string& _optname) : optname(_optname) {}; }; - struct invalid_arg { string optname,argname; invalid_arg(const string& _optname,const string& _argname) : optname(_optname) , argname(_argname) {}; }; + invalid_opt(const std::string& _optname) : + optname(_optname) + { } + }; + struct missing_arg + { + std::string optname; + + missing_arg( const std::string& _optname) : + optname(_optname) + { } + }; + + struct invalid_arg + { + std::string optname; + std::string argname; + + invalid_arg( const std::string& _optname, const std::string& _argname) : + optname(_optname), + argname(_argname) + { } + }; + - vector< string > args; -private: - // data - vector< Opt > storage; + std::vector< std::string > args; + private: + // data + std::vector< Opt > storage; - string pname; - string brief; - string author; - string copyright; + std::string pname; + std::string brief; + std::string author; + std::string copyright; - bool isterm(const string& s); - bool is_opt_name(const string& s); - bool is_flag_group(const string& s); - bool is_substr(const string& small,const string& big); - int get_opt_index(string s); + bool isterm( const std::string& s ); + bool is_opt_name( const std::string& s ); + bool is_flag_group( const std::string& s ); + bool is_substr(const std::string& small, const std::string& big ); + int get_opt_index( std::string s ); }; template <class T> -T Opts::get(char _shortname,T& res) +T Opts::get( char _shortname, T& res ) { int i; - for (i = 0;i < storage.size();i++) + for (i = 0;i < storage.size();i++) { if (storage[i].shortname == _shortname) { if (storage[i].is_set && storage[i].has_arg) @@ -86,23 +114,24 @@ { try { - stringstream ss(storage[i].args[0]); + std::stringstream ss(storage[i].args[0]); ss >> res; } catch(...) { - throw invalid_arg(string("-") + string(1,_shortname),storage[i].args[0]); + throw invalid_arg(std::string("-") + std::string(1,_shortname),storage[i].args[0]); } } break; - } + } + } if (i == storage.size()) - throw invalid_opt(string("-") + string(1,_shortname)); + throw invalid_opt(std::string("-") + std::string(1,_shortname)); return res; } template <class T> -T Opts::get(const string& _longname,T& res) +T Opts::get(const std::string& _longname,T& res) { int i; for (i = 0;i < storage.size();i++) @@ -113,7 +142,7 @@ { try { - stringstream ss(storage[i].args[0]); + std::stringstream ss(storage[i].args[0]); ss >> res; } catch(...) Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-04-30 13:02:36 UTC (rev 1868) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-05-01 11:24:15 UTC (rev 1869) @@ -2,8 +2,9 @@ #include <string> #include <sstream> #include <typeinfo> -#include "opts.h" +#include <misc/opts.h> + using namespace std; string Opts::get_pname() const { return pname; } @@ -125,7 +126,7 @@ return false; } -void Opts::parse(int ac,char** av) +void Opts::parse(int ac,const char** av) { pname = av[0]; Deleted: trunk/complement/explore/lib/misc/opts_usage.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts_usage.cpp 2008-04-30 13:02:36 UTC (rev 1868) +++ trunk/complement/explore/lib/misc/opts_usage.cpp 2008-05-01 11:24:15 UTC (rev 1869) @@ -1,92 +0,0 @@ -#include <iostream> -#include <string> -#include "opts.h" - -using namespace std; - -struct point -{ - int x; - int y; - point(int _x = 0,int _y = 0) : x(_x) , y(_y) {}; -}; - -istream& operator>>(istream& t,point& p) -{ - t >> p.x >> p.y; - return t; -} - -ostream& operator<<(ostream& t,const point& p) -{ - t << p.x << ' ' << p.y; - return t; -} - -int main(int ac,char** av) -{ - Opts opts; - - // control variables with default values - point p(1,1); - string name = "maos"; - int port = 80; - - opts.add('h',"help","display help message"); - opts.add('v',"verbose","verbose"); - opts.add('j',"just","just do it"); - - opts.add('p',"port","port number",true); - opts.add('s',"point","start point",true); - opts.add('n',"name","your name",true); - opts.add('g'); - - try - { - opts.parse(ac,av); - } - catch(Opts::invalid_opt& t) - { - cout << "Invalid option: " << t.optname << endl; - return 1; - } - catch(Opts::invalid_arg& t) - { - cout << "Invalid argument: " << t.optname << ' ' << t.argname << endl; - return 1; - } - catch(Opts::missing_arg& t) - { - cout << "Missing argument: " << t.optname << endl; - return 1; - } - - if (opts.is_set('h')) - opts.help(cout); - - if (opts.is_set('v')) - cout << "Verbose mode is set" << endl; - else - cout << "Verbose mode is not set" << endl; - - if (opts.is_set('g')) - cout << "-g is set" << endl; - else - cout << "-g is not set" << endl; - - if (opts.is_set("just")) - cout << "Just do it!" << endl; - else - cout << "Just don't do it!" << endl; - - cout << "port = " << opts.get('p',port) << endl; - cout << "point = " << opts.get('s',p) << endl; - cout << "name = " << opts.get('n',name) << endl; - - cout << "operands: " << endl; - - for (int i = 0;i < opts.args.size();i++) - cout << opts.args[i] << endl; - - return 0; -} Modified: trunk/complement/explore/lib/misc/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) +++ trunk/complement/explore/lib/misc/ut/Makefile.inc 2008-05-01 11:24:15 UTC (rev 1869) @@ -1,5 +1,7 @@ -# -*- makefile -*- Time-stamp: <07/07/16 22:12:31 ptr> +# -*- makefile -*- Time-stamp: <08/05/01 12:00:01 ptr> PRGNAME = misc_ut SRC_CC = unit_test.cc \ - misc_test.cc misc_test_suite.cc + misc_test.cc misc_test_suite.cc opts_test.cc + +SRC_CPP = ../opts.cpp Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-04-30 13:02:36 UTC (rev 1868) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-05-01 11:24:15 UTC (rev 1869) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/12/02 18:57:27 ptr> +// -*- C++ -*- Time-stamp: <08/05/01 15:18:28 ptr> /* - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -10,6 +10,7 @@ #include "misc_test_suite.h" #include "misc_test.h" +#include "opts_test.h" #include <config/feature.h> @@ -54,5 +55,21 @@ t.add( &misc_test::type_traits_is_pod, test, "is_pod", tc[0] ); t.add( &misc_test::type_traits_is_empty, test, "is_empty", tc[0] ); + + // test for options parsing + + opts_test opts; + + t.add( &opts_test::bool_option_long, opts, "simple boolean option, long", + t.add( &opts_test::bool_option, opts, "simple boolean option" ) ); + + t.add( &opts_test::int_option_long, opts, "option with int parameter, long", + t.add( &opts_test::int_option, opts, "option with int parameter" ) ); + + t.add( &opts_test::bad_option, opts, "bad option" ); + t.add( &opts_test::bad_argument, opts, "bad argument" ); + + t.add( &opts_test::user_defined, opts, "user-defined type" ); + return t.girdle(); }; Added: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc (rev 0) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-05-01 11:24:15 UTC (rev 1869) @@ -0,0 +1,344 @@ +// -*- C++ -*- Time-stamp: <08/05/01 15:16:10 ptr> + +/* + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include "opts_test.h" + +#include <misc/opts.h> + +// #include <iostream> + +using namespace std; + +int EXAM_IMPL(opts_test::bool_option) +{ + const char* argv[] = { "name", "-h" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'h', "help", "print this help message" ); + + try { + opts.parse( argc, argv ); + + EXAM_CHECK( opts.is_set( 'h' ) ); + } + catch ( const Opts::invalid_opt& e ) { + } + catch ( const Opts::invalid_arg& e ) { + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::bool_option_long) +{ + const char* argv[] = { "name", "--help" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'h', "help", "print this help message" ); + + try { + opts.parse( argc, argv ); + + EXAM_CHECK( opts.is_set( 'h' ) ); + } + catch ( const Opts::invalid_opt& e ) { + } + catch ( const Opts::invalid_arg& e ) { + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::int_option) +{ + + const char* argv[] = { "name", "-p", "80" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'p', "port", "listen tcp port" ); + + try { + opts.parse( argc, argv ); + + int port = 0; + + EXAM_CHECK( opts.is_set( 'p' ) ); + EXAM_CHECK( opts.get( 'p', port ) == 80 ); + } + catch ( const Opts::invalid_opt& e ) { + } + catch ( const Opts::invalid_arg& e ) { + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::int_option_long) +{ + const char* argv[] = { "name", "--port=80" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'p', "port", "listen tcp port" ); + + try { + opts.parse( argc, argv ); + + int port = 0; + + EXAM_CHECK( opts.is_set( 'p' ) ); + EXAM_CHECK( opts.get( 'p', port ) == 80 ); + } + catch ( const Opts::invalid_opt& e ) { + } + catch ( const Opts::invalid_arg& e ) { + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::bad_option) +{ + const char* argv[] = { "name", "-v" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'h', "help", "print this help message" ); + + bool exception_happens = false; + + try { + opts.parse( argc, argv ); + + EXAM_ERROR( "exception expected" ); + } + catch ( const Opts::invalid_opt& e ) { + exception_happens = true; + EXAM_CHECK( e.optname == "-v" ); + } + catch ( const Opts::invalid_arg& e ) { + } + + EXAM_CHECK( exception_happens ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::bad_argument) +{ + const char* argv[] = { "name", "--port=www" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'p', "port", "listen tcp port" ); + + bool exception_happens = false; + + try { + opts.parse( argc, argv ); + + EXAM_ERROR( "exception expected" ); + } + catch ( const Opts::invalid_opt& e ) { + } + catch ( const Opts::invalid_arg& e ) { + exception_happens = true; + EXAM_CHECK( e.optname == "--port" ); + EXAM_CHECK( e.argname == "www" ); + } + + EXAM_CHECK( exception_happens ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::multiple) +{ + { + const char* argv[] = { "name", "-vvv" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'v', "verbose", "more trace messages" ); + + opts.parse( argc, argv ); + } + + { + const char* argv[] = { "name", "-v", "-v", "-v" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'v', "verbose", "more trace messages" ); + + opts.parse( argc, argv ); + } + + { + const char* argv[] = { "name", "--verbose", "--verbose", "--verbose" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'v', "verbose", "more trace messages" ); + + opts.parse( argc, argv ); + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::compound) +{ + { + const char* argv[] = { "name", "-abc" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'a', "a-option", "option a" ); + opts.add( 'b', "b-option", "option b" ); + opts.add( 'c', "c-option", "option c" ); + + opts.parse( argc, argv ); + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::args) +{ + { + const char* argv[] = { "name", "-f", "filename.conf", "file1", "file2" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'f', "config", "configuration file" ); + + opts.parse( argc, argv ); + + EXAM_CHECK( argc == 3 ); + EXAM_CHECK( argv[0] == "name" ); + EXAM_CHECK( argv[1] == "file1" ); + EXAM_CHECK( argv[2] == "file2" ); + } + + { + const char* argv[] = { "name", "file1", "file2", "-f", "filename.conf" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'f', "config", "configuration file" ); + + opts.parse( argc, argv ); + + EXAM_CHECK( argc == 3 ); + EXAM_CHECK( argv[0] == "name" ); + EXAM_CHECK( argv[1] == "file1" ); + EXAM_CHECK( argv[2] == "file2" ); + } + + { + const char* argv[] = { "name", "file1", "-f", "filename.conf", "file2" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'f', "config", "configuration file" ); + + opts.parse( argc, argv ); + + EXAM_CHECK( argc == 3 ); + EXAM_CHECK( argv[0] == "name" ); + EXAM_CHECK( argv[1] == "file1" ); + EXAM_CHECK( argv[2] == "file2" ); + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(opts_test::stop) +{ + { + const char* argv[] = { "name", "-a", "--", "-f" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 'a', "a-option", "option a" ); + + opts.parse( argc, argv ); + + EXAM_CHECK( argc == 2 ); + EXAM_CHECK( argv[1] == "-f" ); + } + + return EXAM_RESULT; +} + +struct point +{ + point( int _x = 0, int _y = 0 ) : + x(_x), + y(_y) + { } + + int x; + int y; +}; + +istream& operator >>( istream& s, point& p ) +{ + s >> p.x >> p.y; + + return s; +} + +ostream& operator <<( ostream& s, const point& p ) +{ + s << p.x << ' ' << p.y; + + return s; +} + +int EXAM_IMPL(opts_test::user_defined) +{ + { + const char* argv[] = { "name", "-s", "1 2" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts.add( 's', "start-point", "start point", true ); + + opts.parse( argc, argv ); + + point p( 1, 1 ); + + opts.get( 's', p ); + + EXAM_CHECK( (p.x == 1) && (p.y = 2) ); + } + + return EXAM_RESULT; +} Added: trunk/complement/explore/lib/misc/ut/opts_test.h =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.h (rev 0) +++ trunk/complement/explore/lib/misc/ut/opts_test.h 2008-05-01 11:24:15 UTC (rev 1869) @@ -0,0 +1,35 @@ +// -*- C++ -*- Time-stamp: <08/05/01 15:17:31 ptr> + +/* + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#ifndef __OPTS_TEST_H +#define __OPTS_TEST_H + +#define FIT_EXAM + +#include <exam/suite.h> + +class opts_test +{ + public: + // implementation + int EXAM_DECL(bool_option); + int EXAM_DECL(bool_option_long); + int EXAM_DECL(int_option); + int EXAM_DECL(int_option_long); + int EXAM_DECL(bad_option); + int EXAM_DECL(bad_argument); + int EXAM_DECL(multiple); + int EXAM_DECL(compound); + int EXAM_DECL(args); + int EXAM_DECL(stop); + int EXAM_DECL(user_defined); +}; + +#endif // __MISC_TEST_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-30 13:02:48
|
Revision: 1868 http://complement.svn.sourceforge.net/complement/?rev=1868&view=rev Author: complement Date: 2008-04-30 06:02:36 -0700 (Wed, 30 Apr 2008) Log Message: ----------- add example and sylog for fastcgi-daemon; custom build for Yandex Modified Paths: -------------- trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc trunk/complement/extern/custom/fastcgi-daemon/main/Makefile trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc trunk/complement/extern/custom/log4cxx/src/Makefile.inc Added Paths: ----------- trunk/complement/extern/custom/fastcgi-daemon/example/ trunk/complement/extern/custom/fastcgi-daemon/example/Makefile trunk/complement/extern/custom/fastcgi-daemon/example/Makefile.inc trunk/complement/extern/custom/fastcgi-daemon/syslog/ trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile.inc Property changes on: trunk/complement/extern/custom/fastcgi-daemon/example ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/fastcgi-daemon/example/Makefile =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/example/Makefile (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/example/Makefile 2008-04-30 13:02:36 UTC (rev 1868) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:15:40 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${FASTCGIDAEMON_SRC}/../include -I${FASTCGIDAEMON_SRC} -I../include -I/usr/include/libxml2 Added: trunk/complement/extern/custom/fastcgi-daemon/example/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/example/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/example/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:13:44 yeti> + +FASTCGIDAEMON_SRC = /home/yeti/FCGID-1/library +LIBPREFIX = +LIBNAME = example +MAJOR = 0 +MINOR = 0 +PATCH = 0 +SRC_CPP = ${FASTCGIDAEMON_SRC}/../example/example.cpp Modified: trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc 2008-04-29 14:12:55 UTC (rev 1867) +++ trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -1,6 +1,6 @@ # -*- makefile -*- Time-stamp: <08/04/29 11:13:44 yeti> -FASTCGIDAEMON_SRC = /export/hostel/labs/FastCGI/fastcgi-daemon-FCGID-1/library +FASTCGIDAEMON_SRC = /home/yeti/FCGID-1/library LIBNAME = fastcgi-daemon MAJOR = 0 MINOR = 0 Modified: trunk/complement/extern/custom/fastcgi-daemon/main/Makefile =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/main/Makefile 2008-04-29 14:12:55 UTC (rev 1867) +++ trunk/complement/extern/custom/fastcgi-daemon/main/Makefile 2008-04-30 13:02:36 UTC (rev 1868) @@ -3,7 +3,7 @@ SRCROOT := ../../../../explore # POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so -FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0 +FCGI_SRC = /home/yeti/fcgi-2.4.0 include Makefile.inc include ${SRCROOT}/Makefiles/gmake/top.mak Modified: trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc 2008-04-29 14:12:55 UTC (rev 1867) +++ trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -1,6 +1,6 @@ # -*- makefile -*- Time-stamp: <08/04/29 11:20:02 yeti> -FASTCGIDAEMON_SRC = /export/hostel/labs/FastCGI/fastcgi-daemon-FCGID-1/library +FASTCGIDAEMON_SRC = /home/yeti/FCGID-1/library PRGNAME = fastcgi-daemon SRC_CPP = ${FASTCGIDAEMON_SRC}/../main/main.cpp \ ${FASTCGIDAEMON_SRC}/../main/server.cpp Property changes on: trunk/complement/extern/custom/fastcgi-daemon/syslog ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile 2008-04-30 13:02:36 UTC (rev 1868) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:15:40 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${FASTCGIDAEMON_SRC}/../include -I${FASTCGIDAEMON_SRC} -I../include -I/usr/include/libxml2 Added: trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/syslog/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:13:44 yeti> + +FASTCGIDAEMON_SRC = /home/yeti/FCGID-1/library +LIBPREFIX = +LIBNAME = fastcgi-syslog +MAJOR = 0 +MINOR = 0 +PATCH = 0 +SRC_CPP = ${FASTCGIDAEMON_SRC}/../syslog/syslog-logger.cpp Modified: trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc 2008-04-29 14:12:55 UTC (rev 1867) +++ trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -1,6 +1,6 @@ # -*- makefile -*- Time-stamp: <08/04/29 12:12:25 yeti> -FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0/libfcgi +FCGI_SRC = /home/yeti/fcgi-2.4.0/libfcgi LIBNAME = fcgi MAJOR = 2 MINOR = 4 Modified: trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc 2008-04-29 14:12:55 UTC (rev 1867) +++ trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -1,6 +1,6 @@ # -*- makefile -*- Time-stamp: <08/04/29 12:12:25 yeti> -FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0/libfcgi +FCGI_SRC = /home/yeti/fcgi-2.4.0/libfcgi LIBNAME = fcgi++ MAJOR = 2 MINOR = 4 Modified: trunk/complement/extern/custom/log4cxx/src/Makefile.inc =================================================================== --- trunk/complement/extern/custom/log4cxx/src/Makefile.inc 2008-04-29 14:12:55 UTC (rev 1867) +++ trunk/complement/extern/custom/log4cxx/src/Makefile.inc 2008-04-30 13:02:36 UTC (rev 1868) @@ -1,6 +1,6 @@ # -*- makefile -*- Time-stamp: <08/04/28 16:11:18 yeti> -LOG4CXX_SRC = /export/hostel/labs/FastCGI/log4cxx-0.9.7/src +LOG4CXX_SRC = /home/yeti/log4cxx-0.9.7/src LIBNAME = log4cxx MAJOR = 0 MINOR = 9 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-04-29 14:13:33
|
Revision: 1867 http://complement.svn.sourceforge.net/complement/?rev=1867&view=rev Author: okechina Date: 2008-04-29 07:12:55 -0700 (Tue, 29 Apr 2008) Log Message: ----------- Checking if the string read is not the whole command or if several commands were sent at once Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-29 12:19:14 UTC (rev 1866) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-29 14:12:55 UTC (rev 1867) @@ -90,39 +90,57 @@ char buffer[buf_size]; state st = connect; command com; - string param, message, stout; while ( st != disconnect ) { if ( st != letter ) { - int n = read( fd2[0], buffer, sizeof(buffer) ); + bool full = false; + stringstream st_stream; + while (!full) { + int n = read( fd2[0], buffer, sizeof(buffer) ); + if ( n < 0 ) { + cerr << "Reading error\n"; + break; + } else if ( n == 0 ) { + break; + } else { + buffer[n] = '\0'; + cerr << ">> " << buffer; + st_stream << buffer; + full = full || (buffer[n-1] == '\n'); + } + }; + if (full) { + cerr << st_stream.str(); + while (st_stream.good()) { + string str; + string param, stout; + st_stream >> str; + if (str != "") { + getline (st_stream, param); + cerr << param; +// param.assign( str, com_length, str.size() ); +// str.erase( com_length, str.size() - com_length + 1 ); + com = setCom( str ); + change( st, com, param, stout ); + write( fd1[1], stout.data(), stout.length() ); + } + } + } else { //error appeared while reading a command + break; + }; + } else { + string message, s; + int n = read( fd2[0], buffer, sizeof(buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; break; } else if ( n == 0 ) { + cerr << "Empty\n"; break; } else { buffer[n] = '\0'; - cerr << ">> " << buffer << endl; - stringstream st_stream; - st_stream << buffer << " "; - string str; - st_stream >> str >> param; -// param.assign( str, com_length, str.size() ); -// str.erase( com_length, str.size() - com_length + 1 ); - com = setCom( str ); - change( st, com, param, stout ); - write( fd1[1], stout.data(), stout.length() ); - } - } else { - int n = read( fd2[0], buffer, sizeof(buffer) ); - if ( n < 0 ) { - cerr << "Reading error\n"; - } else if ( n == 0 ) { - cerr << "Empty string\n"; - } else { - buffer[n] = '\0'; - param.assign (buffer, 0, sizeof(buffer) ); - if ( param != "." ) { - message += param + "\n"; + s.assign (buffer, 0, n); + if ( s != "." ) { + message += s + "\n"; } else { st = hello; // cout << message; @@ -164,17 +182,24 @@ getline( in, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); + write( fd2[1], "\n", 1 ); int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); if ( n < 0 ) { cerr << "Reading error\n"; + break; } else if ( n == 0 ) { cerr << "Empty string\n"; + break; } else { r_buffer[n] = '\0'; cerr << "<< " << r_buffer; } } } + +// string str ("helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\nquit\n"); + write( fd2[1], str.data(), str.length() ); + close(fd2[1]); close(fd1[0]); in.close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-29 12:19:16
|
Revision: 1866 http://complement.svn.sourceforge.net/complement/?rev=1866&view=rev Author: complement Date: 2008-04-29 05:19:14 -0700 (Tue, 29 Apr 2008) Log Message: ----------- libs for dbg and stldbg Modified Paths: -------------- trunk/complement/extern/custom/fastcgi-daemon/main/Makefile Modified: trunk/complement/extern/custom/fastcgi-daemon/main/Makefile =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/main/Makefile 2008-04-29 09:41:55 UTC (rev 1865) +++ trunk/complement/extern/custom/fastcgi-daemon/main/Makefile 2008-04-29 12:19:14 UTC (rev 1866) @@ -1,4 +1,4 @@ -# -*- makefile -*- Time-stamp: <08/04/29 12:25:34 yeti> +# -*- makefile -*- Time-stamp: <08/04/29 16:18:23 yeti> SRCROOT := ../../../../explore # POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so @@ -12,4 +12,8 @@ release-shared: LDLIBS += -L../../boost/libs/thread/${OUTPUT_DIR} -lboost_thread -L../../boost/libs/regex/${OUTPUT_DIR} -lboost_regex -L../../fcgi/libfcgi/${OUTPUT_DIR} -lfcgi -L../../fcgi/libfcgi++/${OUTPUT_DIR} -lfcgi++ -L../library/${OUTPUT_DIR} -lfastcgi-daemon -ldl -lxml2 -# \ No newline at end of file +dbg-shared: LDLIBS += -L../../boost/libs/thread/${OUTPUT_DIR_DBG} -lboost_threadg -L../../boost/libs/regex/${OUTPUT_DIR_DBG} -lboost_regexg -L../../fcgi/libfcgi/${OUTPUT_DIR_DBG} -lfcgig -L../../fcgi/libfcgi++/${OUTPUT_DIR_DBG} -lfcgi++g -L../library/${OUTPUT_DIR_DBG} -lfastcgi-daemong -ldl -lxml2 + +ifndef WITHOUT_STLPORT +stldbg-shared: LDLIBS += -L../../boost/libs/thread/${OUTPUT_DIR_STLDBG} -lboost_threadstlg -L../../boost/libs/regex/${OUTPUT_DIR_STLDBG} -lboost_regexstlg -L../../fcgi/libfcgi/${OUTPUT_DIR_STLDBG} -lfcgistlg -L../../fcgi/libfcgi++/${OUTPUT_DIR_STLDBG} -lfcgi++stlg -L../library/${OUTPUT_DIR_STLDBG} -lfastcgi-daemonstlg -ldl -lxml2 +endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Dmi...@us...> - 2008-04-29 09:42:05
|
Revision: 1865 http://complement.svn.sourceforge.net/complement/?rev=1865&view=rev Author: DmitryOsmakov Date: 2008-04-29 02:41:55 -0700 (Tue, 29 Apr 2008) Log Message: ----------- fixed lib Opts : fixed problem with destructor and changed view on setting default values Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/opts_usage.cpp Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-04-29 09:22:25 UTC (rev 1864) +++ trunk/complement/explore/include/misc/opts.h 2008-04-29 09:41:55 UTC (rev 1865) @@ -10,245 +10,122 @@ using namespace std; -class Value -{ -public: - void* ptr; - Value() { ptr = 0; } -}; - class Opt { public: - char shortname; - string longname; - string desc; - vector< string > args; - Value val; // must be vector + char shortname; + string longname; + string desc; + vector< string > args; - bool has_arg; - bool is_set; + bool has_arg; + bool is_set; }; class Opts { public: // construct - Opts(const string& _brief = "",const string& _author = "",const string& _copyright = "") : brief(_brief) , author(_author) , copyright(_copyright) {}; + Opts(const string& _brief = "",const string& _author = "",const string& _copyright = "") : brief(_brief) , author(_author) , copyright(_copyright) {}; // adding option - // 4 params - template <class T> - void add(char _shortname,const string& _longname,const string& _desc,T v); - - - // 3 params - template <class T> - void add(char _shortname,const string& desc,T v); - template <class T> - void add(const string& longname,const string& desc,T v); - - // 2 params - template <class T> - void add(char _shortname,T v); - template <class T> - void add(const string& _longname,T v); + void add(char _shortname,const string& _longname = "",const string& _desc = "",bool has_arg = false); - // 1 param - randomly generated names? - -// adding flag - void addf(char _shortname,const string& _longname,const string& _desc); - void addf(char _shortname,const string& _desc); - void addf(const string& _longname,const string& _desc); - // getting option - template <class T> - T get(char _shortname,T& dest); - template <class T> - T get(const string& _longname,T& dest); - - bool is_set(char _shortname); - bool is_set(const string& _longname); + template <class T> + T get(char _shortname,T& dest); + template <class T> + T get(const string& _longname,T& dest); + + bool is_set(char _shortname); + bool is_set(const string& _longname); + // parse - void parse(int ac,char** av); + void parse(int ac,char** av); // stuff - void help(ostream& out); - string get_pname() const; - string get_brief() const; - string get_author() const; - string get_copyright() const; + void help(ostream& out); + string get_pname() const; + string get_brief() const; + string get_author() const; + string get_copyright() const; // error handling - struct invalid_opt { string optname; invalid_opt(const string& _optname) : optname(_optname) {}; }; - struct missing_arg { string optname; missing_arg(const string& _optname) : optname(_optname) {}; }; - struct invalid_arg { string optname,argname; invalid_arg(const string& _optname,const string& _argname) : optname(_optname) , argname(_argname) {}; }; + struct invalid_opt { string optname; invalid_opt(const string& _optname) : optname(_optname) {}; }; + struct missing_arg { string optname; missing_arg(const string& _optname) : optname(_optname) {}; }; + struct invalid_arg { string optname,argname; invalid_arg(const string& _optname,const string& _argname) : optname(_optname) , argname(_argname) {}; }; + + vector< string > args; private: - // data - vector< Opt > storage; - vector< string > args; - - string pname; - string brief; - string author; - string copyright; + // data + vector< Opt > storage; + + string pname; + string brief; + string author; + string copyright; - bool isterm(const string& s); - bool is_opt_name(const string& s); - bool is_flag_group(const string& s); - bool is_substr(const string& small,const string& big); - int get_opt_index(string s); + bool isterm(const string& s); + bool is_opt_name(const string& s); + bool is_flag_group(const string& s); + bool is_substr(const string& small,const string& big); + int get_opt_index(string s); }; template <class T> -void Opts::add(char _shortname,const string& _longname,const string& _desc,T v) -{ - Opt opt; - - //opt.val.tinfo = typeid(T); - opt.val.ptr = new T; - *(reinterpret_cast<T*>(opt.val.ptr)) = v; - - opt.shortname = _shortname; - opt.longname = _longname; - opt.desc = _desc; - - opt.has_arg = true; - opt.is_set = false; - - storage.push_back(opt); -} - -template <class T> -void Opts::add(char _shortname,const string& _desc,T v) -{ - Opt opt; - - //opt.val.tinfo = typeid(T); - opt.val.ptr = new T; - *(reinterpret_cast<T*>(opt.val.ptr)) = v; - - opt.shortname = _shortname; - opt.desc = _desc; - - opt.has_arg = true; - opt.is_set = false; - - storage.push_back(opt); -} - -template <class T> -void Opts::add(const string& _longname,const string& _desc,T v) -{ - Opt opt; - - //opt.val.tinfo = typeid(T); - opt.val.ptr = new T; - *(reinterpret_cast<T*>(opt.val.ptr)) = v; - - opt.longname = _longname; - opt.desc = _desc; - - opt.has_arg = true; - opt.is_set = false; - - storage.push_back(opt); -} - -template <class T> -void Opts::add(char _shortname,T v) -{ - Opt opt; - - //opt.val.tinfo = typeid(T); - opt.val.ptr = new T; - *(reinterpret_cast<T*>(opt.val.ptr)) = v; - - opt.shortname = _shortname; - - opt.has_arg = true; - opt.is_set = false; - - storage.push_back(opt); -} - -template <class T> -void Opts::add(const string& _longname,T v) -{ - Opt opt; - - //opt.val.tinfo = typeid(T); - opt.val.ptr = new T; - *(reinterpret_cast<T*>(opt.val.ptr)) = v; - - opt.longname = _longname; - - opt.has_arg = true; - opt.is_set = false; - - storage.push_back(opt); -} - -template <class T> T Opts::get(char _shortname,T& res) { - int i; - for (i = 0;i < storage.size();i++) - if (storage[i].shortname == _shortname) - { - if (storage[i].is_set && storage[i].has_arg) - { - try - { - stringstream ss(storage[i].args[0]); - ss >> res; - } - catch(...) - { - throw invalid_arg(string("-") + string(1,_shortname),storage[i].args[0]); - } - } - else - { - res = *reinterpret_cast<T*>(storage[i].val.ptr); - } - break; - } - if (i == storage.size()) - throw invalid_opt(string("-") + string(1,_shortname)); - return res; + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + { + if (storage[i].is_set && storage[i].has_arg) + if (!storage[i].args.empty()) + { + try + { + stringstream ss(storage[i].args[0]); + ss >> res; + } + catch(...) + { + throw invalid_arg(string("-") + string(1,_shortname),storage[i].args[0]); + } + } + break; + } + if (i == storage.size()) + throw invalid_opt(string("-") + string(1,_shortname)); + return res; } template <class T> T Opts::get(const string& _longname,T& res) { - int i; - for (i = 0;i < storage.size();i++) - if (storage[i].longname == _longname) - { - if (storage[i].is_set && storage[i].has_arg) - { - try - { - stringstream ss(storage[i].args[0]); - ss >> res; - } - catch(...) - { - throw invalid_arg(_longname,storage[i].args[0]); - } - } - else - { - res = *reinterpret_cast<T*>(storage[i].val.ptr); - } - break; - } - if (i == storage.size()) - throw invalid_opt(_longname); - return res; + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + { + if (storage[i].is_set && storage[i].has_arg) + if (!storage[i].args.empty()) + { + try + { + stringstream ss(storage[i].args[0]); + ss >> res; + } + catch(...) + { + throw invalid_arg(_longname,storage[i].args[0]); + } + } + break; + } + if (i == storage.size()) + throw invalid_opt(_longname); + return res; } #endif Modified: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp 2008-04-29 09:22:25 UTC (rev 1864) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-04-29 09:41:55 UTC (rev 1865) @@ -13,212 +13,192 @@ bool Opts::isterm(const string& s) { - return (s == "--"); + return (s == "--"); } bool Opts::is_opt_name(const string& s) { - return (s.size() > 0) && (s[0] == '-') && !is_flag_group(s); + return (s.size() > 0) && (s[0] == '-') && !is_flag_group(s); } bool Opts::is_substr(const string& small,const string& big) { - if (small.size() > big.size()) - return false; - for (int i = 0;i < small.size();i++) - if (small[i] != big[i]) - return false; + if (small.size() > big.size()) + return false; + for (int i = 0;i < small.size();i++) + if (small[i] != big[i]) + return false; - return true; + return true; } bool Opts::is_flag_group(const string& s) { - if (s.size() > 2 && s[0] == '-') - { - for (int i = 1;i < s.size();i++) - if (!isalnum(s[i])) - return false; - return true; - } - else - return false; + if (s.size() > 2 && s[0] == '-') + { + for (int i = 1;i < s.size();i++) + if (!isalnum(s[i])) + return false; + return true; + } + else + return false; } // this function assumes that is_opt_name(s) = true; int Opts::get_opt_index(string s) { - if (s.size() == 2 && isalnum(s[1]) ) // is short name - { - int i; - for (i = 0;i < storage.size();i++) - if (storage[i].shortname == s[1]) - break; - return i; - } - - if (s.size() > 2 && s[1] == '-') - { - int i; - s = s.substr(2); + if (s.size() == 2 && isalnum(s[1]) ) // is short name + { + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].shortname == s[1]) + break; + return i; + } + + if (s.size() > 2 && s[1] == '-') + { + int i; + s = s.substr(2); - // exact match - for (i = 0;i < storage.size();i++) - if (storage[i].longname == s) - return i; + // exact match + for (i = 0;i < storage.size();i++) + if (storage[i].longname == s) + return i; - vector<int> matches; - for (i = 0;i < storage.size();i++) - if (is_substr(s,storage[i].longname)) - matches.push_back(i); + vector<int> matches; + for (i = 0;i < storage.size();i++) + if (is_substr(s,storage[i].longname)) + matches.push_back(i); - if (matches.size() == 1) - return matches[0]; - else - return storage.size(); - } - - return storage.size(); + if (matches.size() == 1) + return matches[0]; + else + return storage.size(); + } + + return storage.size(); } void Opts::help(ostream& out) { - if (!brief.empty()) - out << brief << endl; - if (!author.empty()) - out << author << endl; - if (!copyright.empty()) - out << copyright << endl; - - out << "usage: " << endl; - out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; - out << "available options:" << endl; - for (int i = 0;i < storage.size();i++) - out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "]\t-\t" << storage[i].desc << endl; + if (!brief.empty()) + out << brief << endl; + if (!author.empty()) + out << author << endl; + if (!copyright.empty()) + out << copyright << endl; + + out << "usage: " << endl; + out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; + out << "available options:" << endl; + for (int i = 0;i < storage.size();i++) + out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "]\t-\t" << storage[i].desc << endl; } - -void Opts::addf(char _shortname,const string& _longname,const string& _desc) +void Opts::add(char _shortname,const string& _longname,const string& _desc,bool has_arg ) { - Opt opt; - opt.shortname = _shortname; - opt.longname = _longname; - opt.desc = _desc; - opt.has_arg = false; - opt.is_set = false; - storage.push_back(opt); + Opt opt; + opt.shortname = _shortname; + opt.longname = _longname; + opt.desc = _desc; + opt.has_arg = has_arg; + opt.is_set = false; + storage.push_back(opt); } -void Opts::addf(char _shortname,const string& _desc) -{ - Opt opt; - opt.shortname = _shortname; - opt.desc = _desc; - opt.has_arg = false; - opt.is_set = false; - storage.push_back(opt); -} -void Opts::addf(const string& _longname,const string& _desc) -{ - Opt opt; - opt.longname = _longname; - opt.desc = _desc; - opt.has_arg = false; - opt.is_set = false; - storage.push_back(opt); -} - bool Opts::is_set(char _shortname) { - for (int i = 0;i < storage.size();i++) - if (storage[i].shortname == _shortname) - return storage[i].is_set; - return false; + for (int i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + return storage[i].is_set; + return false; } bool Opts::is_set(const string& _longname) { - for (int i = 0;i < storage.size();i++) - if (storage[i].longname == _longname) - return storage[i].is_set; - return false; + for (int i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + return storage[i].is_set; + return false; } void Opts::parse(int ac,char** av) { - pname = av[0]; + pname = av[0]; - int i = 1; - while (i < ac && !isterm(av[i])) - { - if (is_opt_name(av[i])) - { - string opt = av[i]; - string arg; - - int k = opt.find("="); + int i = 1; + while (i < ac && !isterm(av[i])) + { + if (is_opt_name(av[i])) + { + string opt = av[i]; + string arg; + + int k = opt.find("="); - if (k != string::npos) - { - arg = opt.substr(k + 1); - opt = opt.substr(0,k); - } + if (k != string::npos) + { + arg = opt.substr(k + 1); + opt = opt.substr(0,k); + } - int p = get_opt_index(opt); + int p = get_opt_index(opt); - if (p == storage.size()) - throw invalid_opt(opt); - else - { - if (storage[p].has_arg) - { - if (!arg.empty()) - { - storage[p].is_set = true; - storage[p].args.push_back(arg); - } - else - if (i + 1 < ac) - { - storage[p].is_set = true; - storage[p].args.push_back(av[++i]); - } - else - throw missing_arg(opt); - } - else - { - storage[p].is_set = true; - if (!arg.empty()) - throw invalid_arg(opt,arg); - } - } - } - else - if (is_flag_group(av[i])) - { - string optgroup = av[i]; - for (int j = 1;j < optgroup.size();j++) - { - int p = get_opt_index(string("-") + optgroup[j]); - if (p == storage.size()) - throw invalid_opt( "-" + string(1,optgroup[j]) ); - else - { - storage[p].is_set = true; - if (storage[p].has_arg) - throw missing_arg( "-" + string(1,optgroup[j]) ); - } - } - } - else - args.push_back(av[i]); - i++; - } - - i += (i < ac && isterm(av[i])); + if (p == storage.size()) + throw invalid_opt(opt); + else + { + if (storage[p].has_arg) + { + if (!arg.empty()) + { + storage[p].is_set = true; + storage[p].args.push_back(arg); + } + else + if (i + 1 < ac) + { + storage[p].is_set = true; + storage[p].args.push_back(av[++i]); + } + else + throw missing_arg(opt); + } + else + { + storage[p].is_set = true; + if (!arg.empty()) + throw invalid_arg(opt,arg); + } + } + } + else + if (is_flag_group(av[i])) + { + string optgroup = av[i]; + for (int j = 1;j < optgroup.size();j++) + { + int p = get_opt_index(string("-") + optgroup[j]); + if (p == storage.size()) + throw invalid_opt( "-" + string(1,optgroup[j]) ); + else + { + storage[p].is_set = true; + if (storage[p].has_arg) + throw missing_arg( "-" + string(1,optgroup[j]) ); + } + } + } + else + args.push_back(av[i]); + i++; + } + + i += (i < ac && isterm(av[i])); - while (i < ac) - args.push_back(av[i++]); + while (i < ac) + args.push_back(av[i++]); } Modified: trunk/complement/explore/lib/misc/opts_usage.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts_usage.cpp 2008-04-29 09:22:25 UTC (rev 1864) +++ trunk/complement/explore/lib/misc/opts_usage.cpp 2008-04-29 09:41:55 UTC (rev 1865) @@ -6,74 +6,87 @@ struct point { - int x; - int y; - point(int _x = 0,int _y = 0) : x(_x) , y(_y) {}; + int x; + int y; + point(int _x = 0,int _y = 0) : x(_x) , y(_y) {}; }; istream& operator>>(istream& t,point& p) { - t >> p.x >> p.y; - return t; + t >> p.x >> p.y; + return t; } ostream& operator<<(ostream& t,const point& p) { - t << p.x << ' ' << p.y; - return t; + t << p.x << ' ' << p.y; + return t; } int main(int ac,char** av) { - Opts opts; - point p; - string name; - int port; - - opts.addf('h',"help","display help message"); - opts.addf('v',"verbose","verbose"); - opts.addf('j',"just","just do it"); + Opts opts; - opts.add('p',"port","port number",80); - opts.add('s',"point","start point",point(1,1)); - opts.add('n',"name","your name",string("maos")); - - try - { - opts.parse(ac,av); - } - catch(Opts::invalid_opt& t) - { - cout << "Invalid option: " << t.optname << endl; - return 1; - } - catch(Opts::invalid_arg& t) - { - cout << "Invalid argument: " << t.optname << ' ' << t.argname << endl; - return 1; - } - catch(Opts::missing_arg& t) - { - cout << "Missing argument: " << t.optname << endl; - return 1; - } - - if (opts.is_set('h')) - opts.help(cout); + // control variables with default values + point p(1,1); + string name = "maos"; + int port = 80; + + opts.add('h',"help","display help message"); + opts.add('v',"verbose","verbose"); + opts.add('j',"just","just do it"); - if (opts.is_set('v')) - cout << "Verbose mode is set" << endl; - else - cout << "Verbose mode is not set" << endl; + opts.add('p',"port","port number",true); + opts.add('s',"point","start point",true); + opts.add('n',"name","your name",true); + opts.add('g'); + + try + { + opts.parse(ac,av); + } + catch(Opts::invalid_opt& t) + { + cout << "Invalid option: " << t.optname << endl; + return 1; + } + catch(Opts::invalid_arg& t) + { + cout << "Invalid argument: " << t.optname << ' ' << t.argname << endl; + return 1; + } + catch(Opts::missing_arg& t) + { + cout << "Missing argument: " << t.optname << endl; + return 1; + } + + if (opts.is_set('h')) + opts.help(cout); - if (opts.is_set("just")) - cout << "Just do it!" << endl; - else - cout << "Just don't do it!" << endl; + if (opts.is_set('v')) + cout << "Verbose mode is set" << endl; + else + cout << "Verbose mode is not set" << endl; - cout << "port = " << opts.get('p',port) << endl; - cout << "point = " << opts.get('s',p) << endl; - cout << "name = " << opts.get('n',name) << endl; + if (opts.is_set('g')) + cout << "-g is set" << endl; + else + cout << "-g is not set" << endl; - return 0; + if (opts.is_set("just")) + cout << "Just do it!" << endl; + else + cout << "Just don't do it!" << endl; + + cout << "port = " << opts.get('p',port) << endl; + cout << "point = " << opts.get('s',p) << endl; + cout << "name = " << opts.get('n',name) << endl; + + cout << "operands: " << endl; + + for (int i = 0;i < opts.args.size();i++) + cout << opts.args[i] << endl; + + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-29 09:22:27
|
Revision: 1864 http://complement.svn.sourceforge.net/complement/?rev=1864&view=rev Author: complement Date: 2008-04-29 02:22:25 -0700 (Tue, 29 Apr 2008) Log Message: ----------- custom for libfcgi++ and fastcgi-daemon Modified Paths: -------------- trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc Added Paths: ----------- trunk/complement/extern/custom/fastcgi-daemon/ trunk/complement/extern/custom/fastcgi-daemon/include/ trunk/complement/extern/custom/fastcgi-daemon/include/settings.h trunk/complement/extern/custom/fastcgi-daemon/library/ trunk/complement/extern/custom/fastcgi-daemon/library/Makefile trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc trunk/complement/extern/custom/fastcgi-daemon/main/ trunk/complement/extern/custom/fastcgi-daemon/main/Makefile trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc trunk/complement/extern/custom/fcgi/libfcgi++/ trunk/complement/extern/custom/fcgi/libfcgi++/Makefile trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc Added: trunk/complement/extern/custom/fastcgi-daemon/include/settings.h =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/include/settings.h (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/include/settings.h 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,7 @@ + +#ifndef __SETTINGS_H +#define __SETTINGS_H + +#define HAVE_STLPORT_HASHMAP + +#endif // __SETTINGS_H Property changes on: trunk/complement/extern/custom/fastcgi-daemon/library ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/fastcgi-daemon/library/Makefile =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/library/Makefile (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/library/Makefile 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:15:40 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${FASTCGIDAEMON_SRC}/../include -I${FASTCGIDAEMON_SRC} -I../include -I/usr/include/libxml2 Added: trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/library/Makefile.inc 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,27 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:13:44 yeti> + +FASTCGIDAEMON_SRC = /export/hostel/labs/FastCGI/fastcgi-daemon-FCGID-1/library +LIBNAME = fastcgi-daemon +MAJOR = 0 +MINOR = 0 +PATCH = 0 +SRC_CPP = ${FASTCGIDAEMON_SRC}/component.cpp \ + ${FASTCGIDAEMON_SRC}/config.cpp \ + ${FASTCGIDAEMON_SRC}/cookie.cpp \ + ${FASTCGIDAEMON_SRC}/except.cpp \ + ${FASTCGIDAEMON_SRC}/functors.cpp \ + ${FASTCGIDAEMON_SRC}/handler.cpp \ + ${FASTCGIDAEMON_SRC}/handlerset.cpp \ + ${FASTCGIDAEMON_SRC}/helpers.cpp \ + ${FASTCGIDAEMON_SRC}/loader.cpp \ + ${FASTCGIDAEMON_SRC}/logger.cpp \ + ${FASTCGIDAEMON_SRC}/parser.cpp \ + ${FASTCGIDAEMON_SRC}/range.cpp \ + ${FASTCGIDAEMON_SRC}/request.cpp \ + ${FASTCGIDAEMON_SRC}/requestimpl.cpp \ + ${FASTCGIDAEMON_SRC}/stream.cpp \ + ${FASTCGIDAEMON_SRC}/util.cpp \ + ${FASTCGIDAEMON_SRC}/xml.cpp \ + ${FASTCGIDAEMON_SRC}/componentset.cpp \ + ${FASTCGIDAEMON_SRC}/component_factory.cpp \ + ${FASTCGIDAEMON_SRC}/component_context.cpp Property changes on: trunk/complement/extern/custom/fastcgi-daemon/main ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/fastcgi-daemon/main/Makefile =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/main/Makefile (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/main/Makefile 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,15 @@ +# -*- makefile -*- Time-stamp: <08/04/29 12:25:34 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0 + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${FASTCGIDAEMON_SRC}/../include -I${FASTCGIDAEMON_SRC} -I../include -I/usr/include/libxml2 -I${FCGI_SRC}/include + +release-shared: LDLIBS += -L../../boost/libs/thread/${OUTPUT_DIR} -lboost_thread -L../../boost/libs/regex/${OUTPUT_DIR} -lboost_regex -L../../fcgi/libfcgi/${OUTPUT_DIR} -lfcgi -L../../fcgi/libfcgi++/${OUTPUT_DIR} -lfcgi++ -L../library/${OUTPUT_DIR} -lfastcgi-daemon -ldl -lxml2 + +# \ No newline at end of file Added: trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/fastcgi-daemon/main/Makefile.inc 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,6 @@ +# -*- makefile -*- Time-stamp: <08/04/29 11:20:02 yeti> + +FASTCGIDAEMON_SRC = /export/hostel/labs/FastCGI/fastcgi-daemon-FCGID-1/library +PRGNAME = fastcgi-daemon +SRC_CPP = ${FASTCGIDAEMON_SRC}/../main/main.cpp \ + ${FASTCGIDAEMON_SRC}/../main/server.cpp Modified: trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc 2008-04-28 16:56:16 UTC (rev 1863) +++ trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc 2008-04-29 09:22:25 UTC (rev 1864) @@ -1,4 +1,4 @@ -# -*- makefile -*- Time-stamp: <08/04/28 19:49:29 yeti> +# -*- makefile -*- Time-stamp: <08/04/29 12:12:25 yeti> FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0/libfcgi LIBNAME = fcgi Property changes on: trunk/complement/extern/custom/fcgi/libfcgi++ ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/fcgi/libfcgi++/Makefile =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi++/Makefile (rev 0) +++ trunk/complement/extern/custom/fcgi/libfcgi++/Makefile 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/28 19:39:18 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${FCGI_SRC}/../include -I../include Added: trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/fcgi/libfcgi++/Makefile.inc 2008-04-29 09:22:25 UTC (rev 1864) @@ -0,0 +1,8 @@ +# -*- makefile -*- Time-stamp: <08/04/29 12:12:25 yeti> + +FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0/libfcgi +LIBNAME = fcgi++ +MAJOR = 2 +MINOR = 4 +PATCH = 0 +SRC_CPP = ${FCGI_SRC}/fcgio.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-28 17:15:56
|
Revision: 1863 http://complement.svn.sourceforge.net/complement/?rev=1863&view=rev Author: complement Date: 2008-04-28 09:56:16 -0700 (Mon, 28 Apr 2008) Log Message: ----------- log4cxx and fcgi custom builds Added Paths: ----------- trunk/complement/extern/custom/fcgi/ trunk/complement/extern/custom/fcgi/include/ trunk/complement/extern/custom/fcgi/include/fcgi_config.h trunk/complement/extern/custom/fcgi/libfcgi/ trunk/complement/extern/custom/fcgi/libfcgi/Makefile trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc trunk/complement/extern/custom/log4cxx/ trunk/complement/extern/custom/log4cxx/include/ trunk/complement/extern/custom/log4cxx/include/log4cxx/ trunk/complement/extern/custom/log4cxx/include/log4cxx/config_auto.h trunk/complement/extern/custom/log4cxx/src/ trunk/complement/extern/custom/log4cxx/src/Makefile trunk/complement/extern/custom/log4cxx/src/Makefile.inc Added: trunk/complement/extern/custom/fcgi/include/fcgi_config.h =================================================================== --- trunk/complement/extern/custom/fcgi/include/fcgi_config.h (rev 0) +++ trunk/complement/extern/custom/fcgi/include/fcgi_config.h 2008-04-28 16:56:16 UTC (rev 1863) @@ -0,0 +1,111 @@ +/* fcgi_config.h.in. Generated automatically from configure.in by autoheader. */ + +/* Define if you have the <arpa/inet.h> header file. */ +#define HAVE_ARPA_INET_H + +/* Define if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H + +/* Define if there's a fileno() prototype in stdio.h */ +#define HAVE_FILENO_PROTO + +/* Define if the fpos_t typedef is in stdio.h */ +#define HAVE_FPOS + +/* Define if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define if cin/cout/cerr has a streambuf assignment operator */ +#undef HAVE_IOSTREAM_WITHASSIGN_STREAMBUF + +/* Define if you have the `nsl' library (-lnsl). */ +#undef HAVE_LIBNSL + +/* Define if you have the `socket' library (-lsocket). */ +#undef HAVE_LIBSOCKET + +/* Define if you have the <limits.h> header file. */ +#define HAVE_LIMITS_H + +/* Define if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define if you have the <netdb.h> header file. */ +#define HAVE_NETDB_H + +/* Define if you have the <netinet/in.h> header file. */ +#define HAVE_NETINET_IN_H + +/* Define if you have POSIX threads libraries and header files. */ +#define HAVE_PTHREAD + +/* Define if sockaddr_un in sys/un.h contains a sun_len component */ +#undef HAVE_SOCKADDR_UN_SUN_LEN + +/* Define if the socklen_t typedef is in sys/socket.h */ +#define HAVE_SOCKLEN + +/* Define if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define if char_type is defined in the context of streambuf */ +#define HAVE_STREAMBUF_CHAR_TYPE + +/* Define if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define if you have the <sys/param.h> header file. */ +#undef HAVE_SYS_PARAM_H + +/* Define if you have the <sys/socket.h> header file. */ +#define HAVE_SYS_SOCKET_H + +/* Define if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define if you have the <sys/time.h> header file. */ +#define HAVE_SYS_TIME_H + +/* Define if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H + +/* Define if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H + +/* Define if va_arg(arg, long double) crashes the compiler */ +#undef HAVE_VA_ARG_LONG_DOUBLE_BUG + +/* Name of package */ +#undef PACKAGE + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* Define if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define if cross-process locking is required by accept() */ +#undef USE_LOCKING + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define as `__inline' if that's what the C compiler calls it, or to nothing + if it is not supported. */ +#undef inline + +/* Define to `int' if <sys/types.h> does not define. */ +#undef ssize_t Property changes on: trunk/complement/extern/custom/fcgi/libfcgi ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/fcgi/libfcgi/Makefile =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi/Makefile (rev 0) +++ trunk/complement/extern/custom/fcgi/libfcgi/Makefile 2008-04-28 16:56:16 UTC (rev 1863) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/28 19:39:18 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${FCGI_SRC}/../include -I../include Added: trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc =================================================================== --- trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/fcgi/libfcgi/Makefile.inc 2008-04-28 16:56:16 UTC (rev 1863) @@ -0,0 +1,10 @@ +# -*- makefile -*- Time-stamp: <08/04/28 19:49:29 yeti> + +FCGI_SRC = /export/hostel/labs/FastCGI/fcgi-2.4.0/libfcgi +LIBNAME = fcgi +MAJOR = 2 +MINOR = 4 +PATCH = 0 +SRC_C = ${FCGI_SRC}/fcgiapp.c \ + ${FCGI_SRC}/fcgi_stdio.c \ + ${FCGI_SRC}/os_unix.c Added: trunk/complement/extern/custom/log4cxx/include/log4cxx/config_auto.h =================================================================== --- trunk/complement/extern/custom/log4cxx/include/log4cxx/config_auto.h (rev 0) +++ trunk/complement/extern/custom/log4cxx/include/log4cxx/config_auto.h 2008-04-28 16:56:16 UTC (rev 1863) @@ -0,0 +1,142 @@ +/* include/log4cxx/config_auto.h.in. Generated from configure.in by autoheader. */ + +/* Define to 1 if you have the <alloca.h> header file. */ +#undef HAVE_ALLOCA_H + +/* Define to 1 if you have the <boost/regex.hpp> header file. */ +#define HAVE_BOOST_REGEX_HPP + +/* SMTP support through Microsoft CDO. */ +#undef HAVE_CDO_SMTP + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the `ftime' function. */ +#undef HAVE_FTIME + +/* Define to 1 if you have the `gethostbyname' function. */ +#define HAVE_GETHOSTBYNAME + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the <io.h> header file. */ +#undef HAVE_IO_H + +/* ODBC support through iODBC. */ +#undef HAVE_I_ODBC + +/* Define to 1 if you have the `boost_regex' library (-lboost_regex). */ +#undef HAVE_LIBBOOST_REGEX + +/* Define to 1 if you have the `nsl' library (-lnsl). */ +#undef HAVE_LIBNSL + +/* SMTP support through libsmtp library. */ +#undef HAVE_LIBSMTP + +/* Define to 1 if you have the `smtp_mime' library (-lsmtp_mime). */ +#undef HAVE_LIBSMTP_MIME + +/* Define to 1 if you have the `socket' library (-lsocket). */ +#undef HAVE_LIBSOCKET + +/* XML support through libxml2. */ +#define HAVE_LIBXML2 + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* ODBC support through Microsoft ODBC. */ +#undef HAVE_MS_ODBC + +/* thread support through Microsoft threads. */ +#undef HAVE_MS_THREAD + +/* ODBC support through Microsoft XML. */ +#undef HAVE_MS_XML + +/* no explicit exports */ +#define LOG4CXX_EXPORT + +/* ODBC support */ +#undef HAVE_ODBC + +/* thread support through pthread library. */ +#define HAVE_PTHREAD + +/* Define to 1 if you have the `setenv' function. */ +#define HAVE_SETENV + +/* Define to 1 if you have the `setsockopt' function. */ +#undef HAVE_SETSOCKOPT + +/* SMTP support */ +/* #define HAVE_SMTP */ + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `syslog' function. */ +#define HAVE_SYSLOG + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* thread support */ +#undef HAVE_THREAD + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* ODBC support through unixODBC. */ +#undef HAVE_UNIX_ODBC + +/* XML support */ +#define HAVE_XML + +/* Defined to 1 if macro _T has to be undefined */ +#undef MUST_UNDEF_T + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* UTF-16 Unicode support. */ +#undef UNICODE + +/* Version number of package */ +#undef VERSION Property changes on: trunk/complement/extern/custom/log4cxx/include/log4cxx/config_auto.h ___________________________________________________________________ Name: svn:executable + * Property changes on: trunk/complement/extern/custom/log4cxx/src ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/extern/custom/log4cxx/src/Makefile =================================================================== --- trunk/complement/extern/custom/log4cxx/src/Makefile (rev 0) +++ trunk/complement/extern/custom/log4cxx/src/Makefile 2008-04-28 16:56:16 UTC (rev 1863) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <08/04/28 16:32:55 yeti> + +SRCROOT := ../../../../explore +# POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_date_time.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} -I${LOG4CXX_SRC}/../include -I../include -I/usr/include/libxml2 Added: trunk/complement/extern/custom/log4cxx/src/Makefile.inc =================================================================== --- trunk/complement/extern/custom/log4cxx/src/Makefile.inc (rev 0) +++ trunk/complement/extern/custom/log4cxx/src/Makefile.inc 2008-04-28 16:56:16 UTC (rev 1863) @@ -0,0 +1,89 @@ +# -*- makefile -*- Time-stamp: <08/04/28 16:11:18 yeti> + +LOG4CXX_SRC = /export/hostel/labs/FastCGI/log4cxx-0.9.7/src +LIBNAME = log4cxx +MAJOR = 0 +MINOR = 9 +PATCH = 7 +SRC_CPP = ${LOG4CXX_SRC}/appenderattachableimpl.cpp \ + ${LOG4CXX_SRC}/appenderskeleton.cpp \ + ${LOG4CXX_SRC}/asyncappender.cpp \ + ${LOG4CXX_SRC}/basicconfigurator.cpp \ + ${LOG4CXX_SRC}/boundedfifo.cpp \ + ${LOG4CXX_SRC}/class.cpp \ + ${LOG4CXX_SRC}/condition.cpp \ + ${LOG4CXX_SRC}/configurator.cpp \ + ${LOG4CXX_SRC}/consoleappender.cpp \ + ${LOG4CXX_SRC}/criticalsection.cpp \ + ${LOG4CXX_SRC}/cyclicbuffer.cpp \ + ${LOG4CXX_SRC}/dailyrollingfileappender.cpp \ + ${LOG4CXX_SRC}/datagrampacket.cpp \ + ${LOG4CXX_SRC}/datagramsocket.cpp \ + ${LOG4CXX_SRC}/datelayout.cpp \ + ${LOG4CXX_SRC}/dateformat.cpp \ + ${LOG4CXX_SRC}/defaultcategoryfactory.cpp \ + ${LOG4CXX_SRC}/domconfigurator.cpp \ + ${LOG4CXX_SRC}/event.cpp \ + ${LOG4CXX_SRC}/fallbackerrorhandler.cpp \ + ${LOG4CXX_SRC}/fileappender.cpp \ + ${LOG4CXX_SRC}/filewatchdog.cpp \ + ${LOG4CXX_SRC}/formattinginfo.cpp \ + ${LOG4CXX_SRC}/gnomexml.cpp \ + ${LOG4CXX_SRC}/hierarchy.cpp \ + ${LOG4CXX_SRC}/htmllayout.cpp \ + ${LOG4CXX_SRC}/inetaddress.cpp \ + ${LOG4CXX_SRC}/layout.cpp\ + ${LOG4CXX_SRC}/level.cpp \ + ${LOG4CXX_SRC}/levelmatchfilter.cpp \ + ${LOG4CXX_SRC}/levelrangefilter.cpp \ + ${LOG4CXX_SRC}/loader.cpp\ + ${LOG4CXX_SRC}/locale.cpp\ + ${LOG4CXX_SRC}/logger.cpp \ + ${LOG4CXX_SRC}/loggingevent.cpp \ + ${LOG4CXX_SRC}/loglog.cpp \ + ${LOG4CXX_SRC}/logmanager.cpp \ + ${LOG4CXX_SRC}/msxml.cpp \ + ${LOG4CXX_SRC}/mutex.cpp \ + ${LOG4CXX_SRC}/ndc.cpp \ + ${LOG4CXX_SRC}/mdc.cpp \ + ${LOG4CXX_SRC}/nteventlogappender.cpp \ + ${LOG4CXX_SRC}/objectimpl.cpp \ + ${LOG4CXX_SRC}/odbcappender.cpp \ + ${LOG4CXX_SRC}/onlyonceerrorhandler.cpp \ + ${LOG4CXX_SRC}/optionconverter.cpp \ + ${LOG4CXX_SRC}/patternconverter.cpp \ + ${LOG4CXX_SRC}/patternlayout.cpp \ + ${LOG4CXX_SRC}/patternparser.cpp \ + ${LOG4CXX_SRC}/properties.cpp \ + ${LOG4CXX_SRC}/propertyconfigurator.cpp \ + ${LOG4CXX_SRC}/propertyresourcebundle.cpp \ + ${LOG4CXX_SRC}/propertysetter.cpp \ + ${LOG4CXX_SRC}/resourcebundle.cpp \ + ${LOG4CXX_SRC}/rollingfileappender.cpp \ + ${LOG4CXX_SRC}/rootcategory.cpp \ + ${LOG4CXX_SRC}/serversocket.cpp \ + ${LOG4CXX_SRC}/semaphore.cpp \ + ${LOG4CXX_SRC}/simplelayout.cpp \ + ${LOG4CXX_SRC}/smtpappender.cpp \ + ${LOG4CXX_SRC}/socket.cpp \ + ${LOG4CXX_SRC}/socketappender.cpp \ + ${LOG4CXX_SRC}/sockethubappender.cpp \ + ${LOG4CXX_SRC}/socketimpl.cpp \ + ${LOG4CXX_SRC}/socketinputstream.cpp \ + ${LOG4CXX_SRC}/socketnode.cpp \ + ${LOG4CXX_SRC}/socketoutputstream.cpp \ + ${LOG4CXX_SRC}/stringhelper.cpp \ + ${LOG4CXX_SRC}/stringmatchfilter.cpp \ + ${LOG4CXX_SRC}/stringtokenizer.cpp \ + ${LOG4CXX_SRC}/syslogappender.cpp \ + ${LOG4CXX_SRC}/syslogwriter.cpp \ + ${LOG4CXX_SRC}/system.cpp \ + ${LOG4CXX_SRC}/telnetappender.cpp \ + ${LOG4CXX_SRC}/timezone.cpp \ + ${LOG4CXX_SRC}/transform.cpp \ + ${LOG4CXX_SRC}/thread.cpp \ + ${LOG4CXX_SRC}/threadspecificdata.cpp \ + ${LOG4CXX_SRC}/ttcclayout.cpp \ + ${LOG4CXX_SRC}/writerappender.cpp \ + ${LOG4CXX_SRC}/xmllayout.cpp\ + ${LOG4CXX_SRC}/xmlsocketappender.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Dmi...@us...> - 2008-04-28 15:58:41
|
Revision: 1862 http://complement.svn.sourceforge.net/complement/?rev=1862&view=rev Author: DmitryOsmakov Date: 2008-04-28 08:58:14 -0700 (Mon, 28 Apr 2008) Log Message: ----------- added lib: Opts - new lib to work with command line options. Added Paths: ----------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cpp trunk/complement/explore/lib/misc/opts_usage.cpp Added: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h (rev 0) +++ trunk/complement/explore/include/misc/opts.h 2008-04-28 15:58:14 UTC (rev 1862) @@ -0,0 +1,254 @@ +#ifndef __OPTS_H__ +#define __OPTS_H__ + +#include <iostream> +#include <string> +#include <vector> +#include <sstream> +#include <typeinfo> +#include <cctype> + +using namespace std; + +class Value +{ +public: + void* ptr; + Value() { ptr = 0; } +}; + +class Opt +{ +public: + char shortname; + string longname; + string desc; + vector< string > args; + Value val; // must be vector + + bool has_arg; + bool is_set; +}; + +class Opts +{ +public: +// construct + Opts(const string& _brief = "",const string& _author = "",const string& _copyright = "") : brief(_brief) , author(_author) , copyright(_copyright) {}; + +// adding option + // 4 params + template <class T> + void add(char _shortname,const string& _longname,const string& _desc,T v); + + + // 3 params + template <class T> + void add(char _shortname,const string& desc,T v); + template <class T> + void add(const string& longname,const string& desc,T v); + + // 2 params + template <class T> + void add(char _shortname,T v); + template <class T> + void add(const string& _longname,T v); + + // 1 param - randomly generated names? + +// adding flag + void addf(char _shortname,const string& _longname,const string& _desc); + void addf(char _shortname,const string& _desc); + void addf(const string& _longname,const string& _desc); + +// getting option + template <class T> + T get(char _shortname,T& dest); + template <class T> + T get(const string& _longname,T& dest); + + bool is_set(char _shortname); + bool is_set(const string& _longname); + +// parse + void parse(int ac,char** av); + +// stuff + void help(ostream& out); + string get_pname() const; + string get_brief() const; + string get_author() const; + string get_copyright() const; + +// error handling + struct invalid_opt { string optname; invalid_opt(const string& _optname) : optname(_optname) {}; }; + struct missing_arg { string optname; missing_arg(const string& _optname) : optname(_optname) {}; }; + struct invalid_arg { string optname,argname; invalid_arg(const string& _optname,const string& _argname) : optname(_optname) , argname(_argname) {}; }; + +private: + // data + vector< Opt > storage; + vector< string > args; + + string pname; + string brief; + string author; + string copyright; + + bool isterm(const string& s); + bool is_opt_name(const string& s); + bool is_flag_group(const string& s); + bool is_substr(const string& small,const string& big); + int get_opt_index(string s); +}; + +template <class T> +void Opts::add(char _shortname,const string& _longname,const string& _desc,T v) +{ + Opt opt; + + //opt.val.tinfo = typeid(T); + opt.val.ptr = new T; + *(reinterpret_cast<T*>(opt.val.ptr)) = v; + + opt.shortname = _shortname; + opt.longname = _longname; + opt.desc = _desc; + + opt.has_arg = true; + opt.is_set = false; + + storage.push_back(opt); +} + +template <class T> +void Opts::add(char _shortname,const string& _desc,T v) +{ + Opt opt; + + //opt.val.tinfo = typeid(T); + opt.val.ptr = new T; + *(reinterpret_cast<T*>(opt.val.ptr)) = v; + + opt.shortname = _shortname; + opt.desc = _desc; + + opt.has_arg = true; + opt.is_set = false; + + storage.push_back(opt); +} + +template <class T> +void Opts::add(const string& _longname,const string& _desc,T v) +{ + Opt opt; + + //opt.val.tinfo = typeid(T); + opt.val.ptr = new T; + *(reinterpret_cast<T*>(opt.val.ptr)) = v; + + opt.longname = _longname; + opt.desc = _desc; + + opt.has_arg = true; + opt.is_set = false; + + storage.push_back(opt); +} + +template <class T> +void Opts::add(char _shortname,T v) +{ + Opt opt; + + //opt.val.tinfo = typeid(T); + opt.val.ptr = new T; + *(reinterpret_cast<T*>(opt.val.ptr)) = v; + + opt.shortname = _shortname; + + opt.has_arg = true; + opt.is_set = false; + + storage.push_back(opt); +} + +template <class T> +void Opts::add(const string& _longname,T v) +{ + Opt opt; + + //opt.val.tinfo = typeid(T); + opt.val.ptr = new T; + *(reinterpret_cast<T*>(opt.val.ptr)) = v; + + opt.longname = _longname; + + opt.has_arg = true; + opt.is_set = false; + + storage.push_back(opt); +} + +template <class T> +T Opts::get(char _shortname,T& res) +{ + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + { + if (storage[i].is_set && storage[i].has_arg) + { + try + { + stringstream ss(storage[i].args[0]); + ss >> res; + } + catch(...) + { + throw invalid_arg(string("-") + string(1,_shortname),storage[i].args[0]); + } + } + else + { + res = *reinterpret_cast<T*>(storage[i].val.ptr); + } + break; + } + if (i == storage.size()) + throw invalid_opt(string("-") + string(1,_shortname)); + return res; +} + +template <class T> +T Opts::get(const string& _longname,T& res) +{ + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + { + if (storage[i].is_set && storage[i].has_arg) + { + try + { + stringstream ss(storage[i].args[0]); + ss >> res; + } + catch(...) + { + throw invalid_arg(_longname,storage[i].args[0]); + } + } + else + { + res = *reinterpret_cast<T*>(storage[i].val.ptr); + } + break; + } + if (i == storage.size()) + throw invalid_opt(_longname); + return res; +} + +#endif Added: trunk/complement/explore/lib/misc/opts.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts.cpp (rev 0) +++ trunk/complement/explore/lib/misc/opts.cpp 2008-04-28 15:58:14 UTC (rev 1862) @@ -0,0 +1,224 @@ +#include <vector> +#include <string> +#include <sstream> +#include <typeinfo> +#include "opts.h" + +using namespace std; + +string Opts::get_pname() const { return pname; } +string Opts::get_brief() const { return brief; } +string Opts::get_author() const { return author; } +string Opts::get_copyright() const { return copyright; } + +bool Opts::isterm(const string& s) +{ + return (s == "--"); +} + +bool Opts::is_opt_name(const string& s) +{ + return (s.size() > 0) && (s[0] == '-') && !is_flag_group(s); +} + +bool Opts::is_substr(const string& small,const string& big) +{ + if (small.size() > big.size()) + return false; + for (int i = 0;i < small.size();i++) + if (small[i] != big[i]) + return false; + + return true; +} + +bool Opts::is_flag_group(const string& s) +{ + if (s.size() > 2 && s[0] == '-') + { + for (int i = 1;i < s.size();i++) + if (!isalnum(s[i])) + return false; + return true; + } + else + return false; +} + +// this function assumes that is_opt_name(s) = true; +int Opts::get_opt_index(string s) +{ + if (s.size() == 2 && isalnum(s[1]) ) // is short name + { + int i; + for (i = 0;i < storage.size();i++) + if (storage[i].shortname == s[1]) + break; + return i; + } + + if (s.size() > 2 && s[1] == '-') + { + int i; + s = s.substr(2); + + // exact match + for (i = 0;i < storage.size();i++) + if (storage[i].longname == s) + return i; + + vector<int> matches; + for (i = 0;i < storage.size();i++) + if (is_substr(s,storage[i].longname)) + matches.push_back(i); + + if (matches.size() == 1) + return matches[0]; + else + return storage.size(); + } + + return storage.size(); +} + +void Opts::help(ostream& out) +{ + if (!brief.empty()) + out << brief << endl; + if (!author.empty()) + out << author << endl; + if (!copyright.empty()) + out << copyright << endl; + + out << "usage: " << endl; + out << pname << " [option ...] [optiongoup ...] [end operands ...]" << endl; + out << "available options:" << endl; + for (int i = 0;i < storage.size();i++) + out << "-" << storage[i].shortname << "\t[--" << storage[i].longname << "]\t-\t" << storage[i].desc << endl; +} + + +void Opts::addf(char _shortname,const string& _longname,const string& _desc) +{ + Opt opt; + opt.shortname = _shortname; + opt.longname = _longname; + opt.desc = _desc; + opt.has_arg = false; + opt.is_set = false; + storage.push_back(opt); +} + +void Opts::addf(char _shortname,const string& _desc) +{ + Opt opt; + opt.shortname = _shortname; + opt.desc = _desc; + opt.has_arg = false; + opt.is_set = false; + storage.push_back(opt); +} + +void Opts::addf(const string& _longname,const string& _desc) +{ + Opt opt; + opt.longname = _longname; + opt.desc = _desc; + opt.has_arg = false; + opt.is_set = false; + storage.push_back(opt); +} + +bool Opts::is_set(char _shortname) +{ + for (int i = 0;i < storage.size();i++) + if (storage[i].shortname == _shortname) + return storage[i].is_set; + return false; +} + +bool Opts::is_set(const string& _longname) +{ + for (int i = 0;i < storage.size();i++) + if (storage[i].longname == _longname) + return storage[i].is_set; + return false; +} + +void Opts::parse(int ac,char** av) +{ + pname = av[0]; + + int i = 1; + while (i < ac && !isterm(av[i])) + { + if (is_opt_name(av[i])) + { + string opt = av[i]; + string arg; + + int k = opt.find("="); + + if (k != string::npos) + { + arg = opt.substr(k + 1); + opt = opt.substr(0,k); + } + + int p = get_opt_index(opt); + + if (p == storage.size()) + throw invalid_opt(opt); + else + { + if (storage[p].has_arg) + { + if (!arg.empty()) + { + storage[p].is_set = true; + storage[p].args.push_back(arg); + } + else + if (i + 1 < ac) + { + storage[p].is_set = true; + storage[p].args.push_back(av[++i]); + } + else + throw missing_arg(opt); + } + else + { + storage[p].is_set = true; + if (!arg.empty()) + throw invalid_arg(opt,arg); + } + } + } + else + if (is_flag_group(av[i])) + { + string optgroup = av[i]; + for (int j = 1;j < optgroup.size();j++) + { + int p = get_opt_index(string("-") + optgroup[j]); + if (p == storage.size()) + throw invalid_opt( "-" + string(1,optgroup[j]) ); + else + { + storage[p].is_set = true; + if (storage[p].has_arg) + throw missing_arg( "-" + string(1,optgroup[j]) ); + } + } + } + else + args.push_back(av[i]); + i++; + } + + i += (i < ac && isterm(av[i])); + + while (i < ac) + args.push_back(av[i++]); +} Added: trunk/complement/explore/lib/misc/opts_usage.cpp =================================================================== --- trunk/complement/explore/lib/misc/opts_usage.cpp (rev 0) +++ trunk/complement/explore/lib/misc/opts_usage.cpp 2008-04-28 15:58:14 UTC (rev 1862) @@ -0,0 +1,79 @@ +#include <iostream> +#include <string> +#include "opts.h" + +using namespace std; + +struct point +{ + int x; + int y; + point(int _x = 0,int _y = 0) : x(_x) , y(_y) {}; +}; + +istream& operator>>(istream& t,point& p) +{ + t >> p.x >> p.y; + return t; +} + +ostream& operator<<(ostream& t,const point& p) +{ + t << p.x << ' ' << p.y; + return t; +} + +int main(int ac,char** av) +{ + Opts opts; + point p; + string name; + int port; + + opts.addf('h',"help","display help message"); + opts.addf('v',"verbose","verbose"); + opts.addf('j',"just","just do it"); + + opts.add('p',"port","port number",80); + opts.add('s',"point","start point",point(1,1)); + opts.add('n',"name","your name",string("maos")); + + try + { + opts.parse(ac,av); + } + catch(Opts::invalid_opt& t) + { + cout << "Invalid option: " << t.optname << endl; + return 1; + } + catch(Opts::invalid_arg& t) + { + cout << "Invalid argument: " << t.optname << ' ' << t.argname << endl; + return 1; + } + catch(Opts::missing_arg& t) + { + cout << "Missing argument: " << t.optname << endl; + return 1; + } + + if (opts.is_set('h')) + opts.help(cout); + + if (opts.is_set('v')) + cout << "Verbose mode is set" << endl; + else + cout << "Verbose mode is not set" << endl; + + if (opts.is_set("just")) + cout << "Just do it!" << endl; + else + cout << "Just don't do it!" << endl; + + cout << "port = " << opts.get('p',port) << endl; + cout << "point = " << opts.get('s',p) << endl; + cout << "name = " << opts.get('n',name) << endl; + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-04-28 14:38:30
|
Revision: 1861 http://complement.svn.sourceforge.net/complement/?rev=1861&view=rev Author: okechina Date: 2008-04-28 07:37:50 -0700 (Mon, 28 Apr 2008) Log Message: ----------- Checking whether a proper command string was read Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 11:26:22 UTC (rev 1860) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-28 14:37:50 UTC (rev 1861) @@ -29,12 +29,12 @@ // letter const string set_state[] = { - "quit\n", +// "quit\n", "", "helo mail.ru\n", "helo mail.ru\nmail from:se...@ma...\n", "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", - "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" +// "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" }; //possible commands @@ -68,13 +68,13 @@ }; const int set_result[][sizeof(set_command)/sizeof(set_command[0])] = { - {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, +// {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, // {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, - {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} +// {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} }; const int buf_size = 1024; @@ -91,32 +91,48 @@ state st = connect; command com; string param, message, stout; - while ( st != disconnect ) { if ( st != letter ) { - if ( read( fd2[0], buffer, sizeof(buffer) ) < 1 ) { // <-- error (1) + int n = read( fd2[0], buffer, sizeof(buffer) ); + if ( n < 0 ) { cerr << "Reading error\n"; + break; + } else if ( n == 0 ) { + break; } else { + buffer[n] = '\0'; cerr << ">> " << buffer << endl; - string str( buffer ); // <-- error (1) - param.assign( str, com_length, str.size() ); - str.erase( com_length, str.size() - com_length + 1 ); + stringstream st_stream; + st_stream << buffer << " "; + string str; + st_stream >> str >> param; +// param.assign( str, com_length, str.size() ); +// str.erase( com_length, str.size() - com_length + 1 ); com = setCom( str ); change( st, com, param, stout ); write( fd1[1], stout.data(), stout.length() ); } } else { - read( fd2[0], buffer, sizeof(buffer) ); // <-- error (2) - param.assign (buffer, 0, sizeof(buffer) ); // <-- error (2) - if ( param != "." ) { - message += param + "\n"; - } else { - st = hello; - // cout << message; - message = ""; + int n = read( fd2[0], buffer, sizeof(buffer) ); + if ( n < 0 ) { + cerr << "Reading error\n"; + } else if ( n == 0 ) { + cerr << "Empty string\n"; + } else { + buffer[n] = '\0'; + param.assign (buffer, 0, sizeof(buffer) ); + if ( param != "." ) { + message += param + "\n"; + } else { + st = hello; + // cout << message; + message = ""; + } } } } + close(fd2[0]); + close(fd1[1]); active = false; // cerr << "Server's loop may be here" << endl; @@ -131,7 +147,6 @@ string s; string expected; - for ( int i = 0; i <= test_num; ++i ) { char r_buffer[buf_size], w_buffer[buf_size]; @@ -149,13 +164,20 @@ getline( in, s ); if ( !s.empty() ) { write( fd2[1], s.data(), s.length() ); - read( fd1[0], r_buffer, sizeof(r_buffer) ); // <-- error (3) - cerr << "<< " << r_buffer; // <-- error (3) + int n = read( fd1[0], r_buffer, sizeof(r_buffer) ); + if ( n < 0 ) { + cerr << "Reading error\n"; + } else if ( n == 0 ) { + cerr << "Empty string\n"; + } else { + r_buffer[n] = '\0'; + cerr << "<< " << r_buffer; + } } } - + close(fd2[1]); + close(fd1[0]); in.close(); - t.join(); string result(r_buffer); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-25 11:26:38
|
Revision: 1860 http://complement.svn.sourceforge.net/complement/?rev=1860&view=rev Author: complement Date: 2008-04-25 04:26:22 -0700 (Fri, 25 Apr 2008) Log Message: ----------- clean code, no principal changes, but ones should be... Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Added Paths: ----------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/aux/ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/aux/test_0 Removed Paths: ------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 Property Changed: ---------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/ Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut ___________________________________________________________________ Name: svn:ignore - obj test_* + obj Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-25 09:17:02 UTC (rev 1859) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-25 11:26:22 UTC (rev 1860) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/25 13:13:10 yeti> +// -*- C++ -*- Time-stamp: <08/04/25 14:45:59 yeti> #include <iostream> #include <string> @@ -9,150 +9,203 @@ using namespace std; -command setCom(const string& str) { - string Str(str); - for(int i = 0; Str[i] != '\0'; i++) - Str[i] = tolower(Str[i]); - if (Str == "helo") return helo; - else if (Str == "ehlo") return ehlo; - else if (Str == "mail") return mail; - else if (Str == "rcpt") return rcpt; - else if (Str == "data") return data; - else if (Str == "rset") return rset; - else if (Str == "vrfy") return vrfy; - else if (Str == "expn") return expn; - else if (Str == "help") return help; - else if (Str == "noop") return noop; - else if (Str == "quit") return quit; - else return none; +command setCom( const string& str ) +{ + string Str; + + for ( string::const_iterator i = str.begin(); i != str.end(); ++i ) { + Str += tolower( *i ); + } + + if ( Str == "helo" ) { + return helo; + } + + if ( Str == "ehlo" ) { + return ehlo; + } + + if ( Str == "mail" ) { + return mail; + } + + if ( Str == "rcpt" ) { + return rcpt; + } + + if ( Str == "data" ) { + return data; + } + + if (Str == "rset") { + return rset; + } + + if (Str == "vrfy") { + return vrfy; + } + + if (Str == "expn") { + return expn; + } + + if (Str == "help") { + return help; + } + + if (Str == "noop") { + return noop; + } + + if (Str == "quit") { + return quit; + } + + return none; } -void change(state& st, command& com, string& param, string& stout) { - switch (com) { - case helo: - if (st == connect) { - stout = "250 localhost Hello localhost, pleased to meet you\n"; - st = hello; - return; - } - else { - stout = "503 localhost Duplicate HELO/EHLO\n"; - return; - } - case ehlo: - if (st == connect) { - stout = "250-localhost Hello localhost, pleased to meet you\n"; - stout += "250-8BITMIME\n"; - stout += "250-SIZE 8000000\n"; - stout += "250 HELP\n"; - st = hello; - return; - } - else { - stout = "503 localhost Duplicate HELO/EHLO\n"; - return; - } - case mail: - switch (st) { - case connect: - stout = "503 Polite people say HELO first\n"; - return; - case hello: - stout = "250 " + param + "... Sender ok\n"; - st = sender; - return; - case sender: - stout = "503 Sender already specified\n"; - return; - case recipient: - stout = "503 Sender already specified\n"; - return; - } - case rcpt: - switch (st) { - case connect: - stout = "503 Need MAIL before RCPT\n"; - return; - case hello: - stout = "503 Need MAIL before RCPT\n"; - return; - case sender: - stout = "250 " + param + "... Recipient ok\n"; - st = recipient; - return; - case recipient: - stout = "250 " + param + "... Recipient ok\n"; - return; - } - case data: - switch (st) { - case connect: - stout = "503 Need MAIL command\n"; - return; - case hello: - stout = "503 Need MAIL command\n"; - return; - case sender: - stout = "503 Need RCPT (recipient)\n"; - return; - case recipient: - stout = "354 Enter mail, end with '.' on a line by itself\n"; - st = letter; - return; - } - case rset: - stout = "250 Reset state\n"; - if (st!=connect) st = hello; - return; - case vrfy: - stout = "502 Command not implemented\n"; - return; - case expn: - stout = "502 Command not implemented\n"; - return; - case help: - stout = "214-This is SMTP_Server\n"; - stout += "214 End of HELP info\n"; - return; - case noop: - stout = "250 OK\n"; - return; - case quit: - stout = "221 localhost closing connection\n"; - stout += "Connection closed by foreign host.\n"; - st = disconnect; - return; - case none: - stout = "500 Command unrecognized\n"; - return; - } +void change( state& st, const command& com, const string& param, string& stout ) +{ + switch ( com ) { + case helo: + if (st == connect) { + stout = "250 localhost Hello localhost, pleased to meet you\n"; + st = hello; + } else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + } + return; + + case ehlo: + if (st == connect) { + stout = "250-localhost Hello localhost, pleased to meet you\n"; + stout += "250-8BITMIME\n"; + stout += "250-SIZE 8000000\n"; + stout += "250 HELP\n"; + st = hello; + } else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + } + return; + + case mail: + switch (st) { + case connect: + stout = "503 Polite people say HELO first\n"; + return; + case hello: + stout = "250 " + param + "... Sender ok\n"; + st = sender; + return; + case sender: + stout = "503 Sender already specified\n"; + return; + case recipient: + stout = "503 Sender already specified\n"; + return; + } + break; + + case rcpt: + switch (st) { + case connect: + stout = "503 Need MAIL before RCPT\n"; + return; + case hello: + stout = "503 Need MAIL before RCPT\n"; + return; + case sender: + stout = "250 " + param + "... Recipient ok\n"; + st = recipient; + return; + case recipient: + stout = "250 " + param + "... Recipient ok\n"; + return; + } + break; + + case data: + switch (st) { + case connect: + stout = "503 Need MAIL command\n"; + return; + case hello: + stout = "503 Need MAIL command\n"; + return; + case sender: + stout = "503 Need RCPT (recipient)\n"; + return; + case recipient: + stout = "354 Enter mail, end with '.' on a line by itself\n"; + st = letter; + return; + } + break; + + case rset: + stout = "250 Reset state\n"; + if ( st != connect ) { + st = hello; + } + return; + + case vrfy: + stout = "502 Command not implemented\n"; + return; + + case expn: + stout = "502 Command not implemented\n"; + return; + + case help: + stout = "214-This is SMTP_Server\n"; + stout += "214 End of HELP info\n"; + return; + + case noop: + stout = "250 OK\n"; + return; + + case quit: + stout = "221 localhost closing connection\n"; + stout += "Connection closed by foreign host.\n"; + st = disconnect; + return; + + case none: + stout = "500 Command unrecognized\n"; + return; + } } -int ServerWork() { - state st = connect; - command com; - string param, message, stout; - while (st != disconnect) { - if (st != letter) { - string str; - cin >> str; - getline(cin, param); - com = setCom(str); - change(st, com, param, stout); - cout << stout; - } - else { - getline(cin, param); - if (param != ".") message = message + param + "\n"; - else { - st = hello; - cout << message; - message = ""; - } - }; - }; - return 0; +int ServerWork() +{ + state st = connect; + command com; + string param, message, stout; + + while ( st != disconnect ) { + if ( st != letter ) { + string str; + cin >> str; + getline(cin, param); + com = setCom(str); + change(st, com, param, stout); + cout << stout; + } else { + getline( cin, param ); + if ( param != "." ) { + message += param + "\n"; + } else { + st = hello; + cout << message; + message = ""; + } + } + } + + return 0; } } // namespace smtp Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-25 09:17:02 UTC (rev 1859) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-25 11:26:22 UTC (rev 1860) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/25 13:11:53 yeti> +// -*- C++ -*- Time-stamp: <08/04/25 14:35:17 yeti> #ifndef __SMPT_SERVER_H #define __SMPT_SERVER_H @@ -37,7 +37,7 @@ command setCom( const std::string& str ); -void change( state& st, command& com, std::string& param, std::string& stout ); +void change( state& st, const command& com, const std::string& param, std::string& stout ); } // namespace smtp Copied: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/aux/test_0 (from rev 1857, trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0) =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/aux/test_0 (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/aux/test_0 2008-04-25 11:26:22 UTC (rev 1860) @@ -0,0 +1,4 @@ +221 +helo ya.ru +help +quit Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 09:17:02 UTC (rev 1859) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 11:26:22 UTC (rev 1860) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/25 13:14:01 yeti> +// -*- C++ -*- Time-stamp: <08/04/25 15:23:35 yeti> #include "my_test.h" @@ -13,12 +13,8 @@ #include <iostream> #include <fstream> -#include <semaphore.h> +#include <sstream> -#include <sys/wait.h> -#include <sys/ipc.h> -#include <sys/shm.h> - #include <unistd.h> using namespace std; @@ -32,14 +28,14 @@ // recipient // letter -const string set_state [6] = { - "quit\n", - "", - "helo mail.ru\n", - "helo mail.ru\nmail from:se...@ma...\n", - "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", - "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" - }; +const string set_state[] = { + "quit\n", + "", + "helo mail.ru\n", + "helo mail.ru\nmail from:se...@ma...\n", + "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", + "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" +}; //possible commands // helo @@ -56,30 +52,30 @@ // none -const string set_command [12] = { - "helo mail.ru", - "ehlo mail.ru", - "mail from:se...@ma...", - "rcpt to:rec...@ma...", - "data", - "rset", - "vrfy se...@ma...", - "expn se...@ma...", - "help", - "noop", - "quit", - "none" - }; +const string set_command[] = { + "helo mail.ru", + "ehlo mail.ru", + "mail from:se...@ma...", + "rcpt to:rec...@ma...", + "data", + "rset", + "vrfy se...@ma...", + "expn se...@ma...", + "help", + "noop", + "quit", + "none" +}; -const int set_result [6][12] = { - {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, -// {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, - {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, - {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, - {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, - {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, - {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} - }; +const int set_result[][sizeof(set_command)/sizeof(set_command[0])] = { + {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, + // {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, + {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, + {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} +}; const int buf_size = 1024; const int com_length = 4; @@ -91,75 +87,83 @@ void server_thread() { - char buffer[buf_size]; - state st = connect; - command com; - string param, message, stout; - while (st != disconnect) { - if (st != letter) { - if (read (fd2[0], buffer, sizeof(buffer)) < 1) fprintf(stderr,"Reading error\n"); - else { - cerr << ">> "<< buffer << endl; - string str (buffer); - param.assign (str, com_length, str.size()); - str.erase (com_length, str.size() - com_length + 1); - com = setCom (str); - change (st, com, param, stout); - - strcpy (buffer, stout.c_str()); - write (fd1[1], buffer, sizeof(buffer)); - } - } - else { - read (fd2[0], buffer, sizeof(buffer)); - param.assign (buffer, 0, sizeof(buffer)); - if (param != ".") message = message + param + "\n"; - else { - st = hello; -// cout << message; - message = ""; - } - }; - }; - active = false; -// cerr << "Server's loop may be here" << endl; + char buffer[buf_size]; + state st = connect; + command com; + string param, message, stout; + + while ( st != disconnect ) { + if ( st != letter ) { + if ( read( fd2[0], buffer, sizeof(buffer) ) < 1 ) { // <-- error (1) + cerr << "Reading error\n"; + } else { + cerr << ">> " << buffer << endl; + string str( buffer ); // <-- error (1) + param.assign( str, com_length, str.size() ); + str.erase( com_length, str.size() - com_length + 1 ); + com = setCom( str ); + change( st, com, param, stout ); + write( fd1[1], stout.data(), stout.length() ); + } + } else { + read( fd2[0], buffer, sizeof(buffer) ); // <-- error (2) + param.assign (buffer, 0, sizeof(buffer) ); // <-- error (2) + if ( param != "." ) { + message += param + "\n"; + } else { + st = hello; + // cout << message; + message = ""; + } + } + } + + active = false; + // cerr << "Server's loop may be here" << endl; } int EXAM_IMPL(my_test::thread_call) { - pipe (fd1); - pipe (fd2); - active = false; - for (int i = 0; i <= test_num; i++) { - char r_buffer[buf_size], w_buffer[buf_size]; - std::tr2::basic_thread<0,0> t( server_thread ); - active = true; + pipe (fd1); + pipe (fd2); + + active = false; - ostringstream st; - st << "test_" << i; - ifstream in (st.str().c_str()); - - string expected; - getline(in, expected); - - while (!in.eof()){ - string s; - getline(in, s); - if (s != "") { - strcpy (w_buffer, s.c_str()); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << "<< " << r_buffer; - } - } - in.close(); - t.join(); + string s; + string expected; - string result (r_buffer); - if (expected.compare (0, 3, result, 0, 3) != 0) - cerr << expected << "!=" << result << " at " << i << endl; + for ( int i = 0; i <= test_num; ++i ) { + char r_buffer[buf_size], w_buffer[buf_size]; + + std::tr2::basic_thread<0,0> t( server_thread ); + active = true; + + ostringstream st; + st << "aux/test_" << i; + + ifstream in( st.str().c_str() ); + + getline( in, expected ); + + while ( in.good() ){ + getline( in, s ); + if ( !s.empty() ) { + write( fd2[1], s.data(), s.length() ); + read( fd1[0], r_buffer, sizeof(r_buffer) ); // <-- error (3) + cerr << "<< " << r_buffer; // <-- error (3) + } + } + + in.close(); + + t.join(); + + string result(r_buffer); + if ( expected.compare(0, 3, result, 0, 3) != 0 ) { + cerr << expected << "!=" << result << " at " << i << endl; + } - EXAM_CHECK ((expected.compare (0, 3, result, 0, 3) == 0)); + EXAM_CHECK( expected.compare(0, 3, result, 0, 3) == 0 ); /* strcpy (w_buffer, "help"); write (fd2[1], w_buffer, sizeof(w_buffer)); @@ -173,33 +177,32 @@ cerr << "Client's text may be here" << endl; */ - } - // EXAM_CHECK( val == 1 ); - // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); - // t2.join(); - // EXAM_CHECK( val == 2 ); - // val = 0; + } + // EXAM_CHECK( val == 1 ); + // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); + // t2.join(); + // EXAM_CHECK( val == 2 ); + // val = 0; - return EXAM_RESULT; + return EXAM_RESULT; } int EXAM_IMPL(my_test::test_gen) { - int num = 1; - for (int i = 0; i < 6; i++) { - for (int j = 0; j < 12; j++) { - ostringstream st; - st << "test_" << num; -// st << "test_" << i << "_" << j; - ofstream os (st.str().c_str()); - os << set_result [i][j] << endl; - os << set_state [i] << set_command [j]; - os.close(); - num++; - } + int num = 1; + + for ( int i = 0; i < sizeof(set_state)/sizeof(set_state[0]); ++i ) { + for ( int j = 0; j < sizeof(set_command)/sizeof(set_command[0]); ++j ) { + ostringstream st; + st << "aux/test_" << num++; + + ofstream os( st.str().c_str() ); + + os << set_result[i][j] << "\n" + << set_state[i] << set_command[j]; } - return EXAM_RESULT; + } + + return EXAM_RESULT; } - - Deleted: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 2008-04-25 09:17:02 UTC (rev 1859) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 2008-04-25 11:26:22 UTC (rev 1860) @@ -1,4 +0,0 @@ -221 -helo ya.ru -help -quit This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-25 09:17:07
|
Revision: 1859 http://complement.svn.sourceforge.net/complement/?rev=1859&view=rev Author: complement Date: 2008-04-25 02:17:02 -0700 (Fri, 25 Apr 2008) Log Message: ----------- include guard added; server functions/data structs moved to smtp namespace Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-25 08:55:14 UTC (rev 1858) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-25 09:17:02 UTC (rev 1859) @@ -1,7 +1,12 @@ +// -*- C++ -*- Time-stamp: <08/04/25 13:13:10 yeti> + #include <iostream> #include <string> + #include "SMTP_Server.h" +namespace smtp { + using namespace std; command setCom(const string& str) { @@ -149,3 +154,5 @@ }; return 0; } + +} // namespace smtp Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-25 08:55:14 UTC (rev 1858) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-25 09:17:02 UTC (rev 1859) @@ -1,32 +1,44 @@ -using namespace std; +// -*- C++ -*- Time-stamp: <08/04/25 13:11:53 yeti> -enum state { - disconnect, - connect, - hello, - sender, - recipient, - letter - }; -enum command { - helo, - ehlo, - mail, - rcpt, - data, - rset, - vrfy, - expn, - help, - noop, - quit, - none - }; +#ifndef __SMPT_SERVER_H +#define __SMPT_SERVER_H +#include <string> +namespace smtp { + +enum state +{ + disconnect, + connect, + hello, + sender, + recipient, + letter +}; + +enum command +{ + helo, + ehlo, + mail, + rcpt, + data, + rset, + vrfy, + expn, + help, + noop, + quit, + none +}; + int ServerWork(); -command setCom(const string& str); +command setCom( const std::string& str ); -void change(state& st, command& com, string& param, string& stout); +void change( state& st, command& com, std::string& param, std::string& stout ); +} // namespace smtp + +#endif // __SMPT_SERVER_H Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 08:55:14 UTC (rev 1858) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 09:17:02 UTC (rev 1859) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/25 12:51:09 yeti> +// -*- C++ -*- Time-stamp: <08/04/25 13:14:01 yeti> #include "my_test.h" @@ -22,6 +22,7 @@ #include <unistd.h> using namespace std; +using namespace smtp; //possible states // disconnect This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-25 08:55:17
|
Revision: 1858 http://complement.svn.sourceforge.net/complement/?rev=1858&view=rev Author: complement Date: 2008-04-25 01:55:14 -0700 (Fri, 25 Apr 2008) Log Message: ----------- change EOL style to native Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Property Changed: ---------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut ___________________________________________________________________ Name: svn:ignore - obj + obj test_* Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile ___________________________________________________________________ Name: svn:eol-style + native Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-25 08:53:58 UTC (rev 1857) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-25 08:55:14 UTC (rev 1858) @@ -1,151 +1,151 @@ -#include <iostream> -#include <string> +#include <iostream> +#include <string> #include "SMTP_Server.h" - -using namespace std; - + +using namespace std; + command setCom(const string& str) { string Str(str); for(int i = 0; Str[i] != '\0'; i++) Str[i] = tolower(Str[i]); - if (Str == "helo") return helo; - else if (Str == "ehlo") return ehlo; - else if (Str == "mail") return mail; - else if (Str == "rcpt") return rcpt; - else if (Str == "data") return data; - else if (Str == "rset") return rset; - else if (Str == "vrfy") return vrfy; - else if (Str == "expn") return expn; - else if (Str == "help") return help; - else if (Str == "noop") return noop; - else if (Str == "quit") return quit; - else return none; -} - -void change(state& st, command& com, string& param, string& stout) { - switch (com) { - case helo: - if (st == connect) { - stout = "250 localhost Hello localhost, pleased to meet you\n"; + if (Str == "helo") return helo; + else if (Str == "ehlo") return ehlo; + else if (Str == "mail") return mail; + else if (Str == "rcpt") return rcpt; + else if (Str == "data") return data; + else if (Str == "rset") return rset; + else if (Str == "vrfy") return vrfy; + else if (Str == "expn") return expn; + else if (Str == "help") return help; + else if (Str == "noop") return noop; + else if (Str == "quit") return quit; + else return none; +} + +void change(state& st, command& com, string& param, string& stout) { + switch (com) { + case helo: + if (st == connect) { + stout = "250 localhost Hello localhost, pleased to meet you\n"; st = hello; - return; - } - else { - stout = "503 localhost Duplicate HELO/EHLO\n"; - return; - } - case ehlo: - if (st == connect) { - stout = "250-localhost Hello localhost, pleased to meet you\n"; - stout += "250-8BITMIME\n"; - stout += "250-SIZE 8000000\n"; - stout += "250 HELP\n"; - st = hello; - return; - } - else { - stout = "503 localhost Duplicate HELO/EHLO\n"; - return; - } - case mail: - switch (st) { - case connect: - stout = "503 Polite people say HELO first\n"; - return; - case hello: - stout = "250 " + param + "... Sender ok\n"; - st = sender; - return; - case sender: - stout = "503 Sender already specified\n"; - return; - case recipient: - stout = "503 Sender already specified\n"; - return; - } - case rcpt: - switch (st) { - case connect: - stout = "503 Need MAIL before RCPT\n"; - return; - case hello: - stout = "503 Need MAIL before RCPT\n"; - return; - case sender: - stout = "250 " + param + "... Recipient ok\n"; - st = recipient; - return; - case recipient: - stout = "250 " + param + "... Recipient ok\n"; - return; - } - case data: - switch (st) { - case connect: - stout = "503 Need MAIL command\n"; - return; - case hello: - stout = "503 Need MAIL command\n"; - return; - case sender: - stout = "503 Need RCPT (recipient)\n"; - return; - case recipient: - stout = "354 Enter mail, end with '.' on a line by itself\n"; - st = letter; - return; - } - case rset: - stout = "250 Reset state\n"; - if (st!=connect) st = hello; - return; - case vrfy: - stout = "502 Command not implemented\n"; - return; - case expn: - stout = "502 Command not implemented\n"; - return; - case help: - stout = "214-This is SMTP_Server\n"; - stout += "214 End of HELP info\n"; - return; - case noop: - stout = "250 OK\n"; - return; - case quit: - stout = "221 localhost closing connection\n"; - stout += "Connection closed by foreign host.\n"; - st = disconnect; - return; - case none: - stout = "500 Command unrecognized\n"; - return; - } -} + return; + } + else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + return; + } + case ehlo: + if (st == connect) { + stout = "250-localhost Hello localhost, pleased to meet you\n"; + stout += "250-8BITMIME\n"; + stout += "250-SIZE 8000000\n"; + stout += "250 HELP\n"; + st = hello; + return; + } + else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + return; + } + case mail: + switch (st) { + case connect: + stout = "503 Polite people say HELO first\n"; + return; + case hello: + stout = "250 " + param + "... Sender ok\n"; + st = sender; + return; + case sender: + stout = "503 Sender already specified\n"; + return; + case recipient: + stout = "503 Sender already specified\n"; + return; + } + case rcpt: + switch (st) { + case connect: + stout = "503 Need MAIL before RCPT\n"; + return; + case hello: + stout = "503 Need MAIL before RCPT\n"; + return; + case sender: + stout = "250 " + param + "... Recipient ok\n"; + st = recipient; + return; + case recipient: + stout = "250 " + param + "... Recipient ok\n"; + return; + } + case data: + switch (st) { + case connect: + stout = "503 Need MAIL command\n"; + return; + case hello: + stout = "503 Need MAIL command\n"; + return; + case sender: + stout = "503 Need RCPT (recipient)\n"; + return; + case recipient: + stout = "354 Enter mail, end with '.' on a line by itself\n"; + st = letter; + return; + } + case rset: + stout = "250 Reset state\n"; + if (st!=connect) st = hello; + return; + case vrfy: + stout = "502 Command not implemented\n"; + return; + case expn: + stout = "502 Command not implemented\n"; + return; + case help: + stout = "214-This is SMTP_Server\n"; + stout += "214 End of HELP info\n"; + return; + case noop: + stout = "250 OK\n"; + return; + case quit: + stout = "221 localhost closing connection\n"; + stout += "Connection closed by foreign host.\n"; + st = disconnect; + return; + case none: + stout = "500 Command unrecognized\n"; + return; + } +} - + int ServerWork() { - state st = connect; + state st = connect; command com; - string param, message, stout; - while (st != disconnect) { - if (st != letter) { - string str; + string param, message, stout; + while (st != disconnect) { + if (st != letter) { + string str; cin >> str; getline(cin, param); - com = setCom(str); + com = setCom(str); change(st, com, param, stout); - cout << stout; - } - else { - getline(cin, param); - if (param != ".") message = message + param + "\n"; - else { - st = hello; - cout << message; - message = ""; - } - }; - }; - return 0; -} + cout << stout; + } + else { + getline(cin, param); + if (param != ".") message = message + param + "\n"; + else { + st = hello; + cout << message; + message = ""; + } + }; + }; + return 0; +} Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-25 08:53:58 UTC (rev 1857) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-25 08:55:14 UTC (rev 1858) @@ -7,7 +7,7 @@ sender, recipient, letter - }; + }; enum command { helo, ehlo, @@ -21,7 +21,7 @@ noop, quit, none - }; + }; int ServerWork(); Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 08:53:58 UTC (rev 1857) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-25 08:55:14 UTC (rev 1858) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 01:53:46 ptr> +// -*- C++ -*- Time-stamp: <08/04/25 12:51:09 yeti> #include "my_test.h" @@ -91,10 +91,10 @@ void server_thread() { char buffer[buf_size]; - state st = connect; + state st = connect; command com; string param, message, stout; - while (st != disconnect) { + while (st != disconnect) { if (st != letter) { if (read (fd2[0], buffer, sizeof(buffer)) < 1) fprintf(stderr,"Reading error\n"); else { @@ -102,23 +102,23 @@ string str (buffer); param.assign (str, com_length, str.size()); str.erase (com_length, str.size() - com_length + 1); - com = setCom (str); + com = setCom (str); change (st, com, param, stout); strcpy (buffer, stout.c_str()); write (fd1[1], buffer, sizeof(buffer)); } - } + } else { read (fd2[0], buffer, sizeof(buffer)); param.assign (buffer, 0, sizeof(buffer)); - if (param != ".") message = message + param + "\n"; - else { - st = hello; -// cout << message; + if (param != ".") message = message + param + "\n"; + else { + st = hello; +// cout << message; message = ""; } - }; + }; }; active = false; // cerr << "Server's loop may be here" << endl; Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc ___________________________________________________________________ Name: svn:eol-style + native Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-25 08:54:16
|
Revision: 1857 http://complement.svn.sourceforge.net/complement/?rev=1857&view=rev Author: complement Date: 2008-04-25 01:53:58 -0700 (Fri, 25 Apr 2008) Log Message: ----------- fix dependency between tests; sample of setting dependency between tests Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc Property Changed: ---------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-24 12:03:43 UTC (rev 1856) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-25 08:53:58 UTC (rev 1857) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 10:12:21 ptr> +// -*- C++ -*- Time-stamp: <08/04/25 12:01:55 yeti> #include "my_test_suite.h" #include "my_test.h" @@ -7,11 +7,20 @@ int EXAM_IMPL(my_test_suite) { - exam::test_suite t( "my test" ); + exam::test_suite t( "test suite for SMTP server" ); my_test test; - t.add( &my_test::test_gen, test, "my_test::test_gen" ); - t.add( &my_test::thread_call, test, "my_test::thread_call" ); + // exam::test_suite::test_case_type tc0; + + t.add( &my_test::thread_call, test, "my_test::thread_call", + t.add( &my_test::test_gen, test, "my_test::test_gen" ) ); + +#if 0 + tc0 = t.add( &my_test::test_gen, test, "my_test::test_gen" ); + t.add( &my_test::thread_call, test, "my_test::thread_call", tc0 ); + t.add( &my_test::thread_call, test, "my_test::thread_call_yet_more", tc0 ); +#endif + return t.girdle(); }; Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-04-24 12:03:47
|
Revision: 1856 http://complement.svn.sourceforge.net/complement/?rev=1856&view=rev Author: okechina Date: 2008-04-24 05:03:43 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Added Paths: ----------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/test_0 2008-04-24 12:03:43 UTC (rev 1856) @@ -0,0 +1,4 @@ +221 +helo ya.ru +help +quit This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <oke...@us...> - 2008-04-24 11:58:28
|
Revision: 1855 http://complement.svn.sourceforge.net/complement/?rev=1855&view=rev Author: okechina Date: 2008-04-24 04:58:15 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-23 19:22:40 UTC (rev 1854) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-24 11:58:15 UTC (rev 1855) @@ -1,6 +1,8 @@ // -*- C++ -*- Time-stamp: <08/03/26 01:53:46 ptr> #include "my_test.h" + + #include "SMTP_Server.h" #include <mt/thread> @@ -10,6 +12,7 @@ #include <typeinfo> #include <iostream> +#include <fstream> #include <semaphore.h> #include <sys/wait.h> @@ -20,72 +23,156 @@ using namespace std; -static int fd1[2], fd2[2]; +//possible states +// disconnect +// connect +// hello +// sender +// recipient +// letter +const string set_state [6] = { + "quit\n", + "", + "helo mail.ru\n", + "helo mail.ru\nmail from:se...@ma...\n", + "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", + "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" + }; + +//possible commands +// helo +// ehlo +// mail +// rcpt +// data +// rset +// vrfy +// expn +// help +// noop +// quit +// none + + +const string set_command [12] = { + "helo mail.ru", + "ehlo mail.ru", + "mail from:se...@ma...", + "rcpt to:rec...@ma...", + "data", + "rset", + "vrfy se...@ma...", + "expn se...@ma...", + "help", + "noop", + "quit", + "none" + }; + +const int set_result [6][12] = { + {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, +// {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, + {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, + {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} + }; + const int buf_size = 1024; const int com_length = 4; +const int test_num = 0; +static int fd1[2], fd2[2]; + +bool active; + void server_thread() { char buffer[buf_size]; state st = connect; command com; string param, message, stout; - while (st != disconnect) { if (st != letter) { - if (read (fd2[0], buffer, sizeof(buffer)) < 1) fprintf(stderr,"Reading error\n"); - else fprintf (stderr,"%s\n",buffer); - - string str(buffer); - param.assign (str, com_length, str.size()); - str.erase (com_length, str.size() - com_length + 1); - com = setCom (str); - change (st, com, param, stout); + else { + cerr << ">> "<< buffer << endl; + string str (buffer); + param.assign (str, com_length, str.size()); + str.erase (com_length, str.size() - com_length + 1); + com = setCom (str); + change (st, com, param, stout); - strcpy (buffer, stout.c_str()); - write (fd1[1], buffer, sizeof(buffer)); + strcpy (buffer, stout.c_str()); + write (fd1[1], buffer, sizeof(buffer)); + } } - else { + else { read (fd2[0], buffer, sizeof(buffer)); param.assign (buffer, 0, sizeof(buffer)); if (param != ".") message = message + param + "\n"; else { st = hello; // cout << message; - message = ""; - } + message = ""; + } }; }; - cerr << "Server's loop may be here" << endl; + active = false; +// cerr << "Server's loop may be here" << endl; } int EXAM_IMPL(my_test::thread_call) { - char r_buffer[buf_size], w_buffer[buf_size]; pipe (fd1); pipe (fd2); - std::tr2::basic_thread<0,0> t( server_thread ); + active = false; + for (int i = 0; i <= test_num; i++) { + char r_buffer[buf_size], w_buffer[buf_size]; + std::tr2::basic_thread<0,0> t( server_thread ); + active = true; - strcpy (w_buffer, "ehlo"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; + ostringstream st; + st << "test_" << i; + ifstream in (st.str().c_str()); + + string expected; + getline(in, expected); + + while (!in.eof()){ + string s; + getline(in, s); + if (s != "") { + strcpy (w_buffer, s.c_str()); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << "<< " << r_buffer; + } + } + in.close(); + t.join(); - strcpy (w_buffer, "help"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; + string result (r_buffer); + if (expected.compare (0, 3, result, 0, 3) != 0) + cerr << expected << "!=" << result << " at " << i << endl; + + EXAM_CHECK ((expected.compare (0, 3, result, 0, 3) == 0)); + +/* strcpy (w_buffer, "help"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; - strcpy (w_buffer, "quit"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; + strcpy (w_buffer, "quit"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; - cerr << "Client's text may be here" << endl; - t.join(); - + cerr << "Client's text may be here" << endl; +*/ + } // EXAM_CHECK( val == 1 ); // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); // t2.join(); @@ -95,3 +182,23 @@ return EXAM_RESULT; } + +int EXAM_IMPL(my_test::test_gen) +{ + int num = 1; + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 12; j++) { + ostringstream st; + st << "test_" << num; +// st << "test_" << i << "_" << j; + ofstream os (st.str().c_str()); + os << set_result [i][j] << endl; + os << set_state [i] << set_command [j]; + os.close(); + num++; + } + } + return EXAM_RESULT; +} + + Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h 2008-04-23 19:22:40 UTC (rev 1854) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h 2008-04-24 11:58:15 UTC (rev 1855) @@ -13,6 +13,7 @@ { public: int EXAM_DECL(thread_call); + int EXAM_DECL(test_gen); }; #endif // __MY_TEST_H Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-23 19:22:40 UTC (rev 1854) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-24 11:58:15 UTC (rev 1855) @@ -10,6 +10,7 @@ exam::test_suite t( "my test" ); my_test test; + t.add( &my_test::test_gen, test, "my_test::test_gen" ); t.add( &my_test::thread_call, test, "my_test::thread_call" ); return t.girdle(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-23 19:23:36
|
Revision: 1854 http://complement.svn.sourceforge.net/complement/?rev=1854&view=rev Author: complement Date: 2008-04-23 12:22:40 -0700 (Wed, 23 Apr 2008) Log Message: ----------- remove STLport-specific macro STATIC_CAST; include sys/time.h required for gettimeofday; bump libxmt revision to 2.0.2 Modified Paths: -------------- trunk/complement/explore/include/mt/mutex trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/date_time.cc Modified: trunk/complement/explore/include/mt/mutex =================================================================== --- trunk/complement/explore/include/mt/mutex 2008-04-23 09:22:13 UTC (rev 1853) +++ trunk/complement/explore/include/mt/mutex 2008-04-23 19:22:40 UTC (rev 1854) @@ -379,7 +379,7 @@ { if ( --_count == 0 ) { # ifdef __FIT_PTHREADS - _id = __STATIC_CAST(pthread_t,-1); + _id = static_cast<pthread_t>(-1); pthread_spin_unlock( &this->_M_lock ); # endif } Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-04-23 09:22:13 UTC (rev 1853) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-04-23 19:22:40 UTC (rev 1854) @@ -1,5 +1,12 @@ 2008-04-23 Petr Ovtchenkov <pt...@is...> + * mutex: remove STLport-specific macro STATIC_CAST; + + * date_time.cc: include sys/time.h required for gettimeofday; + patch #1938561; + + * libxmt: bump revision to 2.0.2; + * thread: fix access to thread's _id in case of detached thread; really take thread's id into fake variable and keep _id as bad_thread_id. Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-04-23 09:22:13 UTC (rev 1853) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-04-23 19:22:40 UTC (rev 1854) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <07/11/21 11:35:57 ptr> +# -*- Makefile -*- Time-stamp: <08/04/23 23:15:02 ptr> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 1 +PATCH = 2 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/date_time.cc =================================================================== --- trunk/complement/explore/lib/mt/date_time.cc 2008-04-23 09:22:13 UTC (rev 1853) +++ trunk/complement/explore/lib/mt/date_time.cc 2008-04-23 19:22:40 UTC (rev 1854) @@ -14,6 +14,7 @@ #include <mt/date_time> #include <ctime> +#include <sys/time.h> namespace std { @@ -81,7 +82,7 @@ { #if defined(__linux) || defined(__FreeBSD__) || defined(__OpenBSD__) timeval tv; - gettimeofday( &tv, 0 ); + ::gettimeofday( &tv, 0 ); return system_time( tv.tv_sec * nanoseconds::ticks_per_second + tv.tv_usec * 1000LL, system_time::_adopt_t() ); #elif defined( WIN32 ) union { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |