2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
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,
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.
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.
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.
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.
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.
45 * FML interpreter. Europagate, 1995
48 * Revision 1.5 1995/05/16 09:39:34 adam
51 * Revision 1.4 1995/03/02 08:06:09 adam
52 * Fml function strsub implemented. New test files marc[45].fml.
53 * New test options in fmltest.
55 * Revision 1.3 1995/02/23 08:32:06 adam
58 * Revision 1.1.1.1 1995/02/06 13:48:10 adam
59 * First version of the FML interpreter. It's slow and memory isn't
60 * freed properly. In particular, the FML nodes aren't released yet.
72 struct fml_sym_info info;
76 struct fml_sym *level_link;
82 struct fml_sym **array;
83 struct fml_sym *level_link_0;
84 struct fml_sym *level_link_n;
85 struct fml_sym *free_list;
88 static struct fml_sym *sym_alloc (struct fml_sym_tab *tab)
90 struct fml_sym *p = tab->free_list;
95 tab->free_list = p = malloc (sizeof(*p) * SYM_CHUNK);
97 for (i = 0; i<SYM_CHUNK-1; i++)
101 tab->free_list = p->next;
105 static void sym_release (struct fml_sym_tab *tab, struct fml_sym *p)
107 p->next = tab->free_list;
111 struct fml_sym_tab *fml_sym_open (void)
113 struct fml_sym_tab *tab;
116 tab = malloc (sizeof (*tab));
120 tab->level_link_0 = NULL;
121 tab->level_link_n = NULL;
122 tab->free_list = NULL;
124 tab->array = malloc (sizeof(*tab->array) * tab->hash);
130 for (i = 0; i<tab->hash; i++)
131 tab->array[i] = NULL;
135 void fml_sym_close (struct fml_sym_tab **tabp)
137 struct fml_sym *sym, *sym1;
139 for (i = (*tabp)->hash; --i >= 0; )
140 for (sym = (*tabp)->array[i]; sym; sym = sym1)
150 void fml_sym_push (struct fml_sym_tab *tab)
155 void fml_sym_pop (struct fml_sym_tab *tab, void (*ph)(struct fml_sym_info *i))
157 struct fml_sym **fsp;
160 assert (tab->level > 0);
161 for (i = tab->hash; --i >= 0; )
163 fsp = tab->array + i;
166 if ((*fsp)->level == tab->level)
175 sym_release (tab, fs);
184 static unsigned fml_sym_hash (const char *s, unsigned hash)
193 static struct fml_sym_info *sym_add (struct fml_sym_tab *tab,
194 const char *s, int level)
198 struct fml_sym **sym_entry;
200 cp = malloc (strlen(s)+1);
205 sym = sym_alloc (tab);
207 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
209 sym->next = *sym_entry;
214 sym->level_link = tab->level_link_n;
215 tab->level_link_n = sym;
219 sym->level_link = tab->level_link_0;
220 tab->level_link_0 = sym;
225 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s)
227 return sym_add (tab, s, 0);
230 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab, const char *s)
232 return sym_add (tab, s, tab->level);
235 static struct fml_sym_info *sym_lookup (struct fml_sym_tab *tab,
236 const char *s, int level)
239 struct fml_sym *sym0 = NULL;
240 struct fml_sym **sym_entry;
242 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
243 for (sym = *sym_entry; sym; sym = sym->next)
244 if (!strcmp (sym->name, s))
245 if (!sym0 || sym->level > sym0->level)
249 assert (sym0->level <= tab->level);
250 if (level && sym0->level != level)
258 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s)
260 return sym_lookup (tab, s, 0);
263 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
266 return sym_lookup (tab, s, tab->level);