#!@PERL@ -w

=comment

  YamCha -- Yet Another Multipurpose CHunk Annotator
 
  $Id: mkparam.in,v 1.8 2004/03/26 13:33:03 taku-ku Exp $;

  Copyright (C) 2000-2004 Taku Kudo <taku-ku@is.aist-nara.ac.jp>
  This is free software with ABSOLUTELY NO WARRANTY.
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
=cut
 
use Getopt::Std;
my %arg;
getopts("o:",\%arg);

my $outFileNamePrefix = $arg{o} || pop(@ARGV);

die "Usage: $0 -o output_filename_prefix [-s] < files....\n" unless ($outFileNamePrefix);

my $paramFileName = $outFileNamePrefix  . ".param";
my $param;
my %dicHash = ();
my %classHash = ();

while(<>) {
  last if (/^\s*$/);
  $param .= $_;
}

while(<>) {
    chomp;
    next if (/^\s*$/);
    my @a = split;
    my $class = shift @a;
    $classHash{$class} = 1;
    for (@a) {
	$dicHash{$_} = 1;
    }
}

open(S, "> $paramFileName") || die "$! $paramFileName\n";
print S $param;
print S "Date: ", &gettime(), "\n";
print S "User: ", getlogin() || (getpwuid($<))[0] || "UNKNOWN" , "\n";
print S "Class_List: ", join(" ",sort keys %classHash) , "\n";
print S "\n";

my $id = 1;
for (sort keys %dicHash) {
    $dicHash{$_} = $id;
    print S "$dicHash{$_} $_\n";
    $id++;
}

print S "\n";
close(S);

sub gettime
{
   my($sec,$min,$hour,$mday,$mon,$year) = localtime;
   return sprintf("%04d/%02d/%02d %02d:%02d:%02d",
        $year+1900,$mon+1,$mday,$hour,$min,$sec);
}
