#!/usr/bin/tclsh8.3 ############################################################################### # # Abfrageprozessor für Leo.org # Erik Buchmann, August '01 # an neues Layout von Leo angepasst, Juli '02 set debug false regsub {[ ]+} $argv {+} search # Anfrage aufbauen set client_request "\ GET /?search=$search HTTP/1.0 Connection: close User-Agent: dict.tcl Host: dict.leo.org Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* Accept-Language: en Accept-Charset: iso-8859-1,*,utf-8" regsub -all -lineanchor "^\[\t \n\]+" [string trim $client_request] "" client_request if {$debug} {puts "Opening socket" ; flush stdout} # Socket aufmachen und Daten holen if {[catch {set server_channel [socket dict.leo.org 80]}]} { puts "Got Error: Server not found" exit } if {$debug} {puts "Sending request" ; flush stdout} fconfigure $server_channel -translation crlf -blocking true puts $server_channel "$client_request\n" flush $server_channel if {$debug} {puts "Get header" ; flush stdout} #Header holen set line "foo" set header "" while {$line!="" } { set line [gets $server_channel] set header "$header\n$line" } if {$debug} {puts "Get data" ; flush stdout} # Daten holen fconfigure $server_channel -translation binary -blocking true set content [read $server_channel] close $server_channel if {$debug} {puts "Calculate data" ; flush stdout} # regsub {^.*?(search results)} $content {} content # regsub {^.*?(GERMAN)} $content {} content set content [string range $content [expr [string first "GERMAN" $content]+6] end] set content [string range $content 0 [string first "\n" $content]] regsub -all {\} $content "\n" content regsub -all { } $content " " content regsub -all {\} $content "|" content regsub -all {\<.+?\>} $content "" content regsub -all {[\t ]{2,}} $content " " content set clist [split $content "\n"] set count 0 foreach x $clist { set left "" set right "" regexp {^ *\| *\|(.*?)\| \|(.*?)\|} $x nix left right set left [string trim $left] set right [string trim $right] set fill [string repeat "." [expr 35 - [string length $left]]] if {$right != "" && $left != ""} { puts "$left $fill $right" } incr count if {$count>24} {exit} }