* OF THIS SOFTWARE.
*
* $Log: data1.h,v $
- * Revision 1.7 1995-12-12 16:37:05 quinn
+ * Revision 1.8 1995-12-13 13:44:23 quinn
+ * Modified Data1-system to use nmem
+ *
+ * Revision 1.7 1995/12/12 16:37:05 quinn
* Added destroy element to data1_node.
*
* Revision 1.6 1995/12/11 15:22:12 quinn
#include <stdio.h>
+#include <nmem.h>
#include <oid.h>
#include <proto.h>
data1_node *get_parent_tag(data1_node *n);
data1_node *data1_read_node(char **buf, data1_node *parent, int *line,
- data1_absyn *absyn);
-data1_node *data1_read_record(int (*rf)(int, char *, size_t), int fd);
+ data1_absyn *absyn, NMEM m);
+data1_node *data1_read_record(int (*rf)(int, char *, size_t), int fd, NMEM m);
data1_absyn *data1_read_absyn(char *file);
data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value);
data1_tagset *data1_read_tagset(char *file);
void data1_free_tree(data1_node *t);
char *data1_nodetobuf(data1_node *n, int select, int *len);
data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at,
- char *tagname);
+ char *tagname, NMEM m);
data1_datatype data1_maptype(char *t);
data1_varset *data1_read_varset(char *file);
data1_vartype *data1_getvartypebyct(data1_varset *set, char *class, char *type);
int data1_doespec1(data1_node *n, Z_Espec1 *e);
data1_esetname *data1_getesetbyname(data1_absyn *a, char *name);
data1_element *data1_getelementbyname(data1_absyn *absyn, char *name);
-data1_node *data1_mk_node(void);
+data1_node *data1_mk_node(NMEM m);
data1_absyn *data1_get_absyn(char *name);
data1_maptab *data1_read_maptab(char *file);
-data1_node *data1_map_record(data1_node *n, data1_maptab *map);
+data1_node *data1_map_record(data1_node *n, data1_maptab *map, NMEM m);
data1_marctab *data1_read_marctab(char *file);
char *data1_nodetomarc(data1_marctab *p, data1_node *n, int selected, int *len);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: d1_map.c,v $
- * Revision 1.6 1995-12-12 16:37:08 quinn
+ * Revision 1.7 1995-12-13 13:44:31 quinn
+ * Modified Data1-system to use nmem
+ *
+ * Revision 1.6 1995/12/12 16:37:08 quinn
* Added destroy element to data1_node.
*
* Revision 1.5 1995/12/12 14:11:31 quinn
return 1;
}
-static int map_children(data1_node *n, data1_maptab *map, data1_node *res)
+static int map_children(data1_node *n, data1_maptab *map, data1_node *res,
+ NMEM mem)
{
data1_node *c;
data1_mapunit *m;
{
if (!cur || mt->new_field || !tagmatch(cur, mt))
{
- cur = data1_mk_node();
+ cur = data1_mk_node(mem);
cur->which = DATA1N_tag;
cur->u.tag.element = 0;
cur->u.tag.tag = mt->value.string;
break;
}
}
- if (map_children(c, map, res) < 0)
+ if (map_children(c, map, res, mem) < 0)
return -1;
}
return 0;
* table. The new copy will refer back to the data of the original record,
* which should not be discarded during the lifetime of the copy.
*/
-data1_node *data1_map_record(data1_node *n, data1_maptab *map)
+data1_node *data1_map_record(data1_node *n, data1_maptab *map, NMEM m)
{
- data1_node *res = data1_mk_node();
+ data1_node *res = data1_mk_node(m);
res->which = DATA1N_root;
res->u.root.type = map->target_absyn_name;
res->parent = 0;
res->root = res;
- if (map_children(n, map, res) < 0)
+ if (map_children(n, map, res, m) < 0)
{
data1_free_tree(res);
return 0;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: d1_read.c,v $
- * Revision 1.6 1995-12-12 16:37:08 quinn
+ * Revision 1.7 1995-12-13 13:44:32 quinn
+ * Modified Data1-system to use nmem
+ *
+ * Revision 1.6 1995/12/12 16:37:08 quinn
* Added destroy element to data1_node.
*
* Revision 1.5 1995/12/11 15:22:37 quinn
void data1_set_tabpath(char *p)
{ data1_tabpath = p; }
+#if 0
static data1_node *freelist = 0;
+#endif
/*
* get the tag which is the immediate parent of this node (this may mean
return 0;
}
-data1_node *data1_mk_node(void)
+data1_node *data1_mk_node(NMEM m)
{
data1_node *r;
+#if 0
if ((r = freelist))
freelist = r->next;
else
if (!(r = xmalloc(sizeof(*r))))
abort();
+#else
+ r = nmem_malloc(m, sizeof(*r));
+#endif
r->next = r->child = r->last_child = r->parent = 0;
r->num_children = 0;
r->destroy = 0;
return r;
}
+#if 0
static void fr_node(data1_node *n)
{
n->next = freelist;
freelist = n;
}
+#endif
void data1_free_tree(data1_node *t)
{
}
if (t->destroy)
(*t->destroy)(t);
+#if 0
fr_node(t);
+#endif
}
/*
* which can then be modified.
*/
data1_node *data1_insert_taggeddata(data1_node *root, data1_node *at,
- char *tagname)
+ char *tagname, NMEM m)
{
- data1_node *tagn = data1_mk_node();
+ data1_node *tagn = data1_mk_node(m);
data1_node *datn;
tagn->which = DATA1N_tag;
tagn->u.tag.no_data_requested = 0;
if (!(tagn->u.tag.element = data1_getelementbytagname(root->u.root.absyn,
0, tagname)))
- {
- fr_node(tagn);
return 0;
- }
- tagn->child = datn = data1_mk_node();
+ tagn->child = datn = data1_mk_node(m);
tagn->num_children = 1;
datn->parent = tagn;
datn->root = root;
* 'node' and its children.
*/
data1_node *data1_read_node(char **buf, data1_node *parent, int *line,
- data1_absyn *absyn)
+ data1_absyn *absyn, NMEM m)
{
data1_node *res;
tag);
return 0;
}
- res = data1_mk_node();
+ res = data1_mk_node(m);
res->which = DATA1N_root;
res->u.root.type = tag;
res->u.root.absyn = absyn;
*/
if (parent->which != DATA1N_variant)
{
- res = data1_mk_node();
+ res = data1_mk_node(m);
res->which = DATA1N_variant;
res->u.variant.type = 0;
res->u.variant.value = 0;
return 0;
}
- res = data1_mk_node();
+ res = data1_mk_node(m);
res->which = DATA1N_variant;
res->root = parent->root;
res->u.variant.type = tp;
#else
elem = data1_getelementbytagname(absyn, e, tag);
#endif
- res = data1_mk_node();
+ res = data1_mk_node(m);
res->which = DATA1N_tag;
res->u.tag.element = elem;
res->u.tag.tag = tag;
/*
* Read child nodes.
*/
- while ((*pp = data1_read_node(buf, res, line, absyn)))
+ while ((*pp = data1_read_node(buf, res, line, absyn, m)))
{
res->last_child = *pp;
res->num_children++;
}
while (isspace(data[len-1]))
len--;
- res = data1_mk_node();
+ res = data1_mk_node(m);
res->parent = parent;
res->which = DATA1N_data;
res->u.data.what = DATA1I_text;
res->u.data.len = len;
res->u.data.data = data;
res->root = parent->root;
-
- /*
- * if the parent is structured, we'll insert a 'wellKnown' marker
- * in front of the data.
- */
-#if 0
- if (partag->u.tag.element && partag->u.tag.element->tag->kind ==
- DATA1K_structured)
- {
- data1_node *wk = mk_node();
- static data1_element wk_element = { 0, 0, 0, 0, 0};
-
- wk->parent = partag;
- wk->root = partag->root;
- wk->which = DATA1N_tag;
- wk->u.tag.tag = 0;
- /*
- * get well-known tagdef if required.
- */
- if (!wk_element.tag && !(wk_element.tag =
- data1_gettagbynum(wk->root->u.root.absyn->tagset, 1, 19)))
- {
- logf(LOG_WARN,
- "Failed to initialize 'wellknown' tag from tagsetM");
- return 0;
- }
- wk->u.tag.element = &wk_element;
- wk->child = partag->child;
- if (wk->child)
- wk->child->parent = wk;
- partag->child = wk;
- }
-#endif
}
return res;
}
/*
* Read a record in the native syntax.
*/
-data1_node *data1_read_record(int (*rf)(int, char *, size_t), int fd)
+data1_node *data1_read_record(int (*rf)(int, char *, size_t), int fd, NMEM m)
{
static char *buf = 0;
char *bp;
if (!buf && !(buf = xmalloc(size = 4096)))
abort();
+
for (;;)
{
if (rd + 4096 > size && !(buf =xrealloc(buf, size *= 2)))
if (!res)
{
bp = buf;
- return data1_read_node(&bp, 0, &line, 0);
+ return data1_read_node(&bp, 0, &line, 0, m);
}
else
return 0;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: nmem.c,v $
- * Revision 1.1 1995-11-13 09:27:52 quinn
+ * Revision 1.2 1995-12-13 13:44:37 quinn
+ * Modified Data1-system to use nmem
+ *
+ * Revision 1.1 1995/11/13 09:27:52 quinn
* Fiddling with the variant stuff.
*
*
{
int total;
nmem_block *blocks;
+ struct nmem_control *next;
} nmem_control;
-static nmem_block *freelist = 0; /* global freelist */
+static nmem_block *freelist = 0; /* global freelists */
+static nmem_control *cfreelist = 0;
static void free_block(nmem_block *p)
{
NMEM nmem_create(void)
{
- NMEM r = xmalloc(sizeof(*r));
+ NMEM r = cfreelist;
+ if (r)
+ cfreelist = cfreelist->next;
+ else
+ r = xmalloc(sizeof(*r));
r->blocks = 0;
r->total = 0;
+ r->next = 0;
return r;
}
if (!n)
return;
nmem_reset(n);
- xfree(n);
+ n->next = cfreelist;
+ cfreelist = n;
}