diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2009-12-29 11:38:01 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2009-12-29 11:38:01 -0500 |
commit | cfcb5a25dec927279a739d53884058b9221bcb49 (patch) | |
tree | e983d1b1ebf726f9872df77e5d6c0ddb0e11f3ef | |
parent | 90c372a96486e1a778368b0631f4979057f9ed56 (diff) |
Read a list of files from the "in" directory.
-rw-r--r-- | inc/global.hxx | 5 | ||||
-rw-r--r-- | source/global.cxx | 7 | ||||
-rw-r--r-- | source/main.cxx | 73 |
3 files changed, 81 insertions, 4 deletions
diff --git a/inc/global.hxx b/inc/global.hxx index 6b38895..fbb780f 100644 --- a/inc/global.hxx +++ b/inc/global.hxx @@ -4,12 +4,15 @@ #include <com/sun/star/frame/XDesktop.hpp> +#include <string> + namespace test { ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDesktop > bootstrap(); -void info(const char* msg); +void info(const ::std::string& msg); +void error(const ::std::string& msg); } diff --git a/source/global.cxx b/source/global.cxx index f41c81b..4a9f1e2 100644 --- a/source/global.cxx +++ b/source/global.cxx @@ -39,9 +39,14 @@ Reference<XDesktop> bootstrap() return xDesktop; } -void info(const char* msg) +void info(const string& msg) { cout << "info: " << msg << endl; } +void error(const string& msg) +{ + cerr << "error: " << msg << endl; +} + } diff --git a/source/main.cxx b/source/main.cxx index d400167..771d77a 100644 --- a/source/main.cxx +++ b/source/main.cxx @@ -1,14 +1,76 @@ #include "global.hxx" + #include <iostream> #include <cstdlib> +#include <string> +#include <vector> +#include <algorithm> + +#include <dirent.h> +#include <sys/stat.h> #include <com/sun/star/lang/DisposedException.hpp> using ::com::sun::star::uno::Reference; using ::com::sun::star::frame::XDesktop; using ::com::sun::star::lang::DisposedException; +using ::rtl::OUString; using namespace std; +using namespace test; + +bool getImportDocuments(const string& inpath, vector<OUString>& rFilePaths) +{ + struct stat statbuf; + if (lstat(inpath.c_str(), &statbuf) < 0) + { + error("lstat failed on " + inpath); + return false; + } + + if (!S_ISDIR(statbuf.st_mode)) + { + error(inpath + " is not a directory."); + return false; + } + + cout << "control xls inport directory: " << inpath << endl; + + DIR* dp; + struct dirent* dirp; + if ((dp = opendir(inpath.c_str())) == NULL) + { + error("failed to open " + inpath); + return false; + } + + vector<OUString> aFilePaths; + while ((dirp = readdir(dp)) != NULL) + { + string aFileName = dirp->d_name; // does Linux still have 256 char file name limit ? + if (aFileName == "." || aFileName == "..") + continue; + + string aFilePath = inpath + "/" + aFileName; + OUString aOUPath(aFilePath.c_str(), aFilePath.size(), RTL_TEXTENCODING_UTF8); + aFilePaths.push_back(aOUPath); + } + + rFilePaths.swap(aFilePaths); + return true; +} + +namespace { + +struct PrintFilePath : public ::std::unary_function<void, OUString> +{ + void operator() (const OUString& r) const + { + cout << rtl::OUStringToOString(r, RTL_TEXTENCODING_UTF8).getStr() << endl; + } +}; + +} int main() { @@ -17,7 +79,14 @@ int main() if (!pXlsInDir) return EXIT_FAILURE; - cout << "control xls inport directory: " << pXlsInDir << endl; + string aXclImportPath(pXlsInDir); + vector<OUString> aFilePaths; + if (!getImportDocuments(aXclImportPath, aFilePaths)) + return EXIT_FAILURE; + + for_each(aFilePaths.begin(), aFilePaths.end(), PrintFilePath()); + + return EXIT_SUCCESS; Reference<XDesktop> xDesktop = ::test::bootstrap(); try @@ -26,6 +95,6 @@ int main() } catch (const DisposedException&) { - ::test::info("terminate has been called, but the desktop instance has already been disposed of."); + info("terminate has been called, but the desktop instance has already been disposed of."); } } |