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. */
/* 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>
#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) {

36
mkfile
View file

@ -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
#</sys/src/cmd/mkone
install:
mkdir $MODDIR
cp init.scm $MODDIR
install:V: $BIN/$TARG
mkdir -p $MODDIR
cp init.scm $MODDIR/