IDZEBRA  2.1.2
inline.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
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
7 version.
8 
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
12 for more details.
13 
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
17 
18 */
19 #if HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22 #include <stdio.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <yaz/yaz-util.h>
26 #include "inline.h"
27 
29 
31 {
32  inline_field *p = (inline_field *) xmalloc(sizeof(*p));
33 
34  if (p)
35  {
36  memset(p, 0, sizeof(*p));
37  p->name = (char *) xmalloc(SZ_FNAME+1);
38  *(p->name) = '\0';
39  p->ind1 = (char *) xmalloc(SZ_IND+1);
40  *(p->ind1) = '\0';
41  p->ind2 = (char *) xmalloc(SZ_IND+1);
42  *(p->ind2) = '\0';
43  }
44  return p;
45 }
47 {
48  if (p)
49  {
50  if (p->name) xfree(p->name);
51  if (p->ind1) xfree(p->ind1);
52  if (p->ind2) xfree(p->ind2);
53  if (p->list)
55  xfree(p);
56  }
57 }
59 {
60  inline_subfield *p = (inline_subfield *)xmalloc(sizeof(*p));
61 
62  if (p)
63  {
64  memset(p, 0, sizeof(*p));
65  p->name = (char *) xmalloc(SZ_SFNAME+1);
66  *(p->name) = '\0';
67  p->parent = parent;
68  }
69  return p;
70 }
71 
72 #if 0
73 static void inline_destroy_subfield(inline_subfield *p)
74 {
75  if (p)
76  {
77  if (p->name) xfree(p->name);
78  if (p->data) xfree(p->data);
79  if (p->parent) p->parent->next = p->next;
80  xfree(p);
81  }
82 }
83 #endif
84 
86 {
87  if (p)
88  {
90  if (p->name) xfree(p->name);
91  if (p->data) xfree(p->data);
92  if (p->parent)
93  p->parent->next = 0;
94  xfree(p);
95  }
96 }
97 int inline_parse(inline_field *pif, const char *tag, const char *s)
98 {
99  inline_field *pf = pif;
100  char *p = (char *)s;
101 
102  if (!pf)
103  return -1;
104 
105  if (pf->name[0] == '\0')
106  {
107  if ((sscanf(p, "%3s", pf->name)) != 1)
108  return -2;
109 
110  p += SZ_FNAME;
111 
112  if (!memcmp(pf->name, "00", 2))
113  {
114  pf->list = inline_mk_subfield(0);
115  pf->list->data = xstrdup(p);
116  }
117  else
118  {
119  if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) != 2)
120  return -3;
121  }
122  }
123  else
124  {
126 
127  sscanf(tag, "%1s", psf->name);
128  psf->data = xstrdup(p);
129 
130  if (!pf->list)
131  {
132  pf->list = psf;
133  }
134  else
135  {
136  inline_subfield *last = pf->list;
137  while (last->next)
138  last = last->next;
139  last->next = psf;
140  }
141  }
142  return 0;
143 }
144 /*
145  * Local variables:
146  * c-basic-offset: 4
147  * c-file-style: "Stroustrup"
148  * indent-tabs-mode: nil
149  * End:
150  * vim: shiftwidth=4 tabstop=8 expandtab
151  */
152 
struct inline_subfield * parent
Definition: inline.h:41
static inline_subfield * inline_mk_subfield(inline_subfield *parent)
Definition: inline.c:58
char * data
Definition: inline.h:39
#define SZ_IND
Definition: marcomp.h:48
#define SZ_SFNAME
Definition: marcomp.h:49
int inline_parse(inline_field *pif, const char *tag, const char *s)
Definition: inline.c:97
char * name
Definition: inline.h:31
char * name
Definition: inline.h:38
struct inline_subfield * next
Definition: inline.h:40
void inline_destroy_field(inline_field *p)
Definition: inline.c:46
static void inline_destroy_subfield_recursive(inline_subfield *p)
Definition: inline.c:85
char * ind2
Definition: inline.h:33
inline_field * inline_mk_field(void)
Definition: inline.c:30
#define SZ_FNAME
Definition: marcomp.h:47
struct inline_subfield * list
Definition: inline.h:34
char * ind1
Definition: inline.h:32