+sub loadfoundries () {
+ foreach my $path (@rulespath) {
+ my $p = "$path/foundries";
+ my $f = new IO::File $p;
+ if (!$f) {
+ die "$p $!" unless $!==&ENOENT;
+ print $reportfh "foundries: none in $p\n" or die $! if $verbose;
+ next;
+ }
+ while (<$f>) {
+ s/^\s*//; s/\s+$//;
+ next if m/^\#/;
+ m/^(\w+)\s+(\w+)$/ or die;
+ my $k = lc $1;
+ next if exists $foundrymap{$k};
+ $foundrymap{$k}=$2;
+ }
+ $f->error and die $!;
+ reportloaded('foundries: loaded ',$p);
+ }
+ die "no foundry maps\n" unless %foundrymap;
+}
+
+our $stdin = new IO::File '<&STDIN' or die $!;
+our $stdout = new IO::File '>&STDOUT' or die $!;
+our $stderr = new IO::File '>&STDERR' or die $!;
+$reportfh = $stdout;
+
+define_mode('bdf-filter', sub {
+ die "no arguments allowed with --bdf-filter\n" if @ARGV;
+ $reportfh = $stderr;
+ loadfoundries();
+ my $r = processbdf($stdin,$stdout,'stdin');
+ if ($r !~ m/^\d/) {
+ print STDERR "stdin not processed: $r\n";
+ exit 2;
+ }
+});
+
+Getopt::Long::Configure(qw(bundling));
+GetOptions(@options) or exit 127;
+
+push @rulespath, "$sharedir/rules";
+
+die "need a mode\n" unless $mode;
+
+$mode->();