1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 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
22 #include <yaz/yaz-util.h>
25 static void inline_destroy_subfield_recursive(inline_subfield *p);
27 inline_field *inline_mk_field(void)
29 inline_field *p = (inline_field *) xmalloc(sizeof(*p));
33 memset(p, 0, sizeof(*p));
34 p->name = (char *) xmalloc(SZ_FNAME+1);
36 p->ind1 = (char *) xmalloc(SZ_IND+1);
38 p->ind2 = (char *) xmalloc(SZ_IND+1);
43 void inline_destroy_field(inline_field *p)
47 if (p->name) xfree(p->name);
48 if (p->ind1) xfree(p->ind1);
49 if (p->ind2) xfree(p->ind2);
51 inline_destroy_subfield_recursive(p->list);
55 static inline_subfield *inline_mk_subfield(inline_subfield *parent)
57 inline_subfield *p = (inline_subfield *)xmalloc(sizeof(*p));
61 memset(p, 0, sizeof(*p));
62 p->name = (char *) xmalloc(SZ_SFNAME+1);
70 static void inline_destroy_subfield(inline_subfield *p)
74 if (p->name) xfree(p->name);
75 if (p->data) xfree(p->data);
76 if (p->parent) p->parent->next = p->next;
82 static void inline_destroy_subfield_recursive(inline_subfield *p)
86 inline_destroy_subfield_recursive(p->next);
87 if (p->name) xfree(p->name);
88 if (p->data) xfree(p->data);
94 int inline_parse(inline_field *pif, const char *tag, const char *s)
96 inline_field *pf = pif;
102 if (pf->name[0] == '\0')
104 if ((sscanf(p, "%3s", pf->name)) != 1)
109 if (!memcmp(pf->name, "00", 2))
111 pf->list = inline_mk_subfield(0);
112 pf->list->data = xstrdup(p);
116 if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) != 2)
122 inline_subfield *psf = inline_mk_subfield(0);
124 sscanf(tag, "%1s", psf->name);
125 psf->data = xstrdup(p);
133 inline_subfield *last = pf->list;
144 * c-file-style: "Stroustrup"
145 * indent-tabs-mode: nil
147 * vim: shiftwidth=4 tabstop=8 expandtab