##Eskil Plugin : Swap sides of contents

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

# This plugin swaps data between files. A fairly useless thing.
# This is to test and exemplify how to use yield in a plugin.

# 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 {[info commands yield] eq ""} {
        puts $cho "Swap plugin must be run with Tcl 8.6 or newer"
        return 1
    }
    # Read all data from both sides
    set ::data($side) [read $chi]
    yield

    # Output data from other side
    if {$side eq "left"} {
        puts $cho $::data(right)
    } else {
        puts $cho $::data(left)
    }

    # Signal that the file after processing should be used both
    # for comparison and for displaying.
    return 1
}
