X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=util%2Fiso2709.c;h=2f6bc37009b949ab5632b9b02fcb7de9be8ecfbe;hb=96a9d6aeb02795cecf237b892c8ac28073e4a785;hp=62cb8fe0a7e0d6e88719f7bd0bf6eda63cd98b4c;hpb=5bc115d3b598f5ad198411dcd033a91a8356c9be;p=egate.git diff --git a/util/iso2709.c b/util/iso2709.c index 62cb8fe..2f6bc37 100644 --- a/util/iso2709.c +++ b/util/iso2709.c @@ -1,12 +1,32 @@ /* - gw-res.c: Iso2709 record management - - Europagate, 1994-1995. - - $Log: iso2709.c,v $ - Revision 1.1 1995/02/09 17:27:10 adam - Initial revision - + * Iso2709 record management + * + * Europagate, 1994-1995. + * + * $Log: iso2709.c,v $ + * Revision 1.7 1995/02/22 21:28:03 adam + * Changed header. + * + * Revision 1.5 1995/02/22 15:24:14 adam + * Function iso2709_cvt makes a litte check for the format. It returns + * NULL if the buffer parameter can never be a MARC record. + * + * Revision 1.4 1995/02/15 17:45:44 adam + * Bug fix in iso2709 module. + * + * Revision 1.3 1995/02/10 17:05:18 adam + * New function iso2709_display to display MARC records in a + * line-by-line format. The iso2709_cvt function no longer + * prints the record to stderr. + * + * Revision 1.2 1995/02/10 16:50:32 adam + * Indicator field moved to 'struct iso2709_dir' from 'struct + * iso2709_field'. + * Function iso2709_rm implemented - to delete a MARC record. + * + * Revision 1.1.1.1 1995/02/09 17:27:11 adam + * Initial version of email gateway under CVS control. + * */ #include @@ -78,6 +98,7 @@ Iso2709Rec iso2709_cvt (const char *buf) if (!(p = malloc (sizeof(*p)))) return NULL; + /* deal with record label (24 characters) */ p->record_length = atoin (buf, 5); strncpyx (p->record_status, buf+5, 1); strncpyx (p->implementation_codes, buf+6, 4); @@ -86,13 +107,18 @@ Iso2709Rec iso2709_cvt (const char *buf) p->base_address = atoin (buf+12, 4); strncpyx (p->user_systems, buf+17, 3); + if (p->record_length < 26) + { + free (p); + return NULL; + } p->length_data_entry = atoin (buf+20, 1); p->length_starting = atoin (buf+21, 1); p->length_implementation = atoin (buf+22, 1); strncpyx (p->future_use, buf+23, 1); + /* deal with directory */ dpp = &p->directory; - *dpp = NULL; while (buf[pos] != ISO2709_FS) { @@ -108,16 +134,12 @@ Iso2709Rec iso2709_cvt (const char *buf) dpp = &(*dpp)->next; } pos++; -#if 0 - fprintf (stderr, "indicator_len=%d, identifier_len=%d\n", - p->indicator_length, p->identifier_length); -#endif + /* deal with datafields */ for (dp = p->directory; dp; dp = dp->next) { int tag00; struct iso2709_field **fpp; int dpos = pos+dp->offset; - char *save_indicator = NULL; fpp = &dp->fields; @@ -125,18 +147,17 @@ Iso2709Rec iso2709_cvt (const char *buf) (*fpp)->next = NULL; if (p->indicator_length && memcmp (dp->tag, "00", 2)) { - (*fpp)->indicator = malloc (p->indicator_length+1); - strncpyx ((*fpp)->indicator, buf+dpos, p->indicator_length); + dp->indicator = malloc (p->indicator_length+1); + strncpyx (dp->indicator, buf+dpos, p->indicator_length); dpos += p->indicator_length; } else - (*fpp)->indicator = NULL; + dp->indicator = NULL; if (memcmp (dp->tag, "00", 2)) tag00 = 0; else tag00 = 1; - fprintf (stderr, "%s", dp->tag); while (1) { int dpos_n; @@ -151,28 +172,42 @@ Iso2709Rec iso2709_cvt (const char *buf) (*fpp)->identifier = NULL; dpos_n = dpos; - while (buf[dpos_n] != ISO2709_FS && buf[dpos_n] != ISO2709_IDFS) + while (buf[dpos_n] != ISO2709_FS && buf[dpos_n] != ISO2709_IDFS && + buf[dpos_n] != ISO2709_RS) dpos_n++; (*fpp)->data = malloc (dpos_n - dpos + 1); strncpyx ((*fpp)->data, buf+dpos, dpos_n - dpos); dpos = dpos_n; - if (!save_indicator && (*fpp)->indicator) - fprintf (stderr, " %s", (*fpp)->indicator); - if ((*fpp)->identifier) - fprintf (stderr, " *%s", (*fpp)->identifier); - fprintf (stderr, " %s", (*fpp)->data); - if (buf[dpos] == ISO2709_FS) + if (buf[dpos] == ISO2709_FS || buf[dpos] == ISO2709_RS) break; - save_indicator = (*fpp)->indicator; fpp = &(*fpp)->next; *fpp = malloc (sizeof(**fpp)); (*fpp)->next = NULL; - (*fpp)->indicator = save_indicator; } - fprintf (stderr, "\n"); } return p; } + +void iso2709_rm (Iso2709Rec rec) +{ + struct iso2709_dir *dir, *dir1; + + for (dir = rec->directory; dir; dir = dir1) + { + struct iso2709_field *field, *field1; + + for (field = dir->fields; field; field = field1) + { + free (field->identifier); + free (field->data); + field1 = field->next; + free (field); + } + free (dir->indicator); + dir1 = dir->next; + free (dir); + } +}