1. rebuild all elements of testmain properly for safety.

2. add fload and key prims for doing simple file and terminal I/O, respectively
This commit is contained in:
Jordan K. Hubbard 1998-11-05 07:27:55 +00:00
parent dd2461309f
commit 5eb1c6c169
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40927
3 changed files with 99 additions and 7 deletions

View File

@ -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}

View File

@ -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;

View File

@ -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