Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Console Application Framework

0.00/5 (No votes)
12 Jul 2005 1  
A framework for rapidly creating a console application.

Sample Image

Introduction

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.

Framework overview

  1. Console application framework for C and C++ users.
  2. Although the included project file is a Visual Studio .NET file, the source is IDE independent.
  3. You can add as many commands as you like. Each command is allowed multiple parameters.
  4. Ghost commands can be defined (commands not visible to the user).
  5. Command line parameters are allowed to contain blank characters.
  6. Framework based applications can be called from within a script or DOS box.
  7. You can use up- and down arrows on your keyboard to roam the command history.
  8. Basic logging functionality is available.
  9. Timing functionality with micro resolution is available.
  10. Automatic versioning supported by means of a Perl script.

Framework details

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:

  1. Command name: the name you have to type on the command line in order to execute the command.
  2. Parameters: (TRUE/FALSE) indication whether the command takes parameters or not.
  3. Function address: the reference to the function that will be called to execute the command.
  4. Comment: some explanation which is displayed when the '?' command is executed.
START_COMMAND_TABLE

    CMD_ENTRY("q", FALSE, NULL, "Quit command")
    CMD_ENTRY("?", FALSE, NULL, "Help me please")
    CMD_ENTRY("cls", FALSE, clsCmd, "Clear screen")

    // PUT HERE YOUR OWN COMMAND ENTRIES

    // ALWAYS LEAVE FIRST TWO COMMANDS IN PLACE !!


END_COMMAND_TABLE

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.

History

  • 8 July 2005, Version 2.0.0, Initial CodeProject release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here