Further de-PLIB-ification.
This commit is contained in:
parent
d8d3be6fb1
commit
881d83d245
4 changed files with 82 additions and 116 deletions
|
@ -4,7 +4,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src/Lib)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles)
|
include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles)
|
||||||
|
|
||||||
add_subdirectory(Osgb36)
|
add_subdirectory(Osgb36)
|
||||||
#add_subdirectory(Parallel)
|
add_subdirectory(Parallel)
|
||||||
add_subdirectory(Triangulate)
|
add_subdirectory(Triangulate)
|
||||||
add_subdirectory(Clipper)
|
add_subdirectory(Clipper)
|
||||||
add_subdirectory(GenOutput)
|
add_subdirectory(GenOutput)
|
||||||
|
|
|
@ -41,15 +41,17 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <simgear/bucket/newbucket.hxx>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#include <plib/ul.h>
|
#include <simgear/bucket/newbucket.hxx>
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
|
#include <simgear/misc/strutils.hxx>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
|
|
||||||
#define MAXBUF 1024
|
#define MAXBUF 1024
|
||||||
#define BUSY_WAIT_TIME 30
|
#define BUSY_WAIT_TIME 30
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ void check_master_switch() {
|
||||||
// check if the host system is free of interactive users
|
// check if the host system is free of interactive users
|
||||||
int system_free() {
|
int system_free() {
|
||||||
|
|
||||||
#if !defined(BSD) && !defined(__CYGWIN__) && !defined(_MSC_VER)
|
#if !defined(BSD) && !defined(__CYGWIN__) && !defined(_MSC_VER) && !defined(__APPLE__)
|
||||||
struct utmp *uptr;
|
struct utmp *uptr;
|
||||||
|
|
||||||
setutent();
|
setutent();
|
||||||
|
@ -189,88 +191,68 @@ long int get_next_task( const string& host, int port, long int last_tile ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool endswith(const char* s, const char* suffix) {
|
|
||||||
size_t slen=strlen(s);
|
|
||||||
size_t sufflen=strlen(suffix);
|
|
||||||
if (slen<sufflen)
|
|
||||||
return false;
|
|
||||||
return (strncmp(s+slen-sufflen,suffix,sufflen)==0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the tile really has to be generated
|
// check if the tile really has to be generated
|
||||||
static bool must_generate( const SGBucket& b ) {
|
static bool must_generate( const SGBucket& b ) {
|
||||||
if (do_overwrite)
|
if (do_overwrite)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
string btg_file = output_base + "/" + b.gen_base_path()
|
SGPath btg_file(output_base + "/" + b.gen_base_path()
|
||||||
+ "/" + b.gen_index_str() + ".btg.gz";
|
+ "/" + b.gen_index_str() + ".btg.gz");
|
||||||
string stg_file = output_base + "/" + b.gen_base_path()
|
SGPath stg_file (output_base + "/" + b.gen_base_path()
|
||||||
+ "/" + b.gen_index_str() + ".stg";
|
+ "/" + b.gen_index_str() + ".stg");
|
||||||
struct stat btg_stat, stg_stat;
|
|
||||||
bool have_btg, have_stg;
|
|
||||||
|
if ( !btg_file.exists() ) {
|
||||||
have_btg= ( stat( btg_file.c_str(), &btg_stat ) == 0 );
|
cout << "Output file " << btg_file.str() << " was not found\n";
|
||||||
have_stg = ( stat( stg_file.c_str(), &stg_stat ) == 0 );
|
|
||||||
|
|
||||||
if ( !have_btg ) {
|
|
||||||
cout << "Output file " << btg_file << " was not found\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !have_stg ) {
|
if ( !stg_file.exists() ) {
|
||||||
cout << "Output file " << stg_file << " was not found\n";
|
cout << "Output file " << stg_file.str() << " was not found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now check the load dirs for any source data and
|
/* Now check the load dirs for any source data and
|
||||||
* whether any of that is newer than the btg-file or the stg-file
|
* whether any of that is newer than the btg-file or the stg-file
|
||||||
*/
|
*/
|
||||||
const string& prefix=b.gen_index_str()+".";
|
const string prefix=b.gen_index_str()+".";
|
||||||
size_t prefix_len=prefix.size();
|
|
||||||
for (int i = 0; i < (int)load_dirs.size(); i++) {
|
for (int i = 0; i < (int)load_dirs.size(); i++) {
|
||||||
string path=load_dirs[i]+"/"+b.gen_base_path();
|
SGPath path(load_dirs[i]+"/"+b.gen_base_path());
|
||||||
ulDir *loaddir=ulOpenDir(path.c_str());
|
simgear::Dir loadDir(path);
|
||||||
if (!loaddir) {
|
if (!loadDir.exists()) {
|
||||||
if (errno!=ENOENT)
|
cout << " Could not open load directory " << path.str() << ":" << strerror(errno) << "\n";
|
||||||
cout << " Could not open load directory " << path << ":" << strerror(errno) << "\n";
|
continue;
|
||||||
continue;
|
}
|
||||||
|
|
||||||
|
BOOST_FOREACH(const SGPath& c, loadDir.children(simgear::Dir::TYPE_FILE)) {
|
||||||
|
if (!simgear::strutils::starts_with(c.file(), prefix)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ulDirEnt* de;
|
if (btg_file.exists() && (btg_file.modTime() < c.modTime())) {
|
||||||
struct stat src_stat;
|
cout << " File " << c.str() << " is newer than btg-file => rebuild\n";
|
||||||
|
return true;
|
||||||
while ((de=ulReadDir(loaddir))) {
|
|
||||||
if (strncmp(de->d_name,prefix.c_str(),prefix_len))
|
|
||||||
continue;
|
|
||||||
string file=path+"/"+de->d_name;
|
|
||||||
if ( stat(file.c_str(), &src_stat) != 0) {
|
|
||||||
/* huh!? */
|
|
||||||
cerr << " Could not stat file " << file << ":" << strerror(errno) << "\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( have_btg && src_stat.st_mtime>btg_stat.st_mtime ) {
|
|
||||||
cout << " File " << file << " is newer than btg-file => rebuild\n";
|
|
||||||
ulCloseDir(loaddir);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if ( have_stg && src_stat.st_mtime>stg_stat.st_mtime ) {
|
|
||||||
cout << " File " << file << " is newer than stg-file => rebuild\n";
|
|
||||||
ulCloseDir(loaddir);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/* Ignore elevation data, as it is not used if we have no
|
|
||||||
* landmass data. So in addition to elevation data we need at
|
|
||||||
* least one polygon file.
|
|
||||||
*/
|
|
||||||
if ( endswith( de->d_name, ".arr.gz" ) || endswith( de->d_name, ".fit.gz" ) )
|
|
||||||
continue;
|
|
||||||
if ( !(have_stg && have_btg) ) {
|
|
||||||
cout << " There is source-data (" << file << ") for tile " << b.gen_index_str() << " but .btg or .stg is missing => build\n";
|
|
||||||
ulCloseDir(loaddir);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ulCloseDir(loaddir);
|
if (stg_file.exists() && (stg_file.modTime() < c.modTime())) {
|
||||||
}
|
cout << " File " << c.str() << " is newer than stg-file => rebuild\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ignore elevation data, as it is not used if we have no
|
||||||
|
* landmass data. So in addition to elevation data we need at
|
||||||
|
* least one polygon file.
|
||||||
|
*/
|
||||||
|
string lext = c.complete_lower_extension();
|
||||||
|
if ((lext == "arr.gz") || (lext == "fit.gz")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !(stg_file.exists() && btg_file.exists()) ) {
|
||||||
|
cout << " There is source-data (" << c.str() << ") for tile " << b.gen_index_str() << " but .btg or .stg is missing => build\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // of load-dir child iteration
|
||||||
|
|
||||||
|
} // of load dirs iteration
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,4 @@ include_directories(${PROJECT_SOURCE_DIR}/src/Lib)
|
||||||
# seems unfortunate that lib depends on other dirs
|
# seems unfortunate that lib depends on other dirs
|
||||||
#include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles)
|
#include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles)
|
||||||
|
|
||||||
#add_subdirectory(poly2ogr)
|
add_subdirectory(poly2ogr)
|
||||||
|
|
|
@ -35,12 +35,14 @@
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/io/sg_binobj.hxx>
|
#include <simgear/io/sg_binobj.hxx>
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/misc/sgstream.hxx>
|
#include <simgear/misc/sgstream.hxx>
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <plib/ul.h>
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
|
|
||||||
#include <Polygon/polygon.hxx>
|
#include <Polygon/polygon.hxx>
|
||||||
#include <Polygon/point2d.hxx>
|
#include <Polygon/point2d.hxx>
|
||||||
|
@ -411,49 +413,31 @@ void process_points_file(const std::string& path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_file(const std::string& path) {
|
void process_file(const SGPath& path)
|
||||||
struct stat sbuf;
|
{
|
||||||
|
if (path.isDir()) {
|
||||||
if ( stat(path.c_str(),&sbuf) != 0 ) {
|
// recurse downwards!
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to stat path '" << path << "'");
|
simgear::Dir d(path);
|
||||||
return;
|
int flags = simgear::Dir::TYPE_FILE | simgear::Dir::TYPE_DIR |
|
||||||
}
|
simgear::Dir::NO_DOT_OR_DOTDOT;
|
||||||
|
BOOST_FOREACH(const SGPath& c, d.children(flags)) {
|
||||||
if (S_ISDIR(sbuf.st_mode)) {
|
process_file(c);
|
||||||
ulDir* dir;
|
|
||||||
|
|
||||||
dir=ulOpenDir(path.c_str());
|
|
||||||
if (!dir) {
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to open directory '" << path << "'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ulDirEnt *de;
|
|
||||||
|
|
||||||
while ((de=ulReadDir(dir))) {
|
|
||||||
if (!strcmp(de->d_name,".") || !strcmp(de->d_name,"..")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string subpath=path+"/"+de->d_name;
|
|
||||||
process_file(subpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
ulCloseDir(dir);
|
|
||||||
} else if (endswith(path,".pts")) {
|
|
||||||
// This is a points file
|
|
||||||
process_points_file(path);
|
|
||||||
} else if (endswith(path,".btg.gz") || endswith(path,".btg")) {
|
|
||||||
// This is a scenery file
|
|
||||||
process_scenery_file(path);
|
|
||||||
} else if (!endswith(path,".gz") &&
|
|
||||||
!endswith(path,".arr") &&
|
|
||||||
!endswith(path,".fit") &&
|
|
||||||
!endswith(path,".stg") &&
|
|
||||||
!endswith(path,".ind")) {
|
|
||||||
// should be a polygon file
|
|
||||||
process_polygon_file(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string lext = path.complete_lower_extension();
|
||||||
|
if (lext == "pts") {
|
||||||
|
process_points_file(path.str());
|
||||||
|
} else if ((lext == "btg.gz") || (lext == "btg")) {
|
||||||
|
process_scenery_file(path.str());
|
||||||
|
} else if ((lext != "gz") && (lext != "arr") && (lext != "fit") &&
|
||||||
|
(lext != "stg") && (lext != "ind"))
|
||||||
|
{
|
||||||
|
// should be a polygon file
|
||||||
|
process_polygon_file(path.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(const char* progname, const std::string& msg) {
|
void usage(const char* progname, const std::string& msg) {
|
||||||
|
@ -553,7 +537,7 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=optind;i<argc;i++) {
|
for (int i=optind;i<argc;i++) {
|
||||||
process_file(argv[i]);
|
process_file(SGPath(argv[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
OGRDataSource::DestroyDataSource( datasource );
|
OGRDataSource::DestroyDataSource( datasource );
|
||||||
|
|
Loading…
Reference in a new issue