diff options
| -rw-r--r-- | src/build.l | 4 | ||||
| -rw-r--r-- | src/builder.cpp | 5 | ||||
| -rw-r--r-- | src/builder.h | 2 | ||||
| -rw-r--r-- | 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() | |||
| 113 | { | 113 | { |
| 114 | yy_flex_debug = false; | 114 | yy_flex_debug = false; |
| 115 | if( !(yyin = fopen( file.c_str(), "r" )) ) | 115 | if( !(yyin = fopen( file.c_str(), "r" )) ) |
| 116 | fprintf( stderr, "cannot open %s\n", file.c_str() ); | 116 | { |
| 117 | error( std::string("cannot open file: ") + file ); | ||
| 118 | } | ||
| 117 | } | 119 | } |
| 118 | 120 | ||
| 119 | void Builder::scanEnd() | 121 | 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<std::string> &lst ) | |||
| 558 | } | 558 | } |
| 559 | } | 559 | } |
| 560 | 560 | ||
| 561 | void Builder::error( const std::string &err ) | ||
| 562 | { | ||
| 563 | throw BuildException( err.c_str() ); | ||
| 564 | } | ||
| 565 | |||
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: | |||
| 40 | void execute( Action *pAct ); | 40 | void execute( Action *pAct ); |
| 41 | 41 | ||
| 42 | //void error( const yy::location &l, const std::string &m ); | 42 | //void error( const yy::location &l, const std::string &m ); |
| 43 | //void error( const std::string &m ); | 43 | void error( const std::string &m ); |
| 44 | 44 | ||
| 45 | std::string file; | 45 | std::string file; |
| 46 | 46 | ||
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 @@ | |||
| 1 | #include "builder.h" | 1 | #include "builder.h" |
| 2 | #include "viewerplain.h" | 2 | #include "viewerplain.h" |
| 3 | #include "viewerpercent.h" | 3 | #include "viewerpercent.h" |
| 4 | #include "paramproc.h" | ||
| 5 | #include "staticstring.h" | ||
| 6 | |||
| 7 | class Param : public ParamProc | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | Param() : | ||
| 11 | sFile("build.conf") | ||
| 12 | { | ||
| 13 | addHelpBanner("Build r?\n\n"); | ||
| 14 | addParam("file", 'f', &sFile, | ||
| 15 | "Set the input script, default: build.conf"); | ||
| 16 | addParam('p', mkproc(Param::procViewPercent), | ||
| 17 | "Switch to percent view."); | ||
| 18 | addParam("help", mkproc(ParamProc::help), | ||
| 19 | "This help"); | ||
| 20 | pViewer = new ViewerPlain; | ||
| 21 | } | ||
| 22 | |||
| 23 | virtual ~Param() | ||
| 24 | { | ||
| 25 | delete pViewer; | ||
| 26 | } | ||
| 27 | |||
| 28 | virtual int cmdParam( int argc, char *argv[] ) | ||
| 29 | { | ||
| 30 | if( sAction > 0 ) | ||
| 31 | { | ||
| 32 | printf("You can only specify one action per command line.\n\n"); | ||
| 33 | exit( 1 ); | ||
| 34 | } | ||
| 35 | sAction = argv[0]; | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | int procViewPercent( int argc, char *argv[] ) | ||
| 40 | { | ||
| 41 | delete pViewer; | ||
| 42 | pViewer = new ViewerPercent; | ||
| 43 | } | ||
| 44 | |||
| 45 | std::string sFile; | ||
| 46 | StaticString sAction; | ||
| 47 | Viewer *pViewer; | ||
| 48 | |||
| 49 | private: | ||
| 50 | }; | ||
| 4 | 51 | ||
| 5 | int main( int argc, char *argv[] ) | 52 | int main( int argc, char *argv[] ) |
| 6 | { | 53 | { |
| 7 | ViewerPercent p; | 54 | Param prm; |
| 8 | Builder bld( p ); | 55 | prm.process( argc, argv ); |
| 56 | |||
| 57 | Builder bld( *prm.pViewer ); | ||
| 9 | 58 | ||
| 10 | bld.load("build.conf"); | 59 | bld.load( prm.sFile.c_str() ); |
| 11 | 60 | ||
| 12 | if( argc >= 2 ) | 61 | if( prm.sAction > 0 ) |
| 13 | bld.build( argv[1] ); | 62 | bld.build( prm.sAction ); |
| 14 | else | 63 | else |
| 15 | bld.build(); | 64 | bld.build(); |
| 16 | /* | 65 | /* |
