FML can be called from the outside multiple times by the functions:
[egate.git] / fml / fmltest.c
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmltest.c,v $
5  * Revision 1.4  1995/02/09 16:06:08  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  * Revision 1.3  1995/02/09  13:07:15  adam
12  * Nodes are freed now. Many bugs fixed.
13  *
14  * Revision 1.2  1995/02/07  16:09:24  adam
15  * The \ character is no longer INCLUDED when terminating a token.
16  * Major changes in tokenization routines. Bug fixes in expressions
17  * with lists (fml_sub0).
18  *
19  * Revision 1.1.1.1  1995/02/06  13:48:10  adam
20  * First version of the FML interpreter. It's slow and memory isn't
21  * freed properly. In particular, the FML nodes aren't released yet.
22  *
23  */
24
25 #include <stdio.h>
26 #include <string.h>
27 #include "fml.h"
28
29 static FILE *inf;
30
31 static int inf_read (void)
32 {
33     return getc (inf);
34 }
35
36 int main (int argc, char **argv)
37 {
38     Fml fml;
39     int nfiles = 0;
40     int interactive = 0;
41
42     fml = fml_open ();
43     while (-- argc > 0)
44     {
45         ++argv;
46         if (**argv == '-')
47         {
48             if (argv[0][1] == 'd')
49                 fml->debug |= 1;
50             else if (argv[0][1] == 'm')
51                 fml->debug |= 2;
52             else if (argv[0][1] == 'i')
53             {
54                 interactive = 1;
55             }
56             else
57             {
58                 fprintf (stderr, "uknown option `%s'\n", *argv);
59                 exit (1);
60             }
61         }
62         else
63         {
64             nfiles++;
65             inf = fopen (*argv, "r");
66             if (!inf)
67             {
68                 fprintf (stderr, "cannot open `%s'\n", *argv);
69                 exit (1);
70             }
71             fml->read_func = inf_read;
72             fml_preprocess (fml);
73             fml_exec (fml);
74             fclose (inf);
75         }
76     }
77     if (!nfiles)
78     {
79         fml_preprocess (fml);
80         fml_exec (fml);
81     }
82     else
83     {
84         if (interactive)
85         {
86             char arg[128];
87
88             while (1)
89             {
90                 char *cp;
91
92                 printf ("\nFML>");
93                 fflush (stdout);
94
95                 if (!fgets (arg, 127, stdin))
96                     break;
97                 if ((cp = strchr (arg, '\n')))
98                     *cp = '\0';
99                 fml_exec_call_str (fml, arg);
100             }
101         }
102     }
103     return 0;
104 }