[pure-lang-svn] SF.net SVN: pure-lang:[513] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-16 21:44:46
|
Revision: 513
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=513&view=rev
Author: agraef
Date: 2008-08-16 21:44:56 +0000 (Sat, 16 Aug 2008)
Log Message:
-----------
More robust test for presence of the prelude.
Modified Paths:
--------------
pure/trunk/ChangeLog
pure/trunk/pure.cc
Modified: pure/trunk/ChangeLog
===================================================================
--- pure/trunk/ChangeLog 2008-08-16 21:27:39 UTC (rev 512)
+++ pure/trunk/ChangeLog 2008-08-16 21:44:56 UTC (rev 513)
@@ -1,5 +1,7 @@
2008-08-16 Albert Graef <Dr....@t-...>
+ * pure.cc (main): More robust test for presence of the prelude.
+
* interpreter.cc, lexer.ll: Implemented new script search
algorithm, as discussed on the mailing list.
Modified: pure/trunk/pure.cc
===================================================================
--- pure/trunk/pure.cc 2008-08-16 21:27:39 UTC (rev 512)
+++ pure/trunk/pure.cc 2008-08-16 21:44:56 UTC (rev 513)
@@ -5,6 +5,8 @@
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <locale.h>
#include <signal.h>
@@ -174,6 +176,12 @@
if (histfile) write_history(histfile);
}
+static inline bool chkfile(const string& s)
+{
+ struct stat st;
+ return !stat(s.c_str(), &st) && !S_ISDIR(st.st_mode);
+}
+
int
main(int argc, char *argv[])
{
@@ -272,15 +280,12 @@
interp.init_sys_vars(PACKAGE_VERSION, HOST, myargs);
if (want_prelude) {
// load the prelude if we can find it
- FILE *fp = fopen("prelude.pure", "r");
- if (fp)
+ if (chkfile("prelude.pure")) {
prelude = "prelude.pure";
- else
- // try again in the PURELIB directory
- fp = fopen(prelude.c_str(), "r");
- if (fp) {
- fclose(fp);
have_prelude = true;
+ } else if (chkfile(prelude)) // try again in the PURELIB directory
+ have_prelude = true;
+ if (have_prelude) {
interp.run(prelude);
interp.compile();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|