Fixed error with linked fields for UNIMARC clone records.
authoroleg <oleg>
Sun, 9 Nov 2003 11:49:49 +0000 (11:49 +0000)
committeroleg <oleg>
Sun, 9 Nov 2003 11:49:49 +0000 (11:49 +0000)
recctrl/inline.c
recctrl/inline.h
recctrl/marcread.c

index 4b09b69..d921715 100644 (file)
@@ -1,3 +1,6 @@
+/*
+    $Id: inline.c,v 1.3 2003-11-09 11:49:49 oleg Exp $
+*/
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
@@ -6,7 +9,7 @@
 
 static void inline_destroy_subfield_recursive(inline_subfield *p);
 
-static inline_field *inline_mk_field(void)
+inline_field *inline_mk_field(void)
 {
     inline_field *p = (inline_field *) xmalloc(sizeof(*p));
 
@@ -73,59 +76,50 @@ static void inline_destroy_subfield_recursive(inline_subfield *p)
        xfree(p);
     }
 }
-inline_field *inline_parse(const char *s)
+int inline_parse(inline_field *pif, const char *tag, const char *s)
 {
-    inline_field *pf = inline_mk_field();
+    inline_field *pf = pif;
     char *p = (char *)s;
     
     if (!pf)
-       return 0;
-
-    if ((sscanf(p, "%3s", pf->name)) != 1)
-       return 0;
+       return -1;
+       
+    if (pf->name[0] == '\0')
+    {
+       if ((sscanf(p, "%3s", pf->name)) != 1)
+           return -2;
 
-    p += SZ_FNAME;
+       p += SZ_FNAME;
 
-    if (!memcmp(pf->name, "00", 2))
-    {
-       pf->list = inline_mk_subfield(0);
-       pf->list->data = xstrdup(p);
+       if (!memcmp(pf->name, "00", 2))
+       {
+           pf->list = inline_mk_subfield(0);
+           pf->list->data = xstrdup(p);
+       }
+       else
+       {
+           if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) != 2)
+               return -3;
+       }
     }
     else
     {
-       if ((sscanf(p, "%c%c", pf->ind1, pf->ind2)) == 2)
+       inline_subfield *psf = inline_mk_subfield(0);
+       
+       sscanf(tag, "%1s", psf->name);
+       psf->data = xstrdup(p);
+       
+       if (!pf->list)
        {
-           char *pdup;
-           inline_subfield *parent = 0;
-           
-           p += 2*SZ_IND;
-    
-           if (!strlen(p) || *p != '$')
-           {
-               return pf;
-           }
-           
-           pdup = p = xstrdup(p);
-           
-           for (p=strtok(p, "$"); p; p = strtok(NULL, "$"))
-           {
-               inline_subfield *psf = inline_mk_subfield(parent);
-               
-               if (!psf)
-                   break;
-                   
-               if (!parent)
-                   pf->list = psf;
-               else
-                   parent->next = psf;
-               parent = psf;   
-               sscanf(p, "%1s", psf->name);
-               p += SZ_SFNAME;
-               psf->data = (char *) xstrdup(p);
-           }
-           
-           xfree(pdup);
+           pf->list = psf;
+       }
+       else
+       {
+           inline_subfield *last = pf->list;
+           while (last->next)
+               last = last->next;
+           last->next = psf;
        }
     }
-    return pf;
+    return 0;
 }
index 70ba71d..d30531d 100644 (file)
@@ -1,3 +1,6 @@
+/*
+    $Id: inline.h,v 1.2 2003-11-09 11:49:49 oleg Exp $
+*/
 #ifndef INLINE_H
 #define INLINE_H
 
@@ -23,7 +26,8 @@ typedef struct inline_subfield
     struct inline_subfield *parent;
 } inline_subfield;
 
-inline_field *inline_parse(const char *s);
+inline_field *intline_mk_field(void);
+int inline_parse(inline_field *pf, const char *tag, const char *s);
 void inline_destroy_field(inline_field *p);
 
 #ifdef __cplusplus
index f3214ff..9b231d3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: marcread.c,v 1.21 2003-08-21 10:29:00 adam Exp $
+/* $Id: marcread.c,v 1.22 2003-11-09 11:49:49 oleg Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -210,37 +210,7 @@ static data1_node *grs_read_iso2709 (struct grs_read_info *p, int marc_xml)
         i0 = i;
         while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset)
         {
-
-           if (!memcmp(tag, "4", 1) && (!yaz_matchstr(absynName, "UNIMARC")||
-               !yaz_matchstr(absynName, "RUSMARC")))
-           {
-               int go = 1;
-               data1_node *res =
-                   data1_mk_tag_n (p->dh, p->mem,
-                                    buf+i+1, identifier_length-1, 
-                                    0 /* attr */, parent);
-                i += identifier_length;
-                i0 = i;
-               do {
-                   while (buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS &&
-                        buf[i] != ISO2709_FS && i < end_offset)
-                   {
-                       i++;
-                   }
-                   if (!memcmp(buf+i+1, "1", 1) && i<end_offset)
-                   {
-                       go = 0;
-                   }
-                   else
-                   {
-                       buf[i] = '$';
-                   }               
-               } while (go && i < end_offset);
-               
-               data1_mk_text_n (p->dh, p->mem, buf + i0, i - i0, res);
-               i0 = i;
-           }
-            else if (memcmp (tag, "00", 2) && identifier_length)
+           if (memcmp (tag, "00", 2) && identifier_length)
             {
                data1_node *res;
                if (marc_xml)
@@ -340,7 +310,6 @@ static char *get_data(data1_node *n, int *len)
     *len = strlen(r);
     return r;
 }
-
 static data1_node *lookup_subfield(data1_node *node, const char *name)
 {
     data1_node *p;
@@ -433,15 +402,38 @@ static inline_subfield *cat_inline_subfield(mc_subfield *psf, char *buf, inline_
     return pisf; 
 }
 static void cat_inline_field(mc_field *pf, char *buf, data1_node *subfield)
-{
-    
+{    
     if (!pf || !subfield)
        return;
 
-    for (;subfield; subfield = subfield->next)
+    for (;subfield;)
     {
        int len;
-       inline_field *pif = inline_parse(get_data(subfield,&len));
+       inline_field *pif=NULL;
+       data1_node *psubf;
+       
+       if (yaz_matchstr(subfield->u.tag.tag, "1"))
+       {
+           subfield = subfield->next;
+           continue;
+       }
+       
+       psubf = subfield;
+       pif = inline_mk_field();
+       do
+       {
+           int i;
+           if ((i=inline_parse(pif, psubf->u.tag.tag, get_data(psubf, &len)))<0)
+           {
+               logf(LOG_WARN, "inline subfield ($%s): parse error",
+                   psubf->u.tag.tag);
+               inline_destroy_field(pif);
+               return; 
+           }
+           psubf = psubf->next;
+       } while (psubf && yaz_matchstr(psubf->u.tag.tag, "1"));
+       
+       subfield = psubf;
        
        if (pif && !yaz_matchstr(pif->name, pf->name))
        {