License, documentation, and memory fixes
[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.3  1995-05-16 08:51:12  quinn
8  * License, documentation, and memory fixes
9  *
10  * Revision 1.2  1995/05/15  11:56:56  quinn
11  * Debuggng & adjustments.
12  *
13  * Revision 1.1  1995/04/10  10:28:47  quinn
14  * Added copy of CCL and MARC display
15  *
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <marcdisp.h>
22 #include <dmalloc.h>
23
24 #ifndef SEEK_SET
25 #define SEEK_SET 0
26 #endif
27 #ifndef SEEK_END
28 #define SEEK_END 2
29 #endif
30  
31 int main (int argc, char **argv)
32 {
33     FILE *inf;
34     long file_size;
35     char *buf;
36     int r;
37
38     if (argc < 2)
39     {
40         fprintf (stderr, "usage\n%s <file>\n", *argv);
41         exit (1);
42     }
43     inf = fopen (argv[1], "r");
44     if (!inf)
45     {
46         fprintf (stderr, "%s: cannot open %s:%s\n",
47                  *argv, argv[1], strerror (errno));
48         exit (1);
49     }
50     if (fseek (inf, 0L, SEEK_END))
51     {
52         fprintf (stderr, "%s: cannot seek in %s:%s\n",
53                  *argv, argv[1], strerror (errno));
54         exit (1);
55     }
56     file_size = ftell (inf);    
57     if (fseek (inf, 0L, SEEK_SET))
58     {
59         fprintf (stderr, "%s: cannot seek in %s:%s\n",
60                  *argv, argv[1], strerror (errno));
61         exit (1);
62     }
63     buf = malloc (file_size);
64     if (!buf)
65     {
66         fprintf (stderr, "%s: cannot malloc: %s\n",
67                  *argv, strerror (errno));
68         exit (1);
69     }
70     if (fread (buf, 1, file_size, inf) != file_size)
71     {
72         fprintf (stderr, "%s: cannot read %s: %s\n",
73                  *argv, argv[1], strerror (errno));
74         exit (1);
75     }
76     while ((r = marc_display (buf, stdout)) > 0)
77         buf += r;
78     exit (0);
79 }