imain(3)

Section: Interp SDK (3)
Updated: 2009-08-23

NAME

imain - implements interp's outer interpreter

SYNOPSIS

#include itypes.h
#include interp.h
#include imain.h

Interp_T icreate( void );
void setargs( Interp_T cp, int argc, char * argv[], int * optind );
int iexecute( Interp_T cp, char * buffer, int trace_flag );
int iexecute_cmd( Interp_T cp, char * buffer, int trace_flag );
int imain( Interp_T cp, char * prompt, int redirect_flag, int echo_flag, int trace_flag, int continue_flag );

DESCRIPTION

This API allows you to instantiate a complete interpreter, including the outer interpreter with pre-defined macros, directives (handles commands beginning with "#" in column one), in-line comments (starting with "__"), and the macro processor, and initiate an interactive (or file-based) session.  

LIST OF FUNCTIONS

Function
Description
icreate
Creates a new interpreter instance by calling interp_new() (See interp(3)), and adds the predefined macros. (See the documentation - "Simple Interpreter for Embedded Computers", Appendix A, for details.) Returns a pointer to the control block that was created for this new instance. When called repeatedly, system constant 6 is reset to its initial value (from the first call), but nothing else happens.
setargs
Sets the values of three system constants. The second argument sets 24K (argc), the third one sets 25K (argv[]), and the fourth sets 26K (the pointer to optind.) Typically, this function is called immediately after icreate(), as the second half of the instantiation/initialization process.
iexecute
This function calls interp() to execute the contents of buffer, displays a message (if there was an error), and returns zero for success or one of interp's error codes (>0 = error, -1 = terminated because of "$" command.) trace_flag enables verbose-style error messages featuring function call traceback (0 = disable, non-zero = enable.)
iexecute_cmd
This function strips inline comments, expands macros, and calls interp() to execute the contents of buffer, displays a message (if there was an error), and returns zero for success or one of interp's error codes (>0 = error, -1 = terminated because of "$" command.) trace_flag enables verbose-style error messages featuring function call traceback (0 = disable, non-zero = enable.)
imain
This function initiates an interactive session if prompt points to a zero-terminated string, or a file-based session if prompt is NULL. This function does not return until the QUIT ("$") command, an error (if redirect_flag is non-zero) or an end-of-file is encountered. If continue_flag is non-zero, errors from redirected input do not stop execution. If redirect_flag is non-zero input redirection was used on the command line and the prompt is automatically suppressed. Typically, imain() is called after initialization has been completed. If input redirection is in use, and echo_flag is non-zero, the redirected input is echoed to the output before being processed (before comment stripping and macro expansion.) If trace_flag is non-zero, verbose-style error messages (featuring function call traceback) are enabled. When this function returns 0 (termination by EOF), or -1 (termination by "$" command), a "normal" termination has occurred. If it returns >0, an error was found while processing redirected input. Errors found while processing terminal (not file-based) input do not cause imain() to terminate prematurely.

SEE ALSO

interp(3)