#!/usr/bin/perl

# $Id: selecttag.in,v 1.2 2001/06/21 06:36:59 taku-ku Exp $;

my %tag;
my $default = "";
my $syntax  = shift (@ARGV);

# header
while (<>) {
  print;
  last if (/^\s*$/);
}

# noconv
if (lc($syntax) eq "__noconv__") {
    while (<>) { print };
}

# conv
while ($syntax =~ s/([^=\s]+)=([^,\s]+)//) {
    my $from = $1;
    my $to   = $2;

    if (lc($from) eq "__default__") {
	$default = $to;
    } else {
	my @list = split /,/, $from;
	for (@list) {
	    $tag{$_} = $to;
	}
    }
}

while (<>) {
    my ($i,$v) = split /\s+/, $_, 2;

    my $to = $tag{$i};
    if (defined $to) {
	print $to, " ";
    } elsif ($default ne "") {
	print $default, " ";
    } else {
	die "FATAL: Cannot know how to convert the tag [$i]\n";
    }

    print $v;
}




