<html>
<body>
  <div id="body" style="background-color:#ffffff;" >
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head" style="border-bottom-width:1px;border-bottom-style:solid;" ><td class="headtd" style="padding:0;padding-top:.2em;" colspan="4">Commit in <b><tt>lxdream/src/tools</tt></b></td></tr>
<tr><td><tt><a href="#file1">gendec.c</a></tt></td><td id="added" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ddffdd;" align="right">+56</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-3</td><td class="headtd2" style="padding-left:.3em;padding-right:.3em;" nowrap="nowrap">34895c8bab20 -> 852412cf56e0</td></tr>
</table>
<pre class="comment" style="white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd;" >
Gendec tweaks
  - add more useful command line help + long options
  - add action checks for missing or empty rules
</pre>
<hr /><a name="file1" /><div class="file" style="border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;" >
<span class="pathname" style="font-family:monospace; float:right;" >lxdream/src/tools</span><br />
<div class="fileheader" style="margin-bottom:.5em;" ><big><b>gendec.c</b></big> <small id="info" style="color: #888888;" >34895c8bab20 -> 852412cf56e0</small></div>
<pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >--- lxdream/src/tools/gendec.c
+++ lxdream/src/tools/gendec.c
@@ -38,12 +38,59 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > 
 FILE *ins_file, *act_file, *out_file;
 
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-char *option_list = "tmho:";
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+char *option_list = "tmho:<span id="addedchars" style="background-color:#99ff99;font-weight:bolder;" >w</span>";
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > int gen_mode = GEN_SOURCE;
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-struct option longopts[1] = { { NULL, 0, 0, 0 } };
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+int emit_warnings = 0;
+
+struct option longopts[] = { 
+    { "help", no_argument, NULL, 'h' },
+    { "output", required_argument, NULL, 'o' },
+    { "template", no_argument, NULL, 't' },
+    { "warnings", no_argument, NULL, 'w' },
+    { NULL, 0, 0, 0 } };
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > 
 static void usage() {
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-    printf( "<span id="removedchars" style="background-color:#ff9999;font-weight:bolder;" >gendec</span> <instruction-file> <action-file> [ -o <output-file> ]\n" );
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    printf( "<span id="addedchars" style="background-color:#99ff99;font-weight:bolder;" >Usage: gendec [options]</span> <instruction-file> <action-file> [ -o <output-file> ]\n" );
+    printf( "Options:\n" );
+    printf( "  -h, --help         Print this help message\n" );
+    printf( "  -o, --output=FILE  Generate output to the given file\n" );
+    printf( "  -t, --template     Generate a template skeleton instead of an instruction matcher\n" );
+    printf( "  -w, --warnings     Emit warnings when unmatched instructions are found\n" );
+}
+
+/**
+ * Check that rules are provided for all actions
+ */
+static void check_actions( struct ruleset *rules, const actiontoken_t token )
+{
+    int i;
+    int warnings = 0;
+    for( i=0; i<rules->rule_count; i++ ) {
+        if( token->actions[i].text == NULL ) {
+            if( warnings == 0 ) {
+                fprintf( stderr, "In action block starting at line %d of file %s:\n",
+                         token->lineno, token->filename );
+            }
+            fprintf( stderr, "Warning: No action matches rule %d %s\n", i, rules->rules[i]->format );
+            warnings++;
+        } else {
+            const char *s = token->actions[i].text;
+            while( *s ) {
+                if( !isspace(*s) )
+                    break;
+                s++;
+            }
+            if( !*s ) {
+                if( warnings == 0 ) {
+                    fprintf( stderr, "In action block starting at line %d of file %s:\n",
+                         token->lineno, token->filename );
+                }
+                fprintf( stderr, "Warning: Empty action for rule %d %s at line %d\n", i, rules->rules[i]->format,
+                    token->actions[i].lineno );
+                warnings++;
+            }
+        }
+    }
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > }
 
 /**
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -242,6 +289,9 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >             fprintf( stderr, "Error parsing action file" );
             return -1;
         } else {
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+            if( emit_warnings ) {
+                check_actions( rules, token );
+            }
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >             split_and_generate( rules, token->actions, ruleidx, rules->rule_count, 0, 1, out );
         }
         token = action_file_next(af);
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -288,6 +338,9 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >         case 'o':
             out_filename = optarg;
             break;
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+        case 'w':
+            emit_warnings = 1;
+            break;
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >         case 'h':
             usage();
             exit(0);
</pre></div>
<center><small>Chaos Theory</small></center>
</div></body></html>