lintfilter.js & mulitypclint.bat

@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
::修复js文件的关联,否则js脚本无法执行
reg add "hkcr\.js" /ve /d JSFile /f >nul
set time1=%time:~0,2%%time:~3,2%%time:~6,2%

set PRJ_DIR=%CD%
set WORK_FILE=lint
set BAT=run.bat
set SOURCE=filelist.txt

::进工作目录
IF NOT EXIST %WORK_FILE% (
    echo No %WORK_FILE%!!!
    EXIT
)

cd %WORK_FILE%

IF NOT EXIST %SOURCE% (
    echo No %SOURCE%!!!
    EXIT
)

set tmpIndex=0
set duplicateCount=0

::遍历文件列表
FOR /F "eol=/delims=" %%i in (%SOURCE%) do (
    set tmp=%%i
    
    set isannotate=false
    IF "!tmp:~0,1!"=="#" (
        set isannotate=true
    )
    IF "!tmp:~0,2!"=="//" (
        set isannotate=true
    )
    
    IF !isannotate!==false (
        set fileorfolder=!tmp:%%PRJ_DIR%%=%PRJ_DIR%!
        set existfile=false
        FOR /F "delims=" %%j in ('dir /s /b /A:-D !fileorfolder!') do (
            IF EXIST "%%j" (
                set existfile=true
                
                ::判重标识
                set duplicate=false
                FOR /L %%k IN (0,1,!tmpIndex!) do (
                    IF /I !tmp[%%k]!=="%%j" (
                        set duplicate=true
                    )
                )
                
                ::判重
                IF !duplicate!==false (
                    set tmp[!tmpIndex!]="%%j"
                    set /a tmpIndex=tmpIndex+1
                ) ELSE (
                    set /a duplicateCount=duplicateCount+1
                )
            )
        )
        
        IF !existfile!==false (
            echo !tmp! error
            echo !fileorfolder!
        )
    )
)

::清空临时环境变量,否则后面执行xgConsole时会尝试解析这些环境变量而出错
set tmp=
set fileorfolder=
set existfile=
set duplicate=

echo TaskInfo FileCount:!tmpIndex!  Duplicate:!duplicateCount!
title TaskInfo FileCount:!tmpIndex!

::重新生成bat
IF EXIST "%BAT%" (
    del "%BAT%"
)

echo @ECHO OFF >>%BAT%

::按实际大小遍历
set /a tmpIndex=tmpIndex-1

