Chances are big that anyone in the business of writing software once encounters the situation in which the use of a console application is appropriate. These ‘consoles’ are often used to test the real application code or to quickly set up some kind of test. Most of the time these applications are not long life assigned and that's exactly why you don't want to spend too much time on implementation. In addition one can say that a lot of functionality such as timers or logging utility functions are needed in most console applications.
Wouldn’t it be helpful to have some sort of ‘empty’ console application offering a lot of basic functionality to which you just have to add your own specific code? If not, please stop reading.
The APP002 application framework offers an empty console application mimicking the well-known DOS interface and as such allowing self-defined commands to be entered on the command line. By default, only the ‘quit’, ‘?’ and some example commands are supported.
- Console application framework for C and C++ users.
- Although the included project file is a Visual Studio .NET file, the source is IDE independent.
- You can add as many commands as you like. Each command is allowed multiple parameters.
- Ghost commands can be defined (commands not visible to the user).
- Command line parameters are allowed to contain blank characters.
- Framework based applications can be called from within a script or DOS box.
- You can use up- and down arrows on your keyboard to roam the command history.
- Basic logging functionality is available.
- Timing functionality with micro resolution is available.
- Automatic versioning supported by means of a Perl script.
The framework contains three main parts: the Engine, the Command Table and the Utilities. The next paragraphs discuss them briefly. Much more detailed information together with some example code is available inside the user's manual that goes with the source code you can download.
1. The Engine
The Engine is the piece of code that takes care of two things: providing the user interface and executing the commands you enter on the command line. There is not much to say about the user interface: there is a default header and a command prompt (see look.h). Both can be changed by the framework user.
The Engine supports two ways of executing commands. First, you can start the console application, enter a command on the command line, and hit Enter. The result is displayed inside the console window. However, you can also call the console application from within a script or a batch file.
2. The Command Table
The Command Table (see commandTable.h) is where you add the new commands you want to enter on the command line. Adding an entry to the table is easy: copy/paste an existing
CMD_ENTRY and update its individual fields. Each entry has four fields:
- Command name: the name you have to type on the command line in order to execute the command.
- Parameters: (
FALSE) indication whether the command takes parameters or not.
- Function address: the reference to the function that will be called to execute the command.
- Comment: some explanation which is displayed when the '?' command is executed.
CMD_ENTRY("q", FALSE, NULL, "Quit command")
CMD_ENTRY("?", FALSE, NULL, "Help me please")
CMD_ENTRY("cls", FALSE, clsCmd, "Clear screen")
The function inside the third field is implemented by the framework user. You can use the commands.h and the commands.cpp files to accomplish this.
3. The Utilities
While implementing your own commands, you will often find yourself implementing the same functionality over and over gain. Therefore, the framework provides a set of common utility functions. Currently there are three main groups: timing functions, logging functions and parsing functions. The use of timing and logging functions speak for themselves. The parsing functions are very useful when it comes to analyzing the command parameters you enter on the command line. More information is provided inside the user's manual.
- 8 July 2005, Version 2.0.0, Initial CodeProject release.