19.3. Interpreting Commands from a File

For all practical purposes, any interpreter is pretty useless if it works only interactively. I have added a 'source' built-in command to 'sic_builtin.c', which takes lines of input from a file and evaluates them using 'sic_repl.c' in much the same way as lines typed at the prompt are evaluated otherwise. Here is the built-in handler:

/* List of built in functions. */
#define builtin_functions               \
        BUILTIN(exit,           0, 1)   \
        BUILTIN(load,           1, 1)   \
        BUILTIN(source,         1, -1)  \
        BUILTIN(unload,         1, -1)

BUILTIN_DECLARATION (source)
{
  int status = SIC_OKAY;
  int i;

  for (i = 1; status == SIC_OKAY && argv[i]; ++i)
    status = source (sic, argv[i]);

  return status;
}

And the 'source' function from 'sic_repl.c':

 int source (Sic ...

Get GNU Autoconf, Automake, and Libtool now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.