Minor changes.
[egate.git] / fml / fmlp.h
1 /*
2  * Copyright (c) 1995, the EUROPAGATE consortium (see below).
3  *
4  * The EUROPAGATE consortium members are:
5  *
6  *    University College Dublin
7  *    Danmarks Teknologiske Videnscenter
8  *    An Chomhairle Leabharlanna
9  *    Consejo Superior de Investigaciones Cientificas
10  *
11  * Permission to use, copy, modify, distribute, and sell this software and
12  * its documentation, in whole or in part, for any purpose, is hereby granted,
13  * provided that:
14  *
15  * 1. This copyright and permission notice appear in all copies of the
16  * software and its documentation. Notices of copyright or attribution
17  * which appear at the beginning of any file must remain unchanged.
18  *
19  * 2. The names of EUROPAGATE or the project partners may not be used to
20  * endorse or promote products derived from this software without specific
21  * prior written permission.
22  *
23  * 3. Users of this software (implementors and gateway operators) agree to
24  * inform the EUROPAGATE consortium of their use of the software. This
25  * information will be used to evaluate the EUROPAGATE project and the
26  * software, and to plan further developments. The consortium may use
27  * the information in later publications.
28  * 
29  * 4. Users of this software agree to make their best efforts, when
30  * documenting their use of the software, to acknowledge the EUROPAGATE
31  * consortium, and the role played by the software in their work.
32  *
33  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36  * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38  * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39  * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40  * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41  * USE OR PERFORMANCE OF THIS SOFTWARE.
42  *
43  */
44 /*
45  * FML interpreter. Europagate, 1995
46  *
47  * $Log: fmlp.h,v $
48  * Revision 1.13  1995/05/16 09:39:34  adam
49  * LICENSE.
50  *
51  * Revision 1.12  1995/03/02  08:06:05  adam
52  * Fml function strsub implemented. New test files marc[45].fml.
53  * New test options in fmltest.
54  *
55  * Revision 1.11  1995/02/27  09:01:21  adam
56  * Regular expression support. Argument passing by name option. New FML
57  * function strlen.
58  *
59  * Revision 1.10  1995/02/23  08:32:06  adam
60  * Changed header.
61  *
62  * Revision 1.8  1995/02/10  18:15:52  adam
63  * FML function 'strcmp' implemented. This function can be used to
64  * test for existence of MARC fields.
65  *
66  * Revision 1.7  1995/02/10  15:50:56  adam
67  * MARC interface implemented. Minor bugs fixed. fmltest can
68  * be used to format single MARC records. New function '\list'
69  * implemented.
70  *
71  * Revision 1.6  1995/02/09  16:06:07  adam
72  * FML can be called from the outside multiple times by the functions:
73  * fml_exec_call and fml_exec_call_str.
74  * An interactive parameter (-i) to fmltest starts a shell-like
75  * interface to FML by using the fml_exec_call_str function.
76  *
77  * Revision 1.5  1995/02/09  14:37:19  adam
78  * Removed .depend from cvs. Removed function fml_mk_list.
79  *
80  * Revision 1.4  1995/02/09  14:33:37  adam
81  * Split source fml.c and define relevant build-in functions in separate
82  * files. New operators mult, div, not, llen implemented.
83  *
84  * Revision 1.3  1995/02/09  13:07:15  adam
85  * Nodes are freed now. Many bugs fixed.
86  *
87  * Revision 1.2  1995/02/07  16:09:23  adam
88  * The \ character is no longer INCLUDED when terminating a token.
89  * Major changes in tokenization routines. Bug fixes in expressions
90  * with lists (fml_sub0).
91  *
92  * Revision 1.1.1.1  1995/02/06  13:48:10  adam
93  * First version of the FML interpreter. It's slow and memory isn't
94  * freed properly. In particular, the FML nodes aren't released yet.
95  *
96  */
97
98 #include <fml.h>
99
100 #ifndef FMLP_H
101 #define FMLP_H
102
103 #define FML_MAX_TOKEN 2048
104
105 #define FML_ATOM_BUF 12
106
107 struct fml_node {
108     void *p[2];
109     unsigned is_atom : 1;
110 };
111
112 struct fml_atom {
113     struct fml_atom *next;
114     char buf[FML_ATOM_BUF];
115 };
116
117 struct fml_node *fml_tokenize (Fml fml);
118 struct fml_node *fml_node_alloc (Fml fml);
119 struct fml_atom *fml_atom_alloc (Fml fml, char *str);
120 int fml_atom_str (struct fml_atom *a, char *str);
121 int fml_atom_len (struct fml_atom *a);
122 void fml_atom_strx (struct fml_atom *a, char *str, int max);
123 int fml_atom_val (struct fml_atom *a);
124 void fml_node_delete (Fml fml, struct fml_node *fn);
125 struct fml_node *fml_node_copy (Fml fml, struct fml_node *fn);
126 struct fml_node *fml_mk_node_val (Fml fml, int val);
127 int fml_atom_cmp (Fml fml, struct fml_atom *a1, struct fml_atom *a2);
128 struct fml_atom *fml_atom_strsub (Fml fml, struct fml_atom *a, int o, int l);
129
130 struct token {
131     int             kind;
132     int             separate;
133     int             maxbuf;
134     int             offset;
135     char            *atombuf;
136     char            *tokenbuf;
137
138     int             escape_char;
139
140     struct          fml_node *sub;
141     struct          fml_atom *atom;
142     char            sbuf[FML_ATOM_BUF*4];
143 };
144
145 struct fml_sym_info {
146     int kind;
147     struct fml_node *args;
148     struct fml_node *body;
149     struct fml_node *(*binary)(Fml fml, struct fml_node *l,
150                                struct fml_node *r);
151     struct fml_node *(*prefix)(Fml fml, struct fml_node **lp,
152                                struct token *tp);
153 };
154
155 struct fml_sym_tab *fml_sym_open (void);
156 void fml_sym_close (struct fml_sym_tab **tabp);
157 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s);
158 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab,const char *s);
159
160 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s);
161 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
162                                            const char *s);
163 void fml_sym_push (struct fml_sym_tab *tab);
164 void fml_sym_pop (struct fml_sym_tab *tab, void(*ph)(struct fml_sym_info *i));
165
166 void fml_pr_list (struct fml_node *p);
167 void fml_node_stat (Fml fml);
168
169 #define FML_FUNC     1
170 #define FML_IF       2
171 #define FML_ELSE     3
172 #define FML_PREFIX   4
173 #define FML_VAR      5
174 #define FML_FOREACH  6
175 #define FML_RETURN   7
176 #define FML_SET      8
177 #define FML_WHILE    9
178 #define FML_CBINARY 10
179 #define FML_CPREFIX 11
180 #define FML_BINARY  12
181 #define FML_BIN     13
182 #define FML_CODE    14
183
184 void fml_rel_init (Fml fml);
185 void fml_arit_init (Fml fml);
186 void fml_list_init (Fml fml);
187 void fml_str_init (Fml fml);
188 void fml_lr_values (Fml fml, struct fml_node *l, int *left_val,
189                            struct fml_node *r, int *right_val);
190 void fml_cmd_lex (struct fml_node **np, struct token *tp);
191 void fml_cmd_lex_s (struct fml_node **np, struct token *tp, int esc_stop);
192 void fml_init_token (struct token *tp, Fml fml);
193 void fml_del_token (struct token *tp, Fml fml);
194 struct fml_node *fml_expr_term (Fml fml, struct fml_node **lp, 
195                                 struct token *tp);
196 struct fml_node *fml_exec_group (struct fml_node *list, Fml fml);
197 #endif