diff options
author | jkh <jkh@FreeBSD.org> | 1998-11-05 07:27:55 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1998-11-05 07:27:55 +0000 |
commit | 8d2ee599b0077d4c7b82deb3086b9e17934b209c (patch) | |
tree | 8db91bd563d9cbac543a0336f42431d5ee5e79d2 /sys/boot | |
parent | 3950d98847bfa92c74a0a2a101cce789546bc8f3 (diff) | |
download | FreeBSD-src-8d2ee599b0077d4c7b82deb3086b9e17934b209c.zip FreeBSD-src-8d2ee599b0077d4c7b82deb3086b9e17934b209c.tar.gz |
1. rebuild all elements of testmain properly for safety.
2. add fload and key prims for doing simple file and terminal I/O, respectively
Diffstat (limited to 'sys/boot')
-rw-r--r-- | sys/boot/ficl/Makefile | 16 | ||||
-rw-r--r-- | sys/boot/ficl/ficl.c | 2 | ||||
-rw-r--r-- | sys/boot/ficl/words.c | 88 |
3 files changed, 99 insertions, 7 deletions
diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile index 62562e2..2455714 100644 --- a/sys/boot/ficl/Makefile +++ b/sys/boot/ficl/Makefile @@ -1,11 +1,11 @@ -# $Id: Makefile,v 1.3 1998/11/04 03:42:16 msmith Exp $ +# $Id: Makefile,v 1.4 1998/11/05 04:54:05 msmith Exp $ # LIB= ficl NOPROFILE= yes INTERNALLIB= yes INTERNALSTATICLIB= yes -SRCS= dict.c ficl.c math64.c softcore.c stack.c sysdep.c \ - vm.c words.c +BASE_SRCS= dict.c ficl.c math64.c stack.c sysdep.c vm.c words.c +SRCS= ${BASE_SRCS} softcore.c CLEANFILES= softcore.c testmain # Standard softwords @@ -17,10 +17,14 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr CFLAGS+= -I${.CURDIR} softcore.c: ${SOFTWORDS} softcore.pl - (cd ${.CURDIR}/softwords; perl softcore.pl ${SOFTWORDS}) > ${.TARGET} + (cd ${.CURDIR}/softwords; ${PERL} softcore.pl ${SOFTWORDS}) > ${.TARGET} .include <bsd.lib.mk> +testmain: ${.CURDIR}/testmain.c ${SRCS} + @for i in ${BASE_SRCS}; do echo $${i}... ; \ + ${CC} -c ${CFLAGS} -DTESTMAIN ${.CURDIR}/$${i}; done + @echo softdep.c... + @${CC} -c ${CFLAGS} -D_TESTMAIN softcore.c + cc -o ${.TARGET} ${.CURDIR}/testmain.c ${OBJS} -testmain: testmain.c ${SRCS} - cc -o testmain -DTESTMAIN testmain.c ${SRCS} diff --git a/sys/boot/ficl/ficl.c b/sys/boot/ficl/ficl.c index 6bf6503..7322b81 100644 --- a/sys/boot/ficl/ficl.c +++ b/sys/boot/ficl/ficl.c @@ -220,10 +220,12 @@ int ficlExec(FICL_VM *pVM, char *pText) except = VM_OUTOFTEXT; break; +#ifdef TESTMAIN case VM_OUTOFTEXT: if ((pVM->state != COMPILE) && (pVM->sourceID.i == 0)) ficlTextOut(pVM, FICL_PROMPT, 0); break; +#endif case VM_USEREXIT: break; diff --git a/sys/boot/ficl/words.c b/sys/boot/ficl/words.c index 71b8c6b..1bd9d35 100644 --- a/sys/boot/ficl/words.c +++ b/sys/boot/ficl/words.c @@ -11,6 +11,7 @@ #include <stdlib.h> #include <stdio.h> #include <ctype.h> +#include <fcntl.h> #else #include <stand.h> #endif @@ -4018,10 +4019,92 @@ static void forget(FICL_VM *pVM) return; } +/************************* freebsd added I/O words **************************/ + +/* fload - load a file and interpret it + * + * grabbed out of testmain.c example and frobbed to fit. + * + * Usage: + * fload test.ficl + */ +#define nLINEBUF 256 +static void fload(FICL_VM *pVM) +{ + char cp[nLINEBUF]; + char filename[nLINEBUF]; + FICL_STRING *pFilename = (FICL_STRING *)filename; + int i, fd, nLine = 0; + char ch; + CELL id; + + vmGetString(pVM, pFilename, '\n'); + + if (pFilename->count <= 0) + { + vmTextOut(pVM, "fload: no filename specified", 1); + return; + } + + /* + ** get the file's size and make sure it exists + */ + fd = open(pFilename->text, O_RDONLY); + + if (fd == -1) + { + vmTextOut(pVM, "fload: Unable to open file: ", 0); + vmTextOut(pVM, pFilename->text, 1); + vmThrow(pVM, VM_QUIT); + } + + id = pVM->sourceID; + pVM->sourceID.i = fd; + + /* feed each line to ficlExec */ + while (1) { + int status, i; + + i = 0; + while ((status = read(fd, &ch, 1)) > 0 && ch != '\n') + cp[i++] = ch; + nLine++; + if (!i) { + if (status < 1) + break; + continue; + } + cp[i] = '\0'; + if (ficlExec(pVM, cp) >= VM_ERREXIT) + { + pVM->sourceID = id; + close(fd); + vmThrowErr(pVM, "fload: Error in file %s, line %d", pFilename->text, nLine); + break; + } + } + /* + ** Pass an empty line with SOURCE-ID == 0 to flush + ** any pending REFILLs (as required by FILE wordset) + */ + pVM->sourceID.i = -1; + ficlExec(pVM, ""); + + pVM->sourceID = id; + close(fd); + return; +} + +/* Get a character from stdin */ +static void key(FICL_VM *pVM) +{ + stackPushINT32(pVM->pStack, getchar()); + return; +} #if 0 /************************************************************************** - + ** **************************************************************************/ static void funcname(FICL_VM *pVM) @@ -4193,6 +4276,9 @@ void ficlCompileCore(FICL_DICT *dp) dictAppendWord(dp, "value", constant, FW_DEFAULT); dictAppendWord(dp, "\\", commentLine, FW_IMMEDIATE); + /* FreeBSD extention words */ + dictAppendWord(dp, "fload", fload, FW_DEFAULT); + dictAppendWord(dp, "key", key, FW_DEFAULT); /* ** Set CORE environment query values |