#!/usr/bin/perl # Biorytm.pl is freeware: (c)GOMASUKE # Dept. of Computer Science, Faculty of Engineering, # Shizuoka Univ., Hamamatsu, Japan # Ver.1.0 1997/08/31 # $base = 'http://www.hogehoge.(or|ne).jp/~foo/'; $x_width = 60; $y_height = 10; $pi = 3.1415926536; @yday = (0,0,31,59,90,120,151,181,212,243,273,304,334); @mday = (0,31,28,31,30,31,30,31,31,30,31,30,31); @week = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime(time); $year += 1900; #VALID THRU 12/2037 $mon++; $tday = sprintf("%4d/%02d/%02d %3s", $year,$mon,$mday,$week[$wday]); $ref = $ENV{'HTTP_REFERER'}; $ref =~ s/%7E/~/gi; $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $dat = $ENV{'QUERY_STRING'}; } else { read(STDIN, $dat, $ENV{'CONTENT_LENGTH'}); } @buf = split('&',$dat); foreach $item (@buf) { ($var,$value) = split('=',$item); $value =~ tr/+/ /; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; $itm{$var} = $value; } $nt = $itm{'nt'}; $yy = $y = $itm{'yy'}; $mm = $itm{'mm'}; $dd = $itm{'dd'}; if (!($ref =~ /^$base/)) { &err0; } if ($nt =~ /s/i) { if ($yy == 0 || $yy >= 65) { &err1; } $yy += 1925; } else { if ($yy == 0 || $yy >= 100) { &err1; } $yy += 1988; } if ($mm == 0 || $mm > 12) { &err2; } if (&leap($yy)) { $mday[2] = 29; } if ($dd > $mday[$mm]) { &err2; } $n = &nday($year,$mon,$mday); $n1 = &nday($yy,$mm,$dd); if ($n1 > $n) { &err3; } $n -= $n1; $n1 = $n1 % 7; $bday = sprintf("%4d/%02d/%02d", $yy,$mm,$dd); $y_width = $y_height * 2; for ($i = 0; $i <= $y_width; $i++) { $graph[$i] = " " x $x_width; substr($graph[$i],0,1) = "+"; } $graph[$y_height] = "+" x $x_width; &plot(23,'P'); &plot(28,'S'); &plot(33,'I'); print "Content-type: text/html\n\n"; print < biorhythm biorhythm

本日から60日間


Today        : $tday ($n days)
Your Birthday: $bday $week[$n1] ($nt.$y)

身体:Physical, 感情:Sympathy, 知性:Intellectual

EOF

for ($i = 0; $i <= $y_width; $i++) {
  $g = $graph[$i];
  $g =~ s/P/P<\/FONT>/g;
  $g =~ s/S/S<\/FONT>/g;
  $g =~ s/I/I<\/FONT>/g;
  print "$g\n";
}

print <


cgi script (c)GOMASUKE<Biorytm.pl>
EOF exit; sub leap { local($y,$i,$j); $y = $_[0]; $i = 0; $j = $y % 4; if ($j == 0) { $j = $y % 100; if ($j != 0) { $i = 1; } else { $j = $y % 400; if ($j == 0) { $i = 1; } } } $i; } sub nday { local($y,$i); $i = $yday[$_[1]]; if ($_[1] > 2 && &leap($_[0]) == 1) { $i += 1; } $y = $_[0] - 1; $i += $y * 365; $i += int($y / 4); $i -= int($y / 100); $i += int($y / 400); $i += $_[2]; $i; } sub plot { local($x,$i,$j); for ($i = 0; $i < $x_width; $i++) { $x = ($n + $i) % $_[0]; $j = int($y_height * sin(2.0 * $x * $pi / $_[0]) + 0.5); $j = $y_height - $j; substr($graph[$j],$i,1) = $_[1]; } } sub err0 { print "Content-type: text/html\n\n"; print "正規のフォームからリクエストして下さい\n"; exit; } sub err1 { print "Content-type: text/html\n\n"; print "生年が誤っています($nt\.$y)\n"; exit; } sub err2 { print "Content-type: text/html\n\n"; print "月日が誤っています ($yy/$mm/$dd)\n"; exit; } sub err3 { print "Content-type: text/html\n\n"; print "生年月日が誤っています ($yy/$mm/$dd)\n"; exit; }