Eskil

Artifact [96ee8809a1]
Login

Artifact 96ee8809a181acdc7acb0c26c782521fdbe305ea:


##Eskil Plugin : Compare after filtering lines
## Option -grepre : Regexp to filter on
#
# This plugin only compares lines that match a regexp pattern.
# Example usage:
# eskil -plugin grep -grepre "<t>" f1 f2

# 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 may declare command line options that should be allowed through
# to ::argv

# 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} {
    if {[catch {llength $::Info}]} {
        puts $cho "Grep plugin needs -plugininfo parameter to be a list"
        return 1
    }
    # Look for parameters in info string
    set opts(-re) "."
    foreach {opt val} $::Info {
        set opts($opt) $val
    }
    # And on command line
    set i [lsearch -exact $::argv -grepre]
    if {$i >= 0} {
        incr i
        set opts(-re) [lindex $::argv $i]
    }
    while {[gets $chi line] >= 0} {
        if {[regexp -- $opts(-re) $line]} {
            puts $cho $line
        }
    }
    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}