Added copy of CCL and MARC display
authorSebastian Hammer <quinn@indexdata.com>
Mon, 10 Apr 1995 10:28:46 +0000 (10:28 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Mon, 10 Apr 1995 10:28:46 +0000 (10:28 +0000)
util/marcdisp.c [new file with mode: 0644]
util/marcdump.c [new file with mode: 0644]
util/query.c [new file with mode: 0644]

diff --git a/util/marcdisp.c b/util/marcdisp.c
new file mode 100644 (file)
index 0000000..714c561
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: marcdisp.c,v $
+ * Revision 1.1  1995-04-10 10:28:46  quinn
+ * Added copy of CCL and MARC display
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <marcdisp.h>
+
+#define ISO2709_RS 035
+#define ISO2709_FS 036
+#define ISO2709_IDFS 037
+
+int atoi_n (const char *buf, int len)
+{
+    int val = 0;
+
+    while (--len >= 0)
+    {
+        if (isdigit (*buf))
+            val = val*10 + (*buf - '0');
+       buf++;
+    }
+    return val;
+}
+
+int marc_display (const char *buf, FILE *outf)
+{
+    int entry_p;
+    int record_length;
+    int indicator_length;
+    int identifier_length;
+    int base_address;
+    int length_data_entry;
+    int length_starting;
+    int length_implementation;
+
+    record_length = atoi_n (buf, 5);
+    if (record_length < 25)
+        return -1;
+    indicator_length = atoi_n (buf+10, 1);
+    identifier_length = atoi_n (buf+11, 1);
+    base_address = atoi_n (buf+12, 4);
+
+    length_data_entry = atoi_n (buf+20, 1);
+    length_starting = atoi_n (buf+21, 1);
+    length_implementation = atoi_n (buf+22, 1);
+
+    for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
+        entry_p += 3+length_data_entry+length_starting;
+    base_address = entry_p+1;
+    for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
+    {
+        int data_length;
+       int data_offset;
+       int end_offset;
+       int i, j;
+       char tag[4];
+
+        memcpy (tag, buf+entry_p, 3);
+       entry_p += 3;
+        tag[3] = '\0';
+       fprintf (outf, "%s ", tag);
+       data_length = atoi_n (buf+entry_p, length_data_entry);
+       entry_p += length_data_entry;
+       data_offset = atoi_n (buf+entry_p, length_starting);
+       entry_p += length_starting;
+       i = data_offset + base_address;
+       end_offset = i+data_length-1;
+        if (memcmp (tag, "00", 2) && indicator_length)
+       {
+            for (j = 0; j<indicator_length; j++)
+               fprintf (outf, "%c", buf[i++]);
+       }
+       while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset)
+       {
+            if (memcmp (tag, "00", 2) && identifier_length)
+           {
+               i++;
+               fprintf (outf, " $"); 
+                for (j = 1; j<identifier_length; j++)
+                    fprintf (outf, "%c", buf[i++]);
+               fprintf (outf, " ");
+               while (buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS &&
+                      buf[i] != ISO2709_FS && i < end_offset)
+                   fprintf (outf, "%c", buf[i++]);
+           }
+           else
+               fprintf (outf, "%c", buf[i++]);
+       }
+       fprintf (outf, "\n");
+       if (i < end_offset)
+           fprintf (outf, "-- separator but not at end of field\n");
+       if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS)
+           fprintf (outf, "-- no separator at end of field\n");
+    }
+    return record_length;
+}
+
diff --git a/util/marcdump.c b/util/marcdump.c
new file mode 100644 (file)
index 0000000..2b254cf
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: marcdump.c,v $
+ * Revision 1.1  1995-04-10 10:28:47  quinn
+ * Added copy of CCL and MARC display
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <marcdisp.h>
+
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2
+#endif
+int main (int argc, char **argv)
+{
+    FILE *inf;
+    long file_size;
+    char *buf;
+    int r;
+
+    if (argc < 2)
+    {
+        fprintf (stderr, "usage\n%s <file>\n", *argv);
+       exit (1);
+    }
+    inf = fopen (argv[1], "r");
+    if (!inf)
+    {
+        fprintf (stderr, "%s: cannot open %s:%s\n",
+                *argv, argv[1], strerror (errno));
+        exit (1);
+    }
+    if (fseek (inf, 0L, SEEK_END))
+    {
+        fprintf (stderr, "%s: cannot seek in %s:%s\n",
+                *argv, argv[1], strerror (errno));
+        exit (1);
+    }
+    file_size = ftell (inf);    
+    if (fseek (inf, 0L, SEEK_SET))
+    {
+        fprintf (stderr, "%s: cannot seek in %s:%s\n",
+                *argv, argv[1], strerror (errno));
+        exit (1);
+    }
+    buf = malloc (file_size);
+    if (!buf)
+    {
+        fprintf (stderr, "%s: cannot malloc: %s\n",
+                *argv, strerror (errno));
+        exit (1);
+    }
+    if (fread (buf, 1, file_size, inf) != file_size)
+    {
+        fprintf (stderr, "%s: cannot read %s: %s\n",
+                *argv, argv[1], strerror (errno));
+        exit (1);
+    }
+    while ((r = marc_display (buf, stdout)) > 0)
+        buf += r;
+    exit (0);
+}
diff --git a/util/query.c b/util/query.c
new file mode 100644 (file)
index 0000000..e194430
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: query.c,v $
+ * Revision 1.1  1995-04-10 10:28:47  quinn
+ * Added copy of CCL and MARC display
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#include <odr.h>
+#include <proto.h>
+
+static Z_Complex *makecomplex(ODR o, char **buf);
+static Z_Operand *makesimple(ODR o, char **buf);
+Z_RPNStructure *makerpn(ODR o, char **buf);
+
+void skip_spaces(char**p)
+{
+    while (**p && isspace(**p))
+       (*p)++;
+}
+
+static Z_Operand *makesimple(ODR o, char **buf)
+{
+    Z_Operand *r;
+    Z_AttributesPlusTerm *t;
+    char *b;
+
+    r = odr_malloc(o, sizeof(*r));
+    if (**buf == 's' && *((*buf) + 1) == '=')
+    {
+       char *b = odr_malloc(o, 100);
+
+       r->which = Z_Operand_resultSetId;
+       r->u.resultSetId = b;
+       (*buf)++;
+       (*buf)++;
+       while (**buf && !isspace(**buf))
+           *(b++) = *((*buf)++);
+       *b = 0;
+       return r;
+    }
+    else if (**buf != '"')
+       return 0;
+    (*buf)++;
+    r->which = Z_Operand_APT;
+    r->u.attributesPlusTerm = t = odr_malloc(o, sizeof(*t));
+    t->num_attributes = 0;
+    t->attributeList = 0;
+    t->term = odr_malloc(o, sizeof(*t->term));
+    t->term->which = Z_Term_general;
+    t->term->u.general = odr_malloc(o, sizeof(Odr_oct));
+    t->term->u.general->buf = odr_malloc(o, 100);
+    t->term->u.general->size = 100;
+    t->term->u.general->len = 0;
+    b = (char*) t->term->u.general->buf;
+    while (**buf && **buf != '"')
+    {
+       *(b++) = *((*buf)++);
+       t->term->u.general->len++;
+    }
+    if (**buf != '"')
+       return 0;
+    (*buf)++;
+    return r;
+}
+
+static Z_Complex *makecomplex(ODR o, char **buf)
+{
+    Z_Complex *r;
+    char op[100], *b;
+
+    r = odr_malloc(o, sizeof(*r));
+    r->operator = odr_malloc(o, sizeof(*r->operator));
+
+    b = op;
+    while (**buf && !isspace(**buf))
+       *(b++) = *((*buf)++);
+    *b = 0;
+    if (!strcmp(op, "and"))
+       r->operator->which = Z_Operator_and;
+    else if (!strcmp(op, "or"))
+       r->operator->which = Z_Operator_or;
+    else if (!strcmp(op, "not"))
+       r->operator->which = Z_Operator_and_not;
+    r->operator->u.and = "";
+    while (**buf && !isspace(**buf))
+       (*buf)++;
+    if (!(r->s1 = makerpn(o, buf)))
+       return 0;
+    if (!(r->s2 = makerpn(o, buf)))
+       return 0;
+    return r;
+}
+    
+Z_RPNStructure *makerpn(ODR o, char **buf)
+{
+    Z_RPNStructure *r;
+
+    r = odr_malloc(o, sizeof(*r));
+    skip_spaces(buf);
+    if (**buf == '"' || **buf == 's')
+    {
+       r->which = Z_RPNStructure_simple;
+       if (!(r->u.simple = makesimple(o, buf)))
+           return 0;
+       return r;
+    }
+    r->which = Z_RPNStructure_complex;
+    if (!(r->u.complex = makecomplex(o, buf)))
+       return 0;
+    return r;
+}