Apendice 2-2 (Who.tk)

#!/sw3/common/agent.1.1/binex/bin/agent-tk set machines "" set continue 0 set MyName "" set events 0 set n [mask new] mask handler $n TrapEvent mask add $n "ANY ANY -tag STOP -handler Stop" mask_replace event $n #----------------------------------------------------------------------- proc TrapEvent {source tag string} { global agent global continue global MyName if {$tag == "CREATE"} { agent_name $string set MyName $string set continue 1 } } #----------------------------------------------------------------------- proc Stop {source tag string} { #actions regard to come back o die. } #----------------------------------------------------------------------- proc proccessInput { input } { set pos 0 set output "" set data [ split $input \n] set temp [llength $data] while { $pos < $temp} { set string [lindex $data $pos] if {[lindex [split $string " "] 0] == "----------------------------------"} { append output "F i l e n u m b e r: [lindex [split $string " "] 1]\n" } elseif {$string == "::::::::::"} { set string [lindex $data [expr $pos+2]] set string [split $string " "] set string [split [lindex $string 4] / ] set string [split [lindex $string end] .] append output "image: [lindex $string 0].gif\n" set pos [expr $pos+3] } else { append output "$string\n" } set pos [expr $pos+1] } unset pos data temp string return $output } #----------------------------------------------------------------------- proc who machines { global MyName global agent global topic global keyword global home set list "" foreach m $machines { if {[catch "agent_jump $m" result]} { append list "$m:\nunable to JUMP to this machine ($result)\n\n" } else { agent_name $MyName agent_event "$home Search_Agent" ARRIVAL $MyName if {[catch "exec /home/u/raid/vol07/is091892/proof.csh $MyName $topic $keyword" result]} { append list "<########## $m ##########>\n[proccessInput $result]\n\n" } else { append list "$agent(local):\n$result\n\n" } } } return $list } #----------------------------------------------------------------------- if {[catch {agent_begin}]} { return -code error "ERROR: unable to register on $agent(actual-server)" } set MyName [lindex $argv 0 ] set machines [lindex $argv 1 ] set topic [lindex $argv 2 ] set keyword [lindex $argv 3 ] agent_name MyName set home $agent(local-ip) set data [who $machines] agent_jump $home agent_name $MyName main create -name "Agent: <-- $MyName -->" -display $agent(local-server):0 frame .top -relief raised -bd 1 frame .bot -relief raised -bd 1 pack .bot -side bottom -fill both pack .top -side bottom -fill both -expand 1 text .text -relief sunken -bd 2 -yscrollcommand ".scroll set" scrollbar .scroll -command ".text yview" pack .scroll -in .top -side right -fill y pack .text -in .top -side left -fill both -expand 1 button .done -text "Destroy myself" -command { set done 1 } button .send -text "Send data" -command { agent_event "$agent(local-ip) Search_Agent" DATA $full } pack .done .send -in .bot -side left -expand 1 -padx 3m -pady 2m .text delete 1.0 end set full "topic:$topic\tkeyword:$keyword\tAgent:$MyName\n$data" .text insert end $data agent_event "$agent(local-ip) Search_Agent" HELLO "hi everybody..." tkwait variable done agent_end exit