source: trunk/gsdl/packages/yaz/util/marcdisp.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 1995-2000, Index Data
3 * See the file LICENSE for details.
4 *
5 * $Log$
6 * Revision 1.1 2000/08/03 03:12:07 johnmcp
7 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
8 *
9 * Revision 1.11 2000/02/29 13:44:55 adam
10 * Check for config.h (currently not generated).
11 *
12 * Revision 1.10 2000/02/05 10:47:19 adam
13 * Identifier-length and indicator-lenght no longer set to 2 (forced).
14 *
15 * Revision 1.9 1999/12/21 16:24:48 adam
16 * More robust ISO2709 handling (in case of real bad formats).
17 *
18 * Revision 1.8 1999/11/30 13:47:12 adam
19 * Improved installation. Moved header files to include/yaz.
20 *
21 * Revision 1.7 1997/09/24 13:29:40 adam
22 * Added verbose option -v to marcdump utility.
23 *
24 * Revision 1.6 1997/09/04 07:52:27 adam
25 * Moved atoi_n function to separate source file.
26 *
27 * Revision 1.5 1997/05/01 15:08:15 adam
28 * Added log_mask_str_x routine.
29 *
30 * Revision 1.4 1995/09/29 17:12:34 quinn
31 * Smallish
32 *
33 * Revision 1.3 1995/09/27 15:03:03 quinn
34 * Modified function heads & prototypes.
35 *
36 * Revision 1.2 1995/05/16 08:51:12 quinn
37 * License, documentation, and memory fixes
38 *
39 * Revision 1.1 1995/04/10 10:28:46 quinn
40 * Added copy of CCL and MARC display
41 *
42 */
43
44#if HAVE_CONFIG_H
45#include <config.h>
46#endif
47
48#include <stdio.h>
49#include <string.h>
50#include <ctype.h>
51#include <yaz/marcdisp.h>
52#include <yaz/yaz-util.h>
53
54int marc_display_ex (const char *buf, FILE *outf, int debug)
55{
56 int entry_p;
57 int record_length;
58 int indicator_length;
59 int identifier_length;
60 int base_address;
61 int length_data_entry;
62 int length_starting;
63 int length_implementation;
64
65 if (!outf)
66 outf = stdout;
67 record_length = atoi_n (buf, 5);
68 if (record_length < 25)
69 return -1;
70 if (isdigit(buf[10]))
71 indicator_length = atoi_n (buf+10, 1);
72 else
73 indicator_length = 2;
74 if (isdigit(buf[11]))
75 identifier_length = atoi_n (buf+11, 1);
76 else
77 identifier_length = 2;
78 base_address = atoi_n (buf+12, 4);
79
80 length_data_entry = atoi_n (buf+20, 1);
81 length_starting = atoi_n (buf+21, 1);
82 length_implementation = atoi_n (buf+22, 1);
83
84 if (debug)
85 {
86 fprintf (outf, "Record length %5d\n", record_length);
87 fprintf (outf, "Indicator length %5d\n", indicator_length);
88 fprintf (outf, "Identifier length %5d\n", identifier_length);
89 fprintf (outf, "Base address %5d\n", base_address);
90 fprintf (outf, "Length data entry %5d\n", length_data_entry);
91 fprintf (outf, "Length starting %5d\n", length_starting);
92 fprintf (outf, "Length implementation %5d\n", length_implementation);
93 }
94 for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
95 {
96 entry_p += 3+length_data_entry+length_starting;
97 if (entry_p >= record_length)
98 return -1;
99 }
100 base_address = entry_p+1;
101 for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
102 {
103 int data_length;
104 int data_offset;
105 int end_offset;
106 int i, j;
107 char tag[4];
108
109 memcpy (tag, buf+entry_p, 3);
110 entry_p += 3;
111 tag[3] = '\0';
112 if (debug)
113 fprintf (outf, "Tag: ");
114 fprintf (outf, "%s ", tag);
115 data_length = atoi_n (buf+entry_p, length_data_entry);
116 entry_p += length_data_entry;
117 data_offset = atoi_n (buf+entry_p, length_starting);
118 entry_p += length_starting;
119 i = data_offset + base_address;
120 end_offset = i+data_length-1;
121 if (debug)
122 fprintf (outf, " Ind: ");
123 if (memcmp (tag, "00", 2) && indicator_length)
124 {
125 for (j = 0; j<indicator_length; j++)
126 fprintf (outf, "%c", buf[i++]);
127 }
128 if (debug)
129 fprintf (outf, " Fields: ");
130 while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset)
131 {
132 if (memcmp (tag, "00", 2) && identifier_length)
133 {
134 i++;
135 fprintf (outf, " $");
136 for (j = 1; j<identifier_length; j++)
137 fprintf (outf, "%c", buf[i++]);
138 fprintf (outf, " ");
139 while (buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS &&
140 buf[i] != ISO2709_FS && i < end_offset)
141 fprintf (outf, "%c", buf[i++]);
142 }
143 else
144 fprintf (outf, "%c", buf[i++]);
145 }
146 fprintf (outf, "\n");
147 if (i < end_offset)
148 fprintf (outf, "-- separator but not at end of field\n");
149 if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS)
150 fprintf (outf, "-- no separator at end of field\n");
151 }
152 return record_length;
153}
154
155int marc_display (const char *buf, FILE *outf)
156{
157 return marc_display_ex (buf, outf, 0);
158}
159
160
Note: See TracBrowser for help on using the repository browser.