FOR /L %%k IN (0,1,!tmpIndex!) do (
    echo xgSubmit.exe /group=UTest # lint-nt.exe -u -I.\\lnt -I.\\lint std.lnt !tmp[%%k]! >>%BAT%)

echo xgWait.exe /group=UTest >>%BAT%
::echo echo All Task Finished! >>%BAT%

cscript /nologo lintfilter.js "xgConsole /NOLOGO /command=%BAT%"

set time2=%time:~0,2%%time:~3,2%%time:~6,2%
set /a time3=%time2%-%time1%
echo 耗时%time3%秒

::清理临时文件
IF EXIST "%BAT%" (
    del "%BAT%"
)

EXIT

 

var switchfull = 0;     // 不做过滤

function IsNeedPrint(iEWIN)
{
    switch(iEWIN)
    {
        case EWINError:
        {
            return true;
        }
        case EWINWarning:
        {
            return true;
        }
        case EWINInfo:
        {
            return true;
        }
        case EWINNote:
        {
            return false;
        }
    }
    return false;
}

var EWINError = 0;
var EWINWarning = 1;
var EWINInfo = 2;
var EWINNote = 3;

var regSpaceLine = /^\s+$/gim;
var regError = /\(\d+\) \: Error \d+\: /gim;
var regWarning = /\(\d+\) \: Warning \d+\: /gim;
var regInfo = /\(\d+\) \: Info \d+\: /gim;
var regNote = /\(\d+\) \: Note \d+\: /gim;

var strErrorOutPutFile = "filelist.txt";
var strPoints = "......";
var regIncrediBuildWaitingFor = "IncrediBuild: Waiting for";
var regPCLintHeader = /PC\-lint for C\/C\+\+ \(NT\) Vers\. 8.00w\, Copyright Gimpel Software 1985\-2007/gim;
var regModuleHeader = /^--- Module:\s{3}(.*)\s\(((C\+\+)|(C))\)$/gim;
var strGlobalWrapupHeaderStart = "--- Global Wrap-up";
var regwrapEWIN = /^((Error|Warning|Info|Note) \d+\:) (.+)\(line (\d+)\, file (.*)\)(.*)$/gim;

function Task(time, taskinfo)
{
    this.m_cpuTime = 0;
    this.m_time = time;
    this.m_output = "";
    this.m_info = taskinfo;
}

function OutputArray(a)
{
    for(var i = 0; i < a.length; ++i)
    {
        WScript.StdOut.WriteLine(a[i]);
    }
}
function Output(str)
{
    WScript.StdOut.WriteLine(str);
}

var statout = 0;
var statin = 1;
var statinwrapup = 2;

var stat = statout;

// 数字格式化为指定长度,缺位补0
Number.prototype.Format = function(num)
{
    var ret = this.toString();
    while(ret.length < num)
    {
        ret = "0" + ret;
    }
    return ret;
}

// 数组清空方法
Array.prototype.Clear = function()
{
    this.splice(0, this.length);
}

// 数组拷贝方法,数组直接赋值只相当于赋值引用
Array.prototype.Copy = function()
{
    // 重新生成一个数组返回出去
    var ret = new Array();
    return ret.concat(this);
}

// 数组清理前后空行
Array.prototype.TrimEmptyLine = function()
{
    while(this.length && ("" == this[0]))
    {
        this.splice(0, 1);
    }
    while(this.length && ("" == this[this.length - 1]))
    {
        this.splice(this.length - 1, 1);
    }
}

// 数组清理前后空白行
Array.prototype.TrimSpaceLine = function()
{
    while(this.length && (regSpaceLine.TestNoRecord(this[0])))
    {
        this.splice(0, 1);
    }
    while(this.length && (regSpaceLine.TestNoRecord(this[this.length - 1])))
    {
        this.splice(this.length - 1, 1);
    }
}

// 排重插入
Array.prototype.Insert = function(data)
{
    for(var i = 0; i < this.length; ++i)
    {
        if(data == this[i])
        {
            return;
        }
    }
    this.push(data);
}

// 正则无记忆方法
RegExp.prototype.TestNoRecord = function(str){
    var ret = this.test(str);
    this.lastIndex = 0;
    return ret;
}
RegExp.prototype.ExecNoRecord = function(str){
    var ret = this.exec(str);
    this.lastIndex = 0;
    return ret;
}
function ErrorWarningInfoNote(iErrorType, aryErrorContent)
{
    aryErrorContent.TrimEmptyLine();
    this.m_iType = iErrorType;
    this.m_aryContent = aryErrorContent.Copy();
}

function Module(strModuleHeader, strFilePath, aryModuleContent)
{
    this.m_strHeader = strModuleHeader;
    this.m_strFilePath = strFilePath;
    this.m_aryErrors = new Array();
    this.m_aryWrapupErrors = new Array();
    this.m_aryWrapupLeft = new Array();
    this.m_aryLeft = new Array();

    var bIsInWrapup = false;
    var aryCache = new Array();

    aryModuleContent.TrimEmptyLine();
    for(var i = 0; i < aryModuleContent.length; ++i)
    {
        var str = aryModuleContent[i];
        if(bIsInWrapup)
        {
            // Wrap-up内容检查,非许可内容不打印
            var reret = regwrapEWIN.ExecNoRecord(str);
            // 清除记忆
            if(reret && (7 == reret.length))
            {
                var strTmp = reret[5] + "(" + reret[4] + ")" + " " + ":" + " " + reret[1] + " " + reret[3] + reret[6];
                var strErrorType = reret[2];
                if("Error" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINError, new Array(strTmp)));
                }
                else if("Warning" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINWarning, new Array(strTmp)));
                }
                else if("Info" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINInfo, new Array(strTmp)));
                }
                else if("Note" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINNote, new Array(strTmp)));
                }
                else
                {
                    this.m_aryWrapupLeft.push(str);
                }
            }
            else
            {
                this.m_aryWrapupLeft.push(str);
            }

            continue;
        }

        if(regError.TestNoRecord(str))
        {
            // Error
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINError, aryCache));
            aryCache.Clear();
        }
        else if(regWarning.TestNoRecord(str))
        {
            // Warning
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINWarning, aryCache));
            aryCache.Clear();
        }
        else if(regInfo.TestNoRecord(str))
        {
            // Info
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINInfo, aryCache));
            aryCache.Clear();
        }
        else if(regNote.TestNoRecord(str))
        {
            // Note
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINNote, aryCache));
            aryCache.Clear();
        }
        else if(0 == str.search(strGlobalWrapupHeaderStart))
        {
            // Wrap-up开始
            bIsInWrapup = true;
        }
        else
        {
            aryCache.push(str);
        }
    }

    // 最后部分
    this.m_aryLeft = aryCache.Copy();
    aryCache.Clear();

    // 清除无用空行
    this.m_aryLeft.TrimSpaceLine();
    this.m_aryWrapupLeft.TrimSpaceLine();
}

function IsModuleHasPrintError(objModule)
{
    for(var i = 0; i < objModule.m_aryErrors.length; ++i)
    {
        if(IsNeedPrint(objModule.m_aryErrors[i].m_iType))
        {
            return true;
        }
    }

    for(var j = 0; j < objModule.m_aryWrapupErrors.length; ++j)
    {
        if(IsNeedPrint(objModule.m_aryWrapupErrors[j].m_iType))
        {
            return true;
        }
    }
    return false;
}

