diff options
author | Marius Kintel <marius@kintel.net> | 2011-12-24 23:22:03 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-12-24 23:22:03 (GMT) |
commit | 9293b591c720d2021be15b3bed56633d2ac17a8d (patch) | |
tree | cc1d05a3b9f6599f6bc2168fbfe8a78f2f6711d2 | |
parent | a5ea98c4a499bdc534d58ecf4881d6ce435d3bd5 (diff) |
Ported currentdir handling from Qt to boost filesystem
-rw-r--r-- | src/mainwin.cc | 2 | ||||
-rw-r--r-- | src/openscad.cc | 31 | ||||
-rw-r--r-- | src/openscad.h | 2 | ||||
-rw-r--r-- | src/parser.y | 2 | ||||
-rw-r--r-- | tests/cgalpngtest.cc | 21 | ||||
-rw-r--r-- | tests/cgaltest.cc | 18 | ||||
-rw-r--r-- | tests/csgtermtest.cc | 19 | ||||
-rw-r--r-- | tests/csgtestcore.cc | 15 | ||||
-rw-r--r-- | tests/csgtexttest.cc | 17 | ||||
-rw-r--r-- | tests/dumptest.cc | 21 | ||||
-rw-r--r-- | tests/echotest.cc | 17 |
11 files changed, 78 insertions, 87 deletions
diff --git a/src/mainwin.cc b/src/mainwin.cc index 6ef7777..3567ddd 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -490,7 +490,7 @@ MainWindow::setFileName(const QString &filename) { if (filename.isEmpty()) { this->fileName.clear(); - this->root_ctx.setDocumentPath(currentdir.toStdString()); + this->root_ctx.setDocumentPath(currentdir); setWindowTitle("OpenSCAD - New Document[*]"); } else { diff --git a/src/openscad.cc b/src/openscad.cc index 8b81f48..f65b311 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -48,12 +48,7 @@ #endif #include <QApplication> -#include <QFile> #include <QDir> -#include <QSet> -#include <QSettings> -#include <QTextStream> -#include <boost/program_options.hpp> #include <sstream> #ifdef Q_WS_MAC @@ -61,11 +56,15 @@ #include "AppleEvents.h" #endif +#include <boost/program_options.hpp> +#include <boost/filesystem.hpp> + #ifdef _MSC_VER #define snprintf _snprintf #endif namespace po = boost::program_options; +namespace fs = boost::filesystem; static void help(const char *progname) { @@ -84,7 +83,7 @@ static void version() } std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; using std::string; @@ -115,7 +114,7 @@ int main(int argc, char **argv) #ifdef Q_WS_MAC app.installEventFilter(new EventFilter(&app)); #endif - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); // set up groups for QSettings QCoreApplication::setOrganizationName("OpenSCAD"); @@ -200,7 +199,7 @@ int main(int argc, char **argv) } #endif - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); QDir exdir(QApplication::instance()->applicationDirPath()); #ifdef Q_WS_MAC @@ -259,7 +258,6 @@ int main(int argc, char **argv) ModuleInstantiation root_inst; AbstractNode *root_node; - QFileInfo fileInfo(filename); handle_dep(filename); FILE *fp = fopen(filename, "rt"); if (!fp) { @@ -275,18 +273,17 @@ int main(int argc, char **argv) } fclose(fp); text << commandline_commands; - root_module = parse(text.str().c_str(), fileInfo.absolutePath().toLocal8Bit(), false); + root_module = parse(text.str().c_str(), fs::absolute(filename).generic_string().c_str(), false); if (!root_module) exit(1); } - QDir::setCurrent(fileInfo.absolutePath()); - + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); tree.setRoot(root_node); if (csg_output_file) { - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); std::ofstream fstream(csg_output_file); if (!fstream.is_open()) { PRINTF("Can't open file \"%s\" for export", csg_output_file); @@ -299,7 +296,7 @@ int main(int argc, char **argv) else { CGAL_Nef_polyhedron root_N = cgalevaluator.evaluateCGALMesh(*tree.root()); - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); if (deps_output_file) { if (!write_deps(deps_output_file, @@ -370,7 +367,7 @@ int main(int argc, char **argv) #endif QString qfilename; - if (filename) qfilename = QFileInfo(original_path, filename).absoluteFilePath(); + if (filename) qfilename = QString::fromStdString((original_path / filename).generic_string()); #if 0 /*** disabled by clifford wolf: adds rendering artefacts with OpenCSG ***/ // turn on anti-aliasing @@ -384,8 +381,8 @@ int main(int argc, char **argv) vector<string> inputFiles; if (vm.count("input-file")) { inputFiles = vm["input-file"].as<vector<string> >(); - for (vector<string>::const_iterator i = inputFiles.begin()+1; i != inputFiles.end(); i++) { - new MainWindow(QFileInfo(original_path, i->c_str()).absoluteFilePath()); + for (vector<string>::const_iterator infile = inputFiles.begin()+1; infile != inputFiles.end(); infile++) { + new MainWindow(QString::fromStdString((original_path / *infile).generic_string())); } } app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); diff --git a/src/openscad.h b/src/openscad.h index 23ae4da..dab14cd 100644 --- a/src/openscad.h +++ b/src/openscad.h @@ -36,7 +36,7 @@ extern std::string commandline_commands; #include <QString> // The CWD when application started. We shouldn't change CWD, but until we stop // doing this, use currentdir to get the original CWD. -extern QString currentdir; +extern std::string currentdir; extern QString examplesdir; diff --git a/src/parser.y b/src/parser.y index 2fb0c3f..b8da50d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -649,7 +649,7 @@ Module *Module::compile_library(const std::string &filename) libs_cache[filename] = e; Module *backup_mod = module; - Module *lib_mod = dynamic_cast<Module*>(parse(text.str().c_str(), absolute(filename).generic_string().c_str(), 0)); + Module *lib_mod = dynamic_cast<Module*>(parse(text.str().c_str(), path(filename).parent_path().generic_string().c_str(), 0)); module = backup_mod; if (lib_mod) { diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 59f0d53..7aa740d 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -26,6 +26,7 @@ #include "tests-common.h" #include "openscad.h" +#include "parsersettings.h" #include "node.h" #include "module.h" #include "polyset.h" @@ -43,10 +44,6 @@ #include "OffscreenView.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> -#include <QTextStream> #ifndef _MSC_VER #include <getopt.h> #endif @@ -54,8 +51,11 @@ #include <assert.h> #include <sstream> +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; using std::string; @@ -106,9 +106,11 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); + + currentdir = fs::current_path().generic_string(); - currentdir = QDir::currentPath(); + parser_init(); Context root_ctx; register_builtin(root_ctx); @@ -121,8 +123,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); AbstractNode *absolute_root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -138,7 +139,7 @@ int main(int argc, char **argv) CGAL_Nef_polyhedron N = cgalevaluator.evaluateCGALMesh(*root_node); - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); // match with csgtest ends try { diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 6412338..8bdf417 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -39,10 +39,6 @@ #include "PolySetCGALEvaluator.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> -#include <QTextStream> #ifndef _MSC_VER #include <getopt.h> #endif @@ -50,8 +46,11 @@ #include <assert.h> #include <sstream> +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; using std::string; @@ -86,9 +85,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -103,8 +102,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); AbstractNode *absolute_root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -119,7 +117,7 @@ int main(int argc, char **argv) CGAL_Nef_polyhedron N = cgalevaluator.evaluateCGALMesh(*root_node); - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); if (!N.empty()) { export_stl(&N, std::cout, NULL); } diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 52e55c4..7fae3fb 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -39,9 +39,6 @@ #include "csgterm.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> #ifndef _MSC_VER #include <getopt.h> #endif @@ -50,12 +47,15 @@ #include <sstream> #include <fstream> -using std::cout; +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; +using std::cout; + int main(int argc, char **argv) { if (argc != 3) { @@ -71,9 +71,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -89,8 +89,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -115,7 +114,7 @@ int main(int argc, char **argv) // if (evaluator.background) cout << "Background terms: " << evaluator.background->size() << "\n"; // if (evaluator.highlights) cout << "Highlights terms: " << evaluator.highlights->size() << "\n"; - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); std::ofstream outfile; outfile.open(outfilename); if (root_term) { diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 7ad0a35..4cb612a 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -23,16 +23,16 @@ #include "OffscreenView.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> #include <QTimer> #include <sstream> #include <vector> #include <boost/program_options.hpp> +#include <boost/filesystem.hpp> + namespace po = boost::program_options; +namespace fs = boost::filesystem; using std::string; using std::vector; @@ -251,9 +251,9 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - QString currentdir = QDir::currentPath(); + std::string currentdir = fs::current_path().generic_string(); parser_init(); @@ -273,8 +273,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } if (!sysinfo_dump) { - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); } AbstractNode::resetIndexCounter(); @@ -339,7 +338,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } } - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); try { csgInfo.glview = new OffscreenView(512,512); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index 2c54ed4..d0d27ce 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -38,9 +38,6 @@ #include "Tree.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> #ifndef _MSC_VER #include <getopt.h> #endif @@ -49,8 +46,11 @@ #include <sstream> #include <fstream> +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; + std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; void csgTree(CSGTextCache &cache, const AbstractNode &root) @@ -75,9 +75,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -93,8 +93,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -106,7 +105,7 @@ int main(int argc, char **argv) csgTree(csgcache, *root_node); // std::cout << tree.getString(*root_node) << "\n"; - QDir::setCurrent(original_path.absolutePath()); + current_path(original_path); std::ofstream outfile; outfile.open(outfilename); outfile << csgcache[*root_node] << "\n"; diff --git a/tests/dumptest.cc b/tests/dumptest.cc index 4b1d907..bc48011 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -36,9 +36,6 @@ #include "Tree.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> #ifndef _MSC_VER #include <getopt.h> #endif @@ -47,12 +44,15 @@ #include <sstream> #include <fstream> -using std::string; +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; +using std::string; + string dumptree(const Tree &tree, const AbstractNode &node) { std::stringstream str; @@ -82,9 +82,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -100,8 +100,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); @@ -116,7 +115,7 @@ int main(int argc, char **argv) exit(1); } - QDir::setCurrent(original_path.absolutePath()); + fs::current_path(original_path); std::ofstream outfile; outfile.open(outfilename); outfile << dumpstdstr << "\n"; @@ -130,7 +129,7 @@ int main(int argc, char **argv) fprintf(stderr, "Error: Unable to read back dumped file\n"); exit(1); } - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(original_path); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); diff --git a/tests/echotest.cc b/tests/echotest.cc index 9569f09..7f05149 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -35,9 +35,6 @@ #include "printutils.h" #include <QApplication> -#include <QFile> -#include <QDir> -#include <QSet> #ifndef _MSC_VER #include <getopt.h> #endif @@ -46,12 +43,15 @@ #include <sstream> #include <fstream> -using std::string; +#include <boost/filesystem.hpp> +namespace fs = boost::filesystem; std::string commandline_commands; -QString currentdir; +std::string currentdir; QString examplesdir; +using std::string; + static void outfile_handler(const std::string &msg, void *userdata) { std::ostream *str = static_cast<std::ostream*>(userdata); *str << msg << std::endl; @@ -83,9 +83,9 @@ int main(int argc, char **argv) Builtins::instance()->initialize(); QApplication app(argc, argv, false); - QDir original_path = QDir::current(); + fs::path original_path = fs::current_path(); - currentdir = QDir::currentPath(); + currentdir = fs::current_path().generic_string(); parser_init(); @@ -101,8 +101,7 @@ int main(int argc, char **argv) exit(1); } - QFileInfo fileInfo(filename); - QDir::setCurrent(fileInfo.absolutePath()); + fs::current_path(fs::path(filename).parent_path()); AbstractNode::resetIndexCounter(); root_node = root_module->evaluate(&root_ctx, &root_inst); |