1
0
Fork 0

Honour --work-dir option and use portable code to iterate through directories

This commit is contained in:
Frederic Bouvier 2009-03-21 11:26:48 +01:00
parent edf9447389
commit 4d59fad336

View file

@ -160,55 +160,16 @@ static int actual_load_polys( const string& dir,
string file, f_index, full_path; string file, f_index, full_path;
int pos; int pos;
#ifdef _MSC_VER ulDir *d;
long hfile; struct ulDirEnt *de;
struct _finddata_t de;
string path;
path = dir + "/*.*"; if ( (d = ulOpenDir( dir.c_str() )) == NULL ) {
if ( ( hfile = _findfirst( path.c_str(), &de ) ) == -1 ) {
cout << "cannot open directory " << dir << "\n"; cout << "cannot open directory " << dir << "\n";
return 0; return 0;
} }
// load all matching polygon files // load all matching polygon files
do { while ( (de = ulReadDir(d)) != NULL ) {
file = de.name;
pos = file.find(".");
f_index = file.substr(0, pos);
if ( tile_str == f_index ) {
ext = file.substr(pos + 1);
cout << file << " " << f_index << " '" << ext << "'" << endl;
full_path = dir + "/" + file;
if ( (ext == "arr") || (ext == "arr.gz") ||
(ext == "fit") || (ext == "fit.gz")) {
// skip
} else if (ext == "osgb36") {
cout << "Loading osgb36 poly definition file\n";
clipper.load_osgb36_polys( full_path );
++counter;
} else {
cout << "ext = '" << ext << "'" << endl;
clipper.load_polys( full_path );
++counter;
}
}
} while ( _findnext( hfile, &de ) == 0 );
#else
DIR *d;
struct dirent *de;
if ( (d = opendir( dir.c_str() )) == NULL ) {
cout << "cannot open directory " << dir << "\n";
return 0;
}
// load all matching polygon files
while ( (de = readdir(d)) != NULL ) {
file = de->d_name; file = de->d_name;
pos = file.find("."); pos = file.find(".");
f_index = file.substr(0, pos); f_index = file.substr(0, pos);
@ -232,8 +193,7 @@ static int actual_load_polys( const string& dir,
} }
} }
closedir(d); ulCloseDir(d);
#endif
return counter; return counter;
} }
@ -448,7 +408,7 @@ static int load_polys( TGConstruct& c, const TGArray &array ) {
// load 2D polygons from all directories provided // load 2D polygons from all directories provided
for ( i = 0; i < (int)load_dirs.size(); ++i ) { for ( i = 0; i < (int)load_dirs.size(); ++i ) {
poly_path = load_dirs[i] + '/' + base; poly_path = c.get_work_base() + "/" + load_dirs[i] + '/' + base;
cout << "poly_path = " << poly_path << endl; cout << "poly_path = " << poly_path << endl;
count += actual_load_polys( poly_path, c, clipper ); count += actual_load_polys( poly_path, c, clipper );
cout << " loaded " << count << " total polys" << endl; cout << " loaded " << count << " total polys" << endl;
@ -484,7 +444,7 @@ static bool load_array( TGConstruct& c, TGArray& array) {
int i; int i;
for ( i = 0; i < (int)load_dirs.size(); ++i ) { for ( i = 0; i < (int)load_dirs.size(); ++i ) {
string array_path = load_dirs[i] + "/" + base string array_path = c.get_work_base() + "/" + load_dirs[i] + "/" + base
+ "/" + c.get_bucket().gen_index_str(); + "/" + c.get_bucket().gen_index_str();
cout << "array_path = " << array_path << endl; cout << "array_path = " << array_path << endl;