function OutputModule(objModule)
{
    Output(objModule.m_strHeader);
    for(var i = 0; i < objModule.m_aryErrors.length; ++i)
    {
        if(IsNeedPrint(objModule.m_aryErrors[i].m_iType))
        {
            OutputArray(objModule.m_aryErrors[i].m_aryContent);
        }
    }

    Output("");

    var bIsWrapupErrorOutput = false;

    for(var j = 0; j < objModule.m_aryWrapupErrors.length; ++j)
    {
        if(IsNeedPrint(objModule.m_aryWrapupErrors[j].m_iType))
        {
            OutputArray(objModule.m_aryWrapupErrors[i].m_aryContent);
            bIsWrapupErrorOutput = true;
        }
    }

    if(bIsWrapupErrorOutput)
    {
        Output("");
    }

    if(objModule.m_aryWrapupLeft.length || objModule.m_aryLeft.length)
    {
        Output("!!!Error!!!Something is left.");
        OutputArray(objModule.m_aryWrapupLeft);
        OutputArray(objModule.m_aryLeft);
    }
}

var g_iModuleCount = 0;
var g_strModuleHeader = "";
var g_strFilePath = "";
var g_aryModuleContent = new Array();
var g_aryWaitingModules = new Array();

function WriteConsole(str)
{
    if(switchfull)
    {
        Output(str);
        return;
    }

    if(0 == str.search(regIncrediBuildWaitingFor))
    {
        // 等待任务信息,这句会打印到不是头儿的位置,直接屏蔽
        return;
    }
    if(0 == str.search(regPCLintHeader))
    {
        // PCLint版本号,直接不打印
        return;
    }

    var reret = regModuleHeader.ExecNoRecord(str);
    if(reret && (5 == reret.length))
    {
        g_iModuleCount++;
        // 模块开始,可能是Wrap-up结束
        if("" != g_strModuleHeader)
        {
            var objModule = new Module(g_strModuleHeader, g_strFilePath, g_aryModuleContent);
            if(IsModuleHasPrintError(objModule))
            {
                // 需要等待最后输出的
                g_aryWaitingModules.push(objModule);
                Output(g_strModuleHeader);
                Output(strPoints);
            }
            else
            {
                // 立即输出的
                OutputModule(objModule);
            }
        }

        // 开始新模块
        // 模块头加上编号,便于了解进度
        g_strModuleHeader = str.replace("--- Module:", "--- Module " + g_iModuleCount.Format(4) + " :");
        g_strFilePath = reret[1];
        g_aryModuleContent.Clear();
        return;
    }

    if("" != g_strModuleHeader)
    {
        // 缓存
        g_aryModuleContent.push(str);
    }
    else
    {
        // 还没进入模块,直接输出
        Output(str);
    }
}

function WriteFinish()
{
    // 模块开始,可能是Wrap-up结束
    if("" != g_strModuleHeader)
    {
        var objModule = new Module(g_strModuleHeader, g_strFilePath, g_aryModuleContent);
        if(IsModuleHasPrintError(objModule))
        {
            // 需要等待最后输出的
            g_aryWaitingModules.push(objModule);
            Output(g_strModuleHeader);
            Output(strPoints);
        }
        else
        {
            // 立即输出的
            OutputModule(objModule);
        }
    }
    
    var aryPaths = new Array();
    // 输出有错误的
    for(var i = 0; i < g_aryWaitingModules.length; ++i)
    {
        OutputModule(g_aryWaitingModules[i]);
        aryPaths.Insert(g_aryWaitingModules[i].m_strFilePath);
    }

    try
    {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var temp = new Array();
        if(fso.FileExists(strErrorOutPutFile))
        {
            var objOutPutFile = fso.OpenTextFile(strErrorOutPutFile, 1 , false);
            while (!objOutPutFile.AtEndOfStream)
            {
                var strLine = objOutPutFile.ReadLine();
                if(("###**********B**********###" + WScript.ScriptFullName) == strLine)
                {
                    break;
                }
                temp.push(strLine);
            }
            while (!objOutPutFile.AtEndOfStream)
            {
                var strLine = objOutPutFile.ReadLine();
                if(("###**********E**********###" + WScript.ScriptFullName) == strLine)
                {
                    break;
                }
            }
            while (!objOutPutFile.AtEndOfStream)
            {
                var strLine = objOutPutFile.ReadLine();
                temp.push(strLine);
            }
            objOutPutFile.Close();
        }

        var objOutPutFile = fso.OpenTextFile(strErrorOutPutFile, 2 , true);
        for(var i = 0; i < temp.length; ++i)
        {
            objOutPutFile.WriteLine(temp[i]);
        }
        objOutPutFile.WriteLine("###**********B**********###" + WScript.ScriptFullName);
        for(var i = 0; i < aryPaths.length; ++i)
        {
            var strPath = aryPaths[i];
            if(-1 != strPath.search(" "))
            {
                strPath = "\"" + strPath + "\"";
            }
            objOutPutFile.WriteLine(strPath);
        }
        objOutPutFile.WriteLine("###**********E**********###" + WScript.ScriptFullName);
        objOutPutFile.Close();
    }
    catch (e)
    {
        Output("!!!Error!!!File Operate." + e.name + ":" + e.message);
    }
}

