#!/bin/sh # -*-Tcl-*- the next line restarts using wish \ exec wish "$0" "$@" # slovnik -- X rozhraní pro česko-anglický slovník ecd # Copyright (C) 1997 Pavel Rychlý # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #default values set local 0 set ecdpath /usr/local/lib/ecd/ set maxlines 30 set terminal 0 #process arguments while {$argv != ""} { switch -- [lindex $argv 0] { -? - -help { puts {pouziti: slovnik [-local] [-dir ECDDIR] [-lines MAXLINES] [-terminal]} exit 1 } -local { set local 1 } -dir { set ecdpath [lindex $argv 1]/ set argv [lreplace $argv 0 0] } -lines { set maxlines [lindex $argv 1] set argv [lreplace $argv 0 0] } -terminal { set terminal 1 } default { puts "neznama volba `[lindex $argv 0]'" } } set argv [lreplace $argv 0 0] } if [catch {package require http}] { set local 1 } proc makemainwindow {} { entry .slovo -textvar slovo label .preklad -textvar preklad -justify left pack .slovo -side top -fill both pack .preklad -side left bind .slovo preloz bind . <3> {catch {set slovo [selection get]}; preloz} bind . {destroy .} bind . {destroy .} bind . {destroy .} bind . volby bind . volby bind .preklad <2> {set slovo ""; set preklad ""} bind . help bind . help bind . help focus .slovo wm title . Slovnik } proc prelozwww {} { global slovo preklad maxlines regsub -all " " $slovo "+" htmlsl set url "http://ww2.fce.vutbr.cz/bin/ecd?slovo=$htmlsl&max=$maxlines" set t [::http::geturl $url] # {.*
(.*)
.*} if [regsub ".*
\n(.*)
.*" [::http::data $t] {\1} htmlprek] { regsub -all {<[^>]*>} $htmlprek {} preklad } else { set preklad "NENALEZENO" } unset $t } proc runecd {lang} { global slovo maxlines ecdpath set sl [open "|${ecdpath}ecd" r+] puts $sl "$slovo\n$lang\n\n\n\n\n\n" flush $sl set ret "" set pocet 0 while {![eof $sl] && $pocet < $maxlines} { incr pocet regsub "^.*: *" [gets $sl] {} radek if {$radek != ""} { append ret "\n" $radek } } catch {close $sl} return $ret } proc prelozloc {} { global preklad set prek [runecd c] if {$prek == ""} { set prek [runecd a] } if {$prek == ""} { set preklad "NENALEZENO" } else { regsub -all "^\n*" $prek {} preklad } } if $local { proc preloz {} prelozloc catch {cd $ecdpath} } else { proc preloz {} prelozwww } proc volby {} { global maxlines if [winfo exists .v] { destroy .v return } toplevel .v wm title .v Volby label .v.l -text "Maximalni pocet radek" entry .v.e -textvar maxlines -width 4 button .v.b -text OK -command {destroy .v} pack .v.l .v.e .v.b -side top focus .v.e } proc help {} { if [winfo exists .h] { destroy .h return } toplevel .h wm title .h Napoveda label .h.l -justify left -text {Ovladani: preklad <3> vlozeni vyberu a preklad konec volby <2> vymazani napoveda } catch {.h.l configure -font fixed} button .h.b -text OK -command {destroy .h} pack .h.l .h.b -side top } if {$terminal} { catch {destroy .} while {[gets stdin slovo] >= 0} { preloz puts $preklad } exit } else { makemainwindow }