diff --git a/main.c b/main.c index 1d1f88b9..b9f63700 100644 --- a/main.c +++ b/main.c @@ -2,9 +2,13 @@ /* Copyright (c) 2009 Alex Shinn. All rights reserved. */ /* BSD-style license: http://synthcode.com/license.txt */ -#ifndef PLAN9 +#ifdef PLAN9 +#define file_exists_p(path, buf) (stat(path, buf, 128) >= 0) +#else #include +#define file_exists_p(path, buf) (! stat(path, buf)) #endif + #include "chibi/eval.h" char *chibi_module_dir = NULL; @@ -13,13 +17,15 @@ sexp find_module_file (sexp ctx, char *file) { sexp res; int mlen, flen; char *path; -#ifndef PLAN9 - struct stat buf; - - if (! stat(file, &buf)) +#ifdef PLAN9 + unsigned char buf[128]; +#else + struct stat buf_str; + struct stat *buf = &buf_str; #endif + + if (file_exists_p(file, buf)) return sexp_c_string(ctx, file, -1); -#ifndef PLAN9 if (! chibi_module_dir) { #ifndef PLAN9 chibi_module_dir = getenv("CHIBI_MODULE_DIR"); @@ -34,13 +40,12 @@ sexp find_module_file (sexp ctx, char *file) { path[mlen] = '/'; memcpy(path+mlen+1, file, flen); path[mlen+flen+1] = '\0'; - if (! stat(path, &buf)) + if (file_exists_p(path, buf)) res = sexp_c_string(ctx, path, mlen+flen+2); else res = SEXP_FALSE; free(path); return res; -#endif } void repl (sexp ctx) { diff --git a/mkfile b/mkfile index 4de142a2..3caba3f9 100644 --- a/mkfile +++ b/mkfile @@ -8,29 +8,29 @@ CPPFLAGS= -Iinclude -DPLAN9 -DUSE_STRING_STREAMS=0 -DUSE_DEBUG=0 CFLAGS= -c -B $CPPFLAGS OFILES=sexp.$O eval.$O main.$O +IFILES=${OFILES:%.$O=%.i} +HFILES=include/chibi/sexp.h include/chibi/eval.h include/chibi/config.h include/chibi/install.h -HFILES=include/chibi/sexp.h include/chibi/eval.h include/chibi/config.h +%.i: %.c $HFILES + cpp $CPPFLAGS $stem.c > $target + +%.$O: %.i + $CC $CFLAGS -c -o $target $prereq + +all:V: $TARG include/chibi/install.h: mkfile echo '#define sexp_module_dir "'$MODDIR'"' > include/chibi/install.h -%.i: %.c include/chibi/install.h $HFILES - cpp $CPPFLAGS $stem.c > $target +$TARG: $OFILES + $LD $LDFLAGS -o $target $prereq -sexp.$O: sexp.i - $CC $CFLAGS -c -o $target sexp.i +$BIN/%: % + cp $stem $target -eval.$O: eval.i - $CC $CFLAGS -c -o $target eval.i +clean:V: + rm -f $IFILES $TARG *.[$OS] -main.$O: main.i - $CC $CFLAGS -c -o $target main.i - -chibi-scheme: sexp.$O eval.$O main.$O - $LD -o $target $prereq - -#