# =fujikoオリジナルライブラリ= # 文頭で require 'cgisub.pl'; と宣言する # &html_top; HTMLのトップ部分 &html_top($titlename,$bg_color,$bg_gif);とする # &html_bot; HTMLの最後の部分とする # &html_header; Content-type: text/html\n\nを出力print &html_header;とする # &my_cgi; 該当CGIページのURL # &error_cgi(ErrorMessage , CGI is Error!); のようにメッセージをつける # &date_str; $nengappi = &date_str; のようにする # &kikan_seven; $kikan_7 = &kikan_seven; のようにする # &kikan_fteen; $kikan_14 = &kikan_fteen; のようにする # &hour_str; $jikoku = &hour_str; # 2000/01/01/SUN # &date_get; $nengappi = &date_get($chenge_day); # 2000/1/1/SUN # &date_cooki($kigen); クッキー有効期限用日時 $d_cookie = &date_cooki($kigen); # &us_lock; &us_lock(*FILE); # &un_lock; &un_lock(*FILE); # &error_msg("ファイルへ書き込めません",$my_mail); のようにする # &show_file($txtfile,$mymail); のようにfileとmailつける(file内容表示) # &form_read(*init); と宣言し$initや@initを利用する(入力形式検査) # &c_right; 著作権表示 &c_right($my_home);とする # ©_right; 著作権表示2 ©_right($my_home);とする # &no_string; 使用できない文字の置換$moji = &no_string($moji);のように… # &get_week($year, $month, $day); 曜日を得る&get_week('1999', '3', '3'); # &uru_nen($year); 閏年かどうかを確認する( 閏年-> true ) # &get_month($year,$month); 閏年を計算して月日数を得る&get_month('1999','1'); sub html_top{ local ($t_name,$b_color,$b_gif) = @_; print ""; print ""; print "$t_name"; $url_style = <<"style_hir"; style_hir print "$url_style"; print ""; print ""; return; } sub html_bot{ print"\n\n"; return; } sub html_header { return "Content-type: text/html\n\n"; } sub my_cgi { local ($penv); $penv = ":" . $ENV{'SERVER_PORT'} if $ENV{'SERVER_PORT'} != 80; return 'http://' . $ENV{'SERVER_NAME'} . $penv . $ENV{'SCRIPT_NAME'}; } # &error_cgi(ErrorMessage , CGI is Error!)のようにする sub error_cgi { local (@msg) = @_; local ($i,$name); if (! @msg) { $name = &my_cgi; @msg = ("$name is error!"); } print &html_header; print "$msg[0]\n"; print "

$msg[0]

\n"; foreach $i (1 .. $#msg) { print "

$msg[$i]

