aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-01-07 00:36:55 +0000
committerMike Buland <eichlan@xagasoft.com>2010-01-07 00:36:55 +0000
commitcbd0823fde1b3feb4cfa9ef3a5affca5a4554d5e (patch)
tree774564c97de455c40428ae5fa23638893fd1bbc0
parent3c7e81d3baba06cb1bf37de84aeaa6cad277652a (diff)
downloadbuild-cbd0823fde1b3feb4cfa9ef3a5affca5a4554d5e.tar.gz
build-cbd0823fde1b3feb4cfa9ef3a5affca5a4554d5e.tar.bz2
build-cbd0823fde1b3feb4cfa9ef3a5affca5a4554d5e.tar.xz
build-cbd0823fde1b3feb4cfa9ef3a5affca5a4554d5e.zip
Updated the general rules to use the new regex function, they're safer now,
and everything works. Unfortunately, with this release, you'll have to rebuild with the shell script...
Diffstat (limited to '')
-rwxr-xr-xbuild.sh8
-rw-r--r--share/autoinclude/general-rules.bld13
-rw-r--r--src/functionplugger.cpp2
-rw-r--r--src/functionregex.cpp126
-rw-r--r--src/functionregex.h24
5 files changed, 162 insertions, 11 deletions
diff --git a/build.sh b/build.sh
index 53e9baa..c0ee4f5 100755
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,7 @@
1#!/bin/bash 1#!/bin/bash
2 2
3BUSRC="stack.cpp fstring.cpp fbasicstring.cpp hash.cpp list.cpp trace.cpp stream.cpp formatter.cpp util.cpp sharedcore.cpp exceptionbase.cpp heap.cpp archivebase.cpp archive.cpp queue.cpp archival.cpp sio.cpp stdstream.cpp process.cpp plugger.cpp optparser.cpp signals.cpp array.cpp membuf.cpp file.cpp" 3BUSRC="stack.cpp fstring.cpp fbasicstring.cpp hash.cpp list.cpp trace.cpp stream.cpp formatter.cpp util.cpp sharedcore.cpp exceptionbase.cpp heap.cpp archivebase.cpp archive.cpp queue.cpp archival.cpp sio.cpp stdstream.cpp process.cpp plugger.cpp optparser.cpp signals.cpp array.cpp membuf.cpp file.cpp regex.cpp"
4BUHDR="stack.h fstring.h fbasicstring.h hash.h list.h trace.h stream.h formatter.h util.h sharedcore.h exceptionbase.h heap.h archivebase.h archive.h queue.h archival.h sio.h stdstream.h process.h osx_compatibility.h win32_compatibility.h linux_compatibility.h plugger.h singleton.h optparser.h signals.h array.h membuf.h file.h" 4BUHDR="stack.h fstring.h fbasicstring.h hash.h list.h trace.h stream.h formatter.h util.h sharedcore.h exceptionbase.h heap.h archivebase.h archive.h queue.h archival.h sio.h stdstream.h process.h osx_compatibility.h win32_compatibility.h linux_compatibility.h plugger.h singleton.h optparser.h signals.h array.h membuf.h file.h regex.h"
5 5
6function bld() 6function bld()
7{ 7{
@@ -27,7 +27,7 @@ function cmd()
27 27
28function gpp() 28function gpp()
29{ 29{
30 bld "$1" "$2" || cmd CXX "$1" g++ -ggdb -W -Wall -Iminibu -Iminibu/bu -c -o "$1" "$2" 30 bld "$1" "$2" || cmd CXX "$1" g++ -ggdb -fPIC -rdynamic -W -Wall -Iminibu -c -o "$1" "$2"
31} 31}
32 32
33if [ ! -z "$1" ]; then 33if [ ! -z "$1" ]; then
@@ -64,5 +64,5 @@ for F in src/*.c src/*.cpp; do
64 OUTPUT=${F%.*}.o 64 OUTPUT=${F%.*}.o
65 gpp "$OUTPUT" "$F" 65 gpp "$OUTPUT" "$F"
66done 66done
67bld build src/*.o minibu/src/*.o || cmd LINK build g++ -o build src/*.o minibu/src/*.o -ldl 67bld build src/*.o minibu/src/*.o || cmd LINK build g++ -fPIC -rdynamic -Wl,-export-dynamic -o build src/*.o minibu/src/*.o -ldl
68bld build~ build || cmd CP build~ cp build build~ 68bld build~ build || cmd CP build~ cp build build~
diff --git a/share/autoinclude/general-rules.bld b/share/autoinclude/general-rules.bld
index 9f905a6..94b06eb 100644
--- a/share/autoinclude/general-rules.bld
+++ b/share/autoinclude/general-rules.bld
@@ -40,7 +40,7 @@ function cppToObj()
40 DIR = OBJ_DIR; 40 DIR = OBJ_DIR;
41 } 41 }
42 42
43 return DIR + "/" + INPUT.fileName().replace(".cpp", ".o"); 43 return DIR + "/" + INPUT.fileName().regex("\\.cpp$", ".o");
44} 44}
45 45
46function cToObj() 46function cToObj()
@@ -54,7 +54,7 @@ function cToObj()
54 DIR = OBJ_DIR; 54 DIR = OBJ_DIR;
55 } 55 }
56 56
57 return DIR + "/" + INPUT.fileName().replace(".c", ".o"); 57 return DIR + "/" + INPUT.fileName().regex("\\.c$", ".o");
58} 58}
59 59
60rule "exe" 60rule "exe"
@@ -100,7 +100,6 @@ rule "c"
100{ 100{
101 input "*.c"; 101 input "*.c";
102 output INPUT.cToObj(); 102 output INPUT.cToObj();
103// output replace(".c", ".o");
104 requires getMakeDeps("${CC} ${CFLAGS} -M ${INPUT}"); 103 requires getMakeDeps("${CC} ${CFLAGS} -M ${INPUT}");
105 profile "build" 104 profile "build"
106 { 105 {
@@ -111,10 +110,10 @@ rule "c"
111rule "bison" 110rule "bison"
112{ 111{
113 input "*.y"; 112 input "*.y";
114 output [INPUT.replace(".y", ".tab.c"), INPUT.replace(".y", ".tab.h")]; 113 output [INPUT.regex("\\.y$", ".tab.c"), INPUT.regex("\\.y$", ".tab.h")];
115 profile "build" 114 profile "build"
116 { 115 {
117 BASE = INPUT.replace(".y", ""); 116 BASE = INPUT.regex("\\.y", "");
118 execute("${BISON} -b${BASE} ${INPUT}"); 117 execute("${BISON} -b${BASE} ${INPUT}");
119 // if you add a -v bison will produce a .output file 118 // if you add a -v bison will produce a .output file
120 } 119 }
@@ -123,8 +122,8 @@ rule "bison"
123rule "flex" 122rule "flex"
124{ 123{
125 input "*.l"; 124 input "*.l";
126 output INPUT.replace(".l", ".yy.c"); 125 output INPUT.regex("\\.l$", ".yy.c");
127 output INPUT.replace(".l", ".yy.h"); 126 output INPUT.regex("\\.l$", ".yy.h");
128 profile "build" 127 profile "build"
129 { 128 {
130 execute("${FLEX} ${FLEXFLAGS} ${INPUT}"); 129 execute("${FLEX} ${FLEXFLAGS} ${INPUT}");
diff --git a/src/functionplugger.cpp b/src/functionplugger.cpp
index 83435ae..c8d3fd2 100644
--- a/src/functionplugger.cpp
+++ b/src/functionplugger.cpp
@@ -15,6 +15,7 @@ extern Bu::PluginInfo pluginFunctionReplace;
15extern Bu::PluginInfo pluginFunctionTargets; 15extern Bu::PluginInfo pluginFunctionTargets;
16extern Bu::PluginInfo pluginFunctionToString; 16extern Bu::PluginInfo pluginFunctionToString;
17extern Bu::PluginInfo pluginFunctionUnlink; 17extern Bu::PluginInfo pluginFunctionUnlink;
18extern Bu::PluginInfo pluginFunctionRegEx;
18 19
19FunctionPlugger::FunctionPlugger() 20FunctionPlugger::FunctionPlugger()
20{ 21{
@@ -30,6 +31,7 @@ FunctionPlugger::FunctionPlugger()
30 registerBuiltinPlugin( &pluginFunctionTargets ); 31 registerBuiltinPlugin( &pluginFunctionTargets );
31 registerBuiltinPlugin( &pluginFunctionToString ); 32 registerBuiltinPlugin( &pluginFunctionToString );
32 registerBuiltinPlugin( &pluginFunctionUnlink ); 33 registerBuiltinPlugin( &pluginFunctionUnlink );
34 registerBuiltinPlugin( &pluginFunctionRegEx );
33 35
34 DIR *dir = opendir("/usr/lib/build"); 36 DIR *dir = opendir("/usr/lib/build");
35 if( !dir ) 37 if( !dir )
diff --git a/src/functionregex.cpp b/src/functionregex.cpp
new file mode 100644
index 0000000..f0abc35
--- /dev/null
+++ b/src/functionregex.cpp
@@ -0,0 +1,126 @@
1#include "functionregex.h"
2
3#include <bu/regex.h>
4#include <bu/plugger.h>
5PluginInterface3( pluginFunctionRegEx, regex, FunctionRegEx, Function,
6 "Mike Buland", 0, 1 );
7
8FunctionRegEx::FunctionRegEx()
9{
10}
11
12FunctionRegEx::~FunctionRegEx()
13{
14}
15
16Bu::FString FunctionRegEx::getName() const
17{
18 return "regex";
19}
20
21Variable FunctionRegEx::call( Variable &input, VarList lParams )
22{
23 if( lParams.getSize() == 1 )
24 {
25 Bu::RegEx re( lParams.first().getString() );
26 switch( input.getType() )
27 {
28 case Variable::typeString:
29 return re.execute( input.getString() );
30
31 case Variable::typeList:
32 {
33 Variable vOut( Variable::typeList );
34 for( VarList::iterator i = input.begin(); i; i++ )
35 {
36 if( re.execute( (*i).toString() ) )
37 vOut.append( *i );
38 }
39 return vOut;
40 }
41 break;
42
43 default:
44 break;
45 }
46 }
47 else if( lParams.getSize() == 2 )
48 {
49 Bu::RegEx re( lParams.first().getString() );
50 Bu::FString sPat = lParams.last().getString();
51 switch( input.getType() )
52 {
53 case Variable::typeString:
54 if( re.execute( input.getString() ) )
55 {
56 return replace( re, input.getString(), sPat );
57 }
58 else
59 {
60 return input;
61 }
62 break;
63
64 case Variable::typeList:
65 {
66 Variable vOut( Variable::typeList );
67 for( VarList::iterator i = input.begin(); i; i++ )
68 {
69 if( re.execute( (*i).toString() ) )
70 vOut.append( replace( re, (*i).toString(), sPat ) );
71 else
72 vOut.append( *i );
73 }
74 return vOut;
75 }
76 break;
77
78 default:
79 break;
80 }
81 }
82 throw Bu::ExceptionBase(
83 "regex does not work on non-string or non-list types.");
84}
85
86Bu::FString FunctionRegEx::replace( Bu::RegEx &re, const Bu::FString &sSrc,
87 const Bu::FString &sPat )
88{
89 Bu::FString sOut;
90
91 int iStart, iEnd;
92 re.getSubStringRange( 0, iStart, iEnd ); // Get the range of the full match
93
94 if( iStart > 0 )
95 sOut.append( sSrc, 0, iStart );
96
97 for( Bu::FString::const_iterator i = sPat.begin(); i; i++ )
98 {
99 if( *i == '\\' )
100 {
101 i++;
102 if( *i <= '9' && *i >= '0' )
103 {
104 int iInd = *i-'0';
105 if( iInd < re.getNumSubStrings() )
106 sOut += re.getSubString( iInd );
107 }
108 else
109 {
110 sOut += *i;
111 }
112 }
113 else
114 {
115 sOut += *i;
116 }
117 }
118
119 if( iEnd < sSrc.getSize() )
120 {
121 sOut.append( sSrc, iEnd, -1 );
122 }
123
124 return sOut;
125}
126
diff --git a/src/functionregex.h b/src/functionregex.h
new file mode 100644
index 0000000..2096a64
--- /dev/null
+++ b/src/functionregex.h
@@ -0,0 +1,24 @@
1#ifndef FUNCTION_REG_EX_H
2#define FUNCTION_REG_EX_H
3
4#include "function.h"
5
6namespace Bu
7{
8 class RegEx;
9}
10
11class FunctionRegEx : public Function
12{
13public:
14 FunctionRegEx();
15 virtual ~FunctionRegEx();
16
17 virtual Bu::FString getName() const;
18 virtual Variable call( Variable &input, VarList lParams );
19
20 Bu::FString replace( Bu::RegEx &re, const Bu::FString &sSrc,
21 const Bu::FString &sPat );
22};
23
24#endif