diff options
-rwxr-xr-x | build.sh | 8 | ||||
-rw-r--r-- | share/autoinclude/general-rules.bld | 13 | ||||
-rw-r--r-- | src/functionplugger.cpp | 2 | ||||
-rw-r--r-- | src/functionregex.cpp | 126 | ||||
-rw-r--r-- | src/functionregex.h | 24 |
5 files changed, 162 insertions, 11 deletions
@@ -1,7 +1,7 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | BUSRC="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" | 3 | BUSRC="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" |
4 | BUHDR="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" | 4 | BUHDR="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 | ||
6 | function bld() | 6 | function bld() |
7 | { | 7 | { |
@@ -27,7 +27,7 @@ function cmd() | |||
27 | 27 | ||
28 | function gpp() | 28 | function 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 | ||
33 | if [ ! -z "$1" ]; then | 33 | if [ ! -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" |
66 | done | 66 | done |
67 | bld build src/*.o minibu/src/*.o || cmd LINK build g++ -o build src/*.o minibu/src/*.o -ldl | 67 | bld build src/*.o minibu/src/*.o || cmd LINK build g++ -fPIC -rdynamic -Wl,-export-dynamic -o build src/*.o minibu/src/*.o -ldl |
68 | bld build~ build || cmd CP build~ cp build build~ | 68 | bld 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 | ||
46 | function cToObj() | 46 | function 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 | ||
60 | rule "exe" | 60 | rule "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" | |||
111 | rule "bison" | 110 | rule "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" | |||
123 | rule "flex" | 122 | rule "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; | |||
15 | extern Bu::PluginInfo pluginFunctionTargets; | 15 | extern Bu::PluginInfo pluginFunctionTargets; |
16 | extern Bu::PluginInfo pluginFunctionToString; | 16 | extern Bu::PluginInfo pluginFunctionToString; |
17 | extern Bu::PluginInfo pluginFunctionUnlink; | 17 | extern Bu::PluginInfo pluginFunctionUnlink; |
18 | extern Bu::PluginInfo pluginFunctionRegEx; | ||
18 | 19 | ||
19 | FunctionPlugger::FunctionPlugger() | 20 | FunctionPlugger::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> | ||
5 | PluginInterface3( pluginFunctionRegEx, regex, FunctionRegEx, Function, | ||
6 | "Mike Buland", 0, 1 ); | ||
7 | |||
8 | FunctionRegEx::FunctionRegEx() | ||
9 | { | ||
10 | } | ||
11 | |||
12 | FunctionRegEx::~FunctionRegEx() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Bu::FString FunctionRegEx::getName() const | ||
17 | { | ||
18 | return "regex"; | ||
19 | } | ||
20 | |||
21 | Variable 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 | |||
86 | Bu::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 | |||
6 | namespace Bu | ||
7 | { | ||
8 | class RegEx; | ||
9 | } | ||
10 | |||
11 | class FunctionRegEx : public Function | ||
12 | { | ||
13 | public: | ||
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 | ||