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.6 2001/02/26 14:32:36 adam
49 * Updated for YAZ 1.7. HTML output tidy up. Added LOC target.
51 * Revision 1.5 1995/05/16 09:39:34 adam
54 * Revision 1.4 1995/03/02 08:06:09 adam
55 * Fml function strsub implemented. New test files marc[45].fml.
56 * New test options in fmltest.
58 * Revision 1.3 1995/02/23 08:32:06 adam
61 * Revision 1.1.1.1 1995/02/06 13:48:10 adam
62 * First version of the FML interpreter. It's slow and memory isn't
63 * freed properly. In particular, the FML nodes aren't released yet.
76 struct fml_sym_info info;
80 struct fml_sym *level_link;
86 struct fml_sym **array;
87 struct fml_sym *level_link_0;
88 struct fml_sym *level_link_n;
89 struct fml_sym *free_list;
92 static struct fml_sym *sym_alloc (struct fml_sym_tab *tab)
94 struct fml_sym *p = tab->free_list;
99 tab->free_list = p = malloc (sizeof(*p) * SYM_CHUNK);
101 for (i = 0; i<SYM_CHUNK-1; i++)
105 tab->free_list = p->next;
109 static void sym_release (struct fml_sym_tab *tab, struct fml_sym *p)
111 p->next = tab->free_list;
115 struct fml_sym_tab *fml_sym_open (void)
117 struct fml_sym_tab *tab;
120 tab = malloc (sizeof (*tab));
124 tab->level_link_0 = NULL;
125 tab->level_link_n = NULL;
126 tab->free_list = NULL;
128 tab->array = malloc (sizeof(*tab->array) * tab->hash);
134 for (i = 0; i<tab->hash; i++)
135 tab->array[i] = NULL;
139 void fml_sym_close (struct fml_sym_tab **tabp)
141 struct fml_sym *sym, *sym1;
143 for (i = (*tabp)->hash; --i >= 0; )
144 for (sym = (*tabp)->array[i]; sym; sym = sym1)
154 void fml_sym_push (struct fml_sym_tab *tab)
159 void fml_sym_pop (struct fml_sym_tab *tab, void (*ph)(struct fml_sym_info *i))
161 struct fml_sym **fsp;
164 assert (tab->level > 0);
165 for (i = tab->hash; --i >= 0; )
167 fsp = tab->array + i;
170 if ((*fsp)->level == tab->level)
179 sym_release (tab, fs);
188 static unsigned fml_sym_hash (const char *s, unsigned hash)
197 static struct fml_sym_info *sym_add (struct fml_sym_tab *tab,
198 const char *s, int level)
202 struct fml_sym **sym_entry;
204 cp = malloc (strlen(s)+1);
209 sym = sym_alloc (tab);
211 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
213 sym->next = *sym_entry;
218 sym->level_link = tab->level_link_n;
219 tab->level_link_n = sym;
223 sym->level_link = tab->level_link_0;
224 tab->level_link_0 = sym;
229 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s)
231 return sym_add (tab, s, 0);
234 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab, const char *s)
236 return sym_add (tab, s, tab->level);
239 static struct fml_sym_info *sym_lookup (struct fml_sym_tab *tab,
240 const char *s, int level)
243 struct fml_sym *sym0 = NULL;
244 struct fml_sym **sym_entry;
246 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
247 for (sym = *sym_entry; sym; sym = sym->next)
248 if (!strcmp (sym->name, s))
249 if (!sym0 || sym->level > sym0->level)
253 assert (sym0->level <= tab->level);
254 if (level && sym0->level != level)
262 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s)
264 return sym_lookup (tab, s, 0);
267 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
270 return sym_lookup (tab, s, tab->level);