aboutsummaryrefslogtreecommitdiff
path: root/src/functionfiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/functionfiles.cpp')
-rw-r--r--src/functionfiles.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/functionfiles.cpp b/src/functionfiles.cpp
new file mode 100644
index 0000000..e708d45
--- /dev/null
+++ b/src/functionfiles.cpp
@@ -0,0 +1,61 @@
1#include "functionfiles.h"
2
3#include <sys/types.h>
4#include <sys/stat.h>
5#include <glob.h>
6#include <unistd.h>
7
8FunctionFiles::FunctionFiles()
9{
10}
11
12FunctionFiles::~FunctionFiles()
13{
14}
15
16Bu::FString FunctionFiles::getName() const
17{
18 return "files";
19}
20
21Variable FunctionFiles::call( Variable &/*input*/, VarList lParams )
22{
23 glob_t globbuf;
24
25 int flags = 0;
26
27 for( VarList::const_iterator i = lParams.begin(); i; i++ )
28 {
29 switch( (*i).getType() )
30 {
31 case Variable::typeString:
32 glob( (*i).getString().getStr(), flags, NULL, &globbuf );
33 flags |= GLOB_APPEND;
34 break;
35
36 case Variable::typeList:
37 throw Bu::ExceptionBase("Lists not supported in glob yet.");
38 break;
39
40 default:
41 throw Bu::ExceptionBase(
42 "Cannot use a non-string or non-list as a parameter to glob"
43 );
44 break;
45 }
46 }
47
48 Variable vRet( Variable::typeList );
49 struct stat s;
50 for( size_t j = 0; j < globbuf.gl_pathc; j++ )
51 {
52 stat( globbuf.gl_pathv[j], &s );
53 if( S_ISREG( s.st_mode ) )
54 vRet.append( globbuf.gl_pathv[j] );
55 }
56
57 globfree( &globbuf );
58
59 return vRet;
60}
61