[pure-lang-svn] SF.net SVN: pure-lang:[545] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-20 06:43:29
|
Revision: 545 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=545&view=rev Author: agraef Date: 2008-08-20 06:43:39 +0000 (Wed, 20 Aug 2008) Log Message: ----------- Windows compatibility fixes. Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/pure.cc pure/trunk/runtime.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-20 01:14:23 UTC (rev 544) +++ pure/trunk/interpreter.cc 2008-08-20 06:43:39 UTC (rev 545) @@ -431,6 +431,29 @@ } #endif +static string unixize(const string& s) +{ + string t = s; +#ifdef _WIN32 + for (size_t i = 0, n = t.size(); i<n; i++) + if (t[i] == '\\') + t[i] = '/'; +#endif + return t; +} + +static bool relname(const string& s) +{ + if (s.empty()) return true; +#ifdef _WIN32 + size_t pos = fname.find('/'); + return pos == string::npos || pos == 0 || + pos == 2 && s[1] == ':'; +#else + return s[0]!='/'; +#endif +} + #define BUFSIZE 1024 static string searchdir(const string& srcdir, const string& libdir, @@ -444,11 +467,11 @@ perror("getcwd"); return script; } - string workdir = cwd; + string workdir = unixize(cwd); if (!workdir.empty() && workdir[workdir.size()-1] != '/') workdir += "/"; string fname; - if (script[0] != '/') { + if (relname(script)) { // resolve relative pathname if (!search) { fname = workdir+script; @@ -472,7 +495,7 @@ } else fname = script; found: - if (fname[0] != '/') fname = workdir+fname; + if (relname(fname)) fname = workdir+fname; char buf[BUFSIZE]; #ifndef _WIN32 if (chklink(fname)) { @@ -494,7 +517,7 @@ // canonicalize the pathname string dir = dirname(fname), name = basename(fname); if (chdir(dir.c_str())==0 && getcwd(buf, BUFSIZE)) { - string dir = buf; + string dir = unixize(buf); if (!dir.empty() && dir[dir.size()-1] != '/') dir += "/"; fname = dir+name; @@ -519,11 +542,11 @@ perror("getcwd"); return lib; } - string workdir = cwd; + string workdir = unixize(cwd); if (!workdir.empty() && workdir[workdir.size()-1] != '/') workdir += "/"; string fname; - if (lib[0] != '/') { + if (relname(lib)) { // resolve relative pathname if (!search) { fname = workdir+lib; @@ -560,8 +583,9 @@ #define DLLEXT ".so" #endif -pure_expr* interpreter::run(const string &s, bool check) +pure_expr* interpreter::run(const string &_s, bool check) { + string s = unixize(_s); // check for library modules size_t p = s.find(":"); if (p != string::npos && s.substr(0, p) == "lib") { Modified: pure/trunk/pure.cc =================================================================== --- pure/trunk/pure.cc 2008-08-20 01:14:23 UTC (rev 544) +++ pure/trunk/pure.cc 2008-08-20 06:43:39 UTC (rev 545) @@ -191,7 +191,11 @@ { size_t pos = 0; while (pos != string::npos) { +#ifdef _WIN32 + size_t end = path.find(';', pos); +#else size_t end = path.find(':', pos); +#endif string s; if (end == string::npos) { s = path.substr(pos); @@ -207,6 +211,17 @@ } } +static string unixize(const string& s) +{ + string t = s; +#ifdef _WIN32 + for (size_t i = 0, n = t.size(); i<n; i++) + if (t[i] == '\\') + t[i] = '/'; +#endif + return t; +} + int main(int argc, char *argv[]) { @@ -260,7 +275,7 @@ if (!*end) interpreter::stackmax = n*1024; } if ((env = getenv("PURELIB"))) { - string s = env; + string s = unixize(env); if (!s.empty() && s[s.size()-1] != '/') s.append("/"); interp.libdir = s; } else @@ -294,6 +309,7 @@ } s = *args; } + s = unixize(s); if (!s.empty()) { if (s[s.size()-1] != '/') s.append("/"); interp.includedirs.push_back(s); @@ -307,6 +323,7 @@ } s = *args; } + s = unixize(s); if (!s.empty()) { if (s[s.size()-1] != '/') s.append("/"); interp.librarydirs.push_back(s); @@ -330,8 +347,10 @@ interp.error(prog + ": invalid option " + *args); return 1; } - if ((env = getenv("PURE_INCLUDE"))) add_path(interp.includedirs, env); - if ((env = getenv("PURE_LIBRARY"))) add_path(interp.librarydirs, env); + if ((env = getenv("PURE_INCLUDE"))) + add_path(interp.includedirs, unixize(env)); + if ((env = getenv("PURE_LIBRARY"))) + add_path(interp.librarydirs, unixize(env)); interp.init_sys_vars(PACKAGE_VERSION, HOST, myargs); if (want_prelude) { // load the prelude if we can find it Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-08-20 01:14:23 UTC (rev 544) +++ pure/trunk/runtime.cc 2008-08-20 06:43:39 UTC (rev 545) @@ -892,7 +892,11 @@ { size_t pos = 0; while (pos != string::npos) { +#ifdef _WIN32 + size_t end = path.find(';', pos); +#else size_t end = path.find(':', pos); +#endif string s; if (end == string::npos) { s = path.substr(pos); @@ -908,6 +912,17 @@ } } +static string unixize(const string& s) +{ + string t = s; +#ifdef _WIN32 + for (size_t i = 0, n = t.size(); i<n; i++) + if (t[i] == '\\') + t[i] = '/'; +#endif + return t; +} + extern "C" pure_interp *pure_create_interp(int argc, char *argv[]) { @@ -931,7 +946,7 @@ if (!*end) interpreter::stackmax = n*1024; } if ((env = getenv("PURELIB"))) { - string s = env; + string s = unixize(env); if (!s.empty() && s[s.size()-1] != '/') s.append("/"); interp.libdir = s; } else @@ -963,6 +978,7 @@ } s = *args; } + s = unixize(s); if (!s.empty()) { if (s[s.size()-1] != '/') s.append("/"); interp.includedirs.push_back(s); @@ -977,6 +993,7 @@ } s = *args; } + s = unixize(s); if (!s.empty()) { if (s[s.size()-1] != '/') s.append("/"); interp.librarydirs.push_back(s); @@ -1002,8 +1019,10 @@ delete _interp; return 0; } - if ((env = getenv("PURE_INCLUDE"))) add_path(interp.includedirs, env); - if ((env = getenv("PURE_LIBRARY"))) add_path(interp.librarydirs, env); + if ((env = getenv("PURE_INCLUDE"))) + add_path(interp.includedirs, unixize(env)); + if ((env = getenv("PURE_LIBRARY"))) + add_path(interp.librarydirs, unixize(env)); interp.init_sys_vars(PACKAGE_VERSION, HOST, myargs); if (want_prelude) { // load the prelude if we can find it This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |