X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=fml%2Ffmltest.c;h=996460723569ce7c70cc331374c6794ae68df89c;hb=e1ec9d39463f431383547891f38e30f2ff17842c;hp=6c07b3a8597f476ec21f84d9fe9e58ce065d37af;hpb=332f815feae8b1614c42b0a436f2ab0276d817d8;p=egate.git diff --git a/fml/fmltest.c b/fml/fmltest.c index 6c07b3a..9964607 100644 --- a/fml/fmltest.c +++ b/fml/fmltest.c @@ -1,8 +1,72 @@ /* + * Copyright (c) 1995, the EUROPAGATE consortium (see below). + * + * The EUROPAGATE consortium members are: + * + * University College Dublin + * Danmarks Teknologiske Videnscenter + * An Chomhairle Leabharlanna + * Consejo Superior de Investigaciones Cientificas + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of EUROPAGATE or the project partners may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * 3. Users of this software (implementors and gateway operators) agree to + * inform the EUROPAGATE consortium of their use of the software. This + * information will be used to evaluate the EUROPAGATE project and the + * software, and to plan further developments. The consortium may use + * the information in later publications. + * + * 4. Users of this software agree to make their best efforts, when + * documenting their use of the software, to acknowledge the EUROPAGATE + * consortium, and the role played by the software in their work. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE + * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF + * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND + * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +/* * FML interpreter. Europagate, 1995 * * $Log: fmltest.c,v $ - * Revision 1.3 1995/02/09 13:07:15 adam + * Revision 1.9 1995/05/16 09:39:35 adam + * LICENSE. + * + * Revision 1.8 1995/03/02 08:06:10 adam + * Fml function strsub implemented. New test files marc[45].fml. + * New test options in fmltest. + * + * Revision 1.7 1995/02/23 08:32:06 adam + * Changed header. + * + * Revision 1.5 1995/02/10 15:50:56 adam + * MARC interface implemented. Minor bugs fixed. fmltest can + * be used to format single MARC records. New function '\list' + * implemented. + * + * Revision 1.4 1995/02/09 16:06:08 adam + * FML can be called from the outside multiple times by the functions: + * fml_exec_call and fml_exec_call_str. + * An interactive parameter (-i) to fmltest starts a shell-like + * interface to FML by using the fml_exec_call_str function. + * + * Revision 1.3 1995/02/09 13:07:15 adam * Nodes are freed now. Many bugs fixed. * * Revision 1.2 1995/02/07 16:09:24 adam @@ -17,8 +81,12 @@ */ #include -#include "fml.h" +#include +#include + +#include +char *prog; static FILE *inf; static int inf_read (void) @@ -30,7 +98,13 @@ int main (int argc, char **argv) { Fml fml; int nfiles = 0; + int marc_show = 0; + int interactive = 0; + const char *iso2709_fname = NULL; + const char *format_func = NULL; + int number_of_records = 10000; + prog = *argv; fml = fml_open (); while (-- argc > 0) { @@ -41,9 +115,36 @@ int main (int argc, char **argv) fml->debug |= 1; else if (argv[0][1] == 'm') fml->debug |= 2; + else if (argv[0][1] == 'i') + interactive = 1; + else if (argv[0][1] == 's') + marc_show = 1; + else if (argv[0][1] == 'n') + { + if (argc > 1) + { + number_of_records = atoi (*++argv); + --argc; + } + } + else if (argv[0][1] == '2') + { + if (argc > 2) + { + iso2709_fname = *++argv; + --argc; + format_func = *++argv; + --argc; + } + else + { + fprintf (stderr, "missing marcfile and format\n"); + exit (1); + } + } else { - fprintf (stderr, "uknown option `%s'\n", *argv); + fprintf (stderr, "unknown option `%s'\n", *argv); exit (1); } } @@ -53,7 +154,7 @@ int main (int argc, char **argv) inf = fopen (*argv, "r"); if (!inf) { - fprintf (stderr, "cannot open `%s'\n", *argv); + fprintf (stderr, "cannot open FML file `%s'\n", *argv); exit (1); } fml->read_func = inf_read; @@ -67,5 +168,60 @@ int main (int argc, char **argv) fml_preprocess (fml); fml_exec (fml); } + else if (iso2709_fname) + { + FILE *inf; + char *buf; + const char *nargv[5]; + Iso2709Rec rec; + int no = 0; + + inf = fopen (iso2709_fname, "r"); + if (!inf) + { + fprintf (stderr, "cannot open %s\n", iso2709_fname); + exit (1); + } + while (no < number_of_records && (buf = iso2709_read (inf))) + { + rec = iso2709_cvt (buf); + free (buf); + nargv[0] = "\\"; + nargv[1] = format_func; + nargv[2] = " \\list"; + nargv[4] = NULL; + nargv[3]= marc_to_str (fml, rec); + if (marc_show) + printf ("\n[%s]\n", nargv[3]); + iso2709_rm (rec); + fml_exec_call_argv (fml, nargv); + no++; + } + fclose (inf); + } + else + { + if (interactive) + { + char arg[128]; + + while (1) + { + char *cp; + const char *nargv[4]; + + printf ("\nFML>"); + fflush (stdout); + + if (!fgets (arg, 127, stdin)) + break; + if ((cp = strchr (arg, '\n'))) + *cp = '\0'; + nargv[0] = arg; + nargv[1] = NULL; + fml_exec_call_argv (fml, nargv); + } + } + } return 0; }