From: Adam Dickmeiss Date: Wed, 29 Mar 1995 11:44:25 +0000 (+0000) Subject: New functions: iso2709_a_.. for record manipulation. X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=d5632f532e0757b5c538da730a4afe0bb7de0c94;p=egate.git New functions: iso2709_a_.. for record manipulation. --- diff --git a/include/iso2709.h b/include/iso2709.h index 8fa4243..faa17fe 100644 --- a/include/iso2709.h +++ b/include/iso2709.h @@ -4,7 +4,10 @@ * 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 @@ -35,6 +38,7 @@ #define ISO2709_H typedef struct iso2709_rec *Iso2709Rec; +typedef struct iso2709_anchor *Iso2709Anchor; char *iso2709_read (FILE *inf); Iso2709Rec iso2709_cvt (const char *buf); @@ -42,4 +46,24 @@ void iso2709_rm (Iso2709Rec rec); 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 + diff --git a/include/iso2709p.h b/include/iso2709p.h index 1f5390b..12560ed 100644 --- a/include/iso2709p.h +++ b/include/iso2709p.h @@ -4,7 +4,10 @@ * 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 @@ -28,6 +31,12 @@ #include +struct iso2709_anchor { + struct iso2709_field **f0; + struct iso2709_dir **d0; + Iso2709Rec rec; +}; + struct iso2709_field { char *identifier; char *data; diff --git a/util/Makefile b/util/Makefile index 9390fd1..86e6637 100644 --- a/util/Makefile +++ b/util/Makefile @@ -2,7 +2,10 @@ # 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 @@ -44,7 +47,8 @@ INCLUDE=-I../include 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 diff --git a/util/iso2709a.c b/util/iso2709a.c new file mode 100644 index 0000000..343cea2 --- /dev/null +++ b/util/iso2709a.c @@ -0,0 +1,180 @@ +/* + * 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 +#include +#include +#include + +#include + +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; +} + diff --git a/util/iso27dis.c b/util/iso27dis.c index 247f216..437e497 100644 --- a/util/iso27dis.c +++ b/util/iso27dis.c @@ -4,7 +4,10 @@ * 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 @@ -20,25 +23,32 @@ #include #include -#include +#include 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)); } +