ttyemit moved from kernel directory. Minor editing in gw-db.h
[egate.git] / util / iso2709.c
index d8f935c..d79e422 100644 (file)
@@ -4,7 +4,13 @@
  * Europagate, 1994-1995.
  *
  * $Log: iso2709.c,v $
- * Revision 1.13  1995/03/30 07:33:32  adam
+ * Revision 1.15  1995/03/31 10:42:41  adam
+ * Bug fix.
+ *
+ * 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.
  *
@@ -168,6 +174,7 @@ Iso2709Rec iso2709_cvt (const char *buf)
         }
         (*dpp)->next = NULL;
         (*dpp)->fields = NULL;
+        (*dpp)->indicator = NULL;
         strncpyx ((*dpp)->tag, buf+pos, 3);
         pos += 3;
         (*dpp)->length = atoin (buf+pos, p->length_data_entry);
@@ -191,6 +198,11 @@ Iso2709Rec iso2709_cvt (const char *buf)
         int dpos = pos+dp->offset;
         int epos = pos+dp->offset+dp->length-1;
 
+        if (epos <= dpos)
+        {
+            iso2709_rm (p);
+            return NULL;
+        }
         fpp = &dp->fields;
 
         if (!(*fpp = malloc (sizeof(**fpp))))
@@ -230,11 +242,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 +251,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)
@@ -258,17 +265,17 @@ Iso2709Rec iso2709_cvt (const char *buf)
             strncpyx ((*fpp)->data, buf+dpos, dpos_n - dpos);
             dpos = dpos_n;
             
-            if (dpos == epos)
+            if (dpos >= epos)
             {
                 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 +300,6 @@ void iso2709_rm (Iso2709Rec rec)
 
         for (field = dir->fields; field; field = field1)
         {
-            free (field->identifier);
             free (field->data);
             field1 = field->next;
             free (field);