2 * Iso2709 record management - anchor utilities
7 * Revision 1.1 1995/03/29 11:44:29 adam
8 * New functions: iso2709_a_.. for record manipulation.
19 Iso2709Anchor iso2709_a_mk (Iso2709Rec rec)
23 anchor = malloc (sizeof(*anchor));
27 anchor->d0 = &rec->directory;
29 anchor->f0 = &(*anchor->d0)->fields;
33 void iso2709_a_rm (Iso2709Anchor anchor)
38 int iso2709_a_first (Iso2709Anchor anchor)
40 anchor->d0 = &anchor->rec->directory;
43 anchor->f0 = &(*anchor->d0)->fields;
49 int iso2709_a_next_line (Iso2709Anchor anchor)
53 anchor->d0 = &(*anchor->d0)->next;
55 anchor->f0 = &(*anchor->d0)->fields;
59 int iso2709_a_next_field (Iso2709Anchor anchor)
61 if (!*anchor->d0 || !*anchor->f0)
63 if (!(*anchor->f0)->next)
65 anchor->f0 = &(*anchor->f0)->next;
69 int iso2709_a_next (Iso2709Anchor anchor)
71 if (!*anchor->d0 || !*anchor->f0)
72 return iso2709_a_next_line (anchor);
73 anchor->f0 = &(*anchor->f0)->next;
75 return iso2709_a_next_line (anchor);
79 int iso2709_a_info_field (Iso2709Anchor anchor,
80 char **tag, char **indicator,
81 char **identifier, char **data)
83 if (!*anchor->d0 || !*anchor->f0)
86 *tag = (*anchor->d0)->tag;
88 *indicator = (*anchor->d0)->indicator;
90 *identifier = (*anchor->f0)->identifier;
92 *data = (*anchor->f0)->data;
96 int iso2709_a_info_line (Iso2709Anchor anchor,
97 char **tag, char **indicator)
101 assert (*anchor->f0);
102 return iso2709_a_info_field (anchor, tag, indicator, NULL, NULL);
105 int iso2709_a_delete_field (Iso2709Anchor anchor)
107 struct iso2709_field *field;
112 *anchor->f0 = field->next;
113 free (field->identifier);
118 if (! (*anchor->d0)->fields)
119 iso2709_a_delete_line (anchor);
120 iso2709_a_next_line (anchor);
125 int iso2709_a_delete_line (Iso2709Anchor anchor)
127 struct iso2709_dir *dir;
132 *anchor->d0 = dir->next;
133 free (dir->indicator);
138 static int marc_cmp (const char *field, const char *pattern)
144 for (; *field && *pattern; field++, pattern++)
148 if (*pattern != *field)
151 return *field - *pattern;
154 int iso2709_a_search (Iso2709Anchor anchor,
155 const char *tag_p, const char *indicator_p,
156 const char *identifier_p)
163 if (!iso2709_a_info_field (anchor, &tag, &indicator,
166 if ((!tag_p || !marc_cmp (tag, tag_p)) &&
167 (!indicator_p || !marc_cmp (indicator, indicator_p)) &&
168 (!identifier_p || !marc_cmp (identifier, identifier_p)))
170 } while (iso2709_a_next (anchor));
174 int iso2709_a_insert (Iso2709Anchor anchor,
175 const char *tag, const char *indicator,
176 const char *identifier, const char *data)