X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=util%2Fiso2709dump.c;h=663dd64769b0d2008e4c5a0080f49b5c414feb1d;hb=d5632f532e0757b5c538da730a4afe0bb7de0c94;hp=6757ea973355f093ed3c29f49c279bbf968468dc;hpb=3f6af0f3aa9f114cf562c28f2ed0b954e4c5d659;p=egate.git diff --git a/util/iso2709dump.c b/util/iso2709dump.c index 6757ea9..663dd64 100644 --- a/util/iso2709dump.c +++ b/util/iso2709dump.c @@ -1,9 +1,18 @@ /* - Iso2709 record management - - Europagate, 1994-1995. - - iso2709dump.c,v + * Iso2709 record management + * + * Europagate, 1994-1995. + * + * $Log: iso2709dump.c,v $ + * Revision 1.7 1995/03/28 16:07:07 adam + * New function: iso2709_out. This function is the reverse of iso2709_cvt. + * + * Revision 1.6 1995/03/27 12:52:18 adam + * A little more verbose in marc dump. + * + * Revision 1.5 1995/02/22 21:32:36 adam + * Changed header. + * * Revision 1.3 1995/02/10 17:05:18 adam * New function iso2709_display to display MARC records in a * line-by-line format. The iso2709_cvt function no longer @@ -21,20 +30,154 @@ #include #include +#include #include +static char *prog; + int main (int argc, char **argv) { char *buf; Iso2709Rec rec; + int no = 0; + int start_pos = 0; + int end_pos = 99999; + char *output_file = NULL; + char *input_file = NULL; + int verbose = 0; + int quiet = 0; + FILE *outf = NULL; + FILE *inf = stdin; - while ((buf = iso2709_read (stdin))) + prog = *argv; + while (--argc > 0) + { + if (**++argv == '-') + { + switch (argv[0][1]) + { + case 'h': + case 'H': + fprintf (stderr, "iso2709dump [options] [file]\n"); + fprintf (stderr, "If no file is specified stdin is used\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -p no Starting position\n"); + fprintf (stderr, " -l end Ending position\n"); + fprintf (stderr, " -o file Raw MARC output file\n"); + fprintf (stderr, " -v Verbose\n"); + fprintf (stderr, " -q Quiet mode\n"); + exit (1); + case 'p': + if (argv[0][2]) + start_pos = atoi (argv[0]+2); + else if (argc > 0) + { + --argc; + start_pos = atoi (*++argv); + } + else + { + fprintf (stderr, "%s: missing start pos\n", prog); + exit (1); + } + break; + case 'l': + if (argv[0][2]) + end_pos = atoi (argv[0]+2); + else if (argc > 0) + { + --argc; + end_pos = atoi (*++argv); + } + else + { + fprintf (stderr, "%s: missing end pos\n", prog); + exit (1); + } + break; + case 'o': + if (argv[0][2]) + output_file = argv[0]+2; + else if (argc > 0) + { + --argc; + output_file = *++argv; + } + else + { + fprintf (stderr, "%s: missing output file\n", prog); + exit (1); + } + break; + case 'v': + verbose = 1; + break; + case 'q': + quiet = 1; + break; + default: + fprintf (stderr, "%s: unknown option %s; use -h for help\n", + prog, *argv); + exit (1); + } + } + else + input_file = *argv; + } + if (input_file) + { + inf = fopen (input_file, "r"); + if (!inf) + { + fprintf (stderr, "%s: cannot open %s: %s\n", + prog, input_file, strerror (errno)); + exit (1); + } + } + if (output_file) + { + outf = fopen (output_file, "w"); + if (!outf) + { + fprintf (stderr, "%s: cannot open %s: %s\n", + prog, output_file, strerror (errno)); + exit (1); + } + } + while ((buf = iso2709_read (inf))) { - rec = iso2709_cvt (buf); - iso2709_display (rec, stderr); + if (no >= start_pos && no <= end_pos) + { + char *obuf; + int olen; + + rec = iso2709_cvt (buf); + if (!quiet) + printf ("------- %d --------\n", no); + if (!rec) + { + if (!quiet) + printf ("Bad record\n"); + fprintf (stderr, "%s: bad record at position %d\n", prog, no); + break; + } + olen = iso2709_out (rec, &obuf, 0); + if (!quiet) + iso2709_display (rec, stdout); + if (outf && fwrite (obuf, 1, olen, outf) != olen) + { + fprintf (stderr, "%s: write fail of %s: %s\n", + prog, output_file, strerror (errno)); + exit (1); + } + free (obuf); + iso2709_rm (rec); + } free (buf); - iso2709_rm (rec); + no++; } + if (outf) + fclose (outf); return 0; }