Embedded Systems Firmware Demystified

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 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.
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 ==...