\n"; } print "\n"; } sub date_str { local($sec, $min, $hour, $day, $mon, $year ,$wday); ( $sec, $min, $hour, $day, $mon, $year, $wday ) = localtime(time); $year += 1900; $mon++; $weekday = ('SUN','MON','TUE','WED','THU','FRI','SAT')[$wday]; if ($hour < 10) { $hourstr = "0$hour"; } else { $hourstr = "$hour"; } if ($min < 10) { $minstr = "0$min"; } else { $minstr = "$min"; } if ($sec < 10) { $secstr = "0$sec"; } else { $secstr = "$sec"; } if($mon < 10){ $mon= "0$mon"; } if($day < 10){ $day = "0$day"; } return "$year\/$mon\/$day/$weekday"; # return "$year\/$mon\/$day $hourstr:$minstr:$secstr"; # return "$year年$mon月$day日 $hourstr時$minstr分$secstr秒"; } sub kikan_seven{ local($sec, $min, $hour, $day, $mon, $year ,$wday); ( $sec, $min, $hour, $day, $mon, $year, $wday ) = localtime(time -86400*7); $year += 1900; $mon++; if ($hour < 10) { $hourstr = "0$hour"; } else { $hourstr = "$hour"; } if ($min < 10) { $minstr = "0$min"; } else { $minstr = "$min"; } if ($sec < 10) { $secstr = "0$sec"; } else { $secstr = "$sec"; } if($mon < 10){ $mon= "0$mon"; } if($day < 10){ $day = "0$day"; } return "$year\/$mon\/$day"; } sub kikan_fteen{ local($sec, $min, $hour, $day, $mon, $year ,$wday); ( $sec, $min, $hour, $day, $mon, $year, $wday ) = localtime(time -86400*14); $year += 1900; $mon++; if ($hour < 10) { $hourstr = "0$hour"; } else { $hourstr = "$hour"; } if ($min < 10) { $minstr = "0$min"; } else { $minstr = "$min"; } if ($sec < 10) { $secstr = "0$sec"; } else { $secstr = "$sec"; } if($mon < 10){ $mon= "0$mon"; } if($day < 10){ $day = "0$day"; } return "$year\/$mon\/$day"; } sub hour_str { local($sec, $min, $hour, $day, $mon, $year); ( $sec, $min, $hour, $day, $mon, $year ) = localtime(time); $year += 1900; $mon++; if ($hour < 10) { $hourstr = "0$hour"; } else { $hourstr = "$hour"; } if ($min < 10) { $minstr = "0$min"; } else { $minstr = "$min"; } if ($sec < 10) { $secstr = "0$sec"; } else { $secstr = "$sec"; } return "$hourstr:$minstr:$secstr"; } sub date_cooki{ $hozon = @_; local(@date) = localtime(time + $hozon * 86400); $date[5] += 1900; $date[5] = sprintf("%02d",$date[5]); $date[3] = sprintf("%02d",$date[3]); $date[2] = sprintf("%02d",$date[2]); $date[1] = sprintf("%02d",$date[1]); $date[0] = sprintf("%02d",$date[0]); $wday = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat') [$date[6]]; $month = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') [$date[4]]; $date_gmt = "$wday, $date[3]\-$month\-$date[5] $date[2]:$date[1]:$date[0] GMT"; return($date_gmt); } sub us_lock { local(*FILE) = @_; if ($lockyes) { eval("flock(FILE, 2)"); if ($@) { return 0; } } return 1; } sub un_lock { local(*FILE) = @_; if ($lockyes) { eval("flock(FILE, 8)"); } } sub error_msg { $titlename = 'エラーメッセージ'; $bg_color = 'mistyrose'; local($msg,$mail) = @_; &html_top($titlename,$bg_color); print "$msg
\n"; print "お問い合わせは"; print "$mail"; print "まで…\n"; &html_bot; exit(0); } sub show_file { local($file,$mail) = @_; local($i,$kakuno); if (!open(TXT, "$file")) { &error_msg("ファイルがありません",$mail); } seek(TXT, 0, 0); @kakuno = ; close(TXT); for ($i = 0; $i <= $#kakuno; $i++) { print "$kakuno[$i]
"; } } sub form_read { local (*init) = @_ if @_; local ($i, $key, $val); if ($ENV{'REQUEST_METHOD'} eq "GET") { $init = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$init,$ENV{'CONTENT_LENGTH'}); } @init = split(/[&;]/,$init); foreach $i (0 .. $#init) { $init[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$init[$i],2); $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $init{$key} .= "\0" if (defined($init{$key})); $init{$key} .= $val; } return scalar(@init); } sub c_right { local($myhome)= @_; print "
\n"; print " \n"; print "Copyright 2000 by "; print "\n"; print "Yasuharu Fujishima. All Rights reserved.
\n"; print "
\n"; } sub copy_right { local($myhome)= @_; print "
\n"; print " \n"; print "Copyright 2000 by "; print "
\n"; print "S.F. All Rights reserved.
\n"; print "
\n"; } sub no_string { local($word) = @_; $word =~ s/\r\n/\n/g; $word =~ s/\r/\n/g; $word =~ s/"/"/g; $word =~ s//>/g; $word =~ s/,/,/g; $word =~ s/,/\./gi; $word =~ s/\n/
/g; $word =~ s/\n\n/

/g; # $word =~ s/([\^\$\+\?\.\*\(\)\[\]\{\}\|\\])/\\$1/g; return $word; } sub date_get { local($chenge) = @_; local($sec, $min, $hour, $day, $mon, $year ,$wday); ( $sec, $min, $hour, $day, $mon, $year, $wday ) = localtime(time-86400*$chenge); $year += 1900; $mon++; $weekday = ('SUN','MON','TUE','WED','THU','FRI','SAT')[$wday]; return "$year\/$mon\/$day/$weekday"; } # グレゴリウス暦(1582年10月15日(金)午後以後)有効 # [入力] &get_week($year, $month, $day) # [出力] 0->SUN 〜 6->SAT # @week = ('SUN','MON','TUE','WED','THU','FRI','SAT'); # $year = 2001; # $month = 4; # $day = 27; # print $week[&get_week($year, $month, $day)]; sub get_week{ my($year, $month, $day) = @_; if ($month <= 2) { --$year; $month += 12; } # ツェラーの公式 return (($year + int($year/4) - int($year/100) + int($year/400) + int((13*$month + 8)/5) + $day) % 7); } # [入力] 西暦年号 &uru_nen(1999); # [出力] 閏年-> true 平年-> false sub uru_nen{ my($year) = @_; if ($year % 100) { # 100 で割り切れない if ($year % 4) { # 4 で割り切れない return 0; # 平年 } else { return 1; # 閏年 } } else { # 100 で割り切れる if ($year % 400) { # 400 で割り切れない return 0; # 平年 } else { # 400 で割り切れる if ($year % 4000) { # 4000 で割り切れない return 1; # うるう年 } else { # 4000 で割り切れる return 0; # 平年 } } } } @uru_year = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); @hey_year = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); # # [入力] 年、月 &get_month(1999,1); …1999年1月の日数 # [出力] その月の日数 # sub get_month{ my($year, $month) = @_; return &uru_nen($year) ? $uru_year[$month] : $hey_year[$month]; } 1;