robotSeq(t) moved to control(task,seq)
[tclrobot.git] / robot.tcl
index 968e64e..141ecac 100755 (executable)
--- a/robot.tcl
+++ b/robot.tcl
@@ -1,5 +1,5 @@
 #!/usr/bin/tclsh 
-# $Id: robot.tcl,v 1.36 2003/06/10 11:55:18 adam Exp $
+# $Id: robot.tcl,v 1.42 2003/06/11 08:49:09 adam Exp $
 #
 proc RobotFileNext1 {area lead} {
     # puts "RobotFileNext1 area=$area lead=$lead"
@@ -50,15 +50,15 @@ proc RobotReadRecord {inf fromurlx distancex} {
 }
 
 proc RobotFileNext {task area} {
-    global robotSeq
+    global control
     global idletime ns
     global status
 
-    # puts "RobotFileNext robotSeq=$robotSeq($task)"
-    if {$robotSeq($task) < 0} {
+    # puts "RobotFileNext seq=$control($task,seq)"
+    if {$control($task,seq) < 0} {
        return {}
     }
-    if {$robotSeq($task) == 0} {
+    if {$control($task,seq) == 0} {
        if {[catch {set ns($task) [glob $task/$area/*]}]} {
            return done
        }
@@ -66,17 +66,17 @@ proc RobotFileNext {task area} {
     # puts "ns=$ns($task)"
     set off [string length $task/$area]
     incr off
-    set n [lindex $ns($task) $robotSeq($task)]
+    set n [lindex $ns($task) $control($task,seq)]
     # puts "n=$n"
     if {![string length $n]} {
-       set robotSeq($task) -1
+       set control($task,seq) -1
        flush stdout
         set statusfile [open $task/status w]
         puts $statusfile "$status($task,unvisited) $status($task,bad) $status($task,visited)"
         close $statusfile
        return wait
     }
-    incr robotSeq($task)
+    incr control($task,seq)
     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
@@ -131,7 +131,7 @@ proc RobotFileUnlink {task area host path} {
     for {set i $l} {$i > 0} {incr i -1} {
         set path [join [lrange $comp 0 $i] /]
        if {![catch {glob $path/*}]} return
-        exec rmdir ./$path
+        exec rmdir $path
     }
     # puts "RobotFileUnlink end"
 }
@@ -148,6 +148,8 @@ proc RobotFileOpen {task area host path {mode w}} {
     global status
     global debuglevel
 
+    # puts "RobotFileOpen task=$task path=$path"
+
     if {![info exists workdir]} {
        return stdout
     }
@@ -169,7 +171,9 @@ proc RobotFileOpen {task area host path {mode w}} {
 
     for {set i 0} {$i <= $len} {incr i} {
         set d [lindex $comp $i]
-        if {[catch {cd $d}]} {
+       if {[string length $d] == 0} {
+           cd /
+       } elseif {[catch {cd $d}]} {
             exec mkdir $d
             cd ./$d
            if {![string compare $area unvisited] && $i == $len && $mode == "w"} {
@@ -215,12 +219,13 @@ proc RobotFileOpen {task area host path {mode w}} {
 proc RobotStartJob {fname t} {
     global control
 
-
     set f [open $fname r]
     set xml [read $f]
     puts "Reading $fname"
-    regexp {<status>([^<]*)</status>} $xml x status
     close $f
+    if {![regexp {<status>([^<]*)</status>} $xml x status]} {
+       return
+    }
     if {$status == "done"} {
         puts "already done"
         return
@@ -300,7 +305,7 @@ proc RobotScanDir {} {
 }
 
 proc RobotRR {task} {
-    global robotSeq robotsRunning tasks robotsMax status
+    global control robotsRunning tasks robotsMax status
 
     puts "RobotRR -- running=$robotsRunning max=$robotsMax---------------"
     incr robotsRunning -1
@@ -322,7 +327,7 @@ proc RobotRR {task} {
         set statusfile [open $t/status w]
         puts $statusfile "$status($t,unvisited) $status($t,bad) $status($t,visited)"
         close $statusfile
-        set robotSeq($t) 0
+        set control($t,seq) 0
         RobotStart $t
     }
 }
@@ -345,7 +350,7 @@ proc RobotDaemonLoop {} {
         if {[info exists tasks]} {
             puts "daemon loop tasks $tasks"
             foreach t $tasks {
-                set robotSeq($t) 0
+                set control($t,seq) 0
                 RobotStart $t
             }
             while {$robotsRunning} {
@@ -1058,6 +1063,8 @@ proc checkrule {task type this} {
     global control
     global debuglevel
 
+    set default_ret 1
+
     if {$debuglevel > 3} {
         puts "CHECKRULE $type $this"
     }
@@ -1071,6 +1078,7 @@ proc checkrule {task type this} {
             # consider mask (! negates)
             set masks [lindex $l 2]
            set ok 0
+           set default_ret 0
            foreach mask $masks {       
                 if {$debuglevel > 4} {
                     puts "consider single mask $mask"
@@ -1102,9 +1110,9 @@ proc checkrule {task type this} {
         }
     }
     if {$debuglevel > 3} {
-        puts "CHECKRULE MATCH OK"
+        puts "CHECKRULE MATCH DEFAULT $default_ret"
     }
-    return 1
+    return $default_ret
 }
 
 
@@ -1139,7 +1147,7 @@ proc debug {level} {
 }
 
 proc task {t} {
-    global tasks task status robotSeq control
+    global tasks task status control
 
     set task $t
 
@@ -1155,7 +1163,7 @@ proc task {t} {
     set status($t,bad) 0
     set status($t,raw) 0
     set status($t,active) 1
-    set robotSeq($t) 0
+    set control($t,seq) 0
     set control($t,distance) 10
     return 1
 }