# Copyright for the Uniform Repository Service (c) 1995 - 1999, # by Gerald Banon. All rights reserved. # Version 2.1 # mirror2.tcl (old version of mirror.tcl) proc CompareOccurrence {a b} { set a1 [lindex $a 1] set b1 [lindex $b 1] return [expr $a1>$b1?-1:1] } proc CompareKey {a b} { set a0 [lindex $a 0] set b0 [lindex $b 0] return [string compare $a0 $b0] } proc GetConversionTable {currentRep rep language} { global env set colPath $env(DOCUMENT_ROOT) Load $colPath/col/$currentRep/doc/@siteList.txt fileContent foreach {site loCoInRep} $fileContent { lappend siteList $site } package require http 2.0 foreach serverAddress $siteList { if [catch {http::geturl \ http://$serverAddress/col/$rep/doc/${language}FieldName.tcl} token] { } else { # the file exists on this host eval [http::data $token] } } } proc CreateAbbreviation {currentRep rep language pattern} { # pattern example: ^v global abbreviationArray set col ../../../../.. set URLibServiceRepository dpi.inpe.br/banon/1998/08.02.08.56 source ../$col/$URLibServiceRepository/doc/utilities1.tcl # source ../$col/$rep/doc/${language}FieldName.tcl GetConversionTable $currentRep $rep $language set fieldList [array names field::conversionTable ?*] ;# ?* to drop {} set fieldList [Grep $pattern $fieldList] foreach field $fieldList { set firstLetters [ExtractFirstCharacters fieldList $field] set abbreviationArray($field) $firstLetters } return $fieldList } proc CreateMirror {} { global env global currentRep global numberOfSatisfiedQueries global numberOfSites global s # > 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 set pathInfo [file split $env(PATH_INFO)] set pathInfoLength [llength $pathInfo] # currentRep regsub -all { } [lrange $pathInfo 1 4] {/} currentRep if {$pathInfoLength == 5} { set frameName "" } else { set frameName [lindex $pathInfo 5] source ../$col/$rep/doc/${language}$frameName.tcl } switch -exact -- $frameName { Form { set output [subst [set ${rep}::body]] } Button { set output [subst [set ${rep}::body]] } Help { # array set abbreviationArray $env(ABBREVIATION_LIST) CreateAbbreviation $currentRep $rep $language ^a|^y global field::conversionTable global abbreviationArray set output [subst [set ${rep}::body]] } AdvancedHelp { set fieldList \ [CreateAbbreviation $currentRep $rep $language ^v] global field::conversionTable global abbreviationArray foreach field $fieldList { lappend fLE $field } # fieldListExample set fieldListExample [join $fLE { and }] set output [subst [set ${rep}::body]] } Contributors { # contributorList global contributorList global loCoInRepList source ../$col/$URLibServiceRepository/doc/utilities1.tcl set query {list GetEntries "targetfile @reference.bib [join $loCoInRepList]" yes brief ../} MultipleSubmit $query contributorList set contributorList [join $contributorList] # query2String set query2 "targetfile @reference.bib [join $loCoInRepList]" regsub -all { } $query2 {+} query2 set query2String "query2=$query2&choice2=brief&case2=yes" set contributorList \ [lsort -command CompareKey $contributorList] set entryList {} foreach entry $contributorList { lappend entryList [join $entry \n] } set contributorList [join $entryList] set output [subst [subst [set ${rep}::body]]] } Field { # fieldNameList # set fieldNameList [join $env(FIELD_NAME_LIST)
] CreateAbbreviation $currentRep $rep $language .* global field::conversionTable global abbreviationArray foreach {index value} [array get conversionTable] { set inverseTable($value) $index } # array set abbreviationArray $env(ABBREVIATION_LIST) foreach value [lsort -dictionary [array names inverseTable ?*]] { lappend fieldNameList $value \; \;$abbreviationArray($inverseTable($value)) } set fieldNameList [join $fieldNameList] set output [subst [set ${rep}::body]] } Word { # wordOccurrenceList global wordOccurrenceList source ../$col/$URLibServiceRepository/doc/utilities1.tcl set query {list GetWordOccurrences} MultipleSubmit $query wordOccurrenceList set wordOccurrenceList [join [join $wordOccurrenceList]] foreach {word occurrence} $wordOccurrenceList { if [info exists occurrenceTable($word)] { set occurrenceTable($word) [expr \ $occurrenceTable($word) + $occurrence] incr occurrenceTable2($word) } else { set occurrenceTable($word) $occurrence set occurrenceTable2($word) 1 } } # just the words commun to all the active sites must be considered foreach word [array names occurrenceTable] { if {$occurrenceTable2($word) != "$numberOfActiveSites"} { unset occurrenceTable($word) } } set wordList [array names occurrenceTable] # wordListLength set wordListLength [llength $wordList] set list {} foreach word $wordList { lappend list [list $word $occurrenceTable($word)] } set wordOccurrenceList [lsort -command CompareOccurrence $list] GetConversionTable $currentRep $rep $language global field::conversionTable set output [subst [set ${rep}::body]] } About { global numberOfItems source ../$col/$URLibServiceRepository/doc/utilities1.tcl set query {list GetNumberOfItems} MultipleSubmit $query numberOfItems set numberOfActiveSites $numberOfSatisfiedQueries set numberOfItems [join $numberOfItems] # nOR and nOFT set nOR 0 set nOFT 0 foreach {numberOfReferences numberOfFullTexts} \ $numberOfItems { set nOR [expr $nOR + $numberOfReferences] set nOFT [expr $nOFT + $numberOfFullTexts] } # URLibReferenceRep set URLibReferenceRep xxx set output [subst [set ${rep}::body]] } default { set output " Bibliographic Mirror in $currentRep Your browser cannot display frames. " } } puts {Content-Type: text/html} puts {} puts $output # < }