# Copyright for the Uniform Repository Service (c) 1995 - 1999, # by Gerald Banon. All rights reserved. # Version 2.1 # mirrorsearch2.tcl (old version of mirrorsearch.tcl) proc DecodeURL {url} { regsub -all {\+} $url { } url regsub -all {%([0-9a-hA-H][0-9a-hA-H])} $url \ {[format %c 0x\1]} url return [subst $url] } proc CompareKey {a b} { set a1 [lindex $a 1] set b1 [lindex $b 1] return [string compare $a1 $b1] } proc GetAccessDate {accessDate} { set seconds [clock seconds] set year [clock format $seconds -format %Y] set month [clock format $seconds -format %b] set day [clock format $seconds -format %d] return [subst $accessDate] } proc MirrorSearch {} { global env global cgi global currentRep global searchResult global numberOfActiveSites global numberOfSites global s # > if [info exists env(QUERY_STRING)] { foreach {name value} [split $env(QUERY_STRING) &=] { set cgi([DecodeURL $name]) [DecodeURL $value] } } if ![info exists cgi(case)] {set cgi(case) no} set col ../../../../.. set URLibServiceRepository dpi.inpe.br/banon/1998/08.02.08.56 # create mirrorRepArray array set mirrorRepArray $env(MIRROR_REP_ARRAY) # create mirrorRepArray - end # find the language set language en ;# default language foreach preferredLanguage [split $env(HTTP_ACCEPT_LANGUAGE) ,] { # regexp {..} $preferredLanguage preferredLanguage ;# pt-BR -> pt if {[lsearch -exact [array names mirrorRepArray] \ $preferredLanguage] != -1} { set language $preferredLanguage break } } # find the language - end # find the repository of the language set rep $mirrorRepArray($language) # find the repository of the language - end source ../$col/$rep/doc/${language}SearchResult.tcl source ../$col/$rep/doc/${language}FieldName.tcl set pathInfo [file split $env(PATH_INFO)] # currentRep regsub -all { } [lrange $pathInfo 1 4] {/} currentRep source ../$col/$URLibServiceRepository/doc/utilities1.tcl set query {list GetEntries $cgi(query) $cgi(case) $cgi(choice)} MultipleSubmit $query searchResult set searchResult [join $searchResult] if [info exists cgi(lastupdate)] { if [regexp $cgi(lastupdate) $searchResult] { # accessdate set accessDate [subst [GetAccessDate ${Access Date}]] # searchResult set searchResult [join $searchResult] set searchResult [join $searchResult \n] set output [subst [subst $bodyFull]] } else { # queryString set queryString query=$cgi(query2)&choice=$cgi(choice2)&case=$cgi(case2) regsub -all { } $queryString {+} queryString set output [subst $bodyOutOfDate] } } else { # > if [regexp {^<.*>$} $searchResult] { set output [subst [set bodyForError]] } else { # numberOfEntries # set searchResult [split $searchResult \n] set numberOfEntries [llength $searchResult] if {$numberOfEntries > 10 && ![info exists cgi(continue)]} { set output [subst $bodyForContinue] } else { # accessdate set accessDate [subst [GetAccessDate ${Access Date}]] # query2String set query2String query2=$cgi(query)&choice2=$cgi(choice)&case2=$cgi(case) regsub -all { } $query2String {+} query2String # format begin and end set begin1 {} set end1 {} set begin2 {} set end2 {} if [regsub {short|brief} $cgi(choice) {} format] { # regsub {html} $format {HTML} format if [regexp {^$} $format] { set begin2 {} } regsub {bibtex} $format {BibTeX} format regsub {refer} $format {Refer} format } else { set format "" set begin1 {} } # searchResult set searchResult [lsort -command CompareKey $searchResult] set entryList {} foreach entry $searchResult { lappend entryList [join $entry \n] } # set entryList $searchResult set searchResult [join $entryList] if {$numberOfEntries <= 1} { if [regsub {0} $numberOfEntries {$No} numberOfEntries] { set begin1 {} set begin2 {} set end2 {} } set output [subst [subst $bodySingular]] } else { set output [subst [subst $bodyPlural]] } } } # < } puts {Content-Type: text/html} puts {} puts $output # < }