if(WScript.Arguments.length == 1 && WScript.Arguments(0) != "")
{
    var WshShell = new ActiveXObject("WScript.Shell");

    var process = WshShell.Exec(WScript.Arguments(0));
    var task = new Task((new Date()).getVarDate(), process);

    while(!task.m_info.StdOut.AtEndOfStream)
    {
        var tmpchar = task.m_info.StdOut.ReadLine();
        WriteConsole(tmpchar);
    }

    // 剩下的全部输出
    WriteFinish();
}
else
{
    for(var i = 0; i < WScript.Arguments.length; ++i)
    {
        Output(WScript.Arguments(i));
    }
}

 

最新版本

lintfilter.js

function IsNeedPrint(iEWIN)
{
    switch(iEWIN)
    {
        case EWINError:
        {
            return true;
        }
        case EWINWarning:
        {
            return true;
        }
        case EWINInfo:
        {
            return true;
        }
        case EWINNote:
        {
            return false;
        }
    }
    return false;
}

var EWINError = 0;
var EWINWarning = 1;
var EWINInfo = 2;
var EWINNote = 3;

var regSpaceLine = /^\s*$/gm;
var regError = /\(\d+\) \: Error \d+\: /gm;
var regWarning = /\(\d+\) \: Warning \d+\: /gm;
var regInfo = /\(\d+\) \: Info \d+\: /gm;
var regNote = /\(\d+\) \: Note \d+\: /gm;

var strErrorOutPutFile = "errorfilelist.txt";
var strPoints = "......";
var regIncrediBuildWaitingFor = "IncrediBuild: Waiting for";
var regPCLintHeader = /PC\-lint for C\/C\+\+ \(NT\) Vers\. 8.00w\, Copyright Gimpel Software 1985\-2007/gm;
var regModuleHeader = /^--- Module\s*\d*\s*:\s{3}(.*)\s\(((C\+\+)|(C))\)$/gm;
var regModuleHeader1Part = /--- Module\s*\d*\s*:/gm;
var regGlobalWrapupHeaderStart = /--- ((Global Wrap-up)|(Wrap-up for Module\:))/gm;
var regwrapEWIN = /^((Error|Warning|Info|Note) \d+\:) (.+)\(line (\d+)\, file (.*)\)(.*)$/gm;
var g_bCloseFilter = false;     // 不做过滤
var g_bOnlyOne = false;// 只有一个文件时无需排序输出错误,无需带上序号

function Task(time, taskinfo)
{
    this.m_cpuTime = 0;
    this.m_time = time;
    this.m_output = "";
    this.m_info = taskinfo;
}

function Output(str)
{
    WScript.StdOut.WriteLine(str);
}

function OutputErr(str)
{
    WScript.StdErr.WriteLine(str);
}

function OutputArray(a)
{
    for(var i = 0; i < a.length; ++i)
    {
        Output(a[i]);
    }
}

function OutputArrayErr(a)
{
    var strOutput = "";
    for(var i = 0; i < a.length; ++i)
    {
        if(i != 0)
        {
            strOutput += "\n";
        }
        strOutput += a[i];
    }
    OutputErr(strOutput);
}

function ExistInArray(aryValues, value)
{
    for(var i = 0; i < aryValues.length; ++i)
    {
        if(aryValues[i] == value)
        {
            return true;
        }
    }
    return false;
}

var statout = 0;
var statin = 1;
var statinwrapup = 2;

var stat = statout;

// 数字格式化为指定长度,缺位补0
Number.prototype.Format = function(num)
{
    var ret = this.toString();
    while(ret.length < num)
    {
        ret = "0" + ret;
    }
    return ret;
}

// 数组清空方法
Array.prototype.Clear = function()
{
    this.splice(0, this.length);
}

// 数组拷贝方法,数组直接赋值只相当于赋值引用
Array.prototype.Copy = function()
{
    // 重新生成一个数组返回出去
    var ret = new Array();
    return ret.concat(this);
}

// 数组清理前后空行
Array.prototype.TrimEmptyLine = function()
{
    while(this.length && ("" == this[0]))
    {
        this.splice(0, 1);
    }
    while(this.length && ("" == this[this.length - 1]))
    {
        this.splice(this.length - 1, 1);
    }
}

// 数组清理前后空白行
Array.prototype.TrimSpaceLine = function()
{
    while(this.length && (regSpaceLine.TestNoRecord(this[0])))
    {
        this.splice(0, 1);
    }
    while(this.length && (regSpaceLine.TestNoRecord(this[this.length - 1])))
    {
        this.splice(this.length - 1, 1);
    }
}

