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