2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation, in whole or in part, for any purpose, is hereby granted,
15 * 1. This copyright and permission notice appear in all copies of the
16 * software and its documentation. Notices of copyright or attribution
17 * which appear at the beginning of any file must remain unchanged.
19 * 2. The names of EUROPAGATE or the project partners may not be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * 3. Users of this software (implementors and gateway operators) agree to
24 * inform the EUROPAGATE consortium of their use of the software. This
25 * information will be used to evaluate the EUROPAGATE project and the
26 * software, and to plan further developments. The consortium may use
27 * the information in later publications.
29 * 4. Users of this software agree to make their best efforts, when
30 * documenting their use of the software, to acknowledge the EUROPAGATE
31 * consortium, and the role played by the software in their work.
33 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38 * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39 * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40 * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41 * USE OR PERFORMANCE OF THIS SOFTWARE.
45 * Iso2709 record management - anchor utilities
49 * $Log: iso2709a.c,v $
50 * Revision 1.4 1995/05/16 09:40:54 adam
53 * Revision 1.3 1995/03/30 14:22:18 adam
54 * More work on new MARC anchor functions.
56 * Revision 1.2 1995/03/30 07:33:35 adam
57 * New 2709 function: iso2709_mk.
58 * First implementation of iso2709_a_insert.
60 * Revision 1.1 1995/03/29 11:44:29 adam
61 * New functions: iso2709_a_.. for record manipulation.
72 Iso2709Anchor iso2709_a_mk (Iso2709Rec rec)
76 anchor = malloc (sizeof(*anchor));
80 anchor->d0 = &rec->directory;
82 anchor->f0 = &(*anchor->d0)->fields;
88 void iso2709_a_rm (Iso2709Anchor anchor)
93 int iso2709_a_first (Iso2709Anchor anchor)
95 anchor->d0 = &anchor->rec->directory;
98 anchor->f0 = &(*anchor->d0)->fields;
104 int iso2709_a_next_line (Iso2709Anchor anchor)
108 anchor->d0 = &(*anchor->d0)->next;
110 anchor->f0 = &(*anchor->d0)->fields;
114 int iso2709_a_next_field (Iso2709Anchor anchor)
116 if (!*anchor->d0 || !*anchor->f0)
118 if (!(*anchor->f0)->next)
120 anchor->f0 = &(*anchor->f0)->next;
124 int iso2709_a_next (Iso2709Anchor anchor)
126 if (!*anchor->d0 || !*anchor->f0)
127 return iso2709_a_next_line (anchor);
128 anchor->f0 = &(*anchor->f0)->next;
130 return iso2709_a_next_line (anchor);
134 int iso2709_a_info_field (Iso2709Anchor anchor,
135 char **tag, char **indicator,
136 char **identifier, char **data)
138 if (!*anchor->d0 || !*anchor->f0)
141 *tag = (*anchor->d0)->tag;
144 *indicator = (*anchor->d0)->indicator;
145 if (*indicator && !**indicator)
150 *identifier = (*anchor->f0)->identifier;
151 if (*identifier && !**identifier)
155 *data = (*anchor->f0)->data;
159 int iso2709_a_info_line (Iso2709Anchor anchor,
160 char **tag, char **indicator)
164 assert (*anchor->f0);
165 return iso2709_a_info_field (anchor, tag, indicator, NULL, NULL);
168 int iso2709_a_delete_field (Iso2709Anchor anchor)
170 struct iso2709_field *field;
175 *anchor->f0 = field->next;
180 if (! (*anchor->d0)->fields)
181 iso2709_a_delete_line (anchor);
182 iso2709_a_next_line (anchor);
187 int iso2709_a_delete_line (Iso2709Anchor anchor)
189 struct iso2709_dir *dir;
194 *anchor->d0 = dir->next;
195 free (dir->indicator);
200 static int marc_cmp (const char *field, const char *pattern)
206 for (; *field && *pattern; field++, pattern++)
210 if (*pattern != *field)
213 return *field - *pattern;
216 int iso2709_a_search (Iso2709Anchor anchor,
217 const char *tag_p, const char *indicator_p,
218 const char *identifier_p)
225 if (!iso2709_a_info_field (anchor, &tag, &indicator,
228 if ((!tag_p || !marc_cmp (tag, tag_p)) &&
229 (!indicator_p || !marc_cmp (indicator, indicator_p)) &&
230 (!identifier_p || !marc_cmp (identifier, identifier_p)))
232 } while (iso2709_a_next (anchor));
236 int iso2709_a_insert (Iso2709Anchor a,
237 const char *tag, const char *indicator,
238 const char *identifier, const char *data)
240 struct iso2709_field *field;
245 if (! *a->d0 || strcmp (tag, (*a->d0)->tag))
247 struct iso2709_dir *dir;
249 if (!(dir = malloc (sizeof(*dir))))
251 strcpy (dir->tag, tag);
254 if (!(dir->indicator = malloc (strlen(indicator)+1)))
256 strcpy (dir->indicator, indicator);
259 dir->indicator = NULL;
261 a->d0 = &(*a->d0)->next;
265 a->f0 = &dir->fields;
267 if (!(field = malloc (sizeof(*field))))
270 strcpy (field->identifier, identifier);
272 *field->identifier = '\0';
273 if (!(field->data = malloc (strlen (data)+1)))
275 strcpy (field->data, data);
276 field->next = *a->f0;
278 a->f0 = &field->next;