Debuggng & adjustments.
[yaz-moved-to-github.git] / util / marcdump.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: marcdump.c,v $
7  * Revision 1.2  1995-05-15 11:56:56  quinn
8  * Debuggng & adjustments.
9  *
10  * Revision 1.1  1995/04/10  10:28:47  quinn
11  * Added copy of CCL and MARC display
12  *
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <errno.h>
18 #include <marcdisp.h>
19 #include <dmalloc.h>
20
21 #ifndef SEEK_SET
22 #define SEEK_SET 0
23 #endif
24 #ifndef SEEK_END
25 #define SEEK_END 2
26 #endif
27  
28 int main (int argc, char **argv)
29 {
30     FILE *inf;
31     long file_size;
32     char *buf;
33     int r;
34
35     if (argc < 2)
36     {
37         fprintf (stderr, "usage\n%s <file>\n", *argv);
38         exit (1);
39     }
40     inf = fopen (argv[1], "r");
41     if (!inf)
42     {
43         fprintf (stderr, "%s: cannot open %s:%s\n",
44                  *argv, argv[1], strerror (errno));
45         exit (1);
46     }
47     if (fseek (inf, 0L, SEEK_END))
48     {
49         fprintf (stderr, "%s: cannot seek in %s:%s\n",
50                  *argv, argv[1], strerror (errno));
51         exit (1);
52     }
53     file_size = ftell (inf);    
54     if (fseek (inf, 0L, SEEK_SET))
55     {
56         fprintf (stderr, "%s: cannot seek in %s:%s\n",
57                  *argv, argv[1], strerror (errno));
58         exit (1);
59     }
60     buf = malloc (file_size);
61     if (!buf)
62     {
63         fprintf (stderr, "%s: cannot malloc: %s\n",
64                  *argv, strerror (errno));
65         exit (1);
66     }
67     if (fread (buf, 1, file_size, inf) != file_size)
68     {
69         fprintf (stderr, "%s: cannot read %s: %s\n",
70                  *argv, argv[1], strerror (errno));
71         exit (1);
72     }
73     while ((r = marc_display (buf, stdout)) > 0)
74         buf += r;
75     exit (0);
76 }