Process all source with doyxgen
[idzebra-moved-to-github.git] / data1 / d1_marc.c
index a1fc8d1..a04ef89 100644 (file)
@@ -1,6 +1,6 @@
-/* $Id: d1_marc.c,v 1.4 2003-11-13 23:57:41 adam Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
-   Index Data Aps
+/* $Id: d1_marc.c,v 1.12 2005-02-02 19:37:27 adam Exp $
+   Copyright (C) 1995-2005
+   Index Data ApS
 
 This file is part of the Zebra server.
 
@@ -26,13 +26,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <stdlib.h>
 #include <string.h>
 
-#include <yaz/oid.h>
 #include <yaz/log.h>
+#include <yaz/oid.h>
 #include <yaz/marcdisp.h>
 #include <yaz/readconf.h>
 #include <yaz/xmalloc.h>
 #include <yaz/tpath.h>
-#include <data1.h>
+#include <idzebra/data1.h>
 
 data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
 {
@@ -45,7 +45,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
     
     if (!(f = data1_path_fopen(dh, file, "r")))
     {
-       yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
+       yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
        return 0;
     }
 
@@ -70,7 +70,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d:Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d:Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
@@ -80,13 +80,13 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
            if ((res->reference = oid_getvalbyname(argv[1])) == VAL_NONE)
            {
-               yaz_log(LOG_WARN, "%s:%d: Unknown tagset reference '%s'",
+               yaz_log(YLOG_WARN, "%s:%d: Unknown tagset reference '%s'",
                        file, lineno, argv[1]);
                continue;
            }
@@ -95,7 +95,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
@@ -105,7 +105,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
@@ -115,7 +115,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
@@ -125,7 +125,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
@@ -135,7 +135,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
@@ -145,14 +145,14 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
        {
            if (argc != 2)
            {
-               yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
+               yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno,
                        *argv);
                continue;
            }
            res->force_identifier_length = atoi(argv[1]);
        }
        else
-           yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'", file, lineno,
+           yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'", file, lineno,
                    *argv);
 
     fclose(f);
@@ -164,7 +164,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file)
  * Locate some data under this node. This routine should handle variants
  * prettily.
  */
-static char *get_data(data1_node *n, int *len)
+static char *get_data(data1_node *n, int *len, int chop)
 {
     char *r;
 
@@ -174,15 +174,21 @@ static char *get_data(data1_node *n, int *len)
         {
             int i;
             *len = n->u.data.len;
-
-            for (i = 0; i<*len; i++)
-                if (!d1_isspace(n->u.data.data[i]))
-                    break;
-            while (*len && d1_isspace(n->u.data.data[*len - 1]))
-                (*len)--;
-            *len = *len - i;
-            if (*len > 0)
-                return n->u.data.data + i;
+           
+           if (chop)
+            {
+               for (i = 0; i<*len; i++)
+                   if (!d1_isspace(n->u.data.data[i]))
+                       break;
+               while (*len && d1_isspace(n->u.data.data[*len - 1]))
+                   (*len)--;
+               *len = *len - i;
+               if (*len > 0)
+                   return n->u.data.data + i;
+           }
+           else
+               if (*len > 0)
+                   return n->u.data.data;
         }
         if (n->which == DATA1N_tag)
             n = n->child;
@@ -231,16 +237,15 @@ static int nodetomarc(data1_handle dh,
     char *op;
     data1_node *field, *subf;
 
-    data1_pr_tree (dh, n, stdout);
-
-    yaz_log (LOG_DEBUG, "nodetomarc");
+#if 0
     data1_pr_tree(dh, n, stdout);
+#endif
+    yaz_log (YLOG_DEBUG, "nodetomarc");
 
     memcpy (leader+5, p->record_status, 1);
     memcpy (leader+6, p->implementation_codes, 4);
     memint (leader+10, p->indicator_length, 1);
     memint (leader+11, p->identifier_length, 1);
-    memint (leader+12, base_address, 5);
     memcpy (leader+17, p->user_systems, 3);
     memint (leader+20, p->length_data_entry, 1);
     memint (leader+21, p->length_starting, 1);
@@ -266,7 +271,7 @@ static int nodetomarc(data1_handle dh,
        else if (!strcmp(field->u.tag.tag, "leader"))
        {
            int dlen = 0;
-           char *dbuf = get_data(subf, &dlen);
+           char *dbuf = get_data(subf, &dlen, 0);
            if (dlen > 24)
                dlen = 24;
            if (dbuf && dlen > 0)
@@ -311,7 +316,7 @@ static int nodetomarc(data1_handle dh,
         {
             if (!control_field)
                 len += p->identifier_length;
-           get_data(subf, &dlen);
+           get_data(subf, &dlen, control_field ? 0 : 1);
             len += dlen;
         }
     }
@@ -322,6 +327,11 @@ static int nodetomarc(data1_handle dh,
        *buf = (char *)xrealloc(*buf, *size = len);
        
     op = *buf;
+
+    /* we know the base address now */
+    memint (leader+12, base_address, 5);
+
+    /* copy temp leader to real output buf op */
     memcpy (op, leader, 24);
     memint (op, len, 5);
     
@@ -387,9 +397,9 @@ static int nodetomarc(data1_handle dh,
                if (!strcmp(xa->name, "ind1"))
                    indicator_data[0] = xa->value[0];
                if (!strcmp(xa->name, "ind2"))
-                   indicator_data[1] = xa->value[1];
+                   indicator_data[1] = xa->value[0];
                if (!strcmp(xa->name, "ind3"))
-                   indicator_data[2] = xa->value[2];
+                   indicator_data[2] = xa->value[0];
            }
        }
        if (!control_field)
@@ -416,14 +426,14 @@ static int nodetomarc(data1_handle dh,
                    }
                }
                else if (subf->which != DATA1N_tag)
-                    yaz_log(LOG_WARN, "Malformed fields for marc output.");
+                    yaz_log(YLOG_WARN, "Malformed fields for marc output.");
                 else
                     identifier = subf->u.tag.tag;
                 op[data_p] = ISO2709_IDFS;
                 memcpy (op + data_p+1, identifier, p->identifier_length-1);
                 data_p += p->identifier_length;
             }
-           data = get_data(subf, &dlen);
+           data = get_data(subf, &dlen, control_field ? 0 : 1);
             memcpy (op + data_p, data, dlen);
             data_p += dlen;
         }