Use nmem_init + nmem_exit to track memory usage easier.
[yaz-moved-to-github.git] / util / marcdump.c
index 8e9c4d8..4ecdc86 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (C) 1995-2006, Index Data ApS
+ * Copyright (C) 1995-2007, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: marcdump.c,v 1.46 2006-12-18 10:33:52 adam Exp $
+ * $Id: marcdump.c,v 1.50 2007-03-17 09:14:00 adam Exp $
  */
 
 #define _FILE_OFFSET_BITS 64
@@ -235,6 +235,15 @@ static void dump(const char *fname, const char *from, const char *to,
             r = fread (buf + 5, 1, rlen, inf);
             if (r < rlen)
                 break;
+            while (buf[len-1] != ISO2709_RS)
+            {
+                if (len > sizeof(buf)-2)
+                    break;
+                r = fread (buf + len, 1, 1, inf);
+                if (r != 1)
+                    break;
+                len++;
+            }
             if (split_fname)
             {
                 char fname[256];
@@ -318,7 +327,8 @@ int main (int argc, char **argv)
     const char *split_fname = 0;
     const char *leader_spec = 0;
     int write_using_libxml2 = 0;
-    
+
+    nmem_init();
 #if HAVE_LOCALE_H
     setlocale(LC_CTYPE, "");
 #endif
@@ -341,6 +351,15 @@ int main (int argc, char **argv)
                 fprintf(stderr, "%s: bad input format: %s\n", prog, arg);
                 exit(1);
             }
+#if YAZ_HAVE_XML2
+#else
+            if (input_format == YAZ_MARC_MARCXML 
+                || input_format == YAZ_MARC_XCHANGE)
+            {
+                fprintf(stderr, "%s: Libxml2 support not enabled\n", prog);
+                exit(3);
+            }
+#endif
             break;
         case 'o':
             /* dirty hack so we can make Libxml2 do the writing ..
@@ -424,6 +443,7 @@ int main (int argc, char **argv)
     }
     if (cfile)
         fclose (cfile);
+    nmem_exit();
     if (!no)
     {
         usage(prog);