#! /bin/bash # \ export TCL_LIBRARY=$HOME/tcl/lib/tcl ; \ exec /usr/local/bin/tclsh $0 "$@" source h:/fromUTD/tcl/lib/tcl/ListSet.tcl source h:/fromUTD/tcl/lib/tcl/Random.tcl # Read in the source file line by line, until there are no more. # while {[gets stdin instuff] > -1} { # # We're going to use Regular Expressions to find words because it's # the no-brainer. # while {[string length $instuff]} { # First, pick any non-word stuff from the front of the line # and shoot it out the output. # if {[regexp {(^[^A-Za-z]+)(.*$)} $instuff ta nonWord instuff]} { puts -nonewline $nonWord } # We now either have some word stuff at the head of the line, # or the line is finally empty (finished being processed). # # Which is it? # if {[regexp {(^[A-Za-z]+)(.*$)} $instuff ta word instuff]} { # # We found a word. Deal with it, one way or another. # # First, make a list of the letters (wlist) # and get the letter count (wlen). # set wlen [llength [set wlist [split $word {}]]] if {$wlen == 4} { # # Here, we apply a "standard" scramble # to the middle two letters. # set word [join [concat \ [list [lindex $wlist 0]] \ [list [lindex $wlist 2]] \ [list [lindex $wlist 1]] \ [list [lindex $wlist end]] \ ] {}] } elseif {$wlen > 4} { # # There are more than two letters in the middle of this # word; randomize 'em. # set word [join [concat \ [list [lindex $wlist 0]] \ [ScrambleList [lrange $wlist 1 end-1]] \ [list [lindex $wlist end]] \ ] {}] } # Emit the word. # puts -nonewline $word } } # End of line. Mirror this to the output. # puts {} } exit 0