#!/bin/sh # Copyright for the Uniform Repository Service (c) 1997, # by Gerald Banon. All rights reserved. # Version 1.1 # start \ exec ../../../../../../dpi.inpe.br/banon/1997/10.21.17.24/doc/tk8.0/unix/wish "$0" ${1+"$@"} set col ../../../../.. set service dpi.inpe.br/banon/1995/08.08.00.00/not_sent/library_service if [file exists ../.setenv/library_location] { set fileid [open ../.setenv/library_location] set hn [gets $fileid] close $fileid set s1 "at $hn" } else { set s1 "" } # Set window title and geometry wm title . "URLib Service $s1" wm geometry . 54x20+0+0 # Create a frame for the menu bar. frame .menubar pack .menubar -side top -fill x # Create the command buttons. set width .7 set height .9 frame .menubar.quit -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.quit false pack .menubar.quit -side right set qui [button .menubar.quit.1 -text Quit -command exit -borderwidth 1 \ -cursor hand2] $qui config -disabledforeground red pack $qui -fill both -expand true frame .menubar.ui -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.ui false set wui [button .menubar.ui.1 -text ui -command Run-ui -borderwidth 1 \ -cursor hand2] $wui config -disabledforeground red set bgcolor [$wui cget -background] pack $wui -fill both -expand true frame .menubar.mr -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.mr false set wmr [menubutton .menubar.mr.1 -text mr -menu .menubar.mr.1.menu \ -relief raised -padx 3m -pady 1m -highlightthickness 1 \ -cursor hand2] set m [menu .menubar.mr.1.menu -tearoff 0] $wmr config -disabledforeground red pack $wmr -fill both -expand true bind $wmr <1> "Run1-mr $m" ;# button press frame .menubar.er -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.er false set wer [button .menubar.er.1 -text er -command Run-er -borderwidth 1 \ -cursor hand2] $wer config -disabledforeground red pack $wer -fill both -expand true frame .menubar.rr -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.rr false set wrr [button .menubar.rr.1 -text rr -command Run-rr -borderwidth 1 \ -cursor hand2] $wrr config -disabledforeground red pack $wrr -fill both -expand true frame .menubar.sr -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.sr false set wsr [button .menubar.sr.1 -text sr -command Run-sr -borderwidth 1 \ -cursor hand2] $wsr config -disabledforeground red pack $wsr -fill both -expand true frame .menubar.ir -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.ir false set wir [button .menubar.ir.1 -text ir -command Run-ir -borderwidth 1 \ -cursor hand2] $wir config -disabledforeground red pack $wir -fill both -expand true frame .menubar.um -width [format "%si" $width] \ -height [format "%sc" $height] pack propagate .menubar.um false set wum [button .menubar.um.1 -text um -command Run-um -borderwidth 1 \ -cursor hand2] $wum config -disabledforeground red set bgcolor [$wum cget -background] pack $wum -fill both -expand true pack .menubar.ui .menubar.mr .menubar.er .menubar.rr \ .menubar.sr .menubar.ir .menubar.um -side left # Create a text widget to log the output frame .output set log [text .output.log -width 80 -height 10 \ -borderwidth 2 -relief raised -setgrid true \ -yscrollcommand {.output.scroll set}] scrollbar .output.scroll -command {.output.log yview} pack .output.scroll -side right -fill y pack .output.log -side left -fill both -expand true pack .output -side top -fill both -expand true # Place dialog windows if [file exists ../.setenv/library_location] { set s1 "This file is located at . " } else { set s1 "" } set dui [label .output.ui -text "Update the index" -bg thistle -fg black] set hui [message .output.hui -text "ui button You click ui to update the local collection index html file (index.html). $s1 Any document or bibliographic changes are included in the index by clicking ui. If a repository has been previously selected (in the list box) then just the corresponding index entry is updated (it is much faster). The ui button color change reflects changes in the collection like making, removing or installing a repository." \ -bg thistle -fg black -aspect 600] bind .menubar.ui Enter-ui bind .menubar.ui Leave-ui proc Enter-ui {} { global dui hui xui set xui 1 set x1ui 0 after 1000 {set x1ui 1} vwait x1ui if {$xui == 1} { place $dui -in .output -relx 0.01 -rely 0.05 -anchor nw } set x2ui 0 after 2000 {set x2ui 1} vwait x2ui if {$xui == 1} { place $hui -in .output -relx 0.01 -rely 0.05 -anchor nw } } proc Leave-ui {} { global dui hui xui place forget $dui place forget $hui set xui 0 } set dmr [label .output.mr -text "Make a repository" -bg thistle -fg black] set hmr [message .output.hmr -text "mr button You click mr to make a new repository in the URLib collection where you can deposit your electronic document. The document can be in any format. Through a menu, you choose the document type (e.g., Artigle, Book, ...) for indexing purpose (see er button)." \ -bg thistle -fg black -aspect 600] bind .menubar.mr Enter-mr bind .menubar.mr Leave-mr proc Enter-mr {} { global dmr hmr width xmr set xmr 1 set x1mr 0 after 1000 {set x1mr 1} vwait x1mr if {$xmr == 1} { place $dmr -in .output -relx 0.01 -x [format "%si" $width] \ -rely 0.05 -anchor nw } set x2mr 0 after 2000 {set x2mr 1} vwait x2mr if {$xmr == 1} { place $hmr -in .output -relx 0.01 -rely 0.05 -anchor nw } } proc Leave-mr {} { global dmr hmr xmr place forget $dmr place forget $hmr set xmr 0 } set der [label .output.er -text "Edit a bibliographic reference" \ -bg thistle -fg black] set her [message .output.her -text "er button You click er to edit a bibliographic reference for indexing purpose. From the list box, you select the repository which contains the document you want to index, then you click the er button to open its bibliographic file." \ -bg thistle -fg black -aspect 600] bind .menubar.er Enter-er bind .menubar.er Leave-er proc Enter-er {} { global der her width xer set xer 1 set x1er 0 after 1000 {set x1er 1} vwait x1er if {$xer == 1} { place $der -in .output -relx 0.01 \ -x [format "%si" [expr 2*$width]] \ -rely 0.05 -anchor nw } set x2er 0 after 2000 {set x2er 1} vwait x2er if {$xer == 1} { place $her -in .output -relx 0.01 -rely 0.05 -anchor nw } } proc Leave-er {} { global der her xer place forget $der place forget $her set xer 0 } set drr [label .output.rr -text "Remove a repository" -bg thistle -fg black] set hrr [message .output.hrr -text "rr button You click rr to remove a repository and the document that it contains. From the list box, you select the repository you want to remove, then you click the rr button to remove it. You will be asked to confirm the remotion." \ -bg thistle -fg black -aspect 600] bind .menubar.rr Enter-rr bind .menubar.rr Leave-rr proc Enter-rr {} { global drr hrr width xrr set xrr 1 set x1rr 0 after 1000 {set x1rr 1} vwait x1rr if {$xrr == 1} { place $drr -in .output -relx 0.01 \ -x [format "%si" [expr 3*$width]] \ -rely 0.05 -anchor nw } set x2rr 0 after 2000 {set x2rr 1} vwait x2rr if {$xrr == 1} { place $hrr -in .output -relx 0.01 -rely 0.05 -anchor nw } } proc Leave-rr {} { global drr hrr xrr place forget $drr place forget $hrr set xrr 0 } set dsr [label .output.sr -text "Send a repository" -bg thistle -fg black] set hsr [message .output.hsr -text "sr button You click sr to send to someone else a repository and the document that it contains. From the list box, you select the repository you want to send, then you click the sr button to send it. You will be asked to enter the e-mail recipient address and then to choose including or not some other standart repositories." \ -bg thistle -fg black -aspect 600] bind .menubar.sr Enter-sr bind .menubar.sr Leave-sr proc Enter-sr {} { global dsr hsr width xsr set xsr 1 set x1sr 0 after 1000 {set x1sr 1} vwait x1sr if {$xsr == 1} { place $dsr -in .output -relx 0.01 \ -x [format "%si" [expr 4*$width]] \ -rely 0.05 -anchor nw } set x2sr 0 after 2000 {set x2sr 1} vwait x2sr if {$xsr == 1} { place $hsr -in .output -relx 0.01 -rely 0.05 -anchor nw } } proc Leave-sr {} { global dsr hsr xsr place forget $dsr place forget $hsr set xsr 0 } set dir [label .output.ir -text "Install a repository" \ -bg thistle -fg black] set hir [message .output.hir -text "ir button You click ir to install a repository and the document that it contains. The repository to be installed can be a repository that is in your mail box or in another local collection in your system file. By clicking the ir button, you will be asked to inform the reference of the repository you want to install. If you choose to install one from your mail box, you enter the corresponding e-mail number. If you choose to install one from another local collection, you enter its absolute path." \ -bg thistle -fg black -aspect 600] bind .menubar.ir Enter-ir bind .menubar.ir Leave-ir proc Enter-ir {} { global dir hir width xir set xir 1 set x1ir 0 after 1000 {set x1ir 1} vwait x1ir if {$xir == 1} { place $dir -in .output -relx 0.01 \ -x [format "%si" [expr 5*$width]] \ -rely 0.05 -anchor nw } set x2ir 0 after 2000 {set x2ir 1} vwait x2ir if {$xir == 1} { place $hir -in .output -relx 0.01 -rely 0.05 -anchor nw } } proc Leave-ir {} { global dir hir xir place forget $dir place forget $hir set xir 0 } set dum [label .output.um -text "Update the mirror" -bg thistle -fg black] set hum [message .output.hum -text "um button You click um to update the bibliographical mirror. The mirror can be accessed from the local collection index header. Any bibliographic changes made in any BibTeX files named doc/@reference.bib are included in the mirror by clicking um. Typically, each local collection index is associated with this name so its content will be compiled and included in the mirror. Updating the mirror can be time consuming... At the end you get in the log the message: . Any way, you can use the other buttons whence um is running." \ -bg thistle -fg black -aspect 600] bind .menubar.um Enter-um bind .menubar.um Leave-um proc Enter-um {} { global dum hum width xum set xum 1 set x1um 0 after 1000 {set x1um 1} vwait x1um if {$xum == 1} { place $dum -in .output -relx 0.01 \ -x [format "%si" [expr 6*$width]] \ -rely 0.05 -anchor nw set x2um 0 after 2000 {set x2um 1} vwait x2um if {$xum == 1} { place $hum -in .output -relx 0.01 -rely 0.05 -anchor nw } } } proc Leave-um {} { global dum hum xum place forget $dum place forget $hum set xum 0 } # Run procedures proc Run-ui {} { global input log wui wmr wer wrr wsr wir qui set sel [.entries.index.list curselection] if {$sel == ""} { set x "" } else { foreach i $sel { set x [.entries.index.list get $i] set x [lindex $x 0] } } if [catch {open "|nice ui $x |& cat" r+} input] { $log insert end $input\n } else { fileevent $input readable {Log ui} $log insert end "nice ui $x\n" $wui config -text Stop -command Stop-ui # $wui config -state disabled $wmr config -state disabled $wer config -state disabled $wrr config -state disabled $wsr config -state disabled $wir config -state disabled $qui config -state disabled } } proc Run1-mr {menu} { $menu delete 0 end foreach b {Article Book Booklet Image InBook InCollection InProceedings \ Manual MastersThesis Misc PhdThesis Proceedings TechReport \ Unpublished} { $menu add command -label $b -command "Run2-mr $b" } set fileList [glob -nocomplain ../clipboard/*] set directoryList "" foreach file $fileList { if [file isdirectory $file] {lappend directoryList $file} } # set fileList [glob -nocomplain ../clipboard/*.isis] if {$directoryList != ""} { $menu add cascade -label default -menu $menu.sub if ![winfo exists $menu.sub] { set subMenu [menu $menu.sub -tearoff 0] } else { set subMenu $menu.sub } $subMenu delete 0 end regsub -all {../clipboard/} $directoryList {} directoryList foreach directory $directoryList { $subMenu add command -label $directory \ -command \ "Run2-mr clipboard/$directory" } } } proc Run2-mr {type} { global input log wui wmr wer wrr wsr wir qui if [catch {open "|mr $type |& cat"} input] { $log insert end $input\n } else { fileevent $input readable {Log mr} $log insert end "mr $type\n" $wui config -state disabled $wmr config -state disabled $wer config -state disabled $wrr config -state disabled $wsr config -state disabled $wir config -state disabled $qui config -state disabled } } frame .entries proc Run-er {} { global log col service set sel [.entries.index.list curselection] if {$sel == ""} { $log insert end "er\n\n" $log insert end "select one entry\n\n" } else { foreach i $sel { set x [.entries.index.list get $i] $log insert end "er [lindex $x 0]\n\n" set x [.entries.index.list get $i] regsub { +} $x {/bib/} x regsub -all {:} $x {=} x set pwd [pwd] cd ../$col/$x if [catch {exec textedit a.bib &} input] { if [catch {exec \ /usr/openwin/bin/xview/textedit a.bib &} input] { $log insert end \ {couldn't execute "textedit": no such program\n} } } cd $pwd } } } proc Run-rr {} { global input log wui wmr wer wrr wsr wir qui set sel [.entries.index.list curselection] if {$sel == ""} { $log insert end "rr\n\n" $log insert end "select one entry\n\n" } else { foreach i $sel { set x [.entries.index.list get $i] if [catch {open "|nice rr [lindex $x 0] |& cat" \ r+} input] { $log insert end $input\n } else { fileevent $input readable {Log rr} $log insert end "rr [lindex $x 0]\n" $wrr config -text Stop -command Stop-rr $wui config -state disabled $wmr config -state disabled $wer config -state disabled # $wrr config -state disabled $wsr config -state disabled $wir config -state disabled $qui config -state disabled } } } } proc Run-sr {} { global input log wui wmr wer wrr wsr wir qui sr if [Dialog_sr "Please enter the recipient e-mail address"] { set sel [.entries.index.list curselection] if {$sel == ""} { set x "" } else { foreach i $sel { set x [.entries.index.list get $i] } } if [catch {open "|sr $sr(result) [lindex $x 0] |& cat" \ r+} input] { $log insert end $input\n } else { fileevent $input readable {Log sr} $log insert end "sr $sr(result) [lindex $x 0]\n" $wsr config -text Stop -command Stop-sr $wui config -state disabled $wmr config -state disabled $wer config -state disabled $wrr config -state disabled # $wsr config -state disabled $wir config -state disabled $qui config -state disabled } } } proc Run-ir {} { global input log wui wmr wer wrr wsr wir qui ir if [Dialog_ir "Please enter the repository reference"] { if [catch {open "|ir $ir(result) |& cat" \ r+} input] { $log insert end $input\n } else { fileevent $input readable {Log ir} $log insert end "ir $ir(result)\n" $wir config -text Stop -command Stop-ir $wui config -state disabled $wmr config -state disabled $wer config -state disabled $wrr config -state disabled $wsr config -state disabled # $wir config -state disabled $qui config -state disabled } } } proc Run-um {} { global input log wum if [catch {open "|nice um |& cat" r+} input] { $log insert end $input\n } else { fileevent $input readable {Log um} $log insert end "nice um\n" $wum config -text Stop -command Stop-um } } # Procedures to help build dialogs. # Example 33-1 proc Dialog_Create {top title args} { global dialog if [winfo exists $top] { switch -- [wm state $top] { normal { # Raise a buried window raise $top } withdrawn - iconified { # Open and restore geometry wm deiconify $top catch {wm geometry $top $dialog(geo,$top)} } } return 0 } else { eval {toplevel $top} $args wm title $top $title return 1 } } proc Dialog_Wait {top varName {focus {}}} { upvar $varName var # Poke the variable if the user nukes the window bind $top [list set $varName $var] # Grab focus for the dialog if {[string length $focus] == 0} { set focus $top } set old [focus -displayof $top] focus $focus catch {tkwait visibility $top} catch {grab $top} # Set geometry set geo [wm geometry $top] regsub {\+.*$} $geo {} wh wm geometry $top [format "%s+576+0" $wh] # Wait for the dialog to complete tkwait variable $varName catch {grab release $top} focus $old } proc Dialog_Dismiss {top} { global dialog # Save current size and position catch { # window may have been deleted set dialog(geo,$top) [wm geometry $top] wm withdraw $top } } # Yes or No Dialog # Example 33-2 proc Dialog_yn { string } { global yn set f .yn if [Dialog_Create $f "Yes or No?" -borderwidth 10] { message $f.msg -text $string -aspect 600 \ -justify center set b [frame $f.buttons] pack $f.msg $f.buttons -side top -fill x button $b.yes -text Yes -command {set yn(yes) yes} button $b.no -text No \ -command {set yn(yes) no} pack $b.yes -side left pack $b.no -side right } set yn(yes) no Dialog_Wait $f yn(yes) Dialog_Dismiss $f return $yn(yes) } # Dialog for sr # Example 33-2 proc Dialog_sr { string } { global sr set f .sr if [Dialog_Create $f "Ok or Cancel?" -borderwidth 10] { message $f.msg -text $string -aspect 600 \ -justify center entry $f.entry -textvariable sr(result) set b [frame $f.buttons] pack $f.msg $f.entry $f.buttons -side top -fill x pack $f.entry -pady 5 button $b.ok -text OK -command {set sr(ok) 1} button $b.cancel -text Cancel \ -command {set sr(ok) 0} pack $b.ok -side left pack $b.cancel -side right bind $f.entry {set sr(ok) 1 ; break} bind $f.entry {set sr(ok) 0 ; break} } set sr(ok) 0 Dialog_Wait $f sr(ok) $f.entry Dialog_Dismiss $f return $sr(ok) } # Dialog for sr2 # Example 33-2 proc Dialog_entry {} { global entry set f .entry if [Dialog_Create $f "Entry" -borderwidth 10] { entry $f.entry -textvariable entry(result) -width 50 pack $f.entry -side top -fill x pack $f.entry -pady 5 bind $f.entry {set entry(ok) 1 ; break} bind $f.entry {set entry(ok) 0 ; break} } set entry(ok) 0 Dialog_Wait $f entry(ok) $f.entry Dialog_Dismiss $f return $entry(result) } # Dialog for ir # Example 33-2 proc Dialog_ir { string } { global ir set f .ir if [Dialog_Create $f "Ok or Cancel?" -borderwidth 10] { message $f.msg -text $string -aspect 1000 entry $f.entry -textvariable ir(result) set b [frame $f.buttons] pack $f.msg $f.entry $f.buttons -side top -fill x pack $f.entry -pady 5 button $b.ok -text OK -command {set ir(ok) 1} button $b.cancel -text Cancel \ -command {set ir(ok) 0} pack $b.ok -side left pack $b.cancel -side right bind $f.entry {set ir(ok) 1 ; break} bind $f.entry {set ir(ok) 0 ; break} } set ir(ok) 0 Dialog_Wait $f ir(ok) $f.entry Dialog_Dismiss $f return $ir(ok) } # Read and log output from the program proc Log {program} { global input log if [eof $input] { Stop-$program } else { gets $input line $log insert end $line\n $log see end if {$line == "(answer yes or no, default is no)"} { set choice [Dialog_yn \ "Please answer the question shown in the log"] puts $input $choice flush $input } if {$line == "What is the collection size?"} { set choice [Dialog_entry] puts $input $choice flush $input } if {$line == \ "What is the Local Collection Index repository?"} { set choice [Dialog_entry] puts $input $choice flush $input } } } # Stop procedures proc Stop-ui {} { global input wui wmr wer wrr wsr wir qui catch {close $input} $wui config -text ui -command Run-ui $wui config -state normal $wmr config -state normal $wer config -state normal $wrr config -state normal $wsr config -state normal $wir config -state normal $qui config -state normal UpdateIndex SetIndicator } proc Stop-mr {} { global input wui wmr wer wrr wsr wir qui catch {close $input} $wui config -state normal $wmr config -state normal $wer config -state normal $wrr config -state normal $wsr config -state normal $wir config -state normal $qui config -state normal UpdateIndex SetIndicator } proc Stop-rr {} { global input wui wmr wer wrr wsr wir qui catch {close $input} $wrr config -text rr -command Run-rr $wui config -state normal $wmr config -state normal $wer config -state normal $wrr config -state normal $wsr config -state normal $wir config -state normal $qui config -state normal UpdateIndex SetIndicator } proc Stop-sr {} { global input wui wmr wer wrr wsr wir qui catch {close $input} $wsr config -text sr -command Run-sr $wui config -state normal $wmr config -state normal $wer config -state normal $wrr config -state normal $wsr config -state normal $wir config -state normal $qui config -state normal } proc Stop-ir {} { global input wui wmr wer wrr wsr wir qui catch {close $input} $wir config -text ir -command Run-ir $wui config -state normal $wmr config -state normal $wer config -state normal $wrr config -state normal $wsr config -state normal $wir config -state normal $qui config -state normal UpdateIndex SetIndicator } proc Stop-um {} { global input wum catch {close $input} $wum config -text um -command Run-um } # Scroll_Set manages optional scrollbars # Example 27-2 proc Scroll_Set {scrollbar geoCmd offset size} { if {$offset != 0.0 || $size != 1.0} { eval $geoCmd ;# Make sure it is visible $scrollbar set $offset $size } else { set manager [lindex $geoCmd 0] $manager forget $scrollbar ;# hide it } } # Listbox with optional scrollbars # Example 27-3 proc Scrolled_Listbox { f args } { frame $f listbox $f.list \ -xscrollcommand [list Scroll_Set $f.xscroll \ [list grid $f.xscroll -row 1 -column 0 -sticky we]] \ -yscrollcommand [list Scroll_Set $f.yscroll \ [list grid $f.yscroll -row 0 -column 1 -sticky ns]] eval {$f.list configure} $args scrollbar $f.xscroll -orient horizontal \ -command [list $f.list xview] scrollbar $f.yscroll -orient vertical \ -command [list $f.list yview] grid $f.list $f.yscroll -sticky news grid $f.xscroll -sticky news grid rowconfigure $f 0 -weight 1 grid columnconfigure $f 0 -weight 1 return $f.list } # Create a listbox widget to display the index entries set index [Scrolled_Listbox .entries.index -width 80 -height 10 \ -font {courier 11}] pack .entries.index -fill both -expand true pack .entries -side top -fill both -expand true # Insert of the entries proc UpdateIndex {} { global col service index $index delete 0 end cd ../$col set entryList [glob */*/*/*/bib/*] cd $service set maxLength 1 foreach entry $entryList { regsub {/bib/.*$} $entry {} x set nameLength [string length $x] set maxLength [expr [expr $maxLength > $nameLength] ? \ $maxLength : $nameLength] } foreach entry $entryList { regexp {^(.*)/bib/(.*)$} $entry m rep citationKey set x [format "%-${maxLength}s " "${rep}"]$citationKey regsub -all {=} $x {:} x $index insert end $x } } UpdateIndex # Selecting in index opens a.bib edition # bind $index {ListSel %W} proc ListSel {w} { global col service foreach i [$w curselection] { set x [$w get $i] regsub { +} $x {/bib/} x regsub -all {:} $x {=} x set pwd [pwd] cd ../$col/$x exec textedit a.bib & cd $pwd } } # Computing a new color. # Example 35-2 proc NewColor { win color } { set rgb [winfo rgb $win $color] set mx [Max [lindex $rgb 0] \ [Max [lindex $rgb 1] [lindex $rgb 2]]] set wht [winfo rgb $win white] if {$mx > [expr [lindex $wht 0] / 1.4]} { return [format "#%03x%03x%03x" \ [expr round([lindex $rgb 0] * 0.8)] \ [expr round([lindex $rgb 1] * 0.8)] \ [expr round([lindex $rgb 2] * 0.8)]] } else { return [format "#%03x%03x%03x" \ [expr round([lindex $rgb 0] * 1.4)] \ [expr round([lindex $rgb 1] * 1.4)] \ [expr round([lindex $rgb 2] * 1.4)]] } } proc Max { x y } { return [expr [expr $x > $y]?$x:$y] } proc SetIndicator {} { global wui bgcolor cd .. if [file exists out-of-date] { $wui config -background [NewColor . $bgcolor] } else { $wui config -background $bgcolor } cd library_service } SetIndicator