From 4948c2457f16110c10a2daa416e8fff84824ec69 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Feb 2013 23:16:23 -0500 Subject: [PATCH] Added support for more paths in OPENSCADPATH, also search in HOME/Documents/OpenSCAD/libraries on Mac --- src/CocoaUtils.h | 3 +++ src/CocoaUtils.mm | 6 ++++++ src/parsersettings.cc | 23 +++++++++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/CocoaUtils.h b/src/CocoaUtils.h index 8543d84e..ad5518b7 100644 --- a/src/CocoaUtils.h +++ b/src/CocoaUtils.h @@ -1,10 +1,13 @@ #ifndef COCOAUTILS_H_ #define COCOAUTILS_H_ +#include + class CocoaUtils { public: static void endApplication(); + static std::string documentsPath(); }; #endif diff --git a/src/CocoaUtils.mm b/src/CocoaUtils.mm index 2ac8aef4..295ceb94 100644 --- a/src/CocoaUtils.mm +++ b/src/CocoaUtils.mm @@ -1,5 +1,6 @@ #include "CocoaUtils.h" #import +#include void CocoaUtils::endApplication() { @@ -7,3 +8,8 @@ void CocoaUtils::endApplication() postNotificationName:@"NSApplicationWillTerminateNotification" object:nil]; } + +std::string CocoaUtils::documentsPath() +{ + return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); +} diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 3dda132c..54f9713e 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -2,7 +2,9 @@ #include #include #include "boosty.h" +#include #include // Needed for Q_ defines - move the offending code somewhere else +#include "CocoaUtils.h" namespace fs = boost::filesystem; @@ -28,15 +30,24 @@ std::string locate_file(const std::string &filename) void parser_init(const std::string &applicationpath) { - // Add path from OPENSCADPATH before adding built-in paths - const char *openscadpath = getenv("OPENSCADPATH"); - if (openscadpath) { - add_librarydir(boosty::absolute(fs::path(openscadpath)).string()); + // Add paths from OPENSCADPATH before adding built-in paths + const char *openscadpaths = getenv("OPENSCADPATH"); + if (openscadpaths) { + std::string paths(openscadpaths); + typedef boost::split_iterator string_split_iterator; + for (string_split_iterator it = + make_split_iterator(paths, first_finder(":", boost::is_iequal())); + it != string_split_iterator(); + ++it) { + add_librarydir(boosty::absolute(fs::path(boost::copy_range(*it))).string()); + } } - // FIXME: Support specifying more than one path in OPENSCADPATH // FIXME: Add ~/.openscad/libraries - // FIXME: Add ~/Documents/OpenSCAD/libraries on Mac? +#ifdef __APPLE__ + fs::path docdir(CocoaUtils::documentsPath()); + add_librarydir(boosty::stringy(docdir / "OpenSCAD" / "libraries")); +#endif std::string librarydir; fs::path libdir(applicationpath);