#! /usr/bin/perl # # $Id: evlookup,v 1.9 2013/02/12 07:30:07 doi Exp doi $ # # evlookup - look up event information # # this program will look up the information in the anime event # database, which is maintained by Hitoshi Doi , # and print out information for each voice actor. # it is mainly used for creating parts of the WWW seiyuu pages. # # the seiyuu information is available via WWW at: # http://www.usagi.org/doi/seiyuu/ # # original hack by Hitoshi Doi (doi@usagi.org), 1995.02.05 # # this program is public domain. do whatever you want with it. # this program is offered "as is", and does not have any warrantee. # # --------------------------------------------------------------- # modifications # # 1995.06.30 Hitoshi Doi # use associative arrays to speed things up # # 1996.03.07 Hitoshi Doi # modifications to process non-event databases # the video DB and CD DB might also use this format # --------------------------------------------------------------- $me = $0; $me =~ s/.*\///; # the file containing the voice actor information $evfile = $ENV{'EVENT'}; $s_count = 0; @s_name = (); @s_url = (); @s_events = (); @s_date = (); $www_all = 0; @ev_lookup = (); $ev_ct = 0; $nodate = 0; $listall = ''; $listall2 = ''; $match = ''; $WWW_subdir = 'EV'; # subdirectory for WWW data while ($ai = shift(@ARGV)) { if ($ai =~ m/^-db/i) { $evfile = shift(@ARGV); } elsif ($ai =~ m/^-sub/i) { $WWW_subdir = shift(@ARGV); } elsif ($ai =~ m/^-www/i) { $www_all = 1; } elsif ($ai =~ m/^-printall/i) { # special option for DB.event $printall = 1; } elsif ($ai =~ m/^-nodate/i) { $nodate = 1; } elsif ($ai eq '-listall') { $listall = shift(@ARGV); } elsif ($ai eq '-listall2') { $listall2 = shift(@ARGV); } elsif ($ai =~ m/^-match/i) { $match = shift(@ARGV); } elsif ($ai =~ m/^-help/i) { print "$me - event information lookup usage: $me [options] options: NAME display all events for the actor NAME -www create the WWW event data for all voice actors -sub SUB set the WWW subdirectory -nodate do not write out the date for the WWW data -listall P list all of the events with URLs, preceeded by Path -listall2 P list all of the events (HTML) with URLs, preceeded by Path -db FILE use the file FILE as the event database\n"; exit 0; } elsif ($ai =~ m/^-debug/i) { $debug = 1; } else { $ev_lookup[$ev_ct++] = $ai; } } if (!$evfile) { print "$me: the event database is undefined. please set the environment variable EVENT, or specify the database with the -db option.\n"; exit -1; } $ev_db = "event database $evfile"; if (!open(EV, "<$evfile")) { print "$me: can't open the $ev_db.\n"; exit -1; } &read_profile; $style = " onMouseOver=\"this.style.background='pink'\""; $style .= " onMouseOut=\"this.style.background=''\""; # # go through the event file and do processing # $read_done = 0; $ev_proc = 0; while (1) { if (!$read_done) { $l = ; last if (!$l); # end of file chop($l); } $read_done = 0; next if ($l =~ m/^$/); next if ($l =~ m/^#/); if ($l =~ m/^[1-9][0-9]/) { # new event $event_OK = ($match) ? ($l =~ m/$match/i) : 1; ($ev_date, $ev_name) = split(/[ ]+/, $l, 2); $ev_url = ''; if ($debug) { print "event $ev_name, date $ev_date\n"; } next; } $l =~ s/^[ ]+//i; # # process keywords # if ($l =~ m/^URL/i) { # URL keyword $l =~ s/^URL[ ]*//i; $ev_url = $l; if ($debug) { print "event URL $ev_url\n"; } if ($listall && $event_OK) { print "
  • $ev_date "; print ""; print "$ev_name\n"; } if ($listall2 && $event_OK) { print "$ev_date"; print "$ev_name\n"; } next; } # # others are seiyuu names # $role = ''; if ($l =~ m/\{.*\}/) { ($nn, $role) = split(/\{/, $l, 2); $role =~ s/\}//; $nn =~ s/[ ]+$//; $l = $nn } if ($printall) { print "$ev_date - "; if ($ev_url) { print "$ev_name"; } else { print "$ev_name"; } print " {$role}" if ($role); my $va = $l; $va .= " ($kanji{$va})" if ($kanji{$va}); print " - $va\n"; next; } $s_id = &set_seiyuu($l); if ($debug) { print "seiyuu ($s_id) $s_name[$s_id]\n"; } $s_events[$s_id] .= "$ev_name\t"; $s_url[$s_id] .= "$ev_url\t"; $s_date[$s_id] .= "$ev_date\t"; } # # print out information # if ($www_all) { &write_www(); } if ($ev_ct) { for ($i = 0; $i < $ev_ct; $i++) { print "\n"; $s_id = &find_seiyuu($ev_lookup[$i]); if ($s_id == $s_count - 1) { $s_count--; print "cannot find $ev_lookup[$i]\n"; next; } print "$s_name[$s_id]\n"; @e_name = split(/\t/, $s_events[$s_id]); @e_date = split(/\t/, $s_date[$s_id]); while ($en = shift(@e_name)) { $ed = shift(@e_date); print " $ed $en\n"; } } } exit 0; # # subroutines # sub set_seiyuu { my $name = $_[0]; my $i; if (!($i = $seiyuu_id{$name})) { $s_count++; $seiyuu_id{$name} = $s_count; $i = $s_count; $s_name[$i - 1] = $name; } return $i - 1; } sub find_seiyuu { my $name = $_[0]; my $k; foreach $k (sort keys(%seiyuu_id)) { if ($k =~ m/$name/i) { return($seiyuu_id{$k} - 1); } } return $s_count + 1; } # # write data for WWW use # sub write_www { my($i, @e_name, @e_url, @e_date); my($en, $eu, $ed); my $www_index = "$WWW_subdir/Index"; my $www_out; system "/bin/mv $WWW_subdir $WWW_subdir.old"; mkdir($WWW_subdir, 0755); open(INDEX, ">$www_index"); for ($i = 0; $i < $s_count; $i++) { printf INDEX "%05d:%s\n", $i, $s_name[$i]; $www_out = sprintf("$WWW_subdir/%05d", $i); open(WWWOUT, ">$www_out"); @e_name = split(/\t/, $s_events[$i]); @e_url = split(/\t/, $s_url[$i]); @e_date = split(/\t/, $s_date[$i]); while ($en = shift(@e_name)) { $ed = shift(@e_date); $eu = shift(@e_url); print WWWOUT ""; print WWWOUT "$ed" if (!$nodate); if ($eu) { print WWWOUT ""; } print WWWOUT "$en"; if ($eu) { print WWWOUT ""; } print WWWOUT "\n"; } close(WWWOUT); } close(INDEX); } sub read_profile { $pf = '/home/doi/www/seiyuu/db/DB.profile'; open(PF, "<$pf"); my @all = ; close(PF); %kanji = (); foreach $pl (@all) { chop($pl); ($r, $k) = split(/\t/, $pl, 2); $kanji{$r} = $k; } }