#!/usr/bin/perl
#
#  keywords.pl  extract the \keywords macro from all of the .tex files
#  in the current directory, parse out the comma-separated items for 
#  each one,  and print a list of "paperID\tkeyword" for each keyword.
#  Take this list and compare it to a list of allowed/standard keywords,
#  and modify it to your liking.  Then run the list through the 
#  paperkeys.pl program to format the list back into \keywords macros
#  that you can paste back into the .tex files.
#
($prog = $0) =~ s!.*/!!;
$ENV{'PERL_LIB'} = "$ENV{'HOME'}/usr/lib/perl" 
    if ($ENV{'PERL_LIB'} eq '');

unshift(@INC, "/data/doright2/proceedings/adassXII", $ENV{'PERL_LIB'});
require "texscan.pl";
require "error.pl";
require "readadb.pl";
require "readabstract.pl";

$warn_sub = "warn";
@exclude_papers = ();
@include_papers = ();
$delim = "><";
$extra_cmds = "\\paspreprint";

# process switches
@files = glob( '*.tex ');

foreach $file (@files) {

    ($stat,$keywords) = &fgrep_TeXmacro("keywords", $file, 1, 1, 1);
    $keywords =~ s/\n/ /g;
    @keys = split(',', $keywords);
    $file =~ s/\.tex// ;
    foreach $key (@keys) {
	$key =~ s/^\s+//;
	$key =~ s/\s+$//;
#	print "$file\t$key\n";
	print "$key\t$file\n";
    }
}

exit(0);

sub dowrite {
    local(*dat) = @_;

    return $false if ($dat{"section"} ne "article");
    return (grep(/^$dat{"filename"}$/, @files) == (! $exclude)) 
	if (@files > 0);

    return $true;
}

sub writedata {
    local(*dat) = @_;
    print "$dat{'title'}\n";
    print "$author\n";
    print "$dat{'contact'}";
    print "$dat{'email'}";
}