// 排重插入
Array.prototype.Insert = function(data)
{
    for(var i = 0; i < this.length; ++i)
    {
        if(data == this[i])
        {
            return;
        }
    }
    this.push(data);
}

// 正则无记忆方法
RegExp.prototype.TestNoRecord = function(str){
    var ret = this.test(str);
    this.lastIndex = 0;
    return ret;
}
RegExp.prototype.ExecNoRecord = function(str){
    var ret = this.exec(str);
    this.lastIndex = 0;
    return ret;
}

function ErrorWarningInfoNote(iErrorType, aryErrorContent)
{
    aryErrorContent.TrimEmptyLine();
    this.m_iType = iErrorType;
    this.m_aryContent = aryErrorContent.Copy();
}

function Module(strModuleHeader, strFilePath, aryModuleContent)
{
    this.m_strHeader = strModuleHeader;
    this.m_strFilePath = strFilePath;
    this.m_aryErrors = new Array();
    this.m_aryWrapupErrors = new Array();
    this.m_aryWrapupLeft = new Array();
    this.m_aryLeft = new Array();

    var bIsInWrapup = false;
    var aryCache = new Array();

    aryModuleContent.TrimEmptyLine();
    for(var i = 0; i < aryModuleContent.length; ++i)
    {
        var str = aryModuleContent[i];
        if(bIsInWrapup)
        {
            // Wrap-up内容检查,非许可内容不打印
            var reret = regwrapEWIN.ExecNoRecord(str);
            // 清除记忆
            if(reret && (7 == reret.length))
            {
                var strTmp = reret[5] + "(" + reret[4] + ")" + " " + ":" + " " + reret[1] + " " + reret[3] + reret[6];
                var strErrorType = reret[2];
                if("Error" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINError, new Array(strTmp)));
                }
                else if("Warning" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINWarning, new Array(strTmp)));
                }
                else if("Info" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINInfo, new Array(strTmp)));
                }
                else if("Note" == strErrorType)
                {
                    this.m_aryWrapupErrors.push(new ErrorWarningInfoNote(EWINNote, new Array(strTmp)));
                }
                else
                {
                    this.m_aryWrapupLeft.push(str);
                }
            }
            else
            {
                this.m_aryWrapupLeft.push(str);
            }

            continue;
        }

        if(regError.TestNoRecord(str))
        {
            // Error
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINError, aryCache));
            aryCache.Clear();
        }
        else if(regWarning.TestNoRecord(str))
        {
            // Warning
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINWarning, aryCache));
            aryCache.Clear();
        }
        else if(regInfo.TestNoRecord(str))
        {
            // Info
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINInfo, aryCache));
            aryCache.Clear();
        }
        else if(regNote.TestNoRecord(str))
        {
            // Note
            aryCache.push(str);
            this.m_aryErrors.push(new ErrorWarningInfoNote(EWINNote, aryCache));
            aryCache.Clear();
        }
        else if(regGlobalWrapupHeaderStart.TestNoRecord(str))
        {
            // Wrap-up开始
            bIsInWrapup = true;
        }
        else
        {
            aryCache.push(str);
        }
    }

    // 最后部分
    this.m_aryLeft = aryCache.Copy();
    aryCache.Clear();

    // 清除无用空行
    this.m_aryLeft.TrimSpaceLine();
    this.m_aryWrapupLeft.TrimSpaceLine();
}

function IsModuleHasPrintError(objModule)
{
    for(var i = 0; i < objModule.m_aryErrors.length; ++i)
    {
        if(IsNeedPrint(objModule.m_aryErrors[i].m_iType))
        {
            return true;
        }
    }

    for(var j = 0; j < objModule.m_aryWrapupErrors.length; ++j)
    {
        if(IsNeedPrint(objModule.m_aryWrapupErrors[j].m_iType))
        {
            return true;
        }
    }

    if(objModule.m_aryLeft.length > 0)
    {
        return true;
    }
    return false;
}

function OutputModule(objModule)
{
    Output(objModule.m_strHeader);
    for(var i = 0; i < objModule.m_aryErrors.length; ++i)
    {
        if(IsNeedPrint(objModule.m_aryErrors[i].m_iType))
        {
            OutputArray(objModule.m_aryErrors[i].m_aryContent);
        }
    }

    Output("");

    var bIsWrapupErrorOutput = false;

    for(var j = 0; j < objModule.m_aryWrapupErrors.length; ++j)
    {
        if(IsNeedPrint(objModule.m_aryWrapupErrors[j].m_iType))
        {
            OutputArray(objModule.m_aryWrapupErrors[j].m_aryContent);
            bIsWrapupErrorOutput = true;
        }
    }

    if(bIsWrapupErrorOutput)
    {
        Output("");
    }

    if(objModule.m_aryWrapupLeft.length || objModule.m_aryLeft.length)
    {
        Output("!!!Error!!!Something is left.");
        OutputArray(objModule.m_aryWrapupLeft);
        OutputArray(objModule.m_aryLeft);
    }
}

