Improved memory debugging for xmalloc/nmem.c. References to NMEM
[yaz-moved-to-github.git] / retrieval / d1_absyn.c
index ab1b3ac..c8479a4 100644 (file)
@@ -4,7 +4,16 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_absyn.c,v $
- * Revision 1.12  1997-09-17 12:10:34  adam
+ * Revision 1.14  1997-10-31 12:20:09  adam
+ * Improved memory debugging for xmalloc/nmem.c. References to NMEM
+ * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
+ * Bug fix: missing fclose in data1_read_espec1.
+ *
+ * Revision 1.13  1997/10/27 13:54:18  adam
+ * Changed structure field in data1 node to be simple string which
+ * is "unknown" to the retrieval system itself.
+ *
+ * Revision 1.12  1997/09/17 12:10:34  adam
  * YAZ version 1.4.
  *
  * Revision 1.11  1997/09/05 09:50:55  adam
@@ -158,6 +167,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
     data1_termlist *all = 0;
     int level = 0;
 
+    logf (LOG_DEBUG, "begin data1_read_absyn file=%s", file);
     if (!(f = yaz_path_fopen(data1_get_tabpath (dh), file, "r")))
     {
        logf(LOG_WARN|LOG_ERRNO, "%s", file);
@@ -190,10 +200,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                break;
        }
        if (!r)
-       {
-           fclose(f);
-           return res;
-       }
+            break;
        if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
            *args = '\0';
        if (!strcmp(cmd, "elm"))
@@ -263,7 +270,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                    new_element->tag = nmem_malloc(data1_nmem_get (dh),
                                                   sizeof(*new_element->tag));
                nt->which = DATA1T_string;
-               nt->value.string = xstrdup(p);
+               nt->value.string = nmem_strdup(data1_nmem_get (dh), p);
                nt->names = nmem_malloc(data1_nmem_get(dh), 
                                        sizeof(*new_element->tag->names));
                nt->names->name = nt->value.string;
@@ -317,19 +324,20 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                        return 0;
                    }
                    if (r < 2) /* is the structure qualified? */
-                       (*tp)->structure = DATA1S_word;
-                   else if (!data1_matchstr(structure, "w"))
-                       (*tp)->structure = DATA1S_word;
-                   else if (!data1_matchstr(structure, "p"))
-                       (*tp)->structure = DATA1S_phrase;
-
+                       (*tp)->structure = "w";
+                   else 
+                   {
+                       (*tp)->structure = nmem_malloc (data1_nmem_get (dh),
+                                                       strlen(structure)+1);
+                       strcpy ((*tp)->structure, structure);
+                   }
                    tp = &(*tp)->next;
                }
                while ((p = strchr(p, ',')) && *(++p));
                *tp = all; /* append any ALL entries to the list */
            }
 
-           new_element->name = xstrdup(name);
+           new_element->name = nmem_strdup(data1_nmem_get (dh), name);
        }
        else if (!strcmp(cmd, "all"))
        {
@@ -373,12 +381,13 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
                    return 0;
                }
                if (r < 2) /* is the structure qualified? */
-                   (*tp)->structure = DATA1S_word;
-               else if (!data1_matchstr(structure, "w"))
-                   (*tp)->structure = DATA1S_word;
-               else if (!data1_matchstr(structure, "p"))
-                   (*tp)->structure = DATA1S_phrase;
-               
+                   (*tp)->structure = "w";
+               else 
+               {
+                   (*tp)->structure = nmem_malloc (data1_nmem_get (dh),
+                                                   strlen(structure)+1);
+                   strcpy ((*tp)->structure, structure);
+               }
                (*tp)->next = 0;
                tp = &(*tp)->next;
            }
@@ -479,7 +488,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
            (*esetpp)->next = 0;
            if (*fname == '@')
                (*esetpp)->spec = 0;
-           else if (!((*esetpp)->spec = data1_read_espec1 (dh, fname, 0)))
+           else if (!((*esetpp)->spec = data1_read_espec1 (dh, fname)))
            {
                logf(LOG_WARN, "%s: Espec-1 read failed", file);
                fclose(f);
@@ -528,4 +537,7 @@ data1_absyn *data1_read_absyn (data1_handle dh, const char *file)
            return 0;
        }
     }
+    fclose(f);
+    logf (LOG_DEBUG, "end data1_read_absyn file=%s", file);
+    return res;
 }