From: Adam Dickmeiss Date: Thu, 30 Mar 1995 14:22:18 +0000 (+0000) Subject: More work on new MARC anchor functions. X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=5d2b04d154ff79a61b09f26fff4e60ca95ef4792;p=egate.git More work on new MARC anchor functions. --- diff --git a/util/iso2709.c b/util/iso2709.c index d8f935c..54c32cd 100644 --- a/util/iso2709.c +++ b/util/iso2709.c @@ -4,7 +4,10 @@ * Europagate, 1994-1995. * * $Log: iso2709.c,v $ - * Revision 1.13 1995/03/30 07:33:32 adam + * Revision 1.14 1995/03/30 14:22:18 adam + * More work on new MARC anchor functions. + * + * Revision 1.13 1995/03/30 07:33:32 adam * New 2709 function: iso2709_mk. * First implementation of iso2709_a_insert. * @@ -230,11 +233,6 @@ Iso2709Rec iso2709_cvt (const char *buf) int dpos_n; if (p->identifier_length && identifier_flag) { - if (!((*fpp)->identifier = malloc (p->identifier_length+1))) - { - iso2709_rm (p); - return NULL; - } strncpyx ((*fpp)->identifier, buf+dpos+1, p->identifier_length-1); dpos_n = dpos += p->identifier_length; @@ -244,7 +242,7 @@ Iso2709Rec iso2709_cvt (const char *buf) } else { - (*fpp)->identifier = NULL; + *(*fpp)->identifier = '\0'; dpos_n = dpos; while (buf[dpos_n] != ISO2709_FS && buf[dpos_n] != ISO2709_RS && dpos_n < epos) @@ -262,13 +260,13 @@ Iso2709Rec iso2709_cvt (const char *buf) { if (buf[dpos] != ISO2709_FS && buf[dpos] != ISO2709_RS) fprintf (stderr, "Missing separator at end of field " - "in %s %s\n", dp->tag, (*fpp)->identifier ? - (*fpp)->identifier : ""); + "in %s %s\n", dp->tag, (*fpp)->identifier); break; } if (buf[dpos] == ISO2709_FS || buf[dpos] == ISO2709_RS) { - fprintf (stderr, "Unexpected separator inside field\n"); + fprintf (stderr, "Unexpected separator inside field %s %s\n", + dp->tag, (*fpp)->identifier); break; } fpp = &(*fpp)->next; @@ -293,7 +291,6 @@ void iso2709_rm (Iso2709Rec rec) for (field = dir->fields; field; field = field1) { - free (field->identifier); free (field->data); field1 = field->next; free (field); diff --git a/util/iso2709a.c b/util/iso2709a.c index 6469df1..e635fab 100644 --- a/util/iso2709a.c +++ b/util/iso2709a.c @@ -4,7 +4,10 @@ * Europagate, 1995. * * $Log: iso2709a.c,v $ - * Revision 1.2 1995/03/30 07:33:35 adam + * Revision 1.3 1995/03/30 14:22:18 adam + * More work on new MARC anchor functions. + * + * Revision 1.2 1995/03/30 07:33:35 adam * New 2709 function: iso2709_mk. * First implementation of iso2709_a_insert. * @@ -91,9 +94,17 @@ int iso2709_a_info_field (Iso2709Anchor anchor, if (tag) *tag = (*anchor->d0)->tag; if (indicator) + { *indicator = (*anchor->d0)->indicator; + if (*indicator && !**indicator) + *indicator = NULL; + } if (identifier) + { *identifier = (*anchor->f0)->identifier; + if (*identifier && !**identifier) + *identifier = NULL; + } if (data) *data = (*anchor->f0)->data; return 1; @@ -116,7 +127,6 @@ int iso2709_a_delete_field (Iso2709Anchor anchor) return 0; field = *anchor->f0; *anchor->f0 = field->next; - free (field->identifier); free (field->data); free (field); if (!*anchor->f0) @@ -201,21 +211,19 @@ int iso2709_a_insert (Iso2709Anchor a, } else dir->indicator = NULL; - dir->next = *a->d0; - *a->d0 = dir; + if (*a->d0) + a->d0 = &(*a->d0)->next; + dir->next = *a->d0; + *a->d0 = dir; dir->fields = NULL; a->f0 = &dir->fields; } if (!(field = malloc (sizeof(*field)))) return 0; if (identifier) - { - if (!(field->identifier = malloc (strlen (identifier)+1))) - return 0; strcpy (field->identifier, identifier); - } else - field->identifier = NULL; + *field->identifier = '\0'; if (!(field->data = malloc (strlen (data)+1))) return 0; strcpy (field->data, data); diff --git a/util/iso2709dump.c b/util/iso2709dump.c index 14cdd44..0aa0fa1 100644 --- a/util/iso2709dump.c +++ b/util/iso2709dump.c @@ -4,7 +4,10 @@ * Europagate, 1994-1995. * * $Log: iso2709dump.c,v $ - * Revision 1.8 1995/03/30 07:33:37 adam + * Revision 1.9 1995/03/30 14:22:18 adam + * More work on new MARC anchor functions. + * + * Revision 1.8 1995/03/30 07:33:37 adam * New 2709 function: iso2709_mk. * First implementation of iso2709_a_insert. * @@ -54,11 +57,7 @@ static Iso2709Rec copy_rec (Iso2709Rec rec_in) do { if (!iso2709_a_info_field (a_in, &tag, &indicator, &identifier, &data)) break; - printf ("[%s %s %s]", tag, indicator ? indicator : "", - identifier ? identifier : ""); -#if 1 iso2709_a_insert (a_out, tag, indicator, identifier, data); -#endif } while (iso2709_a_next (a_in)); iso2709_a_rm (a_in); iso2709_a_rm (a_out); @@ -212,6 +211,7 @@ int main (int argc, char **argv) if (!quiet) { iso2709_display (rec_input, stdout); + iso2709_display (rec_output, stdout); } if (outf && fwrite (obuf, 1, olen, outf) != olen) { diff --git a/util/iso2709o.c b/util/iso2709o.c index 1af8693..8588ea1 100644 --- a/util/iso2709o.c +++ b/util/iso2709o.c @@ -4,7 +4,10 @@ * Europagate, 1995. * * $Log: iso2709o.c,v $ - * Revision 1.1 1995/03/28 16:07:07 adam + * Revision 1.2 1995/03/30 14:22:19 adam + * More work on new MARC anchor functions. + * + * Revision 1.1 1995/03/28 16:07:07 adam * New function: iso2709_out. This function is the reverse of iso2709_cvt. * */ @@ -49,7 +52,7 @@ int iso2709_out (Iso2709Rec p, char **buf, int bsize) len += p->indicator_length; for (field = dir->fields; field; field = field->next) { - if (field->identifier) + if (*field->identifier) len += p->identifier_length; len += strlen (field->data); } @@ -93,7 +96,7 @@ int iso2709_out (Iso2709Rec p, char **buf, int bsize) } for (field = dir->fields; field; field = field->next) { - if (field->identifier) + if (*field->identifier) { op[data_p] = ISO2709_IDFS; memcpy (op + data_p+1, field->identifier,