var g_iModuleCount = 0;
var g_strModuleHeader = "";
var g_strFilePath = "";
var g_aryModuleContent = new Array();
var g_aryErrorModules = new Array();

function WriteConsole(str)
{
    if(g_bCloseFilter)
    {
        Output(str);
        return;
    }

    if(0 == str.search(regIncrediBuildWaitingFor))
    {
        // 等待任务信息,这句会打印到不是头儿的位置,直接屏蔽
        return;
    }
    if(0 == str.search(regPCLintHeader))
    {
        // PCLint版本号,直接不打印
        return;
    }

    var reret = regModuleHeader.ExecNoRecord(str);
    if(reret && (5 == reret.length))
    {
        g_iModuleCount++;
        // 模块开始,可能是Wrap-up结束
        if("" != g_strModuleHeader)
        {
            var objModule = new Module(g_strModuleHeader, g_strFilePath, g_aryModuleContent);
            if(IsModuleHasPrintError(objModule))
            {
                // 需要等待最后输出的
                g_aryErrorModules.push(objModule);
                if(!g_bOnlyOne)
                {
                    Output(g_strModuleHeader);
                    Output(strPoints);
                }
            }
            else
            {
                // 立即输出的
                OutputModule(objModule);
            }
        }

        // 开始新模块
        // 模块头加上编号,便于了解进度
        if(!g_bOnlyOne)
        {
            g_strModuleHeader = str.replace(regModuleHeader1Part, "--- Module " + g_iModuleCount.Format(4) + " :");
        }
        else
        {
            g_strModuleHeader = str;
        }
        g_strFilePath = reret[1];
        g_aryModuleContent.Clear();
        return;
    }

    if("" != g_strModuleHeader)
    {
        // 缓存
        g_aryModuleContent.push(str);
    }
    else
    {
        // 还没进入模块,直接输出
        Output(str);
    }
}

function WriteFinish()
{
    // 模块开始,可能是Wrap-up结束
    if("" != g_strModuleHeader)
    {
        var objModule = new Module(g_strModuleHeader, g_strFilePath, g_aryModuleContent);
        if(IsModuleHasPrintError(objModule))
        {
            // 需要等待最后输出的
            g_aryErrorModules.push(objModule);
            if(!g_bOnlyOne)
            {
                Output(g_strModuleHeader);
                Output(strPoints);
            }
        }
        else
        {
            // 立即输出的
            OutputModule(objModule);
        }
    }
}

function RefreshErrorList(aryPaths)
{
    try
    {
        var fso = new ActiveXObject("Scripting.FileSystemObject");

        if(0 != aryPaths.length)
        {
            var temp = new Array();

            var oldPaths = new Array();
            if(fso.FileExists(strErrorOutPutFile))
            {
                var objOutPutFile = fso.OpenTextFile(strErrorOutPutFile, 1 , false);
                while (!objOutPutFile.AtEndOfStream)
                {
                    var strLine = objOutPutFile.ReadLine();
                    if(("###**********B**********###" + WScript.ScriptFullName) == strLine)
                    {
                        break;
                    }
                    temp.push(strLine);
                }
                while (!objOutPutFile.AtEndOfStream)
                {
                    var strLine = objOutPutFile.ReadLine();
                    if(("###**********E**********###" + WScript.ScriptFullName) == strLine)
                    {
                        break;
                    }
                    oldPaths.push(strLine);
                }
                while (!objOutPutFile.AtEndOfStream)
                {
                    var strLine = objOutPutFile.ReadLine();
                    temp.push(strLine);
                }
                objOutPutFile.Close();
            }

            // 判断有木有变化
            var bSame = false;
            if(oldPaths.length == aryPaths.length)
            {
                for(var i = 0; i < oldPaths.length; ++i)
                {
                    if(oldPaths[i] != aryPaths[i])
                    {
                        break;
                    }
                }
                if(i == oldPaths.length)
                {
                    bSame = true;
                }
            }

            if(!bSame)
            {
                var objOutPutFile = fso.OpenTextFile(strErrorOutPutFile, 2 , true);
                for(var i = 0; i < temp.length; ++i)
                {
                    objOutPutFile.WriteLine(temp[i]);
                }
                objOutPutFile.WriteLine("###**********B**********###" + WScript.ScriptFullName);
                for(var i = 0; i < aryPaths.length; ++i)
                {
                    objOutPutFile.WriteLine(aryPaths[i]);
                }
                objOutPutFile.WriteLine("###**********E**********###" + WScript.ScriptFullName);
                objOutPutFile.Close();
            }
        }
        else
        {
            // 没有文件出错
            if(fso.FileExists(strErrorOutPutFile))
            {
                fso.DeleteFile(strErrorOutPutFile);
            }
        }
    }
    catch (e)
    {
        Output("!!!Error!!!File Operate." + e.name + ":" + e.message);
    }
}

