+proc RobotWriteRecord {outf fromurl distance} {
+ puts $outf "<zmbot>"
+ puts $outf "<distance>"
+ puts $outf $distance
+ puts $outf "</distance>"
+ puts $outf "<fromurl>"
+ puts $outf $fromurl
+ puts $outf "</fromurl>"
+ puts $outf "</zmbot>"
+}
+
+proc RobotReadRecord {inf fromurlx distancex} {
+ upvar $fromurlx fromurl
+ upvar $distancex distance
+ gets $inf
+ gets $inf
+ set distance [string trim [gets $inf]]
+ puts "got distance = $distance"
+ gets $inf
+ gets $inf
+ set fromurl [string trim [gets $inf]]
+}
+
+proc RobotFileNext {area} {
+ global robotSeq global idleTime ns
+
+ puts "RobotFileNext robotSeq=$robotSeq"
+ if {$robotSeq < 0} {
+ return {}
+ }
+ if {$robotSeq == 0} {
+ if {[catch {set ns [glob ${area}/*]}]} {
+ return {}
+ }
+ }
+ set off [string length $area]
+ incr off
+ set n [lindex $ns $robotSeq]
+ if {![string length $n]} {
+ set robotSeq -1
+ flush stdout
+ puts "------------ N E X T R O U N D --------"
+ return wait
+ }
+ incr robotSeq
+ if {[file isfile $n/frobots.txt]} {
+ puts "ok returning http://[string range $n $off end]/robots.txt"
+ return http://[string range $n $off end]/robots.txt
+ } elseif {[file isdirectory $n]} {
+ set sb [RobotFileNext1 $n http://[string range $n $off end]]
+ if {[string length $sb]} {
+ return $sb
+ }
+ }
+ puts "no more work at end of RobotFileNext n=$n"
+ puts "ns=$ns"
+ return {}
+}
+
+