blob: 771d77a4ce3a2cc486ae3c0ddf8065a2bde77c66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#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()
{
cout << "test program begins" << endl;
char* pXlsInDir = getenv("CTRL_XLS_IN_DIR");
if (!pXlsInDir)
return EXIT_FAILURE;
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
{
xDesktop->terminate();
}
catch (const DisposedException&)
{
info("terminate has been called, but the desktop instance has already been disposed of.");
}
}
|