function main()
{
    if(WScript.Arguments.length >= 1 && WScript.Arguments.length <= 2 && WScript.Arguments(0) != "")
    {
        var bRefreshErrorList = true;
        if(WScript.Arguments.length == 2 && WScript.Arguments(1) != "")
        {
            var strOptionList = WScript.Arguments(1);
            var aryOptions = strOptionList.split("|");
            if(ExistInArray(aryOptions, "OnlyOne"))
            {
                g_bOnlyOne = true;
            }
            if(ExistInArray(aryOptions, "CloseFilter"))
            {
                g_bCloseFilter = true;
            }
        }

        var WshShell = new ActiveXObject("WScript.Shell");

        var process = WshShell.Exec(WScript.Arguments(0));
        var task = new Task((new Date()).getVarDate(), process);

        while(!task.m_info.StdOut.AtEndOfStream)
        {
            var tmpchar = task.m_info.StdOut.ReadLine();
            WriteConsole(tmpchar);
        }

        // 剩下的全部输出
        WriteFinish();

        var aryPaths = new Array();
        // 输出有错误的
        for(var i = 0; i < g_aryErrorModules.length; ++i)
        {
            OutputModule(g_aryErrorModules[i]);
            var strPath = g_aryErrorModules[i].m_strFilePath;
            if(-1 != strPath.search(" "))
            {
                strPath = "\"" + strPath + "\"";
            }
            aryPaths.Insert(strPath);
        }

        if(!g_bOnlyOne)
        {
            RefreshErrorList(aryPaths);
        }

        if(aryPaths.length)
        {
            //Output("-1");
            WScript.Quit(-1);
        }
        else
        {
            //Output("0");
            WScript.Quit(0);
        }
    }
    else
    {
        for(var i = 0; i < WScript.Arguments.length; ++i)
        {
            Output(WScript.Arguments(i));
        }
        //Output("-1");
        WScript.Quit(-1);
    }
}

main();

 

 mulitypclint.bat

 

::本脚本不用call的原因是 call的效率实在是低,不过不用call便无法支持循环中退出

@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
::切换到bat所在目录
cd /d %~dp0
::跳出Lint目录,跳到工程目录
cd ..

::修复js文件的关联,否则js脚本无法执行
reg add "hkcr\.js" /ve /d JSFile /f >nul
reg add "hkcr\.vbs" /ve /d vbsfile /f >nul
::assoc .vbs=vbsfile
set timebase=%time:~0,2%%time:~3,2%%time:~6,2%

set PRJ_DIR=%CD%
set WORK_FILE=lint
set BAT=run.bat
set CFG_FILE_LIST=filelist.txt
set ERR_FILE_LIST=errorfilelist.txt
set SOURCE=
set PROCESS_STATE=
set Mode=Auto

::当存在出错文件时,是否只执行出错文件
FOR /l %%x in (1,1,9) do ( 
    SHIFT /%%x
    IF "%1"=="" (
        GOTO :BREAK1
    )
    
    IF /I "%1"=="-ForceNormal" (
        set Mode=Normal
    )
    
    IF /I "%1"=="-ForceError" (
        set Mode=Error
    )
) 
:BREAK1

::进工作目录
IF NOT EXIST %WORK_FILE% (
    echo No %WORK_FILE%!!!
    EXIT
)

cd %WORK_FILE%

IF /I %Mode%==Auto (
    IF EXIST %ERR_FILE_LIST% (
        echo 上次执行存在错误,先过一遍错误文件
        set PROCESS_STATE=错误扫描,文件列表:%ERR_FILE_LIST%
        CALL :PROCESS %ERR_FILE_LIST%
        
        IF EXIST %ERR_FILE_LIST% (
            echo 仍存在错误
            EXIT
        ) ELSE (
            echo 错误解决
        )
    )
) ELSE (

    IF /I %Mode%==Error (
        IF EXIST %ERR_FILE_LIST% (
            echo 上次执行存在错误,只扫描错误文件
            set PROCESS_STATE=错误扫描,文件列表:%ERR_FILE_LIST%
            CALL :PROCESS %ERR_FILE_LIST%
            EXIT
        )
    )
)

IF EXIST %CFG_FILE_LIST% (
    set PROCESS_STATE=普通扫描,文件列表:%CFG_FILE_LIST%
    CALL :PROCESS %CFG_FILE_LIST%
) ELSE (
    echo No %CFG_FILE_LIST% !!!
)

EXIT

