Console Application Framework

   

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 Enginethe 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 thecommands 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 commandon 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 thecommand 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 thecommands.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 functionslogging 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.


转自:http://www.codeproject.com/Articles/10955/Console-Application-Framework#_rating

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值