sourceinsight常用宏

最近研究了下sourceinsight的宏编制,挺有意思的,结合网上摘抄的部分代码,然后自己修改了些细节,整体效果还不错,这里贴出来供其他人参考参考;

 

第一个宏:插入文件描述信息

macro InsertFileHeader()
{
    var time;
    var filename;
    var comments;
    szMyName = "xxx";//getenv(MYNAME)
    time = getCommentsTime();
    filename = GetFullFileName();
    hbuf = GetCurrentBuf();

    InsBufLine ( hbuf, 0, "/**************************************************************************" );
    InsBufLine ( hbuf, 1, "* 公     司 :   xxxxxxxxxx" );

    if ( strlen ( szMyName ) > 0 )
    {


        InsBufLine ( hbuf, 2, "* 地     址 :   xxxxxxxxxxxxxxxxxx" );
        InsBufLine ( hbuf, 3, "* 网     址 :   xxxxxxxxxxxxxxxx" );
        sz = "* 编     制 :   @szMyName@";
        InsBufLine ( hbuf, 4, sz );
        comments = "* 时     间 :   ";
        comments = cat ( comments, time );
        InsBufLine ( hbuf, 5, comments );
        InsBufLine ( hbuf, 6, "* 描     述 : " )
        ln = 7;
    }
    else
        ln = 2;

    InsBufLine ( hbuf, ln, "**************************************************************************/" );
}

这个宏在sourceinsight内的效果如图所示:

在MDK内显示效果如图所示:

看得出来在两个不同的编辑环境内没有产生对齐异常的问题;

 

第二个宏:添加#ifdef0---#endif条件编译

macro Ifdefin0()
{
    hwnd = GetCurrentWnd();
    sel = GetWndSel ( hwnd );
    lnFirst = GetWndSelLnFirst ( hwnd );
    lnLast = GetWndSelLnLast ( hwnd );
    hbuf = GetCurrentBuf();

    if ( LnFirst == 0 )
    {
        szIfStart = "";
    }
    else
    {
        szIfStart = GetBufLine ( hbuf, LnFirst - 1 );
    }

    szIfEnd = GetBufLine ( hbuf, lnLast + 1 );

    if ( szIfStart == "#if 0" && szIfEnd == "#endif" )
    {
        DelBufLine ( hbuf, lnLast + 1 );
        DelBufLine ( hbuf, lnFirst - 1 );
        //sel.lnFirst = sel.lnFirst + 1;
        //sel.lnLast = sel.lnLast + 1;
    }
    else
    {
        InsBufLine ( hbuf, lnFirst, "#if 0" );
        InsBufLine ( hbuf, lnLast + 2, "#endif" );
        sel.lnFirst = sel.lnFirst + 1;
        sel.lnLast = sel.lnLast + 1;
    }

    SetWndSel ( hwnd, sel );
}

 

第三个宏:添加函数描述信息

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 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 fiparam2;
    var fauthor;
    var time;
    var comments;
    var num;
    var num2;
    var num3;


    num = getFunParamNum();
    num2 = num;
    time = getCommentsTime();
    fauthor = getAuthor();
    ftype = getFunType();
    fname = getFunName();
    fdesc = getFunDesc();


    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 = "* 参数列表 : ";

    while ( num-- )
    {

        num3 = num2 - num;
        fiparam = ASK ( "本函数共@num2@个参数,请输入第@num3@个参数" );

        if ( num3 == num2 )
            fiparam2 = cat ( fiparam2, fiparam );
        else
        {
            fiparam2 = cat ( fiparam2, fiparam );
            fiparam2 = cat ( fiparam2, ", " );

        }

        if ( num3 == 1 )
        {
            comments = cat ( comments, fiparam );
            InsBufLine ( hBuff, line + 2 + num3, comments );

        }

        else
        {
            comments = "*            ";
            comments = cat ( comments, fiparam );
            InsBufLine ( hBuff, line + 2 + num3, comments );

        }

    }

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

    comments = "* 编 制 者 : ";
    comments = cat ( comments, fauthor );
    InsBufLine ( hBuff, line + 4 + num3, comments );

    comments = "* 编制时间 : ";
    comments = cat ( comments, time );
    InsBufLine ( hBuff, line + 5 + num3 comments );

    InsBufLine ( hBuff, line + 6 + num3, "*************************************************************/" );

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

    InsBufLine ( hBuff, line + 8 + num3, "{" );

    InsBufLine ( hBuff, line + 9 + num3, "  " );

    comments = "    ";
    InsBufLine ( hBuff, line + 10 + num3, "}" );
}

最后在sourceinsight内的运行效果如图所示:

 

在MDK内的显示效果如图所示:

 

看得出来在两个不同的编辑环境内也没有产生对齐异常的问题;

 

posted @ 2017-05-05 17:12  迷途小菜鸟  阅读(2919)  评论(0编辑  收藏  举报