From 28ded05fc227b55d00223a979468a2334367965a Mon Sep 17 00:00:00 2001 From: Crystalline Emerald Date: Fri, 1 May 2015 19:00:52 +0300 Subject: [PATCH 1/2] Lots of fixes to enable builds on ubuntu 14.04 LTS, boost filesystem update, writedocs.pl fixes --- CMakeLists.txt | 14 ++++++------- parsedocs.pl | 18 ++++++++++++---- src/AudioBackend.h | 30 +++++++++------------------ src/Catalogue.cpp | 4 ++-- src/Engine.cpp | 28 ++++++++++++------------- src/PathResolver.cpp | 19 +++++++++-------- src/World.cpp | 16 +++++++------- src/backends/qtgui/AgentInjector.cpp | 12 +++++------ src/caos/caosVM_core.cpp | 2 +- src/caos/caosVM_files.cpp | 2 +- src/caos/caosVM_resources.cpp | 10 ++++----- src/caosScript.cpp | 1 + src/cobFile.cpp | 6 +++--- src/imageManager.cpp | 31 ++++++++++++++-------------- src/peFile.cpp | 10 ++++----- src/pray.cpp | 6 +++--- src/prayManager.cpp | 6 +++--- src/tools/praydumper.cpp | 2 +- 18 files changed, 110 insertions(+), 107 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 350f807e..ee2932e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ ENDIF(OPENC2E_USE_OPENAL MATCHES "^(YES|AUTO)$") FIND_PACKAGE(ALUT) FIND_PACKAGE(Boost 1.34.0 COMPONENTS program_options filesystem thread regex serialization REQUIRED) -FIND_LIBRARY(BOOST_SYSTEM_LIBRARY NAMES boost_system-mt) +FIND_LIBRARY(BOOST_SYSTEM_LIBRARY NAMES boost_system) IF(OPENC2E_USE_QT) find_package(Qt4 REQUIRED) ENDIF(OPENC2E_USE_QT) @@ -267,14 +267,14 @@ TARGET_LINK_LIBRARIES(openc2e z m pthread ${OPENAL_LIBRARY} ${ALUT_LIBRARY} ${FRONTEND_LIBS} - boost_program_options-mt - boost_serialization-mt - boost_filesystem-mt - boost_thread-mt - boost_regex-mt + boost_program_options + boost_serialization + boost_filesystem + boost_thread + boost_regex ) IF(BOOST_SYSTEM_LIBRARY) -TARGET_LINK_LIBRARIES(openc2e boost_system-mt) +TARGET_LINK_LIBRARIES(openc2e boost_system) ENDIF(BOOST_SYSTEM_LIBRARY) LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) diff --git a/parsedocs.pl b/parsedocs.pl index a71e0bee..131a54f2 100755 --- a/parsedocs.pl +++ b/parsedocs.pl @@ -176,11 +176,21 @@ } if (!$cat) { - $cat = lc $fnmap{$file} || 'unknown'; + if ($fnmap{$file}) { + $cat = lc $fnmap{$file}; + } else { + $cat = lc 'unknown'; + } } - - $stackdelta = $pragma{stackdelta} if defined $pragma{stackdelta}; - $stackdelta = "INT_MAX" if lc $pragma{stackdelta} eq "any"; + + if (defined $pragma{stackdelta}) { + $stackdelta = $pragma{stackdelta}; + } + + if (defined $pragma{stackdelta} && lc $pragma{stackdelta} eq "any") { + $stackdelta = "INT_MAX"; + } + die "Deprecated use of pragma retc for $fullname" if defined $pragma{retc}; diff --git a/src/AudioBackend.h b/src/AudioBackend.h index 0d45ad34..a830639a 100644 --- a/src/AudioBackend.h +++ b/src/AudioBackend.h @@ -28,34 +28,24 @@ class AudioBuffer; -namespace boost { - static inline void intrusive_ptr_add_ref(AudioBuffer *p); - static inline void intrusive_ptr_release(AudioBuffer *p); -} - class AudioBuffer { - friend void boost::intrusive_ptr_add_ref(AudioBuffer *p); - friend void boost::intrusive_ptr_release(AudioBuffer *p); - -protected: - virtual void add_ref() = 0; - virtual void del_ref() = 0; - + + friend void intrusive_ptr_add_ref(AudioBuffer *p) { + p->add_ref(); + } + friend void intrusive_ptr_release(AudioBuffer *p) { + p->del_ref(); + } + public: virtual ~AudioBuffer() { } virtual unsigned int length_ms() const = 0; /* milliseconds */ virtual unsigned int length_samples() const = 0; + virtual void add_ref() = 0; + virtual void del_ref() = 0; }; typedef boost::intrusive_ptr AudioClip; -namespace boost { - static inline void intrusive_ptr_add_ref(AudioBuffer *p) { - p->add_ref(); - } - static inline void intrusive_ptr_release(AudioBuffer *p) { - p->del_ref(); - } -} /* Base class for sources of streaming data (eg, MNG music) * diff --git a/src/Catalogue.cpp b/src/Catalogue.cpp index d8ce3ed4..30ae303e 100644 --- a/src/Catalogue.cpp +++ b/src/Catalogue.cpp @@ -130,7 +130,7 @@ void Catalogue::initFrom(fs::path path) { assert(fs::exists(path)); assert(fs::is_directory(path)); - //std::cout << "Catalogue is reading " << path.native_directory_string() << std::endl; + //std::cout << "Catalogue is reading " << path.string() << std::endl; fs::directory_iterator end; std::string file; @@ -148,7 +148,7 @@ void Catalogue::initFrom(fs::path path) { } } catch (const std::exception &ex) { - std::cerr << "directory_iterator died on '" << i->path().leaf() << "' with " << ex.what() << std::endl; + std::cerr << "directory_iterator died on '" << i->path().filename().string() << "' with " << ex.what() << std::endl; } } } diff --git a/src/Engine.cpp b/src/Engine.cpp index e23466f8..56cca42f 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -107,7 +107,7 @@ void Engine::loadGameData() { if (fs::exists(palpath) && !fs::is_directory(palpath)) { palette = new unsigned char[768]; - std::ifstream f(palpath.native_directory_string().c_str(), std::ios::binary); + std::ifstream f(palpath.string().c_str(), std::ios::binary); f >> std::noskipws; f.read((char *)palette, 768); @@ -624,7 +624,7 @@ bool Engine::parseCommandLine(int argc, char *argv[]) { // add all the data directories to the list for (std::vector::iterator i = data_vec.begin(); i != data_vec.end(); i++) { - fs::path datadir(*i, fs::native); + fs::path datadir(*i); if (!fs::exists(datadir)) { throw creaturesException("data path '" + *i + "' doesn't exist"); } @@ -746,11 +746,11 @@ bool Engine::initialSetup() { // inform the user of the port used, and store it in the relevant file std::cout << "Listening for connections on port " << listenport << "." << std::endl; #ifndef _WIN32 - fs::path p = fs::path(homeDirectory().native_directory_string() + "/.creaturesengine", fs::native); + fs::path p = fs::path(homeDirectory().string() + "/.creaturesengine"); if (!fs::exists(p)) fs::create_directory(p); if (fs::is_directory(p)) { - std::ofstream f((p.native_directory_string() + "/port").c_str(), std::ios::trunc); + std::ofstream f((p.string() + "/port").c_str(), std::ios::trunc); f << boost::str(boost::format("%d") % listenport); } #endif @@ -776,7 +776,7 @@ bool Engine::initialSetup() { throw creaturesException("multiple bootstrap files provided in C1/C2 mode"); for (std::vector< std::string >::iterator bsi = cmdline_bootstrap.begin(); bsi != cmdline_bootstrap.end(); bsi++) { - fs::path scriptdir(*bsi, fs::native); + fs::path scriptdir(*bsi); if (engine.version > 2 || fs::extension(scriptdir) == ".cos") { // pass it to the world to execute (it handles both files and directories) @@ -792,7 +792,7 @@ bool Engine::initialSetup() { throw creaturesException("non-existant bootstrap file provided in C1/C2 mode"); // TODO: the default SFCFile loading code is in World, maybe this should be too.. SFCFile sfc; - std::ifstream f(scriptdir.native_directory_string().c_str(), std::ios::binary); + std::ifstream f(scriptdir.string().c_str(), std::ios::binary); f >> std::noskipws; sfc.read(&f); sfc.copyToWorld(); @@ -832,18 +832,18 @@ fs::path Engine::homeDirectory() { #ifndef _WIN32 char *envhome = getenv("HOME"); if (envhome) - p = fs::path(envhome, fs::native); + p = fs::path(envhome); if ((!envhome) || (!fs::is_directory(p))) - p = fs::path(getpwuid(getuid())->pw_dir, fs::native); + p = fs::path(getpwuid(getuid())->pw_dir); if (!fs::is_directory(p)) { std::cerr << "Can't work out what your home directory is, giving up and using /tmp for now." << std::endl; - p = fs::path("/tmp", fs::native); // sigh + p = fs::path("/tmp"); // sigh } #else TCHAR szPath[_MAX_PATH]; SHGetSpecialFolderPath(NULL, szPath, CSIDL_PERSONAL, TRUE); - p = fs::path(szPath, fs::native); + p = fs::path(szPath); if (!fs::exists(p) || !fs::is_directory(p)) throw creaturesException("Windows reported that your My Documents folder is at '" + std::string(szPath) + "' but there's no directory there!"); #endif @@ -863,18 +863,18 @@ fs::path Engine::storageDirectory() { #endif // main storage dir - fs::path p = fs::path(homeDirectory().native_directory_string() + dirname, fs::native); + fs::path p = fs::path(homeDirectory().string() + dirname); if (!fs::exists(p)) fs::create_directory(p); else if (!fs::is_directory(p)) - throw creaturesException("Your openc2e data directory " + p.native_directory_string() + " is a file, not a directory. That's bad."); + throw creaturesException("Your openc2e data directory " + p.string() + " is a file, not a directory. That's bad."); // game-specific storage dir - p = fs::path(p.native_directory_string() + std::string("/" + gamename), fs::native); + p = fs::path(p.string() + std::string("/" + gamename)); if (!fs::exists(p)) fs::create_directory(p); else if (!fs::is_directory(p)) - throw creaturesException("Your openc2e game data directory " + p.native_directory_string() + " is a file, not a directory. That's bad."); + throw creaturesException("Your openc2e game data directory " + p.string() + " is a file, not a directory. That's bad."); return p; } diff --git a/src/PathResolver.cpp b/src/PathResolver.cpp index 0d6905df..c365fbb3 100644 --- a/src/PathResolver.cpp +++ b/src/PathResolver.cpp @@ -48,13 +48,13 @@ static string toLowerCase(string in) { } static path lcpath(path &orig) { - return path(toLowerCase(orig.string()), native); + return path(toLowerCase(orig.string())); } static path lcleaf(path &orig) { path br, leaf; - br = orig.branch_path(); - leaf = path(toLowerCase(orig.leaf()), native); + br = orig.parent_path(); + leaf = path(toLowerCase(orig.filename().string())); return br / leaf; } @@ -68,7 +68,7 @@ bool resolveFile(path &p) { if (!resolveFile(s)) return false; } - p = path(s, native); + p = path(s); return true; #else return exists(p); @@ -76,20 +76,21 @@ bool resolveFile(path &p) { } bool resolveFile_(string &srcPath) { - path orig(srcPath, native); + path orig(srcPath); + if (exists(orig)) return true; orig.normalize(); - path dir = orig.branch_path(); - path leaf = path(orig.leaf(), native); + path dir = orig.parent_path(); + path leaf = orig.filename(); if (!checkDirCache(dir)) return false; orig = dir / lcpath(leaf); string fn = orig.string(); - + if (exists(orig)) { srcPath = fn; return true; @@ -180,7 +181,7 @@ std::vector findByWildcard(std::string dir, std::string wild) { wild = toLowerCase(wild); - path dirp(dir, native); + path dirp(dir); dirp.normalize(); if (!resolveFile(dirp)) return std::vector(); diff --git a/src/World.cpp b/src/World.cpp index 3faa5ad7..a18e0d96 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -515,7 +515,7 @@ void World::executeInitScript(fs::path p) { assert(fs::exists(p)); assert(!fs::is_directory(p)); - std::string x = p.native_file_string(); + std::string x = p.string(); std::ifstream s(x.c_str()); assert(s.is_open()); //std::cout << "executing script " << x << "...\n"; @@ -527,9 +527,9 @@ void World::executeInitScript(fs::path p) { script.installScripts(); vm.runEntirely(script.installer); } catch (creaturesException &e) { - std::cerr << "exec of \"" << p.leaf() << "\" failed due to exception " << e.prettyPrint() << std::endl; + std::cerr << "exec of \"" << p.string() << "\" failed due to exception " << e.prettyPrint() << std::endl; } catch (std::exception &e) { - std::cerr << "exec of \"" << p.leaf() << "\" failed due to exception " << e.what() << std::endl; + std::cerr << "exec of \"" << p.string() << "\" failed due to exception " << e.what() << std::endl; } std::cout.flush(); std::cerr.flush(); } @@ -564,7 +564,7 @@ void World::executeBootstrap(bool switcher) { fs::path edenpath(data_directories[0] / "/Eden.sfc"); if (fs::exists(edenpath) && !fs::is_directory(edenpath)) { SFCFile sfc; - std::ifstream f(edenpath.native_directory_string().c_str(), std::ios::binary); + std::ifstream f(edenpath.string().c_str(), std::ios::binary); f >> std::noskipws; sfc.read(&f); sfc.copyToWorld(); @@ -585,7 +585,7 @@ void World::executeBootstrap(bool switcher) { // iterate through each bootstrap directory for (fs::directory_iterator d(b); d != fsend; ++d) { if (fs::exists(*d) && fs::is_directory(*d)) { - std::string s = d->path().leaf(); + std::string s = d->path().filename().string(); // TODO: cvillage has switcher code in 'Startup', so i included it here too if (s == "000 Switcher" || s == "Startup") { if (!switcher) continue; @@ -620,7 +620,7 @@ std::string World::findFile(std::string name) { // Go backwards, so we find files in more 'modern' directories first.. for (int i = data_directories.size() - 1; i != -1; i--) { fs::path p = data_directories[i]; - std::string r = (p / fs::path(name, fs::native)).native_directory_string(); + std::string r = (p / fs::path(name)).string(); if (resolveFile(r)) return r; } @@ -634,7 +634,7 @@ std::vector World::findFiles(std::string dir, std::string wild) { // Go backwards, so we find files in more 'modern' directories first.. for (int i = data_directories.size() - 1; i != -1; i--) { fs::path p = data_directories[i]; - std::string r = (p / fs::path(dir, fs::native)).native_directory_string(); + std::string r = (p / fs::path(dir)).string(); std::vector results = findByWildcard(r, wild); possibles.insert(possibles.end(), results.begin(), results.end()); // merge results } @@ -643,7 +643,7 @@ std::vector World::findFiles(std::string dir, std::string wild) { } std::string World::getUserDataDir() { - return (data_directories.end() - 1)->native_directory_string(); + return (data_directories.end() - 1)->string(); } void World::selectCreature(boost::shared_ptr a) { diff --git a/src/backends/qtgui/AgentInjector.cpp b/src/backends/qtgui/AgentInjector.cpp index 2510368b..31ca57de 100644 --- a/src/backends/qtgui/AgentInjector.cpp +++ b/src/backends/qtgui/AgentInjector.cpp @@ -97,7 +97,7 @@ void AgentInjector::readAgents() { std::transform(cobext.begin(), cobext.end(), cobext.begin(), (int(*)(int))tolower); // downcase if (cobext != ".cob") continue; - std::string cob = itr->path().native_file_string(); + std::string cob = itr->path().string(); if (engine.version == 1) { std::ifstream cobstream(cob.c_str(), std::ios::binary); @@ -166,8 +166,8 @@ void AgentInjector::onInject() { std::string directory = world.praymanager.getResourceDir(praytype); caos_assert(!directory.empty()); - fs::path possiblefile = fs::path(directory, fs::native) / fs::path(name, fs::native); - if (!world.findFile(possiblefile.native_directory_string()).empty()) continue; // TODO: update file if necessary? + fs::path possiblefile = fs::path(directory) / fs::path(name); + if (!world.findFile(possiblefile.string()).empty()) continue; // TODO: update file if necessary? std::vector::iterator j; @@ -179,15 +179,15 @@ void AgentInjector::onInject() { cobFileBlock *a = new cobFileBlock(*j); if (a->filetype == type && a->filename == name) { // Found dependency! - fs::path dir = fs::path(world.getUserDataDir(), fs::native) / fs::path(directory, fs::native); + fs::path dir = fs::path(world.getUserDataDir()) / fs::path(directory); if (!fs::exists(dir)) fs::create_directory(dir); assert(fs::exists(dir) && fs::is_directory(dir)); // TODO: error handling - fs::path outputfile = dir / fs::path(name, fs::native); + fs::path outputfile = dir / fs::path(name); assert(!fs::exists(outputfile)); - std::ofstream output(outputfile.native_directory_string().c_str(), std::ios::binary); + std::ofstream output(outputfile.string().c_str(), std::ios::binary); output.write((char *)a->getFileContents(), a->filesize); a->getParent()->free(); diff --git a/src/caos/caosVM_core.cpp b/src/caos/caosVM_core.cpp index 3aa46294..ed0f9326 100644 --- a/src/caos/caosVM_core.cpp +++ b/src/caos/caosVM_core.cpp @@ -346,7 +346,7 @@ void caosVM::v_OC2E_DDIR() { for (std::vector::iterator i = world.data_directories.begin(); i != world.data_directories.end(); i++) { boost::filesystem::path &p = *i; - d = d + boost::filesystem::system_complete(p).native_file_string() + "\n"; + d = d + boost::filesystem::system_complete(p).string() + "\n"; } result.setString(d); diff --git a/src/caos/caosVM_files.cpp b/src/caos/caosVM_files.cpp index 8875f53f..c23271eb 100644 --- a/src/caos/caosVM_files.cpp +++ b/src/caos/caosVM_files.cpp @@ -59,7 +59,7 @@ std::string calculateJournalFilename(int directory, std::string filename, bool w default: throw caosException("unknown Journal directory"); } - fs::path dir = fs::path(fullfilename, fs::native); + fs::path dir = fs::path(fullfilename); if (!fs::exists(dir)) fs::create_directory(dir); caos_assert(fs::exists(dir) && fs::is_directory(dir)); diff --git a/src/caos/caosVM_resources.cpp b/src/caos/caosVM_resources.cpp index 4053d181..af5145a8 100644 --- a/src/caos/caosVM_resources.cpp +++ b/src/caos/caosVM_resources.cpp @@ -29,19 +29,19 @@ bool prayInstall(std::string name, unsigned int type, bool actually_install) { std::string directory = world.praymanager.getResourceDir(type); caos_assert(!directory.empty()); - fs::path dir = fs::path(world.getUserDataDir(), fs::native) / fs::path(directory, fs::native); + fs::path dir = fs::path(world.getUserDataDir()) / fs::path(directory); if (!fs::exists(dir)) fs::create_directory(dir); caos_assert(fs::exists(dir) && fs::is_directory(dir)); - fs::path outputfile = dir / fs::path(name, fs::native); + fs::path outputfile = dir / fs::path(name); if (fs::exists(outputfile)) { // TODO: update file if necessary? check it's not a directory :P return true; } - fs::path possiblefile = fs::path(directory, fs::native) / fs::path(name, fs::native); - if (!world.findFile(possiblefile.native_directory_string()).empty()) { + fs::path possiblefile = fs::path(directory) / fs::path(name); + if (!world.findFile(possiblefile.string()).empty()) { // TODO: we need to return 'okay' if the file exists anywhere, but someone needs to work out update behaviour (see other comment above, also) return true; } @@ -65,7 +65,7 @@ bool prayInstall(std::string name, unsigned int type, bool actually_install) { } p->load(); - std::ofstream output(outputfile.native_directory_string().c_str(), std::ios::binary); + std::ofstream output(outputfile.string().c_str(), std::ios::binary); output.write((char *)p->getBuffer(), p->getSize()); // p->unload(); diff --git a/src/caosScript.cpp b/src/caosScript.cpp index fabdb14a..794d8400 100644 --- a/src/caosScript.cpp +++ b/src/caosScript.cpp @@ -108,6 +108,7 @@ std::string script::dump() { caosScript::caosScript(const std::string &dialect, const std::string &fn) { enumdepth = 0; d = dialects[dialect].get(); + if (!d) throw parseException(std::string("Unknown dialect ") + dialect); current = installer = shared_ptr