Regular expression support. Argument passing by name option. New FML
[egate.git] / fml / fmlp.h
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmlp.h,v $
5  * Revision 1.11  1995/02/27 09:01:21  adam
6  * Regular expression support. Argument passing by name option. New FML
7  * function strlen.
8  *
9  * Revision 1.10  1995/02/23  08:32:06  adam
10  * Changed header.
11  *
12  * Revision 1.8  1995/02/10  18:15:52  adam
13  * FML function 'strcmp' implemented. This function can be used to
14  * test for existence of MARC fields.
15  *
16  * Revision 1.7  1995/02/10  15:50:56  adam
17  * MARC interface implemented. Minor bugs fixed. fmltest can
18  * be used to format single MARC records. New function '\list'
19  * implemented.
20  *
21  * Revision 1.6  1995/02/09  16:06:07  adam
22  * FML can be called from the outside multiple times by the functions:
23  * fml_exec_call and fml_exec_call_str.
24  * An interactive parameter (-i) to fmltest starts a shell-like
25  * interface to FML by using the fml_exec_call_str function.
26  *
27  * Revision 1.5  1995/02/09  14:37:19  adam
28  * Removed .depend from cvs. Removed function fml_mk_list.
29  *
30  * Revision 1.4  1995/02/09  14:33:37  adam
31  * Split source fml.c and define relevant build-in functions in separate
32  * files. New operators mult, div, not, llen implemented.
33  *
34  * Revision 1.3  1995/02/09  13:07:15  adam
35  * Nodes are freed now. Many bugs fixed.
36  *
37  * Revision 1.2  1995/02/07  16:09:23  adam
38  * The \ character is no longer INCLUDED when terminating a token.
39  * Major changes in tokenization routines. Bug fixes in expressions
40  * with lists (fml_sub0).
41  *
42  * Revision 1.1.1.1  1995/02/06  13:48:10  adam
43  * First version of the FML interpreter. It's slow and memory isn't
44  * freed properly. In particular, the FML nodes aren't released yet.
45  *
46  */
47
48 #include <fml.h>
49
50 #ifndef FMLP_H
51 #define FMLP_H
52
53 #define FML_MAX_TOKEN 2048
54
55 #define FML_ATOM_BUF 12
56
57 struct fml_node {
58     void *p[2];
59     unsigned is_atom : 1;
60 };
61
62 struct fml_atom {
63     struct fml_atom *next;
64     char buf[FML_ATOM_BUF];
65 };
66
67 struct fml_node *fml_tokenize (Fml fml);
68 struct fml_node *fml_node_alloc (Fml fml);
69 struct fml_atom *fml_atom_alloc (Fml fml, char *str);
70 int fml_atom_str (struct fml_atom *a, char *str);
71 int fml_atom_len (struct fml_atom *a);
72 void fml_atom_strx (struct fml_atom *a, char *str, int max);
73 int fml_atom_val (struct fml_atom *a);
74 void fml_node_delete (Fml fml, struct fml_node *fn);
75 struct fml_node *fml_node_copy (Fml fml, struct fml_node *fn);
76 struct fml_node *fml_mk_node_val (Fml fml, int val);
77 int fml_atom_cmp (Fml fml, struct fml_atom *a1, struct fml_atom *a2);
78
79 struct token {
80     int             kind;
81     int             separate;
82     int             maxbuf;
83     int             offset;
84     char            *atombuf;
85     char            *tokenbuf;
86
87     int             escape_char;
88
89     struct          fml_node *sub;
90     struct          fml_atom *atom;
91     char            sbuf[FML_ATOM_BUF*4];
92 };
93
94 struct fml_sym_info {
95     int kind;
96     struct fml_node *args;
97     struct fml_node *body;
98     struct fml_node *(*binary)(Fml fml, struct fml_node *l,
99                                struct fml_node *r);
100     struct fml_node *(*prefix)(Fml fml, struct fml_node **lp,
101                                struct token *tp);
102 };
103
104 struct fml_sym_tab *fml_sym_open (void);
105 void fml_sym_close (struct fml_sym_tab **tabp);
106 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s);
107 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab,const char *s);
108
109 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s);
110 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
111                                            const char *s);
112 void fml_sym_push (struct fml_sym_tab *tab);
113 void fml_sym_pop (struct fml_sym_tab *tab, void(*ph)(struct fml_sym_info *i));
114
115 void fml_pr_list (struct fml_node *p);
116 void fml_node_stat (Fml fml);
117
118 #define FML_FUNC     1
119 #define FML_IF       2
120 #define FML_ELSE     3
121 #define FML_PREFIX   4
122 #define FML_VAR      5
123 #define FML_FOREACH  6
124 #define FML_RETURN   7
125 #define FML_SET      8
126 #define FML_WHILE    9
127 #define FML_CBINARY 10
128 #define FML_CPREFIX 11
129 #define FML_BINARY  12
130 #define FML_BIN     13
131 #define FML_CODE    14
132
133 void fml_rel_init (Fml fml);
134 void fml_arit_init (Fml fml);
135 void fml_list_init (Fml fml);
136 void fml_str_init (Fml fml);
137 void fml_lr_values (Fml fml, struct fml_node *l, int *left_val,
138                            struct fml_node *r, int *right_val);
139 void fml_cmd_lex (struct fml_node **np, struct token *tp);
140 void fml_cmd_lex_s (struct fml_node **np, struct token *tp, int esc_stop);
141 void fml_init_token (struct token *tp, Fml fml);
142 void fml_del_token (struct token *tp, Fml fml);
143 struct fml_node *fml_expr_term (Fml fml, struct fml_node **lp, 
144                                 struct token *tp);
145 struct fml_node *fml_exec_group (struct fml_node *list, Fml fml);
146 #endif