/*
+ * Copyright (c) 1995, the EUROPAGATE consortium (see below).
+ *
+ * The EUROPAGATE consortium members are:
+ *
+ * University College Dublin
+ * Danmarks Teknologiske Videnscenter
+ * An Chomhairle Leabharlanna
+ * Consejo Superior de Investigaciones Cientificas
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation, in whole or in part, for any purpose, is hereby granted,
+ * provided that:
+ *
+ * 1. This copyright and permission notice appear in all copies of the
+ * software and its documentation. Notices of copyright or attribution
+ * which appear at the beginning of any file must remain unchanged.
+ *
+ * 2. The names of EUROPAGATE or the project partners may not be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * 3. Users of this software (implementors and gateway operators) agree to
+ * inform the EUROPAGATE consortium of their use of the software. This
+ * information will be used to evaluate the EUROPAGATE project and the
+ * software, and to plan further developments. The consortium may use
+ * the information in later publications.
+ *
+ * 4. Users of this software agree to make their best efforts, when
+ * documenting their use of the software, to acknowledge the EUROPAGATE
+ * consortium, and the role played by the software in their work.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+ * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
+ * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
+ * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+ * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
+ * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
+ * USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/*
* FML interpreter. Europagate, 1995
*
* $Log: fmlsym.c,v $
- * Revision 1.1 1995/02/06 13:48:09 adam
- * Initial revision
+ * Revision 1.5 1995/05/16 09:39:34 adam
+ * LICENSE.
+ *
+ * Revision 1.4 1995/03/02 08:06:09 adam
+ * Fml function strsub implemented. New test files marc[45].fml.
+ * New test options in fmltest.
+ *
+ * Revision 1.3 1995/02/23 08:32:06 adam
+ * Changed header.
+ *
+ * Revision 1.1.1.1 1995/02/06 13:48:10 adam
+ * First version of the FML interpreter. It's slow and memory isn't
+ * freed properly. In particular, the FML nodes aren't released yet.
*
*/
#include <stdio.h>
#include "fmlp.h"
+#define SYM_CHUNK 128
+
struct fml_sym {
struct fml_sym_info info;
struct fml_sym *next;
int level;
char *name;
+ struct fml_sym *level_link;
};
struct fml_sym_tab {
int level;
int hash;
struct fml_sym **array;
+ struct fml_sym *level_link_0;
+ struct fml_sym *level_link_n;
+ struct fml_sym *free_list;
};
+static struct fml_sym *sym_alloc (struct fml_sym_tab *tab)
+{
+ struct fml_sym *p = tab->free_list;
+ if (!p)
+ {
+ int i;
+
+ tab->free_list = p = malloc (sizeof(*p) * SYM_CHUNK);
+ assert (p);
+ for (i = 0; i<SYM_CHUNK-1; i++)
+ p[i].next = p+i+1;
+ p[i].next = NULL;
+ }
+ tab->free_list = p->next;
+ return p;
+}
+
+static void sym_release (struct fml_sym_tab *tab, struct fml_sym *p)
+{
+ p->next = tab->free_list;
+ tab->free_list = p;
+}
+
struct fml_sym_tab *fml_sym_open (void)
{
struct fml_sym_tab *tab;
if (!tab)
return NULL;
tab->level = 1;
- tab->hash = 101;
+ tab->level_link_0 = NULL;
+ tab->level_link_n = NULL;
+ tab->free_list = NULL;
+ tab->hash = 41;
tab->array = malloc (sizeof(*tab->array) * tab->hash);
if (!tab->array)
{
(*ph)(&fs->info);
*fsp = (*fsp)->next;
free (fs->name);
- free (fs);
+ sym_release (tab, fs);
}
else
fsp = &(*fsp)->next;
return NULL;
strcpy (cp, s);
- sym = malloc (sizeof (*sym));
- if (!sym)
- {
- free (cp);
- return NULL;
- }
+ sym = sym_alloc (tab);
+
sym_entry = tab->array + fml_sym_hash (s, tab->hash);
sym->name = cp;
sym->next = *sym_entry;
*sym_entry = sym;
sym->level = level;
+ if (level)
+ {
+ sym->level_link = tab->level_link_n;
+ tab->level_link_n = sym;
+ }
+ else
+ {
+ sym->level_link = tab->level_link_0;
+ tab->level_link_0 = sym;
+ }
return &sym->info;
}