Embedded Systems Firmware Demystified

Chapter 8: Executing Scripts

Now that the monitor design includes a flash file system and a command line interface, I will extend the system so that a file can execute as a script. Actually, the scripting feature turns out to be a pretty simple addition one that adds a lot of flexibility to MicroMonitor. A single script-running function, with the help of a few script-running-specific commands in MicroMonitor s command set, provides a versatile environment for simple script execution.

The Script Runner

The script runner function ( tfsscript()) (see Listing 8.1) treats a file as a list of commands. The function reads each line of the file and executes the line as a command. Some commands affect the script runner directly, for example goto, gosub, return, and exit. I will discuss these commands in detail later.

Listing 8.1: tfsscript().
inttfsscript(TFILE *fp, int verbose){    char    lcpy[CMDLINESIZE];    int     tfd, lnsize;    /* TFS does not support calling a script from within a subroutine. */    if (ReturnToDepth != 0)        return(TFSERR_SCRIPTINSUB);    tfd = tfsopen(fp->name,TFS_RDONLY,0);    if (tfd < 0)        return(tfd);    ReturnToTfd = tfd;        while(1) {        lnsize = tfsgetline(tfd,lcpy,CMDLINESIZE);        if (lnsize ==...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Hot Runner Systems
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.