From fb28f6800864176be2ffca29e8e664b641f33170 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 21 Dec 2009 18:04:02 +0000 Subject: m3 is copied into trunk, we should be good to go, now. --- src/functiondirs.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/functiondirs.cpp (limited to 'src/functiondirs.cpp') diff --git a/src/functiondirs.cpp b/src/functiondirs.cpp new file mode 100644 index 0000000..fb64ef3 --- /dev/null +++ b/src/functiondirs.cpp @@ -0,0 +1,61 @@ +#include "functiondirs.h" + +#include +#include +#include +#include + +FunctionDirs::FunctionDirs() +{ +} + +FunctionDirs::~FunctionDirs() +{ +} + +Bu::FString FunctionDirs::getName() const +{ + return "dirs"; +} + +Variable FunctionDirs::call( Variable &/*input*/, VarList lParams ) +{ + glob_t globbuf; + + int flags = 0; + + for( VarList::const_iterator i = lParams.begin(); i; i++ ) + { + switch( (*i).getType() ) + { + case Variable::typeString: + glob( (*i).getString().getStr(), flags, NULL, &globbuf ); + flags |= GLOB_APPEND; + break; + + case Variable::typeList: + throw Bu::ExceptionBase("Lists not supported in glob yet."); + break; + + default: + throw Bu::ExceptionBase( + "Cannot use a non-string or non-list as a parameter to glob" + ); + break; + } + } + + Variable vRet( Variable::typeList ); + struct stat s; + for( size_t j = 0; j < globbuf.gl_pathc; j++ ) + { + stat( globbuf.gl_pathv[j], &s ); + if( S_ISDIR( s.st_mode ) ) + vRet.append( globbuf.gl_pathv[j] ); + } + + globfree( &globbuf ); + + return vRet; +} + -- cgit v1.2.3