自动生成函数注释及其模板---source insight自定义宏工具

这是一个可以自动生成函数注释及其模板实现的一个宏工具


/*
note:source insight 的宏扩展描述其实不需要分号的,这里增加分号是编程习惯
*/
macro getFunType()
{
	var fType;
	fType=ASK("请输入函数返回类型");
	return fType;
}
macro getFunName()
{
	var fName;
	fName=ASK("请输入函数名字");
	return fName;
}
macro getFunDesc()
{
    var fDesc;
    fDesc=ASK("请输入函数描述");
    return fDesc;
}
macro getFunParamNum()
{
	var fParamNum;
	fParamNum=ASK("请输入参数个数");
	return fParamNum;
}
macro getFunParamType()
{
	var fParamType;
	fParamType=ASK("请输入参数类型");
	return fParamType;
}
macro getFunInputParamArray()
{
	var fParam;
	fParam=ASK("请输入输入参数列表多个以逗号隔开");
	return fParam;
}
macro getFunOutputParamArray()
{
	var fParam;
	fParam=ASK("请输入输出参数列表多个以逗号隔开");
	return fParam;
}
macro getAuthor()
{
	var fAuthor;
	fAuthor=ASK("请输入作者姓名工号");
	return fAuthor;
}

macro getCommentsTime()
{
    var  year;
    var  month;
    var  day;
    var  commTime;
    var  sysTime;

    sysTime = GetSysTime(1);
    year = sysTime.Year;
    month = sysTime.month;
    day = sysTime.day;
    commTime = "@year@-@month@-@day@";
    return commTime;
}

macro insertFunComment()
{
 	var hBuff;
    var line;

 	var ftype;
 	var fname;
 	var fdesc;
 	var fiparam;
 	var foparam;
 	var fauthor;
    var time;
    var comments;
    
    time=getCommentsTime();
	fauthor=getAuthor();
	ftype=getFunType();
	fname=getFunName();
	fdesc=getFunDesc();

	fiparam=getFunInputParamArray();
	foparam=getFunOutputParamArray();

 	hBuff = GetCurrentBuf();
    line = GetBufLnCur (hBuff);

	InsBufLine(hBuff, line, "/*************************************************************");

	comments = "函      数      名:";
    comments = cat(comments,fname);
	InsBufLine(hBuff,line+1,comments);

	comments = "函  数  描  述:";
    comments = cat(comments,fdesc);
	InsBufLine(hBuff,line+2,comments);	

	comments = "输  入  参  数:";
    comments = cat(comments,fiparam);
	InsBufLine(hBuff,line+3,comments);	

	comments = "输  出  参  数:";
    comments = cat(comments,foparam);
	InsBufLine(hBuff,line+4,comments);	

	comments = "返  回  类  型:";
    comments = cat(comments,ftype);
	InsBufLine(hBuff,line+5,comments);	

	comments = "备          注:";
	InsBufLine(hBuff,line+6,comments);		

 	comments = "  作          者:";
 	comments = cat(comments,fauthor);
	InsBufLine(hBuff,line+7,comments);

 	comments = "  时          间:";
 	comments = cat(comments,time);
	InsBufLine(hBuff,line+8,comments);	

	InsBufLine(hBuff, line+9, "*************************************************************/");

    //下来是生成函数体部分
    //函数定义部分
	comments = "";
	comments = cat(comments,ftype);
	comments = cat(comments," ");
	comments = cat(comments,fname);
	comments = cat(comments,"(");
	comments = cat(comments,fiparam);
	comments = cat(comments,", ");
	comments = cat(comments,foparam);
	comments = cat(comments,")");
	InsBufLine(hBuff,line+10,comments);

	InsBufLine(hBuff,line+11,"{");

	InsBufLine(hBuff,line+12,"	");

	comments = "	";
	comments = cat(comments,"XX_LOG(INFORMATIONAL, \"Enter ");
	comments = cat(comments,fname);
	comments = cat(comments,"!\");");
	InsBufLine(hBuff,line+13,comments);

	InsBufLine(hBuff,line+14,"	//入参判断");

	InsBufLine(hBuff,line+15,"	if( COND == PARAM )");
	InsBufLine(hBuff,line+16,"	{");
	InsBufLine(hBuff,line+17,"		XX_LOG(WARNNING, \"the input pram is invalid!\");");
	InsBufLine(hBuff,line+18,"		return  ;");
	InsBufLine(hBuff,line+19,"	}");

	InsBufLine(hBuff,line+20,"	");

	comments = "	";
	comments = cat(comments,"XX_LOG(INFORMATIONAL, \"Exit ");
	comments = cat(comments,fname);
	comments = cat(comments,"!\");");
	InsBufLine(hBuff,line+21,comments);
	
	InsBufLine(hBuff,line+22,"	return  ;");
	InsBufLine(hBuff,line+23,"}");
}



你可能感兴趣的:(宏,工具使用)