FML can be called from the outside multiple times by the functions:
[egate.git] / fml / fmlcalls.c
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmlcalls.c,v $
5  * Revision 1.1  1995/02/09 16:06:07  adam
6  * FML can be called from the outside multiple times by the functions:
7  * fml_exec_call and fml_exec_call_str.
8  * An interactive parameter (-i) to fmltest starts a shell-like
9  * interface to FML by using the fml_exec_call_str function.
10  *
11  */
12 #include <assert.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 #include "fmlp.h"
17
18 static const char *str_ptr;
19 static int eof_mark;
20 static int str_reader (void)
21 {
22     if (!*str_ptr)
23         return eof_mark;
24     return *str_ptr++;
25 }
26
27 void fml_exec_call_str (Fml fml, const char *str)
28 {
29     int (*old_func)(void) = fml->read_func;
30
31     fml->read_func = str_reader;
32     str_ptr = str;
33     eof_mark = fml->eof_mark;
34     fml_exec_call (fml);
35     fml->read_func = old_func;
36 }