#!/usr/bin/perl use strict; use Data::Dumper; my %key; my %keyns; my @section; my %section; my $section; my %optorder; my $example = 0; my $version; open(BAR,"otaku.html"); while() { if (m||) { $example = !$example; } elsif (m||) { $version = $1; } elsif (!$example and m!

(.*)
!) { $section = $1; unless (exists($key{$section})) { push(@section,{name=>$section,values=>[]}); $section{$section} = $#section; } $key{$section} = {}; } elsif (!$example and $section and /

([A-Z0-9]+) (.*)/) { unless (exists($key{$section}{$1})) { push(@{$section[$section{$section}]{'values'}},$1); } $key{$section}{$1}{'title'} = $2; } elsif (!$example and $section and /

(\w{1,3})(\S*) (.*)/) { my $code = $1; my $opt = $2; my $value = $3; $opt =~ s/\///g; unless (exists($key{$section}{$code})) { push(@{$section[$section{$section}]{'values'}},$code); } $key{$section}{$code}{$opt} = $value; $keyns{$code}{$opt} = $value; push(@{$optorder{$code}},$opt); $keyns{$code}{'section'} = $section; } } close(BAR); my %series = ( '*+' => "I have watched some of #title#", '*++' => "I have watched much of #title#", '*+++' => "I have seen most of #title# (But there's so much of it)", '+++' => "I think #title# is one of the best anime of it's kind out there", '++' => "I think #title# rocks! It's great!", '+' => "I think #title# is good", '' => "I saw #title#", '-' => "I didn't like #title#", '--' => "I am violently opposed to #title#", '---' => "#title# should be destroyed and anyone who watches it shot", ); my %games = ( '+++' => "and I think it is one of the best games of it's kind out there", '++' => "and I think it rocks! It's great!", '+' => "and I like it.", '' => "", '-' => "and I didn't like it.", '--' => "and I am violently opposed to it.", '---' => "and I think that it should be destroyed and anyone who plays it shot.", ); #push(@section,'Series'); foreach my $series (keys(%{$key{'Series'}})) { my $title = $key{'Series'}{$series}{'title'}; foreach (keys(%series)) { $key{'Series'}{$series}{$_} = $series{$_}; $key{'Series'}{$series}{$_} =~ s/#title#/$title/g; $keyns{$series}{$_} = $key{'Series'}{$series}{$_}; $keyns{$series}{'section'} = "Series: $key{'Series'}{$series}{'title'}"; push(@{$optorder{$series}},$_); } } print "Content-Type: text/html\n\n"; use CGI; my $q = CGI->new(); my $dowhat = $q->param('dowhat'); my %result; my @ordered; foreach my $param ($q->param) { if ($param =~ /([^|]*)\|(.*)/) { foreach ($q->param($param)) { my $num; if ($result{$2}) { $num = $result{$2}{'ORDER'}; } else { push(@ordered,[$2]); $result{$2}{'ORDER'} = $#ordered; $num = $#ordered; } push(@{$ordered[$num]},$_); $result{$2}{$_} = $#{$ordered[$num]}; } } } print qq{

The Otaku Code Generator created by me.
\n}; print qq{Otaku Code created by Tundra the Artic Wolf

\n}; if ($dowhat eq 'generate') { print "Your code is:
\n"; print "*---OTAKU CODE V$version---*
\n"; foreach (@ordered) { my $key = shift(@$_); my $opts = join('/',@$_); if ($opts =~ /^\w/) { $opts = '/'.$opts; } print "$key$opts "; } print "
*---OTAKU CODE V$version---*
\n"; print "
\n"; } if ($dowhat eq 'decode') { my $code = $q->param('code'); if ($code =~ /\*-+OTAKU CODE V[\d.]+-+\*(.*)\*-+OTAKU CODE V[\d.]+-+\*/s) { $code = $1; } foreach (split(/\s+/,$code)) { next unless $_; if (/^(\w+)(.*)/ or /^(\()(\w+)\)(.*)/) { my($key,$opt,$gotstarted); if ($3) { $gotstarted = 1; $key = $2; $opt = $3; } else { $key = $1; $opt = $2; } if ($keyns{$key}) { print "$keyns{$key}{'section'}
\n"; if ($gotstarted) { print "It was a series that got me started with anime.
\n"; } if ($opt) { $opt =~ s!^/(\w+)!$key!g; $opt =~ s!/$!/$key!g; foreach (split(/\//,$opt)) { if ($keyns{$key}{$_}) { print "$keyns{$key}{$_}
\n"; $result{$key}{$_} = 1; } elsif ($key eq $_ and $keyns{$key}{''}) { print "$keyns{$key}{''}
\n"; $result{$key}{''} = 1; } elsif ($_ =~ /^$key/ and $keyns{$key}{substr($_,length($key))}) { print $keyns{$key}{substr($_,length($key))},"
\n"; $result{$key}{substr($_,length($key))} = 1; } elsif ($_ =~ /\(g\)(.*)/) { # EWWW: Special case for games. print "I have played the game ".$games{$1}."
"; } else { print "Unknown option $_ for key $key
\n"; } } } else { print "$keyns{$key}{''}
\n"; } } else { print "???
\n"; print "Unknown key $key
\n"; } } else { print "Couldn't understand $_
\n"; } } } if (!$dowhat or $dowhat eq 'decode') { print "
"; print "\n"; print ""; print "

"; print "
"; } if ($dowhat) { print "
"; print "\n"; print ""; # foreach my $section (sort({mycompare($a,$b)} keys(%key))) { foreach my $section (@section) { # foreach my $key (sort(keys(%{$key{$section}}))) { foreach my $key (@{$$section{'values'}}) { foreach my $modifier (@{$optorder{$key}}) { # foreach my $modifier (sort(keys(%{$key{$section}{$key}}))) { next if $modifier eq 'title'; if ($result{$key}{$modifier}) { print qq{}; } } } } print "
"; } if (!$dowhat or $dowhat eq 'form') { print "
"; print "\n"; print ""; # foreach my $section (sort({mycompare($a,$b)} keys(%key))) { foreach my $section (@section) { print "
$$section{'name'}
\n"; foreach my $key (@{$$section{'values'}}) { # foreach my $key (sort(keys(%{$key{$section}}))) { if ($key{$$section{'name'}}{$key}{'title'}) { print qq{$key{$$section{'name'}}{$key}{'title'}
\n}; } foreach my $modifier (@{$optorder{$key}}) { # foreach my $modifier (sort(keys(%{$key{$section}{$key}}))) { next if $modifier eq 'title'; print qq{ $modifier $key{$$section{'name'}}{$key}{$modifier}
\n}; } } } print ""; print "
"; } sub mycompare { my($a,$b) = @_; my $result = $a cmp $b; $result = 1 if $a eq 'Series'; $result = -1 if $b eq 'Series'; return $result; }