Changed header.
[egate.git] / fml / fmlcalls.c
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmlcalls.c,v $
5  * Revision 1.4  1995/02/23 08:32:04  adam
6  * Changed header.
7  *
8  * Revision 1.2  1995/02/10  15:50:55  adam
9  * MARC interface implemented. Minor bugs fixed. fmltest can
10  * be used to format single MARC records. New function '\list'
11  * implemented.
12  *
13  * Revision 1.1  1995/02/09  16:06:07  adam
14  * FML can be called from the outside multiple times by the functions:
15  * fml_exec_call and fml_exec_call_str.
16  * An interactive parameter (-i) to fmltest starts a shell-like
17  * interface to FML by using the fml_exec_call_str function.
18  *
19  */
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 #include "fmlp.h"
25
26 static const char **str_args;
27 static int eof_mark;
28 static int str_reader (void)
29 {
30     int c;
31     while (! (c = **str_args))
32     {
33         if (! str_args[1])
34             return eof_mark;
35         ++str_args;
36     }   
37     ++ *str_args;
38     return c;
39 }
40
41 void fml_exec_call_argv (Fml fml, const char **argv)
42 {
43     int (*old_func)(void) = fml->read_func;
44
45     fml->read_func = str_reader;
46     str_args = argv;
47     eof_mark = fml->eof_mark;
48     fml_exec_call (fml);
49     fml->read_func = old_func;
50 }
51
52
53 void fml_exec_call_str (Fml fml, const char *str)
54 {
55     int (*old_func)(void) = fml->read_func;
56     const char *argv[2];
57
58     argv[0] = str;
59     argv[1] = NULL;
60
61     fml->read_func = str_reader;
62     str_args = argv;
63     eof_mark = fml->eof_mark;
64     fml_exec_call (fml);
65     fml->read_func = old_func;
66 }
67
68