Hack: When tags 00? are used, every separator (DC[1-3]) marks
[egate.git] / util / iso2709.c
index bfb691f..9df6e25 100644 (file)
@@ -1,14 +1,28 @@
 /*
-   Iso2709 record management
-
-   Europagate, 1994-1995.
-
-   $Log: iso2709.c,v $
-   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.
-
+ * Iso2709 record management
+ *
+ * Europagate, 1994-1995.
+ *
+ * $Log: iso2709.c,v $
+ * Revision 1.8  1995/03/08 12:03:15  adam
+ * Hack: When tags 00? are used, every separator (DC[1-3]) marks
+ * the end of the data field.
+ *
+ * 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'.
@@ -97,6 +111,11 @@ 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);
@@ -138,7 +157,7 @@ Iso2709Rec iso2709_cvt (const char *buf)
         }
         else
             dp->indicator = NULL;
-
+        printf ("tag=%.3s, dpos = %d, (0%o)\n", dp->tag, dpos, dpos);
         if (memcmp (dp->tag, "00", 2))
             tag00 = 0;
         else
@@ -157,14 +176,15 @@ 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 (buf[dpos] == ISO2709_FS)
+            if (buf[dpos] == ISO2709_FS || buf[dpos] == ISO2709_RS || tag00)
                 break;
             
             fpp = &(*fpp)->next;