summaryrefslogtreecommitdiff
path: root/repl.c
diff options
context:
space:
mode:
Diffstat (limited to 'repl.c')
-rw-r--r--repl.c62
1 files changed, 57 insertions, 5 deletions
diff --git a/repl.c b/repl.c
index c8d2a4d..f2fd4c4 100644
--- a/repl.c
+++ b/repl.c
@@ -1,23 +1,75 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#ifndef _MSC_VER
+ #include <errno.h>
+ #include <unistd.h>
+#endif
#include "s7.h"
+#ifndef _MSC_VER
+static char *realdir(const char *filename)
+{
+ char *path;
+ char *p;
+
+ if (!strchr(filename, '/'))
+ {
+ char *pwd;
+ if (access("libc_s7.so", F_OK) != 0)
+ {
+ fprintf(stderr, "%s needs libc_s7.so (give the explicit pathname)\n", filename); /* env PATH=/home/bil/cl repl */
+ exit(2);
+ }
+ return(NULL); /* we're in the libc_s7.so directory, I hope (user could start a version of s7 that does not match the local libc_s7.so...) */
+ }
+ if (!(path = realpath(filename, NULL)))
+ {
+ fprintf(stderr, "%s: %s\n", strerror(errno), filename);
+ exit(2);
+ }
+ if (!(p = strrchr(path, '/')))
+ {
+ free(path);
+ fprintf(stderr, "please provide the full pathname for %s\n", filename);
+ exit(2);
+ }
+ if (p > path) *p = '\0'; else p[1] = 0;
+ return(path);
+}
+#endif
+
int main(int argc, char **argv)
{
s7_scheme *sc;
+
sc = s7_init();
+ /* fprintf(stderr, "s7: %s\n", S7_DATE); */
if (argc == 2)
{
fprintf(stderr, "load %s\n", argv[1]);
- if (!s7_load(sc, argv[1]))
- fprintf(stderr, "can't find %s\n", argv[1]); /* it could also be a directory */
+ s7_load(sc, argv[1]);
}
- else
+ else
{
- s7_load(sc, "repl.scm");
- s7_eval_c_string(sc, "((*repl* 'run))");
+#ifdef _MSC_VER
+ dumb_repl(sc);
+#else
+#ifdef S7_LOAD_PATH
+ s7_add_to_load_path(sc, S7_LOAD_PATH);
+#else
+ char *dir;
+ dir = realdir(argv[0]);
+ if (dir)
+ {
+ s7_add_to_load_path(sc, dir);
+ free(dir);
+ }
+#endif
+ s7_repl(sc);
+#endif
}
return(0);
}