2 * Iso2709 record management - anchor utilities
7 * Revision 1.2 1995/03/30 07:33:35 adam
8 * New 2709 function: iso2709_mk.
9 * First implementation of iso2709_a_insert.
11 * Revision 1.1 1995/03/29 11:44:29 adam
12 * New functions: iso2709_a_.. for record manipulation.
23 Iso2709Anchor iso2709_a_mk (Iso2709Rec rec)
27 anchor = malloc (sizeof(*anchor));
31 anchor->d0 = &rec->directory;
33 anchor->f0 = &(*anchor->d0)->fields;
39 void iso2709_a_rm (Iso2709Anchor anchor)
44 int iso2709_a_first (Iso2709Anchor anchor)
46 anchor->d0 = &anchor->rec->directory;
49 anchor->f0 = &(*anchor->d0)->fields;
55 int iso2709_a_next_line (Iso2709Anchor anchor)
59 anchor->d0 = &(*anchor->d0)->next;
61 anchor->f0 = &(*anchor->d0)->fields;
65 int iso2709_a_next_field (Iso2709Anchor anchor)
67 if (!*anchor->d0 || !*anchor->f0)
69 if (!(*anchor->f0)->next)
71 anchor->f0 = &(*anchor->f0)->next;
75 int iso2709_a_next (Iso2709Anchor anchor)
77 if (!*anchor->d0 || !*anchor->f0)
78 return iso2709_a_next_line (anchor);
79 anchor->f0 = &(*anchor->f0)->next;
81 return iso2709_a_next_line (anchor);
85 int iso2709_a_info_field (Iso2709Anchor anchor,
86 char **tag, char **indicator,
87 char **identifier, char **data)
89 if (!*anchor->d0 || !*anchor->f0)
92 *tag = (*anchor->d0)->tag;
94 *indicator = (*anchor->d0)->indicator;
96 *identifier = (*anchor->f0)->identifier;
98 *data = (*anchor->f0)->data;
102 int iso2709_a_info_line (Iso2709Anchor anchor,
103 char **tag, char **indicator)
107 assert (*anchor->f0);
108 return iso2709_a_info_field (anchor, tag, indicator, NULL, NULL);
111 int iso2709_a_delete_field (Iso2709Anchor anchor)
113 struct iso2709_field *field;
118 *anchor->f0 = field->next;
119 free (field->identifier);
124 if (! (*anchor->d0)->fields)
125 iso2709_a_delete_line (anchor);
126 iso2709_a_next_line (anchor);
131 int iso2709_a_delete_line (Iso2709Anchor anchor)
133 struct iso2709_dir *dir;
138 *anchor->d0 = dir->next;
139 free (dir->indicator);
144 static int marc_cmp (const char *field, const char *pattern)
150 for (; *field && *pattern; field++, pattern++)
154 if (*pattern != *field)
157 return *field - *pattern;
160 int iso2709_a_search (Iso2709Anchor anchor,
161 const char *tag_p, const char *indicator_p,
162 const char *identifier_p)
169 if (!iso2709_a_info_field (anchor, &tag, &indicator,
172 if ((!tag_p || !marc_cmp (tag, tag_p)) &&
173 (!indicator_p || !marc_cmp (indicator, indicator_p)) &&
174 (!identifier_p || !marc_cmp (identifier, identifier_p)))
176 } while (iso2709_a_next (anchor));
180 int iso2709_a_insert (Iso2709Anchor a,
181 const char *tag, const char *indicator,
182 const char *identifier, const char *data)
184 struct iso2709_field *field;
189 if (! *a->d0 || strcmp (tag, (*a->d0)->tag))
191 struct iso2709_dir *dir;
193 if (!(dir = malloc (sizeof(*dir))))
195 strcpy (dir->tag, tag);
198 if (!(dir->indicator = malloc (strlen(indicator)+1)))
200 strcpy (dir->indicator, indicator);
203 dir->indicator = NULL;
207 a->f0 = &dir->fields;
209 if (!(field = malloc (sizeof(*field))))
213 if (!(field->identifier = malloc (strlen (identifier)+1)))
215 strcpy (field->identifier, identifier);
218 field->identifier = NULL;
219 if (!(field->data = malloc (strlen (data)+1)))
221 strcpy (field->data, data);
222 field->next = *a->f0;
224 a->f0 = &field->next;