summaryrefslogtreecommitdiffstats
path: root/sys/boot/ficl
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1998-11-05 08:39:43 +0000
committerjkh <jkh@FreeBSD.org>1998-11-05 08:39:43 +0000
commit33ecda9af6cd79db0f8bc85975b466659a140a5d (patch)
treedcf09926361f18a2af7284bb0bd911c4b7a1e1a3 /sys/boot/ficl
parent6a9b63e38581729c20e76a9680f81a0b31961f50 (diff)
downloadFreeBSD-src-33ecda9af6cd79db0f8bc85975b466659a140a5d.zip
FreeBSD-src-33ecda9af6cd79db0f8bc85975b466659a140a5d.tar.gz
Remember a bit more of my forth and do:
o Add fexists word to check for the presence of a file o make fexists and fload immediate words which DTRT both interpreted and compiled (doh!) o add an init word which gets run at bootstrapping time to do extra post-coldload initialization (in the default implementation, we look for /boot/boot.4th and load it if found).
Diffstat (limited to 'sys/boot/ficl')
-rw-r--r--sys/boot/ficl/Makefile4
-rw-r--r--sys/boot/ficl/softwords/softcore.fr3
-rw-r--r--sys/boot/ficl/words.c61
3 files changed, 55 insertions, 13 deletions
diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile
index 2455714..5dd33e1 100644
--- a/sys/boot/ficl/Makefile
+++ b/sys/boot/ficl/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.4 1998/11/05 04:54:05 msmith Exp $
+# $Id: Makefile,v 1.5 1998/11/05 07:27:55 jkh Exp $
#
LIB= ficl
NOPROFILE= yes
@@ -17,7 +17,7 @@ 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>
diff --git a/sys/boot/ficl/softwords/softcore.fr b/sys/boot/ficl/softwords/softcore.fr
index bcc2696..ad3d55b 100644
--- a/sys/boot/ficl/softwords/softcore.fr
+++ b/sys/boot/ficl/softwords/softcore.fr
@@ -121,5 +121,8 @@ decimal 32 constant bl
wordlist constant hidden
: hide hidden dup >search ficl-set-current ;
+\ init - hook for extra startup behavior
+: init ( -- ) fexists "/boot/boot.4th" if fload "/boot/boot.4th" then ;
+
\ ** E N D S O F T C O R E . F R
diff --git a/sys/boot/ficl/words.c b/sys/boot/ficl/words.c
index 1bd9d35..35e4348 100644
--- a/sys/boot/ficl/words.c
+++ b/sys/boot/ficl/words.c
@@ -4031,26 +4031,31 @@ static void forget(FICL_VM *pVM)
#define nLINEBUF 256
static void fload(FICL_VM *pVM)
{
- char cp[nLINEBUF];
- char filename[nLINEBUF];
- FICL_STRING *pFilename = (FICL_STRING *)filename;
+ char *p, cp[nLINEBUF];
+ FICL_STRING *pFilename;
int i, fd, nLine = 0;
char ch;
CELL id;
+ FICL_DICT *dp = ficlGetDict();
- vmGetString(pVM, pFilename, '\n');
+ if (pVM->state == COMPILE)
+ {
+ dictAppendCell(dp, LVALUEtoCELL(pStringLit));
+ dp->here = PTRtoCELL vmGetString(pVM, (FICL_STRING *)dp->here, '\"');
+ dictAlign(dp);
+ return;
+ }
- if (pFilename->count <= 0)
+ pFilename = (FICL_STRING *)dp->here;
+ vmGetString(pVM, pFilename, '\"');
+ if (pFilename->count <= 1)
{
vmTextOut(pVM, "fload: no filename specified", 1);
return;
}
- /*
- ** get the file's size and make sure it exists
- */
- fd = open(pFilename->text, O_RDONLY);
-
+ p = (*pFilename->text == '\"') ? pFilename->text + 1 : pFilename->text;
+ fd = open(p, O_RDONLY);
if (fd == -1)
{
vmTextOut(pVM, "fload: Unable to open file: ", 0);
@@ -4095,6 +4100,39 @@ static void fload(FICL_VM *pVM)
return;
}
+static void fexists(FICL_VM *pVM)
+{
+ char *p;
+ FICL_STRING *pFilename;
+ int fd;
+ FICL_DICT *dp = ficlGetDict();
+
+ if (pVM->state == COMPILE)
+ {
+ dictAppendCell(dp, LVALUEtoCELL(pStringLit));
+ dp->here = PTRtoCELL vmGetString(pVM, (FICL_STRING *)dp->here, '\"');
+ dictAlign(dp);
+ return;
+ }
+
+ pFilename = (FICL_STRING *)dp->here;
+ vmGetString(pVM, pFilename, '\"');
+ if (pFilename->count <= 1)
+ {
+ vmTextOut(pVM, "fexists: no filename specified", 1);
+ return;
+ }
+ p = (*pFilename->text == '\"') ? pFilename->text + 1 : pFilename->text;
+ fd = open(p, O_RDONLY);
+ if (fd > 0) {
+ stackPushINT32(pVM->pStack, TRUE);
+ close(fd);
+ }
+ else
+ stackPushINT32(pVM->pStack, FALSE);
+ return;
+}
+
/* Get a character from stdin */
static void key(FICL_VM *pVM)
{
@@ -4277,7 +4315,8 @@ void ficlCompileCore(FICL_DICT *dp)
dictAppendWord(dp, "\\", commentLine, FW_IMMEDIATE);
/* FreeBSD extention words */
- dictAppendWord(dp, "fload", fload, FW_DEFAULT);
+ dictAppendWord(dp, "fload", fload, FW_IMMEDIATE);
+ dictAppendWord(dp, "fexists", fexists, FW_IMMEDIATE);
dictAppendWord(dp, "key", key, FW_DEFAULT);
/*
OpenPOWER on IntegriCloud