2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation, in whole or in part, for any purpose, is hereby granted,
15 * 1. This copyright and permission notice appear in all copies of the
16 * software and its documentation. Notices of copyright or attribution
17 * which appear at the beginning of any file must remain unchanged.
19 * 2. The names of EUROPAGATE or the project partners may not be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * 3. Users of this software (implementors and gateway operators) agree to
24 * inform the EUROPAGATE consortium of their use of the software. This
25 * information will be used to evaluate the EUROPAGATE project and the
26 * software, and to plan further developments. The consortium may use
27 * the information in later publications.
29 * 4. Users of this software agree to make their best efforts, when
30 * documenting their use of the software, to acknowledge the EUROPAGATE
31 * consortium, and the role played by the software in their work.
33 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38 * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39 * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40 * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41 * USE OR PERFORMANCE OF THIS SOFTWARE.
45 * Iso2709 record management
47 * Europagate, 1994-1995.
49 * $Log: iso2709dump.c,v $
50 * Revision 1.11 1995/05/16 09:40:54 adam
53 * Revision 1.10 1995/03/31 09:43:24 adam
54 * Removed test display.
56 * Revision 1.9 1995/03/30 14:22:18 adam
57 * More work on new MARC anchor functions.
59 * Revision 1.8 1995/03/30 07:33:37 adam
60 * New 2709 function: iso2709_mk.
61 * First implementation of iso2709_a_insert.
63 * Revision 1.7 1995/03/28 16:07:07 adam
64 * New function: iso2709_out. This function is the reverse of iso2709_cvt.
66 * Revision 1.6 1995/03/27 12:52:18 adam
67 * A little more verbose in marc dump.
69 * Revision 1.5 1995/02/22 21:32:36 adam
72 * Revision 1.3 1995/02/10 17:05:18 adam
73 * New function iso2709_display to display MARC records in a
74 * line-by-line format. The iso2709_cvt function no longer
75 * prints the record to stderr.
77 * Revision 1.2 1995/02/10 16:50:33 adam
78 * Indicator field moved to 'struct iso2709_dir' from 'struct
80 * Function iso2709_rm implemented - to delete a MARC record.
82 * Revision 1.1.1.1 1995/02/09 17:27:11 adam
83 * Initial version of email gateway under CVS control.
95 static Iso2709Rec copy_rec (Iso2709Rec rec_in)
98 Iso2709Anchor a_in, a_out;
99 char *tag, *indicator, *identifier, *data;
101 rec_out = iso2709_mk();
103 a_in = iso2709_a_mk (rec_in);
104 a_out = iso2709_a_mk (rec_out);
107 if (!iso2709_a_info_field (a_in, &tag, &indicator, &identifier, &data))
109 iso2709_a_insert (a_out, tag, indicator, identifier, data);
110 } while (iso2709_a_next (a_in));
112 iso2709_a_rm (a_out);
116 int main (int argc, char **argv)
122 char *output_file = NULL;
123 char *input_file = NULL;
139 fprintf (stderr, "iso2709dump [options] [file]\n");
140 fprintf (stderr, "If no file is specified stdin is used\n");
141 fprintf (stderr, "Options:\n");
142 fprintf (stderr, " -p no Starting position\n");
143 fprintf (stderr, " -l end Ending position\n");
144 fprintf (stderr, " -o file Raw MARC output file\n");
145 fprintf (stderr, " -v Verbose\n");
146 fprintf (stderr, " -q Quiet mode\n");
150 start_pos = atoi (argv[0]+2);
154 start_pos = atoi (*++argv);
158 fprintf (stderr, "%s: missing start pos\n", prog);
164 end_pos = atoi (argv[0]+2);
168 end_pos = atoi (*++argv);
172 fprintf (stderr, "%s: missing end pos\n", prog);
178 output_file = argv[0]+2;
182 output_file = *++argv;
186 fprintf (stderr, "%s: missing output file\n", prog);
206 fprintf (stderr, "%s: missing filter\n", prog);
211 fprintf (stderr, "%s: unknown option %s; use -h for help\n",
221 inf = fopen (input_file, "r");
224 fprintf (stderr, "%s: cannot open %s: %s\n",
225 prog, input_file, strerror (errno));
231 outf = fopen (output_file, "w");
234 fprintf (stderr, "%s: cannot open %s: %s\n",
235 prog, output_file, strerror (errno));
239 while ((buf = iso2709_read (inf)))
241 if (no >= start_pos && no <= end_pos)
245 Iso2709Rec rec_input;
246 Iso2709Rec rec_output;
248 rec_input = iso2709_cvt (buf);
250 printf ("------- %d --------\n", no);
254 printf ("Bad record\n");
255 fprintf (stderr, "%s: bad record at position %d\n", prog, no);
258 olen = iso2709_out (rec_input, &obuf, 0);
259 rec_output = copy_rec (rec_input);
261 iso2709_display (rec_input, stdout);
262 if (outf && fwrite (obuf, 1, olen, outf) != olen)
264 fprintf (stderr, "%s: write fail of %s: %s\n",
265 prog, output_file, strerror (errno));
269 iso2709_rm (rec_input);
270 iso2709_rm (rec_output);