* Europagate, 1994-1995.
*
* $Log: iso2709.h,v $
- * Revision 1.8 1995/03/28 16:06:42 adam
+ * Revision 1.9 1995/03/29 11:44:25 adam
+ * New functions: iso2709_a_.. for record manipulation.
+ *
+ * Revision 1.8 1995/03/28 16:06:42 adam
* New function: iso2709_out.
*
* Revision 1.7 1995/03/27 12:50:40 adam
#define ISO2709_H
typedef struct iso2709_rec *Iso2709Rec;
+typedef struct iso2709_anchor *Iso2709Anchor;
char *iso2709_read (FILE *inf);
Iso2709Rec iso2709_cvt (const char *buf);
void iso2709_display (Iso2709Rec rec, FILE *out);
int iso2709_out (Iso2709Rec p, char **buf, int size);
+Iso2709Anchor iso2709_a_mk (Iso2709Rec rec);
+void iso2709_a_rm (Iso2709Anchor anchor);
+int iso2709_a_first (Iso2709Anchor anchor);
+int iso2709_a_next_line (Iso2709Anchor anchor);
+int iso2709_a_next_field (Iso2709Anchor anchor);
+int iso2709_a_next (Iso2709Anchor anchor);
+int iso2709_a_info_field (Iso2709Anchor anchor,
+ char **tag, char **indicator,
+ char **identifier, char **data);
+int iso2709_a_info_line (Iso2709Anchor anchor,
+ char **tag, char **indicator);
+int iso2709_a_delete_field (Iso2709Anchor anchor);
+int iso2709_a_delete_line (Iso2709Anchor anchor);
+int iso2709_a_insert (Iso2709Anchor anchor,
+ const char *tag, const char *indicator,
+ const char *identifier, const char *data);
+int iso2709_a_search (Iso2709Anchor anchor,
+ const char *tag_p, const char *indicator_p,
+ const char *identifier_p);
#endif
+
* Europagate, 1994-1995.
*
* $Log: iso2709p.h,v $
- * Revision 1.6 1995/03/08 12:36:36 adam
+ * Revision 1.7 1995/03/29 11:44:25 adam
+ * New functions: iso2709_a_.. for record manipulation.
+ *
+ * Revision 1.6 1995/03/08 12:36:36 adam
* New function: dbc2709_cvt.
*
* Revision 1.5 1995/02/23 08:32:12 adam
#include <iso2709.h>
+struct iso2709_anchor {
+ struct iso2709_field **f0;
+ struct iso2709_dir **d0;
+ Iso2709Rec rec;
+};
+
struct iso2709_field {
char *identifier;
char *data;
# Europagate, 1995
#
# $Log: Makefile,v $
-# Revision 1.12 1995/03/28 16:07:06 adam
+# Revision 1.13 1995/03/29 11:44:29 adam
+# New functions: iso2709_a_.. for record manipulation.
+#
+# Revision 1.12 1995/03/28 16:07:06 adam
# New function: iso2709_out. This function is the reverse of iso2709_cvt.
#
# Revision 1.11 1995/03/28 11:42:41 adam
TPROG1=iso2709dump
TPROG2=gwdbtest
LIB=../lib/util.a
-PO=iso2709.o iso27dis.o iso2709o.o gw-db.o gip.o gips.o gipc.o strqueue.o
+PO=iso2709.o iso27dis.o iso2709o.o iso2709a.o strqueue.o \
+ gw-db.o gip.o gips.o gipc.o
CPP=$(CC) -E
DEFS=$(INCLUDE) -DSTUPID_ISO_DBC=1
--- /dev/null
+/*
+ * Iso2709 record management - anchor utilities
+ *
+ * Europagate, 1995.
+ *
+ * $Log: iso2709a.c,v $
+ * Revision 1.1 1995/03/29 11:44:29 adam
+ * New functions: iso2709_a_.. for record manipulation.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <iso2709p.h>
+
+Iso2709Anchor iso2709_a_mk (Iso2709Rec rec)
+{
+ Iso2709Anchor anchor;
+
+ anchor = malloc (sizeof(*anchor));
+ if (!anchor)
+ return NULL;
+ anchor->rec = rec;
+ anchor->d0 = &rec->directory;
+ if (*anchor->d0)
+ anchor->f0 = &(*anchor->d0)->fields;
+ return anchor;
+}
+
+void iso2709_a_rm (Iso2709Anchor anchor)
+{
+ free (anchor);
+}
+
+int iso2709_a_first (Iso2709Anchor anchor)
+{
+ anchor->d0 = &anchor->rec->directory;
+ if (*anchor->d0)
+ {
+ anchor->f0 = &(*anchor->d0)->fields;
+ return 1;
+ }
+ return 0;
+}
+
+int iso2709_a_next_line (Iso2709Anchor anchor)
+{
+ if (! *anchor->d0)
+ return 0;
+ anchor->d0 = &(*anchor->d0)->next;
+ if (*anchor->d0)
+ anchor->f0 = &(*anchor->d0)->fields;
+ return 1;
+}
+
+int iso2709_a_next_field (Iso2709Anchor anchor)
+{
+ if (!*anchor->d0 || !*anchor->f0)
+ return 0;
+ if (!(*anchor->f0)->next)
+ return 0;
+ anchor->f0 = &(*anchor->f0)->next;
+ return 1;
+}
+
+int iso2709_a_next (Iso2709Anchor anchor)
+{
+ if (!*anchor->d0 || !*anchor->f0)
+ return iso2709_a_next_line (anchor);
+ anchor->f0 = &(*anchor->f0)->next;
+ if (! *anchor->f0)
+ return iso2709_a_next_line (anchor);
+ return 2;
+}
+
+int iso2709_a_info_field (Iso2709Anchor anchor,
+ char **tag, char **indicator,
+ char **identifier, char **data)
+{
+ if (!*anchor->d0 || !*anchor->f0)
+ return 0;
+ if (tag)
+ *tag = (*anchor->d0)->tag;
+ if (indicator)
+ *indicator = (*anchor->d0)->indicator;
+ if (identifier)
+ *identifier = (*anchor->f0)->identifier;
+ if (data)
+ *data = (*anchor->f0)->data;
+ return 1;
+}
+
+int iso2709_a_info_line (Iso2709Anchor anchor,
+ char **tag, char **indicator)
+{
+ if (!*anchor->d0)
+ return 0;
+ assert (*anchor->f0);
+ return iso2709_a_info_field (anchor, tag, indicator, NULL, NULL);
+}
+
+int iso2709_a_delete_field (Iso2709Anchor anchor)
+{
+ struct iso2709_field *field;
+
+ if (!*anchor->d0)
+ return 0;
+ field = *anchor->f0;
+ *anchor->f0 = field->next;
+ free (field->identifier);
+ free (field->data);
+ free (field);
+ if (!*anchor->f0)
+ {
+ if (! (*anchor->d0)->fields)
+ iso2709_a_delete_line (anchor);
+ iso2709_a_next_line (anchor);
+ }
+ return 1;
+}
+
+int iso2709_a_delete_line (Iso2709Anchor anchor)
+{
+ struct iso2709_dir *dir;
+
+ if (!*anchor->d0)
+ return 0;
+ dir = *anchor->d0;
+ *anchor->d0 = dir->next;
+ free (dir->indicator);
+ free (dir);
+ return 1;
+}
+
+static int marc_cmp (const char *field, const char *pattern)
+{
+ if (*pattern == '*')
+ return 0;
+ if (!field)
+ return -*pattern;
+ for (; *field && *pattern; field++, pattern++)
+ {
+ if (*pattern == '?')
+ continue;
+ if (*pattern != *field)
+ break;
+ }
+ return *field - *pattern;
+}
+
+int iso2709_a_search (Iso2709Anchor anchor,
+ const char *tag_p, const char *indicator_p,
+ const char *identifier_p)
+{
+ char *tag;
+ char *indicator;
+ char *identifier;
+ do
+ {
+ if (!iso2709_a_info_field (anchor, &tag, &indicator,
+ &identifier, NULL))
+ return 0;
+ if ((!tag_p || !marc_cmp (tag, tag_p)) &&
+ (!indicator_p || !marc_cmp (indicator, indicator_p)) &&
+ (!identifier_p || !marc_cmp (identifier, identifier_p)))
+ return 1;
+ } while (iso2709_a_next (anchor));
+ return 0;
+}
+
+int iso2709_a_insert (Iso2709Anchor anchor,
+ const char *tag, const char *indicator,
+ const char *identifier, const char *data)
+{
+ return 0;
+}
+
* Europagate, 1994-1995.
*
* $Log: iso27dis.c,v $
- * Revision 1.3 1995/02/22 21:32:36 adam
+ * Revision 1.4 1995/03/29 11:44:29 adam
+ * New functions: iso2709_a_.. for record manipulation.
+ *
+ * Revision 1.3 1995/02/22 21:32:36 adam
* Changed header.
*
* Revision 1.1 1995/02/10 17:05:18 adam
#include <assert.h>
#include <ctype.h>
-#include <iso2709p.h>
+#include <iso2709.h>
void iso2709_display (Iso2709Rec rec, FILE *out)
{
- struct iso2709_dir *dir;
-
- for (dir = rec->directory; dir; dir = dir->next)
+ Iso2709Anchor a;
+ char *tag;
+ char *indicator;
+ char *identifier;
+ char *data;
+
+ a = iso2709_a_mk (rec);
+ do
{
- struct iso2709_field *field;
-
- fprintf (out, "%s", dir->tag);
- if (dir->indicator)
- fprintf (out, " %s", dir->indicator);
- for (field = dir->fields; field; field = field->next)
+ if (!iso2709_a_info_line (a, &tag, &indicator))
+ break;
+ fprintf (out, "%s", tag);
+ if (indicator)
+ fprintf (out, " %s", indicator);
+ do
{
- if (field->identifier)
- fprintf (out, " $%s", field->identifier);
- fprintf (out, " %s", field->data);
- }
+ iso2709_a_info_field (a, NULL, NULL, &identifier, &data);
+ if (identifier)
+ fprintf (out, " $%s", identifier);
+ fprintf (out, " %s", data);
+ } while (iso2709_a_next_field (a));
fprintf (out, "\n");
- }
+ } while (iso2709_a_next_line(a));
}
+