diff options
Diffstat (limited to '')
| -rw-r--r-- | src/action.cpp | 63 | ||||
| -rw-r--r-- | src/action.h | 45 | ||||
| -rw-r--r-- | src/build.l | 32 | ||||
| -rw-r--r-- | src/build.y | 285 | ||||
| -rw-r--r-- | src/builder.cpp | 825 | ||||
| -rw-r--r-- | src/builder.h | 196 | ||||
| -rw-r--r-- | src/cache.cpp | 149 | ||||
| -rw-r--r-- | src/cache.h | 33 | ||||
| -rw-r--r-- | src/command.cpp | 34 | ||||
| -rw-r--r-- | src/command.h | 42 | ||||
| -rw-r--r-- | src/filetarget.cpp | 178 | ||||
| -rw-r--r-- | src/filetarget.h | 32 | ||||
| -rw-r--r-- | src/main.cpp | 2 | ||||
| -rw-r--r-- | src/perform.cpp | 11 | ||||
| -rw-r--r-- | src/perform.h | 25 | ||||
| -rw-r--r-- | src/performcmd.cpp | 25 | ||||
| -rw-r--r-- | src/performcmd.h | 21 | ||||
| -rw-r--r-- | src/regexp.cpp | 78 | ||||
| -rw-r--r-- | src/regexp.h | 36 | ||||
| -rw-r--r-- | src/rule.cpp | 195 | ||||
| -rw-r--r-- | src/rule.h | 63 | ||||
| -rw-r--r-- | src/target.cpp | 46 | ||||
| -rw-r--r-- | src/target.h | 39 | ||||
| -rw-r--r-- | src/viewer.cpp | 62 | ||||
| -rw-r--r-- | src/viewer.h | 33 | ||||
| -rw-r--r-- | src/viewermake.cpp | 62 | ||||
| -rw-r--r-- | src/viewermake.h | 28 | ||||
| -rw-r--r-- | src/viewerpercent.cpp | 58 | ||||
| -rw-r--r-- | src/viewerpercent.h | 30 | ||||
| -rw-r--r-- | src/viewerplain.cpp | 61 | ||||
| -rw-r--r-- | src/viewerplain.h | 31 |
31 files changed, 70 insertions, 2750 deletions
diff --git a/src/action.cpp b/src/action.cpp deleted file mode 100644 index 51868eb..0000000 --- a/src/action.cpp +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | #include "action.h" | ||
| 2 | #include "command.h" | ||
| 3 | #include "builder.h" | ||
| 4 | |||
| 5 | Action::Action() : | ||
| 6 | bDefault( true ), | ||
| 7 | sName("") | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | Action::Action( const char *sName ) : | ||
| 12 | bDefault( false ), | ||
| 13 | sName( sName ) | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | Action::~Action() | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | void Action::add( Command *pCmd ) | ||
| 22 | { | ||
| 23 | lCommand.push_back( pCmd ); | ||
| 24 | } | ||
| 25 | |||
| 26 | void Action::add( int nType, const char *sCmd ) | ||
| 27 | { | ||
| 28 | lRegExCommand.push_back( std::pair<int,std::string>( nType, sCmd ) ); | ||
| 29 | } | ||
| 30 | |||
| 31 | void Action::debug() | ||
| 32 | { | ||
| 33 | if( bDefault ) | ||
| 34 | printf(" action default:\n"); | ||
| 35 | else | ||
| 36 | printf(" action \"%s\":\n", sName.getString() ); | ||
| 37 | |||
| 38 | for( std::list<Command *>::iterator i = lCommand.begin(); | ||
| 39 | i != lCommand.end(); i++ ) | ||
| 40 | { | ||
| 41 | (*i)->debug(); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | void Action::execute( Builder &bld ) | ||
| 46 | { | ||
| 47 | for( std::list<std::pair<int,std::string> >::iterator i = | ||
| 48 | lRegExCommand.begin(); i != lRegExCommand.end(); i++ ) | ||
| 49 | { | ||
| 50 | std::list<std::string> lTmp = bld.findTargets( (*i).second.c_str() ); | ||
| 51 | for( std::list<std::string>::iterator j = lTmp.begin(); | ||
| 52 | j != lTmp.end(); j++ ) | ||
| 53 | { | ||
| 54 | add( new Command( (Command::CmdType)(*i).first, (*j).c_str() ) ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | for( std::list<Command *>::iterator i = lCommand.begin(); | ||
| 58 | i != lCommand.end(); i++ ) | ||
| 59 | { | ||
| 60 | (*i)->execute( bld ); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/action.h b/src/action.h deleted file mode 100644 index a5555a3..0000000 --- a/src/action.h +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | #ifndef ACTION_H | ||
| 2 | #define ACTION_H | ||
| 3 | |||
| 4 | #include <list> | ||
| 5 | #include "staticstring.h" | ||
| 6 | |||
| 7 | class Command; | ||
| 8 | class Builder; | ||
| 9 | |||
| 10 | class Action | ||
| 11 | { | ||
| 12 | public: | ||
| 13 | Action(); | ||
| 14 | Action( const char *sName ); | ||
| 15 | virtual ~Action(); | ||
| 16 | |||
| 17 | void add( Command *pCmd ); | ||
| 18 | void add( int nType, const char *sCmd ); | ||
| 19 | |||
| 20 | const char *getName() | ||
| 21 | { | ||
| 22 | return sName; | ||
| 23 | } | ||
| 24 | bool isDefault() | ||
| 25 | { | ||
| 26 | return bDefault; | ||
| 27 | } | ||
| 28 | |||
| 29 | int getNumCommands() | ||
| 30 | { | ||
| 31 | return lCommand.size(); | ||
| 32 | } | ||
| 33 | |||
| 34 | void debug(); | ||
| 35 | |||
| 36 | void execute( class Builder &bld ); | ||
| 37 | |||
| 38 | private: | ||
| 39 | bool bDefault; | ||
| 40 | StaticString sName; | ||
| 41 | std::list<Command *> lCommand; | ||
| 42 | std::list<std::pair<int, std::string> > lRegExCommand; | ||
| 43 | }; | ||
| 44 | |||
| 45 | #endif | ||
diff --git a/src/build.l b/src/build.l index 3107431..b174681 100644 --- a/src/build.l +++ b/src/build.l | |||
| @@ -18,43 +18,24 @@ std::string strbuf; | |||
| 18 | %} | 18 | %} |
| 19 | %% | 19 | %% |
| 20 | 20 | ||
| 21 | [,:=] return yytext[0]; | 21 | [,:=[\]] return yytext[0]; |
| 22 | "+=" return TOK_ADDSET; | 22 | "+=" return TOK_ADDSET; |
| 23 | 23 | ||
| 24 | "default" return TOK_DEFAULT; | 24 | "default" return TOK_DEFAULT; |
| 25 | "action" return TOK_ACTION; | 25 | "action" return TOK_ACTION; |
| 26 | "create" return TOK_CREATE; | ||
| 27 | "file" return TOK_FILE; | ||
| 28 | "from" return TOK_FROM; | ||
| 29 | "files" return TOK_FILES; | ||
| 30 | "in" return TOK_IN; | ||
| 31 | "using" return TOK_USING; | ||
| 32 | "rule" return TOK_RULE; | 26 | "rule" return TOK_RULE; |
| 33 | "requires" return TOK_REQUIRES; | 27 | "requires" return TOK_REQUIRES; |
| 34 | "for" return TOK_FOR; | ||
| 35 | "set" return TOK_SET; | 28 | "set" return TOK_SET; |
| 36 | "matches" return TOK_MATCHES; | 29 | "matches" return TOK_MATCHES; |
| 37 | "matching" return TOK_MATCHING; | ||
| 38 | "all" return TOK_ALL; | ||
| 39 | "one" return TOK_ONE; | ||
| 40 | "perform" return TOK_PERFORM; | 30 | "perform" return TOK_PERFORM; |
| 41 | "produces" return TOK_PRODUCES; | 31 | "produces" return TOK_PRODUCES; |
| 42 | "command" return TOK_COMMAND; | ||
| 43 | "check" return TOK_CHECK; | 32 | "check" return TOK_CHECK; |
| 44 | "clean" return TOK_CLEAN; | 33 | "clean" return TOK_CLEAN; |
| 45 | "directories" return TOK_DIRECTORIES; | ||
| 46 | "targets" return TOK_TARGETS; | ||
| 47 | 34 | ||
| 48 | "..."\n { | ||
| 49 | yylloc->last_line += 1; | ||
| 50 | yylloc->first_line = yylloc->last_line; | ||
| 51 | yylloc->first_column = yylloc->last_column = 0; | ||
| 52 | } | ||
| 53 | \n+ { | 35 | \n+ { |
| 54 | yylloc->last_line += yyleng; | 36 | yylloc->last_line += yyleng; |
| 55 | yylloc->first_line = yylloc->last_line; | 37 | yylloc->first_line = yylloc->last_line; |
| 56 | yylloc->first_column = yylloc->last_column = 0; | 38 | yylloc->first_column = yylloc->last_column = 0; |
| 57 | return TOK_EOL; | ||
| 58 | } | 39 | } |
| 59 | 40 | ||
| 60 | [ \t\r]* { | 41 | [ \t\r]* { |
| @@ -77,17 +58,6 @@ std::string strbuf; | |||
| 77 | 58 | ||
| 78 | "#".* /* single line comment */ | 59 | "#".* /* single line comment */ |
| 79 | 60 | ||
| 80 | [^ \t\r\n\'\":+=,/][^ \t\r\n\'\":+=,]* { | ||
| 81 | yylval->strval = stringdup( yytext ); | ||
| 82 | return STRING; | ||
| 83 | } | ||
| 84 | |||
| 85 | [^ \t\r\n\'\":+=,/][^ \t\r\n\'\"+=,]+[^ \t\r\n\'\":+=,] { | ||
| 86 | yylval->strval = stringdup( yytext ); | ||
| 87 | return STRING; | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | \" { | 61 | \" { |
| 92 | BEGIN( strdq ); | 62 | BEGIN( strdq ); |
| 93 | strbuf = ""; | 63 | strbuf = ""; |
diff --git a/src/build.y b/src/build.y index d1f3945..a624418 100644 --- a/src/build.y +++ b/src/build.y | |||
| @@ -20,268 +20,119 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); | |||
| 20 | %error-verbose | 20 | %error-verbose |
| 21 | %union { | 21 | %union { |
| 22 | char *strval; | 22 | char *strval; |
| 23 | int tval; | ||
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | %token <strval> STRING "string literal" | 26 | %token <strval> STRING "string literal" |
| 26 | %token <strval> REGEXP "regular expression" | 27 | %token <strval> REGEXP "regular expression" |
| 28 | %token <tval> TARGETTYPE "target type" | ||
| 29 | %token <strval> FUNCTION "function name" | ||
| 27 | 30 | ||
| 28 | %token TOK_ADDSET "+=" | 31 | %token TOK_ADDSET "+=" |
| 29 | %token TOK_DEFAULT "default" | 32 | %token TOK_DEFAULT "default" |
| 30 | %token TOK_ACTION "action" | 33 | %token TOK_ACTION "action" |
| 31 | %token TOK_CREATE "create" | 34 | %token TOK_CHECK "check" |
| 32 | %token TOK_FILE "file" | 35 | %token TOK_CLEAN "clean" |
| 33 | %token TOK_FROM "from" | ||
| 34 | %token TOK_FILES "files" | ||
| 35 | %token TOK_IN "in" | ||
| 36 | %token TOK_USING "using" | ||
| 37 | %token TOK_RULE "rule" | 36 | %token TOK_RULE "rule" |
| 38 | %token TOK_REQUIRES "requires" | 37 | %token TOK_TARGET "target" |
| 39 | %token TOK_FOR "for" | ||
| 40 | %token TOK_SET "set" | 38 | %token TOK_SET "set" |
| 39 | %token TOK_INPUT "input" | ||
| 40 | %token TOK_FILTER "filter" | ||
| 41 | %token TOK_PREFIX "prefix" | ||
| 42 | %token TOK_REQUIRES "requires" | ||
| 41 | %token TOK_MATCHES "matches" | 43 | %token TOK_MATCHES "matches" |
| 42 | %token TOK_MATCHING "matching" | ||
| 43 | %token TOK_ALL "all" | ||
| 44 | %token TOK_ONE "one" | ||
| 45 | %token TOK_PERFORM "perform" | 44 | %token TOK_PERFORM "perform" |
| 46 | %token TOK_PRODUCES "produces" | 45 | %token TOK_PRODUCES "produces" |
| 47 | %token TOK_COMMAND "command" | 46 | |
| 48 | %token TOK_CHECK "check" | ||
| 49 | %token TOK_CLEAN "clean" | ||
| 50 | %token TOK_DIRECTORIES "directories" | ||
| 51 | %token TOK_TARGETS "targets" | ||
| 52 | %token TOK_EOL "end of line" | ||
| 53 | %token ',' ':' '=' | 47 | %token ',' ':' '=' |
| 54 | 48 | ||
| 55 | %destructor { delete[] $$; } STRING | 49 | %destructor { delete[] $$; } STRING |
| 56 | 50 | ||
| 57 | %% | 51 | %% |
| 58 | 52 | ||
| 53 | // General input format | ||
| 59 | input: | 54 | input: |
| 60 | | input fullline | 55 | | input rule |
| 56 | | input action | ||
| 57 | | input target | ||
| 61 | ; | 58 | ; |
| 62 | 59 | ||
| 63 | fullline: TOK_EOL | 60 | // Rule interpretation |
| 64 | | line TOK_EOL | 61 | rule: TOK_RULE STRING ':' rulecmds |
| 65 | ; | ||
| 66 | |||
| 67 | line: TOK_DEFAULT TOK_ACTION ':' | ||
| 68 | { | ||
| 69 | bld.add( new Action() ); | ||
| 70 | } | ||
| 71 | actionlst | ||
| 72 | | STRING TOK_ACTION ':' | ||
| 73 | { | ||
| 74 | bld.add( new Action( $1 ) ); | ||
| 75 | } | ||
| 76 | actionlst | ||
| 77 | | TOK_FOR fortypes TOK_MATCHING REGEXP | ||
| 78 | { | ||
| 79 | bld.setFilter( $4 ); | ||
| 80 | } | ||
| 81 | augments | ||
| 82 | { | ||
| 83 | bld.endList(); | ||
| 84 | } | ||
| 85 | listcmds | ||
| 86 | | STRING TOK_REQUIRES | ||
| 87 | { | ||
| 88 | bld.setTmp( $1 ); | ||
| 89 | bld.requiresRegexp( false ); | ||
| 90 | } | ||
| 91 | reqcompletion | ||
| 92 | | REGEXP TOK_REQUIRES | ||
| 93 | { | ||
| 94 | bld.setTmp( $1 ); | ||
| 95 | bld.requiresRegexp( true ); | ||
| 96 | } | ||
| 97 | reqcompletion | ||
| 98 | | listcmds | ||
| 99 | | TOK_FOR STRING | ||
| 100 | { | ||
| 101 | bld.startList( STRING ); | ||
| 102 | bld.addListItem( $2 ); | ||
| 103 | } | ||
| 104 | listcmds | ||
| 105 | { | ||
| 106 | |||
| 107 | } | ||
| 108 | | rule | ||
| 109 | ; | 62 | ; |
| 110 | 63 | ||
| 111 | fortypes: TOK_DIRECTORIES | 64 | rulecmds: rulecmd |
| 112 | { | 65 | | rulecmds ',' rulecmd |
| 113 | bld.startList( TOK_DIRECTORIES ); | ||
| 114 | } | ||
| 115 | | TOK_TARGETS | ||
| 116 | { | ||
| 117 | bld.startList( TOK_TARGETS ); | ||
| 118 | } | ||
| 119 | | TOK_FILES | ||
| 120 | { | ||
| 121 | bld.startList( TOK_FILES ); | ||
| 122 | } | ||
| 123 | ; | ||
| 124 | |||
| 125 | augments: | ||
| 126 | | TOK_IN STRING | ||
| 127 | { | ||
| 128 | bld.augmentList( $2 ); | ||
| 129 | } | ||
| 130 | ; | 66 | ; |
| 131 | 67 | ||
| 132 | reqcompletion: reqlst | 68 | rulecmd: TOK_MATCHES REGEXP |
| 133 | | TOK_FROM TOK_COMMAND STRING | 69 | | TOK_PRODUCES STRING |
| 134 | { | 70 | | TOK_REQUIRES list |
| 135 | bld.requiresFromCommand( bld.getTmp(), $3 ); | 71 | | TOK_INPUT TOK_FILTER REGEXP |
| 136 | } | 72 | | TOK_INPUT TOK_FILTER func |
| 137 | ; | 73 | | TOK_PERFORM func |
| 74 | ; | ||
| 138 | 75 | ||
| 139 | reqlst: STRING | 76 | // Action interpretation |
| 140 | { | 77 | action: TOK_DEFAULT TOK_ACTION ':' actioncmds |
| 141 | bld.requires( bld.getTmp(), $1 ); | 78 | | STRING TOK_ACTION ':' actioncmds |
| 142 | } | ||
| 143 | | reqlst ',' STRING | ||
| 144 | { | ||
| 145 | bld.requires( bld.getTmp(), $3 ); | ||
| 146 | } | ||
| 147 | ; | 79 | ; |
| 148 | 80 | ||
| 149 | listcmds: TOK_SET setexpr | 81 | actioncmds: actioncmd |
| 150 | | TOK_CREATE createwhat TOK_FROM createfrom TOK_USING createusing | 82 | | actioncmds ',' actioncmd |
| 151 | { | ||
| 152 | bld.endTarget(); | ||
| 153 | } | ||
| 154 | ; | ||
| 155 | |||
| 156 | createwhat: TOK_FILE STRING | ||
| 157 | { | ||
| 158 | bld.addTarget( TOK_FILE, $2 ); | ||
| 159 | } | ||
| 160 | ; | 83 | ; |
| 161 | 84 | ||
| 162 | createfrom: TOK_FILES TOK_IN | 85 | actioncmd: actioncmdtype list |
| 163 | { | 86 | ; |
| 164 | bld.setTargetInputType( TOK_FILES ); | ||
| 165 | } | ||
| 166 | createfromdirlst | ||
| 167 | ; | ||
| 168 | |||
| 169 | createfromdirlst: createfromdir | ||
| 170 | | createfromdirlst ',' createfromdir | ||
| 171 | ; | ||
| 172 | 87 | ||
| 173 | createfromdir: STRING | 88 | actioncmdtype: TOK_CHECK |
| 174 | { | 89 | | TOK_CLEAN |
| 175 | bld.addTargetInput( $1 ); | ||
| 176 | } | ||
| 177 | ; | 90 | ; |
| 178 | 91 | ||
| 179 | createusing: TOK_RULE STRING | 92 | // Target interpretation |
| 180 | { | ||
| 181 | bld.setTargetRule( $2 ); | ||
| 182 | } | ||
| 183 | ; | ||
| 184 | |||
| 185 | actionlst: action | ||
| 186 | | actionlst ',' action | ||
| 187 | ; | ||
| 188 | 93 | ||
| 189 | action: TOK_CHECK STRING | 94 | target: list ':' targetcmds |
| 190 | { | ||
| 191 | bld.add( new Command( Command::cmdCheck, $2 ) ); | ||
| 192 | } | ||
| 193 | | TOK_CHECK REGEXP | ||
| 194 | { | ||
| 195 | bld.addRegexCommand( Command::cmdCheck, $2 ); | ||
| 196 | } | ||
| 197 | | TOK_CLEAN STRING | ||
| 198 | { | ||
| 199 | bld.add( new Command( Command::cmdClean, $2 ) ); | ||
| 200 | } | ||
| 201 | | TOK_CLEAN REGEXP | ||
| 202 | { | ||
| 203 | bld.addRegexCommand( Command::cmdClean, $2 ); | ||
| 204 | } | ||
| 205 | ; | 95 | ; |
| 206 | 96 | ||
| 207 | setexpr: STRING '=' STRING | 97 | targetcmds: targetcmd |
| 208 | { | 98 | | targetcmds ',' targetcmd |
| 209 | bld.varSet( $1, $3 ); | 99 | ; |
| 210 | } | 100 | |
| 211 | | STRING TOK_ADDSET STRING | 101 | targetcmd: TOK_RULE STRING |
| 212 | { | 102 | | TOK_TARGET TOK_PREFIX STRING |
| 213 | bld.varAddSet( $1, $3 ); | 103 | | TOK_TARGET TARGETTYPE |
| 214 | } | 104 | | TOK_INPUT list |
| 215 | | STRING '=' TOK_FROM TOK_COMMAND STRING | 105 | | TOK_REQUIRES list |
| 216 | { | 106 | ; |
| 217 | bld.varSet( $1, bld.cmdToString( $5 ).c_str() ); | ||
| 218 | } | ||
| 219 | | STRING TOK_ADDSET TOK_FROM TOK_COMMAND STRING | ||
| 220 | { | ||
| 221 | bld.varSet( $1, bld.cmdToString( $5 ).c_str() ); | ||
| 222 | } | ||
| 223 | ; | ||
| 224 | 107 | ||
| 225 | rule: TOK_RULE STRING | 108 | // list goo |
| 226 | { | 109 | |
| 227 | bld.add( new Rule( $2 ) ); | 110 | list: listitem listfilter |
| 228 | } | 111 | | '[' listitems ']' listfilter |
| 229 | rulesublst TOK_PERFORM rulecompletion | ||
| 230 | ; | 112 | ; |
| 231 | 113 | ||
| 232 | rulesublst: rulesub | 114 | listfilter: |
| 233 | | rulesublst rulesub | 115 | | TOK_FILTER REGEXP |
| 116 | | TOK_FILTER func | ||
| 234 | ; | 117 | ; |
| 235 | 118 | ||
| 236 | rulesub: TOK_MATCHES rulematches | 119 | listitems: listitem |
| 237 | | TOK_PRODUCES produceslst | 120 | | listitems ',' listitem |
| 238 | ; | 121 | ; |
| 239 | 122 | ||
| 240 | produceslst: STRING | 123 | listitem: STRING |
| 241 | { | 124 | | func |
| 242 | bld.lastRule()->addProduces( $1 ); | 125 | ; |
| 243 | } | ||
| 244 | | produceslst ',' STRING | ||
| 245 | { | ||
| 246 | bld.lastRule()->addProduces( $3 ); | ||
| 247 | } | ||
| 248 | ; | ||
| 249 | 126 | ||
| 250 | rulematches: TOK_ALL REGEXP | 127 | // Function |
| 251 | { | ||
| 252 | try | ||
| 253 | { | ||
| 254 | bld.lastRule()->setMatches( Rule::matchAll, $2 ); | ||
| 255 | } | ||
| 256 | catch( BuildException &e ) | ||
| 257 | { | ||
| 258 | std::string s("RegExp compile error: "); | ||
| 259 | s += e.what(); | ||
| 260 | yyerror( &yyloc, bld, s.c_str() ); | ||
| 261 | return 1; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | | TOK_ONE REGEXP | ||
| 265 | { | ||
| 266 | try | ||
| 267 | { | ||
| 268 | bld.lastRule()->setMatches( Rule::matchOne, $2 ); | ||
| 269 | } | ||
| 270 | catch( BuildException &e ) | ||
| 271 | { | ||
| 272 | std::string s("RegExp compile error: "); | ||
| 273 | s += e.what(); | ||
| 274 | yyerror( &yyloc, bld, s.c_str() ); | ||
| 275 | return 1; | ||
| 276 | } | ||
| 277 | } | ||
| 278 | ; | ||
| 279 | 128 | ||
| 280 | rulecompletion: TOK_COMMAND STRING | 129 | func: FUNCTION '(' funcparams ')' |
| 281 | { | 130 | ; |
| 282 | bld.lastRule()->setPerforms( Rule::perfCommand, $2 ); | 131 | |
| 283 | } | 132 | funcparams: |
| 284 | ; | 133 | | STRING |
| 134 | | funcparams ',' STRING | ||
| 135 | ; | ||
| 285 | 136 | ||
| 286 | %% | 137 | %% |
| 287 | 138 | ||
diff --git a/src/builder.cpp b/src/builder.cpp deleted file mode 100644 index 8c3bbbb..0000000 --- a/src/builder.cpp +++ /dev/null | |||
| @@ -1,825 +0,0 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <sstream> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <dirent.h> | ||
| 5 | |||
| 6 | #include "builder.h" | ||
| 7 | #include "action.h" | ||
| 8 | #include "command.h" | ||
| 9 | #include "target.h" | ||
| 10 | #include "filetarget.h" | ||
| 11 | #include "build.tab.h" | ||
| 12 | #include "rule.h" | ||
| 13 | #include "viewer.h" | ||
| 14 | #include "cache.h" | ||
| 15 | #include "serializerbinary.h" | ||
| 16 | |||
| 17 | subExceptionDef( BuildException ) | ||
| 18 | |||
| 19 | Builder::Builder( Viewer &rView ) : | ||
| 20 | pDefaultAction( NULL ), | ||
| 21 | pLastAddedAction( NULL ), | ||
| 22 | sTmp(""), | ||
| 23 | sContext(""), | ||
| 24 | rView( rView ), | ||
| 25 | bUsingList( false ) | ||
| 26 | { | ||
| 27 | } | ||
| 28 | |||
| 29 | Builder::~Builder() | ||
| 30 | { | ||
| 31 | if( sCacheFile.getLength() > 0 ) | ||
| 32 | { | ||
| 33 | try | ||
| 34 | { | ||
| 35 | SerializerBinary ar( sCacheFile, Serializer::save ); | ||
| 36 | |||
| 37 | ar << cRequires; | ||
| 38 | } | ||
| 39 | catch( ExceptionBase &e ) | ||
| 40 | { | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | void yyparse( Builder &bld ); | ||
| 46 | |||
| 47 | void Builder::load( const char *sFN ) | ||
| 48 | { | ||
| 49 | file = sFN; | ||
| 50 | |||
| 51 | scanBegin(); | ||
| 52 | yyparse( *this ); | ||
| 53 | scanEnd(); | ||
| 54 | } | ||
| 55 | |||
| 56 | void Builder::build( const char *sAct ) | ||
| 57 | { | ||
| 58 | Action *pAct; | ||
| 59 | if( sAct == NULL ) | ||
| 60 | pAct = pDefaultAction; | ||
| 61 | else | ||
| 62 | { | ||
| 63 | if( mAction.find( sAct ) == mAction.end() ) | ||
| 64 | throw BuildException("No action matches '%s'.", sAct ); | ||
| 65 | pAct = mAction[sAct]; | ||
| 66 | } | ||
| 67 | |||
| 68 | rView.beginAction( sAct, pAct->getNumCommands() ); | ||
| 69 | |||
| 70 | pAct->execute( *this ); | ||
| 71 | |||
| 72 | rView.endAction(); | ||
| 73 | } | ||
| 74 | |||
| 75 | void Builder::setCache( const std::string &sFile ) | ||
| 76 | { | ||
| 77 | sCacheFile = sFile.c_str(); | ||
| 78 | |||
| 79 | try | ||
| 80 | { | ||
| 81 | SerializerBinary ar( sCacheFile, Serializer::load ); | ||
| 82 | |||
| 83 | ar >> cRequires; | ||
| 84 | } | ||
| 85 | catch( ExceptionBase &e ) | ||
| 86 | { | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | void Builder::execute( Action *pAct ) | ||
| 91 | { | ||
| 92 | pAct->execute( *this ); | ||
| 93 | } | ||
| 94 | |||
| 95 | void Builder::add( Action *pAct ) | ||
| 96 | { | ||
| 97 | if( pAct->isDefault() ) | ||
| 98 | { | ||
| 99 | if( pDefaultAction ) | ||
| 100 | throw BuildException("There's already a default exception"); | ||
| 101 | pDefaultAction = pAct; | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | mAction[pAct->getName()] = pAct; | ||
| 106 | } | ||
| 107 | pLastAddedAction = pAct; | ||
| 108 | } | ||
| 109 | |||
| 110 | void Builder::add( Command *pCmd ) | ||
| 111 | { | ||
| 112 | if( pLastAddedAction ) | ||
| 113 | { | ||
| 114 | pLastAddedAction->add( pCmd ); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | void Builder::addRegexCommand( int nType, const char *sReg ) | ||
| 119 | { | ||
| 120 | if( pLastAddedAction ) | ||
| 121 | { | ||
| 122 | pLastAddedAction->add( nType, sReg ); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | void Builder::add( Rule *pRule ) | ||
| 127 | { | ||
| 128 | pLastAddedRule = pRule; | ||
| 129 | mRule[pRule->getName()] = pRule; | ||
| 130 | } | ||
| 131 | |||
| 132 | void Builder::add( Target *pTarg ) | ||
| 133 | { | ||
| 134 | pLastAddedTarget = pTarg; | ||
| 135 | mTarget[pTarg->getName()] = pTarg; | ||
| 136 | } | ||
| 137 | |||
| 138 | void Builder::addTarget( int tokType, const char *sName ) | ||
| 139 | { | ||
| 140 | nTargetType = tokType; | ||
| 141 | sTargetName = sName; | ||
| 142 | } | ||
| 143 | |||
| 144 | void Builder::setTargetInputType( int tokType ) | ||
| 145 | { | ||
| 146 | nTargetInputType = tokType; | ||
| 147 | } | ||
| 148 | |||
| 149 | void Builder::addTargetInput( const char *sInput ) | ||
| 150 | { | ||
| 151 | lsTargetInput.push_back( sInput ); | ||
| 152 | } | ||
| 153 | |||
| 154 | void Builder::setTargetRule( const char *sRule ) | ||
| 155 | { | ||
| 156 | sTargetRule = sRule; | ||
| 157 | } | ||
| 158 | |||
| 159 | void Builder::endTarget() | ||
| 160 | { | ||
| 161 | if( bUsingList == false ) | ||
| 162 | { | ||
| 163 | switch( nTargetType ) | ||
| 164 | { | ||
| 165 | case TOK_FILE: | ||
| 166 | add( new FileTarget( sTargetName.c_str() ) ); | ||
| 167 | switch( nTargetInputType ) | ||
| 168 | { | ||
| 169 | case TOK_FILES: | ||
| 170 | for( std::list<std::string>::iterator | ||
| 171 | i = lsTargetInput.begin(); | ||
| 172 | i != lsTargetInput.end(); i++ ) | ||
| 173 | { | ||
| 174 | ((FileTarget *)lastTarget())->addInputDir( | ||
| 175 | (*i).c_str() | ||
| 176 | ); | ||
| 177 | } | ||
| 178 | break; | ||
| 179 | } | ||
| 180 | lastTarget()->setRule( sTargetRule.c_str() ); | ||
| 181 | break; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | else | ||
| 185 | { | ||
| 186 | switch( nTargetType ) | ||
| 187 | { | ||
| 188 | case TOK_FILE: | ||
| 189 | for( std::list<std::pair<std::string,std::map<std::string,std::string> > >::iterator j = lTok.begin(); j != lTok.end(); j++ ) | ||
| 190 | { | ||
| 191 | std::string sName = varRepl( sTargetName.c_str(), "", &(*j).second ); | ||
| 192 | add( new FileTarget( sName.c_str() ) ); | ||
| 193 | switch( nTargetInputType ) | ||
| 194 | { | ||
| 195 | case TOK_FILES: | ||
| 196 | for( std::list<std::string>::iterator | ||
| 197 | i = lsTargetInput.begin(); | ||
| 198 | i != lsTargetInput.end(); i++ ) | ||
| 199 | { | ||
| 200 | std::string sInput = varRepl( | ||
| 201 | (*i).c_str(), "", | ||
| 202 | &(*j).second | ||
| 203 | ); | ||
| 204 | ((FileTarget *)lastTarget())->addInputDir( | ||
| 205 | sInput.c_str() | ||
| 206 | ); | ||
| 207 | } | ||
| 208 | break; | ||
| 209 | } | ||
| 210 | lastTarget()->setRule( sTargetRule.c_str() ); | ||
| 211 | } | ||
| 212 | break; | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | clearList(); | ||
| 217 | } | ||
| 218 | |||
| 219 | void Builder::debug() | ||
| 220 | { | ||
| 221 | printf("Actions:\n"); | ||
| 222 | pDefaultAction->debug(); | ||
| 223 | for( std::map<const char *, Action *, ltstr>::iterator i = mAction.begin(); | ||
| 224 | i != mAction.end(); i++ ) | ||
| 225 | { | ||
| 226 | (*i).second->debug(); | ||
| 227 | } | ||
| 228 | |||
| 229 | printf("Targets:\n"); | ||
| 230 | for( std::map<const char *, Target *, ltstr>::iterator i = mTarget.begin(); | ||
| 231 | i != mTarget.end(); i++ ) | ||
| 232 | { | ||
| 233 | (*i).second->debug(); | ||
| 234 | } | ||
| 235 | |||
| 236 | printf("Rules:\n"); | ||
| 237 | for( std::map<const char *, Rule *, ltstr>::iterator i = mRule.begin(); | ||
| 238 | i != mRule.end(); i++ ) | ||
| 239 | { | ||
| 240 | (*i).second->debug(); | ||
| 241 | } | ||
| 242 | |||
| 243 | printf("Variables:\n"); | ||
| 244 | for( varmap::iterator i = mVar.begin(); i != mVar.end(); i++ ) | ||
| 245 | { | ||
| 246 | printf(" %s = \"%s\"\n", (*i).first.c_str(), (*i).second.c_str() ); | ||
| 247 | } | ||
| 248 | |||
| 249 | printf("Variables (by context):\n"); | ||
| 250 | for( std::map<std::string, varmap>::iterator j = mContVar.begin(); | ||
| 251 | j != mContVar.end(); j++ ) | ||
| 252 | { | ||
| 253 | printf(" %s:\n", (*j).first.c_str() ); | ||
| 254 | for( varmap::iterator i = (*j).second.begin(); | ||
| 255 | i != (*j).second.end(); i++ ) | ||
| 256 | { | ||
| 257 | printf(" %s = \"%s\"\n", | ||
| 258 | (*i).first.c_str(), (*i).second.c_str() ); | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | printf("Dependancies:\n"); | ||
| 263 | for( std::map<std::string, std::list<std::string> *>::iterator i = | ||
| 264 | mRequires.begin(); i != mRequires.end(); i++ ) | ||
| 265 | { | ||
| 266 | printf(" %s: ", (*i).first.c_str() ); | ||
| 267 | std::list<std::string> *pList = (*i).second; | ||
| 268 | int i = 0; | ||
| 269 | for( std::list<std::string>::iterator j = pList->begin(); | ||
| 270 | j != pList->end(); j++ ) | ||
| 271 | { | ||
| 272 | if( j != pList->begin() ) | ||
| 273 | printf(", "); | ||
| 274 | printf("%s", (*j).c_str() ); | ||
| 275 | if( i++ >= 3 ) | ||
| 276 | { | ||
| 277 | printf("..."); | ||
| 278 | break; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | printf("\n"); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | void Builder::checkVar( const char *cont, const char *sName ) | ||
| 286 | { | ||
| 287 | if( cont[0] != '\0' ) | ||
| 288 | { | ||
| 289 | varmap &mmVar = mContVar[cont]; | ||
| 290 | if( mmVar.find( sName ) == mmVar.end() ) | ||
| 291 | { | ||
| 292 | checkVar( "", sName ); | ||
| 293 | mmVar[sName] = mVar[sName]; | ||
| 294 | } | ||
| 295 | } | ||
| 296 | else | ||
| 297 | { | ||
| 298 | if( mVar.find( sName ) == mVar.end() ) | ||
| 299 | { | ||
| 300 | char *env = getenv( sName ); | ||
| 301 | if( env ) | ||
| 302 | mVar[sName] = env; | ||
| 303 | else | ||
| 304 | mVar[sName] = ""; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 309 | void Builder::varSet( const char *sName, const char *sValue ) | ||
| 310 | { | ||
| 311 | if( bUsingList ) | ||
| 312 | { | ||
| 313 | for( std::list<std::pair<std::string,std::map<std::string,std::string> > >::iterator i = lTok.begin(); i != lTok.end(); i++ ) | ||
| 314 | { | ||
| 315 | checkVar( (*i).first.c_str(), sName ); | ||
| 316 | |||
| 317 | std::string newVal = varRepl( sValue, (*i).first.c_str(), &(*i).second ); | ||
| 318 | |||
| 319 | mContVar[(*i).first.c_str()][sName] = newVal; | ||
| 320 | } | ||
| 321 | } | ||
| 322 | else | ||
| 323 | { | ||
| 324 | checkVar( sContext, sName ); | ||
| 325 | |||
| 326 | std::string newVal = varRepl( sValue, sContext, NULL ); | ||
| 327 | |||
| 328 | if( sContext[0] == '\0' ) | ||
| 329 | { | ||
| 330 | mVar[sName] = newVal; | ||
| 331 | } | ||
| 332 | else | ||
| 333 | { | ||
| 334 | mContVar[sContext.getString()][sName] = newVal; | ||
| 335 | } | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | void Builder::varAddSet( const char *sName, const char *sValue ) | ||
| 340 | { | ||
| 341 | checkVar( sContext, sName ); | ||
| 342 | |||
| 343 | std::string newVal = varRepl( sValue, sContext, NULL ); | ||
| 344 | |||
| 345 | if( sContext[0] == '\0' ) | ||
| 346 | { | ||
| 347 | std::string s = mVar[sName]; | ||
| 348 | s += " "; | ||
| 349 | s += newVal; | ||
| 350 | mVar[sName] = s; | ||
| 351 | } | ||
| 352 | else | ||
| 353 | { | ||
| 354 | std::string s = mContVar[sContext.getString()][sName]; | ||
| 355 | s += " "; | ||
| 356 | s += newVal; | ||
| 357 | mContVar[sContext.getString()][sName] = s; | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 361 | void Builder::processRequires( std::list<std::string> &lInput ) | ||
| 362 | { | ||
| 363 | // These are cheap and handy to have all the time | ||
| 364 | for( regreqlist::iterator i = lRequiresRegexp.begin(); | ||
| 365 | i != lRequiresRegexp.end(); i++ ) | ||
| 366 | { | ||
| 367 | RegExp *re = (*i).first; | ||
| 368 | for( std::list<std::string>::iterator j = lInput.begin(); | ||
| 369 | j != lInput.end(); j++ ) | ||
| 370 | { | ||
| 371 | if( re->execute( (*j).c_str() ) ) | ||
| 372 | { | ||
| 373 | varmap *revars = regexVars( re ); | ||
| 374 | requiresNormal( | ||
| 375 | (*j).c_str(), | ||
| 376 | varRepl( | ||
| 377 | (*i).second.c_str(), | ||
| 378 | "", | ||
| 379 | revars | ||
| 380 | ).c_str() | ||
| 381 | ); | ||
| 382 | delete revars; | ||
| 383 | } | ||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 387 | } | ||
| 388 | |||
| 389 | void Builder::genRequiresFor( const char *sName, time_t tNewTime ) | ||
| 390 | { | ||
| 391 | Cache::Entry *ent = cRequires.get( sName ); | ||
| 392 | if( ent && tNewTime > 0 ) | ||
| 393 | { | ||
| 394 | if( ent->tCreated >= tNewTime ) | ||
| 395 | { | ||
| 396 | for( std::list<std::string>::iterator i = ent->lData.begin(); | ||
| 397 | i != ent->lData.end(); i++ ) | ||
| 398 | { | ||
| 399 | requiresNormal( | ||
| 400 | sName, | ||
| 401 | (*i).c_str() | ||
| 402 | ); | ||
| 403 | } | ||
| 404 | |||
| 405 | return; | ||
| 406 | } | ||
| 407 | } | ||
| 408 | |||
| 409 | ent = new Cache::Entry; | ||
| 410 | ent->tCreated = tNewTime; | ||
| 411 | |||
| 412 | for( regreqlist::iterator i = lRequiresRegexpCommand.begin(); | ||
| 413 | i != lRequiresRegexpCommand.end(); i++ ) | ||
| 414 | { | ||
| 415 | RegExp *re = (*i).first; | ||
| 416 | if( re->execute( sName ) ) | ||
| 417 | { | ||
| 418 | varmap *revars = regexVars( re ); | ||
| 419 | std::string s = varRepl( (*i).second.c_str(), "", revars ); | ||
| 420 | rView.beginExtraRequiresCheck( s.c_str() ); | ||
| 421 | rView.executeCmd( s.c_str() ); | ||
| 422 | FILE *fcmd = popen( s.c_str(), "r" ); | ||
| 423 | std::string rhs; | ||
| 424 | bool bHeader = true; | ||
| 425 | for(;;) | ||
| 426 | { | ||
| 427 | if( feof( fcmd ) ) | ||
| 428 | break; | ||
| 429 | int cc = fgetc( fcmd ); | ||
| 430 | if( cc == EOF ) | ||
| 431 | break; | ||
| 432 | unsigned char c = cc; | ||
| 433 | if( bHeader ) | ||
| 434 | { | ||
| 435 | if( c == ':' ) | ||
| 436 | bHeader = false; | ||
| 437 | } | ||
| 438 | else | ||
| 439 | { | ||
| 440 | if( c == ' ' || c == '\t' ) | ||
| 441 | { | ||
| 442 | if( rhs != "" ) | ||
| 443 | { | ||
| 444 | requiresNormal( | ||
| 445 | sName, | ||
| 446 | rhs.c_str() | ||
| 447 | ); | ||
| 448 | ent->lData.push_back( rhs ); | ||
| 449 | rhs = ""; | ||
| 450 | } | ||
| 451 | } | ||
| 452 | else | ||
| 453 | { | ||
| 454 | if( c == '\\' ) | ||
| 455 | c = fgetc( fcmd ); | ||
| 456 | if( c != '\n' ) | ||
| 457 | rhs += c; | ||
| 458 | } | ||
| 459 | } | ||
| 460 | } | ||
| 461 | if( rhs != "" ) | ||
| 462 | { | ||
| 463 | requiresNormal( | ||
| 464 | sName, | ||
| 465 | rhs.c_str() | ||
| 466 | ); | ||
| 467 | ent->lData.push_back( rhs ); | ||
| 468 | rhs = ""; | ||
| 469 | } | ||
| 470 | pclose( fcmd ); | ||
| 471 | delete revars; | ||
| 472 | rView.endExtraRequiresCheck(); | ||
| 473 | } | ||
| 474 | } | ||
| 475 | |||
| 476 | cRequires.put( sName, ent ); | ||
| 477 | } | ||
| 478 | |||
| 479 | std::map<std::string, std::string> *Builder::regexVars( RegExp *re ) | ||
| 480 | { | ||
| 481 | varmap *map = new varmap; | ||
| 482 | |||
| 483 | int jmax = re->getNumSubStrings(); | ||
| 484 | for( int j = 0; j < jmax; j++ ) | ||
| 485 | { | ||
| 486 | char buf[8]; | ||
| 487 | sprintf( buf, "re:%d", j ); | ||
| 488 | (*map)[buf] = re->getSubString( j ); | ||
| 489 | } | ||
| 490 | |||
| 491 | return map; | ||
| 492 | } | ||
| 493 | |||
| 494 | void Builder::regexVars( RegExp *re, varmap &map ) | ||
| 495 | { | ||
| 496 | int jmax = re->getNumSubStrings(); | ||
| 497 | for( int j = 0; j < jmax; j++ ) | ||
| 498 | { | ||
| 499 | char buf[8]; | ||
| 500 | sprintf( buf, "re:%d", j ); | ||
| 501 | map[buf] = re->getSubString( j ); | ||
| 502 | } | ||
| 503 | } | ||
| 504 | |||
| 505 | void Builder::requires( const char *sBase, const char *sReq ) | ||
| 506 | { | ||
| 507 | if( bReqRegexp ) | ||
| 508 | { | ||
| 509 | requiresRegexp( sBase, sReq ); | ||
| 510 | } | ||
| 511 | else | ||
| 512 | { | ||
| 513 | requiresNormal( sBase, sReq ); | ||
| 514 | } | ||
| 515 | } | ||
| 516 | |||
| 517 | void Builder::requiresNormal( const char *sBase, const char *sReq ) | ||
| 518 | { | ||
| 519 | std::list<std::string> *pList = NULL; | ||
| 520 | if( mRequires.find(sBase) == mRequires.end() ) | ||
| 521 | { | ||
| 522 | pList = new std::list<std::string>; | ||
| 523 | mRequires[sBase] = pList; | ||
| 524 | } | ||
| 525 | else | ||
| 526 | { | ||
| 527 | pList = mRequires[sBase]; | ||
| 528 | } | ||
| 529 | |||
| 530 | pList->push_back( sReq ); | ||
| 531 | } | ||
| 532 | |||
| 533 | void Builder::requiresRegexp( const char *sBase, const char *sReq ) | ||
| 534 | { | ||
| 535 | lRequiresRegexp.push_back( | ||
| 536 | std::pair<RegExp *, std::string>( | ||
| 537 | new RegExp( sBase ), | ||
| 538 | sReq | ||
| 539 | ) | ||
| 540 | ); | ||
| 541 | } | ||
| 542 | |||
| 543 | void Builder::requiresFromCommand( const char *sBase, const char *sCmd ) | ||
| 544 | { | ||
| 545 | lRequiresRegexpCommand.push_back( | ||
| 546 | std::pair<RegExp *, std::string>( | ||
| 547 | new RegExp( sBase ), | ||
| 548 | sCmd | ||
| 549 | ) | ||
| 550 | ); | ||
| 551 | } | ||
| 552 | |||
| 553 | void Builder::setContext( const char *sCont ) | ||
| 554 | { | ||
| 555 | sContext = sCont; | ||
| 556 | } | ||
| 557 | |||
| 558 | void Builder::setContext() | ||
| 559 | { | ||
| 560 | setContext(""); | ||
| 561 | } | ||
| 562 | |||
| 563 | bool Builder::hasVar( varmap *pMap, std::string &var ) | ||
| 564 | { | ||
| 565 | if( pMap == NULL ) | ||
| 566 | return false; | ||
| 567 | if( pMap->find( var ) == pMap->end() ) | ||
| 568 | return false; | ||
| 569 | return true; | ||
| 570 | } | ||
| 571 | |||
| 572 | std::string Builder::varRepl( const char *sSrc, const char *cont, varmap *mExtra ) | ||
| 573 | { | ||
| 574 | varmap *mCont = NULL; | ||
| 575 | if( cont[0] != '\0' ) | ||
| 576 | { | ||
| 577 | if( mContVar.find( cont ) != mContVar.end() ) | ||
| 578 | mCont = &mContVar[cont]; | ||
| 579 | } | ||
| 580 | |||
| 581 | std::string out; | ||
| 582 | std::string var; | ||
| 583 | bool bVar = false; | ||
| 584 | |||
| 585 | for( const char *s = sSrc; *s; s++ ) | ||
| 586 | { | ||
| 587 | if( *s == '{' ) | ||
| 588 | { | ||
| 589 | bVar = true; | ||
| 590 | continue; | ||
| 591 | } | ||
| 592 | else if( *s == '}' && bVar ) | ||
| 593 | { | ||
| 594 | if( hasVar( mExtra, var ) ) | ||
| 595 | { | ||
| 596 | out += (*mExtra)[var]; | ||
| 597 | } | ||
| 598 | else if( hasVar( mCont, var ) ) | ||
| 599 | { | ||
| 600 | out += (*mCont)[var]; | ||
| 601 | } | ||
| 602 | else if( hasVar( &mVar, var ) ) | ||
| 603 | { | ||
| 604 | out += mVar[var]; | ||
| 605 | } | ||
| 606 | var = ""; | ||
| 607 | bVar = false; | ||
| 608 | continue; | ||
| 609 | } | ||
| 610 | |||
| 611 | if( bVar == true ) | ||
| 612 | { | ||
| 613 | var += *s; | ||
| 614 | } | ||
| 615 | else | ||
| 616 | { | ||
| 617 | out += *s; | ||
| 618 | } | ||
| 619 | } | ||
| 620 | |||
| 621 | return out; | ||
| 622 | } | ||
| 623 | |||
| 624 | Rule *Builder::getRule( const char *sName ) | ||
| 625 | { | ||
| 626 | if( mRule.find( sName ) != mRule.end() ) | ||
| 627 | return mRule[sName]; | ||
| 628 | |||
| 629 | throw BuildException("No rule named %s registered.", sName ); | ||
| 630 | return NULL; | ||
| 631 | } | ||
| 632 | |||
| 633 | std::list<Rule *> Builder::findRuleChain( Rule *pRule ) | ||
| 634 | { | ||
| 635 | std::list<Rule *> ret; | ||
| 636 | |||
| 637 | for( std::map<const char *, Rule *, ltstr>::iterator i = mRule.begin(); | ||
| 638 | i != mRule.end(); i++ ) | ||
| 639 | { | ||
| 640 | if( pRule == (*i).second ) | ||
| 641 | continue; | ||
| 642 | |||
| 643 | if( pRule->willChain( (*i).second ) ) | ||
| 644 | { | ||
| 645 | ret.push_back( (*i).second ); | ||
| 646 | } | ||
| 647 | } | ||
| 648 | |||
| 649 | return ret; | ||
| 650 | } | ||
| 651 | |||
| 652 | void cleanList( std::list<std::string> &lst ) | ||
| 653 | { | ||
| 654 | std::map<std::string, bool> m; | ||
| 655 | |||
| 656 | for( std::list<std::string>::iterator i = lst.begin(); i != lst.end(); i++ ) | ||
| 657 | { | ||
| 658 | if( m.find( *i ) == m.end() ) | ||
| 659 | m[ *i ] = true; | ||
| 660 | else | ||
| 661 | { | ||
| 662 | std::list<std::string>::iterator j = i; | ||
| 663 | j--; | ||
| 664 | lst.erase( i ); | ||
| 665 | i = j; | ||
| 666 | } | ||
| 667 | } | ||
| 668 | } | ||
| 669 | |||
| 670 | void Builder::error( const std::string &err ) | ||
| 671 | { | ||
| 672 | throw BuildException( err.c_str() ); | ||
| 673 | } | ||
| 674 | |||
| 675 | void Builder::error( YYLTYPE *locp, const std::string &err ) | ||
| 676 | { | ||
| 677 | std::stringstream s; | ||
| 678 | s << file << ":" << locp->first_line << "." << locp->first_column; | ||
| 679 | if( locp->first_line != locp->last_line ) | ||
| 680 | s << "-" << locp->last_line << "." << locp->last_column; | ||
| 681 | else if( locp->first_column != locp->last_column ) | ||
| 682 | s << "-" << locp->last_column; | ||
| 683 | s << ": " << err; | ||
| 684 | throw BuildException( s.str().c_str() ); | ||
| 685 | } | ||
| 686 | |||
| 687 | void Builder::startList( int tokType ) | ||
| 688 | { | ||
| 689 | bUsingList = true; | ||
| 690 | lTok.clear(); | ||
| 691 | bTokFiltered = false; | ||
| 692 | nTokType = tokType; | ||
| 693 | } | ||
| 694 | |||
| 695 | void Builder::setFilter( const char *sRegExp ) | ||
| 696 | { | ||
| 697 | rTok.compile( sRegExp ); | ||
| 698 | bTokFiltered = true; | ||
| 699 | } | ||
| 700 | |||
| 701 | void Builder::augmentList( const char *sFrom ) | ||
| 702 | { | ||
| 703 | switch( nTokType ) | ||
| 704 | { | ||
| 705 | case TOK_DIRECTORIES: | ||
| 706 | { | ||
| 707 | DIR *dir = opendir( sFrom ); | ||
| 708 | if( dir == NULL ) | ||
| 709 | { | ||
| 710 | printf("dir: %s\n", sFrom ); | ||
| 711 | throw BuildException( strerror( errno ) ); | ||
| 712 | } | ||
| 713 | |||
| 714 | std::string base; | ||
| 715 | base += sFrom; | ||
| 716 | base += "/"; | ||
| 717 | |||
| 718 | struct dirent *de; | ||
| 719 | |||
| 720 | while( (de = readdir( dir )) ) | ||
| 721 | { | ||
| 722 | if( de->d_type != DT_DIR ) | ||
| 723 | continue; | ||
| 724 | if( de->d_name[0] == '.' || de->d_name[0] == '\0' ) | ||
| 725 | continue; | ||
| 726 | |||
| 727 | std::string s( base ); | ||
| 728 | s += de->d_name; | ||
| 729 | addListItem( s.c_str() ); | ||
| 730 | } | ||
| 731 | |||
| 732 | closedir( dir ); | ||
| 733 | } | ||
| 734 | break; | ||
| 735 | |||
| 736 | default: | ||
| 737 | break; | ||
| 738 | } | ||
| 739 | } | ||
| 740 | |||
| 741 | void Builder::endList() | ||
| 742 | { | ||
| 743 | switch( nTokType ) | ||
| 744 | { | ||
| 745 | case TOK_TARGETS: | ||
| 746 | for( std::map<const char *, Target *, ltstr>::iterator i = | ||
| 747 | mTarget.begin(); i != mTarget.end(); i++ ) | ||
| 748 | { | ||
| 749 | addListItem( (*i).first ); | ||
| 750 | } | ||
| 751 | break; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | |||
| 755 | void Builder::addListItem( const char *sItem ) | ||
| 756 | { | ||
| 757 | std::map<std::string,std::string> mVars; | ||
| 758 | mVars["match"] = sItem; | ||
| 759 | if( bTokFiltered ) | ||
| 760 | { | ||
| 761 | if( rTok.execute( sItem ) ) | ||
| 762 | { | ||
| 763 | regexVars( &rTok, mVars ); | ||
| 764 | } | ||
| 765 | else | ||
| 766 | { | ||
| 767 | return; | ||
| 768 | } | ||
| 769 | } | ||
| 770 | lTok.push_back( | ||
| 771 | std::pair<std::string,std::map<std::string,std::string> >( | ||
| 772 | sItem, mVars | ||
| 773 | ) | ||
| 774 | ); | ||
| 775 | } | ||
| 776 | |||
| 777 | void Builder::clearList() | ||
| 778 | { | ||
| 779 | lTok.clear(); | ||
| 780 | lsTargetInput.clear(); | ||
| 781 | bUsingList = false; | ||
| 782 | } | ||
| 783 | |||
| 784 | std::list<std::string> Builder::findTargets( const char *sRegex ) | ||
| 785 | { | ||
| 786 | RegExp r( sRegex ); | ||
| 787 | |||
| 788 | std::list<std::string> lTmp; | ||
| 789 | |||
| 790 | for( std::map<const char *, Target *, ltstr>::iterator i = mTarget.begin(); | ||
| 791 | i != mTarget.end(); i++ ) | ||
| 792 | { | ||
| 793 | if( r.execute( (*i).first ) ) | ||
| 794 | { | ||
| 795 | lTmp.push_back( (*i).first ); | ||
| 796 | } | ||
| 797 | } | ||
| 798 | |||
| 799 | return lTmp; | ||
| 800 | } | ||
| 801 | |||
| 802 | std::string Builder::cmdToString( const char *sCmd ) | ||
| 803 | { | ||
| 804 | std::string buf; | ||
| 805 | FILE *pr = popen( sCmd, "r" ); | ||
| 806 | if( pr == NULL ) | ||
| 807 | throw BuildException("Couldn't execute program \"%s\"", sCmd ); | ||
| 808 | |||
| 809 | char cbuf[2048]; | ||
| 810 | |||
| 811 | for(;;) | ||
| 812 | { | ||
| 813 | int nRead = fread( cbuf, 1, 2048, pr ); | ||
| 814 | for( int j = 0; j < nRead; j++ ) | ||
| 815 | if( cbuf[j] != '\n' && cbuf[j] != '\r' ) | ||
| 816 | buf.append( cbuf+j, 1 ); | ||
| 817 | if( feof( pr ) ) | ||
| 818 | break; | ||
| 819 | } | ||
| 820 | |||
| 821 | pclose( pr ); | ||
| 822 | |||
| 823 | return buf; | ||
| 824 | } | ||
| 825 | |||
diff --git a/src/builder.h b/src/builder.h deleted file mode 100644 index c570dbb..0000000 --- a/src/builder.h +++ /dev/null | |||
| @@ -1,196 +0,0 @@ | |||
| 1 | #ifndef BUILDER_H | ||
| 2 | #define BUILDER_H | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | #include <list> | ||
| 6 | #include <map> | ||
| 7 | #include "build.tab.h" | ||
| 8 | #include "exceptionbase.h" | ||
| 9 | #include "staticstring.h" | ||
| 10 | #include "regexp.h" | ||
| 11 | #include "cache.h" | ||
| 12 | |||
| 13 | subExceptionDecl( BuildException ) | ||
| 14 | |||
| 15 | class Builder; | ||
| 16 | class Action; | ||
| 17 | class Command; | ||
| 18 | class Rule; | ||
| 19 | class Target; | ||
| 20 | class Viewer; | ||
| 21 | class Cache; | ||
| 22 | |||
| 23 | #define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) | ||
| 24 | YY_DECL; | ||
| 25 | |||
| 26 | class Builder | ||
| 27 | { | ||
| 28 | struct ltstr | ||
| 29 | { | ||
| 30 | bool operator()(const char* s1, const char* s2) const | ||
| 31 | { | ||
| 32 | return strcmp(s1, s2) < 0; | ||
| 33 | } | ||
| 34 | }; | ||
| 35 | |||
| 36 | public: | ||
| 37 | Builder( Viewer &rView ); | ||
| 38 | virtual ~Builder(); | ||
| 39 | |||
| 40 | void load( const char *sFN ); | ||
| 41 | void build( const char *sAct=NULL ); | ||
| 42 | void execute( Action *pAct ); | ||
| 43 | |||
| 44 | void error( YYLTYPE *locp, const std::string &m ); | ||
| 45 | void error( const std::string &m ); | ||
| 46 | |||
| 47 | std::string file; | ||
| 48 | |||
| 49 | Viewer &view() | ||
| 50 | { | ||
| 51 | return rView; | ||
| 52 | } | ||
| 53 | |||
| 54 | void startList( int tokType ); | ||
| 55 | void setFilter( const char *sRegExp ); | ||
| 56 | void augmentList( const char *sFrom ); | ||
| 57 | void addListItem( const char *sItem ); | ||
| 58 | void clearList(); | ||
| 59 | void endList(); | ||
| 60 | |||
| 61 | void addTarget( int tokType, const char *sName ); | ||
| 62 | void setTargetInputType( int tokType ); | ||
| 63 | void addTargetInput( const char *sInput ); | ||
| 64 | void setTargetRule( const char *sRule ); | ||
| 65 | void endTarget(); | ||
| 66 | |||
| 67 | void setCache( const std::string &sFile ); | ||
| 68 | void add( Action *pAct ); | ||
| 69 | void add( Command *pCmd ); | ||
| 70 | void addRegexCommand( int nType, const char *sReg ); | ||
| 71 | void add( Rule *pRule ); | ||
| 72 | void add( Target *pTarg ); | ||
| 73 | void varSet( const char *sName, const char *sValue ); | ||
| 74 | void varAddSet( const char *sName, const char *sValue ); | ||
| 75 | Rule *getRule( const char *sName ); | ||
| 76 | std::list<Rule *> findRuleChain( Rule *pRule ); | ||
| 77 | void processRequires( std::list<std::string> &lInput ); | ||
| 78 | void requires( const char *sBase, const char *sReq ); | ||
| 79 | void requiresFromCommand( const char *sBase, const char *sReq ); | ||
| 80 | void genRequiresFor( const char *sName, time_t tNewTime ); | ||
| 81 | std::list<std::string> findTargets( const char *sRegex ); | ||
| 82 | void requiresRegexp( bool on ) | ||
| 83 | { | ||
| 84 | bReqRegexp = on; | ||
| 85 | } | ||
| 86 | bool isRequiresRegexp() | ||
| 87 | { | ||
| 88 | return bReqRegexp; | ||
| 89 | } | ||
| 90 | void setContext( const char *sCont ); | ||
| 91 | void setContext(); | ||
| 92 | |||
| 93 | bool hasDefaultAction() | ||
| 94 | { | ||
| 95 | return pDefaultAction != NULL; | ||
| 96 | } | ||
| 97 | |||
| 98 | void debug(); | ||
| 99 | |||
| 100 | Rule *lastRule() | ||
| 101 | { | ||
| 102 | return pLastAddedRule; | ||
| 103 | } | ||
| 104 | |||
| 105 | Target *lastTarget() | ||
| 106 | { | ||
| 107 | return pLastAddedTarget; | ||
| 108 | } | ||
| 109 | |||
| 110 | void setTmp( const char *s ) | ||
| 111 | { | ||
| 112 | sTmp = s; | ||
| 113 | } | ||
| 114 | |||
| 115 | const char *getTmp() | ||
| 116 | { | ||
| 117 | return sTmp; | ||
| 118 | } | ||
| 119 | |||
| 120 | Target *getTarget( const char *sName ) | ||
| 121 | { | ||
| 122 | if( mTarget.find( sName ) == mTarget.end() ) | ||
| 123 | throw BuildException("Target %s not found.", sName ); | ||
| 124 | |||
| 125 | return mTarget[sName]; | ||
| 126 | } | ||
| 127 | |||
| 128 | std::list<std::string> *getRequires( const char *sReq ) | ||
| 129 | { | ||
| 130 | if( mRequires.find(sReq) == mRequires.end() ) | ||
| 131 | return NULL; | ||
| 132 | return mRequires[sReq]; | ||
| 133 | } | ||
| 134 | |||
| 135 | typedef std::map<std::string, std::string> varmap; | ||
| 136 | varmap *regexVars( RegExp *re ); | ||
| 137 | void regexVars( RegExp *re, varmap &map ); | ||
| 138 | std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra ); | ||
| 139 | |||
| 140 | std::string cmdToString( const char *sCmd ); | ||
| 141 | |||
| 142 | private: | ||
| 143 | void requiresNormal( const char *sBase, const char *sReq ); | ||
| 144 | void requiresRegexp( const char *sBase, const char *sReq ); | ||
| 145 | void checkVar( const char *cont, const char *sName ); | ||
| 146 | void scanBegin(); | ||
| 147 | void scanEnd(); | ||
| 148 | |||
| 149 | bool hasVar( varmap *pMap, std::string &var ); | ||
| 150 | |||
| 151 | Action *pDefaultAction; | ||
| 152 | Action *pLastAddedAction; | ||
| 153 | std::map<const char *, Action *, ltstr> mAction; | ||
| 154 | |||
| 155 | Rule *pLastAddedRule; | ||
| 156 | std::map<const char *, Rule *, ltstr> mRule; | ||
| 157 | |||
| 158 | Target *pLastAddedTarget; | ||
| 159 | std::map<const char *, Target *, ltstr> mTarget; | ||
| 160 | |||
| 161 | varmap mVar; | ||
| 162 | |||
| 163 | std::map<std::string, std::list<std::string> *> mRequires; | ||
| 164 | |||
| 165 | typedef std::list<std::pair<RegExp *, std::string> > regreqlist; | ||
| 166 | regreqlist lRequiresRegexp; | ||
| 167 | regreqlist lRequiresRegexpCommand; | ||
| 168 | |||
| 169 | std::map<std::string, varmap> mContVar; | ||
| 170 | StaticString sContext; | ||
| 171 | |||
| 172 | StaticString sTmp; | ||
| 173 | |||
| 174 | bool bReqRegexp; | ||
| 175 | |||
| 176 | Viewer &rView; | ||
| 177 | |||
| 178 | StaticString sCacheFile; | ||
| 179 | class Cache cRequires; | ||
| 180 | |||
| 181 | std::list<std::pair<std::string,std::map<std::string,std::string> > > lTok; | ||
| 182 | bool bTokFiltered; | ||
| 183 | int nTokType; | ||
| 184 | RegExp rTok; | ||
| 185 | |||
| 186 | int nTargetType; | ||
| 187 | int nTargetInputType; | ||
| 188 | std::string sTargetName; | ||
| 189 | std::list<std::string> lsTargetInput; | ||
| 190 | std::string sTargetRule; | ||
| 191 | bool bUsingList; | ||
| 192 | }; | ||
| 193 | |||
| 194 | void cleanList( std::list<std::string> &lst ); | ||
| 195 | |||
| 196 | #endif | ||
diff --git a/src/cache.cpp b/src/cache.cpp deleted file mode 100644 index 10971b1..0000000 --- a/src/cache.cpp +++ /dev/null | |||
| @@ -1,149 +0,0 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include "serializer.h" | ||
| 3 | #include "staticstring.h" | ||
| 4 | |||
| 5 | Cache::Cache() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | Cache::~Cache() | ||
| 10 | { | ||
| 11 | for( std::map<std::string, Entry *>::iterator i = mCache.begin(); | ||
| 12 | i != mCache.end(); i++ ) | ||
| 13 | { | ||
| 14 | delete (*i).second; | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | void Cache::serialize( class Serializer &ar ) | ||
| 19 | { | ||
| 20 | if( ar.isLoading() ) | ||
| 21 | { | ||
| 22 | int sCache, sData, sIndex; | ||
| 23 | |||
| 24 | ar >> sIndex; | ||
| 25 | StaticString *Index = new StaticString[sIndex]; | ||
| 26 | for( int i = 0; i < sIndex; i++ ) | ||
| 27 | { | ||
| 28 | ar >> Index[i]; | ||
| 29 | } | ||
| 30 | |||
| 31 | ar >> sCache; | ||
| 32 | int nTmp; | ||
| 33 | for( int i = 0; i < sCache; i++ ) | ||
| 34 | { | ||
| 35 | Entry *e = new Entry; | ||
| 36 | ar >> e->tCreated; | ||
| 37 | ar >> sData; | ||
| 38 | std::list<std::string> &lData = e->lData; | ||
| 39 | for( int j = 0; j < sData; j++ ) | ||
| 40 | { | ||
| 41 | ar >> nTmp; | ||
| 42 | lData.push_back( Index[nTmp].getString() ); | ||
| 43 | } | ||
| 44 | ar >> nTmp; | ||
| 45 | mCache[Index[nTmp].getString()] = e; | ||
| 46 | } | ||
| 47 | /* | ||
| 48 | int sCache, sData; | ||
| 49 | ar >> sCache; | ||
| 50 | std::string sTmp; | ||
| 51 | |||
| 52 | for( int i = 0; i < sCache; i++ ) | ||
| 53 | { | ||
| 54 | Entry *e = new Entry; | ||
| 55 | ar >> e->tCreated; | ||
| 56 | ar >> sData; | ||
| 57 | std::list<std::string> &lData = e->lData; | ||
| 58 | for( int j = 0; j < sData; j++ ) | ||
| 59 | { | ||
| 60 | ar >> sTmp; | ||
| 61 | lData.push_back( sTmp ); | ||
| 62 | } | ||
| 63 | ar >> sTmp; | ||
| 64 | mCache[sTmp] = e; | ||
| 65 | } | ||
| 66 | */ | ||
| 67 | } | ||
| 68 | else | ||
| 69 | { | ||
| 70 | std::map<std::string, int> mIndex; | ||
| 71 | for( std::map<std::string, Entry *>::iterator i = mCache.begin(); | ||
| 72 | i != mCache.end(); i++ ) | ||
| 73 | { | ||
| 74 | mIndex[(*i).first] = 0; | ||
| 75 | std::list<std::string> &lData = (*i).second->lData; | ||
| 76 | for( std::list<std::string>::iterator j = lData.begin(); | ||
| 77 | j != lData.end(); j++ ) | ||
| 78 | { | ||
| 79 | mIndex[(*j)] = 0; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | ar << mIndex.size(); | ||
| 84 | int cnt = 0; | ||
| 85 | for( std::map<std::string, int>::iterator i = mIndex.begin(); | ||
| 86 | i != mIndex.end(); i++ ) | ||
| 87 | { | ||
| 88 | (*i).second = cnt; | ||
| 89 | cnt++; | ||
| 90 | std::string s = ((*i).first); | ||
| 91 | ar << s; | ||
| 92 | } | ||
| 93 | |||
| 94 | ar << mCache.size(); | ||
| 95 | for( std::map<std::string, Entry *>::iterator i = mCache.begin(); | ||
| 96 | i != mCache.end(); i++ ) | ||
| 97 | { | ||
| 98 | ar << (*i).second->tCreated; | ||
| 99 | std::list<std::string> &lData = (*i).second->lData; | ||
| 100 | ar << lData.size(); | ||
| 101 | for( std::list<std::string>::iterator j = lData.begin(); | ||
| 102 | j != lData.end(); j++ ) | ||
| 103 | { | ||
| 104 | ar << mIndex[(*j)]; | ||
| 105 | } | ||
| 106 | |||
| 107 | ar << mIndex[(*i).first]; | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | /* | ||
| 112 | ar << mCache.size(); | ||
| 113 | for( std::map<std::string, Entry *>::iterator i = mCache.begin(); | ||
| 114 | i != mCache.end(); i++ ) | ||
| 115 | { | ||
| 116 | ar << (*i).second->tCreated; | ||
| 117 | std::list<std::string> &lData = (*i).second->lData; | ||
| 118 | ar << lData.size(); | ||
| 119 | for( std::list<std::string>::iterator j = lData.begin(); | ||
| 120 | j != lData.end(); j++ ) | ||
| 121 | { | ||
| 122 | ar << (*j); | ||
| 123 | } | ||
| 124 | |||
| 125 | std::string str = (*i).first; | ||
| 126 | ar << str; | ||
| 127 | } | ||
| 128 | */ | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | Cache::Entry *Cache::get( const std::string &id ) | ||
| 133 | { | ||
| 134 | std::map<std::string, Entry *>::iterator i = mCache.find( id ); | ||
| 135 | if( i != mCache.end() ) | ||
| 136 | return (*i).second; | ||
| 137 | |||
| 138 | return NULL; | ||
| 139 | } | ||
| 140 | |||
| 141 | void Cache::put( const std::string &id, Entry *data ) | ||
| 142 | { | ||
| 143 | std::map<std::string, Entry *>::iterator i = mCache.find( id ); | ||
| 144 | if( i != mCache.end() ) | ||
| 145 | delete (*i).second; | ||
| 146 | |||
| 147 | mCache[id] = data; | ||
| 148 | } | ||
| 149 | |||
diff --git a/src/cache.h b/src/cache.h deleted file mode 100644 index 944aa24..0000000 --- a/src/cache.h +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | #ifndef CACHE_H | ||
| 2 | #define CACHE_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <time.h> | ||
| 6 | #include "serializable.h" | ||
| 7 | #include <list> | ||
| 8 | #include <map> | ||
| 9 | #include <string> | ||
| 10 | |||
| 11 | class Cache : public Serializable | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | Cache(); | ||
| 15 | virtual ~Cache(); | ||
| 16 | |||
| 17 | virtual void serialize( class Serializer &ar ); | ||
| 18 | |||
| 19 | class Entry | ||
| 20 | { | ||
| 21 | public: | ||
| 22 | int tCreated; | ||
| 23 | std::list<std::string> lData; | ||
| 24 | }; | ||
| 25 | |||
| 26 | Entry *get( const std::string &id ); | ||
| 27 | void put( const std::string &id, Entry *data ); | ||
| 28 | |||
| 29 | private: | ||
| 30 | std::map<std::string, Entry *> mCache; | ||
| 31 | }; | ||
| 32 | |||
| 33 | #endif | ||
diff --git a/src/command.cpp b/src/command.cpp deleted file mode 100644 index ea5ade3..0000000 --- a/src/command.cpp +++ /dev/null | |||
| @@ -1,34 +0,0 @@ | |||
| 1 | #include "command.h" | ||
| 2 | #include "builder.h" | ||
| 3 | #include "target.h" | ||
| 4 | |||
| 5 | Command::Command( CmdType cmd, const char *sTarget ) : | ||
| 6 | nType( cmd ), | ||
| 7 | sTarget( sTarget ) | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | Command::~Command() | ||
| 12 | { | ||
| 13 | } | ||
| 14 | |||
| 15 | void Command::debug() | ||
| 16 | { | ||
| 17 | static const char *cmdt[]={"Check", "Clean"}; | ||
| 18 | printf(" command: %s %s\n", cmdt[ nType ], sTarget.getString() ); | ||
| 19 | } | ||
| 20 | |||
| 21 | void Command::execute( Builder &bld ) | ||
| 22 | { | ||
| 23 | switch( nType ) | ||
| 24 | { | ||
| 25 | case cmdCheck: | ||
| 26 | bld.getTarget( sTarget )->check( bld ); | ||
| 27 | break; | ||
| 28 | |||
| 29 | case cmdClean: | ||
| 30 | bld.getTarget( sTarget )->clean( bld ); | ||
| 31 | break; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
diff --git a/src/command.h b/src/command.h deleted file mode 100644 index 495c749..0000000 --- a/src/command.h +++ /dev/null | |||
| @@ -1,42 +0,0 @@ | |||
| 1 | #ifndef COMMAND_H | ||
| 2 | #define COMMAND_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include "staticstring.h" | ||
| 6 | |||
| 7 | class Builder; | ||
| 8 | |||
| 9 | class Command | ||
| 10 | { | ||
| 11 | public: | ||
| 12 | enum CmdType | ||
| 13 | { | ||
| 14 | cmdCheck = 0, | ||
| 15 | cmdClean | ||
| 16 | }; | ||
| 17 | |||
| 18 | public: | ||
| 19 | Command( CmdType cmd, const char *sTarget ); | ||
| 20 | virtual ~Command(); | ||
| 21 | |||
| 22 | CmdType getType() | ||
| 23 | { | ||
| 24 | return nType; | ||
| 25 | } | ||
| 26 | |||
| 27 | const char *getTarget() | ||
| 28 | { | ||
| 29 | return sTarget; | ||
| 30 | } | ||
| 31 | |||
| 32 | void debug(); | ||
| 33 | |||
| 34 | void execute( class Builder &bld ); | ||
| 35 | |||
| 36 | private: | ||
| 37 | CmdType nType; | ||
| 38 | StaticString sTarget; | ||
| 39 | |||
| 40 | }; | ||
| 41 | |||
| 42 | #endif | ||
diff --git a/src/filetarget.cpp b/src/filetarget.cpp deleted file mode 100644 index 0d47e6f..0000000 --- a/src/filetarget.cpp +++ /dev/null | |||
| @@ -1,178 +0,0 @@ | |||
| 1 | #include <errno.h> | ||
| 2 | #include <dirent.h> | ||
| 3 | |||
| 4 | #include "perform.h" | ||
| 5 | #include "rule.h" | ||
| 6 | #include "filetarget.h" | ||
| 7 | #include "builder.h" // for BuildException | ||
| 8 | #include "viewer.h" | ||
| 9 | |||
| 10 | FileTarget::FileTarget( const char *sName ) : | ||
| 11 | Target( sName ) | ||
| 12 | { | ||
| 13 | } | ||
| 14 | |||
| 15 | FileTarget::~FileTarget() | ||
| 16 | { | ||
| 17 | } | ||
| 18 | |||
| 19 | void FileTarget::debug() | ||
| 20 | { | ||
| 21 | Target::debug(); | ||
| 22 | printf(" type: FileTarget\n"); | ||
| 23 | } | ||
| 24 | |||
| 25 | char *gnu_getcwd() | ||
| 26 | { | ||
| 27 | size_t size = 1024; | ||
| 28 | |||
| 29 | while (1) | ||
| 30 | { | ||
| 31 | char *buffer = new char[size]; | ||
| 32 | if (getcwd (buffer, size) == buffer) | ||
| 33 | return buffer; | ||
| 34 | delete[] buffer; | ||
| 35 | if (errno != ERANGE) | ||
| 36 | return 0; | ||
| 37 | size *= 2; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | void FileTarget::addInputDir( const char *sDir ) | ||
| 42 | { | ||
| 43 | DIR *dir = opendir( sDir ); | ||
| 44 | if( dir == NULL ) | ||
| 45 | { | ||
| 46 | throw BuildException( strerror( errno ) ); | ||
| 47 | } | ||
| 48 | |||
| 49 | char *cwd = gnu_getcwd(); | ||
| 50 | std::string base;//( cwd ); | ||
| 51 | //base += "/"; | ||
| 52 | base += sDir; | ||
| 53 | base += "/"; | ||
| 54 | delete[] cwd; | ||
| 55 | |||
| 56 | struct dirent *de; | ||
| 57 | |||
| 58 | while( (de = readdir( dir )) ) | ||
| 59 | { | ||
| 60 | if( de->d_name[0] == '.' || de->d_name[0] == '\0' ) | ||
| 61 | continue; | ||
| 62 | |||
| 63 | std::string s( base ); | ||
| 64 | s += de->d_name; | ||
| 65 | addInput( s.c_str() ); | ||
| 66 | } | ||
| 67 | |||
| 68 | closedir( dir ); | ||
| 69 | } | ||
| 70 | |||
| 71 | //int nNew, nCache; | ||
| 72 | |||
| 73 | void FileTarget::check( Builder &bld ) | ||
| 74 | { | ||
| 75 | //nNew = nCache = 0; | ||
| 76 | Rule *pRule = bld.getRule( sRule ); | ||
| 77 | |||
| 78 | std::list<Perform *> perf; | ||
| 79 | std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() ); | ||
| 80 | lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); | ||
| 81 | |||
| 82 | bld.view().beginTarget( getName(), "file", "check", lOutput.size() ); | ||
| 83 | |||
| 84 | bld.processRequires( lOutput ); | ||
| 85 | |||
| 86 | for( std::list<Perform *>::iterator i = perf.begin(); | ||
| 87 | i != perf.end(); i++ ) | ||
| 88 | { | ||
| 89 | bld.view().beginPerform( *i ); | ||
| 90 | bool bExtraReqs = false; | ||
| 91 | time_t target = getTime( bld, std::string((*i)->getTarget()) ); | ||
| 92 | std::list<std::string> *lReqs = bld.getRequires( (*i)->getTarget() ); | ||
| 93 | if( lReqs == NULL ) | ||
| 94 | { | ||
| 95 | printf("No dependancies: %s\n", (*i)->getTarget() ); | ||
| 96 | continue; | ||
| 97 | } | ||
| 98 | time_t rebuild = target; | ||
| 99 | for( std::list<std::string>::iterator j = lReqs->begin(); | ||
| 100 | j != lReqs->end(); j++ ) | ||
| 101 | { | ||
| 102 | time_t srcfile = getTime( bld, *j ); | ||
| 103 | if( srcfile < rebuild ) | ||
| 104 | rebuild = srcfile; | ||
| 105 | if( srcfile > target ) | ||
| 106 | { | ||
| 107 | bld.view().beginExecute(); | ||
| 108 | (*i)->execute( bld ); | ||
| 109 | updateTime( (*i)->getTarget() ); | ||
| 110 | bld.view().endExecute(); | ||
| 111 | break; | ||
| 112 | } | ||
| 113 | if( bExtraReqs == false ) | ||
| 114 | { | ||
| 115 | std::list<std::string>::iterator k = j; | ||
| 116 | k++; | ||
| 117 | if( k == lReqs->end() ) | ||
| 118 | { | ||
| 119 | bExtraReqs = true; | ||
| 120 | bld.genRequiresFor( (*i)->getTarget(), rebuild ); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | bld.view().endPerform(); | ||
| 125 | } | ||
| 126 | |||
| 127 | //printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 ); | ||
| 128 | |||
| 129 | bld.view().endTarget(); | ||
| 130 | } | ||
| 131 | |||
| 132 | void FileTarget::clean( Builder &bld ) | ||
| 133 | { | ||
| 134 | Rule *pRule = bld.getRule( sRule ); | ||
| 135 | |||
| 136 | std::list<Perform *> perf; | ||
| 137 | std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() ); | ||
| 138 | lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); | ||
| 139 | |||
| 140 | for( std::list<std::string>::iterator i = lOutput.begin(); | ||
| 141 | i != lOutput.end(); i++ ) | ||
| 142 | { | ||
| 143 | unlink( (*i).c_str() ); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | time_t FileTarget::getTime( Builder &bld, std::string str ) | ||
| 148 | { | ||
| 149 | std::map<std::string, time_t>::iterator i = mTimes.find( str ); | ||
| 150 | if( i != mTimes.end() ) | ||
| 151 | { | ||
| 152 | //nCache++; | ||
| 153 | bld.view().beginRequiresCheck( true, str.c_str() ); | ||
| 154 | bld.view().endRequiresCheck(); | ||
| 155 | return (*i).second; | ||
| 156 | } | ||
| 157 | |||
| 158 | bld.view().beginRequiresCheck( false, str.c_str() ); | ||
| 159 | struct stat st; | ||
| 160 | stat( str.c_str(), &st ); | ||
| 161 | |||
| 162 | mTimes[str] = st.st_mtime; | ||
| 163 | |||
| 164 | //nNew++; | ||
| 165 | |||
| 166 | bld.view().endRequiresCheck(); | ||
| 167 | |||
| 168 | return st.st_mtime; | ||
| 169 | } | ||
| 170 | |||
| 171 | void FileTarget::updateTime( std::string str ) | ||
| 172 | { | ||
| 173 | struct stat st; | ||
| 174 | stat( str.c_str(), &st ); | ||
| 175 | |||
| 176 | mTimes[str] = st.st_mtime; | ||
| 177 | } | ||
| 178 | |||
diff --git a/src/filetarget.h b/src/filetarget.h deleted file mode 100644 index c78c2fd..0000000 --- a/src/filetarget.h +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | #ifndef FILE_TARGET_H | ||
| 2 | #define FILE_TARGET_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <map> | ||
| 6 | #include <sys/types.h> | ||
| 7 | #include <sys/stat.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | #include "target.h" | ||
| 10 | |||
| 11 | class FileTarget : public Target | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | FileTarget( const char *sName ); | ||
| 15 | virtual ~FileTarget(); | ||
| 16 | |||
| 17 | virtual void debug(); | ||
| 18 | |||
| 19 | void addInputDir( const char *sDir ); | ||
| 20 | |||
| 21 | virtual void check( class Builder &bld ); | ||
| 22 | virtual void clean( class Builder &bld ); | ||
| 23 | |||
| 24 | time_t getTime( class Builder &bld, std::string str ); | ||
| 25 | void updateTime( std::string str ); | ||
| 26 | |||
| 27 | private: | ||
| 28 | std::map<std::string, time_t> mTimes; | ||
| 29 | |||
| 30 | }; | ||
| 31 | |||
| 32 | #endif | ||
diff --git a/src/main.cpp b/src/main.cpp index c1df482..2b4baa5 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -10,7 +10,7 @@ class Param : public ParamProc | |||
| 10 | public: | 10 | public: |
| 11 | Param() : | 11 | Param() : |
| 12 | sFile("build.conf"), | 12 | sFile("build.conf"), |
| 13 | sCache("build.cache"), | 13 | sCache(".build.cache"), |
| 14 | bDebug( false ) | 14 | bDebug( false ) |
| 15 | { | 15 | { |
| 16 | addHelpBanner("Build r?\n\n"); | 16 | addHelpBanner("Build r?\n\n"); |
diff --git a/src/perform.cpp b/src/perform.cpp deleted file mode 100644 index c96d70f..0000000 --- a/src/perform.cpp +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | #include "perform.h" | ||
| 2 | |||
| 3 | Perform::Perform( const char *sTarget ) : | ||
| 4 | sTarget( sTarget ) | ||
| 5 | { | ||
| 6 | } | ||
| 7 | |||
| 8 | Perform::~Perform() | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
diff --git a/src/perform.h b/src/perform.h deleted file mode 100644 index 914f3b0..0000000 --- a/src/perform.h +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | #ifndef PERFORM_H | ||
| 2 | #define PERFORM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include "staticstring.h" | ||
| 6 | |||
| 7 | class Perform | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | Perform( const char *sTarget ); | ||
| 11 | virtual ~Perform(); | ||
| 12 | |||
| 13 | virtual void execute( class Builder &bld ) = 0; | ||
| 14 | |||
| 15 | const char *getTarget() | ||
| 16 | { | ||
| 17 | return sTarget; | ||
| 18 | } | ||
| 19 | |||
| 20 | private: | ||
| 21 | StaticString sTarget; | ||
| 22 | |||
| 23 | }; | ||
| 24 | |||
| 25 | #endif | ||
diff --git a/src/performcmd.cpp b/src/performcmd.cpp deleted file mode 100644 index 8eafc66..0000000 --- a/src/performcmd.cpp +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | #include "performcmd.h" | ||
| 2 | #include "builder.h" | ||
| 3 | #include "viewer.h" | ||
| 4 | |||
| 5 | PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) : | ||
| 6 | Perform( sTarget ), | ||
| 7 | sCommand( sCmd ) | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | PerformCmd::~PerformCmd() | ||
| 12 | { | ||
| 13 | } | ||
| 14 | |||
| 15 | void PerformCmd::execute( class Builder &bld ) | ||
| 16 | { | ||
| 17 | bld.view().executeCmd( sCommand ); | ||
| 18 | int ret; | ||
| 19 | if( (ret = system( sCommand.getString() )) != 0 ) | ||
| 20 | { | ||
| 21 | printf("Error code: %d\n", WEXITSTATUS(ret) ); | ||
| 22 | exit( WEXITSTATUS(ret) ); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
diff --git a/src/performcmd.h b/src/performcmd.h deleted file mode 100644 index 59510a6..0000000 --- a/src/performcmd.h +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #ifndef PERFORM_CMD_H | ||
| 2 | #define PERFORM_CMD_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "perform.h" | ||
| 7 | #include "staticstring.h" | ||
| 8 | |||
| 9 | class PerformCmd : public Perform | ||
| 10 | { | ||
| 11 | public: | ||
| 12 | PerformCmd( const char *sCmd, const char *sTarget ); | ||
| 13 | virtual ~PerformCmd(); | ||
| 14 | |||
| 15 | virtual void execute( class Builder &bld ); | ||
| 16 | |||
| 17 | private: | ||
| 18 | StaticString sCommand; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #endif | ||
diff --git a/src/regexp.cpp b/src/regexp.cpp deleted file mode 100644 index e5a3535..0000000 --- a/src/regexp.cpp +++ /dev/null | |||
| @@ -1,78 +0,0 @@ | |||
| 1 | #include "regexp.h" | ||
| 2 | #include "builder.h" // For BuildException | ||
| 3 | #include "staticstring.h" | ||
| 4 | |||
| 5 | RegExp::RegExp() : | ||
| 6 | bCompiled( false ), | ||
| 7 | aSubStr( NULL ) | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | RegExp::RegExp( const char *sSrc ) : | ||
| 12 | bCompiled( false ), | ||
| 13 | aSubStr( NULL ) | ||
| 14 | { | ||
| 15 | compile( sSrc ); | ||
| 16 | } | ||
| 17 | |||
| 18 | RegExp::~RegExp() | ||
| 19 | { | ||
| 20 | if( bCompiled ) | ||
| 21 | { | ||
| 22 | regfree( &re ); | ||
| 23 | delete[] aSubStr; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | void RegExp::compile( const char *sSrc ) | ||
| 28 | { | ||
| 29 | if( bCompiled ) | ||
| 30 | { | ||
| 31 | regfree( &re ); | ||
| 32 | delete[] aSubStr; | ||
| 33 | bCompiled = false; | ||
| 34 | } | ||
| 35 | |||
| 36 | int nErr = regcomp( &re, sSrc, REG_EXTENDED|REG_NEWLINE ); | ||
| 37 | if( nErr ) | ||
| 38 | { | ||
| 39 | size_t length = regerror( nErr, &re, NULL, 0 ); | ||
| 40 | char *buffer = new char[length]; | ||
| 41 | (void) regerror( nErr, &re, buffer, length ); | ||
| 42 | StaticString s( buffer ); | ||
| 43 | delete[] buffer; | ||
| 44 | throw BuildException( s.getString() ); | ||
| 45 | } | ||
| 46 | bCompiled = true; | ||
| 47 | this->sSrc = sSrc; | ||
| 48 | |||
| 49 | nSubStr = re.re_nsub+1; | ||
| 50 | aSubStr = new regmatch_t[nSubStr]; | ||
| 51 | } | ||
| 52 | |||
| 53 | int RegExp::getNumSubStrings() | ||
| 54 | { | ||
| 55 | return nSubStr; | ||
| 56 | } | ||
| 57 | |||
| 58 | bool RegExp::execute( const char *sSrc ) | ||
| 59 | { | ||
| 60 | sTest = sSrc; | ||
| 61 | if( regexec( &re, sSrc, nSubStr, aSubStr, 0 ) ) | ||
| 62 | return false; | ||
| 63 | return true; | ||
| 64 | } | ||
| 65 | |||
| 66 | std::pair<int,int> RegExp::getSubStringRange( int nIndex ) | ||
| 67 | { | ||
| 68 | return std::pair<int,int>( aSubStr[nIndex].rm_so, aSubStr[nIndex].rm_eo ); | ||
| 69 | } | ||
| 70 | |||
| 71 | std::string RegExp::getSubString( int nIndex ) | ||
| 72 | { | ||
| 73 | return std::string( | ||
| 74 | sTest.getString()+aSubStr[nIndex].rm_so, | ||
| 75 | aSubStr[nIndex].rm_eo - aSubStr[nIndex].rm_so | ||
| 76 | ); | ||
| 77 | } | ||
| 78 | |||
diff --git a/src/regexp.h b/src/regexp.h deleted file mode 100644 index 96f3747..0000000 --- a/src/regexp.h +++ /dev/null | |||
| @@ -1,36 +0,0 @@ | |||
| 1 | #ifndef REG_EXP_H | ||
| 2 | #define REG_EXP_H | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <regex.h> | ||
| 7 | #include <utility> | ||
| 8 | #include "staticstring.h" | ||
| 9 | |||
| 10 | class RegExp | ||
| 11 | { | ||
| 12 | public: | ||
| 13 | RegExp(); | ||
| 14 | RegExp( const char *sSrc ); | ||
| 15 | virtual ~RegExp(); | ||
| 16 | |||
| 17 | void compile( const char *sSrc ); | ||
| 18 | int getNumSubStrings(); | ||
| 19 | bool execute( const char *sSrc ); | ||
| 20 | std::pair<int,int> getSubStringRange( int nIndex ); | ||
| 21 | std::string getSubString( int nIndex ); | ||
| 22 | const char *getSource() | ||
| 23 | { | ||
| 24 | return sSrc; | ||
| 25 | } | ||
| 26 | |||
| 27 | private: | ||
| 28 | StaticString sSrc; | ||
| 29 | StaticString sTest; | ||
| 30 | regex_t re; | ||
| 31 | bool bCompiled; | ||
| 32 | int nSubStr; | ||
| 33 | regmatch_t *aSubStr; | ||
| 34 | }; | ||
| 35 | |||
| 36 | #endif | ||
diff --git a/src/rule.cpp b/src/rule.cpp deleted file mode 100644 index ce37e93..0000000 --- a/src/rule.cpp +++ /dev/null | |||
| @@ -1,195 +0,0 @@ | |||
| 1 | #include "rule.h" | ||
| 2 | #include "perform.h" | ||
| 3 | #include "performcmd.h" | ||
| 4 | #include "builder.h" // for BuildException | ||
| 5 | |||
| 6 | Rule::Rule( const char *sName ) : | ||
| 7 | sName( sName ), | ||
| 8 | bNoProduces( true ) | ||
| 9 | { | ||
| 10 | lProduces.push_back("{target}"); | ||
| 11 | } | ||
| 12 | |||
| 13 | Rule::~Rule() | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | void Rule::debug() | ||
| 18 | { | ||
| 19 | printf(" Rule %s:\n", | ||
| 20 | sName.getString() | ||
| 21 | ); | ||
| 22 | printf(" Produces: "); | ||
| 23 | if( lProduces.empty() ) | ||
| 24 | printf("{target}"); | ||
| 25 | else | ||
| 26 | { | ||
| 27 | for( std::list<std::string>::iterator i = lProduces.begin(); | ||
| 28 | i != lProduces.end(); i++ ) | ||
| 29 | { | ||
| 30 | if( i != lProduces.begin() ) | ||
| 31 | printf(", "); | ||
| 32 | printf("%s", (*i).c_str() ); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | printf("\n Matches "); | ||
| 36 | if( mHow == matchOne ) | ||
| 37 | printf("one "); | ||
| 38 | else if( mHow == matchAll ) | ||
| 39 | printf("all "); | ||
| 40 | printf("/%s/\n", rWhat.getSource() ); | ||
| 41 | |||
| 42 | printf(" Performs "); | ||
| 43 | if( pHow == perfCommand ) | ||
| 44 | printf("command "); | ||
| 45 | printf("\"%s\"\n", sPerfCmd.getString() ); | ||
| 46 | } | ||
| 47 | |||
| 48 | void Rule::addProduces( const char *sP ) | ||
| 49 | { | ||
| 50 | if( bNoProduces ) | ||
| 51 | { | ||
| 52 | lProduces.clear(); | ||
| 53 | bNoProduces = false; | ||
| 54 | } | ||
| 55 | lProduces.push_back( sP ); | ||
| 56 | } | ||
| 57 | |||
| 58 | void Rule::setMatches( Matches how, const char *sW ) | ||
| 59 | { | ||
| 60 | rWhat.compile( sW ); | ||
| 61 | mHow = how; | ||
| 62 | } | ||
| 63 | |||
| 64 | void Rule::setPerforms( ePerform pwhat, const char *sperfcmd ) | ||
| 65 | { | ||
| 66 | pHow = pwhat; | ||
| 67 | sPerfCmd = sperfcmd; | ||
| 68 | } | ||
| 69 | |||
| 70 | Perform *Rule::buildCommand( Builder &bld, const char *sCmd, Builder::varmap *vars ) | ||
| 71 | { | ||
| 72 | return new PerformCmd( | ||
| 73 | bld.varRepl( sCmd, (*vars)["target"].c_str(), vars ).c_str(), | ||
| 74 | (*vars)["target"].c_str() | ||
| 75 | ); | ||
| 76 | } | ||
| 77 | |||
| 78 | std::list<std::string> Rule::execute( Builder &bld, std::list<std::string> lInput, std::list<Perform *> &lPerf, const char *sTarget ) | ||
| 79 | { | ||
| 80 | bld.requiresRegexp( false ); | ||
| 81 | std::list<Rule *> lRule = bld.findRuleChain( this ); | ||
| 82 | /* | ||
| 83 | if( !lRule.empty() ) | ||
| 84 | { | ||
| 85 | printf("Rule %s chains to: ", sName.getString() ); | ||
| 86 | for( std::list<Rule *>::iterator i = lRule.begin(); | ||
| 87 | i != lRule.end(); i++ ) | ||
| 88 | { | ||
| 89 | if( i != lRule.begin() ) | ||
| 90 | printf(", "); | ||
| 91 | printf("%s", (*i)->sName.getString() ); | ||
| 92 | } | ||
| 93 | printf("\n"); | ||
| 94 | }*/ | ||
| 95 | |||
| 96 | std::list<std::string> lOutput; | ||
| 97 | std::string sMatches; | ||
| 98 | |||
| 99 | for( std::list<Rule *>::iterator i = lRule.begin(); i != lRule.end(); i++ ) | ||
| 100 | { | ||
| 101 | std::list<std::string> lTmp = (*i)->execute( bld, lInput, lPerf ); | ||
| 102 | lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); | ||
| 103 | } | ||
| 104 | |||
| 105 | std::list<std::string> lTest; | ||
| 106 | lTest.insert( lTest.end(), lInput.begin(), lInput.end() ); | ||
| 107 | lTest.insert( lTest.end(), lOutput.begin(), lOutput.end() ); | ||
| 108 | |||
| 109 | cleanList( lTest ); | ||
| 110 | |||
| 111 | for( std::list<std::string>::iterator i = lTest.begin(); | ||
| 112 | i != lTest.end(); i++ ) | ||
| 113 | { | ||
| 114 | if( rWhat.execute( (*i).c_str() ) ) | ||
| 115 | { | ||
| 116 | Builder::varmap *revars = bld.regexVars( &rWhat ); | ||
| 117 | for( std::list<std::string>::iterator j = lProduces.begin(); | ||
| 118 | j != lProduces.end(); j++ ) | ||
| 119 | { | ||
| 120 | if( mHow == matchOne ) | ||
| 121 | { | ||
| 122 | lOutput.push_back( | ||
| 123 | bld.varRepl( | ||
| 124 | (*j).c_str(), | ||
| 125 | "", | ||
| 126 | revars | ||
| 127 | ) | ||
| 128 | ); | ||
| 129 | (*revars)["target"] = (sTarget==NULL)? | ||
| 130 | (lOutput.back().c_str()):(sTarget); | ||
| 131 | (*revars)["match"] = (*i).c_str(); | ||
| 132 | Perform *p = buildCommand( | ||
| 133 | bld, | ||
| 134 | sPerfCmd, | ||
| 135 | revars | ||
| 136 | ); | ||
| 137 | lPerf.push_back( p ); | ||
| 138 | |||
| 139 | bld.requires( | ||
| 140 | (*revars)["target"].c_str(), | ||
| 141 | (*revars)["match"].c_str() | ||
| 142 | ); | ||
| 143 | } | ||
| 144 | else if( mHow == matchAll ) | ||
| 145 | { | ||
| 146 | sMatches += " "; | ||
| 147 | sMatches += (*i); | ||
| 148 | |||
| 149 | bld.requires( | ||
| 150 | sTarget, | ||
| 151 | (*i).c_str() | ||
| 152 | ); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | delete revars; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | //std::list<std::string> lTmp = findTargets( bld, lTest, sMatches, sTarget ); | ||
| 159 | //lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); | ||
| 160 | |||
| 161 | if( mHow == matchAll ) | ||
| 162 | { | ||
| 163 | lOutput.push_back( | ||
| 164 | bld.varRepl( | ||
| 165 | sTarget, | ||
| 166 | sTarget, | ||
| 167 | NULL | ||
| 168 | ) | ||
| 169 | ); | ||
| 170 | Builder::varmap vars; | ||
| 171 | vars["target"] = sTarget; | ||
| 172 | vars["match"] = sMatches; | ||
| 173 | Perform *p = buildCommand( | ||
| 174 | bld, | ||
| 175 | sPerfCmd, | ||
| 176 | &vars | ||
| 177 | ); | ||
| 178 | lPerf.push_back( p ); | ||
| 179 | } | ||
| 180 | |||
| 181 | return lOutput; | ||
| 182 | } | ||
| 183 | |||
| 184 | bool Rule::willChain( Rule *pRule ) | ||
| 185 | { | ||
| 186 | for( std::list<std::string>::iterator i = pRule->lProduces.begin(); | ||
| 187 | i != pRule->lProduces.end(); i++ ) | ||
| 188 | { | ||
| 189 | if( rWhat.execute( (*i).c_str() ) ) | ||
| 190 | return true; | ||
| 191 | } | ||
| 192 | |||
| 193 | return false; | ||
| 194 | } | ||
| 195 | |||
diff --git a/src/rule.h b/src/rule.h deleted file mode 100644 index b7c0049..0000000 --- a/src/rule.h +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | #ifndef RULE_H | ||
| 2 | #define RULE_H | ||
| 3 | |||
| 4 | #include <list> | ||
| 5 | #include <string> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include "regexp.h" | ||
| 8 | #include "staticstring.h" | ||
| 9 | #include "builder.h" | ||
| 10 | |||
| 11 | class Perform; | ||
| 12 | |||
| 13 | class Rule | ||
| 14 | { | ||
| 15 | public: | ||
| 16 | enum Matches | ||
| 17 | { | ||
| 18 | matchOne, | ||
| 19 | matchAll | ||
| 20 | }; | ||
| 21 | |||
| 22 | enum ePerform | ||
| 23 | { | ||
| 24 | perfCommand | ||
| 25 | }; | ||
| 26 | |||
| 27 | public: | ||
| 28 | Rule( const char *sName ); | ||
| 29 | virtual ~Rule(); | ||
| 30 | |||
| 31 | const char *getName() | ||
| 32 | { | ||
| 33 | return sName; | ||
| 34 | } | ||
| 35 | |||
| 36 | void debug(); | ||
| 37 | |||
| 38 | void addProduces( const char *sProduces ); | ||
| 39 | void setMatches( Matches how, const char *sWhat ); | ||
| 40 | void setPerforms( ePerform pwhat, const char *sPerfCmd ); | ||
| 41 | |||
| 42 | bool willChain( Rule *pRule ); | ||
| 43 | |||
| 44 | std::list<std::string> execute( class Builder &bld, std::list<std::string> lInput, std::list<Perform *> &lPerf, const char *sTarget=NULL ); | ||
| 45 | |||
| 46 | private: | ||
| 47 | class Perform *buildCommand( class Builder &bld, const char *sCmd, Builder::varmap *vars ); | ||
| 48 | std::list<std::string> findTargets( class Builder &bld, std::list<std::string> &lIn, std::string &sMatches, const char *sTarget ); | ||
| 49 | StaticString sName; | ||
| 50 | std::list<std::string> lProduces; | ||
| 51 | |||
| 52 | Matches mHow; | ||
| 53 | RegExp rWhat; | ||
| 54 | //StaticString sWhat; | ||
| 55 | //regex_t rWhat; | ||
| 56 | |||
| 57 | ePerform pHow; | ||
| 58 | StaticString sPerfCmd; | ||
| 59 | |||
| 60 | bool bNoProduces; | ||
| 61 | }; | ||
| 62 | |||
| 63 | #endif | ||
diff --git a/src/target.cpp b/src/target.cpp deleted file mode 100644 index 8f4cc4b..0000000 --- a/src/target.cpp +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | #include "target.h" | ||
| 2 | |||
| 3 | Target::Target( const char *sName ) : | ||
| 4 | sName( sName ) | ||
| 5 | { | ||
| 6 | } | ||
| 7 | |||
| 8 | Target::~Target() | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | void Target::setRule( const char *sRule ) | ||
| 13 | { | ||
| 14 | this->sRule = sRule; | ||
| 15 | } | ||
| 16 | |||
| 17 | void Target::debug() | ||
| 18 | { | ||
| 19 | printf(" %s:\n Rule: %s\n", | ||
| 20 | sName.getString(), | ||
| 21 | sRule.getString() | ||
| 22 | ); | ||
| 23 | printf(" Input list:\n"); | ||
| 24 | for( std::list<std::string>::iterator i = lInput.begin(); | ||
| 25 | i != lInput.end(); i++ ) | ||
| 26 | { | ||
| 27 | printf(" %s\n", (*i).c_str() ); | ||
| 28 | } | ||
| 29 | printf(" Output list:\n"); | ||
| 30 | for( std::list<std::string>::iterator i = lOutput.begin(); | ||
| 31 | i != lOutput.end(); i++ ) | ||
| 32 | { | ||
| 33 | printf(" %s\n", (*i).c_str() ); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | void Target::addInput( const char *sInput ) | ||
| 38 | { | ||
| 39 | lInput.push_back( sInput ); | ||
| 40 | } | ||
| 41 | |||
| 42 | void Target::addOutput( const char *sOutput ) | ||
| 43 | { | ||
| 44 | lOutput.push_back( sOutput ); | ||
| 45 | } | ||
| 46 | |||
diff --git a/src/target.h b/src/target.h deleted file mode 100644 index 59c5d7e..0000000 --- a/src/target.h +++ /dev/null | |||
| @@ -1,39 +0,0 @@ | |||
| 1 | #ifndef TARGET_H | ||
| 2 | #define TARGET_H | ||
| 3 | |||
| 4 | #include <list> | ||
| 5 | #include <string> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include "staticstring.h" | ||
| 8 | |||
| 9 | class Target | ||
| 10 | { | ||
| 11 | public: | ||
| 12 | Target( const char *sName ); | ||
| 13 | virtual ~Target(); | ||
| 14 | |||
| 15 | const char *getName() | ||
| 16 | { | ||
| 17 | return sName; | ||
| 18 | } | ||
| 19 | |||
| 20 | void setRule( const char *sRule ); | ||
| 21 | |||
| 22 | virtual void debug(); | ||
| 23 | |||
| 24 | void addInput( const char *sInput ); | ||
| 25 | void addOutput( const char *sOutput ); | ||
| 26 | |||
| 27 | virtual void check( class Builder &bld ) = 0; | ||
| 28 | virtual void clean( class Builder &bld ) = 0; | ||
| 29 | |||
| 30 | protected: | ||
| 31 | StaticString sName; | ||
| 32 | StaticString sRule; | ||
| 33 | |||
| 34 | std::list<std::string> lInput; | ||
| 35 | std::list<std::string> lOutput; | ||
| 36 | |||
| 37 | }; | ||
| 38 | |||
| 39 | #endif | ||
diff --git a/src/viewer.cpp b/src/viewer.cpp deleted file mode 100644 index ed6abfb..0000000 --- a/src/viewer.cpp +++ /dev/null | |||
| @@ -1,62 +0,0 @@ | |||
| 1 | #include "viewer.h" | ||
| 2 | |||
| 3 | Viewer::Viewer() | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | Viewer::~Viewer() | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | void Viewer::beginAction( const char *sName, int nCommands ) | ||
| 12 | { | ||
| 13 | } | ||
| 14 | |||
| 15 | void Viewer::endAction() | ||
| 16 | { | ||
| 17 | } | ||
| 18 | |||
| 19 | void Viewer::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) | ||
| 20 | { | ||
| 21 | } | ||
| 22 | |||
| 23 | void Viewer::endTarget() | ||
| 24 | { | ||
| 25 | } | ||
| 26 | |||
| 27 | void Viewer::beginPerform( Perform *pPerf ) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | void Viewer::beginRequiresCheck( bool bCached, const char *sName ) | ||
| 32 | { | ||
| 33 | } | ||
| 34 | |||
| 35 | void Viewer::endRequiresCheck() | ||
| 36 | { | ||
| 37 | } | ||
| 38 | |||
| 39 | void Viewer::beginExtraRequiresCheck( const char *sCommand ) | ||
| 40 | { | ||
| 41 | } | ||
| 42 | |||
| 43 | void Viewer::endExtraRequiresCheck() | ||
| 44 | { | ||
| 45 | } | ||
| 46 | |||
| 47 | void Viewer::beginExecute() | ||
| 48 | { | ||
| 49 | } | ||
| 50 | |||
| 51 | void Viewer::executeCmd( const char *sCmd ) | ||
| 52 | { | ||
| 53 | } | ||
| 54 | |||
| 55 | void Viewer::endExecute() | ||
| 56 | { | ||
| 57 | } | ||
| 58 | |||
| 59 | void Viewer::endPerform() | ||
| 60 | { | ||
| 61 | } | ||
| 62 | |||
diff --git a/src/viewer.h b/src/viewer.h deleted file mode 100644 index 8f2a595..0000000 --- a/src/viewer.h +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | #ifndef VIEWER_H | ||
| 2 | #define VIEWER_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | class Perform; | ||
| 7 | |||
| 8 | class Viewer | ||
| 9 | { | ||
| 10 | public: | ||
| 11 | Viewer(); | ||
| 12 | virtual ~Viewer(); | ||
| 13 | |||
| 14 | virtual void beginAction( const char *sName, int nCommands ); | ||
| 15 | virtual void endAction(); | ||
| 16 | virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); | ||
| 17 | virtual void endTarget(); | ||
| 18 | |||
| 19 | virtual void beginPerform( Perform *pPerf ); | ||
| 20 | virtual void beginRequiresCheck( bool bCached, const char *sName ); | ||
| 21 | virtual void endRequiresCheck(); | ||
| 22 | virtual void beginExtraRequiresCheck( const char *sCommand ); | ||
| 23 | virtual void endExtraRequiresCheck(); | ||
| 24 | virtual void beginExecute(); | ||
| 25 | virtual void executeCmd( const char *sCmd ); | ||
| 26 | virtual void endExecute(); | ||
| 27 | virtual void endPerform(); | ||
| 28 | |||
| 29 | private: | ||
| 30 | |||
| 31 | }; | ||
| 32 | |||
| 33 | #endif | ||
diff --git a/src/viewermake.cpp b/src/viewermake.cpp deleted file mode 100644 index 7f63552..0000000 --- a/src/viewermake.cpp +++ /dev/null | |||
| @@ -1,62 +0,0 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "viewermake.h" | ||
| 3 | #include "perform.h" | ||
| 4 | |||
| 5 | ViewerMake::ViewerMake() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | ViewerMake::~ViewerMake() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | void ViewerMake::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) | ||
| 14 | { | ||
| 15 | //sAction = sName; | ||
| 16 | //bPrinted = false; | ||
| 17 | } | ||
| 18 | |||
| 19 | void ViewerMake::printHead() | ||
| 20 | { | ||
| 21 | /* | ||
| 22 | if( bPrinted == false ) | ||
| 23 | { | ||
| 24 | printf("--- %s ---\n", sAction.getString() ); | ||
| 25 | bPrinted = true; | ||
| 26 | }*/ | ||
| 27 | } | ||
| 28 | |||
| 29 | void ViewerMake::endTarget() | ||
| 30 | { | ||
| 31 | /*if( bPrinted == true ) | ||
| 32 | { | ||
| 33 | printf("\n"); | ||
| 34 | } | ||
| 35 | else | ||
| 36 | { | ||
| 37 | printf("Nothing to be done for %s.\n", sAction.getString() ); | ||
| 38 | }*/ | ||
| 39 | } | ||
| 40 | |||
| 41 | void ViewerMake::beginPerform( Perform *pPerf ) | ||
| 42 | { | ||
| 43 | //sTarget = pPerf->getTarget(); | ||
| 44 | } | ||
| 45 | |||
| 46 | void ViewerMake::beginExtraRequiresCheck( const char *sCommand ) | ||
| 47 | { | ||
| 48 | //printHead(); | ||
| 49 | //printf(" check: %s\n", sTarget.getString() ); | ||
| 50 | } | ||
| 51 | |||
| 52 | void ViewerMake::beginExecute() | ||
| 53 | { | ||
| 54 | //printHead(); | ||
| 55 | //printf(" build: %s\n", sTarget.getString() ); | ||
| 56 | } | ||
| 57 | |||
| 58 | void ViewerMake::executeCmd( const char *sCmd ) | ||
| 59 | { | ||
| 60 | printf("%s\n", sCmd ); | ||
| 61 | } | ||
| 62 | |||
diff --git a/src/viewermake.h b/src/viewermake.h deleted file mode 100644 index 767d0bd..0000000 --- a/src/viewermake.h +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | #ifndef VIEWER_MAKE_H | ||
| 2 | #define VIEWER_MAKE_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "viewer.h" | ||
| 7 | #include "staticstring.h" | ||
| 8 | |||
| 9 | class ViewerMake : public Viewer | ||
| 10 | { | ||
| 11 | public: | ||
| 12 | ViewerMake(); | ||
| 13 | virtual ~ViewerMake(); | ||
| 14 | |||
| 15 | virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); | ||
| 16 | virtual void endTarget(); | ||
| 17 | |||
| 18 | virtual void beginPerform( Perform *pPerf ); | ||
| 19 | virtual void beginExtraRequiresCheck( const char *sCommand ); | ||
| 20 | void printHead(); | ||
| 21 | virtual void beginExecute(); | ||
| 22 | virtual void executeCmd( const char *sCmd ); | ||
| 23 | |||
| 24 | private: | ||
| 25 | |||
| 26 | }; | ||
| 27 | |||
| 28 | #endif | ||
diff --git a/src/viewerpercent.cpp b/src/viewerpercent.cpp deleted file mode 100644 index 0b0344b..0000000 --- a/src/viewerpercent.cpp +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | #include "viewerpercent.h" | ||
| 2 | #include "perform.h" | ||
| 3 | |||
| 4 | ViewerPercent::ViewerPercent() : | ||
| 5 | nWidth( 25 ) | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | ViewerPercent::~ViewerPercent() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | void ViewerPercent::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) | ||
| 14 | { | ||
| 15 | printf("--- %s ---\n", sName ); | ||
| 16 | nMax = nPerforms; | ||
| 17 | nCount = 0; | ||
| 18 | nLastLen = 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | void ViewerPercent::endTarget() | ||
| 22 | { | ||
| 23 | printf("\n\n"); | ||
| 24 | } | ||
| 25 | |||
| 26 | void ViewerPercent::beginPerform( Perform *pPerf ) | ||
| 27 | { | ||
| 28 | sTarget = pPerf->getTarget(); | ||
| 29 | } | ||
| 30 | |||
| 31 | void ViewerPercent::beginExecute() | ||
| 32 | { | ||
| 33 | } | ||
| 34 | |||
| 35 | void ViewerPercent::endPerform() | ||
| 36 | { | ||
| 37 | nCount++; | ||
| 38 | |||
| 39 | int nPer = (nCount*nWidth)/nMax; | ||
| 40 | fputc( '[', stdout ); | ||
| 41 | for( int j = 0; j < nPer; j++ ) | ||
| 42 | fputc('=', stdout ); | ||
| 43 | for( int j = nPer; j < nWidth; j++ ) | ||
| 44 | fputc(' ', stdout ); | ||
| 45 | //fputc(']', stdout ); | ||
| 46 | |||
| 47 | printf("] %s", sTarget.getString() ); | ||
| 48 | |||
| 49 | int diff = nLastLen-sTarget; | ||
| 50 | for( int j = 0; j < diff; j++ ) | ||
| 51 | fputc(' ', stdout ); | ||
| 52 | |||
| 53 | nLastLen = sTarget; | ||
| 54 | |||
| 55 | fputc('\r', stdout ); | ||
| 56 | fflush( stdout ); | ||
| 57 | } | ||
| 58 | |||
diff --git a/src/viewerpercent.h b/src/viewerpercent.h deleted file mode 100644 index d575940..0000000 --- a/src/viewerpercent.h +++ /dev/null | |||
| @@ -1,30 +0,0 @@ | |||
| 1 | #ifndef VIEWER_PERCENT_H | ||
| 2 | #define VIEWER_PERCENT_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "viewer.h" | ||
| 7 | #include "staticstring.h" | ||
| 8 | |||
| 9 | class ViewerPercent : public Viewer | ||
| 10 | { | ||
| 11 | public: | ||
| 12 | ViewerPercent(); | ||
| 13 | virtual ~ViewerPercent(); | ||
| 14 | |||
| 15 | virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); | ||
| 16 | virtual void endTarget(); | ||
| 17 | |||
| 18 | virtual void beginPerform( Perform *pPerf ); | ||
| 19 | virtual void beginExecute(); | ||
| 20 | virtual void endPerform(); | ||
| 21 | |||
| 22 | private: | ||
| 23 | class StaticString sTarget; | ||
| 24 | int nLastLen; | ||
| 25 | int nWidth; | ||
| 26 | int nMax; | ||
| 27 | int nCount; | ||
| 28 | }; | ||
| 29 | |||
| 30 | #endif | ||
diff --git a/src/viewerplain.cpp b/src/viewerplain.cpp deleted file mode 100644 index 52b798b..0000000 --- a/src/viewerplain.cpp +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "viewerplain.h" | ||
| 3 | #include "perform.h" | ||
| 4 | |||
| 5 | ViewerPlain::ViewerPlain() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | ViewerPlain::~ViewerPlain() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | void ViewerPlain::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) | ||
| 14 | { | ||
| 15 | sAction = sName; | ||
| 16 | bPrinted = false; | ||
| 17 | } | ||
| 18 | |||
| 19 | void ViewerPlain::printHead() | ||
| 20 | { | ||
| 21 | if( bPrinted == false ) | ||
| 22 | { | ||
| 23 | printf("--- %s ---\n", sAction.getString() ); | ||
| 24 | bPrinted = true; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | void ViewerPlain::endTarget() | ||
| 29 | { | ||
| 30 | if( bPrinted == true ) | ||
| 31 | { | ||
| 32 | printf("\n"); | ||
| 33 | } | ||
| 34 | else | ||
| 35 | { | ||
| 36 | printf("Nothing to be done for %s.\n", sAction.getString() ); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | void ViewerPlain::beginPerform( Perform *pPerf ) | ||
| 41 | { | ||
| 42 | sTarget = pPerf->getTarget(); | ||
| 43 | } | ||
| 44 | |||
| 45 | void ViewerPlain::beginExtraRequiresCheck( const char *sCommand ) | ||
| 46 | { | ||
| 47 | printHead(); | ||
| 48 | printf(" check: %s\n", sTarget.getString() ); | ||
| 49 | } | ||
| 50 | |||
| 51 | void ViewerPlain::beginExecute() | ||
| 52 | { | ||
| 53 | printHead(); | ||
| 54 | printf(" build: %s\n", sTarget.getString() ); | ||
| 55 | } | ||
| 56 | |||
| 57 | void ViewerPlain::executeCmd( const char *sCmd ) | ||
| 58 | { | ||
| 59 | //printf("--> %s\n", sCmd ); | ||
| 60 | } | ||
| 61 | |||
diff --git a/src/viewerplain.h b/src/viewerplain.h deleted file mode 100644 index 4c88a0f..0000000 --- a/src/viewerplain.h +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | #ifndef VIEWER_PLAIN_H | ||
| 2 | #define VIEWER_PLAIN_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "viewer.h" | ||
| 7 | #include "staticstring.h" | ||
| 8 | |||
| 9 | class ViewerPlain : public Viewer | ||
| 10 | { | ||
| 11 | public: | ||
| 12 | ViewerPlain(); | ||
| 13 | virtual ~ViewerPlain(); | ||
| 14 | |||
| 15 | virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); | ||
| 16 | virtual void endTarget(); | ||
| 17 | |||
| 18 | virtual void beginPerform( Perform *pPerf ); | ||
| 19 | virtual void beginExtraRequiresCheck( const char *sCommand ); | ||
| 20 | void printHead(); | ||
| 21 | virtual void beginExecute(); | ||
| 22 | virtual void executeCmd( const char *sCmd ); | ||
| 23 | |||
| 24 | private: | ||
| 25 | class StaticString sAction; | ||
| 26 | bool bPrinted; | ||
| 27 | class StaticString sTarget; | ||
| 28 | |||
| 29 | }; | ||
| 30 | |||
| 31 | #endif | ||
