chiark / gitweb /
proper error handling in morse generator
authorian <ian>
Wed, 7 Dec 2005 01:28:46 +0000 (01:28 +0000)
committerian <ian>
Wed, 7 Dec 2005 01:28:46 +0000 (01:28 +0000)
cebpic/morse-generator
detpic/morse.messages

index 085ab4f61848e132f944a403b183f396a0db3a5a..132e5d26567abf7aab785e1a66816ee35d2004a3 100755 (executable)
@@ -108,12 +108,13 @@ while (<>) {
     s/\#.*//;
     next unless m/\S/;
     s/\s+$//;
-    m/^([A-Z0-9]+)(?:\s+([^\t ;]+))?(?:\s+\;\s*(.*))?$/
+    m/^([A-Z0-9]+)(\??)(?:\s+([^\t ;]+))?(?:\s+\;\s*(.*))?$/
        or oops("syntax error");
     $morse_name= $1;
+    $morse_optional= $2;
     @morse= split //, $morse_name;
-    @addrs= defined($2) ? split /\,/, $2 : ();
-    $comment= $3;
+    @addrs= defined($3) ? split /\,/, $3 : ();
+    $comment= $4;
 
     @addrs < 8 or oops("only up to 7 addrs are supported");
 
@@ -129,10 +130,21 @@ while (<>) {
 
     unshift @data, sprintf "0x%x%x", scalar(@addrs), $morse_bytes;
     push @data, map {
-       s/^\:/ $filename.':' /e;
+       s/^\:\b/ $filename.':' /e;
        $filename= $1 if m/^([^:]+)\:/;
        $_ = $symval{$_} if exists $symval{$_};
-       m/\:/ ? ' xxx_unknown_xxx' : "$_ - (0xf00 * !(($_ & 0xf00)^0xf00))"
+       if ($which eq 'inc') {
+           $val= $_;
+       } elsif (m/\:/) {
+           printf STDERR "morse-generator: message \`%s': %s".
+               "unknown symbol \`%s'\n",
+               $morse_name, ($morse_optional ? 'warning: ' :''), $_;
+           exit 4 unless $morse_optional;
+           $val= ' xxx_unknown_xxx';
+       } else {
+           $val= "$_ - (0xf00 * !(($_ & 0xf00)^0xf00))";
+       }
+       $val;
     } @addrs;
 
     push @data, ('0') x (3 - (scalar(@data) + 3) % 4);
index 43c499e80168e90354371322e5ed726c5bdb8595..c738b9b026913a8a45b9f2a5e0d3ffe61a86b2b5 100644 (file)
@@ -52,8 +52,8 @@ SD    i2clib:st                       ; impr. i2cm_read_done/i2cs_read_data
 
 # Messages for slave detection/i2c
 DW                                     ; slave write (nyi)
-DQ     FSR2L,:outmsg_end               ; previous slave read incomplete
-DR     FSR2L,:outmsg_end               ; slave read overrun
+DQ     FSR2L,::outmsg_end              ; previous slave read incomplete
+DR     FSR2L,::outmsg_end              ; slave read overrun
 
 # Messages for specific peripherals
 RS     FSR0L                           ; POLARITY message too short
@@ -62,4 +62,4 @@ RL    FSR0L                           ; POLARITY message too long
 PB     points:pointmsg                 ; Firing point when already busy
 PI     points:pointmsg,T3CON           ; Unexpected Timer 3 interrupt
 PU     points:pointmsg                 ; Firing nonexistent point
-PF     points:t                        ; Flash mentions point not on board
+PF     ::t                             ; Flash mentions point not on board