1 /* This file is part of the Zebra server.
2 Copyright (C) Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <yaz/yaz-util.h>
28 static void inline_destroy_subfield_recursive(inline_subfield *p);
30 inline_field *inline_mk_field(void)
32 inline_field *p = (inline_field *) xmalloc(sizeof(*p));
36 memset(p, 0, sizeof(*p));
37 p->name = (char *) xmalloc(SZ_FNAME+1);
39 p->ind1 = (char *) xmalloc(SZ_IND+1);
41 p->ind2 = (char *) xmalloc(SZ_IND+1);
46 void inline_destroy_field(inline_field *p)
50 if (p->name) xfree(p->name);
51 if (p->ind1) xfree(p->ind1);
52 if (p->ind2) xfree(p->ind2);
54 inline_destroy_subfield_recursive(p->list);
58 static inline_subfield *inline_mk_subfield(inline_subfield *parent)
60 inline_subfield *p = (inline_subfield *)xmalloc(sizeof(*p));
64 memset(p, 0, sizeof(*p));
65 p->name = (char *) xmalloc(SZ_SFNAME+1);
73 static void inline_destroy_subfield(inline_subfield *p)
77 if (p->name) xfree(p->name);
78 if (p->data) xfree(p->data);
79 if (p->parent) p->parent->next = p->next;
85 static void inline_destroy_subfield_recursive(inline_subfield *p)
89 inline_destroy_subfield_recursive(p->next);
90 if (p->name) xfree(p->name);
91 if (p->data) xfree(p->data);
97 int inline_parse(inline_field *pif, const char *tag, const char *s)
99 inline_field *pf = pif;
105 if (pf->name[0] == '\0')
107 if ((sscanf(p, "%3s", pf->name)) != 1)
112 if (!memcmp(pf->name, "00", 2))
114 pf->list = inline_mk_subfield(0);
115 pf->list->data = xstrdup(p);
119 if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) != 2)
125 inline_subfield *psf = inline_mk_subfield(0);
127 sscanf(tag, "%1s", psf->name);
128 psf->data = xstrdup(p);
136 inline_subfield *last = pf->list;
147 * c-file-style: "Stroustrup"
148 * indent-tabs-mode: nil
150 * vim: shiftwidth=4 tabstop=8 expandtab