TCL SHELL教学版的改良
// MyCounter.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include "MyCounter.h"
#include "tcl.h"
#include "test.h"
#include "stdio.h"
#include "stdlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//函数声明
int Tcl_AppInit(Tcl_Interp *interp);
int TclEx_Counter(ClientData clientdata,Tcl_Interp *interp,int argc,char*argv[]);
//变量声明
extern int g_iBlankLineNum;
extern int g_iCodeLineNum;
extern int g_iCommLineNum;
extern int g_iTotalLineNum;
extern BOOL g_bStatBlankLineFlag;
extern BOOL g_bStatCodeLineFlag;
extern BOOL g_bStatCommLineFlag;
extern BOOL g_bStatTotalLineFlag;
//创建自己的shell
void main(int argc, char *argv[])
{
Tcl_Main(argc,argv,Tcl_AppInit);
exit(0);
}
//shell函数的实现。
int Tcl_AppInit(Tcl_Interp *interp)
{
//解释器的初始化
Tcl_Init(interp);
//扩展命令的注册
Tcl_CreateCommand(interp,"COUNTER",TclEx_Counter,NULL,NULL);
return TCL_OK;
}
//扩展命令的实现
int TclEx_Counter(ClientData clientdata,Tcl_Interp *interp,int argc,char *argv[])
{
int aRet; //空行行实际输出
int bRet; //注释行实际输出
int cRet; //代码行实际输出
int dRet; //总行数实际输出
int aExceptedRet; //期望空行输出
int bExceptedRet; //期望注释行输出
int cExceptedRet; //期望代码行输出
int dExceptedRet; //期望总行输出
//定义被测试对象
CTest Mytest;
//第一步检查参数个数
if(10 != argc)
{
interp->result ="paras error";
return TCL_OK;
}
//第二步取出参数
Mytest.g_szStatFileName = argv;
//取统计空行标志位
if (TCL_OK != Tcl_GetInt(interp,argv,&g_bStatBlankLineFlag))
{
interp->result = "para2 error(BlankLineFlag)";
return TCL_OK;
}
//取统计注释行标志位
if (TCL_OK != Tcl_GetInt(interp,argv,&g_bStatCommLineFlag))
{
interp->result ="para3 eroor(CommLineFlag)";
return TCL_OK;
}
//取统计代码行标志位
if (TCL_OK != Tcl_GetInt(interp,argv,&g_bStatCodeLineFlag))
{
interp->result= "para4 error(Codelineflag)";
return TCL_OK;
}
//取统计总行标志位
if (TCL_OK != Tcl_GetInt(interp,argv,&g_bStatTotalLineFlag))
{
interp->result= "para5 error(StatTotalLineFlag)";
return TCL_OK;
}
//取期望输出的空行数
if (TCL_OK != Tcl_GetInt(interp,argv,&aExceptedRet))
{
interp->result ="para 6 error(aExceptedRet)";
return TCL_OK;
}
//取期望输出的注释行数
if (TCL_OK != Tcl_GetInt(interp,argv,&bExceptedRet))
{
interp->result= "para 7 error(bExceptedRet)";
return TCL_OK;
}
//取期望输出的代码行数
if (TCL_OK != Tcl_GetInt(interp,argv,&cExceptedRet))
{
interp->result= "para 8 error(cExceptedRet)";
return TCL_OK;
}
//取期望输出的总行数
if (TCL_OK != Tcl_GetInt(interp,argv,&dExceptedRet))
{
interp->result ="para 9 error(dExceptedRet)";
return TCL_OK;
}
//调用被测试函数
Mytest.MainStatFun();
//取得函数执行后的值
aRet=g_iBlankLineNum;
bRet=g_iCommLineNum;
cRet=g_iCodeLineNum;
dRet=g_iTotalLineNum;
//测试结果比较
if ((aRet != aExceptedRet) || (bRet != bExceptedRet)
|| (cRet != cExceptedRet) || (dRet != dExceptedRet))
{
interp->result = "test fail the NO is:";
}
else
{
interp->result = "test pass the NO is:";
}
return TCL_OK;
}
页:
[1]