Eskil

keyword.tcl at trunk
Login

File plugins/keyword.tcl artifact c3ced64263 on branch trunk


##Eskil Plugin : Ignore $Keywords$
#
# This plugin ignores keywords like $Revision$, both in file diff
# and in directory diff

# Example file for a plugin.
# A plugin's first line must start exactly like this one.
# The text after : is the summary you can get at the command line

# A plugin must define this procedure to do the job.
# side: left or right
# chi:  An input channel for reading the original file.
# cho:  An output channel for writing the processed file.
proc PreProcess {side chi cho} {
    while {1} {
        # Read data in large chunks for speed
        set data [read $chi 100000]
        if {$data eq ""} break
        # Replace keywords with nothing
        # Use line mode to be sure not to affect newlines
        regsub -all -line {\$\w+:[^\$]*\$} $data {} data
        puts -nonewline $cho $data
    }
    # Signal that the file after processing should be used only for
    # comparison, not for displaying.
    # The processed file must match the original line-wise.
    return 0
}

# To be used in directory diff, a plugin must define this procedure.
# ch1:  An input channel for reading the first file.
# ch2:  An input channel for reading the second file.
# info1: A dictionary with info about the first file.
# info2: A dictionary with info about the second file.
# Info dictionaries contain at least elements "name" and "size".
proc FileCompare {ch1 ch2 info1 info2} {
    set bufsz 65536
    # Assume that all keywords are in the first block
    set f1 [read $ch1 $bufsz]
    set f2 [read $ch2 $bufsz]
    regsub -all {\$\w+:[^\$]*\$} $f1 {} f1
    regsub -all {\$\w+:[^\$]*\$} $f2 {} f2
    # Compensate for any change in length
    if {[string length $f1] < [string length $f2]} {
        append f1 [read $ch1 [expr {[string length $f2] - [string length $f1]}]]
    }
    if {[string length $f2] < [string length $f1]} {
        append f2 [read $ch2 [expr {[string length $f1] - [string length $f2]}]]
    }
    if { ! [string equal $f1 $f2]} {
        # Returning 0 signals "not equal"
        return 0
    }
    # Return 1 means "equal"
    # Return 2 means "equal this far", and lets normal compare take over
    return 2
}