* FML interpreter. Europagate, 1995
*
* $Log: fmltest.c,v $
- * Revision 1.1 1995/02/06 13:48:09 adam
- * Initial revision
+ * 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
+ * The \ character is no longer INCLUDED when terminating a token.
+ * Major changes in tokenization routines. Bug fixes in expressions
+ * with lists (fml_sub0).
+ *
+ * Revision 1.1.1.1 1995/02/06 13:48:10 adam
+ * First version of the FML interpreter. It's slow and memory isn't
+ * freed properly. In particular, the FML nodes aren't released yet.
*
*/
#include <stdio.h>
-#include "fml.h"
+#include <string.h>
+#include <stdlib.h>
+
+#include <fmlmarc.h>
+
+char *prog;
+static FILE *inf;
+
+static int inf_read (void)
+{
+ return getc (inf);
+}
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 ();
- if (argc >= 2 && (!strcmp (argv[1], "d") ||
- !strcmp (argv[1], "debug")))
+ while (-- argc > 0)
{
- fml->debug = 1;
+ ++argv;
+ if (**argv == '-')
+ {
+ if (argv[0][1] == 'd')
+ 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, "unknown option `%s'\n", *argv);
+ exit (1);
+ }
+ }
+ else
+ {
+ nfiles++;
+ inf = fopen (*argv, "r");
+ if (!inf)
+ {
+ fprintf (stderr, "cannot open FML file `%s'\n", *argv);
+ exit (1);
+ }
+ fml->read_func = inf_read;
+ fml_preprocess (fml);
+ fml_exec (fml);
+ fclose (inf);
+ }
+ }
+ if (!nfiles)
+ {
+ 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);
+ }
+ }
}
- fml_preprocess (fml);
- fml_exec (fml);
return 0;
}