aboutsummaryrefslogtreecommitdiff
path: root/src/rule.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/rule.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/rule.cpp b/src/rule.cpp
new file mode 100644
index 0000000..a7ebf9b
--- /dev/null
+++ b/src/rule.cpp
@@ -0,0 +1,61 @@
1#include "rule.h"
2#include "builder.h" // for BuildException
3
4Rule::Rule( const char *sName ) :
5 sName( sName ),
6 sProduces("{target}")
7{
8}
9
10Rule::~Rule()
11{
12 regfree( &rWhat );
13}
14
15void Rule::debug()
16{
17 printf(" Rule %s produces %s:\n",
18 sName.getString(),
19 sProduces.getString()
20 );
21 printf(" Matches ");
22 if( mHow == matchOne )
23 printf("one ");
24 else if( mHow == matchAll )
25 printf("all ");
26 printf("/%s/\n", sWhat.getString() );
27
28 printf(" Performs ");
29 if( pHow == perfCommand )
30 printf("command ");
31 printf("\"%s\"\n", sPerfCmd.getString() );
32}
33
34void Rule::setProduces( const char *sP )
35{
36 sProduces = sP;
37}
38
39void Rule::setMatches( Matches how, const char *sW )
40{
41 sWhat = sW;
42 mHow = how;
43
44 int nErr = regcomp( &rWhat, sW, REG_EXTENDED|REG_NEWLINE );
45 if( nErr )
46 {
47 size_t length = regerror( nErr, &rWhat, NULL, 0 );
48 char *buffer = new char[length];
49 (void) regerror( nErr, &rWhat, buffer, length );
50 StaticString s( buffer );
51 delete[] buffer;
52 throw BuildException( s.getString() );
53 }
54}
55
56void Rule::setPerforms( Perform pwhat, const char *sperfcmd )
57{
58 pHow = pwhat;
59 sPerfCmd = sperfcmd;
60}
61