4 #include <yaz/yaz-util.h>
7 static void inline_destroy_subfield_recursive(inline_subfield *p);
9 static inline_field *inline_mk_field(void)
11 inline_field *p = (inline_field *) xmalloc(sizeof(*p));
15 memset(p, 0, sizeof(*p));
16 p->name = (char *) xmalloc(SZ_FNAME+1);
18 p->ind1 = (char *) xmalloc(SZ_IND+1);
20 p->ind2 = (char *) xmalloc(SZ_IND+1);
25 void inline_destroy_field(inline_field *p)
29 if (p->name) xfree(p->name);
30 if (p->ind1) xfree(p->ind1);
31 if (p->ind2) xfree(p->ind2);
33 inline_destroy_subfield_recursive(p->list);
37 static inline_subfield *inline_mk_subfield(inline_subfield *parent)
39 inline_subfield *p = (inline_subfield *)xmalloc(sizeof(*p));
43 memset(p, 0, sizeof(*p));
44 p->name = (char *) xmalloc(SZ_SFNAME+1);
52 static void inline_destroy_subfield(inline_subfield *p)
56 if (p->name) xfree(p->name);
57 if (p->data) xfree(p->data);
58 if (p->parent) p->parent->next = p->next;
64 static void inline_destroy_subfield_recursive(inline_subfield *p)
68 inline_destroy_subfield_recursive(p->next);
69 if (p->name) xfree(p->name);
70 if (p->data) xfree(p->data);
76 inline_field *inline_parse(const char *s)
78 inline_field *pf = inline_mk_field();
84 if ((sscanf(p, "%3s", pf->name)) != 1)
89 if (!memcmp(pf->name, "00", 2))
91 pf->list = inline_mk_subfield(0);
92 pf->list->data = xstrdup(p);
96 if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) == 2)
99 inline_subfield *parent = 0;
103 if (!strlen(p) || *p != '$')
108 pdup = p = xstrdup(p);
110 for (p=strtok(p, "$"); p; p = strtok(NULL, "$"))
112 inline_subfield *psf = inline_mk_subfield(parent);
122 sscanf(p, "%1s", psf->name);
124 psf->data = (char *) xstrdup(p);