:PROCESS
    set SOURCE_CONFIG=%~1

    set addStoreCount=0
    set delStoreCount=0
    set duplicateCount=0

    ::遍历文件列表
    FOR /F "eol=/delims=" %%i in (%SOURCE_CONFIG%) do (
        set fileline=%%~i
        
        set isannotate=false
        IF "!fileline:~0,1!"=="#" (
            set isannotate=true
        )
        IF "!fileline:~0,2!"=="//" (
            set isannotate=true
        )
        
        IF !isannotate!==false (
            set isdel=false
            IF "!fileline:~0,1!"=="|" (
                set isdel=true
                set fileline=!fileline:~1!
            )
            
            IF NOT "!fileline!"=="" (
                set fileorfolder="!fileline:%%PRJ_DIR%%=%PRJ_DIR%!"
                IF !isdel!==false (
                    set existfile=false
                    FOR /F "delims=" %%j in ('dir /s /b /A:-D !fileorfolder!') do (
                        IF EXIST "%%j" (
                            set existfile=true
                            
                            ::判重标识
                            set duplicate=false
                            FOR /L %%k IN (0,1,!addStoreCount!) do (
                                IF /I !addStore[%%k]!=="%%j" (
                                    set duplicate=true
                                )
                            )
                            
                            ::判重
                            IF !duplicate!==false (
                                set addStore[!addStoreCount!]="%%j"
                                set /a addStoreCount=addStoreCount+1
                            ) ELSE (
                                set /a duplicateCount=duplicateCount+1
                            )
                        )
                    )
                    
                    IF !existfile!==false (
                        echo !fileline! error
                        echo !fileorfolder!
                    )
                ) ELSE (
                    set existfile=false
                    FOR /F "delims=" %%j in ('dir /s /b /A:-D !fileorfolder!') do (
                        IF EXIST "%%j" (
                            set existfile=true
                            
                            ::判重标识
                            set duplicate=false
                            FOR /L %%k IN (0,1,!delStoreCount!) do (
                                IF /I !delStore[%%k]!=="%%j" (
                                    set duplicate=true
                                )
                            )
                            
                            ::判重
                            IF !duplicate!==false (
                                set delStore[!delStoreCount!]="%%j"
                                set /a delStoreCount=delStoreCount+1
                            ) ELSE (
                                set /a duplicateCount=duplicateCount+1
                            )
                        )
                    )
                    
                    IF !existfile!==false (
                        echo !fileline! error
                        echo !fileorfolder!
                    )
                )
            )
        )
    )

    set timemid=%time:~0,2%%time:~3,2%%time:~6,2%
    set /a timemiddiff=%timemid%-%timebase%
    echo 遍历耗时%timemiddiff%秒

    ::清空临时环境变量,否则后面执行xgConsole时会尝试解析这些环境变量而出错
    set fileline=
    set fileorfolder=
    set existfile=
    set duplicate=

    ::重新生成bat
    IF EXIST "%BAT%" (
        del "%BAT%"
    )

    echo @ECHO OFF >>%BAT%
set fileCount=0
    ::按实际大小遍历
    set /a storeEnd=addStoreCount-1
    FOR /L %%i IN (0,1,!storeEnd!) do (
        IF NOT !addStore[%%i]!=="" (
            set delete=false
            FOR /L %%j IN (0,1,!delStoreCount!) do (
                IF /I !delStore[%%j]!==!addStore[%%i]! (
                    set delete=true
                )
            )
            IF !delete!==false (
                call :GetFileName !addStore[%%i]!
                set fileName=!GetFileName!
                echo xgSubmit.exe /group=UTest /allowremote=on /CAPTION="!fileName!" # cscript /nologo .\\lintfilter.js ".\\lint-nt.exe -u -I.\\lnt -I.\\lint std.lnt !addStore[%%i]!" "OnlyOne" >>%BAT%
set /a fileCount=fileCount+1
            )
            set addStore[%%i]=
        )
    )

    echo xgWait.exe /group=UTest >>%BAT%
    ::echo echo All Task Finished! >>%BAT%

    ::echo TaskInfo FileCount:!addStoreCount!  Duplicate:!duplicateCount!
    set /A commandcount=!fileCount!*2
    title 文件总数:!fileCount!  重复数:!duplicateCount! 执行总数:!commandcount! (!PROCESS_STATE!)

    cscript /nologo lintfilter.js "xgConsole /NOLOGO /MaxCPUS=500 /AvoidLocal=On /command=%BAT%"
    ::cscript /d /nologo lintfilter.js "xgConsole /ShowAgent /NOLOGO /MaxCPUS=500 /AvoidLocal=On /command=%BAT%"

    set timeend=%time:~0,2%%time:~3,2%%time:~6,2%
    set /a timeenddiff=%timeend%-%timebase%
    echo 总耗时%timeenddiff%秒

    ::清理临时文件
    IF EXIST "%BAT%" (
        del "%BAT%"
    )

GOTO :eof

:GetFileName
    set GetFileName=%~nx1
GOTO :eof

 

posted @ 2013-09-09 20:12  dzqabc  阅读(6)  评论(0编辑  收藏  举报