OAI MARC display
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 4 Oct 2002 10:19:58 +0000 (10:19 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 4 Oct 2002 10:19:58 +0000 (10:19 +0000)
util/marcdisp.c
util/marcdump.c

index 8133832..78b4833 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2002, Index Data
  * See the file LICENSE for details.
  *
  * Copyright (c) 1995-2002, Index Data
  * See the file LICENSE for details.
  *
- * $Id: marcdisp.c,v 1.20 2002-10-02 15:51:52 adam Exp $
+ * $Id: marcdisp.c,v 1.21 2002-10-04 10:19:58 adam Exp $
  */
 
 #if HAVE_CONFIG_H
  */
 
 #if HAVE_CONFIG_H
@@ -58,19 +58,42 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
 
     if (xml)
     {
 
     if (xml)
     {
-        char str[40];
+        char str[80];
         int i;
         int i;
-        wrbuf_puts (wr, "<iso2709\n");
-        sprintf (str, " RecordStatus=\"%c\"\n", buf[5]);
-        wrbuf_puts (wr, str);
-        sprintf (str, " TypeOfRecord=\"%c\"\n", buf[6]);
-        wrbuf_puts (wr, str);
-        for (i = 1; i<=19; i++)
+        if (xml > 1)
         {
         {
-            sprintf (str, " ImplDefined%d=\"%c\"\n", i, buf[6+i]);
+            wrbuf_puts(
+                wr,
+                "<sequence xmlns=\"http://www.dlib.vt.edu/projects/OAi/marcxml/container\"\n"
+                
+                "  xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\"\n"
+                "    xsi:schemaLocation=\"http://www.openarchives.org/OAI/oai_marc\n"
+                "    http://www.openarchives.org/OAI/oai_marc.xsd\n"
+                "    http://www.dlib.vt.edu/projects/OAi/marcxml/container\n"
+                "    http://www.dlib.vt.edu/projects/OAi/marcxml/container.xsd\"\n"
+                );
+            wrbuf_puts(
+                wr,
+                "<oai_marc xmlns=\"http://www.openarchives.org/OIA/oai_marc\"" );
+            
+            sprintf (str, "status=\"%c\" type=\"%c\" catForm=\"%c\">\n",
+                     buf[5], buf[6], buf[7]);
             wrbuf_puts (wr, str);
         }
             wrbuf_puts (wr, str);
         }
-        wrbuf_puts (wr, ">\n");
+        else
+        {
+            wrbuf_puts (wr, "<iso2709\n");
+            sprintf (str, " RecordStatus=\"%c\"\n", buf[5]);
+            wrbuf_puts (wr, str);
+            sprintf (str, " TypeOfRecord=\"%c\"\n", buf[6]);
+            wrbuf_puts (wr, str);
+            for (i = 1; i<=19; i++)
+            {
+                sprintf (str, " ImplDefined%d=\"%c\"\n", i, buf[6+i]);
+                wrbuf_puts (wr, str);
+            }
+            wrbuf_puts (wr, ">\n");
+        }
     }
     if (debug)
     {
     }
     if (debug)
     {
@@ -115,19 +138,6 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
         memcpy (tag, buf+entry_p, 3);
        entry_p += 3;
         tag[3] = '\0';
         memcpy (tag, buf+entry_p, 3);
        entry_p += 3;
         tag[3] = '\0';
-        if (xml)
-        {
-            wrbuf_puts (wr, "<field tag=\"");
-            wrbuf_puts (wr, tag);
-            wrbuf_puts (wr, "\"");
-        }
-        else
-        {
-            if (debug)
-                wrbuf_puts (wr, "Tag: ");
-            wrbuf_puts (wr, tag);
-            wrbuf_puts (wr, " ");
-        }
        data_length = atoi_n (buf+entry_p, length_data_entry);
        entry_p += length_data_entry;
        data_offset = atoi_n (buf+entry_p, length_starting);
        data_length = atoi_n (buf+entry_p, length_data_entry);
        entry_p += length_data_entry;
        data_offset = atoi_n (buf+entry_p, length_starting);
@@ -142,6 +152,33 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
         }
         else if (!memcmp (tag, "00", 2))
             identifier_flag = 0;
         }
         else if (!memcmp (tag, "00", 2))
             identifier_flag = 0;
+
+
+        if (xml)
+        {
+            if (xml > 1)
+            {
+                if (identifier_flag)
+                    wrbuf_puts (wr, "<varfield id=\"");
+                else
+                    wrbuf_puts (wr, "<fixfield id=\"");
+                wrbuf_puts (wr, tag);
+                wrbuf_puts (wr, "\"");
+            }
+            else
+            {
+                wrbuf_puts (wr, "<field tag=\"");
+                wrbuf_puts (wr, tag);
+                wrbuf_puts (wr, "\"");
+            }
+        }
+        else
+        {
+            if (debug)
+                wrbuf_puts (wr, "Tag: ");
+            wrbuf_puts (wr, tag);
+            wrbuf_puts (wr, " ");
+        }
         
         if (identifier_flag)
        {
         
         if (identifier_flag)
        {
@@ -152,7 +189,10 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
                 if (xml)
                 {
                     char nostr[30];
                 if (xml)
                 {
                     char nostr[30];
-                    sprintf (nostr, " Indicator%d=\"%c\"", j+1, buf[i]);
+                    if (xml > 1)
+                        sprintf (nostr, " i%d=\"%c\"", j+1, buf[i]);
+                    else
+                        sprintf (nostr, " Indicator%d=\"%c\"", j+1, buf[i]);
                     wrbuf_puts (wr, nostr);
                 }
                 else
                     wrbuf_puts (wr, nostr);
                 }
                 else
@@ -177,7 +217,10 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
                i++;
                 if (xml)
                 {
                i++;
                 if (xml)
                 {
-                    wrbuf_puts (wr, "  <subfield code=\"");
+                    if (xml > 1)
+                        wrbuf_puts (wr, "  <subfield label=\"");
+                    else
+                        wrbuf_puts (wr, "  <subfield code=\"");
                     for (j = 1; j<identifier_length; j++, i++)
                         wrbuf_putc (wr, buf[i]);
                     wrbuf_puts (wr, "\">");
                     for (j = 1; j<identifier_length; j++, i++)
                         wrbuf_putc (wr, buf[i]);
                     wrbuf_puts (wr, "\">");
@@ -209,6 +252,8 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
                     wrbuf_puts(wr, "&lt;");
                 else if (xml && buf[i] == '&')
                     wrbuf_puts(wr, "&amp;");
                     wrbuf_puts(wr, "&lt;");
                 else if (xml && buf[i] == '&')
                     wrbuf_puts(wr, "&amp;");
+                else if (xml && buf[i] == '"')
+                    wrbuf_puts(wr, "&quot;");
                 else
                     wrbuf_putc (wr, buf[i]);
                i++;
                 else
                     wrbuf_putc (wr, buf[i]);
                i++;
@@ -221,7 +266,17 @@ int yaz_marc_decode (const char *buf, WRBUF wr, int debug, int bsize, int xml)
        if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS)
            wrbuf_puts (wr, "  <!-- no separator at end of field -->\n");
         if (xml)
        if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS)
            wrbuf_puts (wr, "  <!-- no separator at end of field -->\n");
         if (xml)
-            wrbuf_puts (wr, "</field>\n");
+        {
+            if (xml > 1)
+            {
+                if (identifier_flag)
+                    wrbuf_puts (wr, "</varfield>\n");
+                else
+                    wrbuf_puts (wr, "</fixfield>\n");
+            }
+            else
+                wrbuf_puts (wr, "</field>\n");
+        }
     }
     if (xml)
         wrbuf_puts (wr, "</iso2709>\n");
     }
     if (xml)
         wrbuf_puts (wr, "</iso2709>\n");
index eb197ef..b3ff370 100644 (file)
@@ -3,7 +3,7 @@
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
- * $Id: marcdump.c,v 1.16 2002-03-18 21:33:48 adam Exp $
+ * $Id: marcdump.c,v 1.17 2002-10-04 10:19:58 adam Exp $
  */
 
 #if HAVE_CONFIG_H
  */
 
 #if HAVE_CONFIG_H
@@ -29,7 +29,7 @@
 
 static void usage(const char *prog)
 {
 
 static void usage(const char *prog)
 {
-    fprintf (stderr, "Usage: %s [-c cfile] [-x] [-v] file...\n", prog);
+    fprintf (stderr, "Usage: %s [-c cfile] [-x] [-O] [-v] file...\n", prog);
 } 
 
 int main (int argc, char **argv)
 } 
 
 int main (int argc, char **argv)
@@ -44,7 +44,7 @@ int main (int argc, char **argv)
     int xml = 0;
     FILE *cfile = 0;
 
     int xml = 0;
     FILE *cfile = 0;
 
-    while ((r = options("vc:x", argv, argc, &arg)) != -2)
+    while ((r = options("vc:xO", argv, argc, &arg)) != -2)
     {
        int count;
        no++;
     {
        int count;
        no++;
@@ -58,6 +58,9 @@ int main (int argc, char **argv)
         case 'x':
             xml = 1;
             break;
         case 'x':
             xml = 1;
             break;
+        case 'O':
+            xml = 2;
+            break;
         case 0:
            inf = fopen (arg, "r");
            count = 0;
         case 0:
            inf = fopen (arg, "r");
            count = 0;