Better errors
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 Jun 2002 00:27:04 +0000 (00:27 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 Jun 2002 00:27:04 +0000 (00:27 +0000)
ledmodule.tcl

index eb1deed..22cfb08 100644 (file)
@@ -81,7 +81,7 @@ proc ldebug {facil m} {
     #    c$lchan
     #    {}             for system stuff
     if {![llength $debugusers]} return
-    if {[regexp {[md]([^:]+)\:} $facil dummy username] &&
+    if {[regexp {[mdu]([^:]+)\:} $facil dummy username] &&
         [lsearch -exact $debugusers $username]==-1} return
 
     regsub {^(.)} $facil {\1 } cc
@@ -224,6 +224,7 @@ proc_dset setbystate {s} {
        if {![string match *$sq* $s]} continue
        set lv $v; break
     }
+    if {![info exists dd(ichan)]} return
     if {![info exists lv]} {
        reporterr "no state for $d matching$s"
        return
@@ -291,9 +292,13 @@ proc reloaduser {username} {
        set cc(time-recentnow) 120
        set cc(time-recent) 450
        set lno 0
+       set contin {}
        foreach l [split $cfg "\n"] {
            incr lno
-           set l [string trim $l]
+           append contin [string trim $l]
+           if {[regsub {\\$} $contin { } contin]} continue
+           set l $contin
+           set contin {}
            if {[regexp {^\#} $l]} {
            } elseif {[regexp {^nick\s+(ignore|nopresence|prefer)\s+(\S.*)$} \
                    $l dummy kind globs]} {
@@ -328,7 +333,7 @@ proc reloaduser {username} {
                }
                ldebug m$m "created"
            } elseif {[regexp \
- {^leds\s+([0-9A-Za-z][-:/0-9A-Za-z]+)\s+(\S+)\s+(\S+.*)$} \
+ {^leds\s+([0-9A-Za-z][-.:/0-9A-Za-z]+)\s+(\S+)\s+(\S+.*)$} \
                    $l dummy g m states]} {
                set d $username:$lno:$g
                set sl {}
@@ -350,8 +355,13 @@ proc reloaduser {username} {
                set dd(username) $username
                dset_start $d
                ldebug d$d "created"
+           } else {
+               error "invalid directive or syntax"
            }
        }
+       if {[string length $contin]} {
+           error "continuation line at end of file"
+       }
     } emsg]} {
        reporterr "setup error $username:$lno:$emsg"
        return ""
@@ -384,9 +394,9 @@ proc_dset start {} {
        set ochan [open |$cmdl r]
        fconfigure $ichan -blocking 0 -buffering line
        fconfigure $ochan -blocking 0 -buffering line
-       fileevent $ochan readable [list dset_rledout $d]
        set dd(ichan) $ichan
        set dd(ochan) $ochan
+       fileevent $ochan readable [list dset_rledout $d]
     } emsg]} {
        reporterr "remoteleds startup $d: $emsg"
        catch { close $ichan }
@@ -398,7 +408,7 @@ proc_dset start {} {
 proc_dset rledout {} {
     global errchan
     while {[gets $dd(ochan) l] != -1} {
-       reporterr "remoteleds on $d: $dd(values): $l"
+       reporterr "on $d: $dd(values): $l"
     }
     if {[fblocked $dd(ochan)]} return
     timed_log ">\$$d failure";
@@ -406,7 +416,7 @@ proc_dset rledout {} {
     catch { close $dd(ochan) }
     unset dd(ichan)
     unset dd(ochan)
-    reporterr "remoteleds on $d died"
+    reporterr "on $d died"
     dset_trylater $d
 }