LoginSignup
6
5

More than 3 years have passed since last update.

WinMergeプラグイン(COBOL行頭番号無視)

Last updated at Posted at 2016-08-06

仕事でCOBOLのソースコードを比較したい時があった。
先輩方はdiff等を使っていたが、個人的にWinMergeを使いたかったので作成。

COBOLは行頭に6桁の行番号を振ることが多く、WinMergeで普通に差分を取ると変更行以降すべてが差分になってしまう。この問題を解決するためにプラグインで行先頭6桁目までを除外するようにした。

IgnoreCobolLineNo.sct
<scriptlet>

<implements type="Automation" id="dispatcher">
    <property name="PluginEvent">
        <get/>
    </property>
    <property name="PluginDescription">
        <get/>
    </property>
    <property name="PluginFileFilters">
        <get/>
    </property>
    <property name="PluginIsAutomatic">
        <get/>
    </property>
    <method name="UnpackFile"/>
    <method name="PackFile"/>
</implements>

<script language="VBS">

Option Explicit

Function get_PluginEvent()
    get_PluginEvent = "FILE_PACK_UNPACK"
End Function

Function get_PluginDescription()
    get_PluginDescription = "COBOLソースコードの行番号を削除する(1-6桁目)"
End Function

Function get_PluginFileFilters()
    get_PluginFileFilters = "\.cbl$;\.ecb$"
End Function

Function get_PluginIsAutomatic()
    get_PluginIsAutomatic = True
End Function

Function UnpackFile(fileSrc, fileDst, pbChanged, pSubcode)
    Dim fso
    Dim foSrc
    Dim foDst

    Set fso = CreateObject("Scripting.FileSystemObject")

    '読み取り専用モード
    Set foSrc = fso.OpenTextFile(fileSrc, 1, True)
    '上書きモード
    Set foDst = fso.OpenTextFile(fileDst, 2, True)

    '1行づつ読み込む
    Dim srcLine
    Dim dstLine
    Do Until foSrc.AtEndOfStream
        srcLine = foSrc.ReadLine

        '行先頭の行番号(6桁)を削除する
        If Len(srcLine) - 6 <= 0 Then
            dstLine = ""
        Else
            dstLine = Right(srcLine, Len(srcLine) - 6)
        End If

        foDst.WriteLine(dstLine)
    Loop

    foSrc.Close
    foDst.Close

    Set foSrc = Nothing
    Set foDst = Nothing
    Set fso = Nothing

    pbChanged = True
    pSubcode = 0
    UnpackFile = True
End Function

Function PackFile(fileSrc, fileDst, pbChanged, pSubcode)
    PackFile = False
End Function

</script>
</scriptlet>
6
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5