Modified to work with yaz 1.0b3.
[ir-tcl-moved-to-github.git] / marc.c
diff --git a/marc.c b/marc.c
index 36f2774..9320d40 100644 (file)
--- a/marc.c
+++ b/marc.c
@@ -1,10 +1,25 @@
 /*
  * IR toolkit for tcl/tk
  * (c) Index Data 1995
+ * See the file LICENSE for details.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: marc.c,v $
- * Revision 1.2  1995-05-26 11:44:11  adam
+ * Revision 1.5  1995-06-30 12:39:26  adam
+ * Bug fix: loadFile didn't set record type.
+ * The MARC routines are a little less strict in the interpretation.
+ * Script display.tcl replaces the old marc.tcl.
+ * New interactive script: shell.tcl.
+ *
+ * Revision 1.4  1995/06/22  13:15:09  adam
+ * Feature: SUTRS. Setting getSutrs implemented.
+ * Work on display formats.
+ * Preferred record syntax can be set by the user.
+ *
+ * Revision 1.3  1995/05/29  08:44:26  adam
+ * Work on delete of objects.
+ *
+ * Revision 1.2  1995/05/26  11:44:11  adam
  * Bugs fixed. More work on MARC utilities and queries. Test
  * client is up-to-date again.
  *
 #define ISO2709_FS 036
 #define ISO2709_IDFS 037
 
-int atoi_n (const char *buf, int len)
+static int atoi_n (const char *buf, int len)
 {
     int val = 0;
 
+    if (!isdigit (buf[len-1]))
+        return 0;
     while (--len >= 0)
     {
         if (isdigit (*buf))
@@ -53,8 +70,6 @@ static int marc_compare (const char *f, const char *p)
     return *f - *p;
 }
 
-FILE *outf = stderr;
-
 char *ir_tcl_fread_marc (FILE *inf, size_t *size)
 {
     char length[5];
@@ -101,6 +116,11 @@ int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf,
         Tcl_AppendResult (interp, "Unknown MARC extract mode", NULL);
        return TCL_ERROR;
     }
+    if (!buf)
+    {
+        Tcl_AppendResult (interp, "Not a MARC record", NULL);
+        return TCL_ERROR;
+    }
     record_length = atoi_n (buf, 5);
     if (record_length < 25)
     {