Send commitlog mailing list submissions to
        commitlog@lists.openmoko.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        commitlog-requ...@lists.openmoko.org

You can reach the person managing the list at
        commitlog-ow...@lists.openmoko.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r5990 - trunk/eda/boom (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2010-10-18 21:55:37 +0200 (Mon, 18 Oct 2010)
New Revision: 5990

Modified:
   trunk/eda/boom/gen2chr
Log:
Added interactive query mode (-q word) to gen2chr.

- boom/gen2chr: added proper command-line parsing so that -d and -n can now be
  in any order
- boom/gen2chr: moved part name translation to separate function "translate"
- boom/gen2chr: added new option -q to translate a word passed on the command
  line



Modified: trunk/eda/boom/gen2chr
===================================================================
--- trunk/eda/boom/gen2chr      2010-10-18 01:42:26 UTC (rev 5989)
+++ trunk/eda/boom/gen2chr      2010-10-18 19:55:37 UTC (rev 5990)
@@ -4,29 +4,19 @@
 require "match.pl";
 
 
-if ($ARGV[0] eq "-d") {
-    $debug = 1;
-    shift @ARGV;
-}
-if ($ARGV[0] eq "-n") {
-    $negate = 1;
-    shift @ARGV;
-}
-$key = shift @ARGV;
-&parse;
+sub translate
+{
+    local ($r) = @_;
 
-print "#CHR\n";
-for (keys %id) {
-    next unless $id{$_} eq "$key $_";
     undef %field;
-    $field{"REF"} = $_;
-    &match_set_error("$_");
+    $field{"REF"} = $r;
+    &match_set_error($r);
     if (!&apply_rules()) {
-       print "$id{$_}\n" if $negate;
-       next;
+       print "$id{$r}\n" if $negate;
+       return;
     }
-    next if $negate;
-    print $id{$_};
+    return if $negate;
+    print $id{$r};
     for (sort keys %field) {
        next if $_ =~ /^_/;
        next if $_ eq "REF";
@@ -34,3 +24,41 @@
     }
     print "\n";
 }
+
+
+sub usage
+{
+    print STDERR "usage: $0 [-d|-n] key file ...\n";
+    print STDERR "       $0 -q query file ...\n";
+    exit(1);
+}
+
+while ($ARGV[0] =~ /^-/) {
+    if ($ARGV[0] eq "-d") {
+       $debug = 1;
+    } elsif ($ARGV[0] eq "-n") {
+       $negate = 1;
+    } elsif ($ARGV[0] eq "-q") {
+       $query = 1;
+    } else {
+       &usage;
+    }
+    shift @ARGV;
+}
+
+$key = shift @ARGV;
+&usage unless defined $key;
+
+&parse;
+
+if ($query) {
+    $debug = 1;
+    &translate($key);
+    exit(0);
+}
+
+print "#CHR\n";
+for (keys %id) {
+    next unless $id{$_} eq "$key $_";
+    &translate($_);
+}




--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to