Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8ccf9cd

Browse files
author
Werner Almesberger
committed
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
1 parent bf85a09 commit 8ccf9cd

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

‎eda/boom/gen2chr‎

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,61 @@ require "parser.pl";
44
require "match.pl";
55

66

7-
if ($ARGV[0] eq "-d") {
8-
$debug = 1;
9-
shift @ARGV;
10-
}
11-
if ($ARGV[0] eq "-n") {
12-
$negate = 1;
13-
shift @ARGV;
14-
}
15-
$key = shift @ARGV;
16-
&parse;
7+
sub translate
8+
{
9+
local ($r) = @_;
1710

18-
print "#CHR\n";
19-
for (keys %id) {
20-
next unless $id{$_} eq "$key $_";
2111
undef %field;
22-
$field{"REF"} = $_;
23-
&match_set_error("$_");
12+
$field{"REF"} = $r;
13+
&match_set_error($r);
2414
if (!&apply_rules()) {
25-
print "$id{$_}\n" if $negate;
26-
next;
15+
print "$id{$r}\n" if $negate;
16+
return;
2717
}
28-
next if $negate;
29-
print $id{$_};
18+
return if $negate;
19+
print $id{$r};
3020
for (sort keys %field) {
3121
next if $_ =~ /^_/;
3222
next if $_ eq "REF";
3323
print " $_=$field{$_}";
3424
}
3525
print "\n";
3626
}
27+
28+
29+
sub usage
30+
{
31+
print STDERR "usage: 0ドル [-d|-n] key file ...\n";
32+
print STDERR " 0ドル -q query file ...\n";
33+
exit(1);
34+
}
35+
36+
while ($ARGV[0] =~ /^-/) {
37+
if ($ARGV[0] eq "-d") {
38+
$debug = 1;
39+
} elsif ($ARGV[0] eq "-n") {
40+
$negate = 1;
41+
} elsif ($ARGV[0] eq "-q") {
42+
$query = 1;
43+
} else {
44+
&usage;
45+
}
46+
shift @ARGV;
47+
}
48+
49+
$key = shift @ARGV;
50+
&usage unless defined $key;
51+
52+
&parse;
53+
54+
if ($query) {
55+
$debug = 1;
56+
&translate($key);
57+
exit(0);
58+
}
59+
60+
print "#CHR\n";
61+
for (keys %id) {
62+
next unless $id{$_} eq "$key $_";
63+
&translate($_);
64+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /