From eccf96035df06287a4a08146741772c88545d76a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 4 Aug 2006 20:37:14 +0000 Subject: Updated error reporting, fixed the command line params, they work now. --- src/build.l | 4 +++- src/builder.cpp | 5 +++++ src/builder.h | 2 +- src/main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/build.l b/src/build.l index 620f9db..540af46 100644 --- a/src/build.l +++ b/src/build.l @@ -113,7 +113,9 @@ void Builder::scanBegin() { yy_flex_debug = false; if( !(yyin = fopen( file.c_str(), "r" )) ) - fprintf( stderr, "cannot open %s\n", file.c_str() ); + { + error( std::string("cannot open file: ") + file ); + } } void Builder::scanEnd() diff --git a/src/builder.cpp b/src/builder.cpp index 65ae0c2..3bcd593 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -558,3 +558,8 @@ void cleanList( std::list &lst ) } } +void Builder::error( const std::string &err ) +{ + throw BuildException( err.c_str() ); +} + diff --git a/src/builder.h b/src/builder.h index 82a82c4..152b969 100644 --- a/src/builder.h +++ b/src/builder.h @@ -40,7 +40,7 @@ public: void execute( Action *pAct ); //void error( const yy::location &l, const std::string &m ); - //void error( const std::string &m ); + void error( const std::string &m ); std::string file; diff --git a/src/main.cpp b/src/main.cpp index 132fb18..70a3ffc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,65 @@ #include "builder.h" #include "viewerplain.h" #include "viewerpercent.h" +#include "paramproc.h" +#include "staticstring.h" + +class Param : public ParamProc +{ +public: + Param() : + sFile("build.conf") + { + addHelpBanner("Build r?\n\n"); + addParam("file", 'f', &sFile, + "Set the input script, default: build.conf"); + addParam('p', mkproc(Param::procViewPercent), + "Switch to percent view."); + addParam("help", mkproc(ParamProc::help), + "This help"); + pViewer = new ViewerPlain; + } + + virtual ~Param() + { + delete pViewer; + } + + virtual int cmdParam( int argc, char *argv[] ) + { + if( sAction > 0 ) + { + printf("You can only specify one action per command line.\n\n"); + exit( 1 ); + } + sAction = argv[0]; + return 1; + } + + int procViewPercent( int argc, char *argv[] ) + { + delete pViewer; + pViewer = new ViewerPercent; + } + + std::string sFile; + StaticString sAction; + Viewer *pViewer; + +private: +}; int main( int argc, char *argv[] ) { - ViewerPercent p; - Builder bld( p ); + Param prm; + prm.process( argc, argv ); + + Builder bld( *prm.pViewer ); - bld.load("build.conf"); + bld.load( prm.sFile.c_str() ); - if( argc >= 2 ) - bld.build( argv[1] ); + if( prm.sAction > 0 ) + bld.build( prm.sAction ); else bld.build(); /* -- cgit v1.2.3