From 52be1ef0d126f09ba943c7afcf367e7d9347f2fd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 8 Nov 2012 22:58:28 +0000 Subject: tabconv: it's all spaces now. --- LICENSE | 28 + bootstrap/signals.h | 2290 ++++++++++++++++----------------- default.bld | 114 +- pkg.bld | 54 +- share/autoinclude/general-rules.bld | 166 +-- share/include/qt4.bld | 236 ++-- src/action.cpp | 178 +-- src/action.h | 22 +- src/ast.cpp | 106 +- src/ast.h | 46 +- src/astbranch.cpp | 36 +- src/astbranch.h | 16 +- src/astleaf.cpp | 132 +- src/astleaf.h | 44 +- src/astnode.cpp | 184 +-- src/astnode.h | 174 +-- src/buildparser.cpp | 150 +-- src/buildparser.h | 28 +- src/cache.cpp | 50 +- src/cache.h | 28 +- src/condition.h | 8 +- src/conditionalways.cpp | 6 +- src/conditionalways.h | 8 +- src/conditionfileexists.cpp | 24 +- src/conditionfileexists.h | 8 +- src/conditionfiletime.cpp | 100 +- src/conditionfiletime.h | 8 +- src/conditionnever.cpp | 6 +- src/conditionnever.h | 8 +- src/conditionplugger.cpp | 50 +- src/conditionplugger.h | 6 +- src/context.cpp | 808 ++++++------ src/context.h | 150 +-- src/filemgr.cpp | 48 +- src/filemgr.h | 16 +- src/function.cpp | 4 +- src/function.h | 12 +- src/functionast.cpp | 44 +- src/functionast.h | 14 +- src/functionclose.cpp | 8 +- src/functionclose.h | 8 +- src/functiondirname.cpp | 40 +- src/functiondirname.h | 8 +- src/functiondirs.cpp | 64 +- src/functiondirs.h | 8 +- src/functionexecute.cpp | 90 +- src/functionexecute.h | 8 +- src/functionexists.cpp | 30 +- src/functionexists.h | 8 +- src/functionfilename.cpp | 36 +- src/functionfilename.h | 8 +- src/functionfiles.cpp | 64 +- src/functionfiles.h | 8 +- src/functiongetmakedeps.cpp | 78 +- src/functiongetmakedeps.h | 8 +- src/functionmatches.cpp | 216 ++-- src/functionmatches.h | 20 +- src/functionopen.cpp | 40 +- src/functionopen.h | 8 +- src/functionplugger.cpp | 74 +- src/functionplugger.h | 6 +- src/functionrange.cpp | 94 +- src/functionrange.h | 8 +- src/functionread.cpp | 36 +- src/functionread.h | 8 +- src/functionregex.cpp | 184 +-- src/functionregex.h | 14 +- src/functionreplace.cpp | 60 +- src/functionreplace.h | 8 +- src/functiontargets.cpp | 40 +- src/functiontargets.h | 8 +- src/functiontostring.cpp | 58 +- src/functiontostring.h | 8 +- src/functionunique.cpp | 40 +- src/functionunique.h | 8 +- src/functionunlink.cpp | 58 +- src/functionunlink.h | 8 +- src/functionwrite.cpp | 24 +- src/functionwrite.h | 8 +- src/location.cpp | 32 +- src/location.h | 20 +- src/main.cpp | 562 ++++---- src/plugins/pluginConditionRandom.cpp | 34 +- src/profile.cpp | 102 +- src/profile.h | 26 +- src/rule.cpp | 168 +-- src/rule.h | 52 +- src/runner.cpp | 1690 ++++++++++++------------ src/runner.h | 52 +- src/target.cpp | 466 +++---- src/target.h | 116 +- src/variable.cpp | 1542 +++++++++++----------- src/variable.h | 190 +-- src/view.h | 50 +- src/viewdefault.cpp | 242 ++-- src/viewdefault.h | 58 +- src/viewmake.cpp | 24 +- src/viewmake.h | 50 +- src/viewplugger.cpp | 40 +- src/viewplugger.h | 6 +- 100 files changed, 6235 insertions(+), 6207 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5eaeb9c --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +Copyright (C) 2007-2012 Xagasoft + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + - Neither the name of Xagasoft nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bootstrap/signals.h b/bootstrap/signals.h index 47ddad4..875f16e 100644 --- a/bootstrap/signals.h +++ b/bootstrap/signals.h @@ -13,1194 +13,1194 @@ namespace Bu { - subExceptionDecl( SignalException ); + subExceptionDecl( SignalException ); #ifndef BU_SIGNAL_PARAM_COUNT_0 #define BU_SIGNAL_PARAM_COUNT_0 - // - // 0 Parameter(s) - // - template - class _Slot0 - { - public: - _Slot0() { } - virtual ~_Slot0() { } - virtual ret operator()( )=0; - virtual _Slot0 *clone() const=0; - }; - - template - class __Slot0 : public _Slot0 - { - public: - __Slot0( cls *pCls, ret (cls::*pFnc)( ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot0() { } - - virtual ret operator()( ) - { - return (pCls->*pFnc)( ); - } - - virtual _Slot0 *clone() const - { - return new __Slot0( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( ); - }; - - template - class __Slot0F : public _Slot0 - { - public: - __Slot0F( ret (*pFnc)( ) ) : - pFnc( pFnc ) { } - virtual ~__Slot0F() { } - - virtual ret operator()( ) - { - return (*pFnc)( ); - } - - virtual _Slot0 *clone() const - { - return new __Slot0F( pFnc ); - } - - private: - ret (*pFnc)( ); - }; - - template - class Signal0 - { - public: - Signal0() : pCb( NULL ) { } - Signal0( _Slot0 *pCb ) : pCb( pCb ) { } - Signal0( const Signal0 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal0() { delete pCb; pCb = NULL; } - - ret operator()( ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal0 &operator=( const Signal0 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot0 *pCb; - }; - - template - Signal0 slot( cls *pCls, ret (cls::*pFnc)( ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal0( - new __Slot0( pCls, pFnc ) - ); - } - - template - Signal0 slot( ret (*pFnc)( ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal0( - new __Slot0F( pFnc ) - ); - } + // + // 0 Parameter(s) + // + template + class _Slot0 + { + public: + _Slot0() { } + virtual ~_Slot0() { } + virtual ret operator()( )=0; + virtual _Slot0 *clone() const=0; + }; + + template + class __Slot0 : public _Slot0 + { + public: + __Slot0( cls *pCls, ret (cls::*pFnc)( ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot0() { } + + virtual ret operator()( ) + { + return (pCls->*pFnc)( ); + } + + virtual _Slot0 *clone() const + { + return new __Slot0( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( ); + }; + + template + class __Slot0F : public _Slot0 + { + public: + __Slot0F( ret (*pFnc)( ) ) : + pFnc( pFnc ) { } + virtual ~__Slot0F() { } + + virtual ret operator()( ) + { + return (*pFnc)( ); + } + + virtual _Slot0 *clone() const + { + return new __Slot0F( pFnc ); + } + + private: + ret (*pFnc)( ); + }; + + template + class Signal0 + { + public: + Signal0() : pCb( NULL ) { } + Signal0( _Slot0 *pCb ) : pCb( pCb ) { } + Signal0( const Signal0 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal0() { delete pCb; pCb = NULL; } + + ret operator()( ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal0 &operator=( const Signal0 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot0 *pCb; + }; + + template + Signal0 slot( cls *pCls, ret (cls::*pFnc)( ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal0( + new __Slot0( pCls, pFnc ) + ); + } + + template + Signal0 slot( ret (*pFnc)( ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal0( + new __Slot0F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_0 #ifndef BU_SIGNAL_PARAM_COUNT_1 #define BU_SIGNAL_PARAM_COUNT_1 - // - // 1 Parameter(s) - // - template - class _Slot1 - { - public: - _Slot1() { } - virtual ~_Slot1() { } - virtual ret operator()( p1t p1 )=0; - virtual _Slot1 *clone() const=0; - }; - - template - class __Slot1 : public _Slot1 - { - public: - __Slot1( cls *pCls, ret (cls::*pFnc)( p1t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot1() { } - - virtual ret operator()( p1t p1 ) - { - return (pCls->*pFnc)( p1 ); - } - - virtual _Slot1 *clone() const - { - return new __Slot1( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t ); - }; - - template - class __Slot1F : public _Slot1 - { - public: - __Slot1F( ret (*pFnc)( p1t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot1F() { } - - virtual ret operator()( p1t p1 ) - { - return (*pFnc)( p1 ); - } - - virtual _Slot1 *clone() const - { - return new __Slot1F( pFnc ); - } - - private: - ret (*pFnc)( p1t ); - }; - - template - class Signal1 - { - public: - Signal1() : pCb( NULL ) { } - Signal1( _Slot1 *pCb ) : pCb( pCb ) { } - Signal1( const Signal1 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal1() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal1 &operator=( const Signal1 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot1 *pCb; - }; - - template - Signal1 slot( cls *pCls, ret (cls::*pFnc)( p1t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal1( - new __Slot1( pCls, pFnc ) - ); - } - - template - Signal1 slot( ret (*pFnc)( p1t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal1( - new __Slot1F( pFnc ) - ); - } + // + // 1 Parameter(s) + // + template + class _Slot1 + { + public: + _Slot1() { } + virtual ~_Slot1() { } + virtual ret operator()( p1t p1 )=0; + virtual _Slot1 *clone() const=0; + }; + + template + class __Slot1 : public _Slot1 + { + public: + __Slot1( cls *pCls, ret (cls::*pFnc)( p1t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot1() { } + + virtual ret operator()( p1t p1 ) + { + return (pCls->*pFnc)( p1 ); + } + + virtual _Slot1 *clone() const + { + return new __Slot1( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t ); + }; + + template + class __Slot1F : public _Slot1 + { + public: + __Slot1F( ret (*pFnc)( p1t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot1F() { } + + virtual ret operator()( p1t p1 ) + { + return (*pFnc)( p1 ); + } + + virtual _Slot1 *clone() const + { + return new __Slot1F( pFnc ); + } + + private: + ret (*pFnc)( p1t ); + }; + + template + class Signal1 + { + public: + Signal1() : pCb( NULL ) { } + Signal1( _Slot1 *pCb ) : pCb( pCb ) { } + Signal1( const Signal1 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal1() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal1 &operator=( const Signal1 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot1 *pCb; + }; + + template + Signal1 slot( cls *pCls, ret (cls::*pFnc)( p1t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal1( + new __Slot1( pCls, pFnc ) + ); + } + + template + Signal1 slot( ret (*pFnc)( p1t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal1( + new __Slot1F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_1 #ifndef BU_SIGNAL_PARAM_COUNT_2 #define BU_SIGNAL_PARAM_COUNT_2 - // - // 2 Parameter(s) - // - template - class _Slot2 - { - public: - _Slot2() { } - virtual ~_Slot2() { } - virtual ret operator()( p1t p1, p2t p2 )=0; - virtual _Slot2 *clone() const=0; - }; - - template - class __Slot2 : public _Slot2 - { - public: - __Slot2( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot2() { } - - virtual ret operator()( p1t p1, p2t p2 ) - { - return (pCls->*pFnc)( p1, p2 ); - } - - virtual _Slot2 *clone() const - { - return new __Slot2( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t ); - }; - - template - class __Slot2F : public _Slot2 - { - public: - __Slot2F( ret (*pFnc)( p1t, p2t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot2F() { } - - virtual ret operator()( p1t p1, p2t p2 ) - { - return (*pFnc)( p1, p2 ); - } - - virtual _Slot2 *clone() const - { - return new __Slot2F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t ); - }; - - template - class Signal2 - { - public: - Signal2() : pCb( NULL ) { } - Signal2( _Slot2 *pCb ) : pCb( pCb ) { } - Signal2( const Signal2 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal2() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal2 &operator=( const Signal2 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot2 *pCb; - }; - - template - Signal2 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal2( - new __Slot2( pCls, pFnc ) - ); - } - - template - Signal2 slot( ret (*pFnc)( p1t, p2t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal2( - new __Slot2F( pFnc ) - ); - } + // + // 2 Parameter(s) + // + template + class _Slot2 + { + public: + _Slot2() { } + virtual ~_Slot2() { } + virtual ret operator()( p1t p1, p2t p2 )=0; + virtual _Slot2 *clone() const=0; + }; + + template + class __Slot2 : public _Slot2 + { + public: + __Slot2( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot2() { } + + virtual ret operator()( p1t p1, p2t p2 ) + { + return (pCls->*pFnc)( p1, p2 ); + } + + virtual _Slot2 *clone() const + { + return new __Slot2( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t ); + }; + + template + class __Slot2F : public _Slot2 + { + public: + __Slot2F( ret (*pFnc)( p1t, p2t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot2F() { } + + virtual ret operator()( p1t p1, p2t p2 ) + { + return (*pFnc)( p1, p2 ); + } + + virtual _Slot2 *clone() const + { + return new __Slot2F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t ); + }; + + template + class Signal2 + { + public: + Signal2() : pCb( NULL ) { } + Signal2( _Slot2 *pCb ) : pCb( pCb ) { } + Signal2( const Signal2 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal2() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal2 &operator=( const Signal2 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot2 *pCb; + }; + + template + Signal2 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal2( + new __Slot2( pCls, pFnc ) + ); + } + + template + Signal2 slot( ret (*pFnc)( p1t, p2t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal2( + new __Slot2F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_2 #ifndef BU_SIGNAL_PARAM_COUNT_3 #define BU_SIGNAL_PARAM_COUNT_3 - // - // 3 Parameter(s) - // - template - class _Slot3 - { - public: - _Slot3() { } - virtual ~_Slot3() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3 )=0; - virtual _Slot3 *clone() const=0; - }; - - template - class __Slot3 : public _Slot3 - { - public: - __Slot3( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot3() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3 ) - { - return (pCls->*pFnc)( p1, p2, p3 ); - } - - virtual _Slot3 *clone() const - { - return new __Slot3( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t ); - }; - - template - class __Slot3F : public _Slot3 - { - public: - __Slot3F( ret (*pFnc)( p1t, p2t, p3t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot3F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3 ) - { - return (*pFnc)( p1, p2, p3 ); - } - - virtual _Slot3 *clone() const - { - return new __Slot3F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t ); - }; - - template - class Signal3 - { - public: - Signal3() : pCb( NULL ) { } - Signal3( _Slot3 *pCb ) : pCb( pCb ) { } - Signal3( const Signal3 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal3() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal3 &operator=( const Signal3 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot3 *pCb; - }; - - template - Signal3 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal3( - new __Slot3( pCls, pFnc ) - ); - } - - template - Signal3 slot( ret (*pFnc)( p1t, p2t, p3t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal3( - new __Slot3F( pFnc ) - ); - } + // + // 3 Parameter(s) + // + template + class _Slot3 + { + public: + _Slot3() { } + virtual ~_Slot3() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3 )=0; + virtual _Slot3 *clone() const=0; + }; + + template + class __Slot3 : public _Slot3 + { + public: + __Slot3( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot3() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3 ) + { + return (pCls->*pFnc)( p1, p2, p3 ); + } + + virtual _Slot3 *clone() const + { + return new __Slot3( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t ); + }; + + template + class __Slot3F : public _Slot3 + { + public: + __Slot3F( ret (*pFnc)( p1t, p2t, p3t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot3F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3 ) + { + return (*pFnc)( p1, p2, p3 ); + } + + virtual _Slot3 *clone() const + { + return new __Slot3F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t ); + }; + + template + class Signal3 + { + public: + Signal3() : pCb( NULL ) { } + Signal3( _Slot3 *pCb ) : pCb( pCb ) { } + Signal3( const Signal3 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal3() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal3 &operator=( const Signal3 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot3 *pCb; + }; + + template + Signal3 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal3( + new __Slot3( pCls, pFnc ) + ); + } + + template + Signal3 slot( ret (*pFnc)( p1t, p2t, p3t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal3( + new __Slot3F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_3 #ifndef BU_SIGNAL_PARAM_COUNT_4 #define BU_SIGNAL_PARAM_COUNT_4 - // - // 4 Parameter(s) - // - template - class _Slot4 - { - public: - _Slot4() { } - virtual ~_Slot4() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )=0; - virtual _Slot4 *clone() const=0; - }; - - template - class __Slot4 : public _Slot4 - { - public: - __Slot4( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot4() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4 ); - } - - virtual _Slot4 *clone() const - { - return new __Slot4( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t ); - }; - - template - class __Slot4F : public _Slot4 - { - public: - __Slot4F( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot4F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) - { - return (*pFnc)( p1, p2, p3, p4 ); - } - - virtual _Slot4 *clone() const - { - return new __Slot4F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t ); - }; - - template - class Signal4 - { - public: - Signal4() : pCb( NULL ) { } - Signal4( _Slot4 *pCb ) : pCb( pCb ) { } - Signal4( const Signal4 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal4() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal4 &operator=( const Signal4 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot4 *pCb; - }; - - template - Signal4 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal4( - new __Slot4( pCls, pFnc ) - ); - } - - template - Signal4 slot( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal4( - new __Slot4F( pFnc ) - ); - } + // + // 4 Parameter(s) + // + template + class _Slot4 + { + public: + _Slot4() { } + virtual ~_Slot4() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )=0; + virtual _Slot4 *clone() const=0; + }; + + template + class __Slot4 : public _Slot4 + { + public: + __Slot4( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot4() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4 ); + } + + virtual _Slot4 *clone() const + { + return new __Slot4( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t ); + }; + + template + class __Slot4F : public _Slot4 + { + public: + __Slot4F( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot4F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) + { + return (*pFnc)( p1, p2, p3, p4 ); + } + + virtual _Slot4 *clone() const + { + return new __Slot4F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t ); + }; + + template + class Signal4 + { + public: + Signal4() : pCb( NULL ) { } + Signal4( _Slot4 *pCb ) : pCb( pCb ) { } + Signal4( const Signal4 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal4() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal4 &operator=( const Signal4 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot4 *pCb; + }; + + template + Signal4 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal4( + new __Slot4( pCls, pFnc ) + ); + } + + template + Signal4 slot( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal4( + new __Slot4F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_4 #ifndef BU_SIGNAL_PARAM_COUNT_5 #define BU_SIGNAL_PARAM_COUNT_5 - // - // 5 Parameter(s) - // - template - class _Slot5 - { - public: - _Slot5() { } - virtual ~_Slot5() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )=0; - virtual _Slot5 *clone() const=0; - }; - - template - class __Slot5 : public _Slot5 - { - public: - __Slot5( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot5() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4, p5 ); - } - - virtual _Slot5 *clone() const - { - return new __Slot5( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ); - }; - - template - class __Slot5F : public _Slot5 - { - public: - __Slot5F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot5F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) - { - return (*pFnc)( p1, p2, p3, p4, p5 ); - } - - virtual _Slot5 *clone() const - { - return new __Slot5F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ); - }; - - template - class Signal5 - { - public: - Signal5() : pCb( NULL ) { } - Signal5( _Slot5 *pCb ) : pCb( pCb ) { } - Signal5( const Signal5 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal5() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4, p5 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal5 &operator=( const Signal5 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot5 *pCb; - }; - - template - Signal5 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal5( - new __Slot5( pCls, pFnc ) - ); - } - - template - Signal5 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal5( - new __Slot5F( pFnc ) - ); - } + // + // 5 Parameter(s) + // + template + class _Slot5 + { + public: + _Slot5() { } + virtual ~_Slot5() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )=0; + virtual _Slot5 *clone() const=0; + }; + + template + class __Slot5 : public _Slot5 + { + public: + __Slot5( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot5() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5 ); + } + + virtual _Slot5 *clone() const + { + return new __Slot5( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ); + }; + + template + class __Slot5F : public _Slot5 + { + public: + __Slot5F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot5F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) + { + return (*pFnc)( p1, p2, p3, p4, p5 ); + } + + virtual _Slot5 *clone() const + { + return new __Slot5F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ); + }; + + template + class Signal5 + { + public: + Signal5() : pCb( NULL ) { } + Signal5( _Slot5 *pCb ) : pCb( pCb ) { } + Signal5( const Signal5 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal5() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4, p5 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal5 &operator=( const Signal5 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot5 *pCb; + }; + + template + Signal5 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal5( + new __Slot5( pCls, pFnc ) + ); + } + + template + Signal5 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal5( + new __Slot5F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_5 #ifndef BU_SIGNAL_PARAM_COUNT_6 #define BU_SIGNAL_PARAM_COUNT_6 - // - // 6 Parameter(s) - // - template - class _Slot6 - { - public: - _Slot6() { } - virtual ~_Slot6() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 )=0; - virtual _Slot6 *clone() const=0; - }; - - template - class __Slot6 : public _Slot6 - { - public: - __Slot6( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot6() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6 ); - } - - virtual _Slot6 *clone() const - { - return new __Slot6( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ); - }; - - template - class __Slot6F : public _Slot6 - { - public: - __Slot6F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot6F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 ) - { - return (*pFnc)( p1, p2, p3, p4, p5, p6 ); - } - - virtual _Slot6 *clone() const - { - return new __Slot6F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ); - }; - - template - class Signal6 - { - public: - Signal6() : pCb( NULL ) { } - Signal6( _Slot6 *pCb ) : pCb( pCb ) { } - Signal6( const Signal6 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal6() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4, p5, p6 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal6 &operator=( const Signal6 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot6 *pCb; - }; - - template - Signal6 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal6( - new __Slot6( pCls, pFnc ) - ); - } - - template - Signal6 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal6( - new __Slot6F( pFnc ) - ); - } + // + // 6 Parameter(s) + // + template + class _Slot6 + { + public: + _Slot6() { } + virtual ~_Slot6() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 )=0; + virtual _Slot6 *clone() const=0; + }; + + template + class __Slot6 : public _Slot6 + { + public: + __Slot6( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot6() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6 ); + } + + virtual _Slot6 *clone() const + { + return new __Slot6( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ); + }; + + template + class __Slot6F : public _Slot6 + { + public: + __Slot6F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot6F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 ) + { + return (*pFnc)( p1, p2, p3, p4, p5, p6 ); + } + + virtual _Slot6 *clone() const + { + return new __Slot6F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ); + }; + + template + class Signal6 + { + public: + Signal6() : pCb( NULL ) { } + Signal6( _Slot6 *pCb ) : pCb( pCb ) { } + Signal6( const Signal6 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal6() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4, p5, p6 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal6 &operator=( const Signal6 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot6 *pCb; + }; + + template + Signal6 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal6( + new __Slot6( pCls, pFnc ) + ); + } + + template + Signal6 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal6( + new __Slot6F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_6 #ifndef BU_SIGNAL_PARAM_COUNT_7 #define BU_SIGNAL_PARAM_COUNT_7 - // - // 7 Parameter(s) - // - template - class _Slot7 - { - public: - _Slot7() { } - virtual ~_Slot7() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 )=0; - virtual _Slot7 *clone() const=0; - }; - - template - class __Slot7 : public _Slot7 - { - public: - __Slot7( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot7() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7 ); - } - - virtual _Slot7 *clone() const - { - return new __Slot7( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ); - }; - - template - class __Slot7F : public _Slot7 - { - public: - __Slot7F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot7F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 ) - { - return (*pFnc)( p1, p2, p3, p4, p5, p6, p7 ); - } - - virtual _Slot7 *clone() const - { - return new __Slot7F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ); - }; - - template - class Signal7 - { - public: - Signal7() : pCb( NULL ) { } - Signal7( _Slot7 *pCb ) : pCb( pCb ) { } - Signal7( const Signal7 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal7() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4, p5, p6, p7 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal7 &operator=( const Signal7 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot7 *pCb; - }; - - template - Signal7 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal7( - new __Slot7( pCls, pFnc ) - ); - } - - template - Signal7 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal7( - new __Slot7F( pFnc ) - ); - } + // + // 7 Parameter(s) + // + template + class _Slot7 + { + public: + _Slot7() { } + virtual ~_Slot7() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 )=0; + virtual _Slot7 *clone() const=0; + }; + + template + class __Slot7 : public _Slot7 + { + public: + __Slot7( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot7() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7 ); + } + + virtual _Slot7 *clone() const + { + return new __Slot7( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ); + }; + + template + class __Slot7F : public _Slot7 + { + public: + __Slot7F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot7F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 ) + { + return (*pFnc)( p1, p2, p3, p4, p5, p6, p7 ); + } + + virtual _Slot7 *clone() const + { + return new __Slot7F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ); + }; + + template + class Signal7 + { + public: + Signal7() : pCb( NULL ) { } + Signal7( _Slot7 *pCb ) : pCb( pCb ) { } + Signal7( const Signal7 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal7() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4, p5, p6, p7 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal7 &operator=( const Signal7 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot7 *pCb; + }; + + template + Signal7 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal7( + new __Slot7( pCls, pFnc ) + ); + } + + template + Signal7 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal7( + new __Slot7F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_7 #ifndef BU_SIGNAL_PARAM_COUNT_8 #define BU_SIGNAL_PARAM_COUNT_8 - // - // 8 Parameter(s) - // - template - class _Slot8 - { - public: - _Slot8() { } - virtual ~_Slot8() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 )=0; - virtual _Slot8 *clone() const=0; - }; - - template - class __Slot8 : public _Slot8 - { - public: - __Slot8( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot8() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8 ); - } - - virtual _Slot8 *clone() const - { - return new __Slot8( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ); - }; - - template - class __Slot8F : public _Slot8 - { - public: - __Slot8F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot8F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 ) - { - return (*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8 ); - } - - virtual _Slot8 *clone() const - { - return new __Slot8F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ); - }; - - template - class Signal8 - { - public: - Signal8() : pCb( NULL ) { } - Signal8( _Slot8 *pCb ) : pCb( pCb ) { } - Signal8( const Signal8 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal8() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4, p5, p6, p7, p8 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal8 &operator=( const Signal8 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot8 *pCb; - }; - - template - Signal8 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal8( - new __Slot8( pCls, pFnc ) - ); - } - - template - Signal8 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal8( - new __Slot8F( pFnc ) - ); - } + // + // 8 Parameter(s) + // + template + class _Slot8 + { + public: + _Slot8() { } + virtual ~_Slot8() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 )=0; + virtual _Slot8 *clone() const=0; + }; + + template + class __Slot8 : public _Slot8 + { + public: + __Slot8( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot8() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8 ); + } + + virtual _Slot8 *clone() const + { + return new __Slot8( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ); + }; + + template + class __Slot8F : public _Slot8 + { + public: + __Slot8F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot8F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 ) + { + return (*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8 ); + } + + virtual _Slot8 *clone() const + { + return new __Slot8F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ); + }; + + template + class Signal8 + { + public: + Signal8() : pCb( NULL ) { } + Signal8( _Slot8 *pCb ) : pCb( pCb ) { } + Signal8( const Signal8 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal8() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4, p5, p6, p7, p8 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal8 &operator=( const Signal8 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot8 *pCb; + }; + + template + Signal8 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal8( + new __Slot8( pCls, pFnc ) + ); + } + + template + Signal8 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal8( + new __Slot8F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_8 #ifndef BU_SIGNAL_PARAM_COUNT_9 #define BU_SIGNAL_PARAM_COUNT_9 - // - // 9 Parameter(s) - // - template - class _Slot9 - { - public: - _Slot9() { } - virtual ~_Slot9() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 )=0; - virtual _Slot9 *clone() const=0; - }; - - template - class __Slot9 : public _Slot9 - { - public: - __Slot9( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot9() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); - } - - virtual _Slot9 *clone() const - { - return new __Slot9( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ); - }; - - template - class __Slot9F : public _Slot9 - { - public: - __Slot9F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot9F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 ) - { - return (*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); - } - - virtual _Slot9 *clone() const - { - return new __Slot9F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ); - }; - - template - class Signal9 - { - public: - Signal9() : pCb( NULL ) { } - Signal9( _Slot9 *pCb ) : pCb( pCb ) { } - Signal9( const Signal9 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal9() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal9 &operator=( const Signal9 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot9 *pCb; - }; - - template - Signal9 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal9( - new __Slot9( pCls, pFnc ) - ); - } - - template - Signal9 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal9( - new __Slot9F( pFnc ) - ); - } + // + // 9 Parameter(s) + // + template + class _Slot9 + { + public: + _Slot9() { } + virtual ~_Slot9() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 )=0; + virtual _Slot9 *clone() const=0; + }; + + template + class __Slot9 : public _Slot9 + { + public: + __Slot9( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot9() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); + } + + virtual _Slot9 *clone() const + { + return new __Slot9( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ); + }; + + template + class __Slot9F : public _Slot9 + { + public: + __Slot9F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot9F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 ) + { + return (*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); + } + + virtual _Slot9 *clone() const + { + return new __Slot9F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ); + }; + + template + class Signal9 + { + public: + Signal9() : pCb( NULL ) { } + Signal9( _Slot9 *pCb ) : pCb( pCb ) { } + Signal9( const Signal9 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal9() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal9 &operator=( const Signal9 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot9 *pCb; + }; + + template + Signal9 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal9( + new __Slot9( pCls, pFnc ) + ); + } + + template + Signal9 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal9( + new __Slot9F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_9 #ifndef BU_SIGNAL_PARAM_COUNT_10 #define BU_SIGNAL_PARAM_COUNT_10 - // - // 10 Parameter(s) - // - template - class _Slot10 - { - public: - _Slot10() { } - virtual ~_Slot10() { } - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 )=0; - virtual _Slot10 *clone() const=0; - }; - - template - class __Slot10 : public _Slot10 - { - public: - __Slot10( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) : - pCls( pCls ), pFnc( pFnc ) { } - virtual ~__Slot10() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 ) - { - return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); - } - - virtual _Slot10 *clone() const - { - return new __Slot10( pCls, pFnc ); - } - - private: - cls *pCls; - ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ); - }; - - template - class __Slot10F : public _Slot10 - { - public: - __Slot10F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) : - pFnc( pFnc ) { } - virtual ~__Slot10F() { } - - virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 ) - { - return (*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); - } - - virtual _Slot10 *clone() const - { - return new __Slot10F( pFnc ); - } - - private: - ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ); - }; - - template - class Signal10 - { - public: - Signal10() : pCb( NULL ) { } - Signal10( _Slot10 *pCb ) : pCb( pCb ) { } - Signal10( const Signal10 &rSrc ) : - pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } - virtual ~Signal10() { delete pCb; pCb = NULL; } - - ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 ) - { - if( !pCb ) throw SignalException("Uninitialized signal called."); - return (*pCb)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); - } - - bool isSet() const { return pCb != NULL; } - operator bool() const { return isSet(); } - - Signal10 &operator=( const Signal10 &rhs ) - { - pCb = rhs.pCb->clone(); - return *this; - } - - private: - _Slot10 *pCb; - }; - - template - Signal10 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) - { - if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal10( - new __Slot10( pCls, pFnc ) - ); - } - - template - Signal10 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) - { - if( !pFnc ) throw SignalException("NULL pointer in slot()."); - return Signal10( - new __Slot10F( pFnc ) - ); - } + // + // 10 Parameter(s) + // + template + class _Slot10 + { + public: + _Slot10() { } + virtual ~_Slot10() { } + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 )=0; + virtual _Slot10 *clone() const=0; + }; + + template + class __Slot10 : public _Slot10 + { + public: + __Slot10( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot10() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); + } + + virtual _Slot10 *clone() const + { + return new __Slot10( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ); + }; + + template + class __Slot10F : public _Slot10 + { + public: + __Slot10F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot10F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 ) + { + return (*pFnc)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); + } + + virtual _Slot10 *clone() const + { + return new __Slot10F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ); + }; + + template + class Signal10 + { + public: + Signal10() : pCb( NULL ) { } + Signal10( _Slot10 *pCb ) : pCb( pCb ) { } + Signal10( const Signal10 &rSrc ) : + pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } + virtual ~Signal10() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 ) + { + if( !pCb ) throw SignalException("Uninitialized signal called."); + return (*pCb)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); + } + + bool isSet() const { return pCb != NULL; } + operator bool() const { return isSet(); } + + Signal10 &operator=( const Signal10 &rhs ) + { + pCb = rhs.pCb->clone(); + return *this; + } + + private: + _Slot10 *pCb; + }; + + template + Signal10 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) + { + if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal10( + new __Slot10( pCls, pFnc ) + ); + } + + template + Signal10 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ) ) + { + if( !pFnc ) throw SignalException("NULL pointer in slot()."); + return Signal10( + new __Slot10F( pFnc ) + ); + } #endif // BU_SIGNAL_PARAM_COUNT_10 }; diff --git a/default.bld b/default.bld index 4c71725..265da03 100644 --- a/default.bld +++ b/default.bld @@ -16,17 +16,17 @@ if PREFIX == null then action "default" { - build: ["build", targets("plugins")]; + build: ["build", targets("plugins")]; } action "man" { - build: targets("all"); + build: targets("all"); } action "clean" { - clean: "build"; + clean: "build"; } action "docs" @@ -41,85 +41,85 @@ action "install" action "devinstall" { - if "$(id -u)" != "0" then - { - error "You can only install as the root user, su then run this."; - } - install: targets("devinstall"); + if "$(id -u)" != "0" then + { + error "You can only install as the root user, su then run this."; + } + install: targets("devinstall"); } action "viminstall" { - if "$(id -u)" != "0" then - { - error "You can only install as the root user, su then run this."; - } - install: targets("viminstall"); + if "$(id -u)" != "0" then + { + error "You can only install as the root user, su then run this."; + } + install: targets("viminstall"); } target "build" { - input [files("src/*.y"), files("src/*.l"), files("src/*.cpp")]; - rule "exe"; - LDFLAGS += "-Llibbu++ -lbu++ -ldl"; - CXXFLAGS += "-Ilibbu++"; - CFLAGS = CXXFLAGS; - tag "tools"; + input [files("src/*.y"), files("src/*.l"), files("src/*.cpp")]; + rule "exe"; + LDFLAGS += "-Llibbu++ -lbu++ -ldl"; + CXXFLAGS += "-Ilibbu++"; + CFLAGS = CXXFLAGS; + tag "tools"; } for IN in files("src/plugins/*.cpp") do { - target IN.replace("src/","").replace(".cpp", ".so") - { - input IN; - rule "so"; - LDFLAGS += "-Llibbu++ -lbu++ -ldl"; - CXXFLAGS += "-Ilibbu++ -Isrc"; - tag "plugins"; - } + target IN.replace("src/","").replace(".cpp", ".so") + { + input IN; + rule "so"; + LDFLAGS += "-Llibbu++ -lbu++ -ldl"; + CXXFLAGS += "-Ilibbu++ -Isrc"; + tag "plugins"; + } } target "/usr/share/build" { - input "$(echo -n $PWD)/share"; - tag "devinstall"; - display "symlink"; - profile "install" - { - execute("ln -fsv \"${INPUT}\" \"${OUTPUT}\""); - } + input "$(echo -n $PWD)/share"; + tag "devinstall"; + display "symlink"; + profile "install" + { + execute("ln -fsv \"${INPUT}\" \"${OUTPUT}\""); + } } target "/usr/lib/build" { - input "$(echo -n $PWD)/plugins"; - tag "devinstall"; - display "symlink"; - profile "install" - { - execute("ln -fsv \"${INPUT}\" \"${OUTPUT}\""); - } + input "$(echo -n $PWD)/plugins"; + tag "devinstall"; + display "symlink"; + profile "install" + { + execute("ln -fsv \"${INPUT}\" \"${OUTPUT}\""); + } } for vimdir in [dirs("/usr/share/vim/vim*"), dirs("/usr/local/share/vim/vim*")] do { - for ftype in ["ftplugin/build.vim", "ftdetect/build.vim", - "syntax/build.vim"] do - { - target vimdir + "/" + ftype - { - input "support/vim/" + ftype; - tag "viminstall"; - display "install"; - profile "install" - { - DIR = OUTPUT.dirName(); - execute("mkdir -p ${DIR}"); - execute("cp -f ${INPUT} ${OUTPUT}"); - } - } - } + for ftype in ["ftplugin/build.vim", "ftdetect/build.vim", + "syntax/build.vim"] do + { + target vimdir + "/" + ftype + { + input "support/vim/" + ftype; + tag "viminstall"; + display "install"; + profile "install" + { + DIR = OUTPUT.dirName(); + execute("mkdir -p ${DIR}"); + execute("cp -f ${INPUT} ${OUTPUT}"); + } + } + } } target PREFIX + "/bin/build" diff --git a/pkg.bld b/pkg.bld index 30c9668..0eb8c1f 100644 --- a/pkg.bld +++ b/pkg.bld @@ -17,33 +17,33 @@ PKG_BASE = "build-$(cat version)-r$(svnversion "-n").tar"; target PKG_BASE { - input [ - "Doxyfile", - files("*.bld"), - "docs/build.1", - "docs/build.7", + input [ + "Doxyfile", + files("*.bld"), + "docs/build.1", + "docs/build.7", files("docs/build-manual.*"), files("docs/html-multi/*"), files("docs/html-single/*"), "build.sh", "version", - "support/vim/syntax/build.vim", - "support/vim/ftdetect/build.vim", - "support/vim/ftplugin/build.vim", - files("src/*.y"), - files("src/*.l"), - files("src/*.c"), - files("src/*.cpp"), - files("src/*.h"), - files("share/autoinclude/*"), - files("share/include/*"), + "support/vim/syntax/build.vim", + "support/vim/ftdetect/build.vim", + "support/vim/ftplugin/build.vim", + files("src/*.y"), + files("src/*.l"), + files("src/*.c"), + files("src/*.cpp"), + files("src/*.h"), + files("share/autoinclude/*"), + files("share/include/*"), "minibu", - files("minibu/bu/*"), - files("minibu/src/*"), + files("minibu/bu/*"), + files("minibu/src/*"), files("bootstrap/*") - ]; - rule "tarball"; - tag "pkg"; + ]; + rule "tarball"; + tag "pkg"; } target PKG_BASE + ".gz" @@ -81,12 +81,12 @@ target PKG_BASE + ".xz" rule "tarball" { - input matches("*.cpp", "*.h", "*.c", "*.y", "*.l", "*.bld", "Doxyfile", - "*.1", "*.7", "*.vim", "*.sh", "version", "*.tex", "*.pdf", "*.html", + input matches("*.cpp", "*.h", "*.c", "*.y", "*.l", "*.bld", "Doxyfile", + "*.1", "*.7", "*.vim", "*.sh", "version", "*.tex", "*.pdf", "*.html", "*.css"); - profile "build" - { - OUTDIR = OUTPUT.replace(".tar",""); - execute("tar -f ./${OUTPUT} --transform=\"s@^@${OUTDIR}/@\" -c ${INPUT}"); - } + profile "build" + { + OUTDIR = OUTPUT.replace(".tar",""); + execute("tar -f ./${OUTPUT} --transform=\"s@^@${OUTDIR}/@\" -c ${INPUT}"); + } } diff --git a/share/autoinclude/general-rules.bld b/share/autoinclude/general-rules.bld index 6c0df30..0e4f0b4 100644 --- a/share/autoinclude/general-rules.bld +++ b/share/autoinclude/general-rules.bld @@ -6,151 +6,151 @@ if CXX == null then { - CXX = "g++"; + CXX = "g++"; } if AR == null then { - AR = "ar"; + AR = "ar"; } if CC == null then { - CC = "cc"; + CC = "cc"; } if BISON == null then { - BISON = "bison"; + BISON = "bison"; } if FLEX == null then { - FLEX = "flex"; + FLEX = "flex"; } function cppToObj() { - if OBJ_DIR == null then - { - return INPUT.regex("\\.cpp$", ".o"); - } - else - { - return OBJ_DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".o"); - } + if OBJ_DIR == null then + { + return INPUT.regex("\\.cpp$", ".o"); + } + else + { + return OBJ_DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".o"); + } } function cToObj() { - if OBJ_DIR == null then - { - return INPUT.regex("\\.c$", ".o"); - } - else - { - return OBJ_DIR + "/" + INPUT.fileName().regex("\\.c$", ".o"); - } + if OBJ_DIR == null then + { + return INPUT.regex("\\.c$", ".o"); + } + else + { + return OBJ_DIR + "/" + INPUT.fileName().regex("\\.c$", ".o"); + } } rule "exe" { - input "*.o"; - profile "build" - { - INPUT = [INPUT].unique().matches("*.o"); - execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); - } + input "*.o"; + profile "build" + { + INPUT = [INPUT].unique().matches("*.o"); + execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); + } } rule "so" { - input "*.o"; - profile "build" - { - INPUT = [INPUT].unique().matches("*.o"); - execute("${CXX} -shared -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); - } + input "*.o"; + profile "build" + { + INPUT = [INPUT].unique().matches("*.o"); + execute("${CXX} -shared -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); + } } rule "lib" { - input "*.o"; - profile "build" - { - INPUT = [INPUT].unique().matches("*.o"); - execute("${AR} cr ${OUTPUT} ${INPUT}"); - } + input "*.o"; + profile "build" + { + INPUT = [INPUT].unique().matches("*.o"); + execute("${AR} cr ${OUTPUT} ${INPUT}"); + } } rule "cpp" { - input "*.cpp"; - output INPUT.cppToObj(); - requires getMakeDeps("${CXX} ${CXXFLAGS} -M -MG ${INPUT}"); - profile "build" - { - execute("${CXX} ${CXXFLAGS} -c -o ${OUTPUT} ${INPUT}", "g++"); - } + input "*.cpp"; + output INPUT.cppToObj(); + requires getMakeDeps("${CXX} ${CXXFLAGS} -M -MG ${INPUT}"); + profile "build" + { + execute("${CXX} ${CXXFLAGS} -c -o ${OUTPUT} ${INPUT}", "g++"); + } } // Heh, we're not going to use this one. rule "c" { - input "*.c"; - output INPUT.cToObj(); - requires getMakeDeps("${CC} ${CFLAGS} -M -MG ${INPUT}"); - profile "build" - { - execute("${CC} ${CFLAGS} -c -o ${OUTPUT} ${INPUT}"); - } + input "*.c"; + output INPUT.cToObj(); + requires getMakeDeps("${CC} ${CFLAGS} -M -MG ${INPUT}"); + profile "build" + { + execute("${CC} ${CFLAGS} -c -o ${OUTPUT} ${INPUT}"); + } } rule "bison" { - input "*.y"; - output [INPUT.regex("\\.y$", ".tab.c"), INPUT.regex("\\.y$", ".tab.h")]; - profile "build" - { - BASE = INPUT.regex("\\.y", ""); - execute("${BISON} -b${BASE} ${BISONFLAGS} ${INPUT}"); - // if you add a -v bison will produce a .output file - } + input "*.y"; + output [INPUT.regex("\\.y$", ".tab.c"), INPUT.regex("\\.y$", ".tab.h")]; + profile "build" + { + BASE = INPUT.regex("\\.y", ""); + execute("${BISON} -b${BASE} ${BISONFLAGS} ${INPUT}"); + // if you add a -v bison will produce a .output file + } } rule "flex" { - input "*.l"; - output INPUT.regex("\\.l$", ".yy.c"); - output INPUT.regex("\\.l$", ".yy.h"); - profile "build" - { - execute("${FLEX} ${FLEXFLAGS} ${INPUT}"); - } + input "*.l"; + output INPUT.regex("\\.l$", ".yy.c"); + output INPUT.regex("\\.l$", ".yy.h"); + profile "build" + { + execute("${FLEX} ${FLEXFLAGS} ${INPUT}"); + } } rule "jar" { - input "*.class"; - profile "build" - { - if exists(OUTPUT) then - { - unlink(OUTPUT); - } - execute("jar cf ${OUTPUT} ${INPUT}"); - } + input "*.class"; + profile "build" + { + if exists(OUTPUT) then + { + unlink(OUTPUT); + } + execute("jar cf ${OUTPUT} ${INPUT}"); + } } rule "class" { - input "*.java"; - output INPUT.regex("\\.java", ".class"); - profile "build" - { - execute("javac -cp . ${INPUT}"); - } + input "*.java"; + output INPUT.regex("\\.java", ".class"); + profile "build" + { + execute("javac -cp . ${INPUT}"); + } } diff --git a/share/include/qt4.bld b/share/include/qt4.bld index ebf26d7..e1cfdd2 100644 --- a/share/include/qt4.bld +++ b/share/include/qt4.bld @@ -1,165 +1,165 @@ function qt_getCXXFLAGS() { - if QTDIR == null then - { - error "QTDIR is not set, cannot find QT tools."; - } + if QTDIR == null then + { + error "QTDIR is not set, cannot find QT tools."; + } - ret = "-D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LI " - "-DQT_SHARED -I${QTDIR}/mkspecs/linux-g++ " - "$(PKG_CONFIG_PATH=PKG_CONFIG_PATH:${QTDIR}/lib/pkgconfig " - "pkg-config --cflags QtCore QtGui ice glu x11 xext libpng freetype2 " - "gobject-2.0 sm xrender fontconfig gthread-2.0 glib-2.0)"; - if UI_DIR != null then - { - ret += "-I${UI_DIR}"; - } - if RCC_DIR != null then - { - ret += "-I${RCC_DIR}"; - } - if MOC_DIR != null then - { - ret += "-I${MOC_DIR}"; - } - return ret; + ret = "-D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LI " + "-DQT_SHARED -I${QTDIR}/mkspecs/linux-g++ " + "$(PKG_CONFIG_PATH=PKG_CONFIG_PATH:${QTDIR}/lib/pkgconfig " + "pkg-config --cflags QtCore QtGui ice glu x11 xext libpng freetype2 " + "gobject-2.0 sm xrender fontconfig gthread-2.0 glib-2.0)"; + if UI_DIR != null then + { + ret += "-I${UI_DIR}"; + } + if RCC_DIR != null then + { + ret += "-I${RCC_DIR}"; + } + if MOC_DIR != null then + { + ret += "-I${MOC_DIR}"; + } + return ret; } function qt_getLDFLAGS() { - if QTDIR == null then - { - error "QTDIR is not set, cannot find QT tools."; - } + if QTDIR == null then + { + error "QTDIR is not set, cannot find QT tools."; + } - return "-Wl,-rpath,${QTDIR}/lib $(PKG_CONFIG_PATH=" - "PKG_CONFIG_PATH:${QTDIR}/lib/pkgconfig " - "pkg-config --libs QtCore QtGui ice glu x11 xext libpng freetype2 " - "gobject-2.0 sm xrender fontconfig gthread-2.0 glib-2.0) -lz " - "-lm -ldl"; + return "-Wl,-rpath,${QTDIR}/lib $(PKG_CONFIG_PATH=" + "PKG_CONFIG_PATH:${QTDIR}/lib/pkgconfig " + "pkg-config --libs QtCore QtGui ice glu x11 xext libpng freetype2 " + "gobject-2.0 sm xrender fontconfig gthread-2.0 glib-2.0) -lz " + "-lm -ldl"; } function qt_getToolPath( TOOL, DEFAULT ) { - if QTDIR == null then - { - error "QTDIR is not set, cannot find QT tools."; - } - if TOOL == null then - { - return "${QTDIR}/bin/${DEFAULT}"; - } - return TOOL; + if QTDIR == null then + { + error "QTDIR is not set, cannot find QT tools."; + } + if TOOL == null then + { + return "${QTDIR}/bin/${DEFAULT}"; + } + return TOOL; } function qt_uiToH() { - if "${UI_DIR}" == "" then - { - DIR = INPUT.dirName(); - } - else - { - DIR = UI_DIR; - } - FILE = INPUT.fileName(); - OUTFILE = FILE.replace(".ui",".h"); - return "${DIR}/ui_${OUTFILE}"; + if "${UI_DIR}" == "" then + { + DIR = INPUT.dirName(); + } + else + { + DIR = UI_DIR; + } + FILE = INPUT.fileName(); + OUTFILE = FILE.replace(".ui",".h"); + return "${DIR}/ui_${OUTFILE}"; } rule "qt_ui" { - display "ui"; - input "*.ui"; - output INPUT.qt_uiToH(); - tag "headers"; - profile "build" - { - UIC = qt_getToolPath( UIC, "uic" ); - execute("${UIC} -o ${OUTPUT} ${INPUT}"); - } + display "ui"; + input "*.ui"; + output INPUT.qt_uiToH(); + tag "headers"; + profile "build" + { + UIC = qt_getToolPath( UIC, "uic" ); + execute("${UIC} -o ${OUTPUT} ${INPUT}"); + } } function qt_qrcToCpp() { - if "${RCC_DIR}" == "" then - { - DIR = INPUT.dirName(); - } - else - { - DIR = RCC_DIR; - } - FILE = INPUT.fileName(); - OUTFILE = FILE.replace(".qrc",".cpp"); - return "${DIR}/qrc_${OUTFILE}"; + if "${RCC_DIR}" == "" then + { + DIR = INPUT.dirName(); + } + else + { + DIR = RCC_DIR; + } + FILE = INPUT.fileName(); + OUTFILE = FILE.replace(".qrc",".cpp"); + return "${DIR}/qrc_${OUTFILE}"; } rule "qt_rcc" { - display "rcc"; - input "*.qrc"; - output INPUT.qt_qrcToCpp(); - profile "build" - { - RCC = qt_getToolPath( RCC, "rcc" ); - NAME = INPUT.fileName().replace(".qrc",""); - execute("${RCC} -name ${NAME} -o ${OUTPUT} ${INPUT}"); - } + display "rcc"; + input "*.qrc"; + output INPUT.qt_qrcToCpp(); + profile "build" + { + RCC = qt_getToolPath( RCC, "rcc" ); + NAME = INPUT.fileName().replace(".qrc",""); + execute("${RCC} -name ${NAME} -o ${OUTPUT} ${INPUT}"); + } } function qt_isMocable() { - if INPUT.matches("*.h") then - { - if exists( INPUT ) then - { - if "$(grep Q_OBJECT ${INPUT})" != "" then - { - return true; - } - } - } - return false; + if INPUT.matches("*.h") then + { + if exists( INPUT ) then + { + if "$(grep Q_OBJECT ${INPUT})" != "" then + { + return true; + } + } + } + return false; } function qt_hToMocCpp() { - if "${MOC_DIR}" == "" then - { - DIR = INPUT.dirName(); - } - else - { - DIR = MOC_DIR; - } - FILE = INPUT.fileName(); - OUTFILE = FILE.replace(".h",".cpp"); - return "${DIR}/moc_${OUTFILE}"; + if "${MOC_DIR}" == "" then + { + DIR = INPUT.dirName(); + } + else + { + DIR = MOC_DIR; + } + FILE = INPUT.fileName(); + OUTFILE = FILE.replace(".h",".cpp"); + return "${DIR}/moc_${OUTFILE}"; } rule "qt_moc" { - display "moc"; - input qt_isMocable(); - output INPUT.qt_hToMocCpp(); - profile "build" - { - MOC = qt_getToolPath( MOC, "moc" ); - execute("${MOC} -o${OUTPUT} ${INPUT}"); - } + display "moc"; + input qt_isMocable(); + output INPUT.qt_hToMocCpp(); + profile "build" + { + MOC = qt_getToolPath( MOC, "moc" ); + execute("${MOC} -o${OUTPUT} ${INPUT}"); + } } rule "exe" { - input regex(".*\\.(h|o)"); - profile "build" - { - INPUT = [INPUT].matches("*.o"); -// execute("echo ${INPUT}"); -// execute("echo ${MYIN}"); - execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); - } + input regex(".*\\.(h|o)"); + profile "build" + { + INPUT = [INPUT].matches("*.o"); +// execute("echo ${INPUT}"); +// execute("echo ${MYIN}"); + execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); + } } diff --git a/src/action.cpp b/src/action.cpp index 1a2b8b1..e06fb45 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -6,127 +6,127 @@ #include "variable.h" Action::Action( const class AstBranch *pRoot ) : - pRoot( pRoot ), - pAst( NULL ) + pRoot( pRoot ), + pAst( NULL ) { - sName = dynamic_cast( - *(*pRoot->getBranchBegin()).begin() - )->getStrValue(); + sName = dynamic_cast( + *(*pRoot->getBranchBegin()).begin() + )->getStrValue(); } Action::~Action() { - delete pAst; - pAst = NULL; + delete pAst; + pAst = NULL; } const Bu::String &Action::getName() const { - return sName; + return sName; } void Action::call( class Runner *pRunner ) { - pRunner->run( (*(pRoot->getBranchBegin()+1)).begin() ); + pRunner->run( (*(pRoot->getBranchBegin()+1)).begin() ); } Action *Action::genDefaultAll() { - Ast *pAst = new Ast(); - pAst->addNode( AstNode::typeActionDef ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "all" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeProcessTarget ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "build" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeFunction ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "targets" ); - pAst->closeNode(); - pAst->closeNode(); - pAst->closeNode(); - Action *pRet = new Action( - dynamic_cast( *pAst->getNodeBegin() ) - ); - pRet->pAst = pAst; + Ast *pAst = new Ast(); + pAst->addNode( AstNode::typeActionDef ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "all" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeProcessTarget ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "build" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeFunction ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "targets" ); + pAst->closeNode(); + pAst->closeNode(); + pAst->closeNode(); + Action *pRet = new Action( + dynamic_cast( *pAst->getNodeBegin() ) + ); + pRet->pAst = pAst; - return pRet; + return pRet; } Action *Action::genDefaultClean() { - Ast *pAst = new Ast(); - pAst->addNode( AstNode::typeActionDef ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "clean" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeProcessTarget ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "clean" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeFunction ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "targets" ); - pAst->closeNode(); - pAst->closeNode(); - pAst->closeNode(); - Action *pRet = new Action( - dynamic_cast( *pAst->getNodeBegin() ) - ); - pRet->pAst = pAst; + Ast *pAst = new Ast(); + pAst->addNode( AstNode::typeActionDef ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "clean" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeProcessTarget ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "clean" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeFunction ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "targets" ); + pAst->closeNode(); + pAst->closeNode(); + pAst->closeNode(); + Action *pRet = new Action( + dynamic_cast( *pAst->getNodeBegin() ) + ); + pRet->pAst = pAst; - return pRet; + return pRet; } Action *Action::genDefaultCleanAll() { - Ast *pAst = new Ast(); - pAst->addNode( AstNode::typeActionDef ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "clean-all" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeProcessTarget ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "clean" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeFunction ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "targets" ); - pAst->closeNode(); - pAst->closeNode(); - pAst->closeNode(); - Action *pRet = new Action( - dynamic_cast( *pAst->getNodeBegin() ) - ); - pRet->pAst = pAst; + Ast *pAst = new Ast(); + pAst->addNode( AstNode::typeActionDef ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "clean-all" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeProcessTarget ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "clean" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeFunction ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "targets" ); + pAst->closeNode(); + pAst->closeNode(); + pAst->closeNode(); + Action *pRet = new Action( + dynamic_cast( *pAst->getNodeBegin() ) + ); + pRet->pAst = pAst; - return pRet; + return pRet; } Action *Action::genDefaultDefault() { - Ast *pAst = new Ast(); - pAst->addNode( AstNode::typeActionDef ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "default" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeProcessTarget ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "build" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeFunction ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "targets" ); - pAst->closeNode(); - pAst->closeNode(); - pAst->closeNode(); - Action *pRet = new Action( - dynamic_cast( *pAst->getNodeBegin() ) - ); - pRet->pAst = pAst; + Ast *pAst = new Ast(); + pAst->addNode( AstNode::typeActionDef ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "default" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeProcessTarget ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "build" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeFunction ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "targets" ); + pAst->closeNode(); + pAst->closeNode(); + pAst->closeNode(); + Action *pRet = new Action( + dynamic_cast( *pAst->getNodeBegin() ) + ); + pRet->pAst = pAst; - return pRet; + return pRet; } diff --git a/src/action.h b/src/action.h index de08911..0808fdb 100644 --- a/src/action.h +++ b/src/action.h @@ -6,22 +6,22 @@ class Action { public: - Action( const class AstBranch *pRoot ); - virtual ~Action(); + Action( const class AstBranch *pRoot ); + virtual ~Action(); - const Bu::String &getName() const; + const Bu::String &getName() const; - void call( class Runner *pRunner ); + void call( class Runner *pRunner ); - static Action *genDefaultAll(); - static Action *genDefaultClean(); - static Action *genDefaultCleanAll(); - static Action *genDefaultDefault(); + static Action *genDefaultAll(); + static Action *genDefaultClean(); + static Action *genDefaultCleanAll(); + static Action *genDefaultDefault(); private: - Bu::String sName; - const class AstBranch *pRoot; - class Ast *pAst; + Bu::String sName; + const class AstBranch *pRoot; + class Ast *pAst; }; #endif diff --git a/src/ast.cpp b/src/ast.cpp index 005372b..6c03607 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -15,122 +15,122 @@ Ast::~Ast() void Ast::addNode( YYLTYPE &loc, AstNode::Type eType ) { - switch( eType&AstNode::typeClassMask ) - { - case AstNode::typeBranch: - { - AstBranch *pNode = new AstBranch( loc, eType ); - addNode( pNode ); - sBranch.push( pNode ); - } - break; - - case AstNode::typeLeaf: - { - AstLeaf *pNode = new AstLeaf( loc, eType ); - addNode( pNode ); - } - break; - - default: - throw Bu::ExceptionBase("You got it wrong."); - break; - } + switch( eType&AstNode::typeClassMask ) + { + case AstNode::typeBranch: + { + AstBranch *pNode = new AstBranch( loc, eType ); + addNode( pNode ); + sBranch.push( pNode ); + } + break; + + case AstNode::typeLeaf: + { + AstLeaf *pNode = new AstLeaf( loc, eType ); + addNode( pNode ); + } + break; + + default: + throw Bu::ExceptionBase("You got it wrong."); + break; + } } void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, int iVal ) { - addNode( new AstLeaf( loc, eType, iVal ) ); + addNode( new AstLeaf( loc, eType, iVal ) ); } void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, float fVal ) { - addNode( new AstLeaf( loc, eType, fVal ) ); + addNode( new AstLeaf( loc, eType, fVal ) ); } void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, bool bVal ) { - addNode( new AstLeaf( loc, eType, bVal ) ); + addNode( new AstLeaf( loc, eType, bVal ) ); } void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const Bu::String &sVal ) { - addNode( new AstLeaf( loc, eType, sVal ) ); + addNode( new AstLeaf( loc, eType, sVal ) ); } void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const char *sVal ) { - addNode( new AstLeaf( loc, eType, sVal ) ); + addNode( new AstLeaf( loc, eType, sVal ) ); } void Ast::addNode( AstNode::Type eType ) { - YYLTYPE none = {-1, -1, -1, -1}; - addNode( none, eType ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType ); } void Ast::addNode( AstNode::Type eType, int iVal ) { - YYLTYPE none = {-1, -1, -1, -1}; - addNode( none, eType, iVal ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, iVal ); } void Ast::addNode( AstNode::Type eType, float fVal ) { - YYLTYPE none = {-1, -1, -1, -1}; - addNode( none, eType, fVal ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, fVal ); } void Ast::addNode( AstNode::Type eType, bool bVal ) { - YYLTYPE none = {-1, -1, -1, -1}; - addNode( none, eType, bVal ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, bVal ); } void Ast::addNode( AstNode::Type eType, const Bu::String &sVal ) { - YYLTYPE none = {-1, -1, -1, -1}; - addNode( none, eType, sVal ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, sVal ); } void Ast::addNode( AstNode::Type eType, const char *sVal ) { - YYLTYPE none = {-1, -1, -1, -1}; - addNode( none, eType, sVal ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, sVal ); } void Ast::addNode( AstNode *pNode ) { - if( sBranch.isEmpty() ) - lNode.append( pNode ); - else - sBranch.peek()->addNode( pNode ); + if( sBranch.isEmpty() ) + lNode.append( pNode ); + else + sBranch.peek()->addNode( pNode ); } void Ast::openBranch() { - sBranch.peek()->addBranch(); + sBranch.peek()->addBranch(); } void Ast::closeNode() { - sBranch.pop(); + sBranch.pop(); } Ast::NodeList::const_iterator Ast::getNodeBegin() const { - return lNode.begin(); + return lNode.begin(); } Bu::Formatter &operator<<( Bu::Formatter &f, const Ast &a ) { - f << "Abstract Syntax Tree:"; - f.incIndent(); - f << f.nl; - for( Ast::NodeList::const_iterator i = a.getNodeBegin(); i; i++ ) - f << **i << f.nl; - f << f.nl; - f.decIndent(); - return f; + f << "Abstract Syntax Tree:"; + f.incIndent(); + f << f.nl; + for( Ast::NodeList::const_iterator i = a.getNodeBegin(); i; i++ ) + f << **i << f.nl; + f << f.nl; + f.decIndent(); + return f; } diff --git a/src/ast.h b/src/ast.h index 3cc7206..b859064 100644 --- a/src/ast.h +++ b/src/ast.h @@ -15,36 +15,36 @@ class Ast { public: - typedef Bu::List NodeList; - Ast(); - virtual ~Ast(); + typedef Bu::List NodeList; + Ast(); + virtual ~Ast(); - void addNode( struct YYLTYPE &loc, AstNode::Type eType ); - void addNode( struct YYLTYPE &loc, AstNode::Type eType, int iVal ); - void addNode( struct YYLTYPE &loc, AstNode::Type eType, float fVal ); - void addNode( struct YYLTYPE &loc, AstNode::Type eType, bool bVal ); - void addNode( struct YYLTYPE &loc, AstNode::Type eType, - const Bu::String &sVal ); - void addNode( struct YYLTYPE &loc, AstNode::Type eType, const char *sVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, int iVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, float fVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, bool bVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, + const Bu::String &sVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, const char *sVal ); - void addNode( AstNode::Type eType ); - void addNode( AstNode::Type eType, int iVal ); - void addNode( AstNode::Type eType, float fVal ); - void addNode( AstNode::Type eType, bool bVal ); - void addNode( AstNode::Type eType, const Bu::String &sVal ); - void addNode( AstNode::Type eType, const char *sVal ); - void addNode( AstNode *pNode ); + void addNode( AstNode::Type eType ); + void addNode( AstNode::Type eType, int iVal ); + void addNode( AstNode::Type eType, float fVal ); + void addNode( AstNode::Type eType, bool bVal ); + void addNode( AstNode::Type eType, const Bu::String &sVal ); + void addNode( AstNode::Type eType, const char *sVal ); + void addNode( AstNode *pNode ); - void openBranch(); + void openBranch(); - void closeNode(); + void closeNode(); - NodeList::const_iterator getNodeBegin() const; + NodeList::const_iterator getNodeBegin() const; private: - NodeList lNode; - typedef Bu::Stack BranchStack; - BranchStack sBranch; + NodeList lNode; + typedef Bu::Stack BranchStack; + BranchStack sBranch; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Ast &a ); diff --git a/src/astbranch.cpp b/src/astbranch.cpp index d247b30..83ecdd7 100644 --- a/src/astbranch.cpp +++ b/src/astbranch.cpp @@ -1,7 +1,7 @@ #include "astbranch.h" AstBranch::AstBranch( const Location &loc, Type eType ) : - AstNode( loc, eType ) + AstNode( loc, eType ) { } @@ -11,34 +11,34 @@ AstBranch::~AstBranch() void AstBranch::addBranch() { - lBranch.append( NodeList() ); + lBranch.append( NodeList() ); } void AstBranch::addNode( AstNode *pNode ) { - lBranch.last().append( pNode ); + lBranch.last().append( pNode ); } AstBranch::BranchList::const_iterator AstBranch::getBranchBegin() const { - return lBranch.begin(); + return lBranch.begin(); } Bu::Formatter &operator<<( Bu::Formatter &f, const AstBranch &l ) { - f.incIndent(); - f << ":"; - for( AstBranch::BranchList::const_iterator i = l.getBranchBegin(); i; i++ ) - { - f << f.nl << "Branch:"; - f.incIndent(); - for( AstBranch::NodeList::const_iterator j = i->begin(); j; j++ ) - { - f << f.nl << **j; - } - f.decIndent(); - } - f.decIndent(); - return f; + f.incIndent(); + f << ":"; + for( AstBranch::BranchList::const_iterator i = l.getBranchBegin(); i; i++ ) + { + f << f.nl << "Branch:"; + f.incIndent(); + for( AstBranch::NodeList::const_iterator j = i->begin(); j; j++ ) + { + f << f.nl << **j; + } + f.decIndent(); + } + f.decIndent(); + return f; } diff --git a/src/astbranch.h b/src/astbranch.h index b582b9f..8140d3c 100644 --- a/src/astbranch.h +++ b/src/astbranch.h @@ -8,18 +8,18 @@ class AstBranch : public AstNode { public: - typedef Bu::List NodeList; - typedef Bu::List BranchList; - AstBranch( const Location &loc, Type eType ); - virtual ~AstBranch(); + typedef Bu::List NodeList; + typedef Bu::List BranchList; + AstBranch( const Location &loc, Type eType ); + virtual ~AstBranch(); - void addBranch(); - void addNode( AstNode *pNode ); + void addBranch(); + void addNode( AstNode *pNode ); - BranchList::const_iterator getBranchBegin() const; + BranchList::const_iterator getBranchBegin() const; private: - BranchList lBranch; + BranchList lBranch; }; Bu::Formatter &operator<<( Bu::Formatter &f, const AstBranch &l ); diff --git a/src/astleaf.cpp b/src/astleaf.cpp index c192dbf..f9ede90 100644 --- a/src/astleaf.cpp +++ b/src/astleaf.cpp @@ -1,137 +1,137 @@ #include "astleaf.h" AstLeaf::AstLeaf( const Location &loc, Type eType ) : - AstNode( loc, eType ), - sVal( NULL ) + AstNode( loc, eType ), + sVal( NULL ) { } AstLeaf::AstLeaf( const Location &loc, Type eType, int iNew ) : - AstNode( loc, eType ), - sVal( NULL ) + AstNode( loc, eType ), + sVal( NULL ) { - setIntValue( iNew ); + setIntValue( iNew ); } AstLeaf::AstLeaf( const Location &loc, Type eType, float fNew ) : - AstNode( loc, eType ), - sVal( NULL ) + AstNode( loc, eType ), + sVal( NULL ) { - setFloatValue( fNew ); + setFloatValue( fNew ); } AstLeaf::AstLeaf( const Location &loc, Type eType, bool bNew ) : - AstNode( loc, eType ), - sVal( NULL ) + AstNode( loc, eType ), + sVal( NULL ) { - setBoolValue( bNew ); + setBoolValue( bNew ); } AstLeaf::AstLeaf( const Location &loc, Type eType, const Bu::String &sNew ) : - AstNode( loc, eType ), - sVal( NULL ) + AstNode( loc, eType ), + sVal( NULL ) { - setStrValue( sNew ); + setStrValue( sNew ); } AstLeaf::AstLeaf( const Location &loc, Type eType, const char *sNew ) : - AstNode( loc, eType ), - sVal( NULL ) + AstNode( loc, eType ), + sVal( NULL ) { - setStrValue( sNew ); + setStrValue( sNew ); } AstLeaf::~AstLeaf() { - if( getDataType() == typeDataString ) - delete sVal; + if( getDataType() == typeDataString ) + delete sVal; } void AstLeaf::setIntValue( int iNew ) { - if( getDataType() != typeDataInt ) - throw Bu::ExceptionBase("Type is not int."); - iVal = iNew; + if( getDataType() != typeDataInt ) + throw Bu::ExceptionBase("Type is not int."); + iVal = iNew; } void AstLeaf::setFloatValue( float fNew ) { - if( getDataType() != typeDataFloat ) - throw Bu::ExceptionBase("Type is not float."); - fVal = fNew; + if( getDataType() != typeDataFloat ) + throw Bu::ExceptionBase("Type is not float."); + fVal = fNew; } void AstLeaf::setBoolValue( bool bNew ) { - if( getDataType() != typeDataBool ) - throw Bu::ExceptionBase("Type is not bool."); - bVal = bNew; + if( getDataType() != typeDataBool ) + throw Bu::ExceptionBase("Type is not bool."); + bVal = bNew; } void AstLeaf::setStrValue( const Bu::String &sNew ) { - if( getDataType() != typeDataString ) - throw Bu::ExceptionBase("Type is not string."); - if( sVal == NULL ) - sVal = new Bu::String( sNew ); - else - *sVal = sNew; + if( getDataType() != typeDataString ) + throw Bu::ExceptionBase("Type is not string."); + if( sVal == NULL ) + sVal = new Bu::String( sNew ); + else + *sVal = sNew; } int AstLeaf::getIntValue() const { - if( getDataType() != typeDataInt ) - throw Bu::ExceptionBase("Type is not int."); - return iVal; + if( getDataType() != typeDataInt ) + throw Bu::ExceptionBase("Type is not int."); + return iVal; } float AstLeaf::getFloatValue() const { - if( getDataType() != typeDataFloat ) - throw Bu::ExceptionBase("Type is not float."); - return fVal; + if( getDataType() != typeDataFloat ) + throw Bu::ExceptionBase("Type is not float."); + return fVal; } bool AstLeaf::getBoolValue() const { - if( getDataType() != typeDataBool ) - throw Bu::ExceptionBase("Type is not bool."); - return bVal; + if( getDataType() != typeDataBool ) + throw Bu::ExceptionBase("Type is not bool."); + return bVal; } Bu::String &AstLeaf::getStrValue() const { - if( getDataType() != typeDataString ) - throw Bu::ExceptionBase("Type is not string."); - return *sVal; + if( getDataType() != typeDataString ) + throw Bu::ExceptionBase("Type is not string."); + return *sVal; } Bu::Formatter &operator<<( Bu::Formatter &f, const AstLeaf &l ) { - switch( l.getDataType() ) - { - case AstNode::typeDataInt: - f << ": " << l.getIntValue(); - break; + switch( l.getDataType() ) + { + case AstNode::typeDataInt: + f << ": " << l.getIntValue(); + break; - case AstNode::typeDataFloat: - f << ": " << l.getFloatValue(); - break; + case AstNode::typeDataFloat: + f << ": " << l.getFloatValue(); + break; - case AstNode::typeDataBool: - f << ": " << l.getBoolValue(); - break; + case AstNode::typeDataBool: + f << ": " << l.getBoolValue(); + break; - case AstNode::typeDataString: - f << ": '" << l.getStrValue() << "'"; - break; + case AstNode::typeDataString: + f << ": '" << l.getStrValue() << "'"; + break; - case AstNode::typeDataNone: - break; + case AstNode::typeDataNone: + break; - default: - f << ": " << "!! Invalid Type !!"; - } - return f; + default: + f << ": " << "!! Invalid Type !!"; + } + return f; } diff --git a/src/astleaf.h b/src/astleaf.h index 85293f1..f78e593 100644 --- a/src/astleaf.h +++ b/src/astleaf.h @@ -8,32 +8,32 @@ class AstLeaf : public AstNode { public: - AstLeaf( const Location &loc, Type eType ); - AstLeaf( const Location &loc, Type eType, int iNew ); - AstLeaf( const Location &loc, Type eType, float fNew ); - AstLeaf( const Location &loc, Type eType, bool bNew ); - AstLeaf( const Location &loc, Type eType, const Bu::String &sNew ); - AstLeaf( const Location &loc, Type eType, const char *sNew ); - virtual ~AstLeaf(); + AstLeaf( const Location &loc, Type eType ); + AstLeaf( const Location &loc, Type eType, int iNew ); + AstLeaf( const Location &loc, Type eType, float fNew ); + AstLeaf( const Location &loc, Type eType, bool bNew ); + AstLeaf( const Location &loc, Type eType, const Bu::String &sNew ); + AstLeaf( const Location &loc, Type eType, const char *sNew ); + virtual ~AstLeaf(); - void setIntValue( int iNew ); - void setFloatValue( float fNew ); - void setBoolValue( bool bNew ); - void setStrValue( const Bu::String &sNew ); + void setIntValue( int iNew ); + void setFloatValue( float fNew ); + void setBoolValue( bool bNew ); + void setStrValue( const Bu::String &sNew ); - int getIntValue() const; - float getFloatValue() const; - bool getBoolValue() const; - Bu::String &getStrValue() const; + int getIntValue() const; + float getFloatValue() const; + bool getBoolValue() const; + Bu::String &getStrValue() const; private: - union - { - int iVal; - float fVal; - bool bVal; - Bu::String *sVal; - }; + union + { + int iVal; + float fVal; + bool bVal; + Bu::String *sVal; + }; }; Bu::Formatter &operator<<( Bu::Formatter &f, const AstLeaf &l ); diff --git a/src/astnode.cpp b/src/astnode.cpp index 87b9383..1e86bdd 100644 --- a/src/astnode.cpp +++ b/src/astnode.cpp @@ -3,8 +3,8 @@ #include "astbranch.h" AstNode::AstNode( const Location &loc, Type eType ) : - eType( eType ), - loc( loc ) + eType( eType ), + loc( loc ) { } @@ -14,101 +14,101 @@ AstNode::~AstNode() Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode &n ) { - f << n.getType(); - if( n.getClass() == AstNode::typeBranch ) - { - f << *dynamic_cast(&n); - } - else - { - f << *dynamic_cast(&n); - } - return f; + f << n.getType(); + if( n.getClass() == AstNode::typeBranch ) + { + f << *dynamic_cast(&n); + } + else + { + f << *dynamic_cast(&n); + } + return f; } Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode::Type &t ) { - switch( t ) - { - case AstNode::typeFunction: f << "Function"; break; - case AstNode::typeSet: f << "Set"; break; - case AstNode::typeUnset: f << "Unset"; break; - case AstNode::typeIf: f << "If"; break; - case AstNode::typeInclude: f << "Include"; break; - case AstNode::typeTarget: f << "Target"; break; - case AstNode::typeRule: f << "Rule"; break; - case AstNode::typeConfig: f << "Config"; break; - case AstNode::typeList: f << "List"; break; - case AstNode::typeInlineFunc: f << "InlineFunc"; break; - case AstNode::typeRequires: f << "Requires"; break; - case AstNode::typeFor: f << "For"; break; - case AstNode::typeFunctionDef: f << "FunctionDef"; break; - case AstNode::typeReturn: f << "Return"; break; - case AstNode::typeProfile: f << "Profile"; break; - case AstNode::typeInput: f << "Input"; break; - case AstNode::typeRuleDef: f << "RuleDef"; break; - case AstNode::typeOutput: f << "Output"; break; - case AstNode::typeAutoConfig: f << "AutoConfig"; break; - case AstNode::typeGlobalConfig: f << "GlobalConfig"; break; - case AstNode::typeType: f << "Type"; break; - case AstNode::typeValue: f << "Value"; break; - case AstNode::typeAllow: f << "Allow"; break; - case AstNode::typeDefault: f << "Default"; break; - case AstNode::typeExport: f << "Export"; break; - case AstNode::typeExpr: f << "Expr"; break; - case AstNode::typeActionDef: f << "ActionDef"; break; - case AstNode::typeProcessTarget:f << "ProcessTarget"; break; - case AstNode::typeTag: f << "Tag"; break; - - case AstNode::typeVariable: f << "Variable"; break; - case AstNode::typeString: f << "String"; break; - case AstNode::typeInt: f << "Int"; break; - case AstNode::typeFloat: f << "Float"; break; - case AstNode::typeBool: f << "Bool"; break; - case AstNode::typeVersion: f << "Version"; break; - case AstNode::typeOpEq: f << "Operator ="; break; - case AstNode::typeOpPlusEq: f << "Operator +="; break; - case AstNode::typeOpPlusEqRaw: f << "Operator <<"; break; - case AstNode::typeError: f << "Error"; break; - case AstNode::typeWarning: f << "Warning"; break; - case AstNode::typeNotice: f << "Notice"; break; - case AstNode::typeTypeString: f << "Type String"; break; - case AstNode::typeTypeInt: f << "Type Int"; break; - case AstNode::typeTypeFloat: f << "Type Float"; break; - case AstNode::typeTypeBool: f << "Type Bool"; break; - case AstNode::typeTypeVersion: f << "Type Version"; break; - case AstNode::typeCmpEq: f << "Compare ="; break; - case AstNode::typeCmpLt: f << "Compare <"; break; - case AstNode::typeCmpGt: f << "Compare >"; break; - case AstNode::typeCmpNe: f << "Compare !="; break; - case AstNode::typeCmpLtEq: f << "Compare <="; break; - case AstNode::typeCmpGtEq: f << "Compare >="; break; - case AstNode::typeCondition: f << "Condition"; break; - case AstNode::typeDisplay: f << "Display"; break; - case AstNode::typeCache: f << "Cache"; break; - case AstNode::typePushPrefix: f << "Push Prefix"; break; - case AstNode::typePopPrefix: f << "Pop Prefix"; break; - case AstNode::typeNull: f << "Null"; break; - case AstNode::typeVariableRef: f << "VariableRef"; break; - case AstNode::typeOpPlus: f << "Operator +"; break; - case AstNode::typeOpMinus: f << "Operator -"; break; - case AstNode::typeOpMultiply: f << "Operator *"; break; - case AstNode::typeOpDivide: f << "Operator /"; break; - case AstNode::typeOpNegate: f << "Operator negate"; break; - case AstNode::typeOpNot: f << "Operator not"; break; + switch( t ) + { + case AstNode::typeFunction: f << "Function"; break; + case AstNode::typeSet: f << "Set"; break; + case AstNode::typeUnset: f << "Unset"; break; + case AstNode::typeIf: f << "If"; break; + case AstNode::typeInclude: f << "Include"; break; + case AstNode::typeTarget: f << "Target"; break; + case AstNode::typeRule: f << "Rule"; break; + case AstNode::typeConfig: f << "Config"; break; + case AstNode::typeList: f << "List"; break; + case AstNode::typeInlineFunc: f << "InlineFunc"; break; + case AstNode::typeRequires: f << "Requires"; break; + case AstNode::typeFor: f << "For"; break; + case AstNode::typeFunctionDef: f << "FunctionDef"; break; + case AstNode::typeReturn: f << "Return"; break; + case AstNode::typeProfile: f << "Profile"; break; + case AstNode::typeInput: f << "Input"; break; + case AstNode::typeRuleDef: f << "RuleDef"; break; + case AstNode::typeOutput: f << "Output"; break; + case AstNode::typeAutoConfig: f << "AutoConfig"; break; + case AstNode::typeGlobalConfig: f << "GlobalConfig"; break; + case AstNode::typeType: f << "Type"; break; + case AstNode::typeValue: f << "Value"; break; + case AstNode::typeAllow: f << "Allow"; break; + case AstNode::typeDefault: f << "Default"; break; + case AstNode::typeExport: f << "Export"; break; + case AstNode::typeExpr: f << "Expr"; break; + case AstNode::typeActionDef: f << "ActionDef"; break; + case AstNode::typeProcessTarget:f << "ProcessTarget"; break; + case AstNode::typeTag: f << "Tag"; break; + + case AstNode::typeVariable: f << "Variable"; break; + case AstNode::typeString: f << "String"; break; + case AstNode::typeInt: f << "Int"; break; + case AstNode::typeFloat: f << "Float"; break; + case AstNode::typeBool: f << "Bool"; break; + case AstNode::typeVersion: f << "Version"; break; + case AstNode::typeOpEq: f << "Operator ="; break; + case AstNode::typeOpPlusEq: f << "Operator +="; break; + case AstNode::typeOpPlusEqRaw: f << "Operator <<"; break; + case AstNode::typeError: f << "Error"; break; + case AstNode::typeWarning: f << "Warning"; break; + case AstNode::typeNotice: f << "Notice"; break; + case AstNode::typeTypeString: f << "Type String"; break; + case AstNode::typeTypeInt: f << "Type Int"; break; + case AstNode::typeTypeFloat: f << "Type Float"; break; + case AstNode::typeTypeBool: f << "Type Bool"; break; + case AstNode::typeTypeVersion: f << "Type Version"; break; + case AstNode::typeCmpEq: f << "Compare ="; break; + case AstNode::typeCmpLt: f << "Compare <"; break; + case AstNode::typeCmpGt: f << "Compare >"; break; + case AstNode::typeCmpNe: f << "Compare !="; break; + case AstNode::typeCmpLtEq: f << "Compare <="; break; + case AstNode::typeCmpGtEq: f << "Compare >="; break; + case AstNode::typeCondition: f << "Condition"; break; + case AstNode::typeDisplay: f << "Display"; break; + case AstNode::typeCache: f << "Cache"; break; + case AstNode::typePushPrefix: f << "Push Prefix"; break; + case AstNode::typePopPrefix: f << "Pop Prefix"; break; + case AstNode::typeNull: f << "Null"; break; + case AstNode::typeVariableRef: f << "VariableRef"; break; + case AstNode::typeOpPlus: f << "Operator +"; break; + case AstNode::typeOpMinus: f << "Operator -"; break; + case AstNode::typeOpMultiply: f << "Operator *"; break; + case AstNode::typeOpDivide: f << "Operator /"; break; + case AstNode::typeOpNegate: f << "Operator negate"; break; + case AstNode::typeOpNot: f << "Operator not"; break; - case AstNode::typeBranch: f << "Branch"; break; - case AstNode::typeLeaf: f << "Leaf"; break; - case AstNode::typeClassMask: f << "ClassMask"; break; + case AstNode::typeBranch: f << "Branch"; break; + case AstNode::typeLeaf: f << "Leaf"; break; + case AstNode::typeClassMask: f << "ClassMask"; break; - case AstNode::typeDataNone: f << ""; break; - case AstNode::typeDataString: f << ""; break; - case AstNode::typeDataInt: f << ""; break; - case AstNode::typeDataFloat: f << ""; break; - case AstNode::typeDataBool: f << ""; break; - case AstNode::typeDataVersion: f << ""; break; - case AstNode::typeDataMask: f << ""; break; - } - return f; + case AstNode::typeDataNone: f << ""; break; + case AstNode::typeDataString: f << ""; break; + case AstNode::typeDataInt: f << ""; break; + case AstNode::typeDataFloat: f << ""; break; + case AstNode::typeDataBool: f << ""; break; + case AstNode::typeDataVersion: f << ""; break; + case AstNode::typeDataMask: f << ""; break; + } + return f; } diff --git a/src/astnode.h b/src/astnode.h index 843dba8..f3b2d70 100644 --- a/src/astnode.h +++ b/src/astnode.h @@ -7,101 +7,101 @@ class AstNode { public: - enum Type - { - // Branching types - typeFunction = 0x100001, - typeSet = 0x100002, - typeUnset = 0x100003, - typeIf = 0x100004, - typeInclude = 0x100005, - typeTarget = 0x100006, - typeRule = 0x100007, - typeConfig = 0x100008, - typeList = 0x100009, - typeInlineFunc = 0x10000A, - typeRequires = 0x10000B, - typeFor = 0x10000C, - typeFunctionDef = 0x10000D, - typeReturn = 0x10000E, - typeProfile = 0x10000F, - typeInput = 0x100010, - typeRuleDef = 0x100011, - typeOutput = 0x100012, - typeAutoConfig = 0x100013, - typeGlobalConfig = 0x100014, - typeType = 0x100015, - typeValue = 0x100016, - typeAllow = 0x100017, - typeDefault = 0x100018, - typeExport = 0x100019, - typeExpr = 0x10001A, /***< Stack based compound expression.*/ - typeActionDef = 0x10001B, - typeProcessTarget = 0x10001C, - typeTag = 0x10001D, + enum Type + { + // Branching types + typeFunction = 0x100001, + typeSet = 0x100002, + typeUnset = 0x100003, + typeIf = 0x100004, + typeInclude = 0x100005, + typeTarget = 0x100006, + typeRule = 0x100007, + typeConfig = 0x100008, + typeList = 0x100009, + typeInlineFunc = 0x10000A, + typeRequires = 0x10000B, + typeFor = 0x10000C, + typeFunctionDef = 0x10000D, + typeReturn = 0x10000E, + typeProfile = 0x10000F, + typeInput = 0x100010, + typeRuleDef = 0x100011, + typeOutput = 0x100012, + typeAutoConfig = 0x100013, + typeGlobalConfig = 0x100014, + typeType = 0x100015, + typeValue = 0x100016, + typeAllow = 0x100017, + typeDefault = 0x100018, + typeExport = 0x100019, + typeExpr = 0x10001A, /***< Stack based compound expression.*/ + typeActionDef = 0x10001B, + typeProcessTarget = 0x10001C, + typeTag = 0x10001D, - // Leaf types - typeVariable = 0x210001, - typeString = 0x210002, - typeInt = 0x220003, - typeFloat = 0x230004, - typeBool = 0x240005, - typeVersion = 0x250006, - typeOpEq = 0x200007, - typeOpPlusEq = 0x200008, - typeOpPlusEqRaw = 0x200009, - typeError = 0x21000A, - typeWarning = 0x21000B, - typeNotice = 0x21000C, - typeTypeString = 0x20000D, - typeTypeInt = 0x20000E, - typeTypeFloat = 0x20000F, - typeTypeBool = 0x200010, - typeTypeVersion = 0x200011, - typeCmpEq = 0x200012, - typeCmpLt = 0x200013, - typeCmpGt = 0x200014, - typeCmpNe = 0x200015, - typeCmpLtEq = 0x200016, - typeCmpGtEq = 0x200017, - typeCondition = 0x210018, - typeDisplay = 0x210019, - typeCache = 0x24001A, - typePushPrefix = 0x21001B, - typePopPrefix = 0x20001C, - typeNull = 0x20001D, - typeVariableRef = 0x21001E, - typeOpPlus = 0x20001F, - typeOpMinus = 0x200020, - typeOpMultiply = 0x200021, - typeOpDivide = 0x200022, - typeOpNegate = 0x200023, - typeOpNot = 0x200024, + // Leaf types + typeVariable = 0x210001, + typeString = 0x210002, + typeInt = 0x220003, + typeFloat = 0x230004, + typeBool = 0x240005, + typeVersion = 0x250006, + typeOpEq = 0x200007, + typeOpPlusEq = 0x200008, + typeOpPlusEqRaw = 0x200009, + typeError = 0x21000A, + typeWarning = 0x21000B, + typeNotice = 0x21000C, + typeTypeString = 0x20000D, + typeTypeInt = 0x20000E, + typeTypeFloat = 0x20000F, + typeTypeBool = 0x200010, + typeTypeVersion = 0x200011, + typeCmpEq = 0x200012, + typeCmpLt = 0x200013, + typeCmpGt = 0x200014, + typeCmpNe = 0x200015, + typeCmpLtEq = 0x200016, + typeCmpGtEq = 0x200017, + typeCondition = 0x210018, + typeDisplay = 0x210019, + typeCache = 0x24001A, + typePushPrefix = 0x21001B, + typePopPrefix = 0x20001C, + typeNull = 0x20001D, + typeVariableRef = 0x21001E, + typeOpPlus = 0x20001F, + typeOpMinus = 0x200020, + typeOpMultiply = 0x200021, + typeOpDivide = 0x200022, + typeOpNegate = 0x200023, + typeOpNot = 0x200024, - typeBranch = 0x100000, - typeLeaf = 0x200000, - typeClassMask = 0x300000, + typeBranch = 0x100000, + typeLeaf = 0x200000, + typeClassMask = 0x300000, - typeDataNone = 0x000000, - typeDataString = 0x010000, - typeDataInt = 0x020000, - typeDataFloat = 0x030000, - typeDataBool = 0x040000, - typeDataVersion = 0x050000, + typeDataNone = 0x000000, + typeDataString = 0x010000, + typeDataInt = 0x020000, + typeDataFloat = 0x030000, + typeDataBool = 0x040000, + typeDataVersion = 0x050000, - typeDataMask = 0x0F0000 - }; + typeDataMask = 0x0F0000 + }; public: - AstNode( const Location &loc, Type eType ); - virtual ~AstNode(); + AstNode( const Location &loc, Type eType ); + virtual ~AstNode(); - Type getType() const { return eType; } - Type getClass() const { return (Type)(eType&typeClassMask); } - Type getDataType() const { return (Type)(eType&typeDataMask); } + Type getType() const { return eType; } + Type getClass() const { return (Type)(eType&typeClassMask); } + Type getDataType() const { return (Type)(eType&typeDataMask); } private: - Type eType; - Location loc; + Type eType; + Location loc; }; Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode &n ); diff --git a/src/buildparser.cpp b/src/buildparser.cpp index cf98090..6ab23cd 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -7,9 +7,9 @@ using Bu::sio; BuildParser::BuildParser( Ast &rAst ) : - xAst( rAst ) + xAst( rAst ) { - lIncludePaths.append("./"); + lIncludePaths.append("./"); StrList lConds = ConditionPlugger::getInstance().getPluginList(); for( StrList::iterator i = lConds.begin(); i; i++ ) hConds.insert( *i, true ); @@ -23,37 +23,37 @@ int build_parse( yyscan_t yyscanner, BuildParser &bld ); void BuildParser::load( const Bu::String &sFile ) { - yyscan_t scanner; + yyscan_t scanner; - sFilename.push( sFile ); - FILE *fIn = fopen( sFile.getStr(), "rt" ); - if( fIn == NULL ) - { - throw Bu::ExceptionBase("Cannot open file: %s", sFile.getStr() ); - } - build_lex_init( &scanner ); - // build_set_debug( true, scanner ); - build_set_in( fIn, scanner ); + sFilename.push( sFile ); + FILE *fIn = fopen( sFile.getStr(), "rt" ); + if( fIn == NULL ) + { + throw Bu::ExceptionBase("Cannot open file: %s", sFile.getStr() ); + } + build_lex_init( &scanner ); + // build_set_debug( true, scanner ); + build_set_in( fIn, scanner ); - build_parse( scanner, *this ); + build_parse( scanner, *this ); - build_lex_destroy( scanner ); - fclose( fIn ); + build_lex_destroy( scanner ); + fclose( fIn ); - // Bu::sio << xAst; + // Bu::sio << xAst; } bool BuildParser::isKeyword( const Bu::String &sStr ) { - if( sStr == "important" ) - return true; - if( sStr == "normal" ) - return true; - if( sStr == "hidden" ) - return true; - if( sStr == "autogenerated" ) - return true; - return false; + if( sStr == "important" ) + return true; + if( sStr == "normal" ) + return true; + if( sStr == "hidden" ) + return true; + if( sStr == "autogenerated" ) + return true; + return false; } bool BuildParser::isCond( const Bu::String &sStr ) @@ -70,67 +70,67 @@ bool BuildParser::isCond( const Bu::String &sStr ) void BuildParser::include( const Bu::String &sStr, void *scanner, YYLTYPE *loc ) { - for( StrList::iterator pi = lIncludePaths.begin(); pi; pi++ ) - { - FILE *fIn = fopen( (*pi + sStr).getStr(), "rt" ); - if( fIn == NULL ) - { - continue; - } - sFilename.push( sStr ); - sLocation.push( *loc ); - loc->first_line = loc->last_line = 1; - loc->first_column = loc->last_column = 0; - build_push_buffer_state( - build__create_buffer( fIn, YY_READ_BUF_SIZE, scanner ), - scanner - ); - Bu::String::const_iterator i = sStr.find('/'); - if( i ) - { - for(;;) - { - Bu::String::const_iterator j = i.find('/'); - if( !j ) - break; - i = j+1; - } - sio << "Hey, found it from here: " << sStr.getSubStr( sStr.begin(), i ) << sio.nl; - xAst.addNode( AstNode::typePushPrefix, sStr.getSubStr( sStr.begin(), i ) ); - } - else - { - xAst.addNode( AstNode::typePushPrefix, "" ); - } - return; - } - Bu::String msg("Could not open include file: "); - msg += sStr; - error( - loc->first_line, loc->last_line, - loc->first_column, loc->last_column, - msg - ); + for( StrList::iterator pi = lIncludePaths.begin(); pi; pi++ ) + { + FILE *fIn = fopen( (*pi + sStr).getStr(), "rt" ); + if( fIn == NULL ) + { + continue; + } + sFilename.push( sStr ); + sLocation.push( *loc ); + loc->first_line = loc->last_line = 1; + loc->first_column = loc->last_column = 0; + build_push_buffer_state( + build__create_buffer( fIn, YY_READ_BUF_SIZE, scanner ), + scanner + ); + Bu::String::const_iterator i = sStr.find('/'); + if( i ) + { + for(;;) + { + Bu::String::const_iterator j = i.find('/'); + if( !j ) + break; + i = j+1; + } + sio << "Hey, found it from here: " << sStr.getSubStr( sStr.begin(), i ) << sio.nl; + xAst.addNode( AstNode::typePushPrefix, sStr.getSubStr( sStr.begin(), i ) ); + } + else + { + xAst.addNode( AstNode::typePushPrefix, "" ); + } + return; + } + Bu::String msg("Could not open include file: "); + msg += sStr; + error( + loc->first_line, loc->last_line, + loc->first_column, loc->last_column, + msg + ); } void BuildParser::endInclude( YYLTYPE *loc ) { - sFilename.pop(); - memcpy( loc, &sLocation.peek(), sizeof(YYLTYPE) ); - sLocation.pop(); - xAst.addNode( AstNode::typePopPrefix ); + sFilename.pop(); + memcpy( loc, &sLocation.peek(), sizeof(YYLTYPE) ); + sLocation.pop(); + xAst.addNode( AstNode::typePopPrefix ); } void BuildParser::error( int iLine1, int iLine2, int iCol1, int iCol2, - const Bu::String &sMsg ) + const Bu::String &sMsg ) { - throw Bu::ExceptionBase("%s: %d-%d:%d-%d: %s", - sFilename.peek().getStr(), iLine1, iLine2, iCol1, iCol2, sMsg.getStr() - ); + throw Bu::ExceptionBase("%s: %d-%d:%d-%d: %s", + sFilename.peek().getStr(), iLine1, iLine2, iCol1, iCol2, sMsg.getStr() + ); } void BuildParser::addIncludePath( const Bu::String &sPath ) { - lIncludePaths.append( sPath + "/" ); + lIncludePaths.append( sPath + "/" ); } diff --git a/src/buildparser.h b/src/buildparser.h index 53e2a50..a6149f0 100644 --- a/src/buildparser.h +++ b/src/buildparser.h @@ -10,27 +10,27 @@ class BuildParser { public: - BuildParser( class Ast &rAst ); - virtual ~BuildParser(); + BuildParser( class Ast &rAst ); + virtual ~BuildParser(); - void load( const Bu::String &sFile ); + void load( const Bu::String &sFile ); - bool isKeyword( const Bu::String &sStr ); - bool isCond( const Bu::String &sStr ); - void include( const Bu::String &sStr, void *scanner, YYLTYPE *loc ); - void endInclude( YYLTYPE *loc ); + bool isKeyword( const Bu::String &sStr ); + bool isCond( const Bu::String &sStr ); + void include( const Bu::String &sStr, void *scanner, YYLTYPE *loc ); + void endInclude( YYLTYPE *loc ); - void error( int iLine1, int iLine2, int iCol1, int iCol2, - const Bu::String &sMsg ); + void error( int iLine1, int iLine2, int iCol1, int iCol2, + const Bu::String &sMsg ); - class Ast &xAst; + class Ast &xAst; - void addIncludePath( const Bu::String &sPath ); + void addIncludePath( const Bu::String &sPath ); private: - Bu::Stack sFilename; - Bu::Stack sLocation; - StrList lIncludePaths; + Bu::Stack sFilename; + Bu::Stack sLocation; + StrList lIncludePaths; Bu::Hash hConds; }; diff --git a/src/cache.cpp b/src/cache.cpp index d6269e3..8d6a91e 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -5,60 +5,60 @@ using namespace Bu; Cache::Cache() : - bCacheChanged( false ), - bIsLoaded( false ) + bCacheChanged( false ), + bIsLoaded( false ) { } Cache::~Cache() { - save(); + save(); } void Cache::bind( const Bu::String &sCacheFile ) { - this->sCacheFile = sCacheFile; - load(); + this->sCacheFile = sCacheFile; + load(); } void Cache::load() { - if( bIsLoaded ) - return; + if( bIsLoaded ) + return; - try - { - Bu::File fIn( sCacheFile, Bu::File::Read ); - Bu::Archive ar( fIn, Bu::Archive::load ); + try + { + Bu::File fIn( sCacheFile, Bu::File::Read ); + Bu::Archive ar( fIn, Bu::Archive::load ); - ar >> hRequires >> hVariables; - } - catch(...) { } + ar >> hRequires >> hVariables; + } + catch(...) { } - bIsLoaded = true; + bIsLoaded = true; } void Cache::save() { - if( !bIsLoaded ) - return; - if( bCacheChanged == false ) - return; + if( !bIsLoaded ) + return; + if( bCacheChanged == false ) + return; - Bu::File fIn( sCacheFile, Bu::File::WriteNew ); - Bu::Archive ar( fIn, Bu::Archive::save ); + Bu::File fIn( sCacheFile, Bu::File::WriteNew ); + Bu::Archive ar( fIn, Bu::Archive::save ); - ar << hRequires << hVariables; + ar << hRequires << hVariables; } StrList Cache::getRequires( const Bu::String &sOutput ) { - return hRequires.get( sOutput ); + return hRequires.get( sOutput ); } void Cache::setRequires( const Bu::String &sOutput, StrList lReqs ) { - hRequires.insert( sOutput, lReqs ); - bCacheChanged = true; + hRequires.insert( sOutput, lReqs ); + bCacheChanged = true; } diff --git a/src/cache.h b/src/cache.h index 57df281..9a53803 100644 --- a/src/cache.h +++ b/src/cache.h @@ -13,26 +13,26 @@ class Cache : public Bu::Singleton { friend class Bu::Singleton; private: - Cache(); - virtual ~Cache(); + Cache(); + virtual ~Cache(); public: - void bind( const Bu::String &sCacheFile ); + void bind( const Bu::String &sCacheFile ); - void load(); - void save(); + void load(); + void save(); - StrList getRequires( const Bu::String &sOutput ); - void setRequires( const Bu::String &sOutput, StrList lReqs ); + StrList getRequires( const Bu::String &sOutput ); + void setRequires( const Bu::String &sOutput, StrList lReqs ); private: - bool bCacheChanged; - Bu::String sCacheFile; - bool bIsLoaded; - typedef Bu::Hash ReqHash; - ReqHash hRequires; - typedef Bu::Hash VarHash; - VarHash hVariables; + bool bCacheChanged; + Bu::String sCacheFile; + bool bIsLoaded; + typedef Bu::Hash ReqHash; + ReqHash hRequires; + typedef Bu::Hash VarHash; + VarHash hVariables; }; #endif diff --git a/src/condition.h b/src/condition.h index 2e9b26a..a6b38bb 100644 --- a/src/condition.h +++ b/src/condition.h @@ -4,11 +4,11 @@ class Condition { public: - Condition(); - virtual ~Condition(); + Condition(); + virtual ~Condition(); - virtual bool shouldExec( class Runner &r, class Target &rTarget )=0; - virtual Condition *clone()=0; + virtual bool shouldExec( class Runner &r, class Target &rTarget )=0; + virtual Condition *clone()=0; private: }; diff --git a/src/conditionalways.cpp b/src/conditionalways.cpp index 8c245f4..c5fc0b0 100644 --- a/src/conditionalways.cpp +++ b/src/conditionalways.cpp @@ -3,7 +3,7 @@ #include PluginInterface3( pluginConditionAlways, always, ConditionAlways, Condition, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); ConditionAlways::ConditionAlways() { @@ -15,11 +15,11 @@ ConditionAlways::~ConditionAlways() bool ConditionAlways::shouldExec( class Runner &/*r*/, Target &/*rTarget*/ ) { - return true; + return true; } Condition *ConditionAlways::clone() { - return new ConditionAlways(); + return new ConditionAlways(); } diff --git a/src/conditionalways.h b/src/conditionalways.h index 1eeeb71..2ac5a79 100644 --- a/src/conditionalways.h +++ b/src/conditionalways.h @@ -6,11 +6,11 @@ class ConditionAlways : public Condition { public: - ConditionAlways(); - virtual ~ConditionAlways(); + ConditionAlways(); + virtual ~ConditionAlways(); - virtual bool shouldExec( class Runner &r, class Target &rTarget ); - virtual Condition *clone(); + virtual bool shouldExec( class Runner &r, class Target &rTarget ); + virtual Condition *clone(); }; #endif diff --git a/src/conditionfileexists.cpp b/src/conditionfileexists.cpp index 0585351..fd21716 100644 --- a/src/conditionfileexists.cpp +++ b/src/conditionfileexists.cpp @@ -10,7 +10,7 @@ using namespace Bu; #include PluginInterface3( pluginConditionFileExists, fileExists, ConditionFileExists, - Condition, "Mike Buland", 0, 1 ); + Condition, "Mike Buland", 0, 1 ); ConditionFileExists::ConditionFileExists() { @@ -22,20 +22,20 @@ ConditionFileExists::~ConditionFileExists() bool ConditionFileExists::shouldExec( class Runner &r, Target &rTarget ) { - for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) - { - // If any input exists, then return true, we should exec. - if( !access( (*j).getStr(), F_OK ) ) - { - return true; - } - } - - return false; + for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) + { + // If any input exists, then return true, we should exec. + if( !access( (*j).getStr(), F_OK ) ) + { + return true; + } + } + + return false; } Condition *ConditionFileExists::clone() { - return new ConditionFileExists(); + return new ConditionFileExists(); } diff --git a/src/conditionfileexists.h b/src/conditionfileexists.h index 6f30297..f1fe568 100644 --- a/src/conditionfileexists.h +++ b/src/conditionfileexists.h @@ -6,11 +6,11 @@ class ConditionFileExists : public Condition { public: - ConditionFileExists(); - virtual ~ConditionFileExists(); + ConditionFileExists(); + virtual ~ConditionFileExists(); - virtual bool shouldExec( class Runner &r, class Target &rTarget ); - virtual Condition *clone(); + virtual bool shouldExec( class Runner &r, class Target &rTarget ); + virtual Condition *clone(); }; #endif diff --git a/src/conditionfiletime.cpp b/src/conditionfiletime.cpp index 43df53b..82d147c 100644 --- a/src/conditionfiletime.cpp +++ b/src/conditionfiletime.cpp @@ -10,7 +10,7 @@ using namespace Bu; #include PluginInterface3( pluginConditionFileTime, fileTime, ConditionFileTime, - Condition, "Mike Buland", 0, 1 ); + Condition, "Mike Buland", 0, 1 ); ConditionFileTime::ConditionFileTime() { @@ -22,59 +22,59 @@ ConditionFileTime::~ConditionFileTime() bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget ) { - for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) - { - if( access( (*j).getStr(), F_OK ) ) - { - //sio << "-- Target processed because '" << *j << "' doesn't exist." - // << sio.nl; - // Output doesn't exist - rTarget.buildRequires( r ); - return true; - } - } + for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) + { + if( access( (*j).getStr(), F_OK ) ) + { + //sio << "-- Target processed because '" << *j << "' doesn't exist." + // << sio.nl; + // Output doesn't exist + rTarget.buildRequires( r ); + return true; + } + } - time_t tOut = 0; - struct stat s; - for( StrList::const_iterator j = rTarget.getOutputList().begin(); - j; j++ ) - { - stat( (*j).getStr(), &s ); - if( tOut == 0 || tOut > s.st_mtime ) - { - tOut = s.st_mtime; - } - } - for( StrList::const_iterator j = rTarget.getInputList().begin(); - j; j++ ) - { - stat( (*j).getStr(), &s ); - if( tOut < s.st_mtime ) - { - //sio << "-- Target processed because '" << *j - // << "' is newer than output." << sio.nl; - rTarget.buildRequires( r ); - return true; - } - } - rTarget.gatherRequires( r ); - for( StrList::const_iterator j = rTarget.getRequiresList().begin(); - j; j++ ) - { - stat( (*j).getStr(), &s ); - if( tOut < s.st_mtime ) - { - //sio << "-- Target processed because '" << *j - // << "' is newer than output." << sio.nl; - rTarget.buildRequires( r ); - return true; - } - } - return false; + time_t tOut = 0; + struct stat s; + for( StrList::const_iterator j = rTarget.getOutputList().begin(); + j; j++ ) + { + stat( (*j).getStr(), &s ); + if( tOut == 0 || tOut > s.st_mtime ) + { + tOut = s.st_mtime; + } + } + for( StrList::const_iterator j = rTarget.getInputList().begin(); + j; j++ ) + { + stat( (*j).getStr(), &s ); + if( tOut < s.st_mtime ) + { + //sio << "-- Target processed because '" << *j + // << "' is newer than output." << sio.nl; + rTarget.buildRequires( r ); + return true; + } + } + rTarget.gatherRequires( r ); + for( StrList::const_iterator j = rTarget.getRequiresList().begin(); + j; j++ ) + { + stat( (*j).getStr(), &s ); + if( tOut < s.st_mtime ) + { + //sio << "-- Target processed because '" << *j + // << "' is newer than output." << sio.nl; + rTarget.buildRequires( r ); + return true; + } + } + return false; } Condition *ConditionFileTime::clone() { - return new ConditionFileTime(); + return new ConditionFileTime(); } diff --git a/src/conditionfiletime.h b/src/conditionfiletime.h index 6fb2e9d..54cc83b 100644 --- a/src/conditionfiletime.h +++ b/src/conditionfiletime.h @@ -6,11 +6,11 @@ class ConditionFileTime : public Condition { public: - ConditionFileTime(); - virtual ~ConditionFileTime(); + ConditionFileTime(); + virtual ~ConditionFileTime(); - virtual bool shouldExec( class Runner &r, class Target &rTarget ); - virtual Condition *clone(); + virtual bool shouldExec( class Runner &r, class Target &rTarget ); + virtual Condition *clone(); }; #endif diff --git a/src/conditionnever.cpp b/src/conditionnever.cpp index f99feb6..74f493b 100644 --- a/src/conditionnever.cpp +++ b/src/conditionnever.cpp @@ -3,7 +3,7 @@ #include PluginInterface3( pluginConditionNever, never, ConditionNever, Condition, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); ConditionNever::ConditionNever() { @@ -15,11 +15,11 @@ ConditionNever::~ConditionNever() bool ConditionNever::shouldExec( class Runner &/*r*/, Target &/*rTarget*/ ) { - return false; + return false; } Condition *ConditionNever::clone() { - return new ConditionNever(); + return new ConditionNever(); } diff --git a/src/conditionnever.h b/src/conditionnever.h index b7e5e92..d0b6e22 100644 --- a/src/conditionnever.h +++ b/src/conditionnever.h @@ -6,11 +6,11 @@ class ConditionNever : public Condition { public: - ConditionNever(); - virtual ~ConditionNever(); + ConditionNever(); + virtual ~ConditionNever(); - virtual bool shouldExec( class Runner &r, class Target &rTarget ); - virtual Condition *clone(); + virtual bool shouldExec( class Runner &r, class Target &rTarget ); + virtual Condition *clone(); }; #endif diff --git a/src/conditionplugger.cpp b/src/conditionplugger.cpp index 53f613a..6eb54cf 100644 --- a/src/conditionplugger.cpp +++ b/src/conditionplugger.cpp @@ -10,31 +10,31 @@ extern Bu::PluginInfo pluginConditionFileExists; ConditionPlugger::ConditionPlugger() { - registerBuiltinPlugin( &pluginConditionAlways ); - registerBuiltinPlugin( &pluginConditionNever ); - registerBuiltinPlugin( &pluginConditionFileTime ); - registerBuiltinPlugin( &pluginConditionFileExists ); - - DIR *dir = opendir("/usr/lib/build"); - if( !dir ) - return; - struct dirent *de; - while( (de = readdir( dir )) ) - { - if( strncmp("pluginCondition", de->d_name, 15 ) ) - continue; - - Bu::String sFile("/usr/lib/build/"); - sFile += de->d_name; - char *s = de->d_name; - for(; *s && *s != '.'; s++ ) { } - registerExternalPlugin( - sFile, - Bu::String( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name ) - ); - } - - closedir( dir ); + registerBuiltinPlugin( &pluginConditionAlways ); + registerBuiltinPlugin( &pluginConditionNever ); + registerBuiltinPlugin( &pluginConditionFileTime ); + registerBuiltinPlugin( &pluginConditionFileExists ); + + DIR *dir = opendir("/usr/lib/build"); + if( !dir ) + return; + struct dirent *de; + while( (de = readdir( dir )) ) + { + if( strncmp("pluginCondition", de->d_name, 15 ) ) + continue; + + Bu::String sFile("/usr/lib/build/"); + sFile += de->d_name; + char *s = de->d_name; + for(; *s && *s != '.'; s++ ) { } + registerExternalPlugin( + sFile, + Bu::String( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name ) + ); + } + + closedir( dir ); } ConditionPlugger::~ConditionPlugger() diff --git a/src/conditionplugger.h b/src/conditionplugger.h index 71fa7e3..294614b 100644 --- a/src/conditionplugger.h +++ b/src/conditionplugger.h @@ -6,12 +6,12 @@ #include class ConditionPlugger : public Bu::Plugger, - public Bu::Singleton + public Bu::Singleton { friend class Bu::Singleton; private: - ConditionPlugger(); - virtual ~ConditionPlugger(); + ConditionPlugger(); + virtual ~ConditionPlugger(); }; #endif diff --git a/src/context.cpp b/src/context.cpp index 22bea57..7f0c56f 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -14,9 +14,9 @@ using namespace Bu; Context::Context() : - pView( NULL ) + pView( NULL ) { - pushScope(); + pushScope(); } Context::~Context() @@ -25,522 +25,522 @@ Context::~Context() void Context::addTarget( Target *pTarget ) { - for( StrList::const_iterator i = pTarget->getOutputList().begin(); i; i++ ) - { - hTarget.insert( (*i).getStr(), pTarget ); - } + for( StrList::const_iterator i = pTarget->getOutputList().begin(); i; i++ ) + { + hTarget.insert( (*i).getStr(), pTarget ); + } } void Context::addRule( Rule *pRule ) { - hRule.insert( pRule->getName(), pRule ); + hRule.insert( pRule->getName(), pRule ); } void Context::addFunction( Function *pFunction ) { - pFunction->setContext( this ); - hFunction.insert( pFunction->getName(), pFunction ); + pFunction->setContext( this ); + hFunction.insert( pFunction->getName(), pFunction ); } void Context::addVariable( const Bu::String &sName, const Variable &vValue ) { - for( ScopeStack::iterator i = sVars.begin(); i; i++ ) - { - if( (*i).has( sName ) ) - { -// sio << "Replacing higher scope variable \"" << sName << "\" with value \"" << (*i).get( sName ) << "\" with new value \"" << vValue << "\"" << sio.nl; - (*i).insert( sName, vValue ); - return; - } - } - sVars.first().insert( sName, vValue ); + for( ScopeStack::iterator i = sVars.begin(); i; i++ ) + { + if( (*i).has( sName ) ) + { +// sio << "Replacing higher scope variable \"" << sName << "\" with value \"" << (*i).get( sName ) << "\" with new value \"" << vValue << "\"" << sio.nl; + (*i).insert( sName, vValue ); + return; + } + } + sVars.first().insert( sName, vValue ); } void Context::addAction( Action *pAction ) { - hAction.insert( pAction->getName(), pAction ); + hAction.insert( pAction->getName(), pAction ); } Action *Context::getAction( const Bu::String &sName ) { - return hAction.get( sName ); + return hAction.get( sName ); } void Context::addTargetToTag( Target *pTarget, const Bu::String &sTag ) { - if( !hTag.has( sTag ) ) - { - hTag.insert( sTag, TargetList() ); - } - hTag.get( sTag ).append( pTarget ); + if( !hTag.has( sTag ) ) + { + hTag.insert( sTag, TargetList() ); + } + hTag.get( sTag ).append( pTarget ); } void Context::addTargetToTags( Target *pTarget, const StrList &sTags ) { - for( StrList::const_iterator i = sTags.begin(); i; i++ ) - { - addTargetToTag( pTarget, *i ); - } + for( StrList::const_iterator i = sTags.begin(); i; i++ ) + { + addTargetToTag( pTarget, *i ); + } } TargetList &Context::getTag( const Bu::String &sTag ) { - return hTag.get( sTag ); + return hTag.get( sTag ); } Variable &Context::getVariable( const Bu::String &sName ) { - for( ScopeStack::iterator i = sVars.begin(); i; i++ ) - { - if( (*i).has( sName ) ) - { - return (*i).get( sName ); - } - } - throw Bu::ExceptionBase("No such variable."); + for( ScopeStack::iterator i = sVars.begin(); i; i++ ) + { + if( (*i).has( sName ) ) + { + return (*i).get( sName ); + } + } + throw Bu::ExceptionBase("No such variable."); } void Context::delVariable( const Bu::String &sName ) { - for( ScopeStack::iterator i = sVars.begin(); i; i++ ) - { - if( (*i).has( sName ) ) - { - (*i).erase( sName ); - } - } + for( ScopeStack::iterator i = sVars.begin(); i; i++ ) + { + if( (*i).has( sName ) ) + { + (*i).erase( sName ); + } + } } void Context::pushScope() { - VarHash h; - if( !sVars.isEmpty() ) - h = sVars.peek(); - sVars.push( h ); + VarHash h; + if( !sVars.isEmpty() ) + h = sVars.peek(); + sVars.push( h ); } void Context::pushScope( const VarHash &hNewVars ) { -// sio << "Pushing scope, merging contexts." << sio.nl << sio.nl; - VarHash h = hNewVars; - if( !sVars.isEmpty() ) - { -// sio << "hNewVars = " << h << sio.nl << sio.nl -// << "sVars = " << sVars.peek() << sio.nl; - for( VarHash::iterator i = sVars.peek().begin(); i; i++ ) - { -// sio << "Checking '" << i.getKey() << "' (" << i.getValue() << ")." << sio.nl; - if( !h.has( i.getKey() ) ) - { -// sio << " Context doesn't have '" << i.getKey() << "' adding... '" << i.getValue() << "'." << sio.nl; - h.insert( i.getKey(), i.getValue() ); - } - } - } - sVars.push( h ); +// sio << "Pushing scope, merging contexts." << sio.nl << sio.nl; + VarHash h = hNewVars; + if( !sVars.isEmpty() ) + { +// sio << "hNewVars = " << h << sio.nl << sio.nl +// << "sVars = " << sVars.peek() << sio.nl; + for( VarHash::iterator i = sVars.peek().begin(); i; i++ ) + { +// sio << "Checking '" << i.getKey() << "' (" << i.getValue() << ")." << sio.nl; + if( !h.has( i.getKey() ) ) + { +// sio << " Context doesn't have '" << i.getKey() << "' adding... '" << i.getValue() << "'." << sio.nl; + h.insert( i.getKey(), i.getValue() ); + } + } + } + sVars.push( h ); } VarHash &Context::getScope() { - return sVars.peek(); + return sVars.peek(); } void Context::popScope() { - sVars.pop(); + sVars.pop(); } Variable Context::call( const Bu::String &sName, Variable &input, - VarList lParams ) + VarList lParams ) { - if( !hFunction.has( sName ) ) - { - // Try to load the function... - try - { - addFunction( FunctionPlugger::getInstance().instantiate( sName ) ); - } - catch(...) - { - throw Bu::ExceptionBase("Unknown function called: %s", - sName.getStr() ); - } - } - return hFunction.get( sName )->call( input, lParams ); + if( !hFunction.has( sName ) ) + { + // Try to load the function... + try + { + addFunction( FunctionPlugger::getInstance().instantiate( sName ) ); + } + catch(...) + { + throw Bu::ExceptionBase("Unknown function called: %s", + sName.getStr() ); + } + } + return hFunction.get( sName )->call( input, lParams ); } #include using namespace Bu; Bu::String Context::expand( const Bu::String &sInS ) { - Bu::String sRet; - Bu::String sIn = sInS; - - for( int iPass = 0; iPass < 2; iPass++ ) - { - Bu::String::const_iterator b = sIn.begin(); - sRet.clear(); - for(;;) - { - Bu::String::const_iterator e = b.find('$'); - if( !e ) - { - sRet.append( b ); - break; - } - sRet.append( b, e ); - b = e+1; - if( !b ) - { - sRet.append('$'); - } - else if( *b == '{' ) - { - b++; - e = b.find('}'); - Bu::String sVar( b, e ); - try - { - sRet.append( getVariable( sVar ).toString() ); - } catch(...) - { - // TODO: This may be handy debugging later... - //sio << "No variable named " << sVar << sio.nl; - //sio << "Vars: " << sVars << sio.nl << sio.nl; - } - b = e+1; - } - else if( *b == '(' && iPass == 1 ) - { - Bu::String sCmd; - b++; - for( e = b; e != ')'; e++ ) - { - if( *e == '\\' && *(e+1) == ')' ) - { - sCmd += ')'; - e++; - } - else - sCmd += *e; - } - //e = b.find(')'); -// Bu::String sCmd( b, e ); - Bu::String sBuf; - try - { - //sio << "Executing command: >>>" << sCmd << "<<<" << sio.nl; - Process p( Process::StdOut, - "/bin/bash", "/bin/bash", "-c", sCmd.getStr(), NULL - ); - char buf[4096]; - do - { - sBuf.append( buf, p.read( buf, 4096 ) ); - } - while( p.isRunning() ); - sBuf.append( buf, p.read( buf, 4096 ) ); - sBuf = sBuf.replace("\n", " ").replace("\r", " "). - trimWhitespace(); - sRet.append( sBuf ); - } catch(...) - { - // TODO: This may be handy debugging later... - //sio << "No variable named " << sVar << sio.nl; - //sio << "Vars: " << sVars << sio.nl << sio.nl; - } - b = e+1; - } - else - { - // Not a match, uh, just output the $ for now... - sRet.append('$'); - } - } - - sIn = sRet; - } - return sRet; + Bu::String sRet; + Bu::String sIn = sInS; + + for( int iPass = 0; iPass < 2; iPass++ ) + { + Bu::String::const_iterator b = sIn.begin(); + sRet.clear(); + for(;;) + { + Bu::String::const_iterator e = b.find('$'); + if( !e ) + { + sRet.append( b ); + break; + } + sRet.append( b, e ); + b = e+1; + if( !b ) + { + sRet.append('$'); + } + else if( *b == '{' ) + { + b++; + e = b.find('}'); + Bu::String sVar( b, e ); + try + { + sRet.append( getVariable( sVar ).toString() ); + } catch(...) + { + // TODO: This may be handy debugging later... + //sio << "No variable named " << sVar << sio.nl; + //sio << "Vars: " << sVars << sio.nl << sio.nl; + } + b = e+1; + } + else if( *b == '(' && iPass == 1 ) + { + Bu::String sCmd; + b++; + for( e = b; e != ')'; e++ ) + { + if( *e == '\\' && *(e+1) == ')' ) + { + sCmd += ')'; + e++; + } + else + sCmd += *e; + } + //e = b.find(')'); +// Bu::String sCmd( b, e ); + Bu::String sBuf; + try + { + //sio << "Executing command: >>>" << sCmd << "<<<" << sio.nl; + Process p( Process::StdOut, + "/bin/bash", "/bin/bash", "-c", sCmd.getStr(), NULL + ); + char buf[4096]; + do + { + sBuf.append( buf, p.read( buf, 4096 ) ); + } + while( p.isRunning() ); + sBuf.append( buf, p.read( buf, 4096 ) ); + sBuf = sBuf.replace("\n", " ").replace("\r", " "). + trimWhitespace(); + sRet.append( sBuf ); + } catch(...) + { + // TODO: This may be handy debugging later... + //sio << "No variable named " << sVar << sio.nl; + //sio << "Vars: " << sVars << sio.nl << sio.nl; + } + b = e+1; + } + else + { + // Not a match, uh, just output the $ for now... + sRet.append('$'); + } + } + + sIn = sRet; + } + return sRet; } Target *Context::getTarget( const Bu::String &sOutput ) { - return hTarget.get( sOutput ); + return hTarget.get( sOutput ); } TargetList Context::getExplicitTargets() { - TargetList lRet; - for( TargetHash::iterator i = hTarget.begin(); i; i++ ) - { - if( (*i)->isExplicit() ) - lRet.append( *i ); - } - return lRet; + TargetList lRet; + for( TargetHash::iterator i = hTarget.begin(); i; i++ ) + { + if( (*i)->isExplicit() ) + lRet.append( *i ); + } + return lRet; } void Context::buildTargetTree( Runner &r ) { - TargetList lTargets = hTarget.getValues(); - - for( TargetList::iterator i = lTargets.begin(); i; i++ ) - { - // I believe we only want to autogenerate targets for explicit targets - // that have rules defined. - if( !(*i)->isExplicit() || !(*i)->hasRule() ) - continue; - - StrList lNewIns; // The new "changed" inputs for this target - - Rule *pMaster; - try - { - pMaster = hRule.get( (*i)->getRule() ); - } - catch( Bu::HashException &e ) - { - throw Bu::ExceptionBase("Unknown rule: %s", (*i)->getRule().getStr() ); - } - - for( StrList::const_iterator j = (*i)->getInputList().begin(); j; j++ ) - { - if( pMaster->ruleMatches( r, *j ) ) - { - lNewIns.append( *j ); - } - - if( hTarget.has( *j ) ) - { - // Find the existing dependancy - lNewIns.append( *j ); - } - //else - //{ - buildTargetTree( r, *i, *j, pMaster, lNewIns ); - //} - } - - pMaster->prepTarget( *i ); - (*i)->resetInputList( lNewIns ); - } - //sio << "Building dependancies: " << Fmt(3) << 0 << "%\r" << sio.flush; - //int iSize = hTarget.getSize(), iCur = 0; - for( TargetHash::iterator i = hTarget.begin(); i; i++ ) - { - // Before we can take a look at the requirements, we need to build - // them... - // (*i)->buildRequires( r ); - - // For every target we have to examine both it's inputs and it's - // additional requirements. Inputs first - StrList lDeps( (*i)->getInputList() ); - lDeps += (*i)->getRequiresList(); - for( StrList::const_iterator j = lDeps.begin(); j; j++ ) - { - try - { - (*i)->addDep( hTarget.get( *j ) ); - } - catch(...) - { - } - } - //iCur++; - // sio << "Building dependancies: " << Fmt(3) << (iCur*100/iSize) << "%\r" << sio.flush; - (*i)->collapseDeps(); - } -// sio << sio.nl; - - for( TargetHash::iterator i = hTarget.begin(); i; i++ ) - { - if( !(*i)->isExplicit() ) - continue; - (*i)->setDepCount(); - (*i)->resetRun( false ); - } + TargetList lTargets = hTarget.getValues(); + + for( TargetList::iterator i = lTargets.begin(); i; i++ ) + { + // I believe we only want to autogenerate targets for explicit targets + // that have rules defined. + if( !(*i)->isExplicit() || !(*i)->hasRule() ) + continue; + + StrList lNewIns; // The new "changed" inputs for this target + + Rule *pMaster; + try + { + pMaster = hRule.get( (*i)->getRule() ); + } + catch( Bu::HashException &e ) + { + throw Bu::ExceptionBase("Unknown rule: %s", (*i)->getRule().getStr() ); + } + + for( StrList::const_iterator j = (*i)->getInputList().begin(); j; j++ ) + { + if( pMaster->ruleMatches( r, *j ) ) + { + lNewIns.append( *j ); + } + + if( hTarget.has( *j ) ) + { + // Find the existing dependancy + lNewIns.append( *j ); + } + //else + //{ + buildTargetTree( r, *i, *j, pMaster, lNewIns ); + //} + } + + pMaster->prepTarget( *i ); + (*i)->resetInputList( lNewIns ); + } + //sio << "Building dependancies: " << Fmt(3) << 0 << "%\r" << sio.flush; + //int iSize = hTarget.getSize(), iCur = 0; + for( TargetHash::iterator i = hTarget.begin(); i; i++ ) + { + // Before we can take a look at the requirements, we need to build + // them... + // (*i)->buildRequires( r ); + + // For every target we have to examine both it's inputs and it's + // additional requirements. Inputs first + StrList lDeps( (*i)->getInputList() ); + lDeps += (*i)->getRequiresList(); + for( StrList::const_iterator j = lDeps.begin(); j; j++ ) + { + try + { + (*i)->addDep( hTarget.get( *j ) ); + } + catch(...) + { + } + } + //iCur++; + // sio << "Building dependancies: " << Fmt(3) << (iCur*100/iSize) << "%\r" << sio.flush; + (*i)->collapseDeps(); + } +// sio << sio.nl; + + for( TargetHash::iterator i = hTarget.begin(); i; i++ ) + { + if( !(*i)->isExplicit() ) + continue; + (*i)->setDepCount(); + (*i)->resetRun( false ); + } } void Context::buildTargetTree( class Runner &r, class Target *pTarget, const Bu::String &sInput, Rule *pMaster, StrList &lNewIns ) { - Target *pNewTarget = NULL; - for( RuleHash::iterator i = hRule.begin(); i; i++ ) - { - if( (*i)->hasOutputs() && (*i)->ruleMatches( r, sInput ) ) - { - pNewTarget = (*i)->createTarget( r, sInput, pTarget ); - - Bu::Hash hDone; - for( StrList::const_iterator oi = - pNewTarget->getOutputList().begin(); oi; oi++ ) - { - try - { - Target *pOver = hTarget.get( *oi ); - if( hDone.has( (ptrdiff_t)pOver ) ) - continue; - hDone.insert( (ptrdiff_t)pOver, true ); - if( !pOver->isExplicit() ) - { - delete pNewTarget; - pNewTarget = pOver; - break; - } - pOver->mergeUnder( pNewTarget ); - delete pNewTarget; -// sio << "Delete: " << Fmt::ptr() << (ptrdiff_t)pNewTarget << sio.nl; - pNewTarget = pOver; - break; - } - catch(...) - { - } - } - - // We actually want to add this either way, if the merge added new - // outputs, then we need to take them into account. - addTarget( pNewTarget ); - addTargetToTags( pNewTarget, (*i)->getTagList() ); - - // We have created a new target (or not, either way, we need to - // check if it matches.) - for( StrList::const_iterator m = - pNewTarget->getOutputList().begin(); m; m++ ) - { - // Does the new output match the master rule? - if( pMaster->ruleMatches( r, (*m) ) ) - { - lNewIns.append( (*m) ); - -// sio << "What?" << sio.nl; - // These relationships are difficult to pick up on except - // that one target was created by the other, I suppose. - // Anyway, that means that we need to add this while we - // can. -// pTarget->addDep( pNewTarget ); - } - // else - // { - buildTargetTree( r, pNewTarget, *m, pMaster, lNewIns ); - // } - } - - return; - } - } - if( !pNewTarget ) - { - //sio << "Incomplete tree created, trying to find purpose for \"" + Target *pNewTarget = NULL; + for( RuleHash::iterator i = hRule.begin(); i; i++ ) + { + if( (*i)->hasOutputs() && (*i)->ruleMatches( r, sInput ) ) + { + pNewTarget = (*i)->createTarget( r, sInput, pTarget ); + + Bu::Hash hDone; + for( StrList::const_iterator oi = + pNewTarget->getOutputList().begin(); oi; oi++ ) + { + try + { + Target *pOver = hTarget.get( *oi ); + if( hDone.has( (ptrdiff_t)pOver ) ) + continue; + hDone.insert( (ptrdiff_t)pOver, true ); + if( !pOver->isExplicit() ) + { + delete pNewTarget; + pNewTarget = pOver; + break; + } + pOver->mergeUnder( pNewTarget ); + delete pNewTarget; +// sio << "Delete: " << Fmt::ptr() << (ptrdiff_t)pNewTarget << sio.nl; + pNewTarget = pOver; + break; + } + catch(...) + { + } + } + + // We actually want to add this either way, if the merge added new + // outputs, then we need to take them into account. + addTarget( pNewTarget ); + addTargetToTags( pNewTarget, (*i)->getTagList() ); + + // We have created a new target (or not, either way, we need to + // check if it matches.) + for( StrList::const_iterator m = + pNewTarget->getOutputList().begin(); m; m++ ) + { + // Does the new output match the master rule? + if( pMaster->ruleMatches( r, (*m) ) ) + { + lNewIns.append( (*m) ); + +// sio << "What?" << sio.nl; + // These relationships are difficult to pick up on except + // that one target was created by the other, I suppose. + // Anyway, that means that we need to add this while we + // can. +// pTarget->addDep( pNewTarget ); + } + // else + // { + buildTargetTree( r, pNewTarget, *m, pMaster, lNewIns ); + // } + } + + return; + } + } + if( !pNewTarget ) + { + //sio << "Incomplete tree created, trying to find purpose for \"" // << sInput << "\"." << sio.nl; - return; - } + return; + } } void Context::attachDefaults() { - for( TargetHash::iterator i = hTarget.begin(); i; i++ ) - { - if( !(*i)->hasProfile("clean") ) - { - (*i)->addProfile( Profile::genDefaultClean() ); - } - } + for( TargetHash::iterator i = hTarget.begin(); i; i++ ) + { + if( !(*i)->hasProfile("clean") ) + { + (*i)->addProfile( Profile::genDefaultClean() ); + } + } } void Context::genDefaultActions() { - if( !hAction.has("all") ) - { - addAction( Action::genDefaultAll() ); - } - if( !hAction.has("clean") ) - { - addAction( Action::genDefaultClean() ); - } - if( !hAction.has("clean-all") ) - { - addAction( Action::genDefaultCleanAll() ); - } - if( !hAction.has("default") ) - { - addAction( Action::genDefaultDefault() ); - } + if( !hAction.has("all") ) + { + addAction( Action::genDefaultAll() ); + } + if( !hAction.has("clean") ) + { + addAction( Action::genDefaultClean() ); + } + if( !hAction.has("clean-all") ) + { + addAction( Action::genDefaultCleanAll() ); + } + if( !hAction.has("default") ) + { + addAction( Action::genDefaultDefault() ); + } } void Context::writeTargetDot() { - Bu::Hash hDone; - sio << "digraph {" << sio.nl - << "\trankdir=LR;" << sio.nl; - for( TargetHash::iterator i = hTarget.begin(); i; i++ ) - { - if( hDone.has( (ptrdiff_t)*i ) ) - continue; - hDone.insert( (ptrdiff_t)*i, true ); - for( StrList::const_iterator l = (*i)->getOutputList().begin(); - l; l++ ) - { - for( StrList::const_iterator k = (*i)->getInputList().begin(); - k; k++ ) - { - sio << "\t\"" << *k << "\" -> \"" + Bu::Hash hDone; + sio << "digraph {" << sio.nl + << "\trankdir=LR;" << sio.nl; + for( TargetHash::iterator i = hTarget.begin(); i; i++ ) + { + if( hDone.has( (ptrdiff_t)*i ) ) + continue; + hDone.insert( (ptrdiff_t)*i, true ); + for( StrList::const_iterator l = (*i)->getOutputList().begin(); + l; l++ ) + { + for( StrList::const_iterator k = (*i)->getInputList().begin(); + k; k++ ) + { + sio << "\t\"" << *k << "\" -> \"" << *l << "\";" << sio.nl; - } - for( StrList::const_iterator k = (*i)->getRequiresList().begin(); - k; k++ ) - { - sio << "\t\"" << *k << "\" -> \"" + } + for( StrList::const_iterator k = (*i)->getRequiresList().begin(); + k; k++ ) + { + sio << "\t\"" << *k << "\" -> \"" << *l << "\" [color=red];" << sio.nl; - } - } + } + } - } - sio << "}" << sio.nl; + } + sio << "}" << sio.nl; } void Context::setView( View *pNewView ) { - delete pView; - pView = pNewView; + delete pView; + pView = pNewView; } View *Context::getView() { - return pView; + return pView; } Bu::Formatter &operator<<( Bu::Formatter &f, const Context &c ) { - f << "Variables: " << c.sVars << f.nl; - f << "Targets: " << c.hTarget << f.nl; - f << "Rules: " << c.hRule << f.nl; + f << "Variables: " << c.sVars << f.nl; + f << "Targets: " << c.hTarget << f.nl; + f << "Rules: " << c.hRule << f.nl; - return f; + return f; } void Context::printBasicInfo() { - sio << "Available actions:" << sio.nl << "\t"; - for( ActionHash::iterator i = hAction.begin(); i; i++ ) - { - if( i != hAction.begin() ) - sio << ", "; - sio << i.getKey(); - } - - TargetList lTargets = getExplicitTargets(); - sio << sio.nl << sio.nl << "Available targets:" << sio.nl << "\t"; - for( TargetList::iterator i = lTargets.begin(); i; i++ ) - { - if( i != lTargets.begin() ) - sio << ", "; - for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ ) - { - if( j != (*i)->getOutputList().begin() ) - sio << ", "; - sio << (*j); - } - } - - sio << sio.nl << sio.nl; + sio << "Available actions:" << sio.nl << "\t"; + for( ActionHash::iterator i = hAction.begin(); i; i++ ) + { + if( i != hAction.begin() ) + sio << ", "; + sio << i.getKey(); + } + + TargetList lTargets = getExplicitTargets(); + sio << sio.nl << sio.nl << "Available targets:" << sio.nl << "\t"; + for( TargetList::iterator i = lTargets.begin(); i; i++ ) + { + if( i != lTargets.begin() ) + sio << ", "; + for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ ) + { + if( j != (*i)->getOutputList().begin() ) + sio << ", "; + sio << (*j); + } + } + + sio << sio.nl << sio.nl; } diff --git a/src/context.h b/src/context.h index 4eaeb25..8dc7527 100644 --- a/src/context.h +++ b/src/context.h @@ -14,86 +14,86 @@ class View; class Context { - friend Bu::Formatter &operator<<( Bu::Formatter &f, const Context &c ); + friend Bu::Formatter &operator<<( Bu::Formatter &f, const Context &c ); public: - Context(); - virtual ~Context(); - - void addTarget( Target *pTarget ); - void addRule( Rule *pRule ); - void addFunction( Function *pFunction ); - void addVariable( const Bu::String &sName, const Variable &vValue ); - void addAction( Action *pAction ); - Action *getAction( const Bu::String &sName ); - - void addTargetToTag( Target *pTarget, const Bu::String &sTag ); - void addTargetToTags( Target *pTarget, const StrList &sTags ); - TargetList &getTag( const Bu::String &sTag ); - - Variable &getVariable( const Bu::String &sName ); - void delVariable( const Bu::String &sName ); - - void pushScope(); - void pushScope( const VarHash &hNewVars ); - VarHash &getScope(); - void popScope(); - - Variable call( const Bu::String &sName, Variable &input, VarList lParams ); - - Bu::String expand( const Bu::String &sIn ); - - Target *getTarget( const Bu::String &sOutput ); - TargetList getExplicitTargets(); - - /** - * This function actually builds the dependancy tree, and is responsible - * for creating all of the auto-generated targets that are required by the - * explicitly created targets. - */ - void buildTargetTree( class Runner &r ); - - /** - * This is done as a final step, it goes through all targets and - * attaches things that they should have even if they haven't defined them, - * like a clean profile, they'll get that even if they haven't added one of - * their own. The defaults in this routine are added only if they aren't - * already defined in the target. It should be excetued after - * buildTargetTree, which means it doesn't need to affect rules. - */ - void attachDefaults(); - - /** - * This function generates some default actions if they don't already - * exist, pretty straight forward, it will create all, clean, and default - * (default is the same as all). - */ - void genDefaultActions(); - - void writeTargetDot(); - - void setView( View *pNewView ); - View *getView(); - - void printBasicInfo(); + Context(); + virtual ~Context(); + + void addTarget( Target *pTarget ); + void addRule( Rule *pRule ); + void addFunction( Function *pFunction ); + void addVariable( const Bu::String &sName, const Variable &vValue ); + void addAction( Action *pAction ); + Action *getAction( const Bu::String &sName ); + + void addTargetToTag( Target *pTarget, const Bu::String &sTag ); + void addTargetToTags( Target *pTarget, const StrList &sTags ); + TargetList &getTag( const Bu::String &sTag ); + + Variable &getVariable( const Bu::String &sName ); + void delVariable( const Bu::String &sName ); + + void pushScope(); + void pushScope( const VarHash &hNewVars ); + VarHash &getScope(); + void popScope(); + + Variable call( const Bu::String &sName, Variable &input, VarList lParams ); + + Bu::String expand( const Bu::String &sIn ); + + Target *getTarget( const Bu::String &sOutput ); + TargetList getExplicitTargets(); + + /** + * This function actually builds the dependancy tree, and is responsible + * for creating all of the auto-generated targets that are required by the + * explicitly created targets. + */ + void buildTargetTree( class Runner &r ); + + /** + * This is done as a final step, it goes through all targets and + * attaches things that they should have even if they haven't defined them, + * like a clean profile, they'll get that even if they haven't added one of + * their own. The defaults in this routine are added only if they aren't + * already defined in the target. It should be excetued after + * buildTargetTree, which means it doesn't need to affect rules. + */ + void attachDefaults(); + + /** + * This function generates some default actions if they don't already + * exist, pretty straight forward, it will create all, clean, and default + * (default is the same as all). + */ + void genDefaultActions(); + + void writeTargetDot(); + + void setView( View *pNewView ); + View *getView(); + + void printBasicInfo(); private: - void buildTargetTree( class Runner &r, class Target *pTarget, const Bu::String &sInput, class Rule *pMaster, StrList &lNewIns ); + void buildTargetTree( class Runner &r, class Target *pTarget, const Bu::String &sInput, class Rule *pMaster, StrList &lNewIns ); private: - typedef Bu::Hash TargetHash; - typedef Bu::Hash RuleHash; - typedef Bu::Hash FunctionHash; - typedef Bu::Hash ActionHash; - typedef Bu::List ScopeStack; - typedef Bu::Hash TagHash; - - TargetHash hTarget; - RuleHash hRule; - FunctionHash hFunction; - ScopeStack sVars; - ActionHash hAction; - TagHash hTag; - View *pView; + typedef Bu::Hash TargetHash; + typedef Bu::Hash RuleHash; + typedef Bu::Hash FunctionHash; + typedef Bu::Hash ActionHash; + typedef Bu::List ScopeStack; + typedef Bu::Hash TagHash; + + TargetHash hTarget; + RuleHash hRule; + FunctionHash hFunction; + ScopeStack sVars; + ActionHash hAction; + TagHash hTag; + View *pView; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Context &c ); diff --git a/src/filemgr.cpp b/src/filemgr.cpp index 00f0410..16f2ba7 100644 --- a/src/filemgr.cpp +++ b/src/filemgr.cpp @@ -1,46 +1,46 @@ #include "filemgr.h" FileMgr::FileMgr() : - iNextId( 1 ) + iNextId( 1 ) { } FileMgr::~FileMgr() { - for( FileHash::iterator i = hFile.begin(); i; i++ ) - { - delete *i; - } + for( FileHash::iterator i = hFile.begin(); i; i++ ) + { + delete *i; + } } int FileMgr::open( const Bu::String &sPath, int iMode ) { - hFile.insert( iNextId, new Bu::File( sPath, iMode ) ); - return iNextId++; + hFile.insert( iNextId, new Bu::File( sPath, iMode ) ); + return iNextId++; } Bu::File &FileMgr::get( int iId ) { - try - { - return *hFile.get( iId ); - } - catch(...) - { - throw Bu::ExceptionBase("Invalid file handle accessed."); - } + try + { + return *hFile.get( iId ); + } + catch(...) + { + throw Bu::ExceptionBase("Invalid file handle accessed."); + } } void FileMgr::close( int iId ) { - try - { - delete hFile.get( iId ); - hFile.erase( iId ); - } - catch(...) - { - throw Bu::ExceptionBase("Invalid file handle accessed."); - } + try + { + delete hFile.get( iId ); + hFile.erase( iId ); + } + catch(...) + { + throw Bu::ExceptionBase("Invalid file handle accessed."); + } } diff --git a/src/filemgr.h b/src/filemgr.h index 517e784..5241eee 100644 --- a/src/filemgr.h +++ b/src/filemgr.h @@ -9,18 +9,18 @@ class FileMgr : public Bu::Singleton { friend class Bu::Singleton; private: - FileMgr(); - virtual ~FileMgr(); + FileMgr(); + virtual ~FileMgr(); public: - int open( const Bu::String &sPath, int iMode ); - Bu::File &get( int iId ); - void close( int iId ); + int open( const Bu::String &sPath, int iMode ); + Bu::File &get( int iId ); + void close( int iId ); private: - typedef Bu::Hash FileHash; - FileHash hFile; - int iNextId; + typedef Bu::Hash FileHash; + FileHash hFile; + int iNextId; }; #endif diff --git a/src/function.cpp b/src/function.cpp index f73f576..c4bf966 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -1,7 +1,7 @@ #include "function.h" Function::Function() : - pContext( NULL ) + pContext( NULL ) { } @@ -11,6 +11,6 @@ Function::~Function() void Function::setContext( class Context *p ) { - pContext = p; + pContext = p; } diff --git a/src/function.h b/src/function.h index 1575bfd..71d87ba 100644 --- a/src/function.h +++ b/src/function.h @@ -7,17 +7,17 @@ class Function { public: - Function(); - virtual ~Function(); + Function(); + virtual ~Function(); - virtual Bu::String getName() const=0; + virtual Bu::String getName() const=0; - virtual Variable call( Variable &input, VarList lParams )=0; + virtual Variable call( Variable &input, VarList lParams )=0; - void setContext( class Context *p ); + void setContext( class Context *p ); protected: - class Context *pContext; + class Context *pContext; }; #endif diff --git a/src/functionast.cpp b/src/functionast.cpp index d4ec61f..437ddd4 100644 --- a/src/functionast.cpp +++ b/src/functionast.cpp @@ -8,12 +8,12 @@ using namespace Bu; FunctionAst::FunctionAst( const AstBranch *pRoot, class Runner *pRunner ) : - pRoot( pRoot ), - pRunner( pRunner ) + pRoot( pRoot ), + pRunner( pRunner ) { - sName = dynamic_cast( - *(*pRoot->getBranchBegin()).begin() - )->getStrValue(); + sName = dynamic_cast( + *(*pRoot->getBranchBegin()).begin() + )->getStrValue(); } FunctionAst::~FunctionAst() @@ -22,26 +22,26 @@ FunctionAst::~FunctionAst() Bu::String FunctionAst::getName() const { - return sName; + return sName; } Variable FunctionAst::call( Variable &input, VarList lParams ) { - pContext->pushScope(); - - AstBranch::NodeList::const_iterator vName = - (*(pRoot->getBranchBegin()+1)).begin(); - VarList::iterator vValue = lParams.begin(); - for( ; vName && vValue; vName++, vValue++ ) - { - pContext->addVariable( - dynamic_cast(*vName)->getStrValue(), - *vValue - ); - } - pContext->addVariable("INPUT", input ); - Variable vRet = pRunner->run( (*(pRoot->getBranchBegin()+2)).begin() ); - pContext->popScope(); - return vRet; + pContext->pushScope(); + + AstBranch::NodeList::const_iterator vName = + (*(pRoot->getBranchBegin()+1)).begin(); + VarList::iterator vValue = lParams.begin(); + for( ; vName && vValue; vName++, vValue++ ) + { + pContext->addVariable( + dynamic_cast(*vName)->getStrValue(), + *vValue + ); + } + pContext->addVariable("INPUT", input ); + Variable vRet = pRunner->run( (*(pRoot->getBranchBegin()+2)).begin() ); + pContext->popScope(); + return vRet; } diff --git a/src/functionast.h b/src/functionast.h index 0de564f..75af751 100644 --- a/src/functionast.h +++ b/src/functionast.h @@ -6,16 +6,16 @@ class FunctionAst : public Function { public: - FunctionAst( const class AstBranch *pRoot, class Runner *pRunner ); - virtual ~FunctionAst(); + FunctionAst( const class AstBranch *pRoot, class Runner *pRunner ); + virtual ~FunctionAst(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); private: - Bu::String sName; - const class AstBranch *pRoot; - class Runner *pRunner; + Bu::String sName; + const class AstBranch *pRoot; + class Runner *pRunner; }; #endif diff --git a/src/functionclose.cpp b/src/functionclose.cpp index d652913..173e224 100644 --- a/src/functionclose.cpp +++ b/src/functionclose.cpp @@ -3,7 +3,7 @@ #include PluginInterface3( pluginFunctionClose, close, FunctionClose, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionClose::FunctionClose() { @@ -15,12 +15,12 @@ FunctionClose::~FunctionClose() Bu::String FunctionClose::getName() const { - return "close"; + return "close"; } Variable FunctionClose::call( Variable &input, VarList ) { - FileMgr::getInstance().close( (ptrdiff_t)input.getOpaque() ); - return Variable(); + FileMgr::getInstance().close( (ptrdiff_t)input.getOpaque() ); + return Variable(); } diff --git a/src/functionclose.h b/src/functionclose.h index 0a30427..225dca0 100644 --- a/src/functionclose.h +++ b/src/functionclose.h @@ -6,11 +6,11 @@ class FunctionClose : public Function { public: - FunctionClose(); - virtual ~FunctionClose(); + FunctionClose(); + virtual ~FunctionClose(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functiondirname.cpp b/src/functiondirname.cpp index 7fc3bf2..c33771e 100644 --- a/src/functiondirname.cpp +++ b/src/functiondirname.cpp @@ -2,7 +2,7 @@ #include PluginInterface3( pluginFunctionDirName, dirName, FunctionDirName, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionDirName::FunctionDirName() { @@ -14,29 +14,29 @@ FunctionDirName::~FunctionDirName() Bu::String FunctionDirName::getName() const { - return "dirName"; + return "dirName"; } Variable FunctionDirName::call( Variable &input, VarList /*lParams*/ ) { - Bu::String sFile; - sFile = input.getString(); + Bu::String sFile; + sFile = input.getString(); - Bu::String::const_iterator i = sFile.begin(); - Bu::String::const_iterator io; - for(;;) - { - Bu::String::const_iterator b = i.find('/'); - if( !b ) - { - return Variable( Bu::String( sFile.begin(), io ) ); - } - io = b; - i = b+1; - if( !i ) - { - return Variable( Bu::String( sFile.begin(), io ) ); - } - } + Bu::String::const_iterator i = sFile.begin(); + Bu::String::const_iterator io; + for(;;) + { + Bu::String::const_iterator b = i.find('/'); + if( !b ) + { + return Variable( Bu::String( sFile.begin(), io ) ); + } + io = b; + i = b+1; + if( !i ) + { + return Variable( Bu::String( sFile.begin(), io ) ); + } + } } diff --git a/src/functiondirname.h b/src/functiondirname.h index 45a943e..763e243 100644 --- a/src/functiondirname.h +++ b/src/functiondirname.h @@ -6,11 +6,11 @@ class FunctionDirName : public Function { public: - FunctionDirName(); - virtual ~FunctionDirName(); + FunctionDirName(); + virtual ~FunctionDirName(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functiondirs.cpp b/src/functiondirs.cpp index e3b88dd..8ed0442 100644 --- a/src/functiondirs.cpp +++ b/src/functiondirs.cpp @@ -7,7 +7,7 @@ #include PluginInterface3( pluginFunctionDirs, dirs, FunctionDirs, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionDirs::FunctionDirs() { @@ -19,47 +19,47 @@ FunctionDirs::~FunctionDirs() Bu::String FunctionDirs::getName() const { - return "dirs"; + return "dirs"; } Variable FunctionDirs::call( Variable &/*input*/, VarList lParams ) { - glob_t globbuf; + glob_t globbuf; - int flags = 0; + int flags = 0; - for( VarList::const_iterator i = lParams.begin(); i; i++ ) - { - switch( (*i).getType() ) - { - case Variable::typeString: - glob( (*i).getString().getStr(), flags, NULL, &globbuf ); - flags |= GLOB_APPEND; - break; + for( VarList::const_iterator i = lParams.begin(); i; i++ ) + { + switch( (*i).getType() ) + { + case Variable::typeString: + glob( (*i).getString().getStr(), flags, NULL, &globbuf ); + flags |= GLOB_APPEND; + break; - case Variable::typeList: - throw Bu::ExceptionBase("Lists not supported in glob yet."); - break; + case Variable::typeList: + throw Bu::ExceptionBase("Lists not supported in glob yet."); + break; - default: - throw Bu::ExceptionBase( - "Cannot use a non-string or non-list as a parameter to glob" - ); - break; - } - } + default: + throw Bu::ExceptionBase( + "Cannot use a non-string or non-list as a parameter to glob" + ); + break; + } + } - Variable vRet( Variable::typeList ); - struct stat s; - for( size_t j = 0; j < globbuf.gl_pathc; j++ ) - { - stat( globbuf.gl_pathv[j], &s ); - if( S_ISDIR( s.st_mode ) ) - vRet.append( globbuf.gl_pathv[j] ); - } + Variable vRet( Variable::typeList ); + struct stat s; + for( size_t j = 0; j < globbuf.gl_pathc; j++ ) + { + stat( globbuf.gl_pathv[j], &s ); + if( S_ISDIR( s.st_mode ) ) + vRet.append( globbuf.gl_pathv[j] ); + } - globfree( &globbuf ); + globfree( &globbuf ); - return vRet; + return vRet; } diff --git a/src/functiondirs.h b/src/functiondirs.h index 899c1ac..60522dc 100644 --- a/src/functiondirs.h +++ b/src/functiondirs.h @@ -6,11 +6,11 @@ class FunctionDirs : public Function { public: - FunctionDirs(); - virtual ~FunctionDirs(); + FunctionDirs(); + virtual ~FunctionDirs(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionexecute.cpp b/src/functionexecute.cpp index 070ca53..cad65fa 100644 --- a/src/functionexecute.cpp +++ b/src/functionexecute.cpp @@ -8,7 +8,7 @@ using namespace Bu; #include PluginInterface3( pluginFunctionExecute, execute, FunctionExecute, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionExecute::FunctionExecute() { @@ -20,54 +20,54 @@ FunctionExecute::~FunctionExecute() Bu::String FunctionExecute::getName() const { - return "execute"; + return "execute"; } Variable FunctionExecute::call( Variable &/*input*/, VarList lParams ) { - // TODO This is lame, really lame, we need to exec on our own and process - // output appropriately. - pContext->getView()->cmdStarted( lParams.first().getString() ); - Process pCmd( Process::Both, "/bin/bash", "/bin/bash", "-c", - lParams.first().getString().getStr(), NULL ); - String sStdOut, sStdErr; - do - { - char buf[4096]; - bool out, err; - pCmd.select( out, err ); - if( err ) - { - int iRead = pCmd.readErr( buf, 4096 ); - sStdErr.append( buf, iRead ); - //sio << "Read " << iRead << " bytes of stderr." << sio.nl; - } - if( out ) - { - int iRead = pCmd.read( buf, 4096 ); - sStdOut.append( buf, iRead ); - //sio << "Read " << iRead << " bytes of stdout." << sio.nl; - } - } - while( pCmd.isRunning() ); + // TODO This is lame, really lame, we need to exec on our own and process + // output appropriately. + pContext->getView()->cmdStarted( lParams.first().getString() ); + Process pCmd( Process::Both, "/bin/bash", "/bin/bash", "-c", + lParams.first().getString().getStr(), NULL ); + String sStdOut, sStdErr; + do + { + char buf[4096]; + bool out, err; + pCmd.select( out, err ); + if( err ) + { + int iRead = pCmd.readErr( buf, 4096 ); + sStdErr.append( buf, iRead ); + //sio << "Read " << iRead << " bytes of stderr." << sio.nl; + } + if( out ) + { + int iRead = pCmd.read( buf, 4096 ); + sStdOut.append( buf, iRead ); + //sio << "Read " << iRead << " bytes of stdout." << sio.nl; + } + } + while( pCmd.isRunning() ); - pContext->getView()->cmdFinished( - sStdOut, sStdErr, pCmd.childExitStatus() - ); - if( pCmd.childExited() ) - { - if( pCmd.childExitStatus() != 0 ) - { - throw Bu::ExceptionBase("Command exited with errorcode %d.", pCmd.childExitStatus() ); - } - } - else - { - pContext->getView()->cmdFinished( - sStdOut, sStdErr, pCmd.childExitStatus() - ); - throw Bu::ExceptionBase("Command Failed"); - } - return Variable( pCmd.childExitStatus() ); + pContext->getView()->cmdFinished( + sStdOut, sStdErr, pCmd.childExitStatus() + ); + if( pCmd.childExited() ) + { + if( pCmd.childExitStatus() != 0 ) + { + throw Bu::ExceptionBase("Command exited with errorcode %d.", pCmd.childExitStatus() ); + } + } + else + { + pContext->getView()->cmdFinished( + sStdOut, sStdErr, pCmd.childExitStatus() + ); + throw Bu::ExceptionBase("Command Failed"); + } + return Variable( pCmd.childExitStatus() ); } diff --git a/src/functionexecute.h b/src/functionexecute.h index b70a2c5..3066440 100644 --- a/src/functionexecute.h +++ b/src/functionexecute.h @@ -6,11 +6,11 @@ class FunctionExecute : public Function { public: - FunctionExecute(); - virtual ~FunctionExecute(); + FunctionExecute(); + virtual ~FunctionExecute(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functionexists.cpp b/src/functionexists.cpp index 5c71874..0fad1e1 100644 --- a/src/functionexists.cpp +++ b/src/functionexists.cpp @@ -4,7 +4,7 @@ #include PluginInterface3( pluginFunctionExists, exists, FunctionExists, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionExists::FunctionExists() { @@ -16,23 +16,23 @@ FunctionExists::~FunctionExists() Bu::String FunctionExists::getName() const { - return "exists"; + return "exists"; } Variable FunctionExists::call( Variable &input, VarList lParams ) { - Bu::String sFile; - if( input.getType() != Variable::typeNone ) - { - sFile = input.toString(); - } - else - { - sFile = lParams.first().toString(); - } - if( access( sFile.getStr(), F_OK ) == 0 ) - return Variable( true ); - else - return Variable( false ); + Bu::String sFile; + if( input.getType() != Variable::typeNone ) + { + sFile = input.toString(); + } + else + { + sFile = lParams.first().toString(); + } + if( access( sFile.getStr(), F_OK ) == 0 ) + return Variable( true ); + else + return Variable( false ); } diff --git a/src/functionexists.h b/src/functionexists.h index f4629fb..e2e7688 100644 --- a/src/functionexists.h +++ b/src/functionexists.h @@ -6,11 +6,11 @@ class FunctionExists : public Function { public: - FunctionExists(); - virtual ~FunctionExists(); + FunctionExists(); + virtual ~FunctionExists(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionfilename.cpp b/src/functionfilename.cpp index 40f0048..36cb61c 100644 --- a/src/functionfilename.cpp +++ b/src/functionfilename.cpp @@ -2,7 +2,7 @@ #include PluginInterface3( pluginFunctionFileName, fileName, FunctionFileName, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionFileName::FunctionFileName() { @@ -14,27 +14,27 @@ FunctionFileName::~FunctionFileName() Bu::String FunctionFileName::getName() const { - return "fileName"; + return "fileName"; } Variable FunctionFileName::call( Variable &input, VarList /*lParams*/ ) { - Bu::String sFile; - sFile = input.getString(); + Bu::String sFile; + sFile = input.getString(); - Bu::String::const_iterator i = sFile.begin(); - for(;;) - { - Bu::String::const_iterator b = i.find('/'); - if( !b ) - { - return Variable( Bu::String( i ) ); - } - i = b+1; - if( !i ) - { - return Variable( Bu::String( i ) ); - } - } + Bu::String::const_iterator i = sFile.begin(); + for(;;) + { + Bu::String::const_iterator b = i.find('/'); + if( !b ) + { + return Variable( Bu::String( i ) ); + } + i = b+1; + if( !i ) + { + return Variable( Bu::String( i ) ); + } + } } diff --git a/src/functionfilename.h b/src/functionfilename.h index 8f1cd13..2bead88 100644 --- a/src/functionfilename.h +++ b/src/functionfilename.h @@ -6,11 +6,11 @@ class FunctionFileName : public Function { public: - FunctionFileName(); - virtual ~FunctionFileName(); + FunctionFileName(); + virtual ~FunctionFileName(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionfiles.cpp b/src/functionfiles.cpp index cd5b122..051ee3a 100644 --- a/src/functionfiles.cpp +++ b/src/functionfiles.cpp @@ -7,7 +7,7 @@ #include PluginInterface3( pluginFunctionFiles, files, FunctionFiles, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionFiles::FunctionFiles() { @@ -19,47 +19,47 @@ FunctionFiles::~FunctionFiles() Bu::String FunctionFiles::getName() const { - return "files"; + return "files"; } Variable FunctionFiles::call( Variable &/*input*/, VarList lParams ) { - glob_t globbuf; + glob_t globbuf; - int flags = 0; + int flags = 0; - for( VarList::const_iterator i = lParams.begin(); i; i++ ) - { - switch( (*i).getType() ) - { - case Variable::typeString: - glob( (*i).getString().getStr(), flags, NULL, &globbuf ); - flags |= GLOB_APPEND; - break; + for( VarList::const_iterator i = lParams.begin(); i; i++ ) + { + switch( (*i).getType() ) + { + case Variable::typeString: + glob( (*i).getString().getStr(), flags, NULL, &globbuf ); + flags |= GLOB_APPEND; + break; - case Variable::typeList: - throw Bu::ExceptionBase("Lists not supported in glob yet."); - break; + case Variable::typeList: + throw Bu::ExceptionBase("Lists not supported in glob yet."); + break; - default: - throw Bu::ExceptionBase( - "Cannot use a non-string or non-list as a parameter to glob" - ); - break; - } - } + default: + throw Bu::ExceptionBase( + "Cannot use a non-string or non-list as a parameter to glob" + ); + break; + } + } - Variable vRet( Variable::typeList ); - struct stat s; - for( size_t j = 0; j < globbuf.gl_pathc; j++ ) - { - stat( globbuf.gl_pathv[j], &s ); - if( S_ISREG( s.st_mode ) ) - vRet.append( globbuf.gl_pathv[j] ); - } + Variable vRet( Variable::typeList ); + struct stat s; + for( size_t j = 0; j < globbuf.gl_pathc; j++ ) + { + stat( globbuf.gl_pathv[j], &s ); + if( S_ISREG( s.st_mode ) ) + vRet.append( globbuf.gl_pathv[j] ); + } - globfree( &globbuf ); + globfree( &globbuf ); - return vRet; + return vRet; } diff --git a/src/functionfiles.h b/src/functionfiles.h index 3828c3e..af04132 100644 --- a/src/functionfiles.h +++ b/src/functionfiles.h @@ -6,11 +6,11 @@ class FunctionFiles : public Function { public: - FunctionFiles(); - virtual ~FunctionFiles(); + FunctionFiles(); + virtual ~FunctionFiles(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functiongetmakedeps.cpp b/src/functiongetmakedeps.cpp index fda6aa2..22cf4aa 100644 --- a/src/functiongetmakedeps.cpp +++ b/src/functiongetmakedeps.cpp @@ -8,7 +8,7 @@ using namespace Bu; #include PluginInterface3( pluginFunctionGetMakeDeps, getMakeDeps, FunctionGetMakeDeps, - Function, "Mike Buland", 0, 1 ); + Function, "Mike Buland", 0, 1 ); FunctionGetMakeDeps::FunctionGetMakeDeps() { @@ -20,50 +20,50 @@ FunctionGetMakeDeps::~FunctionGetMakeDeps() Bu::String FunctionGetMakeDeps::getName() const { - return "getMakeDeps"; + return "getMakeDeps"; } Variable FunctionGetMakeDeps::call( Variable &/*input*/, VarList lParams ) { - pContext->getView()->cmdStarted( lParams.first().getString().getStr() ); - Process p( Process::StdOut, "/bin/bash", "/bin/bash", "-c", - lParams.first().getString().getStr(), NULL ); + pContext->getView()->cmdStarted( lParams.first().getString().getStr() ); + Process p( Process::StdOut, "/bin/bash", "/bin/bash", "-c", + lParams.first().getString().getStr(), NULL ); - // Gather all data from the command. - Bu::String sBuf; - do - { - char buf[4096]; - int iRead = p.read( buf, 4096 ); - sBuf.append( buf, iRead ); - } - while( !p.isEos() ); - - pContext->getView()->cmdFinished( "", "", p.childExitStatus() ); - - Variable vRet( Variable::typeList ); + // Gather all data from the command. + Bu::String sBuf; + do + { + char buf[4096]; + int iRead = p.read( buf, 4096 ); + sBuf.append( buf, iRead ); + } + while( !p.isEos() ); + + pContext->getView()->cmdFinished( "", "", p.childExitStatus() ); + + Variable vRet( Variable::typeList ); - Bu::String::iterator i, j; - i = sBuf.find(':')+2; - while( i ) - { - // Find whitespace at the end of the word, this one is easy, there's - // always a space after a word - for( j = i; j && *j != ' ' && *j != '\n' && *j != '\r'; j++ ) { } - - Bu::String sTmp( i, j ); - vRet.append( sTmp ); - - // Find the begining of the next word, trickier, we don't want to go - // off the end, and we need to skip \ chars at the ends of lines, right - // now this is too stupid to do that, so it may not work on windows. - // TODO: perhaps make this only skip \ chars at the ends of lines, - // we'll see if it matters. - for( i = j+1; - i && (*i == ' ' || *i == '\\' || *i == '\n' || *i == '\r'); i++ ) - { } - } + Bu::String::iterator i, j; + i = sBuf.find(':')+2; + while( i ) + { + // Find whitespace at the end of the word, this one is easy, there's + // always a space after a word + for( j = i; j && *j != ' ' && *j != '\n' && *j != '\r'; j++ ) { } + + Bu::String sTmp( i, j ); + vRet.append( sTmp ); + + // Find the begining of the next word, trickier, we don't want to go + // off the end, and we need to skip \ chars at the ends of lines, right + // now this is too stupid to do that, so it may not work on windows. + // TODO: perhaps make this only skip \ chars at the ends of lines, + // we'll see if it matters. + for( i = j+1; + i && (*i == ' ' || *i == '\\' || *i == '\n' || *i == '\r'); i++ ) + { } + } - return vRet; + return vRet; } diff --git a/src/functiongetmakedeps.h b/src/functiongetmakedeps.h index 566a96b..caa0952 100644 --- a/src/functiongetmakedeps.h +++ b/src/functiongetmakedeps.h @@ -6,11 +6,11 @@ class FunctionGetMakeDeps : public Function { public: - FunctionGetMakeDeps(); - virtual ~FunctionGetMakeDeps(); + FunctionGetMakeDeps(); + virtual ~FunctionGetMakeDeps(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functionmatches.cpp b/src/functionmatches.cpp index 0f76316..b5b5b64 100644 --- a/src/functionmatches.cpp +++ b/src/functionmatches.cpp @@ -4,7 +4,7 @@ #include PluginInterface3( pluginFunctionMatches, matches, FunctionMatches, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionMatches::FunctionMatches() { @@ -16,130 +16,130 @@ FunctionMatches::~FunctionMatches() Bu::String FunctionMatches::getName() const { - return "matches"; + return "matches"; } bool FunctionMatches::globcmp( const Bu::String &sTxt, const Bu::String &sMatches ) { - Bu::String::const_iterator t, g; - t = sTxt.begin(); - g = sMatches.begin(); + Bu::String::const_iterator t, g; + t = sTxt.begin(); + g = sMatches.begin(); - while( g && t ) - { - switch( *g ) - { - case '*': - // First, if the * is at the end, then we do match, it doesn't - // matter what is in sTxt - if( !(g+1) ) - return true; - // Now attempt to scan for the remainder as a matched set - { - Bu::String::const_iterator tn = t+1, gn = g+1, gi=g+1; - bool bFoundMatch = false; - while( tn && gn ) - { - if( *gn == '*' ) - { - g = gn; - t = tn; - break; - } - if( *tn == *gn ) - { - g = gn; - t = tn; - tn++; - gn++; - bFoundMatch = true; - } - else - { - gn = gi; - tn++; - bFoundMatch = false; - } - } - if( bFoundMatch == false ) - return false; - if( !tn && !gn && bFoundMatch ) - return true; - } - break; + while( g && t ) + { + switch( *g ) + { + case '*': + // First, if the * is at the end, then we do match, it doesn't + // matter what is in sTxt + if( !(g+1) ) + return true; + // Now attempt to scan for the remainder as a matched set + { + Bu::String::const_iterator tn = t+1, gn = g+1, gi=g+1; + bool bFoundMatch = false; + while( tn && gn ) + { + if( *gn == '*' ) + { + g = gn; + t = tn; + break; + } + if( *tn == *gn ) + { + g = gn; + t = tn; + tn++; + gn++; + bFoundMatch = true; + } + else + { + gn = gi; + tn++; + bFoundMatch = false; + } + } + if( bFoundMatch == false ) + return false; + if( !tn && !gn && bFoundMatch ) + return true; + } + break; - case '?': - // Don't bother checking. - t++; - g++; - break; + case '?': + // Don't bother checking. + t++; + g++; + break; - default: - if( *t != *g ) - return false; - t++; - g++; - break; - } - } - if( t || (g && *g != '*') ) - return false; - return true; + default: + if( *t != *g ) + return false; + t++; + g++; + break; + } + } + if( t || (g && *g != '*') ) + return false; + return true; } bool FunctionMatches::matchlist( const Bu::String &sTxt, VarList &lParams ) { - for( VarList::iterator i = lParams.begin(); i; i++ ) - { - if( (*i).getType() == Variable::typeList ) - { - for( VarList::iterator j = (*i).begin(); j; j++ ) - { - if( globcmp( sTxt, (*j).toString() ) ) - return true; - } - } - else - { - if( globcmp( sTxt, (*i).toString() ) ) - return true; - } - } - return false; + for( VarList::iterator i = lParams.begin(); i; i++ ) + { + if( (*i).getType() == Variable::typeList ) + { + for( VarList::iterator j = (*i).begin(); j; j++ ) + { + if( globcmp( sTxt, (*j).toString() ) ) + return true; + } + } + else + { + if( globcmp( sTxt, (*i).toString() ) ) + return true; + } + } + return false; } Variable FunctionMatches::call( Variable &input, VarList lParams ) { - switch( input.getType() ) - { - case Variable::typeString: - { - Bu::String sTxt = input.getString(); - return Variable( matchlist( sTxt, lParams ) ); - } - break; + switch( input.getType() ) + { + case Variable::typeString: + { + Bu::String sTxt = input.getString(); + return Variable( matchlist( sTxt, lParams ) ); + } + break; - case Variable::typeList: - { - Variable vRet( Variable::typeList ); - for( VarList::iterator i = input.begin(); i; i++ ) - { - if( (*i).getType() != Variable::typeString ) - continue; - Bu::String sTxt = (*i).getString(); - if( matchlist( sTxt, lParams ) ) - vRet.append( *i ); - } - return vRet; - } - break; + case Variable::typeList: + { + Variable vRet( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( (*i).getType() != Variable::typeString ) + continue; + Bu::String sTxt = (*i).getString(); + if( matchlist( sTxt, lParams ) ) + vRet.append( *i ); + } + return vRet; + } + break; - default: - throw Bu::ExceptionBase("You can only use a string or list as the " - "input to matches."); - break; - } + default: + throw Bu::ExceptionBase("You can only use a string or list as the " + "input to matches."); + break; + } - return Variable(); + return Variable(); } diff --git a/src/functionmatches.h b/src/functionmatches.h index 92ffe26..b569e0b 100644 --- a/src/functionmatches.h +++ b/src/functionmatches.h @@ -6,17 +6,17 @@ class FunctionMatches : public Function { public: - FunctionMatches(); - virtual ~FunctionMatches(); + FunctionMatches(); + virtual ~FunctionMatches(); - /** - * Really basic globbing function, it doesn't handle character classes, - * just * and ?. We can expand on it later, it may be handy. - */ - bool globcmp( const Bu::String &sTxt, const Bu::String &sMatches ); - bool matchlist( const Bu::String &sTxt, VarList &lParams ); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + /** + * Really basic globbing function, it doesn't handle character classes, + * just * and ?. We can expand on it later, it may be handy. + */ + bool globcmp( const Bu::String &sTxt, const Bu::String &sMatches ); + bool matchlist( const Bu::String &sTxt, VarList &lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionopen.cpp b/src/functionopen.cpp index 4026a8c..075f43c 100644 --- a/src/functionopen.cpp +++ b/src/functionopen.cpp @@ -3,7 +3,7 @@ #include PluginInterface3( pluginFunctionOpen, open, FunctionOpen, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionOpen::FunctionOpen() { @@ -15,28 +15,28 @@ FunctionOpen::~FunctionOpen() Bu::String FunctionOpen::getName() const { - return "open"; + return "open"; } Variable FunctionOpen::call( Variable &input, VarList lParams ) { - if( lParams.getSize() != 2 ) - { - throw Bu::ExceptionBase( - "open takes two parameters, filename and mode." - ); - } - Bu::String sMode = lParams.last().toString().toLower(); - int iMode = Bu::File::Create; - if( sMode.find('w') ) - iMode |= Bu::File::Write; - if( sMode.find('r') ) - iMode |= Bu::File::Read; - Variable vRet( - (void *)FileMgr::getInstance().open( - lParams.first().toString(), iMode - ) - ); - return vRet; + if( lParams.getSize() != 2 ) + { + throw Bu::ExceptionBase( + "open takes two parameters, filename and mode." + ); + } + Bu::String sMode = lParams.last().toString().toLower(); + int iMode = Bu::File::Create; + if( sMode.find('w') ) + iMode |= Bu::File::Write; + if( sMode.find('r') ) + iMode |= Bu::File::Read; + Variable vRet( + (void *)FileMgr::getInstance().open( + lParams.first().toString(), iMode + ) + ); + return vRet; } diff --git a/src/functionopen.h b/src/functionopen.h index 5ab3cab..27a18ad 100644 --- a/src/functionopen.h +++ b/src/functionopen.h @@ -6,11 +6,11 @@ class FunctionOpen : public Function { public: - FunctionOpen(); - virtual ~FunctionOpen(); + FunctionOpen(); + virtual ~FunctionOpen(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionplugger.cpp b/src/functionplugger.cpp index 1f2bcf5..3999021 100644 --- a/src/functionplugger.cpp +++ b/src/functionplugger.cpp @@ -25,46 +25,46 @@ extern Bu::PluginInfo pluginFunctionUnique; FunctionPlugger::FunctionPlugger() { - registerBuiltinPlugin( &pluginFunctionDirName ); - registerBuiltinPlugin( &pluginFunctionDirs ); - registerBuiltinPlugin( &pluginFunctionExecute ); - registerBuiltinPlugin( &pluginFunctionExists ); - registerBuiltinPlugin( &pluginFunctionFileName ); - registerBuiltinPlugin( &pluginFunctionFiles ); - registerBuiltinPlugin( &pluginFunctionGetMakeDeps ); - registerBuiltinPlugin( &pluginFunctionMatches ); - registerBuiltinPlugin( &pluginFunctionReplace ); - registerBuiltinPlugin( &pluginFunctionTargets ); - registerBuiltinPlugin( &pluginFunctionToString ); - registerBuiltinPlugin( &pluginFunctionUnlink ); - registerBuiltinPlugin( &pluginFunctionRegEx ); - registerBuiltinPlugin( &pluginFunctionRange ); - registerBuiltinPlugin( &pluginFunctionOpen ); - registerBuiltinPlugin( &pluginFunctionClose ); - registerBuiltinPlugin( &pluginFunctionRead ); - registerBuiltinPlugin( &pluginFunctionWrite ); - registerBuiltinPlugin( &pluginFunctionUnique ); + registerBuiltinPlugin( &pluginFunctionDirName ); + registerBuiltinPlugin( &pluginFunctionDirs ); + registerBuiltinPlugin( &pluginFunctionExecute ); + registerBuiltinPlugin( &pluginFunctionExists ); + registerBuiltinPlugin( &pluginFunctionFileName ); + registerBuiltinPlugin( &pluginFunctionFiles ); + registerBuiltinPlugin( &pluginFunctionGetMakeDeps ); + registerBuiltinPlugin( &pluginFunctionMatches ); + registerBuiltinPlugin( &pluginFunctionReplace ); + registerBuiltinPlugin( &pluginFunctionTargets ); + registerBuiltinPlugin( &pluginFunctionToString ); + registerBuiltinPlugin( &pluginFunctionUnlink ); + registerBuiltinPlugin( &pluginFunctionRegEx ); + registerBuiltinPlugin( &pluginFunctionRange ); + registerBuiltinPlugin( &pluginFunctionOpen ); + registerBuiltinPlugin( &pluginFunctionClose ); + registerBuiltinPlugin( &pluginFunctionRead ); + registerBuiltinPlugin( &pluginFunctionWrite ); + registerBuiltinPlugin( &pluginFunctionUnique ); - DIR *dir = opendir("/usr/lib/build"); - if( !dir ) - return; - struct dirent *de; - while( (de = readdir( dir )) ) - { - if( strncmp("pluginFunction", de->d_name, 15 ) ) - continue; + DIR *dir = opendir("/usr/lib/build"); + if( !dir ) + return; + struct dirent *de; + while( (de = readdir( dir )) ) + { + if( strncmp("pluginFunction", de->d_name, 15 ) ) + continue; - Bu::String sFile("/usr/lib/build/"); - sFile += de->d_name; - char *s = de->d_name; - for(; *s && *s != '.'; s++ ) { } - registerExternalPlugin( - sFile, - Bu::String( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name ) - ); - } + Bu::String sFile("/usr/lib/build/"); + sFile += de->d_name; + char *s = de->d_name; + for(; *s && *s != '.'; s++ ) { } + registerExternalPlugin( + sFile, + Bu::String( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name ) + ); + } - closedir( dir ); + closedir( dir ); } FunctionPlugger::~FunctionPlugger() diff --git a/src/functionplugger.h b/src/functionplugger.h index 30022f6..12655f7 100644 --- a/src/functionplugger.h +++ b/src/functionplugger.h @@ -6,12 +6,12 @@ #include class FunctionPlugger : public Bu::Plugger, - public Bu::Singleton + public Bu::Singleton { friend class Bu::Singleton; private: - FunctionPlugger(); - virtual ~FunctionPlugger(); + FunctionPlugger(); + virtual ~FunctionPlugger(); }; #endif diff --git a/src/functionrange.cpp b/src/functionrange.cpp index f45cf0e..e6267cf 100644 --- a/src/functionrange.cpp +++ b/src/functionrange.cpp @@ -2,7 +2,7 @@ #include PluginInterface3( pluginFunctionRange, range, FunctionRange, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionRange::FunctionRange() { @@ -14,58 +14,58 @@ FunctionRange::~FunctionRange() Bu::String FunctionRange::getName() const { - return "range"; + return "range"; } Variable FunctionRange::call( Variable &input, VarList lParams ) { - Variable vRet( Variable::typeList ); - int iLow = 1; - int iHigh = 1; - int iStep = 1; - if( lParams.getSize() == 1 ) - { - iHigh = lParams.first().toInt(); - } - else if( lParams.getSize() == 2 ) - { - iLow = lParams.first().toInt(); - iHigh = lParams.last().toInt(); - } - else if( lParams.getSize() == 3 ) - { - VarList::iterator i = lParams.begin(); - iLow = (*i).toInt(); - i++; - iHigh = (*i).toInt(); - i++; - iStep = (*i).toInt(); - } - if( iStep == 0 ) - throw Bu::ExceptionBase("Step cannot be zero."); + Variable vRet( Variable::typeList ); + int iLow = 1; + int iHigh = 1; + int iStep = 1; + if( lParams.getSize() == 1 ) + { + iHigh = lParams.first().toInt(); + } + else if( lParams.getSize() == 2 ) + { + iLow = lParams.first().toInt(); + iHigh = lParams.last().toInt(); + } + else if( lParams.getSize() == 3 ) + { + VarList::iterator i = lParams.begin(); + iLow = (*i).toInt(); + i++; + iHigh = (*i).toInt(); + i++; + iStep = (*i).toInt(); + } + if( iStep == 0 ) + throw Bu::ExceptionBase("Step cannot be zero."); - if( iHigh < iLow ) - { - if( iStep > 0 ) - throw Bu::ExceptionBase( - "If start is less than end then step must be negative."); - for( int j = iLow; j >= iHigh; j += iStep ) - { - vRet.append( Variable( j ) ); - } - } - else - { - if( iStep < 0 ) - throw Bu::ExceptionBase( - "If start is more than end then step must be positive."); - for( int j = iLow; j <= iHigh; j += iStep ) - { - vRet.append( Variable( j ) ); - } - } + if( iHigh < iLow ) + { + if( iStep > 0 ) + throw Bu::ExceptionBase( + "If start is less than end then step must be negative."); + for( int j = iLow; j >= iHigh; j += iStep ) + { + vRet.append( Variable( j ) ); + } + } + else + { + if( iStep < 0 ) + throw Bu::ExceptionBase( + "If start is more than end then step must be positive."); + for( int j = iLow; j <= iHigh; j += iStep ) + { + vRet.append( Variable( j ) ); + } + } - return vRet; + return vRet; } diff --git a/src/functionrange.h b/src/functionrange.h index 1f6d8c5..ddd7650 100644 --- a/src/functionrange.h +++ b/src/functionrange.h @@ -6,11 +6,11 @@ class FunctionRange : public Function { public: - FunctionRange(); - virtual ~FunctionRange(); + FunctionRange(); + virtual ~FunctionRange(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionread.cpp b/src/functionread.cpp index b9c8397..a59519c 100644 --- a/src/functionread.cpp +++ b/src/functionread.cpp @@ -3,7 +3,7 @@ #include PluginInterface3( pluginFunctionRead, read, FunctionRead, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionRead::FunctionRead() { @@ -15,26 +15,26 @@ FunctionRead::~FunctionRead() Bu::String FunctionRead::getName() const { - return "read"; + return "read"; } Variable FunctionRead::call( Variable &input, VarList lParams ) { - Variable vRet; - if( lParams.getSize() == 1 ) - { - int iSize = lParams.first().toInt(); - Bu::String sBuf( iSize ); - sBuf.resize( - FileMgr::getInstance().get( (ptrdiff_t)input.getOpaque() ).read( - sBuf.getStr(), iSize - ) - ); - vRet = sBuf; - return vRet; - } - throw Bu::ExceptionBase( - "read takes zero or one parameters." - ); + Variable vRet; + if( lParams.getSize() == 1 ) + { + int iSize = lParams.first().toInt(); + Bu::String sBuf( iSize ); + sBuf.resize( + FileMgr::getInstance().get( (ptrdiff_t)input.getOpaque() ).read( + sBuf.getStr(), iSize + ) + ); + vRet = sBuf; + return vRet; + } + throw Bu::ExceptionBase( + "read takes zero or one parameters." + ); } diff --git a/src/functionread.h b/src/functionread.h index 39bf32e..8bb6e8a 100644 --- a/src/functionread.h +++ b/src/functionread.h @@ -6,11 +6,11 @@ class FunctionRead : public Function { public: - FunctionRead(); - virtual ~FunctionRead(); + FunctionRead(); + virtual ~FunctionRead(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/functionregex.cpp b/src/functionregex.cpp index c80f527..007b3fe 100644 --- a/src/functionregex.cpp +++ b/src/functionregex.cpp @@ -3,7 +3,7 @@ #include #include PluginInterface3( pluginFunctionRegEx, regex, FunctionRegEx, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionRegEx::FunctionRegEx() { @@ -15,112 +15,112 @@ FunctionRegEx::~FunctionRegEx() Bu::String FunctionRegEx::getName() const { - return "regex"; + return "regex"; } Variable FunctionRegEx::call( Variable &input, VarList lParams ) { - if( lParams.getSize() == 1 ) - { - Bu::RegEx re( lParams.first().getString() ); - switch( input.getType() ) - { - case Variable::typeString: - return re.execute( input.getString() ); + if( lParams.getSize() == 1 ) + { + Bu::RegEx re( lParams.first().getString() ); + switch( input.getType() ) + { + case Variable::typeString: + return re.execute( input.getString() ); - case Variable::typeList: - { - Variable vOut( Variable::typeList ); - for( VarList::iterator i = input.begin(); i; i++ ) - { - if( re.execute( (*i).toString() ) ) - vOut.append( *i ); - } - return vOut; - } - break; + case Variable::typeList: + { + Variable vOut( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( re.execute( (*i).toString() ) ) + vOut.append( *i ); + } + return vOut; + } + break; - default: - break; - } - } - else if( lParams.getSize() == 2 ) - { - Bu::RegEx re( lParams.first().getString() ); - Bu::String sPat = lParams.last().getString(); - switch( input.getType() ) - { - case Variable::typeString: - if( re.execute( input.getString() ) ) - { - return replace( re, input.getString(), sPat ); - } - else - { - return input; - } - break; + default: + break; + } + } + else if( lParams.getSize() == 2 ) + { + Bu::RegEx re( lParams.first().getString() ); + Bu::String sPat = lParams.last().getString(); + switch( input.getType() ) + { + case Variable::typeString: + if( re.execute( input.getString() ) ) + { + return replace( re, input.getString(), sPat ); + } + else + { + return input; + } + break; - case Variable::typeList: - { - Variable vOut( Variable::typeList ); - for( VarList::iterator i = input.begin(); i; i++ ) - { - if( re.execute( (*i).toString() ) ) - vOut.append( replace( re, (*i).toString(), sPat ) ); - else - vOut.append( *i ); - } - return vOut; - } - break; + case Variable::typeList: + { + Variable vOut( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( re.execute( (*i).toString() ) ) + vOut.append( replace( re, (*i).toString(), sPat ) ); + else + vOut.append( *i ); + } + return vOut; + } + break; - default: - break; - } - } - throw Bu::ExceptionBase( - "regex does not work on non-string or non-list types."); + default: + break; + } + } + throw Bu::ExceptionBase( + "regex does not work on non-string or non-list types."); } Bu::String FunctionRegEx::replace( Bu::RegEx &re, const Bu::String &sSrc, - const Bu::String &sPat ) + const Bu::String &sPat ) { - Bu::String sOut; + Bu::String sOut; - int iStart, iEnd; - re.getSubStringRange( 0, iStart, iEnd ); // Get the range of the full match - - if( iStart > 0 ) - sOut.append( sSrc, 0, iStart ); + int iStart, iEnd; + re.getSubStringRange( 0, iStart, iEnd ); // Get the range of the full match + + if( iStart > 0 ) + sOut.append( sSrc, 0, iStart ); - for( Bu::String::const_iterator i = sPat.begin(); i; i++ ) - { - if( *i == '\\' ) - { - i++; - if( *i <= '9' && *i >= '0' ) - { - int iInd = *i-'0'; - if( iInd < re.getNumSubStrings() ) - sOut += re.getSubString( iInd ); - } - else - { - sOut += *i; - } - } - else - { - sOut += *i; - } - } + for( Bu::String::const_iterator i = sPat.begin(); i; i++ ) + { + if( *i == '\\' ) + { + i++; + if( *i <= '9' && *i >= '0' ) + { + int iInd = *i-'0'; + if( iInd < re.getNumSubStrings() ) + sOut += re.getSubString( iInd ); + } + else + { + sOut += *i; + } + } + else + { + sOut += *i; + } + } - if( iEnd < sSrc.getSize() ) - { - sOut.append( sSrc, iEnd, -1 ); - } + if( iEnd < sSrc.getSize() ) + { + sOut.append( sSrc, iEnd, -1 ); + } - return sOut; + return sOut; } diff --git a/src/functionregex.h b/src/functionregex.h index edc21c6..1ded9ab 100644 --- a/src/functionregex.h +++ b/src/functionregex.h @@ -5,20 +5,20 @@ namespace Bu { - class RegEx; + class RegEx; } class FunctionRegEx : public Function { public: - FunctionRegEx(); - virtual ~FunctionRegEx(); + FunctionRegEx(); + virtual ~FunctionRegEx(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); - Bu::String replace( Bu::RegEx &re, const Bu::String &sSrc, - const Bu::String &sPat ); + Bu::String replace( Bu::RegEx &re, const Bu::String &sSrc, + const Bu::String &sPat ); }; #endif diff --git a/src/functionreplace.cpp b/src/functionreplace.cpp index 589ef55..6cf455e 100644 --- a/src/functionreplace.cpp +++ b/src/functionreplace.cpp @@ -2,7 +2,7 @@ #include PluginInterface3( pluginFunctionReplace, replace, FunctionReplace, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionReplace::FunctionReplace() { @@ -14,38 +14,38 @@ FunctionReplace::~FunctionReplace() Bu::String FunctionReplace::getName() const { - return "replace"; + return "replace"; } Variable FunctionReplace::call( Variable &input, VarList lParams ) { - Bu::String sA, sB; - sA = lParams.first().getString(); - sB = lParams.last().getString(); - switch( input.getType() ) - { - case Variable::typeString: - { - Variable vOut( input.getString().replace( sA, sB ) ); - return vOut; - } - break; - - case Variable::typeList: - { - Variable vOut( Variable::typeList ); - for( VarList::iterator i = input.begin(); i; i++ ) - { - vOut.append( (*i).getString().replace( sA, sB ) ); - } - return vOut; - } - break; - - default: - break; - } - throw Bu::ExceptionBase( - "replace does not work on non-string or non-list types."); + Bu::String sA, sB; + sA = lParams.first().getString(); + sB = lParams.last().getString(); + switch( input.getType() ) + { + case Variable::typeString: + { + Variable vOut( input.getString().replace( sA, sB ) ); + return vOut; + } + break; + + case Variable::typeList: + { + Variable vOut( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + vOut.append( (*i).getString().replace( sA, sB ) ); + } + return vOut; + } + break; + + default: + break; + } + throw Bu::ExceptionBase( + "replace does not work on non-string or non-list types."); } diff --git a/src/functionreplace.h b/src/functionreplace.h index 05442d8..dbecef6 100644 --- a/src/functionreplace.h +++ b/src/functionreplace.h @@ -6,11 +6,11 @@ class FunctionReplace : public Function { public: - FunctionReplace(); - virtual ~FunctionReplace(); + FunctionReplace(); + virtual ~FunctionReplace(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functiontargets.cpp b/src/functiontargets.cpp index 3fd145e..ad92376 100644 --- a/src/functiontargets.cpp +++ b/src/functiontargets.cpp @@ -4,7 +4,7 @@ #include PluginInterface3( pluginFunctionTargets, targets, FunctionTargets, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionTargets::FunctionTargets() { @@ -16,28 +16,28 @@ FunctionTargets::~FunctionTargets() Bu::String FunctionTargets::getName() const { - return "targets"; + return "targets"; } Variable FunctionTargets::call( Variable &/*input*/, VarList lParams ) { - Variable vRet( Variable::typeList ); - TargetList lTrg; - if( lParams.getSize() == 0 ) - { - lTrg = pContext->getExplicitTargets(); - } - else - { - lTrg = pContext->getTag( lParams.first().toString() ); - } - for( TargetList::const_iterator i = lTrg.begin(); i; i++ ) - { - for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ ) - { - vRet.append( *j ); - } - } - return vRet; + Variable vRet( Variable::typeList ); + TargetList lTrg; + if( lParams.getSize() == 0 ) + { + lTrg = pContext->getExplicitTargets(); + } + else + { + lTrg = pContext->getTag( lParams.first().toString() ); + } + for( TargetList::const_iterator i = lTrg.begin(); i; i++ ) + { + for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ ) + { + vRet.append( *j ); + } + } + return vRet; } diff --git a/src/functiontargets.h b/src/functiontargets.h index a6e7d21..6b892e2 100644 --- a/src/functiontargets.h +++ b/src/functiontargets.h @@ -6,11 +6,11 @@ class FunctionTargets : public Function { public: - FunctionTargets(); - virtual ~FunctionTargets(); + FunctionTargets(); + virtual ~FunctionTargets(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp index bc5db6c..b3ffb5b 100644 --- a/src/functiontostring.cpp +++ b/src/functiontostring.cpp @@ -6,7 +6,7 @@ using namespace Bu; #include PluginInterface3( pluginFunctionToString, toString, FunctionToString, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionToString::FunctionToString() { @@ -18,37 +18,37 @@ FunctionToString::~FunctionToString() Bu::String FunctionToString::getName() const { - return "toString"; + return "toString"; } Variable FunctionToString::call( Variable &input, VarList lParams ) { - Bu::String sStr; - Bu::String sSep; - if( lParams.getSize() == 0 ) - { - sSep = " "; - } - else - { - sSep = lParams.first().getString(); - } - switch( input.getType() ) - { - case Variable::typeString: - return input; - - case Variable::typeList: - for( VarList::iterator i = input.begin(); i; i++ ) - { - if( i != input.begin() ) - sStr += sSep; - sStr += (*i).getString(); - } - return Variable( sStr ); - - default: - return Variable( input.getString() ); - } + Bu::String sStr; + Bu::String sSep; + if( lParams.getSize() == 0 ) + { + sSep = " "; + } + else + { + sSep = lParams.first().getString(); + } + switch( input.getType() ) + { + case Variable::typeString: + return input; + + case Variable::typeList: + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( i != input.begin() ) + sStr += sSep; + sStr += (*i).getString(); + } + return Variable( sStr ); + + default: + return Variable( input.getString() ); + } } diff --git a/src/functiontostring.h b/src/functiontostring.h index c5bc50d..177ecc6 100644 --- a/src/functiontostring.h +++ b/src/functiontostring.h @@ -6,11 +6,11 @@ class FunctionToString : public Function { public: - FunctionToString(); - virtual ~FunctionToString(); + FunctionToString(); + virtual ~FunctionToString(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functionunique.cpp b/src/functionunique.cpp index ca2461f..f12712e 100644 --- a/src/functionunique.cpp +++ b/src/functionunique.cpp @@ -3,7 +3,7 @@ #include #include PluginInterface3( pluginFunctionUnique, unique, FunctionUnique, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionUnique::FunctionUnique() { @@ -15,33 +15,33 @@ FunctionUnique::~FunctionUnique() Bu::String FunctionUnique::getName() const { - return "unique"; + return "unique"; } Variable FunctionUnique::call( Variable &input, VarList lParams ) { - if( lParams.getSize() > 0 ) - throw Bu::ExceptionBase("Unique does not take any parameters."); - if( input.getType() != Variable::typeList ) - throw Bu::ExceptionBase("unique does not work on non-list types."); + if( lParams.getSize() > 0 ) + throw Bu::ExceptionBase("Unique does not take any parameters."); + if( input.getType() != Variable::typeList ) + throw Bu::ExceptionBase("unique does not work on non-list types."); - Bu::Hash hHas; + Bu::Hash hHas; - Variable vOut( Variable::typeList ); - for( VarList::iterator i = input.begin(); i; i++ ) - { - if( (*i).getType() != Variable::typeString ) - continue; + Variable vOut( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( (*i).getType() != Variable::typeString ) + continue; - Bu::String s = (*i).getString(); - - if( hHas.has( s ) ) - continue; + Bu::String s = (*i).getString(); + + if( hHas.has( s ) ) + continue; - hHas.insert( s, true ); - vOut.append( *i ); - } + hHas.insert( s, true ); + vOut.append( *i ); + } - return vOut; + return vOut; } diff --git a/src/functionunique.h b/src/functionunique.h index 6bc4225..cb7132a 100644 --- a/src/functionunique.h +++ b/src/functionunique.h @@ -6,11 +6,11 @@ class FunctionUnique : public Function { public: - FunctionUnique(); - virtual ~FunctionUnique(); + FunctionUnique(); + virtual ~FunctionUnique(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functionunlink.cpp b/src/functionunlink.cpp index 48985bb..590833c 100644 --- a/src/functionunlink.cpp +++ b/src/functionunlink.cpp @@ -7,7 +7,7 @@ using namespace Bu; #include PluginInterface3( pluginFunctionUnlink, unlink, FunctionUnlink, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionUnlink::FunctionUnlink() { @@ -19,37 +19,37 @@ FunctionUnlink::~FunctionUnlink() Bu::String FunctionUnlink::getName() const { - return "unlink"; + return "unlink"; } Variable FunctionUnlink::call( Variable &/*input*/, VarList lParams ) { - //sio << "Unlink called: " << lParams << sio.nl; - for( VarList::iterator p = lParams.begin(); p; p++ ) - { - switch( (*p).getType() ) - { - case Variable::typeString: - //sio << " xx> " << (*p).getString() << sio.nl; - unlink( (*p).getString().getStr() ); - break; - - case Variable::typeList: - //sio << " xx>"; - for( VarList::iterator i = (*p).begin(); i; i++ ) - { - //sio << " " << (*i).getString(); - unlink( (*i).getString().getStr() ); - } - //sio << sio.nl; - break; - - default: - throw Bu::ExceptionBase("Hey, wrong type passed."); - break; - } - } - - return Variable(); + //sio << "Unlink called: " << lParams << sio.nl; + for( VarList::iterator p = lParams.begin(); p; p++ ) + { + switch( (*p).getType() ) + { + case Variable::typeString: + //sio << " xx> " << (*p).getString() << sio.nl; + unlink( (*p).getString().getStr() ); + break; + + case Variable::typeList: + //sio << " xx>"; + for( VarList::iterator i = (*p).begin(); i; i++ ) + { + //sio << " " << (*i).getString(); + unlink( (*i).getString().getStr() ); + } + //sio << sio.nl; + break; + + default: + throw Bu::ExceptionBase("Hey, wrong type passed."); + break; + } + } + + return Variable(); } diff --git a/src/functionunlink.h b/src/functionunlink.h index ab95615..ef1c4e4 100644 --- a/src/functionunlink.h +++ b/src/functionunlink.h @@ -6,11 +6,11 @@ class FunctionUnlink : public Function { public: - FunctionUnlink(); - virtual ~FunctionUnlink(); + FunctionUnlink(); + virtual ~FunctionUnlink(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; #endif diff --git a/src/functionwrite.cpp b/src/functionwrite.cpp index 14a396a..4aee4e0 100644 --- a/src/functionwrite.cpp +++ b/src/functionwrite.cpp @@ -3,7 +3,7 @@ #include PluginInterface3( pluginFunctionWrite, write, FunctionWrite, Function, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); FunctionWrite::FunctionWrite() { @@ -15,20 +15,20 @@ FunctionWrite::~FunctionWrite() Bu::String FunctionWrite::getName() const { - return "write"; + return "write"; } Variable FunctionWrite::call( Variable &input, VarList lParams ) { - if( lParams.getSize() != 1 ) - { - throw Bu::ExceptionBase( - "write takes one parameter, the string to write." - ); - } - FileMgr::getInstance().get( (ptrdiff_t)input.getOpaque() ).write( - lParams.first().toString() - ); - return Variable(); + if( lParams.getSize() != 1 ) + { + throw Bu::ExceptionBase( + "write takes one parameter, the string to write." + ); + } + FileMgr::getInstance().get( (ptrdiff_t)input.getOpaque() ).write( + lParams.first().toString() + ); + return Variable(); } diff --git a/src/functionwrite.h b/src/functionwrite.h index 75b2283..6a7678d 100644 --- a/src/functionwrite.h +++ b/src/functionwrite.h @@ -6,11 +6,11 @@ class FunctionWrite : public Function { public: - FunctionWrite(); - virtual ~FunctionWrite(); + FunctionWrite(); + virtual ~FunctionWrite(); - virtual Bu::String getName() const; - virtual Variable call( Variable &input, VarList lParams ); + virtual Bu::String getName() const; + virtual Variable call( Variable &input, VarList lParams ); }; diff --git a/src/location.cpp b/src/location.cpp index 933379c..3dba48f 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -2,30 +2,30 @@ #include "build.tab.h" Location::Location() : - sFile("none"), - iStartRow( -1 ), - iStartCol( -1 ), - iEndRow( -1 ), - iEndCol( -1 ) + sFile("none"), + iStartRow( -1 ), + iStartCol( -1 ), + iEndRow( -1 ), + iEndCol( -1 ) { } Location::Location( struct YYLTYPE &loc ) : - sFile("???"), - iStartRow( loc.first_line ), - iStartCol( loc.first_column ), - iEndRow( loc.last_line ), - iEndCol( loc.last_column ) + sFile("???"), + iStartRow( loc.first_line ), + iStartCol( loc.first_column ), + iEndRow( loc.last_line ), + iEndCol( loc.last_column ) { } Location::Location( const Bu::String &sFile, int iStartRow, int iStartCol, - int iEndRow, int iEndCol ) : - sFile( sFile ), - iStartRow( iStartRow ), - iStartCol( iStartCol ), - iEndRow( iEndRow ), - iEndCol( iEndCol ) + int iEndRow, int iEndCol ) : + sFile( sFile ), + iStartRow( iStartRow ), + iStartCol( iStartCol ), + iEndRow( iEndRow ), + iEndCol( iEndCol ) { } diff --git a/src/location.h b/src/location.h index db329bb..a141073 100644 --- a/src/location.h +++ b/src/location.h @@ -6,18 +6,18 @@ class Location { public: - Location(); - Location( struct YYLTYPE &loc ); - Location( const Bu::String &sFile, int iStartRow, int iStartCol, - int iEndRow, int iEndCol ); - virtual ~Location(); + Location(); + Location( struct YYLTYPE &loc ); + Location( const Bu::String &sFile, int iStartRow, int iStartCol, + int iEndRow, int iEndCol ); + virtual ~Location(); private: - const Bu::String sFile; - int iStartRow; - int iStartCol; - int iEndRow; - int iEndCol; + const Bu::String sFile; + int iStartRow; + int iStartCol; + int iEndRow; + int iEndCol; }; #endif diff --git a/src/main.cpp b/src/main.cpp index caa33e6..ded91ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,290 +24,290 @@ using namespace Bu; class Options : public Bu::OptParser { public: - Options( int argc, char *argv[] ) : - sView("default"), - sAction("default"), - sConfig("default.bld"), - sCacheFile(".build_cache"), - bDot( false ), - bDebug( false ), - bAutoInclude( true ), - bAstDump( false ), - bEnviron( true ), - bCache( true ), - iInfoLevel( 0 ) - { - bool bClean = false; - addHelpBanner("build mark 3\n"); - - Bu::String sViews("Select a view from: "); - StrList lViews = ViewPlugger::getInstance().getPluginList(); - for( StrList::iterator i = lViews.begin(); i; i++ ) - { - if( i != lViews.begin() ) - sViews += ", "; - sViews += *i; - } - - addHelpBanner("The following options do things other than build:"); - addOption( iInfoLevel, 'i', "info", "Display some basic info about the " - "loaded build config, including available targets."); - addOption( slot( this, &Options::onListPlugins), "list-plugins", - "List all available plugins."); - addHelpOption(); - - addHelpBanner("\nThe following options control general execution:"); - addOption( sView, 'v', "view", sViews ); - addOption( sConfig, 'f', "file", "Select a different config file." ); - addOption( bClean, 'c', "Shorthand for running action 'clean'. If an " - "action is specified, this will modify it to run 'clean-action'."); - addOption( slot(this, &Options::onChdir), 'C', "chdir", - "Change to directory before doing anything else."); - addOption( sCacheFile, "cache", "Select a different cache file."); - addOption( bCache, "no-cache", "Disable using the cache."); - - addHelpBanner("\nThe following options control debugging:"); - addOption( bEnviron, "no-env", "Do not import environment variables."); - addOption( bDot, "dot", "Generate a dot chart after execution." ); - addOption( bDebug, "debug", - "Dump massive amounts of hard to read debugging data." ); - addOption( bAstDump, "debug-ast", - "Display the raw AST that is computed from parsing the input. " - "You should probably never ever use this, it'll scare you." - ); - - setHelpDefault( "view", "=[view]" ); - setHelpDefault( "file", "=[file]" ); - setHelpDefault( "cache", "=[file]" ); - setHelpDefault( "chdir", "=[dir]" ); - - setOverride( "no-env", "false" ); - setOverride( "dot", "true" ); - setOverride( "debug", "true" ); - setOverride( "debug-ast", "true" ); - setOverride( "info", "1" ); - setOverride( 'c', "true" ); - setOverride( "no-cache", "false" ); - - setNonOption( slot( this, &Options::onNonOption ) ); - - parse( argc, argv ); - - if( bClean ) - { - if( sAction == "default" ) - sAction = "clean"; - else - sAction.prepend("clean-"); - } - } - - virtual ~Options() - { - } - - int onChdir( StrArray sParams ) - { - if( sParams.getSize() == 0 ) - { - sio << "You must specify a directory name!" << sio.nl << sio.nl; - exit(2); - } - chdir( sParams[1].getStr() ); - return 1; - } - - int onNonOption( StrArray sParams ) - { - sAction = sParams[0]; - return 0; - } - - int onListPlugins( StrArray /*sParams*/ ) - { - StrList lViews = ViewPlugger::getInstance().getPluginList(); - sio << "Available view plugins:" << sio.nl << "\t"; - for( StrList::iterator i = lViews.begin(); i; i++ ) - { - if( i != lViews.begin() ) - sio << ", "; - sio << *i; - } - - StrList lFuncs = FunctionPlugger::getInstance().getPluginList(); - sio << sio.nl << sio.nl << "Available function plugins:" - << sio.nl << "\t"; - for( StrList::iterator i = lFuncs.begin(); i; i++ ) - { - if( i != lFuncs.begin() ) - sio << ", "; - sio << *i; - } - - StrList lConds = ConditionPlugger::getInstance().getPluginList(); - sio << sio.nl << sio.nl << "Available condition plugins:" - << sio.nl << "\t"; - for( StrList::iterator i = lConds.begin(); i; i++ ) - { - if( i != lConds.begin() ) - sio << ", "; - sio << *i; - } - - sio << sio.nl << sio.nl; - - return 0; - } - - Bu::String sView; - Bu::String sAction; - Bu::String sConfig; - Bu::String sCacheFile; - bool bDot; - bool bDebug; - bool bAutoInclude; - bool bAstDump; - bool bEnviron; - bool bCache; - int iInfoLevel; + Options( int argc, char *argv[] ) : + sView("default"), + sAction("default"), + sConfig("default.bld"), + sCacheFile(".build_cache"), + bDot( false ), + bDebug( false ), + bAutoInclude( true ), + bAstDump( false ), + bEnviron( true ), + bCache( true ), + iInfoLevel( 0 ) + { + bool bClean = false; + addHelpBanner("build mark 3\n"); + + Bu::String sViews("Select a view from: "); + StrList lViews = ViewPlugger::getInstance().getPluginList(); + for( StrList::iterator i = lViews.begin(); i; i++ ) + { + if( i != lViews.begin() ) + sViews += ", "; + sViews += *i; + } + + addHelpBanner("The following options do things other than build:"); + addOption( iInfoLevel, 'i', "info", "Display some basic info about the " + "loaded build config, including available targets."); + addOption( slot( this, &Options::onListPlugins), "list-plugins", + "List all available plugins."); + addHelpOption(); + + addHelpBanner("\nThe following options control general execution:"); + addOption( sView, 'v', "view", sViews ); + addOption( sConfig, 'f', "file", "Select a different config file." ); + addOption( bClean, 'c', "Shorthand for running action 'clean'. If an " + "action is specified, this will modify it to run 'clean-action'."); + addOption( slot(this, &Options::onChdir), 'C', "chdir", + "Change to directory before doing anything else."); + addOption( sCacheFile, "cache", "Select a different cache file."); + addOption( bCache, "no-cache", "Disable using the cache."); + + addHelpBanner("\nThe following options control debugging:"); + addOption( bEnviron, "no-env", "Do not import environment variables."); + addOption( bDot, "dot", "Generate a dot chart after execution." ); + addOption( bDebug, "debug", + "Dump massive amounts of hard to read debugging data." ); + addOption( bAstDump, "debug-ast", + "Display the raw AST that is computed from parsing the input. " + "You should probably never ever use this, it'll scare you." + ); + + setHelpDefault( "view", "=[view]" ); + setHelpDefault( "file", "=[file]" ); + setHelpDefault( "cache", "=[file]" ); + setHelpDefault( "chdir", "=[dir]" ); + + setOverride( "no-env", "false" ); + setOverride( "dot", "true" ); + setOverride( "debug", "true" ); + setOverride( "debug-ast", "true" ); + setOverride( "info", "1" ); + setOverride( 'c', "true" ); + setOverride( "no-cache", "false" ); + + setNonOption( slot( this, &Options::onNonOption ) ); + + parse( argc, argv ); + + if( bClean ) + { + if( sAction == "default" ) + sAction = "clean"; + else + sAction.prepend("clean-"); + } + } + + virtual ~Options() + { + } + + int onChdir( StrArray sParams ) + { + if( sParams.getSize() == 0 ) + { + sio << "You must specify a directory name!" << sio.nl << sio.nl; + exit(2); + } + chdir( sParams[1].getStr() ); + return 1; + } + + int onNonOption( StrArray sParams ) + { + sAction = sParams[0]; + return 0; + } + + int onListPlugins( StrArray /*sParams*/ ) + { + StrList lViews = ViewPlugger::getInstance().getPluginList(); + sio << "Available view plugins:" << sio.nl << "\t"; + for( StrList::iterator i = lViews.begin(); i; i++ ) + { + if( i != lViews.begin() ) + sio << ", "; + sio << *i; + } + + StrList lFuncs = FunctionPlugger::getInstance().getPluginList(); + sio << sio.nl << sio.nl << "Available function plugins:" + << sio.nl << "\t"; + for( StrList::iterator i = lFuncs.begin(); i; i++ ) + { + if( i != lFuncs.begin() ) + sio << ", "; + sio << *i; + } + + StrList lConds = ConditionPlugger::getInstance().getPluginList(); + sio << sio.nl << sio.nl << "Available condition plugins:" + << sio.nl << "\t"; + for( StrList::iterator i = lConds.begin(); i; i++ ) + { + if( i != lConds.begin() ) + sio << ", "; + sio << *i; + } + + sio << sio.nl << sio.nl; + + return 0; + } + + Bu::String sView; + Bu::String sAction; + Bu::String sConfig; + Bu::String sCacheFile; + bool bDot; + bool bDebug; + bool bAutoInclude; + bool bAstDump; + bool bEnviron; + bool bCache; + int iInfoLevel; }; int main( int argc, char *argv[] ) { - typedef Bu::List StrList; - StrList lShareList; - lShareList.append("/usr/share/build/").append("./share/"); - Ast ast; - Context cnt; - BuildParser bp( ast ); - - for( StrList::iterator i = lShareList.begin(); i; i++ ) - { - bp.addIncludePath( *i + "include"); - } - - Options opts( argc, argv ); - - try - { - cnt.setView( ViewPlugger::getInstance().instantiate( opts.sView ) ); - } - catch( Bu::HashException &e ) - { - sio << "Error: Invalid view specified, please choose from the " - "following choices:" << sio.nl << sio.nl << "\t"; - - StrList lViews = ViewPlugger::getInstance().getPluginList(); - for( StrList::iterator i = lViews.begin(); i; i++ ) - { - if( i != lViews.begin() ) - sio << ", "; - sio << *i; - } - sio << sio.nl << sio.nl; - return 1; - } - - if( opts.bCache ) - { - Cache::getInstance().bind( opts.sCacheFile ); - } - - // Load up the environment as vars. - if( opts.bEnviron ) - { - for( char **env = environ; *env; env++ ) - { - int iSplit; - for( iSplit = 0; (*env)[iSplit] != '='; iSplit++ ) { } - cnt.addVariable( - String( *env, iSplit ), - String( *env+iSplit+1 ) - ); - } - } - - if( opts.bAutoInclude ) - { - DIR *d; - Bu::String sAutoDir; - for( StrList::iterator i = lShareList.begin(); i; i++ ) - { - sAutoDir = *i + "autoinclude"; - d = opendir( sAutoDir.getStr() ); - if( d ) - break; - } - if( !d ) - { - cnt.getView()->sysWarning( - "Could not find an autoinclude directory." - ); - } - else - { - struct dirent *de; - while( (de = readdir( d )) ) - { - if( de->d_name[0] == '.' || (de->d_type != DT_REG) ) - continue; - //sio << "Auto-including: " << de->d_name << sio.nl; - bp.load( sAutoDir + "/" + de->d_name ); - } - } - } - - bp.load( opts.sConfig ); - - if( opts.bAstDump ) - { - sio << ast << sio.nl << sio.nl; - return 0; - } - -// sio << ast << sio.nl; - - Runner r( ast, cnt ); - r.initialize(); - - r.run(); - - switch( opts.iInfoLevel ) - { - case 0: - // Do nothing - break; - - case 1: - cnt.printBasicInfo(); - return 0; - } - - try - { - r.execAction( opts.sAction ); - } - catch( std::exception &e ) - { - cnt.getView()->sysError(e.what()); - } - catch( ... ) - { - cnt.getView()->sysError( - "Unknown error occured, this is probably bad..." - ); - } - - if( opts.bDot ) - { - cnt.writeTargetDot(); - } - - if( opts.bDebug ) - { - sio << "Final context:" << sio.nl << cnt << sio.nl << sio.nl; - } - - return 0; + typedef Bu::List StrList; + StrList lShareList; + lShareList.append("/usr/share/build/").append("./share/"); + Ast ast; + Context cnt; + BuildParser bp( ast ); + + for( StrList::iterator i = lShareList.begin(); i; i++ ) + { + bp.addIncludePath( *i + "include"); + } + + Options opts( argc, argv ); + + try + { + cnt.setView( ViewPlugger::getInstance().instantiate( opts.sView ) ); + } + catch( Bu::HashException &e ) + { + sio << "Error: Invalid view specified, please choose from the " + "following choices:" << sio.nl << sio.nl << "\t"; + + StrList lViews = ViewPlugger::getInstance().getPluginList(); + for( StrList::iterator i = lViews.begin(); i; i++ ) + { + if( i != lViews.begin() ) + sio << ", "; + sio << *i; + } + sio << sio.nl << sio.nl; + return 1; + } + + if( opts.bCache ) + { + Cache::getInstance().bind( opts.sCacheFile ); + } + + // Load up the environment as vars. + if( opts.bEnviron ) + { + for( char **env = environ; *env; env++ ) + { + int iSplit; + for( iSplit = 0; (*env)[iSplit] != '='; iSplit++ ) { } + cnt.addVariable( + String( *env, iSplit ), + String( *env+iSplit+1 ) + ); + } + } + + if( opts.bAutoInclude ) + { + DIR *d; + Bu::String sAutoDir; + for( StrList::iterator i = lShareList.begin(); i; i++ ) + { + sAutoDir = *i + "autoinclude"; + d = opendir( sAutoDir.getStr() ); + if( d ) + break; + } + if( !d ) + { + cnt.getView()->sysWarning( + "Could not find an autoinclude directory." + ); + } + else + { + struct dirent *de; + while( (de = readdir( d )) ) + { + if( de->d_name[0] == '.' || (de->d_type != DT_REG) ) + continue; + //sio << "Auto-including: " << de->d_name << sio.nl; + bp.load( sAutoDir + "/" + de->d_name ); + } + } + } + + bp.load( opts.sConfig ); + + if( opts.bAstDump ) + { + sio << ast << sio.nl << sio.nl; + return 0; + } + +// sio << ast << sio.nl; + + Runner r( ast, cnt ); + r.initialize(); + + r.run(); + + switch( opts.iInfoLevel ) + { + case 0: + // Do nothing + break; + + case 1: + cnt.printBasicInfo(); + return 0; + } + + try + { + r.execAction( opts.sAction ); + } + catch( std::exception &e ) + { + cnt.getView()->sysError(e.what()); + } + catch( ... ) + { + cnt.getView()->sysError( + "Unknown error occured, this is probably bad..." + ); + } + + if( opts.bDot ) + { + cnt.writeTargetDot(); + } + + if( opts.bDebug ) + { + sio << "Final context:" << sio.nl << cnt << sio.nl << sio.nl; + } + + return 0; } diff --git a/src/plugins/pluginConditionRandom.cpp b/src/plugins/pluginConditionRandom.cpp index 42a4e00..facd201 100644 --- a/src/plugins/pluginConditionRandom.cpp +++ b/src/plugins/pluginConditionRandom.cpp @@ -4,28 +4,28 @@ class ConditionRandom : public Condition { public: - ConditionRandom() - { - } + ConditionRandom() + { + } - virtual ~ConditionRandom() - { - } + virtual ~ConditionRandom() + { + } - virtual bool shouldExec( class Runner &, class Target & ) - { - if( (random()/(double)RAND_MAX) >= .5 ) - return true; - return false; - } + virtual bool shouldExec( class Runner &, class Target & ) + { + if( (random()/(double)RAND_MAX) >= .5 ) + return true; + return false; + } - virtual Condition *clone() - { - return new ConditionRandom(); - } + virtual Condition *clone() + { + return new ConditionRandom(); + } }; #include PluginInterface3( pluginConditionRandom, random, ConditionRandom, Condition, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); diff --git a/src/profile.cpp b/src/profile.cpp index a9c1d5b..20251c3 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -10,92 +10,92 @@ using namespace Bu; Profile::Profile( const class AstBranch *pRoot ) : - pRoot( pRoot ), - pCond( NULL ), - pAst( NULL ) + pRoot( pRoot ), + pCond( NULL ), + pAst( NULL ) { - sName = dynamic_cast( - (*pRoot->getBranchBegin()).first() - )->getStrValue(); + sName = dynamic_cast( + (*pRoot->getBranchBegin()).first() + )->getStrValue(); - setCondition(); + setCondition(); } Profile::Profile( const Profile &rSrc ) : - sName( rSrc.sName ), - pRoot( rSrc.pRoot ), - pCond( rSrc.pCond->clone() ), - pAst( NULL ) + sName( rSrc.sName ), + pRoot( rSrc.pRoot ), + pCond( rSrc.pCond->clone() ), + pAst( NULL ) { } Profile::~Profile() { - delete pAst; - pAst = NULL; + delete pAst; + pAst = NULL; } const Bu::String &Profile::getName() const { - return sName; + return sName; } const AstBranch *Profile::getRoot() const { - return pRoot; + return pRoot; } const Condition *Profile::getCond() const { - return pCond; + return pCond; } bool Profile::shouldExec( class Runner &r, class Target &rTarget ) const { - return pCond->shouldExec( r, rTarget ); + return pCond->shouldExec( r, rTarget ); } Profile *Profile::genDefaultClean() { - Ast *pAst = new Ast(); - pAst->addNode( AstNode::typeProfile ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "clean" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeCondition, "fileExists" ); - pAst->addNode( AstNode::typeFunction ); - pAst->openBranch(); - pAst->addNode( AstNode::typeString, "unlink" ); - pAst->openBranch(); - pAst->addNode( AstNode::typeVariable, "OUTPUT" ); - pAst->closeNode(); - pAst->closeNode(); - //pAst->closeNode(); - Profile *pRet = new Profile( - dynamic_cast(*pAst->getNodeBegin()) - ); - pRet->pAst = pAst; + Ast *pAst = new Ast(); + pAst->addNode( AstNode::typeProfile ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "clean" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeCondition, "fileExists" ); + pAst->addNode( AstNode::typeFunction ); + pAst->openBranch(); + pAst->addNode( AstNode::typeString, "unlink" ); + pAst->openBranch(); + pAst->addNode( AstNode::typeVariable, "OUTPUT" ); + pAst->closeNode(); + pAst->closeNode(); + //pAst->closeNode(); + Profile *pRet = new Profile( + dynamic_cast(*pAst->getNodeBegin()) + ); + pRet->pAst = pAst; - return pRet; + return pRet; } void Profile::setCondition() { - for( AstBranch::NodeList::const_iterator i = - (*(pRoot->getBranchBegin()+1)).begin(); i; i++ ) - { - if( (*i)->getType() == AstNode::typeCondition ) - { - Bu::String sCond = dynamic_cast(*i)->getStrValue(); - delete pCond; - pCond = ConditionPlugger::getInstance().instantiate( sCond ); - } - } + for( AstBranch::NodeList::const_iterator i = + (*(pRoot->getBranchBegin()+1)).begin(); i; i++ ) + { + if( (*i)->getType() == AstNode::typeCondition ) + { + Bu::String sCond = dynamic_cast(*i)->getStrValue(); + delete pCond; + pCond = ConditionPlugger::getInstance().instantiate( sCond ); + } + } - if( pCond == NULL ) - { - // The default condition - pCond = ConditionPlugger::getInstance().instantiate("fileTime"); - } + if( pCond == NULL ) + { + // The default condition + pCond = ConditionPlugger::getInstance().instantiate("fileTime"); + } } diff --git a/src/profile.h b/src/profile.h index 4f89306..8490121 100644 --- a/src/profile.h +++ b/src/profile.h @@ -6,25 +6,25 @@ class Profile { public: - Profile( const class AstBranch *pRoot ); - Profile( const Profile &rSrc ); - virtual ~Profile(); + Profile( const class AstBranch *pRoot ); + Profile( const Profile &rSrc ); + virtual ~Profile(); - const Bu::String &getName() const; - const class AstBranch *getRoot() const; - const class Condition *getCond() const; - bool shouldExec( class Runner &r, class Target &rTarget ) const; + const Bu::String &getName() const; + const class AstBranch *getRoot() const; + const class Condition *getCond() const; + bool shouldExec( class Runner &r, class Target &rTarget ) const; - static Profile *genDefaultClean(); + static Profile *genDefaultClean(); private: - void setCondition(); + void setCondition(); private: - Bu::String sName; - const class AstBranch *pRoot; - class Condition *pCond; - class Ast *pAst; + Bu::String sName; + const class AstBranch *pRoot; + class Condition *pCond; + class Ast *pAst; }; #endif diff --git a/src/rule.cpp b/src/rule.cpp index 81e775e..15b2388 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -12,8 +12,8 @@ using namespace Bu; Rule::Rule( const Bu::String &sName ) : - sName( sName ), - pInput( NULL ) + sName( sName ), + pInput( NULL ) { } @@ -23,146 +23,146 @@ Rule::~Rule() const Bu::String &Rule::getName() const { - return sName; + return sName; } void Rule::setInput( const AstBranch *pNewInput ) { - pInput = pNewInput; + pInput = pNewInput; } const AstBranch *Rule::getInput() const { - return pInput; + return pInput; } bool Rule::hasOutputs() const { - return !lOutput.isEmpty(); + return !lOutput.isEmpty(); } void Rule::addOutput( const AstBranch *pNewOutput ) { - lOutput.append( pNewOutput ); + lOutput.append( pNewOutput ); } void Rule::addProfile( const AstBranch *pProfRoot ) { - Profile *pProf = new Profile( pProfRoot ); - hProfiles.insert( pProf->getName(), pProf ); - /* - hProfiles.insert( - dynamic_cast( - (*pProfile->getBranchBegin()).first() - )->getStrValue(), - pProfile - ); - */ + Profile *pProf = new Profile( pProfRoot ); + hProfiles.insert( pProf->getName(), pProf ); + /* + hProfiles.insert( + dynamic_cast( + (*pProfile->getBranchBegin()).first() + )->getStrValue(), + pProfile + ); + */ } void Rule::prepTarget( class Target *pTarget ) { - pTarget->setDisplay( getDisplay() ); - for( ProfileHash::iterator i = hProfiles.begin(); i; i++ ) - { - pTarget->addProfile( *i ); - } - for( AstBranchList::iterator i = lRequires.begin(); i; i++ ) - { - pTarget->addRequires( *i ); - } + pTarget->setDisplay( getDisplay() ); + for( ProfileHash::iterator i = hProfiles.begin(); i; i++ ) + { + pTarget->addProfile( *i ); + } + for( AstBranchList::iterator i = lRequires.begin(); i; i++ ) + { + pTarget->addRequires( *i ); + } } Target *Rule::createTarget( class Runner &r, const Bu::String &sInput, - Target *pParent ) -{ - r.getContext().pushScope( pParent->getVars() ); - r.getContext().addVariable("INPUT", sInput ); - Target *pTrg = new Target( false ); - for( AstBranchList::iterator i = lOutput.begin(); i; i++ ) - { - Variable vOut = r.execExpr( - (*(*i)->getBranchBegin()).begin(), - Variable( sInput ) - ); - if( vOut.getType() == Variable::typeString ) - { - pTrg->addOutput( vOut.getString() ); - } - else if( vOut.getType() == Variable::typeList ) - { - for( VarList::iterator j = vOut.begin(); j; j++ ) - { - pTrg->addOutput( (*j).getString() ); - } - } - } - r.getContext().addVariable("OUTPUT", pTrg->getOutputList() ); - pTrg->addInput( sInput ); - pTrg->setDisplay( getDisplay() ); - for( ProfileHash::iterator i = hProfiles.begin(); i; i++ ) - { - pTrg->addProfile( *i ); - } - for( AstBranchList::iterator i = lRequires.begin(); i; i++ ) - { - pTrg->addRequires( *i ); - } - pTrg->setVars( r.getContext().getScope() ); - r.getContext().popScope(); - - return pTrg; + Target *pParent ) +{ + r.getContext().pushScope( pParent->getVars() ); + r.getContext().addVariable("INPUT", sInput ); + Target *pTrg = new Target( false ); + for( AstBranchList::iterator i = lOutput.begin(); i; i++ ) + { + Variable vOut = r.execExpr( + (*(*i)->getBranchBegin()).begin(), + Variable( sInput ) + ); + if( vOut.getType() == Variable::typeString ) + { + pTrg->addOutput( vOut.getString() ); + } + else if( vOut.getType() == Variable::typeList ) + { + for( VarList::iterator j = vOut.begin(); j; j++ ) + { + pTrg->addOutput( (*j).getString() ); + } + } + } + r.getContext().addVariable("OUTPUT", pTrg->getOutputList() ); + pTrg->addInput( sInput ); + pTrg->setDisplay( getDisplay() ); + for( ProfileHash::iterator i = hProfiles.begin(); i; i++ ) + { + pTrg->addProfile( *i ); + } + for( AstBranchList::iterator i = lRequires.begin(); i; i++ ) + { + pTrg->addRequires( *i ); + } + pTrg->setVars( r.getContext().getScope() ); + r.getContext().popScope(); + + return pTrg; } bool Rule::ruleMatches( Runner &r, const Bu::String &sInput ) { - r.getContext().pushScope(); - r.getContext().addVariable("INPUT", sInput ); - Variable vInput( sInput ); - Variable vOut = r.execExpr( - (*pInput->getBranchBegin()).begin(), - vInput - ); - r.getContext().popScope(); - if( vOut.getType() == Variable::typeBool ) - return vOut.getBool(); - else if( vOut.getType() == Variable::typeList ) - return vOut.begin(); - return false; + r.getContext().pushScope(); + r.getContext().addVariable("INPUT", sInput ); + Variable vInput( sInput ); + Variable vOut = r.execExpr( + (*pInput->getBranchBegin()).begin(), + vInput + ); + r.getContext().popScope(); + if( vOut.getType() == Variable::typeBool ) + return vOut.getBool(); + else if( vOut.getType() == Variable::typeList ) + return vOut.begin(); + return false; } void Rule::addTag( const Bu::String &sTag ) { - lsTags.append( sTag ); + lsTags.append( sTag ); } const StrList &Rule::getTagList() const { - return lsTags; + return lsTags; } void Rule::setDisplay( const Bu::String &sStr ) { - sDisplay = sStr; + sDisplay = sStr; } const Bu::String &Rule::getDisplay() const { - return (sDisplay.isSet())?(sDisplay):(sName); + return (sDisplay.isSet())?(sDisplay):(sName); } void Rule::addRequires( const AstBranch *pBr ) { - lRequires.append( pBr ); + lRequires.append( pBr ); } Bu::Formatter &operator<<( Bu::Formatter &f, const Rule &/*t*/ ) { - return f << "rule"; + return f << "rule"; } template<> Bu::Formatter &Bu::operator<< ( Bu::Formatter &f, const Rule *t ) { - return f << (*t); + return f << (*t); } diff --git a/src/rule.h b/src/rule.h index d8accf0..5e12a20 100644 --- a/src/rule.h +++ b/src/rule.h @@ -6,49 +6,49 @@ class Rule { - friend Bu::Formatter &operator<<( Bu::Formatter &f, const Rule &t ); + friend Bu::Formatter &operator<<( Bu::Formatter &f, const Rule &t ); public: - Rule( const Bu::String &sName ); - virtual ~Rule(); + Rule( const Bu::String &sName ); + virtual ~Rule(); - const Bu::String &getName() const; + const Bu::String &getName() const; - void setInput( const AstBranch *pNewInput ); - const AstBranch *getInput() const; + void setInput( const AstBranch *pNewInput ); + const AstBranch *getInput() const; - bool hasOutputs() const; + bool hasOutputs() const; - void addOutput( const AstBranch *pNewOutput ); - void addProfile( const AstBranch *pProfile ); + void addOutput( const AstBranch *pNewOutput ); + void addProfile( const AstBranch *pProfile ); - void prepTarget( class Target *pTarget ); - class Target *createTarget( class Runner &r, const Bu::String &sInput, - class Target *pParent ); - bool ruleMatches( class Runner &r, const Bu::String &sInput ); + void prepTarget( class Target *pTarget ); + class Target *createTarget( class Runner &r, const Bu::String &sInput, + class Target *pParent ); + bool ruleMatches( class Runner &r, const Bu::String &sInput ); - void addTag( const Bu::String &sTag ); - const StrList &getTagList() const; + void addTag( const Bu::String &sTag ); + const StrList &getTagList() const; - void setDisplay( const Bu::String &sStr ); - const Bu::String &getDisplay() const; + void setDisplay( const Bu::String &sStr ); + const Bu::String &getDisplay() const; - void addRequires( const AstBranch *pBr ); + void addRequires( const AstBranch *pBr ); private: - Bu::String sName; - Bu::String sDisplay; - const AstBranch *pInput; - AstBranchList lOutput; - ProfileHash hProfiles; - StrList lsTags; - AstBranchList lRequires; + Bu::String sName; + Bu::String sDisplay; + const AstBranch *pInput; + AstBranchList lOutput; + ProfileHash hProfiles; + StrList lsTags; + AstBranchList lRequires; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Rule &t ); namespace Bu { - template<> Bu::Formatter &operator<< ( Bu::Formatter &f, const Rule *t ); + template<> Bu::Formatter &operator<< ( Bu::Formatter &f, const Rule *t ); }; #endif diff --git a/src/runner.cpp b/src/runner.cpp index 64ad8e8..766a2f5 100644 --- a/src/runner.cpp +++ b/src/runner.cpp @@ -17,10 +17,10 @@ using Bu::sio; Runner::Runner( Ast &rAst, Context &rCont ) : - rAst( rAst ), - rCont( rCont ), - pCurTarget( NULL ), - pCurRule( NULL ) + rAst( rAst ), + rCont( rCont ), + pCurTarget( NULL ), + pCurRule( NULL ) { } @@ -30,897 +30,897 @@ Runner::~Runner() void Runner::initialize() { - for( Ast::NodeList::const_iterator i = rAst.getNodeBegin(); i; i++ ) - { - if( (*i)->getType() == AstNode::typeFunctionDef ) - { - AstBranch *pFnc = dynamic_cast(*i); - rCont.addFunction( new FunctionAst( pFnc, this ) ); - } - else if( (*i)->getType() == AstNode::typeActionDef ) - { - AstBranch *pAction = dynamic_cast(*i); - rCont.addAction( new Action( pAction ) ); - } - } + for( Ast::NodeList::const_iterator i = rAst.getNodeBegin(); i; i++ ) + { + if( (*i)->getType() == AstNode::typeFunctionDef ) + { + AstBranch *pFnc = dynamic_cast(*i); + rCont.addFunction( new FunctionAst( pFnc, this ) ); + } + else if( (*i)->getType() == AstNode::typeActionDef ) + { + AstBranch *pAction = dynamic_cast(*i); + rCont.addAction( new Action( pAction ) ); + } + } } Variable Runner::execFunc( const AstBranch *pFunc, Variable &vIn ) { - Bu::String sName = dynamic_cast( - (*pFunc->getBranchBegin()).first())->getStrValue(); + Bu::String sName = dynamic_cast( + (*pFunc->getBranchBegin()).first())->getStrValue(); - VarList lParams; - for( AstBranch::BranchList::const_iterator p = - pFunc->getBranchBegin()+1; p; p++ ) - { - lParams.append( execExpr( (*p).begin() ) ); - } + VarList lParams; + for( AstBranch::BranchList::const_iterator p = + pFunc->getBranchBegin()+1; p; p++ ) + { + lParams.append( execExpr( (*p).begin() ) ); + } - return rCont.call( sName, vIn, lParams ); + return rCont.call( sName, vIn, lParams ); } Variable Runner::execExpr( AstBranch::NodeList::const_iterator e ) { - Variable vBlank; - return execExpr( e, vBlank ); + Variable vBlank; + return execExpr( e, vBlank ); } Variable Runner::execExpr( AstBranch::NodeList::const_iterator e, - const Variable &vIn ) + const Variable &vIn ) { -// Variable v( vIn ); - VarList lStack; - lStack.push( vIn ); - - for(; e; e++ ) - { - if( ((*e)->getType()&AstNode::typeClassMask) == AstNode::typeBranch ) - { - const AstBranch *pBranch = dynamic_cast( *e ); - switch( pBranch->getType() ) - { - case AstNode::typeFunction: - //sio << "FUNC: " << *pBranch << sio.nl << sio.nl; - { - Variable v = lStack.peekPop(); - lStack.push( execFunc( pBranch, v ) ); - } - break; - - case AstNode::typeSet: - lStack.push( doSet( pBranch ) ); - break; - - case AstNode::typeList: - { - Variable vLst( Variable::typeList ); - for( AstBranch::BranchList::const_iterator i = - pBranch->getBranchBegin(); i; i++ ) - { - vLst.append( execExpr( (*i).begin() ) ); - } - lStack.push( vLst ); - } - break; - - case AstNode::typeExpr: - { - sio << "!!! typeExpr in an expr maybe should be an error..." << sio.nl; - for( AstBranch::BranchList::const_iterator i = - pBranch->getBranchBegin(); i; i++ ) - { - lStack.push( - execExpr( (*i).begin() ) // Are they atomic? - ); - } - if( lStack.getSize() != 1 ) - { - throw Bu::ExceptionBase( - "Something went wrong, expression processing " - "left %d elements on stack, should be 1.", - lStack.getSize() ); - } - } - break; - - default: - sio << "?? branch ???: " - << (pBranch)->getType(); - break; - } - } - else - { - const AstLeaf *pLeaf = dynamic_cast( *e ); - switch( pLeaf->getType() ) - { - case AstNode::typeVariable: - try - { - lStack.push( - rCont.getVariable( pLeaf->getStrValue() ) - ); - } - catch(...) - { - lStack.push( Variable() ); - } - break; - - case AstNode::typeVariableRef: - lStack.push( - Variable::mkRef( pLeaf->getStrValue() ) - ); - break; - - case AstNode::typeString: - lStack.push( - rCont.expand( pLeaf->getStrValue() ) - ); - break; - - case AstNode::typeInt: - lStack.push( - pLeaf->getIntValue() - ); - break; - - case AstNode::typeFloat: - lStack.push( - pLeaf->getFloatValue() - ); - break; - - case AstNode::typeBool: - lStack.push( - pLeaf->getBoolValue() - ); - break; - - case AstNode::typeVersion: - break; - - case AstNode::typeNull: - lStack.push( - Variable() - ); - break; - - case AstNode::typeCmpEq: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( a == b ) ); - } - break; - - case AstNode::typeCmpLt: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b < a ) ); - } - break; - - case AstNode::typeCmpGt: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b > a ) ); - } - break; - - case AstNode::typeCmpNe: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( a != b ) ); - } - break; - - case AstNode::typeCmpLtEq: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b <= a ) ); - } - break; - - case AstNode::typeCmpGtEq: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b >= a ) ); - } - break; - - case AstNode::typeOpEq: - { - Variable ref, val; - val = lStack.peekPop(); - ref = lStack.peekPop(); - rCont.addVariable( ref.getString(), val ); - lStack.push( val ); - } - break; - - case AstNode::typeOpPlusEq: - { - Variable ref, val; - val = lStack.peekPop(); - ref = lStack.peekPop(); - try - { - Variable &nVal = rCont.getVariable( - ref.getString() - ); - nVal += val; - lStack.push( nVal ); - } catch(...) - { - rCont.addVariable( ref.getString(), val ); - lStack.push( val ); - } - } - break; - - case AstNode::typeOpPlusEqRaw: - { - Variable ref, val; - val = lStack.peekPop(); - ref = lStack.peekPop(); - try - { - Variable &nVal = rCont.getVariable( - ref.getString() - ); - nVal << val; - lStack.push( nVal ); - } catch(...) - { - rCont.addVariable( ref.getString(), val ); - lStack.push( val ); - } - } - break; - - case AstNode::typeOpPlus: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b + a ) ); - } - break; - - case AstNode::typeOpMinus: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b - a ) ); - } - break; - - case AstNode::typeOpMultiply: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b * a ) ); - } - break; - - case AstNode::typeOpDivide: - { - Variable a, b; - a = lStack.peekPop(); - b = lStack.peekPop(); - lStack.push( Variable( b / a ) ); - } - break; - - case AstNode::typeOpNegate: - lStack.peek().doNegate(); - break; - - case AstNode::typeOpNot: - lStack.peek().doNot(); - break; - - default: - sio << "?? leaf ???: " - << (pLeaf)->getType(); - break; - } - } - } - - return lStack.peek(); +// Variable v( vIn ); + VarList lStack; + lStack.push( vIn ); + + for(; e; e++ ) + { + if( ((*e)->getType()&AstNode::typeClassMask) == AstNode::typeBranch ) + { + const AstBranch *pBranch = dynamic_cast( *e ); + switch( pBranch->getType() ) + { + case AstNode::typeFunction: + //sio << "FUNC: " << *pBranch << sio.nl << sio.nl; + { + Variable v = lStack.peekPop(); + lStack.push( execFunc( pBranch, v ) ); + } + break; + + case AstNode::typeSet: + lStack.push( doSet( pBranch ) ); + break; + + case AstNode::typeList: + { + Variable vLst( Variable::typeList ); + for( AstBranch::BranchList::const_iterator i = + pBranch->getBranchBegin(); i; i++ ) + { + vLst.append( execExpr( (*i).begin() ) ); + } + lStack.push( vLst ); + } + break; + + case AstNode::typeExpr: + { + sio << "!!! typeExpr in an expr maybe should be an error..." << sio.nl; + for( AstBranch::BranchList::const_iterator i = + pBranch->getBranchBegin(); i; i++ ) + { + lStack.push( + execExpr( (*i).begin() ) // Are they atomic? + ); + } + if( lStack.getSize() != 1 ) + { + throw Bu::ExceptionBase( + "Something went wrong, expression processing " + "left %d elements on stack, should be 1.", + lStack.getSize() ); + } + } + break; + + default: + sio << "?? branch ???: " + << (pBranch)->getType(); + break; + } + } + else + { + const AstLeaf *pLeaf = dynamic_cast( *e ); + switch( pLeaf->getType() ) + { + case AstNode::typeVariable: + try + { + lStack.push( + rCont.getVariable( pLeaf->getStrValue() ) + ); + } + catch(...) + { + lStack.push( Variable() ); + } + break; + + case AstNode::typeVariableRef: + lStack.push( + Variable::mkRef( pLeaf->getStrValue() ) + ); + break; + + case AstNode::typeString: + lStack.push( + rCont.expand( pLeaf->getStrValue() ) + ); + break; + + case AstNode::typeInt: + lStack.push( + pLeaf->getIntValue() + ); + break; + + case AstNode::typeFloat: + lStack.push( + pLeaf->getFloatValue() + ); + break; + + case AstNode::typeBool: + lStack.push( + pLeaf->getBoolValue() + ); + break; + + case AstNode::typeVersion: + break; + + case AstNode::typeNull: + lStack.push( + Variable() + ); + break; + + case AstNode::typeCmpEq: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( a == b ) ); + } + break; + + case AstNode::typeCmpLt: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b < a ) ); + } + break; + + case AstNode::typeCmpGt: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b > a ) ); + } + break; + + case AstNode::typeCmpNe: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( a != b ) ); + } + break; + + case AstNode::typeCmpLtEq: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b <= a ) ); + } + break; + + case AstNode::typeCmpGtEq: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b >= a ) ); + } + break; + + case AstNode::typeOpEq: + { + Variable ref, val; + val = lStack.peekPop(); + ref = lStack.peekPop(); + rCont.addVariable( ref.getString(), val ); + lStack.push( val ); + } + break; + + case AstNode::typeOpPlusEq: + { + Variable ref, val; + val = lStack.peekPop(); + ref = lStack.peekPop(); + try + { + Variable &nVal = rCont.getVariable( + ref.getString() + ); + nVal += val; + lStack.push( nVal ); + } catch(...) + { + rCont.addVariable( ref.getString(), val ); + lStack.push( val ); + } + } + break; + + case AstNode::typeOpPlusEqRaw: + { + Variable ref, val; + val = lStack.peekPop(); + ref = lStack.peekPop(); + try + { + Variable &nVal = rCont.getVariable( + ref.getString() + ); + nVal << val; + lStack.push( nVal ); + } catch(...) + { + rCont.addVariable( ref.getString(), val ); + lStack.push( val ); + } + } + break; + + case AstNode::typeOpPlus: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b + a ) ); + } + break; + + case AstNode::typeOpMinus: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b - a ) ); + } + break; + + case AstNode::typeOpMultiply: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b * a ) ); + } + break; + + case AstNode::typeOpDivide: + { + Variable a, b; + a = lStack.peekPop(); + b = lStack.peekPop(); + lStack.push( Variable( b / a ) ); + } + break; + + case AstNode::typeOpNegate: + lStack.peek().doNegate(); + break; + + case AstNode::typeOpNot: + lStack.peek().doNot(); + break; + + default: + sio << "?? leaf ???: " + << (pLeaf)->getType(); + break; + } + } + } + + return lStack.peek(); } void Runner::run() { - run( rAst.getNodeBegin() ); + run( rAst.getNodeBegin() ); - rCont.buildTargetTree( *this ); + rCont.buildTargetTree( *this ); - rCont.attachDefaults(); - rCont.genDefaultActions(); + rCont.attachDefaults(); + rCont.genDefaultActions(); -// rCont.writeTargetDot(); +// rCont.writeTargetDot(); } Variable Runner::run( AstBranch::NodeList::const_iterator n ) { - /* Execute the top level code. */ - - Variable vReturn; - Bu::List sI; - sI.push( n ); -// for( Ast::NodeList::const_iterator i = rAst.getNodeBegin(); i; i++ ) - while( !sI.isEmpty() ) - { - while( !sI.isEmpty() && !(sI.peek()) ) - { - sI.pop(); - } - if( sI.isEmpty() ) - break; - Ast::NodeList::const_iterator &i = sI.peek(); - if( ((*i)->getType()&AstNode::typeClassMask) == AstNode::typeLeaf ) - { - const AstLeaf *pExpr = dynamic_cast( *i ); - switch( pExpr->getType() ) - { - case AstNode::typeError: - { - Bu::String sMsg = rCont.expand( pExpr->getStrValue() ); - rCont.getView()->userError( sMsg.getStr() ); - throw Bu::ExceptionBase( sMsg.getStr() ); - } - break; - - case AstNode::typeWarning: - rCont.getView()->userWarning( - rCont.expand( pExpr->getStrValue() ) - ); - break; - - case AstNode::typeNotice: - rCont.getView()->userNotice( - rCont.expand( pExpr->getStrValue() ) - ); - break; - - case AstNode::typeCondition: - break; - - case AstNode::typeDisplay: - if( pCurTarget ) - { - pCurTarget->setDisplay( - rCont.expand( pExpr->getStrValue() ) - ); - } - else if( pCurRule ) - { - pCurRule->setDisplay( - rCont.expand( pExpr->getStrValue() ) - ); - } - break; - - case AstNode::typePushPrefix: - case AstNode::typePopPrefix: - break; + /* Execute the top level code. */ + + Variable vReturn; + Bu::List sI; + sI.push( n ); +// for( Ast::NodeList::const_iterator i = rAst.getNodeBegin(); i; i++ ) + while( !sI.isEmpty() ) + { + while( !sI.isEmpty() && !(sI.peek()) ) + { + sI.pop(); + } + if( sI.isEmpty() ) + break; + Ast::NodeList::const_iterator &i = sI.peek(); + if( ((*i)->getType()&AstNode::typeClassMask) == AstNode::typeLeaf ) + { + const AstLeaf *pExpr = dynamic_cast( *i ); + switch( pExpr->getType() ) + { + case AstNode::typeError: + { + Bu::String sMsg = rCont.expand( pExpr->getStrValue() ); + rCont.getView()->userError( sMsg.getStr() ); + throw Bu::ExceptionBase( sMsg.getStr() ); + } + break; + + case AstNode::typeWarning: + rCont.getView()->userWarning( + rCont.expand( pExpr->getStrValue() ) + ); + break; + + case AstNode::typeNotice: + rCont.getView()->userNotice( + rCont.expand( pExpr->getStrValue() ) + ); + break; + + case AstNode::typeCondition: + break; + + case AstNode::typeDisplay: + if( pCurTarget ) + { + pCurTarget->setDisplay( + rCont.expand( pExpr->getStrValue() ) + ); + } + else if( pCurRule ) + { + pCurRule->setDisplay( + rCont.expand( pExpr->getStrValue() ) + ); + } + break; + + case AstNode::typePushPrefix: + case AstNode::typePopPrefix: + break; /* - case AstNode::typeCondition: - if( pCurTarget ) - { - if( pExpr->getStrValue() == "filetime" ) - { - pCurTarget->setCondition( - new ConditionFileTime() - ); - } - } - else if( pCurRule ) - { - if( pExpr->getStrValue() == "filetime" ) - { - pCurRule->setCondition( - new ConditionFileTime() - ); - } - } - else - { - throw Bu::ExceptionBase( - "You can only set a condition in a target or rule."); - } - break; + case AstNode::typeCondition: + if( pCurTarget ) + { + if( pExpr->getStrValue() == "filetime" ) + { + pCurTarget->setCondition( + new ConditionFileTime() + ); + } + } + else if( pCurRule ) + { + if( pExpr->getStrValue() == "filetime" ) + { + pCurRule->setCondition( + new ConditionFileTime() + ); + } + } + else + { + throw Bu::ExceptionBase( + "You can only set a condition in a target or rule."); + } + break; */ - default: - sio << "Leaf? " << (*i)->getType() << sio.nl; - break; - } - } - else - { - const AstBranch *pExpr = dynamic_cast( *i ); - switch( pExpr->getType() ) - { - case AstNode::typeSet: - { - // This is effectively legacy, if we add the set - // keyword back in I want it to work. - doSet( pExpr ); - } - break; - - case AstNode::typeUnset: - { - AstBranch::NodeList::const_iterator n = - (*pExpr->getBranchBegin()).begin(); - Bu::String sVar = dynamic_cast( - *n )->getStrValue(); - rCont.delVariable( sVar ); - } - break; - - case AstNode::typeIf: - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - - Variable v = execExpr( (*b).begin() ); - if( v.getType() != Variable::typeBool ) - { - throw Bu::ExceptionBase( - "If statement evaluated to non-boolean."); - } - b++; - if( v.getBool() ) - { - i++; - sI.push( (*b).begin() ); - continue; - } - else - { - b++; - if( b ) - { - i++; - sI.push( (*b).begin() ); - continue; - } - } - } - break; - - case AstNode::typeFor: - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - Bu::String sVar = dynamic_cast( - (*b).first() )->getStrValue(); - b++; - Variable v = execExpr( (*b).begin() ); - b++; - for( VarList::const_iterator vi = v.getList().begin(); - vi; vi++ ) - { - rCont.addVariable( sVar, *vi ); - run( (*b).begin() ); - } - } - break; - - case AstNode::typeFunction: - { - Variable vIn; - execFunc( pExpr, vIn ); - } - break; - - case AstNode::typeReturn: - vReturn = execExpr( (*pExpr->getBranchBegin()).begin() ); - return vReturn; - break; - - case AstNode::typeFunctionDef: - case AstNode::typeActionDef: - // We ignore these, we already dealt with them - break; - - case AstNode::typeTarget: - // This actually runs exactly like a for loop, if there's - // only one item, then we only go once, if it's a list, go - // more than once :-P - if( pCurTarget == NULL ) - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - Variable vLoop = execExpr( (*b).begin() ); - b++; - if( vLoop.getType() == Variable::typeString ) - { - rCont.addTarget( - buildTarget( - vLoop.getString(), (*b).begin() - ) - ); - } - else if( vLoop.getType() == Variable::typeList ) - { - for( VarList::iterator i = vLoop.begin(); i; i++ ) - { - rCont.addTarget( - buildTarget( - (*i).getString(), (*b).begin() - ) - ); - } - } - } - else - { - throw Bu::ExceptionBase( - "You cannot declare a target within " - "a target decleration."); - } - break; - - case AstNode::typeRuleDef: - if( pCurRule == NULL ) - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - Bu::String sName = dynamic_cast( - (*b).first() - )->getStrValue(); - b++; - rCont.addRule( buildRule( sName, (*b).begin() ) ); - } - else - { - throw Bu::ExceptionBase( - "You cannot declare a rule within " - "a rule decleration."); - } - break; - - case AstNode::typeInput: - if( pCurTarget != NULL ) - { - Variable vRet = execExpr( - (*pExpr->getBranchBegin()).begin() - ); - if( vRet.getType() == Variable::typeString ) - { - pCurTarget->addInput( vRet.getString() ); - } - else if( vRet.getType() == Variable::typeList ) - { - for( VarList::iterator i = vRet.begin(); i; i++ ) - { - pCurTarget->addInput( - (*i).getString() - ); - } - } - } - else if( pCurRule != NULL ) - { - pCurRule->setInput( pExpr ); - } - else - { - throw Bu::ExceptionBase( - "input can only occur within a target or rule."); - } - break; - - case AstNode::typeRequires: - if( pCurTarget != NULL ) - { - Variable vRet = execExpr( - (*pExpr->getBranchBegin()).begin() - ); - if( vRet.getType() == Variable::typeString ) - { - pCurTarget->addRequires( vRet.getString() ); - } - else if( vRet.getType() == Variable::typeList ) - { - for( VarList::iterator i = vRet.begin(); i; i++ ) - { - pCurTarget->addRequires( - (*i).getString() - ); - } - } - } - else if( pCurRule != NULL ) - { - pCurRule->addRequires( pExpr ); - } - else - { - throw Bu::ExceptionBase( - "requires can only occur within a target or rule."); - } - break; - - case AstNode::typeRule: - if( pCurTarget ) - { - pCurTarget->setRule( - dynamic_cast( - (*pExpr->getBranchBegin()).first() - )->getStrValue() - ); - } - else - { - throw Bu::ExceptionBase( - "rule can only occur within a target."); - } - break; - - case AstNode::typeProfile: - if( pCurTarget ) - { - pCurTarget->addProfile( pExpr ); - } - else if( pCurRule ) - { - pCurRule->addProfile( pExpr ); - } - else - { - throw Bu::ExceptionBase( - "profile can only occur within a target or rule."); - } - break; - - case AstNode::typeOutput: - if( pCurRule ) - { - pCurRule->addOutput( pExpr ); - } - else - { - throw Bu::ExceptionBase( - "output can only occur within a rule."); - } - break; - - case AstNode::typeProcessTarget: - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - Bu::String sProfile = dynamic_cast( - (*b).first() - )->getStrValue(); - b++; - Variable vTargs = execExpr( (*b).begin() ); - if( vTargs.getType() == Variable::typeString ) - { - rCont.getTarget( vTargs.getString() )->process( - *this, sProfile - ); - } - else if( vTargs.getType() == Variable::typeList ) - { - for( VarList::iterator v = vTargs.begin(); - v; v++ ) { - rCont.getTarget( (*v).getString() )->process( - *this, sProfile - ); - } - } - } - break; - - case AstNode::typeTag: - if( pCurTarget ) - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - Variable vTags = execExpr( (*b).begin() ); - if( vTags.getType() == Variable::typeList ) - { - for( VarList::iterator i = vTags.begin(); i; i++ ) - { - rCont.addTargetToTag( pCurTarget, (*i).toString() ); - } - } - else - { - Bu::String sTag = vTags.toString(); - if( sTag.isSet() ) - { - rCont.addTargetToTag( pCurTarget, sTag ); - } - else - { - throw Bu::ExceptionBase( - "A tag evaluted to empty string." - ); - } - } - } - else if( pCurRule ) - { - AstBranch::BranchList::const_iterator b = - pExpr->getBranchBegin(); - Variable vTags = execExpr( (*b).begin() ); - if( vTags.getType() == Variable::typeList ) - { - for( VarList::iterator i = vTags.begin(); i; i++ ) - { - pCurRule->addTag( (*i).toString() ); - } - } - else - { - Bu::String sTag = vTags.toString(); - if( sTag.isSet() ) - { - pCurRule->addTag( sTag ); - } - else - { - throw Bu::ExceptionBase( - "A tag evaluted to empty string." - ); - } - } - } - else - { - throw Bu::ExceptionBase( - "tag can only occur within a target or rule."); - } - break; - - case AstNode::typeExpr: - execExpr( (*pExpr->getBranchBegin()).begin() ); - break; - - default: - sio << "Branch? " << (*i)->getType() << sio.nl; - break; - } - } - - i++; - } - - return vReturn; + default: + sio << "Leaf? " << (*i)->getType() << sio.nl; + break; + } + } + else + { + const AstBranch *pExpr = dynamic_cast( *i ); + switch( pExpr->getType() ) + { + case AstNode::typeSet: + { + // This is effectively legacy, if we add the set + // keyword back in I want it to work. + doSet( pExpr ); + } + break; + + case AstNode::typeUnset: + { + AstBranch::NodeList::const_iterator n = + (*pExpr->getBranchBegin()).begin(); + Bu::String sVar = dynamic_cast( + *n )->getStrValue(); + rCont.delVariable( sVar ); + } + break; + + case AstNode::typeIf: + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + + Variable v = execExpr( (*b).begin() ); + if( v.getType() != Variable::typeBool ) + { + throw Bu::ExceptionBase( + "If statement evaluated to non-boolean."); + } + b++; + if( v.getBool() ) + { + i++; + sI.push( (*b).begin() ); + continue; + } + else + { + b++; + if( b ) + { + i++; + sI.push( (*b).begin() ); + continue; + } + } + } + break; + + case AstNode::typeFor: + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + Bu::String sVar = dynamic_cast( + (*b).first() )->getStrValue(); + b++; + Variable v = execExpr( (*b).begin() ); + b++; + for( VarList::const_iterator vi = v.getList().begin(); + vi; vi++ ) + { + rCont.addVariable( sVar, *vi ); + run( (*b).begin() ); + } + } + break; + + case AstNode::typeFunction: + { + Variable vIn; + execFunc( pExpr, vIn ); + } + break; + + case AstNode::typeReturn: + vReturn = execExpr( (*pExpr->getBranchBegin()).begin() ); + return vReturn; + break; + + case AstNode::typeFunctionDef: + case AstNode::typeActionDef: + // We ignore these, we already dealt with them + break; + + case AstNode::typeTarget: + // This actually runs exactly like a for loop, if there's + // only one item, then we only go once, if it's a list, go + // more than once :-P + if( pCurTarget == NULL ) + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + Variable vLoop = execExpr( (*b).begin() ); + b++; + if( vLoop.getType() == Variable::typeString ) + { + rCont.addTarget( + buildTarget( + vLoop.getString(), (*b).begin() + ) + ); + } + else if( vLoop.getType() == Variable::typeList ) + { + for( VarList::iterator i = vLoop.begin(); i; i++ ) + { + rCont.addTarget( + buildTarget( + (*i).getString(), (*b).begin() + ) + ); + } + } + } + else + { + throw Bu::ExceptionBase( + "You cannot declare a target within " + "a target decleration."); + } + break; + + case AstNode::typeRuleDef: + if( pCurRule == NULL ) + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + Bu::String sName = dynamic_cast( + (*b).first() + )->getStrValue(); + b++; + rCont.addRule( buildRule( sName, (*b).begin() ) ); + } + else + { + throw Bu::ExceptionBase( + "You cannot declare a rule within " + "a rule decleration."); + } + break; + + case AstNode::typeInput: + if( pCurTarget != NULL ) + { + Variable vRet = execExpr( + (*pExpr->getBranchBegin()).begin() + ); + if( vRet.getType() == Variable::typeString ) + { + pCurTarget->addInput( vRet.getString() ); + } + else if( vRet.getType() == Variable::typeList ) + { + for( VarList::iterator i = vRet.begin(); i; i++ ) + { + pCurTarget->addInput( + (*i).getString() + ); + } + } + } + else if( pCurRule != NULL ) + { + pCurRule->setInput( pExpr ); + } + else + { + throw Bu::ExceptionBase( + "input can only occur within a target or rule."); + } + break; + + case AstNode::typeRequires: + if( pCurTarget != NULL ) + { + Variable vRet = execExpr( + (*pExpr->getBranchBegin()).begin() + ); + if( vRet.getType() == Variable::typeString ) + { + pCurTarget->addRequires( vRet.getString() ); + } + else if( vRet.getType() == Variable::typeList ) + { + for( VarList::iterator i = vRet.begin(); i; i++ ) + { + pCurTarget->addRequires( + (*i).getString() + ); + } + } + } + else if( pCurRule != NULL ) + { + pCurRule->addRequires( pExpr ); + } + else + { + throw Bu::ExceptionBase( + "requires can only occur within a target or rule."); + } + break; + + case AstNode::typeRule: + if( pCurTarget ) + { + pCurTarget->setRule( + dynamic_cast( + (*pExpr->getBranchBegin()).first() + )->getStrValue() + ); + } + else + { + throw Bu::ExceptionBase( + "rule can only occur within a target."); + } + break; + + case AstNode::typeProfile: + if( pCurTarget ) + { + pCurTarget->addProfile( pExpr ); + } + else if( pCurRule ) + { + pCurRule->addProfile( pExpr ); + } + else + { + throw Bu::ExceptionBase( + "profile can only occur within a target or rule."); + } + break; + + case AstNode::typeOutput: + if( pCurRule ) + { + pCurRule->addOutput( pExpr ); + } + else + { + throw Bu::ExceptionBase( + "output can only occur within a rule."); + } + break; + + case AstNode::typeProcessTarget: + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + Bu::String sProfile = dynamic_cast( + (*b).first() + )->getStrValue(); + b++; + Variable vTargs = execExpr( (*b).begin() ); + if( vTargs.getType() == Variable::typeString ) + { + rCont.getTarget( vTargs.getString() )->process( + *this, sProfile + ); + } + else if( vTargs.getType() == Variable::typeList ) + { + for( VarList::iterator v = vTargs.begin(); + v; v++ ) { + rCont.getTarget( (*v).getString() )->process( + *this, sProfile + ); + } + } + } + break; + + case AstNode::typeTag: + if( pCurTarget ) + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + Variable vTags = execExpr( (*b).begin() ); + if( vTags.getType() == Variable::typeList ) + { + for( VarList::iterator i = vTags.begin(); i; i++ ) + { + rCont.addTargetToTag( pCurTarget, (*i).toString() ); + } + } + else + { + Bu::String sTag = vTags.toString(); + if( sTag.isSet() ) + { + rCont.addTargetToTag( pCurTarget, sTag ); + } + else + { + throw Bu::ExceptionBase( + "A tag evaluted to empty string." + ); + } + } + } + else if( pCurRule ) + { + AstBranch::BranchList::const_iterator b = + pExpr->getBranchBegin(); + Variable vTags = execExpr( (*b).begin() ); + if( vTags.getType() == Variable::typeList ) + { + for( VarList::iterator i = vTags.begin(); i; i++ ) + { + pCurRule->addTag( (*i).toString() ); + } + } + else + { + Bu::String sTag = vTags.toString(); + if( sTag.isSet() ) + { + pCurRule->addTag( sTag ); + } + else + { + throw Bu::ExceptionBase( + "A tag evaluted to empty string." + ); + } + } + } + else + { + throw Bu::ExceptionBase( + "tag can only occur within a target or rule."); + } + break; + + case AstNode::typeExpr: + execExpr( (*pExpr->getBranchBegin()).begin() ); + break; + + default: + sio << "Branch? " << (*i)->getType() << sio.nl; + break; + } + } + + i++; + } + + return vReturn; } void Runner::execProfile( Target *pTarget, const Bu::String &sProfile ) { - rCont.pushScope( pTarget->getVars() ); - run( (*(pTarget->getProfile( sProfile )->getRoot()-> - getBranchBegin()+1)).begin() ); - rCont.popScope(); + rCont.pushScope( pTarget->getVars() ); + run( (*(pTarget->getProfile( sProfile )->getRoot()-> + getBranchBegin()+1)).begin() ); + rCont.popScope(); } void Runner::execAction( const Bu::String &sName ) { - try - { - Action *pAct = rCont.getAction( sName ); - - pAct->call( this ); - } - catch( Bu::HashException &e ) - { - Bu::String sError("No such action '" + sName + "' found."); - rCont.getView()->sysError( sError ); - } + try + { + Action *pAct = rCont.getAction( sName ); + + pAct->call( this ); + } + catch( Bu::HashException &e ) + { + Bu::String sError("No such action '" + sName + "' found."); + rCont.getView()->sysError( sError ); + } } Context &Runner::getContext() { - return rCont; + return rCont; } Target *Runner::buildTarget( const Bu::String &sOutput, - AstBranch::NodeList::const_iterator n ) + AstBranch::NodeList::const_iterator n ) { - Target *pTrg = NULL; - try - { - pTrg = rCont.getTarget( sOutput ); - rCont.pushScope( pTrg->getVars() ); - } - catch( Bu::HashException &e ) - { - pTrg = new Target( sOutput, true ); - rCont.pushScope(); - } - - // sio << " (target) \"" << sOutput << "\" explicit." << sio.nl; - - rCont.addVariable("OUTPUT", sOutput ); - pCurTarget = pTrg; - run( n ); - - rCont.addVariable("INPUT", pTrg->getInputList() ); - pCurTarget = NULL; - - pTrg->setVars( rCont.getScope() ); - rCont.popScope(); - - return pTrg; + Target *pTrg = NULL; + try + { + pTrg = rCont.getTarget( sOutput ); + rCont.pushScope( pTrg->getVars() ); + } + catch( Bu::HashException &e ) + { + pTrg = new Target( sOutput, true ); + rCont.pushScope(); + } + + // sio << " (target) \"" << sOutput << "\" explicit." << sio.nl; + + rCont.addVariable("OUTPUT", sOutput ); + pCurTarget = pTrg; + run( n ); + + rCont.addVariable("INPUT", pTrg->getInputList() ); + pCurTarget = NULL; + + pTrg->setVars( rCont.getScope() ); + rCont.popScope(); + + return pTrg; } Rule *Runner::buildRule( const Bu::String &sName, - AstBranch::NodeList::const_iterator n ) + AstBranch::NodeList::const_iterator n ) { - Rule *pRule = new Rule( sName ); - - rCont.pushScope(); - pCurRule = pRule; - run( n ); - rCont.popScope(); - pCurRule = NULL; - - return pRule; + Rule *pRule = new Rule( sName ); + + rCont.pushScope(); + pCurRule = pRule; + run( n ); + rCont.popScope(); + pCurRule = NULL; + + return pRule; } Variable Runner::doSet( const AstBranch *pRoot ) { - AstBranch::NodeList::const_iterator n = - (*pRoot->getBranchBegin()).begin(); - Bu::String sVar = dynamic_cast( *n )->getStrValue(); - n++; - const AstLeaf *pLeaf = dynamic_cast( *n ); - n++; - Variable v = execExpr( n ); - - switch( pLeaf->getType() ) - { - case AstNode::typeOpEq: - rCont.addVariable( sVar, v ); - break; - - case AstNode::typeOpPlusEq: - try - { - rCont.getVariable( sVar ) += v; - } catch(...) - { - rCont.addVariable( sVar, v ); - } - break; - - case AstNode::typeOpPlusEqRaw: - try - { - rCont.getVariable( sVar ) << v; - } catch(...) - { - rCont.addVariable( sVar, v ); - } - break; - - default: break; - } - - return v; + AstBranch::NodeList::const_iterator n = + (*pRoot->getBranchBegin()).begin(); + Bu::String sVar = dynamic_cast( *n )->getStrValue(); + n++; + const AstLeaf *pLeaf = dynamic_cast( *n ); + n++; + Variable v = execExpr( n ); + + switch( pLeaf->getType() ) + { + case AstNode::typeOpEq: + rCont.addVariable( sVar, v ); + break; + + case AstNode::typeOpPlusEq: + try + { + rCont.getVariable( sVar ) += v; + } catch(...) + { + rCont.addVariable( sVar, v ); + } + break; + + case AstNode::typeOpPlusEqRaw: + try + { + rCont.getVariable( sVar ) << v; + } catch(...) + { + rCont.addVariable( sVar, v ); + } + break; + + default: break; + } + + return v; } diff --git a/src/runner.h b/src/runner.h index 0efcb44..59f1703 100644 --- a/src/runner.h +++ b/src/runner.h @@ -6,38 +6,38 @@ class Runner { public: - Runner( class Ast &rAst, class Context &rCont ); - virtual ~Runner(); + Runner( class Ast &rAst, class Context &rCont ); + virtual ~Runner(); - /** - * Run through and pull out all of the functions. Maybe more later. - */ - void initialize(); - class Variable execExpr( AstBranch::NodeList::const_iterator e ); - class Variable execExpr( AstBranch::NodeList::const_iterator e, - const class Variable &vIn ); - void run(); - Variable run( AstBranch::NodeList::const_iterator n ); - class Variable execFunc( const class AstBranch *pFunc, - class Variable &vIn ); - void execProfile( class Target *pTarget, const Bu::String &sProfile ); - void execAction( const Bu::String &sName ); + /** + * Run through and pull out all of the functions. Maybe more later. + */ + void initialize(); + class Variable execExpr( AstBranch::NodeList::const_iterator e ); + class Variable execExpr( AstBranch::NodeList::const_iterator e, + const class Variable &vIn ); + void run(); + Variable run( AstBranch::NodeList::const_iterator n ); + class Variable execFunc( const class AstBranch *pFunc, + class Variable &vIn ); + void execProfile( class Target *pTarget, const Bu::String &sProfile ); + void execAction( const Bu::String &sName ); - Context &getContext(); + Context &getContext(); private: - class Target *buildTarget( const Bu::String &sOutput, - AstBranch::NodeList::const_iterator n ); - class Rule *buildRule( const Bu::String &sName, - AstBranch::NodeList::const_iterator n ); - void attachDefaults(); - Variable doSet( const AstBranch *pRoot ); + class Target *buildTarget( const Bu::String &sOutput, + AstBranch::NodeList::const_iterator n ); + class Rule *buildRule( const Bu::String &sName, + AstBranch::NodeList::const_iterator n ); + void attachDefaults(); + Variable doSet( const AstBranch *pRoot ); private: - class Ast &rAst; - class Context &rCont; - Target *pCurTarget; - Rule *pCurRule; + class Ast &rAst; + class Context &rCont; + Target *pCurTarget; + Rule *pCurRule; }; #endif diff --git a/src/target.cpp b/src/target.cpp index 3a90c01..175030c 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -17,16 +17,16 @@ using namespace Bu; Target::Target( bool bExplicit ) : - bExplicit( bExplicit ), - bRun( false ), - iDepCount( 0 ) + bExplicit( bExplicit ), + bRun( false ), + iDepCount( 0 ) { } Target::Target( const Bu::String &sOutput, bool bExplicit ) : - bExplicit( bExplicit ), - lsOutput( sOutput ), - iDepCount( 0 ) + bExplicit( bExplicit ), + lsOutput( sOutput ), + iDepCount( 0 ) { } @@ -36,385 +36,385 @@ Target::~Target() void Target::addInput( const Bu::String &sInput ) { - lsInput.append( sInput ); + lsInput.append( sInput ); } const StrList &Target::getInputList() const { - return lsInput; + return lsInput; } void Target::resetInputList( const StrList &lInputs ) { - lsInput = lInputs; - if( lsInput.getSize() == 1 ) - { - hVars.insert("INPUT", lsInput.first() ); - } - else - { - Variable vInput( Variable::typeList ); - for( StrList::iterator i = lsInput.begin(); i; i++ ) - { - vInput.append( Variable( *i ) ); - } - hVars.insert("INPUT", vInput ); - } + lsInput = lInputs; + if( lsInput.getSize() == 1 ) + { + hVars.insert("INPUT", lsInput.first() ); + } + else + { + Variable vInput( Variable::typeList ); + for( StrList::iterator i = lsInput.begin(); i; i++ ) + { + vInput.append( Variable( *i ) ); + } + hVars.insert("INPUT", vInput ); + } } void Target::addRequires( const Bu::String &sReq ) { - lsRequires.append( sReq ); + lsRequires.append( sReq ); } void Target::addRequires( const AstBranch *pBr ) { - lbRequires.append( pBr ); + lbRequires.append( pBr ); } const StrList &Target::getRequiresList() const { - return lsRequires; + return lsRequires; } void Target::gatherRequires( Runner &r ) { - Cache &c = Cache::getInstance(); - try - { - lsRequires = c.getRequires( lsOutput.first() ); - } - catch( Bu::HashException &e ) - { - buildRequires( r ); - } + Cache &c = Cache::getInstance(); + try + { + lsRequires = c.getRequires( lsOutput.first() ); + } + catch( Bu::HashException &e ) + { + buildRequires( r ); + } } void Target::buildRequires( Runner &r ) { - r.getContext().getView()->buildRequires( *this ); - r.getContext().pushScope( hVars ); - for( AstBranchList::iterator i = lbRequires.begin(); i; i++ ) - { - Variable v = r.execExpr( (*(*i)->getBranchBegin()).begin() ); - if( v.getType() == Variable::typeList ) - { - for( VarList::iterator j = v.begin(); j; j++ ) - { - Bu::String sReq = (*j).toString(); - addRequires( sReq ); - /* try - { - addDep( r.getContext().getTarget( sReq ) ); - } - catch(...) { }*/ - } - } - else - { - Bu::String sReq = v.toString(); - addRequires( sReq ); - /* try - { - addDep( r.getContext().getTarget( sReq ) ); - } - catch(...) { }*/ - } - } - r.getContext().popScope(); - - Cache &c = Cache::getInstance(); - c.setRequires( lsOutput.first(), lsRequires ); + r.getContext().getView()->buildRequires( *this ); + r.getContext().pushScope( hVars ); + for( AstBranchList::iterator i = lbRequires.begin(); i; i++ ) + { + Variable v = r.execExpr( (*(*i)->getBranchBegin()).begin() ); + if( v.getType() == Variable::typeList ) + { + for( VarList::iterator j = v.begin(); j; j++ ) + { + Bu::String sReq = (*j).toString(); + addRequires( sReq ); + /* try + { + addDep( r.getContext().getTarget( sReq ) ); + } + catch(...) { }*/ + } + } + else + { + Bu::String sReq = v.toString(); + addRequires( sReq ); + /* try + { + addDep( r.getContext().getTarget( sReq ) ); + } + catch(...) { }*/ + } + } + r.getContext().popScope(); + + Cache &c = Cache::getInstance(); + c.setRequires( lsOutput.first(), lsRequires ); } void Target::addOutput( const Bu::String &sOutput ) { - lsOutput.append( sOutput ); + lsOutput.append( sOutput ); } const StrList &Target::getOutputList() const { - return lsOutput; + return lsOutput; } void Target::setPrefix( const Bu::String &sPrefix ) { - this->sPrefix = sPrefix; + this->sPrefix = sPrefix; } const Bu::String &Target::getPrefix() const { - return sPrefix; + return sPrefix; } void Target::setRule( const Bu::String &sRule ) { - this->sRule = sRule; + this->sRule = sRule; } const Bu::String &Target::getRule() const { - return sRule; + return sRule; } bool Target::hasRule() const { - return !sRule.isEmpty(); + return !sRule.isEmpty(); } bool Target::isExplicit() const { - return bExplicit; + return bExplicit; } void Target::addDep( Target *pDep ) { - lDeps.append( pDep ); + lDeps.append( pDep ); } const TargetList &Target::getDepList() const { - return lDeps; + return lDeps; } void Target::addProfile( const class AstBranch *pProfRoot ) { - Profile *pProf = new Profile( pProfRoot ); - hProfiles.insert( pProf->getName(), pProf ); - /* - hProfiles.insert( - dynamic_cast( - (*pProfRoot->getBranchBegin()).first() - )->getStrValue(), - pProfRoot - ); - */ + Profile *pProf = new Profile( pProfRoot ); + hProfiles.insert( pProf->getName(), pProf ); + /* + hProfiles.insert( + dynamic_cast( + (*pProfRoot->getBranchBegin()).first() + )->getStrValue(), + pProfRoot + ); + */ } void Target::addProfile( const class Profile *pSrc ) { - hProfiles.insert( pSrc->getName(), new Profile( *pSrc ) ); + hProfiles.insert( pSrc->getName(), new Profile( *pSrc ) ); } bool Target::hasProfile( const Bu::String &sName ) const { - return hProfiles.has( sName ); + return hProfiles.has( sName ); } const Profile *Target::getProfile( const Bu::String &sName ) const { - return hProfiles.get( sName ); + return hProfiles.get( sName ); } void Target::setVars( const VarHash &hNewVars ) { - hVars = hNewVars; + hVars = hNewVars; } const VarHash &Target::getVars() const { - return hVars; + return hVars; } void Target::setDisplay( const Bu::String &sNewDisplay ) { - if( !sDisplay.isSet() ) - sDisplay = sNewDisplay; + if( !sDisplay.isSet() ) + sDisplay = sNewDisplay; } const Bu::String &Target::getDisplay() const { - return sDisplay; + return sDisplay; } void Target::process( class Runner &r, const Bu::String &sProfile ) { - r.getContext().getView()->beginTarget( sProfile, *this ); - bRun = true; - bool bShouldExec = false; - - for( TargetList::iterator i = lDeps.begin(); i; i++ ) - { - if( (*i)->bRun ) - continue; - - // TODO: This is important, in the future, it may be possible for a - // target to be triggered by multiple dependant targets, to cover for - // this the below mergeUnder should be *TEMPORARY* and the target - // that was marged to be reset post processing. - (*i)->mergeUnder( hVars ); - (*i)->process( r, sProfile ); - } - try - { - bShouldExec = hProfiles.get( sProfile )->shouldExec( r, *this ); - } - catch( Bu::HashException &e ) - { - } - - if( !bShouldExec ) - { - r.getContext().getView()->skipTarget( sProfile, *this ); - } - else - { - r.getContext().getView()->processTarget( sProfile, *this ); - r.execProfile( this, sProfile ); - } - - r.getContext().getView()->endTarget(); + r.getContext().getView()->beginTarget( sProfile, *this ); + bRun = true; + bool bShouldExec = false; + + for( TargetList::iterator i = lDeps.begin(); i; i++ ) + { + if( (*i)->bRun ) + continue; + + // TODO: This is important, in the future, it may be possible for a + // target to be triggered by multiple dependant targets, to cover for + // this the below mergeUnder should be *TEMPORARY* and the target + // that was marged to be reset post processing. + (*i)->mergeUnder( hVars ); + (*i)->process( r, sProfile ); + } + try + { + bShouldExec = hProfiles.get( sProfile )->shouldExec( r, *this ); + } + catch( Bu::HashException &e ) + { + } + + if( !bShouldExec ) + { + r.getContext().getView()->skipTarget( sProfile, *this ); + } + else + { + r.getContext().getView()->processTarget( sProfile, *this ); + r.execProfile( this, sProfile ); + } + + r.getContext().getView()->endTarget(); } void Target::mergeUnder( const VarHash &hNewVars ) { - for( VarHash::const_iterator i = hNewVars.begin(); i; i++ ) - { - if( !hVars.has( i.getKey() ) ) - { - hVars.insert( i.getKey(), i.getValue() ); - } - } + for( VarHash::const_iterator i = hNewVars.begin(); i; i++ ) + { + if( !hVars.has( i.getKey() ) ) + { + hVars.insert( i.getKey(), i.getValue() ); + } + } } bool Target::hasRun() { - return bRun; + return bRun; } void Target::mergeUnder( const Target *pSrc ) { - // If either are explicit, then it's explicit - bExplicit = bExplicit || pSrc->bExplicit; + // If either are explicit, then it's explicit + bExplicit = bExplicit || pSrc->bExplicit; - merge( lsInput, pSrc->lsInput ); - merge( lsRequires, pSrc->lsRequires ); - merge( lsOutput, pSrc->lsOutput ); + merge( lsInput, pSrc->lsInput ); + merge( lsRequires, pSrc->lsRequires ); + merge( lsOutput, pSrc->lsOutput ); - if( !sPrefix.isSet() ) - sPrefix = pSrc->sPrefix; + if( !sPrefix.isSet() ) + sPrefix = pSrc->sPrefix; - sRule = pSrc->sRule; + sRule = pSrc->sRule; - mergeUnder( pSrc->hVars ); + mergeUnder( pSrc->hVars ); - // Deps? They should be computed much after merging anyway, peh! - - for( ProfileHash::const_iterator i = pSrc->hProfiles.begin(); i; i++ ) - { - if( !hProfiles.has( i.getKey() ) ) - { - hProfiles.insert( i.getKey(), i.getValue() ); - } - } + // Deps? They should be computed much after merging anyway, peh! + + for( ProfileHash::const_iterator i = pSrc->hProfiles.begin(); i; i++ ) + { + if( !hProfiles.has( i.getKey() ) ) + { + hProfiles.insert( i.getKey(), i.getValue() ); + } + } - if( !sDisplay.isSet() ) - sDisplay = pSrc->sDisplay; + if( !sDisplay.isSet() ) + sDisplay = pSrc->sDisplay; - // Now we need to reset our vars. - hVars.insert("INPUT", lsInput ); - hVars.insert("REQUIRES", lsRequires ); - hVars.insert("OUTPUT", lsOutput ); + // Now we need to reset our vars. + hVars.insert("INPUT", lsInput ); + hVars.insert("REQUIRES", lsRequires ); + hVars.insert("OUTPUT", lsOutput ); } void Target::merge( StrList &lOut, const StrList &lIn ) { - Bu::Heap hStr; - for( StrList::const_iterator i = lOut.begin(); i; i++ ) - { - hStr.enqueue( *i ); - } - for( StrList::const_iterator i = lIn.begin(); i; i++ ) - { - hStr.enqueue( *i ); - } - - lOut.clear(); - - if( hStr.isEmpty() ) - return; - - lOut.append( hStr.dequeue() ); - while( !hStr.isEmpty() ) - { - if( hStr.peek() == lOut.last() ) - { - hStr.dequeue(); - } - else - { - lOut.append( hStr.dequeue() ); - } - } + Bu::Heap hStr; + for( StrList::const_iterator i = lOut.begin(); i; i++ ) + { + hStr.enqueue( *i ); + } + for( StrList::const_iterator i = lIn.begin(); i; i++ ) + { + hStr.enqueue( *i ); + } + + lOut.clear(); + + if( hStr.isEmpty() ) + return; + + lOut.append( hStr.dequeue() ); + while( !hStr.isEmpty() ) + { + if( hStr.peek() == lOut.last() ) + { + hStr.dequeue(); + } + else + { + lOut.append( hStr.dequeue() ); + } + } } void Target::resetRun( bool bHasRun ) { - bRun = bHasRun; + bRun = bHasRun; - for( TargetList::iterator i = lDeps.begin(); i; i++ ) - { - (*i)->resetRun( bHasRun ); - } + for( TargetList::iterator i = lDeps.begin(); i; i++ ) + { + (*i)->resetRun( bHasRun ); + } } void Target::setDepCount() { - bRun = true; - iDepCount = 1; - for( TargetList::iterator i = lDeps.begin(); i; i++ ) - { - if( (*i)->bRun ) - { - continue; - } - (*i)->setDepCount(); - iDepCount += (*i)->getDepCount(); - } + bRun = true; + iDepCount = 1; + for( TargetList::iterator i = lDeps.begin(); i; i++ ) + { + if( (*i)->bRun ) + { + continue; + } + (*i)->setDepCount(); + iDepCount += (*i)->getDepCount(); + } } int Target::getDepCount() const { - return iDepCount; + return iDepCount; } void Target::collapseDeps() { - if( lDeps.getSize() <= 1 ) - return; - Bu::Hash hDep; - for( TargetList::iterator i = lDeps.begin(); i; i++ ) - { - if( hDep.has( (ptrdiff_t)*i ) ) - { - lDeps.erase( i ); - i--; - } - else - { - hDep.insert( (ptrdiff_t)*i, true ); - } - } + if( lDeps.getSize() <= 1 ) + return; + Bu::Hash hDep; + for( TargetList::iterator i = lDeps.begin(); i; i++ ) + { + if( hDep.has( (ptrdiff_t)*i ) ) + { + lDeps.erase( i ); + i--; + } + else + { + hDep.insert( (ptrdiff_t)*i, true ); + } + } } Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t ) { - f.incIndent(); - f << f.nl << "Input = " << t.lsInput << "," << f.nl - << "Requires = " << t.lsRequires << "," << f.nl - << "Output = \"" << t.lsOutput << "\"," << f.nl - << "Prefix = \"" << t.sPrefix << "\"," << f.nl - << "Rule = \"" << t.sRule << "\"," << f.nl - << "Explicit = " << t.bExplicit << "," << f.nl - << "Vars = " << t.hVars - << f.nl; - f.decIndent(); - return f; + f.incIndent(); + f << f.nl << "Input = " << t.lsInput << "," << f.nl + << "Requires = " << t.lsRequires << "," << f.nl + << "Output = \"" << t.lsOutput << "\"," << f.nl + << "Prefix = \"" << t.sPrefix << "\"," << f.nl + << "Rule = \"" << t.sRule << "\"," << f.nl + << "Explicit = " << t.bExplicit << "," << f.nl + << "Vars = " << t.hVars + << f.nl; + f.decIndent(); + return f; } template<> Bu::Formatter &Bu::operator<< ( Bu::Formatter &f, const Target *t ) { - return f << (*t); + return f << (*t); } diff --git a/src/target.h b/src/target.h index b325682..e7645dc 100644 --- a/src/target.h +++ b/src/target.h @@ -6,90 +6,90 @@ class Target { - friend Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t ); + friend Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t ); public: - Target( bool bExplicit ); - Target( const Bu::String &sOutput, bool bExplicit ); - virtual ~Target(); + Target( bool bExplicit ); + Target( const Bu::String &sOutput, bool bExplicit ); + virtual ~Target(); - void addInput( const Bu::String &sInput ); - const StrList &getInputList() const; - void resetInputList( const StrList &lInputs ); + void addInput( const Bu::String &sInput ); + const StrList &getInputList() const; + void resetInputList( const StrList &lInputs ); - void addRequires( const Bu::String &sReq ); - void addRequires( const AstBranch *pBr ); - const StrList &getRequiresList() const; - /** - * This function will get the cached requires if they exist, build them - * if they don't. Use this is conditions, but use buildRequires to force - * a rebuild even if cached data exists. - */ - void gatherRequires( class Runner &r ); - void buildRequires( class Runner &r ); + void addRequires( const Bu::String &sReq ); + void addRequires( const AstBranch *pBr ); + const StrList &getRequiresList() const; + /** + * This function will get the cached requires if they exist, build them + * if they don't. Use this is conditions, but use buildRequires to force + * a rebuild even if cached data exists. + */ + void gatherRequires( class Runner &r ); + void buildRequires( class Runner &r ); - void addOutput( const Bu::String &sOutput ); - const StrList &getOutputList() const; + void addOutput( const Bu::String &sOutput ); + const StrList &getOutputList() const; - void setPrefix( const Bu::String &sPrefix ); - const Bu::String &getPrefix() const; + void setPrefix( const Bu::String &sPrefix ); + const Bu::String &getPrefix() const; - void setRule( const Bu::String &sRule ); - const Bu::String &getRule() const; - bool hasRule() const; + void setRule( const Bu::String &sRule ); + const Bu::String &getRule() const; + bool hasRule() const; - bool isExplicit() const; + bool isExplicit() const; - void addDep( Target *pDep ); - const TargetList &getDepList() const; + void addDep( Target *pDep ); + const TargetList &getDepList() const; - void addProfile( const class AstBranch *pProfRoot ); - void addProfile( const class Profile *pSrc ); - bool hasProfile( const Bu::String &sName ) const; - const class Profile *getProfile( const Bu::String &sName ) const; + void addProfile( const class AstBranch *pProfRoot ); + void addProfile( const class Profile *pSrc ); + bool hasProfile( const Bu::String &sName ) const; + const class Profile *getProfile( const Bu::String &sName ) const; - void setVars( const VarHash &hNewVars ); - const VarHash &getVars() const; + void setVars( const VarHash &hNewVars ); + const VarHash &getVars() const; - void setDisplay( const Bu::String &sNewDisplay ); - const Bu::String &getDisplay() const; + void setDisplay( const Bu::String &sNewDisplay ); + const Bu::String &getDisplay() const; - void process( class Runner &r, const Bu::String &sProfile ); + void process( class Runner &r, const Bu::String &sProfile ); - void mergeUnder( const Target *pSrc ); + void mergeUnder( const Target *pSrc ); - bool hasRun(); + bool hasRun(); - void resetRun( bool bHasRun=true ); - void setDepCount(); - int getDepCount() const; + void resetRun( bool bHasRun=true ); + void setDepCount(); + int getDepCount() const; - void collapseDeps(); + void collapseDeps(); private: - void mergeUnder( const VarHash &hVars ); - void merge( StrList &lOut, const StrList &lIn ); + void mergeUnder( const VarHash &hVars ); + void merge( StrList &lOut, const StrList &lIn ); private: - bool bExplicit; - StrList lsInput; - StrList lsRequires; - StrList lsOutput; - Bu::String sPrefix; - Bu::String sRule; - VarHash hVars; - TargetList lDeps; - ProfileHash hProfiles; - Bu::String sDisplay; - bool bRun; - AstBranchList lbRequires; - int iDepCount; + bool bExplicit; + StrList lsInput; + StrList lsRequires; + StrList lsOutput; + Bu::String sPrefix; + Bu::String sRule; + VarHash hVars; + TargetList lDeps; + ProfileHash hProfiles; + Bu::String sDisplay; + bool bRun; + AstBranchList lbRequires; + int iDepCount; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t ); namespace Bu { - template<> Bu::Formatter &operator<< ( Bu::Formatter &f, const Target *t ); + template<> Bu::Formatter &operator<< ( Bu::Formatter &f, const Target *t ); }; #endif diff --git a/src/variable.cpp b/src/variable.cpp index ffc41a6..bef0ca8 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -6,1036 +6,1036 @@ using Bu::sio; #include Variable::Variable() : - eType( typeNone ) + eType( typeNone ) { - memset( &uVal, 0, sizeof(uVal) ); + memset( &uVal, 0, sizeof(uVal) ); } Variable::Variable( Type t ) : - eType( t ) + eType( t ) { - memset( &uVal, 0, sizeof(uVal) ); - if( eType == typeString || eType == typeRef ) - { - uVal.sVal = new Bu::String; - } - else if( eType == typeList ) - { - uVal.lVal = new VarList; - } + memset( &uVal, 0, sizeof(uVal) ); + if( eType == typeString || eType == typeRef ) + { + uVal.sVal = new Bu::String; + } + else if( eType == typeList ) + { + uVal.lVal = new VarList; + } } Variable::Variable( int iVal ) : - eType( typeInt ) + eType( typeInt ) { - memset( &uVal, 0, sizeof(uVal) ); - uVal.iVal = iVal; + memset( &uVal, 0, sizeof(uVal) ); + uVal.iVal = iVal; } Variable::Variable( double fVal ) : - eType( typeFloat ) + eType( typeFloat ) { - memset( &uVal, 0, sizeof(uVal) ); - uVal.fVal = fVal; + memset( &uVal, 0, sizeof(uVal) ); + uVal.fVal = fVal; } Variable::Variable( bool bVal ) : - eType( typeBool ) + eType( typeBool ) { - memset( &uVal, 0, sizeof(uVal) ); - uVal.bVal = bVal; + memset( &uVal, 0, sizeof(uVal) ); + uVal.bVal = bVal; } Variable::Variable( const Bu::String &sVal ) : - eType( typeString ) + eType( typeString ) { - memset( &uVal, 0, sizeof(uVal) ); - uVal.sVal = new Bu::String( sVal ); + memset( &uVal, 0, sizeof(uVal) ); + uVal.sVal = new Bu::String( sVal ); } Variable::Variable( const char *sVal ) : - eType( typeString ) + eType( typeString ) { - memset( &uVal, 0, sizeof(uVal) ); - uVal.sVal = new Bu::String( sVal ); + memset( &uVal, 0, sizeof(uVal) ); + uVal.sVal = new Bu::String( sVal ); } Variable::Variable( const Variable &v ) : - eType( v.eType ) + eType( v.eType ) { - memset( &uVal, 0, sizeof(uVal) ); - if( eType == typeString || eType == typeRef ) - { - uVal.sVal = new Bu::String( *v.uVal.sVal ); - } - else if( eType == typeList ) - { - uVal.lVal = new VarList( *v.uVal.lVal ); - } - else - { - uVal = v.uVal; - } + memset( &uVal, 0, sizeof(uVal) ); + if( eType == typeString || eType == typeRef ) + { + uVal.sVal = new Bu::String( *v.uVal.sVal ); + } + else if( eType == typeList ) + { + uVal.lVal = new VarList( *v.uVal.lVal ); + } + else + { + uVal = v.uVal; + } } - + Variable::Variable( const class AstLeaf &l ) { - switch( l.getDataType() ) - { - case AstNode::typeDataInt: - eType = typeInt; - uVal.iVal = l.getIntValue(); - break; - - case AstNode::typeDataFloat: - eType = typeFloat; - uVal.fVal = l.getFloatValue(); - break; - - case AstNode::typeDataBool: - eType = typeBool; - uVal.bVal = l.getBoolValue(); - break; - - case AstNode::typeDataString: - eType = typeString; - uVal.sVal = new Bu::String( l.getStrValue() ); - break; - - case AstNode::typeDataNone: - eType = typeNone; - memset( &uVal, 0, sizeof(uVal) ); - break; - - default: - sio << "Unhandled type <>" << sio.nl << sio.nl; - break; - } + switch( l.getDataType() ) + { + case AstNode::typeDataInt: + eType = typeInt; + uVal.iVal = l.getIntValue(); + break; + + case AstNode::typeDataFloat: + eType = typeFloat; + uVal.fVal = l.getFloatValue(); + break; + + case AstNode::typeDataBool: + eType = typeBool; + uVal.bVal = l.getBoolValue(); + break; + + case AstNode::typeDataString: + eType = typeString; + uVal.sVal = new Bu::String( l.getStrValue() ); + break; + + case AstNode::typeDataNone: + eType = typeNone; + memset( &uVal, 0, sizeof(uVal) ); + break; + + default: + sio << "Unhandled type <>" << sio.nl << sio.nl; + break; + } } Variable::Variable( const StrList &lst ) { - if( lst.getSize() == 1 ) - { - eType = typeString; - uVal.sVal = new Bu::String( lst.first() ); - } - else - { - eType = typeList; - uVal.lVal = new VarList(); - for( StrList::const_iterator i = lst.begin(); i; i++ ) - { - uVal.lVal->append( Variable( *i ) ); - } - } + if( lst.getSize() == 1 ) + { + eType = typeString; + uVal.sVal = new Bu::String( lst.first() ); + } + else + { + eType = typeList; + uVal.lVal = new VarList(); + for( StrList::const_iterator i = lst.begin(); i; i++ ) + { + uVal.lVal->append( Variable( *i ) ); + } + } } Variable::Variable( const VarList &lst ) { - eType = typeList; - uVal.lVal = new VarList( lst ); + eType = typeList; + uVal.lVal = new VarList( lst ); } Variable::Variable( void *oVal ) : - eType( typeOpaque ) + eType( typeOpaque ) { - memset( &uVal, 0, sizeof(uVal) ); - uVal.oVal = oVal; + memset( &uVal, 0, sizeof(uVal) ); + uVal.oVal = oVal; } Variable::~Variable() { - if( eType == typeString || eType == typeRef ) - { - delete uVal.sVal; - } - else if( eType == typeList ) - { - delete uVal.lVal; - } + if( eType == typeString || eType == typeRef ) + { + delete uVal.sVal; + } + else if( eType == typeList ) + { + delete uVal.lVal; + } } Variable Variable::mkRef( const Bu::String &sVal ) { - Variable v( typeRef ); - (*v.uVal.sVal) = sVal; - return v; + Variable v( typeRef ); + (*v.uVal.sVal) = sVal; + return v; } Variable::Type Variable::getType() const { - return eType; + return eType; } int Variable::getInt() const { - if( eType != typeInt ) throw Bu::ExceptionBase("Wrong variable type."); - return uVal.iVal; + if( eType != typeInt ) throw Bu::ExceptionBase("Wrong variable type."); + return uVal.iVal; } double Variable::getFloat() const { - if( eType != typeFloat ) throw Bu::ExceptionBase("Wrong variable type."); - return uVal.fVal; + if( eType != typeFloat ) throw Bu::ExceptionBase("Wrong variable type."); + return uVal.fVal; } bool Variable::getBool() const { - if( eType != typeBool ) throw Bu::ExceptionBase("Wrong variable type."); - return uVal.bVal; + if( eType != typeBool ) throw Bu::ExceptionBase("Wrong variable type."); + return uVal.bVal; } const Bu::String &Variable::getString() const { - if( eType != typeString && eType != typeRef ) throw Bu::ExceptionBase("Wrong variable type."); - return *uVal.sVal; + if( eType != typeString && eType != typeRef ) throw Bu::ExceptionBase("Wrong variable type."); + return *uVal.sVal; } const VarList &Variable::getList() const { - if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); - return *uVal.lVal; + if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); + return *uVal.lVal; } const void *Variable::getOpaque() const { - if( eType != typeOpaque ) throw Bu::ExceptionBase("Wrong variable type."); - return uVal.oVal; + if( eType != typeOpaque ) throw Bu::ExceptionBase("Wrong variable type."); + return uVal.oVal; } int Variable::toInt() const { - switch( eType ) - { - case typeInt: - return uVal.iVal; + switch( eType ) + { + case typeInt: + return uVal.iVal; - case typeFloat: - return (int)uVal.fVal; + case typeFloat: + return (int)uVal.fVal; - case typeBool: - return (uVal.bVal)?(1):(0); + case typeBool: + return (uVal.bVal)?(1):(0); - case typeString: - case typeRef: - return strtol( uVal.sVal->getStr(), NULL, 0 ); + case typeString: + case typeRef: + return strtol( uVal.sVal->getStr(), NULL, 0 ); - default: - return 0; - } - return 0; + default: + return 0; + } + return 0; } double Variable::toFloat() const { - switch( eType ) - { - case typeInt: - return (double)uVal.iVal; + switch( eType ) + { + case typeInt: + return (double)uVal.iVal; - case typeFloat: - return uVal.fVal; + case typeFloat: + return uVal.fVal; - case typeBool: - return (uVal.bVal)?(1.0):(0.0); + case typeBool: + return (uVal.bVal)?(1.0):(0.0); - case typeString: - case typeRef: - return strtod( uVal.sVal->getStr(), NULL ); + case typeString: + case typeRef: + return strtod( uVal.sVal->getStr(), NULL ); - default: - return 0.0; - } - return 0.0; + default: + return 0.0; + } + return 0.0; } bool Variable::toBool() const { - switch( eType ) - { - case typeInt: - return uVal.iVal != 0; + switch( eType ) + { + case typeInt: + return uVal.iVal != 0; - case typeFloat: - return uVal.fVal != 0.0; + case typeFloat: + return uVal.fVal != 0.0; - case typeBool: - return uVal.bVal; + case typeBool: + return uVal.bVal; - case typeString: - case typeRef: - return (*uVal.sVal) == "true"; + case typeString: + case typeRef: + return (*uVal.sVal) == "true"; - case typeList: - return !(*uVal.lVal).isEmpty(); + case typeList: + return !(*uVal.lVal).isEmpty(); - default: - return false; - } - return false; + default: + return false; + } + return false; } Bu::String Variable::toString() const { - Bu::String sRet; - switch( eType ) - { - case typeNone: - // No type, no data, we return empty string - break; - - case typeInt: - sRet = Bu::String("%1").arg( uVal.iVal ); - break; - - case typeFloat: - sRet = Bu::String("%1").arg( uVal.fVal ); - break; - - case typeBool: - sRet = (uVal.bVal)?("true"):("false"); - break; - - case typeString: - case typeRef: - sRet = *uVal.sVal; - break; - - case typeList: - { - for( VarList::const_iterator i = uVal.lVal->begin(); i; i++ ) - { - if( i != uVal.lVal->begin() ) - sRet += " "; - sRet += (*i).toString(); - } - } - break; - - case typeVersion: - break; - - case typeOpaque: - sRet = Bu::String("").arg( uVal.oVal ); - break; - } - - return sRet; + Bu::String sRet; + switch( eType ) + { + case typeNone: + // No type, no data, we return empty string + break; + + case typeInt: + sRet = Bu::String("%1").arg( uVal.iVal ); + break; + + case typeFloat: + sRet = Bu::String("%1").arg( uVal.fVal ); + break; + + case typeBool: + sRet = (uVal.bVal)?("true"):("false"); + break; + + case typeString: + case typeRef: + sRet = *uVal.sVal; + break; + + case typeList: + { + for( VarList::const_iterator i = uVal.lVal->begin(); i; i++ ) + { + if( i != uVal.lVal->begin() ) + sRet += " "; + sRet += (*i).toString(); + } + } + break; + + case typeVersion: + break; + + case typeOpaque: + sRet = Bu::String("").arg( uVal.oVal ); + break; + } + + return sRet; } VarList Variable::toList() const { - if( eType == typeList ) - return *uVal.lVal; - return VarList( *this ); + if( eType == typeList ) + return *uVal.lVal; + return VarList( *this ); } Variable Variable::toType( Type eNewType ) const { - switch( eNewType ) - { - case typeNone: - return Variable(); + switch( eNewType ) + { + case typeNone: + return Variable(); - case typeBool: - return Variable( toBool() ); + case typeBool: + return Variable( toBool() ); - case typeInt: - return Variable( toInt() ); + case typeInt: + return Variable( toInt() ); - case typeFloat: - return Variable( toFloat() ); + case typeFloat: + return Variable( toFloat() ); - case typeVersion: - return Variable(); + case typeVersion: + return Variable(); - case typeString: - return Variable( toString() ); + case typeString: + return Variable( toString() ); - case typeList: - return Variable( toList() ); - - case typeRef: - return Variable::mkRef( toString() ); + case typeList: + return Variable( toList() ); + + case typeRef: + return Variable::mkRef( toString() ); - case typeOpaque: - throw Bu::ExceptionBase("Cannot convert opaque types."); - } - throw Bu::ExceptionBase("Unhandled case in Variable toType"); + case typeOpaque: + throw Bu::ExceptionBase("Cannot convert opaque types."); + } + throw Bu::ExceptionBase("Unhandled case in Variable toType"); } void Variable::append( const Variable &v ) { - if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); - - if( v.eType == typeList ) - { - uVal.lVal->append( *v.uVal.lVal ); - } - else - { - uVal.lVal->append( v ); - } + if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); + + if( v.eType == typeList ) + { + uVal.lVal->append( *v.uVal.lVal ); + } + else + { + uVal.lVal->append( v ); + } } VarList::iterator Variable::begin() { - if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); + if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); - return uVal.lVal->begin(); + return uVal.lVal->begin(); } VarList::const_iterator Variable::begin() const { - if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); - - return const_cast(uVal.lVal)->begin(); + if( eType != typeList ) throw Bu::ExceptionBase("Wrong variable type."); + + return const_cast(uVal.lVal)->begin(); } void Variable::doNegate() { - switch( eType ) - { - case typeNone: - break; - - case typeBool: - throw Bu::ExceptionBase("You cannot negate boolean values."); - - case typeInt: - uVal.iVal = -uVal.iVal; - break; - - case typeFloat: - uVal.fVal = -uVal.fVal; - break; - - case typeVersion: - throw Bu::ExceptionBase("You cannot negate version values."); - - case typeString: - throw Bu::ExceptionBase("You cannot negate string values."); - - case typeList: - throw Bu::ExceptionBase("You cannot negate list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot negate reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot negate opaque values."); - } + switch( eType ) + { + case typeNone: + break; + + case typeBool: + throw Bu::ExceptionBase("You cannot negate boolean values."); + + case typeInt: + uVal.iVal = -uVal.iVal; + break; + + case typeFloat: + uVal.fVal = -uVal.fVal; + break; + + case typeVersion: + throw Bu::ExceptionBase("You cannot negate version values."); + + case typeString: + throw Bu::ExceptionBase("You cannot negate string values."); + + case typeList: + throw Bu::ExceptionBase("You cannot negate list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot negate reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot negate opaque values."); + } } void Variable::doNot() { - bool bVal = !toBool(); - reset( typeBool ); - uVal.bVal = bVal; + bool bVal = !toBool(); + reset( typeBool ); + uVal.bVal = bVal; } const Variable &Variable::operator=( const Variable &rhs ) { - reset( rhs.eType ); - if( rhs.eType == typeString || rhs.eType == typeRef ) - { - uVal.sVal = new Bu::String( *rhs.uVal.sVal ); - } - else if( rhs.eType == typeList ) - { - uVal.lVal = new VarList( *rhs.uVal.lVal ); - } - else - { - uVal = rhs.uVal; - } - - return *this; + reset( rhs.eType ); + if( rhs.eType == typeString || rhs.eType == typeRef ) + { + uVal.sVal = new Bu::String( *rhs.uVal.sVal ); + } + else if( rhs.eType == typeList ) + { + uVal.lVal = new VarList( *rhs.uVal.lVal ); + } + else + { + uVal = rhs.uVal; + } + + return *this; } const Variable &Variable::operator=( const int &rhs ) { - reset( typeInt ); - uVal.iVal = rhs; + reset( typeInt ); + uVal.iVal = rhs; - return *this; + return *this; } const Variable &Variable::operator=( const double &rhs ) { - reset( typeFloat ); - uVal.fVal = rhs; + reset( typeFloat ); + uVal.fVal = rhs; - return *this; + return *this; } const Variable &Variable::operator=( const bool &rhs ) { - reset( typeBool ); - uVal.bVal = rhs; + reset( typeBool ); + uVal.bVal = rhs; - return *this; + return *this; } const Variable &Variable::operator=( const Bu::String &rhs ) { - reset( typeString ); - uVal.sVal = new Bu::String( rhs ); + reset( typeString ); + uVal.sVal = new Bu::String( rhs ); - return *this; + return *this; } const Variable &Variable::operator=( void *rhs ) { - reset( typeOpaque ); - uVal.oVal = rhs; + reset( typeOpaque ); + uVal.oVal = rhs; - return *this; + return *this; } const Variable &Variable::operator+=( const Variable &rhs ) { - switch( eType ) - { - case typeNone: - reset( rhs.eType ); - if( eType == typeString || eType == typeRef ) - { - uVal.sVal = new Bu::String( *rhs.uVal.sVal ); - } - else if( eType == typeList ) - { - uVal.lVal = new VarList( *rhs.uVal.lVal ); - } - else - { - uVal = rhs.uVal; - } - break; - - case typeInt: - uVal.iVal += rhs.getInt(); - break; - - case typeFloat: - uVal.fVal += rhs.getFloat(); - break; - - case typeBool: - throw Bu::ExceptionBase("Can't += with a boolean..."); - break; - - case typeString: - uVal.sVal->append(" "); - uVal.sVal->append( rhs.getString() ); - break; - - case typeList: - uVal.lVal->append( rhs.getList() ); - break; - - case typeVersion: - break; - - default: - break; - } - return *this; + switch( eType ) + { + case typeNone: + reset( rhs.eType ); + if( eType == typeString || eType == typeRef ) + { + uVal.sVal = new Bu::String( *rhs.uVal.sVal ); + } + else if( eType == typeList ) + { + uVal.lVal = new VarList( *rhs.uVal.lVal ); + } + else + { + uVal = rhs.uVal; + } + break; + + case typeInt: + uVal.iVal += rhs.getInt(); + break; + + case typeFloat: + uVal.fVal += rhs.getFloat(); + break; + + case typeBool: + throw Bu::ExceptionBase("Can't += with a boolean..."); + break; + + case typeString: + uVal.sVal->append(" "); + uVal.sVal->append( rhs.getString() ); + break; + + case typeList: + uVal.lVal->append( rhs.getList() ); + break; + + case typeVersion: + break; + + default: + break; + } + return *this; } const Variable &Variable::operator<<( const Variable &rhs ) { - switch( eType ) - { - case typeNone: - reset( rhs.eType ); - if( eType == typeString ) - { - uVal.sVal = new Bu::String( *rhs.uVal.sVal ); - } - else if( eType == typeList ) - { - uVal.lVal = new VarList( *rhs.uVal.lVal ); - } - else - { - uVal = rhs.uVal; - } - break; - - case typeString: - uVal.sVal->append( rhs.getString() ); - break; - - case typeList: - uVal.lVal->append( rhs.getList() ); - break; - - default: - throw Bu::ExceptionBase("Can't << with non-string or non-list."); - break; - } - return *this; + switch( eType ) + { + case typeNone: + reset( rhs.eType ); + if( eType == typeString ) + { + uVal.sVal = new Bu::String( *rhs.uVal.sVal ); + } + else if( eType == typeList ) + { + uVal.lVal = new VarList( *rhs.uVal.lVal ); + } + else + { + uVal = rhs.uVal; + } + break; + + case typeString: + uVal.sVal->append( rhs.getString() ); + break; + + case typeList: + uVal.lVal->append( rhs.getList() ); + break; + + default: + throw Bu::ExceptionBase("Can't << with non-string or non-list."); + break; + } + return *this; } bool Variable::operator==( const Variable &rhs ) const { - if( eType != rhs.eType ) - return false; - switch( eType ) - { - case typeNone: - return true; + if( eType != rhs.eType ) + return false; + switch( eType ) + { + case typeNone: + return true; - case typeInt: - return uVal.iVal == rhs.uVal.iVal; + case typeInt: + return uVal.iVal == rhs.uVal.iVal; - case typeFloat: - return uVal.fVal == rhs.uVal.fVal; + case typeFloat: + return uVal.fVal == rhs.uVal.fVal; - case typeBool: - return uVal.bVal == rhs.uVal.bVal; + case typeBool: + return uVal.bVal == rhs.uVal.bVal; - case typeString: - case typeRef: - return *uVal.sVal == *rhs.uVal.sVal; + case typeString: + case typeRef: + return *uVal.sVal == *rhs.uVal.sVal; - case typeList: - return *uVal.lVal == *rhs.uVal.lVal; + case typeList: + return *uVal.lVal == *rhs.uVal.lVal; - case typeVersion: - return false; + case typeVersion: + return false; - case typeOpaque: - return uVal.oVal == rhs.uVal.oVal; - } + case typeOpaque: + return uVal.oVal == rhs.uVal.oVal; + } - return false; + return false; } bool Variable::operator!=( const Variable &rhs ) const { - return !(*this == rhs); + return !(*this == rhs); } bool Variable::operator<( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return false; - - case typeBool: - throw Bu::ExceptionBase("You cannot < compare boolean values."); - - case typeInt: - return toInt() < rhs.toInt(); - - case typeFloat: - return toFloat() < rhs.toFloat(); - - case typeVersion: - return true; - - case typeString: - return toString() < rhs.toString(); - - case typeList: - throw Bu::ExceptionBase("You cannot < compare list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot < compare reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot < compare opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable < compare"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return false; + + case typeBool: + throw Bu::ExceptionBase("You cannot < compare boolean values."); + + case typeInt: + return toInt() < rhs.toInt(); + + case typeFloat: + return toFloat() < rhs.toFloat(); + + case typeVersion: + return true; + + case typeString: + return toString() < rhs.toString(); + + case typeList: + throw Bu::ExceptionBase("You cannot < compare list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot < compare reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot < compare opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable < compare"); } bool Variable::operator>( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return false; - - case typeBool: - throw Bu::ExceptionBase("You cannot > compare boolean values."); - - case typeInt: - return toInt() > rhs.toInt(); - - case typeFloat: - return toFloat() > rhs.toFloat(); - - case typeVersion: - return true; - - case typeString: - return toString() > rhs.toString(); - - case typeList: - throw Bu::ExceptionBase("You cannot > compare list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot > compare reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot > compare opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable > compare"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return false; + + case typeBool: + throw Bu::ExceptionBase("You cannot > compare boolean values."); + + case typeInt: + return toInt() > rhs.toInt(); + + case typeFloat: + return toFloat() > rhs.toFloat(); + + case typeVersion: + return true; + + case typeString: + return toString() > rhs.toString(); + + case typeList: + throw Bu::ExceptionBase("You cannot > compare list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot > compare reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot > compare opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable > compare"); } bool Variable::operator<=( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return false; - - case typeBool: - throw Bu::ExceptionBase("You cannot <= compare boolean values."); - - case typeInt: - return toInt() <= rhs.toInt(); - - case typeFloat: - return toFloat() <= rhs.toFloat(); - - case typeVersion: - return true; - - case typeString: - return toString() <= rhs.toString(); - - case typeList: - throw Bu::ExceptionBase("You cannot <= compare list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot <= compare reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot <= compare opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable <= compare"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return false; + + case typeBool: + throw Bu::ExceptionBase("You cannot <= compare boolean values."); + + case typeInt: + return toInt() <= rhs.toInt(); + + case typeFloat: + return toFloat() <= rhs.toFloat(); + + case typeVersion: + return true; + + case typeString: + return toString() <= rhs.toString(); + + case typeList: + throw Bu::ExceptionBase("You cannot <= compare list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot <= compare reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot <= compare opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable <= compare"); } bool Variable::operator>=( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return false; - - case typeBool: - throw Bu::ExceptionBase("You cannot >= compare boolean values."); - - case typeInt: - return toInt() >= rhs.toInt(); - - case typeFloat: - return toFloat() >= rhs.toFloat(); - - case typeVersion: - return true; - - case typeString: - return toString() >= rhs.toString(); - - case typeList: - throw Bu::ExceptionBase("You cannot >= compare list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot >= compare reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot >= compare opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable >= compare"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return false; + + case typeBool: + throw Bu::ExceptionBase("You cannot >= compare boolean values."); + + case typeInt: + return toInt() >= rhs.toInt(); + + case typeFloat: + return toFloat() >= rhs.toFloat(); + + case typeVersion: + return true; + + case typeString: + return toString() >= rhs.toString(); + + case typeList: + throw Bu::ExceptionBase("You cannot >= compare list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot >= compare reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot >= compare opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable >= compare"); } Variable Variable::operator+( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return Variable(); - - case typeBool: - throw Bu::ExceptionBase("You cannot add boolean values."); - - case typeInt: - return Variable( toInt() + rhs.toInt() ); - - case typeFloat: - return Variable( toFloat() + rhs.toFloat() ); - - case typeVersion: - throw Bu::ExceptionBase("You cannot add version values."); - - case typeString: - return Variable( toString() + rhs.toString() ); - - case typeList: - return Variable( toList() + rhs.toList() ); - - case typeRef: - throw Bu::ExceptionBase("You cannot add reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot add opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable add"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return Variable(); + + case typeBool: + throw Bu::ExceptionBase("You cannot add boolean values."); + + case typeInt: + return Variable( toInt() + rhs.toInt() ); + + case typeFloat: + return Variable( toFloat() + rhs.toFloat() ); + + case typeVersion: + throw Bu::ExceptionBase("You cannot add version values."); + + case typeString: + return Variable( toString() + rhs.toString() ); + + case typeList: + return Variable( toList() + rhs.toList() ); + + case typeRef: + throw Bu::ExceptionBase("You cannot add reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot add opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable add"); } Variable Variable::operator-( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return Variable(); - - case typeBool: - throw Bu::ExceptionBase("You cannot subtract boolean values."); - - case typeInt: - return Variable( toInt() - rhs.toInt() ); - - case typeFloat: - return Variable( toFloat() - rhs.toFloat() ); - - case typeVersion: - throw Bu::ExceptionBase("You cannot subtract version values."); - - case typeString: - throw Bu::ExceptionBase("You cannot subtract string values."); - - case typeList: - return Variable( toList() - rhs.toList() ); - - case typeRef: - throw Bu::ExceptionBase("You cannot subtract reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot subtract opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable subtract"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return Variable(); + + case typeBool: + throw Bu::ExceptionBase("You cannot subtract boolean values."); + + case typeInt: + return Variable( toInt() - rhs.toInt() ); + + case typeFloat: + return Variable( toFloat() - rhs.toFloat() ); + + case typeVersion: + throw Bu::ExceptionBase("You cannot subtract version values."); + + case typeString: + throw Bu::ExceptionBase("You cannot subtract string values."); + + case typeList: + return Variable( toList() - rhs.toList() ); + + case typeRef: + throw Bu::ExceptionBase("You cannot subtract reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot subtract opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable subtract"); } Variable Variable::operator*( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return Variable(); - - case typeBool: - throw Bu::ExceptionBase("You cannot multiply boolean values."); - - case typeInt: - return Variable( toInt() * rhs.toInt() ); - - case typeFloat: - return Variable( toFloat() * rhs.toFloat() ); - - case typeVersion: - throw Bu::ExceptionBase("You cannot multiply version values."); - - case typeString: - throw Bu::ExceptionBase("You cannot multiply string values."); - - case typeList: - throw Bu::ExceptionBase("You cannot multiply list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot multiply reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot multiply opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable multiply"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return Variable(); + + case typeBool: + throw Bu::ExceptionBase("You cannot multiply boolean values."); + + case typeInt: + return Variable( toInt() * rhs.toInt() ); + + case typeFloat: + return Variable( toFloat() * rhs.toFloat() ); + + case typeVersion: + throw Bu::ExceptionBase("You cannot multiply version values."); + + case typeString: + throw Bu::ExceptionBase("You cannot multiply string values."); + + case typeList: + throw Bu::ExceptionBase("You cannot multiply list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot multiply reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot multiply opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable multiply"); } Variable Variable::operator/( const Variable &rhs ) const { - Type eTop = Bu::buMax( eType, rhs.eType ); - switch( eTop ) - { - case typeNone: - return Variable(); - - case typeBool: - throw Bu::ExceptionBase("You cannot divide boolean values."); - - case typeInt: - return Variable( toInt() / rhs.toInt() ); - - case typeFloat: - return Variable( toFloat() / rhs.toFloat() ); - - case typeVersion: - throw Bu::ExceptionBase("You cannot divide version values."); - - case typeString: - throw Bu::ExceptionBase("You cannot divide string values."); - - case typeList: - throw Bu::ExceptionBase("You cannot divide list values."); - - case typeRef: - throw Bu::ExceptionBase("You cannot divide reference values."); - - case typeOpaque: - throw Bu::ExceptionBase("You cannot divide opaque values."); - } - throw Bu::ExceptionBase("Unhandled case in Variable divide"); + Type eTop = Bu::buMax( eType, rhs.eType ); + switch( eTop ) + { + case typeNone: + return Variable(); + + case typeBool: + throw Bu::ExceptionBase("You cannot divide boolean values."); + + case typeInt: + return Variable( toInt() / rhs.toInt() ); + + case typeFloat: + return Variable( toFloat() / rhs.toFloat() ); + + case typeVersion: + throw Bu::ExceptionBase("You cannot divide version values."); + + case typeString: + throw Bu::ExceptionBase("You cannot divide string values."); + + case typeList: + throw Bu::ExceptionBase("You cannot divide list values."); + + case typeRef: + throw Bu::ExceptionBase("You cannot divide reference values."); + + case typeOpaque: + throw Bu::ExceptionBase("You cannot divide opaque values."); + } + throw Bu::ExceptionBase("Unhandled case in Variable divide"); } void Variable::reset( Type eNewType ) { - if( eType == typeString || eType == typeRef ) - { - delete uVal.sVal; - } - else if( eType == typeList ) - { - delete uVal.lVal; - } - memset( &uVal, 0, sizeof(uVal) ); - - eType = eNewType; + if( eType == typeString || eType == typeRef ) + { + delete uVal.sVal; + } + else if( eType == typeList ) + { + delete uVal.lVal; + } + memset( &uVal, 0, sizeof(uVal) ); + + eType = eNewType; } Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t ) { - switch( t ) - { - case Variable::typeNone: f << "*typeless*"; break; - case Variable::typeInt: f << "int"; break; - case Variable::typeFloat: f << "double"; break; - case Variable::typeBool: f << "bool"; break; - case Variable::typeString: f << "string"; break; - case Variable::typeList: f << "list"; break; - case Variable::typeVersion: f << "version"; break; - case Variable::typeRef: f << "ref"; break; - case Variable::typeOpaque: f << "opaque"; break; - } - return f; + switch( t ) + { + case Variable::typeNone: f << "*typeless*"; break; + case Variable::typeInt: f << "int"; break; + case Variable::typeFloat: f << "double"; break; + case Variable::typeBool: f << "bool"; break; + case Variable::typeString: f << "string"; break; + case Variable::typeList: f << "list"; break; + case Variable::typeVersion: f << "version"; break; + case Variable::typeRef: f << "ref"; break; + case Variable::typeOpaque: f << "opaque"; break; + } + return f; } Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v ) { - f << "Variable(" << v.getType() << ") = "; - switch( v.getType() ) - { - case Variable::typeNone: break; - case Variable::typeInt: f << v.getInt(); break; - case Variable::typeFloat: f << v.getFloat(); break; - case Variable::typeBool: f << v.getBool(); break; - case Variable::typeString: f << v.getString(); break; - case Variable::typeList: f << v.getList(); break; - case Variable::typeVersion:/*f << v.getVersion();*/ break; - case Variable::typeRef: f << v.getString(); break; - case Variable::typeOpaque: f << ""; - break; - } - - return f; + f << "Variable(" << v.getType() << ") = "; + switch( v.getType() ) + { + case Variable::typeNone: break; + case Variable::typeInt: f << v.getInt(); break; + case Variable::typeFloat: f << v.getFloat(); break; + case Variable::typeBool: f << v.getBool(); break; + case Variable::typeString: f << v.getString(); break; + case Variable::typeList: f << v.getList(); break; + case Variable::typeVersion:/*f << v.getVersion();*/ break; + case Variable::typeRef: f << v.getString(); break; + case Variable::typeOpaque: f << ""; + break; + } + + return f; } Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ) { - ar << (int8_t)v.eType; - switch( v.eType ) - { - case Variable::typeNone: - break; + ar << (int8_t)v.eType; + switch( v.eType ) + { + case Variable::typeNone: + break; - case Variable::typeBool: - ar << v.uVal.bVal; - break; + case Variable::typeBool: + ar << v.uVal.bVal; + break; - case Variable::typeInt: - ar << v.uVal.iVal; - break; + case Variable::typeInt: + ar << v.uVal.iVal; + break; - case Variable::typeFloat: - ar << v.uVal.fVal; - break; + case Variable::typeFloat: + ar << v.uVal.fVal; + break; - case Variable::typeVersion: - break; + case Variable::typeVersion: + break; - case Variable::typeString: - ar << *v.uVal.sVal; - break; + case Variable::typeString: + ar << *v.uVal.sVal; + break; - case Variable::typeList: - ar << *v.uVal.lVal; - break; + case Variable::typeList: + ar << *v.uVal.lVal; + break; - case Variable::typeRef: - ar << *v.uVal.sVal; - break; + case Variable::typeRef: + ar << *v.uVal.sVal; + break; - case Variable::typeOpaque: - break; - } + case Variable::typeOpaque: + break; + } - return ar; + return ar; } Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ) { - int8_t t; - ar >> t; - v.eType = (Variable::Type)t; - v.reset( v.eType ); - switch( v.eType ) - { - case Variable::typeNone: - break; - - case Variable::typeBool: - ar >> v.uVal.bVal; - break; - - case Variable::typeInt: - ar >> v.uVal.iVal; - break; - - case Variable::typeFloat: - ar >> v.uVal.fVal; - break; - - case Variable::typeVersion: - break; - - case Variable::typeString: - ar >> *v.uVal.sVal; - break; - - case Variable::typeList: - ar >> *v.uVal.lVal; - break; - - case Variable::typeRef: - ar >> *v.uVal.sVal; - break; - - case Variable::typeOpaque: - break; - } - - return ar; + int8_t t; + ar >> t; + v.eType = (Variable::Type)t; + v.reset( v.eType ); + switch( v.eType ) + { + case Variable::typeNone: + break; + + case Variable::typeBool: + ar >> v.uVal.bVal; + break; + + case Variable::typeInt: + ar >> v.uVal.iVal; + break; + + case Variable::typeFloat: + ar >> v.uVal.fVal; + break; + + case Variable::typeVersion: + break; + + case Variable::typeString: + ar >> *v.uVal.sVal; + break; + + case Variable::typeList: + ar >> *v.uVal.lVal; + break; + + case Variable::typeRef: + ar >> *v.uVal.sVal; + break; + + case Variable::typeOpaque: + break; + } + + return ar; } VarList operator-( const VarList &rBase, const VarList &rSub ) diff --git a/src/variable.h b/src/variable.h index 890552a..f6c2044 100644 --- a/src/variable.h +++ b/src/variable.h @@ -12,109 +12,109 @@ class Variable friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v ); friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v ); public: - enum Type - { - typeNone, - typeBool, - typeInt, - typeFloat, - typeVersion, - typeString, - typeList, - typeRef, /**< Reference by name, it's just a string. */ - typeOpaque /**< Only useful to functions. */ - }; + enum Type + { + typeNone, + typeBool, + typeInt, + typeFloat, + typeVersion, + typeString, + typeList, + typeRef, /**< Reference by name, it's just a string. */ + typeOpaque /**< Only useful to functions. */ + }; public: - Variable(); - Variable( Type t ); - Variable( int iVal ); - Variable( double fVal ); - Variable( bool bVal ); - Variable( const Bu::String &sVal ); - Variable( const char *sVal ); - Variable( const Variable &v ); - Variable( const class AstLeaf &l ); - /** - * This special case function turns the variable into a string if there is - * only one string in the list, or a list of strings if there is more or - * less than one. - */ - Variable( const StrList &lst ); - Variable( const VarList &lst ); - Variable( void *oVal ); - virtual ~Variable(); - - static Variable mkRef( const Bu::String &sVal ); - - Type getType() const; - - // Raw aquisition functions, if the type isn't right, - // they throw an exception - int getInt() const; - double getFloat() const; - bool getBool() const; - const Bu::String &getString() const; - const VarList &getList() const; - const void *getOpaque() const; - - // Conversion functions, they'll return the requested type, maybe an error - // if the source data is really bad - int toInt() const; - double toFloat() const; - bool toBool() const; - Bu::String toString() const; - VarList toList() const; - - Variable toType( Type eNewType ) const; - - void append( const Variable &v ); - VarList::iterator begin(); - VarList::const_iterator begin() const; - - void doNegate(); - void doNot(); - - const Variable &operator=( const Variable &rhs ); - const Variable &operator=( const int &rhs ); - const Variable &operator=( const double &rhs ); - const Variable &operator=( const bool &rhs ); - const Variable &operator=( const Bu::String &rhs ); - const Variable &operator=( void *rhs ); - - const Variable &operator+=( const Variable &rhs ); - const Variable &operator<<( const Variable &rhs ); - - bool operator==( const Variable &rhs ) const; - bool operator!=( const Variable &rhs ) const; - bool operator<( const Variable &rhs ) const; - bool operator>( const Variable &rhs ) const; - bool operator<=( const Variable &rhs ) const; - bool operator>=( const Variable &rhs ) const; - - Variable operator+( const Variable &rhs ) const; - Variable operator-( const Variable &rhs ) const; - Variable operator*( const Variable &rhs ) const; - Variable operator/( const Variable &rhs ) const; + Variable(); + Variable( Type t ); + Variable( int iVal ); + Variable( double fVal ); + Variable( bool bVal ); + Variable( const Bu::String &sVal ); + Variable( const char *sVal ); + Variable( const Variable &v ); + Variable( const class AstLeaf &l ); + /** + * This special case function turns the variable into a string if there is + * only one string in the list, or a list of strings if there is more or + * less than one. + */ + Variable( const StrList &lst ); + Variable( const VarList &lst ); + Variable( void *oVal ); + virtual ~Variable(); + + static Variable mkRef( const Bu::String &sVal ); + + Type getType() const; + + // Raw aquisition functions, if the type isn't right, + // they throw an exception + int getInt() const; + double getFloat() const; + bool getBool() const; + const Bu::String &getString() const; + const VarList &getList() const; + const void *getOpaque() const; + + // Conversion functions, they'll return the requested type, maybe an error + // if the source data is really bad + int toInt() const; + double toFloat() const; + bool toBool() const; + Bu::String toString() const; + VarList toList() const; + + Variable toType( Type eNewType ) const; + + void append( const Variable &v ); + VarList::iterator begin(); + VarList::const_iterator begin() const; + + void doNegate(); + void doNot(); + + const Variable &operator=( const Variable &rhs ); + const Variable &operator=( const int &rhs ); + const Variable &operator=( const double &rhs ); + const Variable &operator=( const bool &rhs ); + const Variable &operator=( const Bu::String &rhs ); + const Variable &operator=( void *rhs ); + + const Variable &operator+=( const Variable &rhs ); + const Variable &operator<<( const Variable &rhs ); + + bool operator==( const Variable &rhs ) const; + bool operator!=( const Variable &rhs ) const; + bool operator<( const Variable &rhs ) const; + bool operator>( const Variable &rhs ) const; + bool operator<=( const Variable &rhs ) const; + bool operator>=( const Variable &rhs ) const; + + Variable operator+( const Variable &rhs ) const; + Variable operator-( const Variable &rhs ) const; + Variable operator*( const Variable &rhs ) const; + Variable operator/( const Variable &rhs ) const; private: - Type eType; - union - { - int iVal; - double fVal; - bool bVal; - Bu::String *sVal; - VarList *lVal; - void *oVal; - } uVal; - - void reset( Type eType ); + Type eType; + union + { + int iVal; + double fVal; + bool bVal; + Bu::String *sVal; + VarList *lVal; + void *oVal; + } uVal; + + void reset( Type eType ); }; namespace Bu { - class Formatter; + class Formatter; } Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t ); diff --git a/src/view.h b/src/view.h index 389ad15..d1e1936 100644 --- a/src/view.h +++ b/src/view.h @@ -14,31 +14,31 @@ class View { public: - View(); - virtual ~View(); - - virtual void beginAction( const Bu::String &sAction )=0; - virtual void endAction()=0; - - virtual void skipTarget( const Bu::String &sProfile, - const Target &rTarget )=0; - virtual void beginTarget( const Bu::String &sProfile, - const Target &rTarget )=0; - virtual void processTarget( const Bu::String &sProfile, - const Target &rTarget )=0; - virtual void endTarget()=0; - - virtual void buildRequires( const Target &rTarget )=0; - virtual void cmdStarted( const Bu::String &sCmd )=0; - virtual void cmdFinished( const Bu::String &sStdOut, - const Bu::String &sStdErr, long iExit )=0; - - virtual void userError( const Bu::String &sMsg )=0; - virtual void userWarning( const Bu::String &sMsg )=0; - virtual void userNotice( const Bu::String &sMsg )=0; - - virtual void sysError( const Bu::String &sMsg )=0; - virtual void sysWarning( const Bu::String &sMsg )=0; + View(); + virtual ~View(); + + virtual void beginAction( const Bu::String &sAction )=0; + virtual void endAction()=0; + + virtual void skipTarget( const Bu::String &sProfile, + const Target &rTarget )=0; + virtual void beginTarget( const Bu::String &sProfile, + const Target &rTarget )=0; + virtual void processTarget( const Bu::String &sProfile, + const Target &rTarget )=0; + virtual void endTarget()=0; + + virtual void buildRequires( const Target &rTarget )=0; + virtual void cmdStarted( const Bu::String &sCmd )=0; + virtual void cmdFinished( const Bu::String &sStdOut, + const Bu::String &sStdErr, long iExit )=0; + + virtual void userError( const Bu::String &sMsg )=0; + virtual void userWarning( const Bu::String &sMsg )=0; + virtual void userNotice( const Bu::String &sMsg )=0; + + virtual void sysError( const Bu::String &sMsg )=0; + virtual void sysWarning( const Bu::String &sMsg )=0; private: }; diff --git a/src/viewdefault.cpp b/src/viewdefault.cpp index 8b7e345..815be39 100644 --- a/src/viewdefault.cpp +++ b/src/viewdefault.cpp @@ -7,44 +7,44 @@ using namespace Bu; PluginInterface3( pluginViewDefault, default, ViewDefault, View, - "Mike Buland", 0, 1 ); - -#define ESC "\x1b" - -#define C_RESET ESC "[0m" -#define C_RED ESC "[31m" -#define C_GREEN ESC "[32m" -#define C_YELLOW ESC "[33m" -#define C_BLUE ESC "[34m" -#define C_MAGENTA ESC "[35m" -#define C_CYAN ESC "[36m" -#define C_WHITE ESC "[37m" -#define C_DEFAULT ESC "[39m" - -#define C_BR_RED ESC "[1;31m" -#define C_BR_GREEN ESC "[1;32m" -#define C_BR_YELLOW ESC "[1;33m" -#define C_BR_BLUE ESC "[1;34m" -#define C_BR_MAGENTA ESC "[1;35m" -#define C_BR_CYAN ESC "[1;36m" -#define C_BR_WHITE ESC "[1;37m" + "Mike Buland", 0, 1 ); + +#define ESC "\x1b" + +#define C_RESET ESC "[0m" +#define C_RED ESC "[31m" +#define C_GREEN ESC "[32m" +#define C_YELLOW ESC "[33m" +#define C_BLUE ESC "[34m" +#define C_MAGENTA ESC "[35m" +#define C_CYAN ESC "[36m" +#define C_WHITE ESC "[37m" +#define C_DEFAULT ESC "[39m" + +#define C_BR_RED ESC "[1;31m" +#define C_BR_GREEN ESC "[1;32m" +#define C_BR_YELLOW ESC "[1;33m" +#define C_BR_BLUE ESC "[1;34m" +#define C_BR_MAGENTA ESC "[1;35m" +#define C_BR_CYAN ESC "[1;36m" +#define C_BR_WHITE ESC "[1;37m" ViewDefault::ViewDefault() : - bFirst( true ), - bDisped( false ), - bDispedTrg( false ), - iDepth( 0 ), - iTotal( 0 ), - iCurrent( 0 ) + bFirst( true ), + bDisped( false ), + bDispedTrg( false ), + iDepth( 0 ), + iTotal( 0 ), + iCurrent( 0 ) { } ViewDefault::~ViewDefault() { - if( bDisped == false ) - { - sio << "Nothing to be done." << sio.nl << sio.nl; - } + if( bDisped == false ) + { + sio << "Nothing to be done." << sio.nl << sio.nl; + } } void ViewDefault::beginAction( const Bu::String &/*sAction*/ ) @@ -56,73 +56,73 @@ void ViewDefault::endAction() } void ViewDefault::skipTarget( const Bu::String &/*sProfile*/, - const Target &/*rTarget*/ ) + const Target &/*rTarget*/ ) { - iCurrent++; + iCurrent++; } void ViewDefault::beginTarget( const Bu::String &sProfile, - const Target &rTarget ) + const Target &rTarget ) { - if( iDepth == 0 ) - { - bDispedTrg = false; - iTotal = rTarget.getDepCount(); - iCurrent = 0; - sTopTarget = rTarget.getOutputList().first(); - } - iDepth++; + if( iDepth == 0 ) + { + bDispedTrg = false; + iTotal = rTarget.getDepCount(); + iCurrent = 0; + sTopTarget = rTarget.getOutputList().first(); + } + iDepth++; - sCurProfile = sProfile; + sCurProfile = sProfile; } void ViewDefault::drawTargetHdr( const Bu::String &sProfile, - const Target &rTarget ) -{ - if( bDispedTrg == false ) - { - bDispedTrg = true; - if( bFirst == false ) - { - sio << sio.nl; - } - bFirst = false; - sio << C_BR_WHITE << " --- " << C_BR_CYAN << sProfile << " " - << sTopTarget << C_BR_WHITE << " --- " - << C_RESET << sio.nl; - } + const Target &rTarget ) +{ + if( bDispedTrg == false ) + { + bDispedTrg = true; + if( bFirst == false ) + { + sio << sio.nl; + } + bFirst = false; + sio << C_BR_WHITE << " --- " << C_BR_CYAN << sProfile << " " + << sTopTarget << C_BR_WHITE << " --- " + << C_RESET << sio.nl; + } } void ViewDefault::processTarget( const Bu::String &sProfile, - const Target &rTarget ) + const Target &rTarget ) { - drawTargetHdr( sProfile, rTarget ); - iCurrent++; + drawTargetHdr( sProfile, rTarget ); + iCurrent++; - int iPct = (iTotal>0)?(iCurrent*100/iTotal):(100); - sio << C_BR_WHITE << "[" << C_BR_GREEN << Fmt(3) << iPct - << "%" << C_BR_WHITE << "] " << C_BR_MAGENTA - << Fmt(10) << rTarget.getDisplay() << C_BR_WHITE - << ": " << rTarget.getOutputList().first() << C_RESET << sio.nl; + int iPct = (iTotal>0)?(iCurrent*100/iTotal):(100); + sio << C_BR_WHITE << "[" << C_BR_GREEN << Fmt(3) << iPct + << "%" << C_BR_WHITE << "] " << C_BR_MAGENTA + << Fmt(10) << rTarget.getDisplay() << C_BR_WHITE + << ": " << rTarget.getOutputList().first() << C_RESET << sio.nl; - bDisped = true; + bDisped = true; } void ViewDefault::endTarget() { - iDepth--; + iDepth--; } void ViewDefault::buildRequires( const Target &rTarget ) { - drawTargetHdr( sCurProfile, rTarget ); + drawTargetHdr( sCurProfile, rTarget ); - int iPct = (iTotal>0)?(iCurrent*100/iTotal):(100); - sio << C_BR_WHITE << "[" << C_BR_GREEN << Fmt(3) << iPct - << "%" << C_BR_WHITE << "] " << C_BR_MAGENTA - << Fmt(10) << "deps" << C_BR_WHITE - << ": " << rTarget.getOutputList().first() << C_RESET << sio.nl; - bDisped = true; + int iPct = (iTotal>0)?(iCurrent*100/iTotal):(100); + sio << C_BR_WHITE << "[" << C_BR_GREEN << Fmt(3) << iPct + << "%" << C_BR_WHITE << "] " << C_BR_MAGENTA + << Fmt(10) << "deps" << C_BR_WHITE + << ": " << rTarget.getOutputList().first() << C_RESET << sio.nl; + bDisped = true; } void ViewDefault::cmdStarted( const Bu::String &/*sCmd*/ ) @@ -130,72 +130,72 @@ void ViewDefault::cmdStarted( const Bu::String &/*sCmd*/ ) } void ViewDefault::cmdFinished( const Bu::String &sStdOut, - const Bu::String &sStdErr, long /*iExit*/ ) -{ - if( sStdOut.isSet() ) - { - Bu::String::const_iterator b; - b = sStdOut.begin(); - while( b ) - { - Bu::String::const_iterator e, max; - max = b + 78; - for( e = b; e != max && *e != '\n'; e++ ) { } - sio << C_BR_GREEN << "| " << C_RESET << String( b, e ) << sio.nl; - b = e; - if( *b == '\n' ) - b++; - } - sio << C_BR_GREEN << "\\-----" << C_RESET << sio.nl; - } - if( sStdErr.isSet() ) - { - Bu::String::const_iterator b; - b = sStdErr.begin(); - while( b ) - { - Bu::String::const_iterator e, max; - max = b + 78; - for( e = b; e != max && *e != '\n'; e++ ) { } - sio << C_BR_RED << "| " << C_RESET << String( b, e ) << sio.nl; - b = e; - if( *b == '\n' ) - b++; - } - sio << C_BR_RED << "\\-----" << C_RESET << sio.nl; - } - //sio << C_BR_WHITE << "[" << C_BR_GREEN << sStdOut << C_BR_WHITE << "]" << sio.nl; - //sio << C_BR_WHITE << "[" << C_BR_RED << sStdErr << C_BR_WHITE << "]" << sio.nl; - bDisped = true; + const Bu::String &sStdErr, long /*iExit*/ ) +{ + if( sStdOut.isSet() ) + { + Bu::String::const_iterator b; + b = sStdOut.begin(); + while( b ) + { + Bu::String::const_iterator e, max; + max = b + 78; + for( e = b; e != max && *e != '\n'; e++ ) { } + sio << C_BR_GREEN << "| " << C_RESET << String( b, e ) << sio.nl; + b = e; + if( *b == '\n' ) + b++; + } + sio << C_BR_GREEN << "\\-----" << C_RESET << sio.nl; + } + if( sStdErr.isSet() ) + { + Bu::String::const_iterator b; + b = sStdErr.begin(); + while( b ) + { + Bu::String::const_iterator e, max; + max = b + 78; + for( e = b; e != max && *e != '\n'; e++ ) { } + sio << C_BR_RED << "| " << C_RESET << String( b, e ) << sio.nl; + b = e; + if( *b == '\n' ) + b++; + } + sio << C_BR_RED << "\\-----" << C_RESET << sio.nl; + } + //sio << C_BR_WHITE << "[" << C_BR_GREEN << sStdOut << C_BR_WHITE << "]" << sio.nl; + //sio << C_BR_WHITE << "[" << C_BR_RED << sStdErr << C_BR_WHITE << "]" << sio.nl; + bDisped = true; } void ViewDefault::userError( const Bu::String &sMsg ) { - sio << C_BR_RED << "Error: " << sMsg << C_RESET << sio.nl; - bDisped = true; + sio << C_BR_RED << "Error: " << sMsg << C_RESET << sio.nl; + bDisped = true; } void ViewDefault::userWarning( const Bu::String &sMsg ) { - sio << C_BR_YELLOW << "Warning: " << sMsg << C_RESET << sio.nl; - bDisped = true; + sio << C_BR_YELLOW << "Warning: " << sMsg << C_RESET << sio.nl; + bDisped = true; } void ViewDefault::userNotice( const Bu::String &sMsg ) { - sio << C_BR_GREEN << "Notice: " << sMsg << C_RESET << sio.nl; - bDisped = true; + sio << C_BR_GREEN << "Notice: " << sMsg << C_RESET << sio.nl; + bDisped = true; } void ViewDefault::sysError( const Bu::String &sMsg ) { - sio << C_BR_RED << sMsg << C_RESET << sio.nl; - bDisped = true; + sio << C_BR_RED << sMsg << C_RESET << sio.nl; + bDisped = true; } void ViewDefault::sysWarning( const Bu::String &sMsg ) { - sio << C_BR_YELLOW << sMsg << C_RESET << sio.nl; - bDisped = true; + sio << C_BR_YELLOW << sMsg << C_RESET << sio.nl; + bDisped = true; } diff --git a/src/viewdefault.h b/src/viewdefault.h index ee9302b..35d420b 100644 --- a/src/viewdefault.h +++ b/src/viewdefault.h @@ -6,43 +6,43 @@ class ViewDefault : public View { public: - ViewDefault(); - virtual ~ViewDefault(); + ViewDefault(); + virtual ~ViewDefault(); - virtual void beginAction( const Bu::String &sAction ); - virtual void endAction(); + virtual void beginAction( const Bu::String &sAction ); + virtual void endAction(); - virtual void skipTarget( const Bu::String &sProfile, - const Target &rTarget ); - virtual void beginTarget( const Bu::String &sProfile, - const Target &rTarget ); - virtual void processTarget( const Bu::String &sProfile, - const Target &rTarget ); - virtual void endTarget(); + virtual void skipTarget( const Bu::String &sProfile, + const Target &rTarget ); + virtual void beginTarget( const Bu::String &sProfile, + const Target &rTarget ); + virtual void processTarget( const Bu::String &sProfile, + const Target &rTarget ); + virtual void endTarget(); - virtual void buildRequires( const Target &rTarget ); - virtual void cmdStarted( const Bu::String &sCmd ); - virtual void cmdFinished( const Bu::String &sStdOut, - const Bu::String &sStdErr, long iExit ); + virtual void buildRequires( const Target &rTarget ); + virtual void cmdStarted( const Bu::String &sCmd ); + virtual void cmdFinished( const Bu::String &sStdOut, + const Bu::String &sStdErr, long iExit ); - virtual void userError( const Bu::String &sMsg ); - virtual void userWarning( const Bu::String &sMsg ); - virtual void userNotice( const Bu::String &sMsg ); + virtual void userError( const Bu::String &sMsg ); + virtual void userWarning( const Bu::String &sMsg ); + virtual void userNotice( const Bu::String &sMsg ); - virtual void sysError( const Bu::String &sMsg ); - virtual void sysWarning( const Bu::String &sMsg ); + virtual void sysError( const Bu::String &sMsg ); + virtual void sysWarning( const Bu::String &sMsg ); - void drawTargetHdr( const Bu::String &sProfile, const Target &rTarget ); + void drawTargetHdr( const Bu::String &sProfile, const Target &rTarget ); private: - bool bFirst; - bool bDisped; - bool bDispedTrg; - int iDepth; - int iTotal; - int iCurrent; - Bu::String sCurProfile; - Bu::String sTopTarget; + bool bFirst; + bool bDisped; + bool bDispedTrg; + int iDepth; + int iTotal; + int iCurrent; + Bu::String sCurProfile; + Bu::String sTopTarget; }; #endif diff --git a/src/viewmake.cpp b/src/viewmake.cpp index 14f5526..4b0cc12 100644 --- a/src/viewmake.cpp +++ b/src/viewmake.cpp @@ -7,7 +7,7 @@ using namespace Bu; PluginInterface3( pluginViewMake, make, ViewMake, View, - "Mike Buland", 0, 1 ); + "Mike Buland", 0, 1 ); ViewMake::ViewMake() { @@ -26,17 +26,17 @@ void ViewMake::endAction() } void ViewMake::skipTarget( const Bu::String &/*sProfile*/, - const Target &/*rTarget*/ ) + const Target &/*rTarget*/ ) { } void ViewMake::beginTarget( const Bu::String &/*sProfile*/, - const Target &/*rTarget*/ ) + const Target &/*rTarget*/ ) { } void ViewMake::processTarget( const Bu::String &/*sProfile*/, - const Target &/*rTarget*/ ) + const Target &/*rTarget*/ ) { } @@ -50,37 +50,37 @@ void ViewMake::buildRequires( const Target &/*rTarget*/ ) void ViewMake::cmdStarted( const Bu::String &sCmd ) { - sio << sCmd << sio.nl; + sio << sCmd << sio.nl; } void ViewMake::cmdFinished( const Bu::String &sStdOut, - const Bu::String &sStdErr, long /*iExit*/ ) + const Bu::String &sStdErr, long /*iExit*/ ) { - sio << sStdOut << sStdErr; + sio << sStdOut << sStdErr; } void ViewMake::userError( const Bu::String &sMsg ) { - sio << "Error: " << sMsg << sio.nl; + sio << "Error: " << sMsg << sio.nl; } void ViewMake::userWarning( const Bu::String &sMsg ) { - sio << "Warning: " << sMsg << sio.nl; + sio << "Warning: " << sMsg << sio.nl; } void ViewMake::userNotice( const Bu::String &sMsg ) { - sio << "Notice: " << sMsg << sio.nl; + sio << "Notice: " << sMsg << sio.nl; } void ViewMake::sysError( const Bu::String &sMsg ) { - sio << sMsg << sio.nl; + sio << sMsg << sio.nl; } void ViewMake::sysWarning( const Bu::String &sMsg ) { - sio << sMsg << sio.nl; + sio << sMsg << sio.nl; } diff --git a/src/viewmake.h b/src/viewmake.h index 8960ef0..0c50b00 100644 --- a/src/viewmake.h +++ b/src/viewmake.h @@ -6,31 +6,31 @@ class ViewMake : public View { public: - ViewMake(); - virtual ~ViewMake(); - - virtual void beginAction( const Bu::String &sAction ); - virtual void endAction(); - - virtual void skipTarget( const Bu::String &sProfile, - const Target &rTarget ); - virtual void beginTarget( const Bu::String &sProfile, - const Target &rTarget ); - virtual void processTarget( const Bu::String &sProfile, - const Target &rTarget ); - virtual void endTarget(); - - virtual void buildRequires( const Target &rTarget ); - virtual void cmdStarted( const Bu::String &sCmd ); - virtual void cmdFinished( const Bu::String &sStdOut, - const Bu::String &sStdErr, long iExit ); - - virtual void userError( const Bu::String &sMsg ); - virtual void userWarning( const Bu::String &sMsg ); - virtual void userNotice( const Bu::String &sMsg ); - - virtual void sysError( const Bu::String &sMsg ); - virtual void sysWarning( const Bu::String &sMsg ); + ViewMake(); + virtual ~ViewMake(); + + virtual void beginAction( const Bu::String &sAction ); + virtual void endAction(); + + virtual void skipTarget( const Bu::String &sProfile, + const Target &rTarget ); + virtual void beginTarget( const Bu::String &sProfile, + const Target &rTarget ); + virtual void processTarget( const Bu::String &sProfile, + const Target &rTarget ); + virtual void endTarget(); + + virtual void buildRequires( const Target &rTarget ); + virtual void cmdStarted( const Bu::String &sCmd ); + virtual void cmdFinished( const Bu::String &sStdOut, + const Bu::String &sStdErr, long iExit ); + + virtual void userError( const Bu::String &sMsg ); + virtual void userWarning( const Bu::String &sMsg ); + virtual void userNotice( const Bu::String &sMsg ); + + virtual void sysError( const Bu::String &sMsg ); + virtual void sysWarning( const Bu::String &sMsg ); }; #endif diff --git a/src/viewplugger.cpp b/src/viewplugger.cpp index cdde2f6..1187ab7 100644 --- a/src/viewplugger.cpp +++ b/src/viewplugger.cpp @@ -7,29 +7,29 @@ extern Bu::PluginInfo pluginViewDefault; extern Bu::PluginInfo pluginViewMake; ViewPlugger::ViewPlugger() { - registerBuiltinPlugin( &pluginViewDefault ); - registerBuiltinPlugin( &pluginViewMake ); + registerBuiltinPlugin( &pluginViewDefault ); + registerBuiltinPlugin( &pluginViewMake ); - DIR *dir = opendir("/usr/lib/build"); - if( !dir ) - return; - struct dirent *de; - while( (de = readdir( dir )) ) - { - if( strncmp("pluginView", de->d_name, 15 ) ) - continue; + DIR *dir = opendir("/usr/lib/build"); + if( !dir ) + return; + struct dirent *de; + while( (de = readdir( dir )) ) + { + if( strncmp("pluginView", de->d_name, 15 ) ) + continue; - Bu::String sFile("/usr/lib/build/"); - sFile += de->d_name; - char *s = de->d_name; - for(; *s && *s != '.'; s++ ) { } - registerExternalPlugin( - sFile, - Bu::String( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name ) - ); - } + Bu::String sFile("/usr/lib/build/"); + sFile += de->d_name; + char *s = de->d_name; + for(; *s && *s != '.'; s++ ) { } + registerExternalPlugin( + sFile, + Bu::String( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name ) + ); + } - closedir( dir ); + closedir( dir ); } ViewPlugger::~ViewPlugger() diff --git a/src/viewplugger.h b/src/viewplugger.h index b58635c..bea5c5f 100644 --- a/src/viewplugger.h +++ b/src/viewplugger.h @@ -7,12 +7,12 @@ class ViewPlugger : public Bu::Plugger, public Bu::Singleton { - friend class Bu::Singleton; + friend class Bu::Singleton; private: - ViewPlugger(); + ViewPlugger(); public: - virtual ~ViewPlugger(); + virtual ~ViewPlugger(); private: }; -- cgit v1.2.3