Definition of CPP changed. Output function can be customized.
[egate.git] / fml / fmltest.c
index 1947ba2..13dda1e 100644 (file)
@@ -2,7 +2,21 @@
  * FML interpreter. Europagate, 1995
  *
  * $Log: fmltest.c,v $
- * Revision 1.2  1995/02/07 16:09:24  adam
+ * 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).
  */
 
 #include <stdio.h>
-#include "fml.h"
+#include <string.h>
+#include <stdlib.h>
+
+#include <fmlmarc.h>
 
 static FILE *inf;
 
@@ -27,6 +44,8 @@ int main (int argc, char **argv)
 {
     Fml fml;
     int nfiles = 0;
+    int interactive = 0;
+    Iso2709Rec rec = NULL;
 
     fml = fml_open ();
     while (-- argc > 0)
@@ -35,10 +54,42 @@ int main (int argc, char **argv)
         if (**argv == '-')
         {
             if (argv[0][1] == 'd')
-                fml->debug = 1;
+                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] == '2')
+            {
+                if (argc > 1)
+                {
+                    char *buf;
+                    FILE *inf;
+                    ++argv;
+                    --argc;
+
+                    inf = fopen (*argv, "r");
+                    if (!inf)
+                    {
+                        fprintf (stderr, "cannot open record `%s'\n", *argv);
+                        exit (1);
+                    }
+                    if ((buf = iso2709_read (inf)))
+                    {
+                        rec = iso2709_cvt (buf);
+                        free (buf);
+                    }
+                    else
+                    {
+                        fprintf (stderr, "no record in `%s'\n", *argv);
+                        exit (1);
+                    }
+                    fclose (inf);
+                }
+            }
             else
             {
-                fprintf (stderr, "uknown option `%s'\n", *argv);
+                fprintf (stderr, "unknown option `%s'\n", *argv);
                 exit (1);
             }
         }
@@ -48,7 +99,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;
@@ -62,5 +113,40 @@ int main (int argc, char **argv)
         fml_preprocess (fml);
         fml_exec (fml);
     }
+    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';
+                if (*arg == '!' && rec)
+                {
+                    nargv[0] = arg+1;
+                    nargv[1] = " ";
+                    nargv[2] = marc_to_str (fml, rec);
+                    printf ("passing '%s'\n", nargv[2]);
+                    nargv[3] = NULL;
+                }
+                else
+                {
+                    nargv[0] = arg;
+                    nargv[1] = NULL;
+                }
+                fml_exec_call_argv (fml, nargv);
+            }
+        }
+    }
     return 0;
 }