| ||
Each general-purpose command in MicroMonitor has the data structure shown in Listing 5.1. The command data structures are stored in the command table.
struct monCommand { char *name; /* Name of command seen by user. */ int (*func)(); /* Function called when command is invoked. */ char **helptxt; /* Help text. */ };
The first member, name , points to the string that must match the first token typed on the command line. The function pointer, func , points to the code that is to be called as a result of the token match, and the helptxt pointer shows the location of the help text for the specific command.
At the base of the command table is a preprocessor #include directive that allows you to add additional, target-specific commands that are independent of the core generic commands. [1] The CLI handler scans a table of these structures looking for a match between the first token on the command line and the name member. Listing 5.2 is a small example of the command table.
extern int Add(), Echo(), Help(), Version(); extern char *AddHelp[], *EchoHelp[], *HelpHelp[]; extern char *VersionHelp[]; struct monCommand cmdlist[] = { { "add", Add, AddHelp, }, { "echo", Echo, EchoHelp, }, { "help", Help, HelpHelp, }, { "?", Help, HelpHelp, }, { "version", Version, VersionHelp, }, #include "xcmdtbl.h" { 0,0,0, }, };
[1] Remember that we are discussing a boot monitor that supports extensions for various target specific needs. This #include allows the extensions to be added without actually touching the monitors generic command table.
| ||