2 $Id: inline.c,v 1.6 2006-05-10 08:13:28 adam Exp $
7 #include <yaz/yaz-util.h>
10 static void inline_destroy_subfield_recursive(inline_subfield *p);
12 inline_field *inline_mk_field(void)
14 inline_field *p = (inline_field *) xmalloc(sizeof(*p));
18 memset(p, 0, sizeof(*p));
19 p->name = (char *) xmalloc(SZ_FNAME+1);
21 p->ind1 = (char *) xmalloc(SZ_IND+1);
23 p->ind2 = (char *) xmalloc(SZ_IND+1);
28 void inline_destroy_field(inline_field *p)
32 if (p->name) xfree(p->name);
33 if (p->ind1) xfree(p->ind1);
34 if (p->ind2) xfree(p->ind2);
36 inline_destroy_subfield_recursive(p->list);
40 static inline_subfield *inline_mk_subfield(inline_subfield *parent)
42 inline_subfield *p = (inline_subfield *)xmalloc(sizeof(*p));
46 memset(p, 0, sizeof(*p));
47 p->name = (char *) xmalloc(SZ_SFNAME+1);
55 static void inline_destroy_subfield(inline_subfield *p)
59 if (p->name) xfree(p->name);
60 if (p->data) xfree(p->data);
61 if (p->parent) p->parent->next = p->next;
67 static void inline_destroy_subfield_recursive(inline_subfield *p)
71 inline_destroy_subfield_recursive(p->next);
72 if (p->name) xfree(p->name);
73 if (p->data) xfree(p->data);
79 int inline_parse(inline_field *pif, const char *tag, const char *s)
81 inline_field *pf = pif;
87 if (pf->name[0] == '\0')
89 if ((sscanf(p, "%3s", pf->name)) != 1)
94 if (!memcmp(pf->name, "00", 2))
96 pf->list = inline_mk_subfield(0);
97 pf->list->data = xstrdup(p);
101 if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) != 2)
107 inline_subfield *psf = inline_mk_subfield(0);
109 sscanf(tag, "%1s", psf->name);
110 psf->data = xstrdup(p);
118 inline_subfield *last = pf->list;
129 * indent-tabs-mode: nil
131 * vim: shiftwidth=4 tabstop=8 expandtab