From 5f82d212861388cc73741917b38f67d773d01549 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 9 Feb 1995 16:06:04 +0000 Subject: [PATCH] FML can be called from the outside multiple times by the functions: fml_exec_call and fml_exec_call_str. An interactive parameter (-i) to fmltest starts a shell-like interface to FML by using the fml_exec_call_str function. --- fml/Makefile | 6 ++++-- fml/fml.c | 17 +++++++++-------- fml/fml.h | 14 ++++++++++++-- fml/fmlcall.c | 28 ++++++++++++++++++++++++++++ fml/fmlcalls.c | 36 ++++++++++++++++++++++++++++++++++++ fml/fmlp.h | 9 ++++++++- fml/fmltest.c | 35 ++++++++++++++++++++++++++++++++++- 7 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 fml/fmlcall.c create mode 100644 fml/fmlcalls.c diff --git a/fml/Makefile b/fml/Makefile index b9b95e2..db2b779 100644 --- a/fml/Makefile +++ b/fml/Makefile @@ -1,6 +1,6 @@ # FML interpreter. Europagate, 1995 # -# $Id: Makefile,v 1.2 1995/02/09 14:33:36 adam Exp $ +# $Id: Makefile,v 1.3 1995/02/09 16:06:04 adam Exp $ SHELL=/bin/sh INCLUDE=-I../include @@ -8,7 +8,9 @@ TPROG1=fmltest CFLAGS=-g -Wall -pedantic DEFS=$(INCLUDE) LIB=fml.a -PO = fmltoken.o fmlmem.o fml.o fmlsym.o fmlrel.o fmlarit.o fmllist.o +PO = fmltoken.o fmlmem.o fml.o fmlsym.o fmlrel.o fmlarit.o fmllist.o \ +fmlcall.o fmlcalls.o + CPP=cc -E CC=gcc diff --git a/fml/fml.c b/fml/fml.c index b2eb160..9423b95 100644 --- a/fml/fml.c +++ b/fml/fml.c @@ -2,7 +2,13 @@ * FML interpreter. Europagate, 1995 * * $Log: fml.c,v $ - * Revision 1.5 1995/02/09 14:33:36 adam + * Revision 1.6 1995/02/09 16:06:06 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + * Revision 1.5 1995/02/09 14:33:36 adam * Split source fml.c and define relevant build-in functions in separate * files. New operators mult, div, not, llen implemented. * @@ -256,8 +262,6 @@ struct fml_node *fml_expr_term (Fml fml, struct fml_node **lp, return fn; } -static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml); - void fml_lr_values (Fml fml, struct fml_node *l, int *left_val, struct fml_node *r, int *right_val) { @@ -724,7 +728,7 @@ static void fml_emit_expr (Fml fml, struct fml_node **lp, struct token *tp) fml_node_delete (fml, fn); } -static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) +struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) { struct token token; struct fml_sym_info *info; @@ -862,9 +866,6 @@ static struct fml_node *fml_exec_group (struct fml_node *list, Fml fml) } break; case 't': -#if 0 - printf ("", token.tokenbuf); -#endif if (token.separate && !first) putchar (' '); first = 0; @@ -883,5 +884,5 @@ void fml_exec (Fml fml) fml_node_stat (fml); fml_exec_group (fml->list, fml); if (fml->debug & 1) - printf ("\n"); + putchar ('\n'); } diff --git a/fml/fml.h b/fml/fml.h index c65e428..38dfd91 100644 --- a/fml/fml.h +++ b/fml/fml.h @@ -2,8 +2,15 @@ * FML interpreter. Europagate, 1995 * * $Log: fml.h,v $ - * Revision 1.1 1995/02/06 13:48:09 adam - * Initial revision + * Revision 1.2 1995/02/09 16:06:06 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + * Revision 1.1.1.1 1995/02/06 13:48:10 adam + * First version of the FML interpreter. It's slow and memory isn't + * freed properly. In particular, the FML nodes aren't released yet. * */ @@ -26,7 +33,10 @@ typedef struct Fml_record { Fml fml_open (void); int fml_preprocess (Fml fml); + void fml_exec (Fml fml); +void fml_exec_call (Fml fml); +void fml_exec_call_str (Fml fml, const char *str); #define FML_ERR_NOMEM 1 diff --git a/fml/fmlcall.c b/fml/fmlcall.c new file mode 100644 index 0000000..02e0d38 --- /dev/null +++ b/fml/fmlcall.c @@ -0,0 +1,28 @@ +/* + * FML interpreter. Europagate, 1995 + * + * $Log: fmlcall.c,v $ + * Revision 1.1 1995/02/09 16:06:07 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + */ +#include +#include +#include + +#include "fmlp.h" + +void fml_exec_call (Fml fml) +{ + struct fml_node *fn; + + fml_node_stat (fml); + fn = fml_tokenize (fml); + + fml_exec_group (fn, fml); + fml_node_delete (fml, fn); +} + diff --git a/fml/fmlcalls.c b/fml/fmlcalls.c new file mode 100644 index 0000000..5e73f0e --- /dev/null +++ b/fml/fmlcalls.c @@ -0,0 +1,36 @@ +/* + * FML interpreter. Europagate, 1995 + * + * $Log: fmlcalls.c,v $ + * Revision 1.1 1995/02/09 16:06:07 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + */ +#include +#include +#include + +#include "fmlp.h" + +static const char *str_ptr; +static int eof_mark; +static int str_reader (void) +{ + if (!*str_ptr) + return eof_mark; + return *str_ptr++; +} + +void fml_exec_call_str (Fml fml, const char *str) +{ + int (*old_func)(void) = fml->read_func; + + fml->read_func = str_reader; + str_ptr = str; + eof_mark = fml->eof_mark; + fml_exec_call (fml); + fml->read_func = old_func; +} diff --git a/fml/fmlp.h b/fml/fmlp.h index 6a2552e..3c7015e 100644 --- a/fml/fmlp.h +++ b/fml/fmlp.h @@ -2,7 +2,13 @@ * FML interpreter. Europagate, 1995 * * $Log: fmlp.h,v $ - * Revision 1.5 1995/02/09 14:37:19 adam + * Revision 1.6 1995/02/09 16:06:07 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + * Revision 1.5 1995/02/09 14:37:19 adam * Removed .depend from cvs. Removed function fml_mk_list. * * Revision 1.4 1995/02/09 14:33:37 adam @@ -112,3 +118,4 @@ void fml_init_token (struct token *tp, Fml fml); void fml_del_token (struct token *tp, Fml fml); struct fml_node *fml_expr_term (Fml fml, struct fml_node **lp, struct token *tp); +struct fml_node *fml_exec_group (struct fml_node *list, Fml fml); diff --git a/fml/fmltest.c b/fml/fmltest.c index 6c07b3a..9c944e1 100644 --- a/fml/fmltest.c +++ b/fml/fmltest.c @@ -2,7 +2,13 @@ * FML interpreter. Europagate, 1995 * * $Log: fmltest.c,v $ - * Revision 1.3 1995/02/09 13:07:15 adam + * Revision 1.4 1995/02/09 16:06:08 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + * Revision 1.3 1995/02/09 13:07:15 adam * Nodes are freed now. Many bugs fixed. * * Revision 1.2 1995/02/07 16:09:24 adam @@ -17,6 +23,7 @@ */ #include +#include #include "fml.h" static FILE *inf; @@ -30,6 +37,7 @@ int main (int argc, char **argv) { Fml fml; int nfiles = 0; + int interactive = 0; fml = fml_open (); while (-- argc > 0) @@ -41,6 +49,10 @@ int main (int argc, char **argv) fml->debug |= 1; else if (argv[0][1] == 'm') fml->debug |= 2; + else if (argv[0][1] == 'i') + { + interactive = 1; + } else { fprintf (stderr, "uknown option `%s'\n", *argv); @@ -67,5 +79,26 @@ int main (int argc, char **argv) fml_preprocess (fml); fml_exec (fml); } + else + { + if (interactive) + { + char arg[128]; + + while (1) + { + char *cp; + + printf ("\nFML>"); + fflush (stdout); + + if (!fgets (arg, 127, stdin)) + break; + if ((cp = strchr (arg, '\n'))) + *cp = '\0'; + fml_exec_call_str (fml, arg); + } + } + } return 0; } -- 1.7.10.4