merging plan9 work

This commit is contained in:
Alex Shinn 2009-06-30 13:45:47 +09:00
commit fc04f16b1d
2 changed files with 31 additions and 26 deletions

21
main.c
View file

@ -2,9 +2,13 @@
/* Copyright (c) 2009 Alex Shinn. All rights reserved. */ /* Copyright (c) 2009 Alex Shinn. All rights reserved. */
/* BSD-style license: http://synthcode.com/license.txt */ /* 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 <sys/stat.h> #include <sys/stat.h>
#define file_exists_p(path, buf) (! stat(path, buf))
#endif #endif
#include "chibi/eval.h" #include "chibi/eval.h"
char *chibi_module_dir = NULL; char *chibi_module_dir = NULL;
@ -13,13 +17,15 @@ sexp find_module_file (sexp ctx, char *file) {
sexp res; sexp res;
int mlen, flen; int mlen, flen;
char *path; char *path;
#ifndef PLAN9 #ifdef PLAN9
struct stat buf; unsigned char buf[128];
#else
if (! stat(file, &buf)) struct stat buf_str;
struct stat *buf = &buf_str;
#endif #endif
if (file_exists_p(file, buf))
return sexp_c_string(ctx, file, -1); return sexp_c_string(ctx, file, -1);
#ifndef PLAN9
if (! chibi_module_dir) { if (! chibi_module_dir) {
#ifndef PLAN9 #ifndef PLAN9
chibi_module_dir = getenv("CHIBI_MODULE_DIR"); chibi_module_dir = getenv("CHIBI_MODULE_DIR");
@ -34,13 +40,12 @@ sexp find_module_file (sexp ctx, char *file) {
path[mlen] = '/'; path[mlen] = '/';
memcpy(path+mlen+1, file, flen); memcpy(path+mlen+1, file, flen);
path[mlen+flen+1] = '\0'; path[mlen+flen+1] = '\0';
if (! stat(path, &buf)) if (file_exists_p(path, buf))
res = sexp_c_string(ctx, path, mlen+flen+2); res = sexp_c_string(ctx, path, mlen+flen+2);
else else
res = SEXP_FALSE; res = SEXP_FALSE;
free(path); free(path);
return res; return res;
#endif
} }
void repl (sexp ctx) { void repl (sexp ctx) {

36
mkfile
View file

@ -8,29 +8,29 @@ CPPFLAGS= -Iinclude -DPLAN9 -DUSE_STRING_STREAMS=0 -DUSE_DEBUG=0
CFLAGS= -c -B $CPPFLAGS CFLAGS= -c -B $CPPFLAGS
OFILES=sexp.$O eval.$O main.$O 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 include/chibi/install.h: mkfile
echo '#define sexp_module_dir "'$MODDIR'"' > include/chibi/install.h echo '#define sexp_module_dir "'$MODDIR'"' > include/chibi/install.h
%.i: %.c include/chibi/install.h $HFILES $TARG: $OFILES
cpp $CPPFLAGS $stem.c > $target $LD $LDFLAGS -o $target $prereq
sexp.$O: sexp.i $BIN/%: %
$CC $CFLAGS -c -o $target sexp.i cp $stem $target
eval.$O: eval.i clean:V:
$CC $CFLAGS -c -o $target eval.i rm -f $IFILES $TARG *.[$OS]
main.$O: main.i install:V: $BIN/$TARG
$CC $CFLAGS -c -o $target main.i mkdir -p $MODDIR
cp init.scm $MODDIR/
chibi-scheme: sexp.$O eval.$O main.$O
$LD -o $target $prereq
#</sys/src/cmd/mkone
install:
mkdir $MODDIR
cp init.scm $MODDIR