The function prog_c is used to initialize the command interpreter. Recall the structure of this function :
void prog_c(int argc, char *argv[], char *A, char B[], int n, char *pr, int cas);
The last integer parameter must be 1 to tell the interpreter that it will be run non-interactively. If the string pr is not NULL, the interpreter will execute the command contained in it. It will then return. The functions load_cmd or loadcmd can be used to load programs contained in character strings or files in the command directory respectively. The function
void Exec_interp_command(char *h);
executes the command contained in the string h. It can be for instance the name of a program.
We reproduce below the source file test_in.c (in the directory test) that is self-explanatory.
#include "interp.h"
FUNCTION *Funcs;
pfi *proc[]={
};
int
main(void)
{
char h[50],
h2[1000],
*k[3];
/*------ Initialization of the command interpreter ---------------*/
Funcs = Funcs_interp;
_NBFONC = _NBFONC0;
prog_c(0, NULL, "interp.ini", NULL, 0, NULL, 1);
/*----------------------------------------------------------------*/
/*------ We load the program file 'magic' ------------------------*/
if (loadcmd("magic") == 0)
printf("magic loaded\n");
else
return 1;
/*----------------------------------------------------------------*/
/*------ We run one of the programs ------------------------------*/
sprintf(h, "magic x\n");
Exec_interp_command(h);
/*----------------------------------------------------------------*/
/*------ We write a program ('example') in
the string h2 -------------------------------------------*/
memset(h , 0, 50);
memset(h2 , 0, 1000);
sprintf(h, ":example\n");
strcat(h2, h);
memset(h , 0, 50);
sprintf(h, "1\n");
strcat(h2, h);
memset(h , 0, 50);
sprintf(h, "0\n");
strcat(h2, h);
memset(h , 0, 50);
sprintf(h, "-1\n");
strcat(h2, h);
memset(h , 0, 50);
sprintf(h, "mon test_x.out\n");
strcat(h2, h);
memset(h , 0, 50);
sprintf(h, "magicb\n");
strcat(h2, h);
memset(h , 0, 50);
sprintf(h, "end_mon\n");
strcat(h2, h);
k[0] = NULL;
k[1] = h2;
/*----------------------------------------------------------------*/
/*------ We load this program in the command interpreter --------*/
load_cmd(0, k);
/*----------------------------------------------------------------*/
/*------ We execute the program 'example' ------------------------*/
sprintf(h, "example\n");
Exec_interp_command(h);
/*----------------------------------------------------------------*/
/*------ We clean the memory used by the interpreter -------------*/
clean_exit_interp(&flow_I[0]);
/*----------------------------------------------------------------*/
return 0;
}
void
init_prog(flow_data *flow_interp)
{
}
void
exit_prog()
{
exit(0);
}
void
dest_prop(int typ, int i0, flow_data *flow_interp)
{
}
void
init_thread_param(flow_data *flow_interp)
{
}
void
clean_thread_param(flow_data *flow_interp)
{
}