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