set filename /usr/share/fortune/fortunes ;# put your own here
package require Tk
pack [message .m -font {Courier 10} -textvariable fortune -width 800]
bind . <1> showFortune
set size [file size $filename]
set fp [open $filename]
proc showFortune {} {
global fp size fortune
seek $fp [expr {int(rand()*$size)}]
while {[gets $fp line]>=0 && $line!="%"} {}
set fortune ""
while {[gets $fp line]>=0 && $line!="%"} {
append fortune $line\n
}
}
showFortuneramsan (2003-07-24) says: if you plan also to deal with the offensive files (normally ended with -0, then it is necessary to unencrypt them. They are in rot13 format. Look at rot13 or use something like (taken from that page):
set fortune [subst [regsub -all {[a-zA-Z]} \
[regsub -all "\[\[$\\\\\]" $fortune {\\&}] \
{[format %c [expr [set c [scan & %c]]\&96|(($c\&31)+12)%26+1]]}]]RS prefers this: set text [string map -nocase {
a n b o c p d q e r f s g t h u i v j w k x l y m z
n a o b p c q d r e s f t g u h v i w j x k y l z m} $line]
