cmdscan.h
Types | |
The CommandScanner type offers a simple command-scanning abstraction that is primarily used to construct test programs. | |
This type represents the space of functions that can be used as commands. | |
Functions | |
Allocates a new command scanner. | |
Frees the specified command scanner. | |
Adds an entry to the internal command table for the command scanner by associating the specified command name with the corresponding function. | |
Executes a loop that reads and executes commands from the user. | |
Executes a command line as if it were entered by the user. | |
Associates a data block with the command scanner. | |
Returns the data block associated with the command scanner. | |
Reads the next token from the command line, which is returned as a string. | |
Returns the current command line. | |
Returns the current command name. | |
Returns the TokenScanner used internally to parse tokens. | |
This callback function exits from the command scanner. |
typedef struct CommandScannerCDT *CommandScanner;
CommandScanner
type offers a simple command-scanning
abstraction that is primarily used to construct test programs. The
typical pattern of use requires the following steps:
newCommandScanner
to create an empty command scanner.
defineCommand
to associate commands with functions.
commandLoop
to execute a command loop.
typedef void CommandFn(*CommandFn)(CommandScanner cs);
CommandScanner newCommandScanner(void);
Usage:
cs = newCommandScanner();
void freeCommandScanner(CommandScanner cs);
Usage:
freeCommandScanner(cs);
void defineCommand(CommandScanner cs, string cmdName, CommandFn cmdFn);
Usage:
defineCommand(cs, cmdName, cmdFn);
void commandLoop(CommandScanner cs, string prompt);
commandLoop
performs the following operations:
If a command is undefined, commandLoop
displays a message
to that effect and allows the user to enter a new command. If any
errors occur in the command processing, they are caught by the
command loop.
Usage:
commandLoop(cs, prompt);
bool executeCommand(CommandScanner cs, string line);
true
if the command is
defined, and false
otherwise.
Usage:
ok = executeCommand(cs, line);
void setCommandData(CommandScanner cs, void *data);
Usage:
setCommandData(cs, data);
void *getCommandData(CommandScanner cs);
Usage:
data = getCommandData(cs);
string readCommandToken(CommandScanner cs);
readCommandToken
returns the empty string.
Usage:
token = readCommandToken(cs);
string getCommandLine(CommandScanner cs);
Usage:
line = getCommandLine(cs);
string getCommandName(CommandScanner cs);
Usage:
name = getCommandName(cs);
TokenScanner getTokenScanner(CommandScanner cs);
TokenScanner
used internally to parse tokens.
Usage:
scanner = getTokenScanner(cs);
void quitCommand(CommandScanner cs);
Usage:
defineCommand(cs, "quit", quitCommand);