aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docs/build.74
-rw-r--r--share/autoinclude/general-rules.bld3
-rw-r--r--src/functionplugger.cpp2
-rw-r--r--src/functionunique.cpp47
-rw-r--r--src/functionunique.h16
-rw-r--r--support/vim/syntax/build.vim2
6 files changed, 73 insertions, 1 deletions
diff --git a/docs/build.7 b/docs/build.7
index b9099de..77b9f85 100644
--- a/docs/build.7
+++ b/docs/build.7
@@ -93,6 +93,10 @@ Takes a file handle as it's input, and takes an integer as it's parameter. The
93.B 93.B
94close() 94close()
95Takes a file handle as it's input, and no parameters. Closes the file indicated by the handle provided as input. While it is reccomended to close all files as soon as you are done with them, any files left open will be closed automatically and safely before build exists. 95Takes a file handle as it's input, and no parameters. Closes the file indicated by the handle provided as input. While it is reccomended to close all files as soon as you are done with them, any files left open will be closed automatically and safely before build exists.
96.TP
97.B
98unique()
99At the moment only works on lists of strings. It will return the input string in the same order, with all duplicate entries removed. It will also remove any non-strings in the list at the moment.
96.P 100.P
97Here, lets list functions we wish we had... 101Here, lets list functions we wish we had...
98.SH ENVIRONMENT 102.SH ENVIRONMENT
diff --git a/share/autoinclude/general-rules.bld b/share/autoinclude/general-rules.bld
index cdc2d40..6c0df30 100644
--- a/share/autoinclude/general-rules.bld
+++ b/share/autoinclude/general-rules.bld
@@ -60,6 +60,7 @@ rule "exe"
60 input "*.o"; 60 input "*.o";
61 profile "build" 61 profile "build"
62 { 62 {
63 INPUT = [INPUT].unique().matches("*.o");
63 execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); 64 execute("${CXX} -o ${OUTPUT} ${INPUT} ${LDFLAGS}");
64 } 65 }
65} 66}
@@ -69,6 +70,7 @@ rule "so"
69 input "*.o"; 70 input "*.o";
70 profile "build" 71 profile "build"
71 { 72 {
73 INPUT = [INPUT].unique().matches("*.o");
72 execute("${CXX} -shared -o ${OUTPUT} ${INPUT} ${LDFLAGS}"); 74 execute("${CXX} -shared -o ${OUTPUT} ${INPUT} ${LDFLAGS}");
73 } 75 }
74} 76}
@@ -78,6 +80,7 @@ rule "lib"
78 input "*.o"; 80 input "*.o";
79 profile "build" 81 profile "build"
80 { 82 {
83 INPUT = [INPUT].unique().matches("*.o");
81 execute("${AR} cr ${OUTPUT} ${INPUT}"); 84 execute("${AR} cr ${OUTPUT} ${INPUT}");
82 } 85 }
83} 86}
diff --git a/src/functionplugger.cpp b/src/functionplugger.cpp
index 8bd2edd..1f2bcf5 100644
--- a/src/functionplugger.cpp
+++ b/src/functionplugger.cpp
@@ -21,6 +21,7 @@ extern Bu::PluginInfo pluginFunctionOpen;
21extern Bu::PluginInfo pluginFunctionClose; 21extern Bu::PluginInfo pluginFunctionClose;
22extern Bu::PluginInfo pluginFunctionRead; 22extern Bu::PluginInfo pluginFunctionRead;
23extern Bu::PluginInfo pluginFunctionWrite; 23extern Bu::PluginInfo pluginFunctionWrite;
24extern Bu::PluginInfo pluginFunctionUnique;
24 25
25FunctionPlugger::FunctionPlugger() 26FunctionPlugger::FunctionPlugger()
26{ 27{
@@ -42,6 +43,7 @@ FunctionPlugger::FunctionPlugger()
42 registerBuiltinPlugin( &pluginFunctionClose ); 43 registerBuiltinPlugin( &pluginFunctionClose );
43 registerBuiltinPlugin( &pluginFunctionRead ); 44 registerBuiltinPlugin( &pluginFunctionRead );
44 registerBuiltinPlugin( &pluginFunctionWrite ); 45 registerBuiltinPlugin( &pluginFunctionWrite );
46 registerBuiltinPlugin( &pluginFunctionUnique );
45 47
46 DIR *dir = opendir("/usr/lib/build"); 48 DIR *dir = opendir("/usr/lib/build");
47 if( !dir ) 49 if( !dir )
diff --git a/src/functionunique.cpp b/src/functionunique.cpp
new file mode 100644
index 0000000..ca2461f
--- /dev/null
+++ b/src/functionunique.cpp
@@ -0,0 +1,47 @@
1#include "functionunique.h"
2
3#include <bu/hash.h>
4#include <bu/plugger.h>
5PluginInterface3( pluginFunctionUnique, unique, FunctionUnique, Function,
6 "Mike Buland", 0, 1 );
7
8FunctionUnique::FunctionUnique()
9{
10}
11
12FunctionUnique::~FunctionUnique()
13{
14}
15
16Bu::String FunctionUnique::getName() const
17{
18 return "unique";
19}
20
21Variable FunctionUnique::call( Variable &input, VarList lParams )
22{
23 if( lParams.getSize() > 0 )
24 throw Bu::ExceptionBase("Unique does not take any parameters.");
25 if( input.getType() != Variable::typeList )
26 throw Bu::ExceptionBase("unique does not work on non-list types.");
27
28 Bu::Hash<Bu::String, bool> hHas;
29
30 Variable vOut( Variable::typeList );
31 for( VarList::iterator i = input.begin(); i; i++ )
32 {
33 if( (*i).getType() != Variable::typeString )
34 continue;
35
36 Bu::String s = (*i).getString();
37
38 if( hHas.has( s ) )
39 continue;
40
41 hHas.insert( s, true );
42 vOut.append( *i );
43 }
44
45 return vOut;
46}
47
diff --git a/src/functionunique.h b/src/functionunique.h
new file mode 100644
index 0000000..6bc4225
--- /dev/null
+++ b/src/functionunique.h
@@ -0,0 +1,16 @@
1#ifndef FUNCTION_UNIQUE_H
2#define FUNCTION_UNIQUE_H
3
4#include "function.h"
5
6class FunctionUnique : public Function
7{
8public:
9 FunctionUnique();
10 virtual ~FunctionUnique();
11
12 virtual Bu::String getName() const;
13 virtual Variable call( Variable &input, VarList lParams );
14};
15
16#endif
diff --git a/support/vim/syntax/build.vim b/support/vim/syntax/build.vim
index 721cfd4..04d1f90 100644
--- a/support/vim/syntax/build.vim
+++ b/support/vim/syntax/build.vim
@@ -19,7 +19,7 @@ syn keyword Statement include set unset function target input condition requir
19syn keyword Todo TODO FIXME XXX 19syn keyword Todo TODO FIXME XXX
20syn keyword Type int string bool float version 20syn keyword Type int string bool float version
21syn keyword Constant null true false file never always important normal hidden autogenerated filetime 21syn keyword Constant null true false file never always important normal hidden autogenerated filetime
22syn keyword Builtins files dirs matches replace regex execute unlink exists getMakeDeps toString targets fileName dirName 22syn keyword Builtins files dirs matches replace regex execute unlink exists getMakeDeps toString targets fileName dirName unique
23 23
24syn match TargetProcess /[a-zA-Z_][a-zA-Z0-9_]*:/he=e-1 24syn match TargetProcess /[a-zA-Z_][a-zA-Z0-9_]*:/he=e-1
25 25