#!/usr/bin/perl # isbncheck: ISBN validation checker # regenerated by femc.org # ver 1.0 2005/08/17 $owner = "snews.net";#ファイルの所有者指定 $css = "/css/index2004.css";#StyleSheetファイル指定 if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; }; @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name,$value) = split(/=/, $pair); $FORM{$name} = $value; } $cnt=0; $isbn=$FORM{'ISBN'}; $ccodec=$FORM{'CCODE'}; $first=$FORM{'first'}; $second=$FORM{'second'}; $third=$FORM{'third'}; $hanbai=$FORM{'hanbai'}; $hakkou=$FORM{'hakkou'}; $code=$FORM{'CODE'}; $chk=$FORM{'CHK'}; $isbn =~s/\+//g; if($ARGV[0] ne ""){$isbn = $ARGV[0];$isbn =~ s/^978//;✓‐&txt;exit;}; if ($chk eq "FTH"){ if ($first eq "" or $second eq "" or $third eq ""){ &end; }else{ $isbn = "$first-$second-$third-"; ✓ $view = "$first-$second-$third-$isbndigit"; $msg = "ISBN generated"; &html; }; }elsif ($chk eq "CCODE"){ if ($hanbai eq "" or $hakkou eq "" or $code eq ""){&end; }else{ $ccode = $hanbai . $hakkou . $code; $ccodec=$ccode; &ccheck; &html; }; }else{ if($isbn eq ""){ if($ccodec eq ""){&end;} elsif($ccodec ne ""){&ccheck;}; }else{ ✓ ‐ if($ccodec ne ""){&ccheck;}; &html; }; }; exit; #--------------------------------------------------- sub check{ if($isbn =~/--/){&end;#ハイフンが重複している場合 }elsif($isbn =~/[A-WYZa-wyz]/){#数字とX以外処理 &end; }; #長さとハイフンチェック $isbnw = $isbn; $isbnw =~ s/-//g; $isbncnt = ($isbn =~ tr/-//); $isbnlen = length($isbnw); if ($isbnlen < 9){ $msg = "ISBN length short";&end;exit; }elsif($isbnlen > 10){ $msg = "ISBN length over";&end;exit; }elsif($isbncnt eq 1){ $msg = "ISBN hyphen is few";&end;exit; }elsif($isbncnt eq 2 and $isbnlen eq 10){ $msg = "ISBN hyphen is few & length over";&end;exit; }; foreach $cnt (0..8){ #substrの関係上0から8までまわす。 $isbncut{$cnt} = substr($isbnw,$cnt,1); $cntd = 10 - $cnt; $isbnval = $isbnval + ($isbncut{$cnt} * $cntd); }; $isbndigit = 11 - ($isbnval % 11);#合計を11で割った余りを11から引く if($isbndigit eq 10){ $isbndigit = "X"; }elsif($isbndigit eq 11){ $isbndigit = "0"; }; $isbnfth = substr($isbnw,9,1); if($isbnfth eq "x"){$isbnfth = "X";};#xが小文字のとき } #--------------------------------------------------- sub hyphen{#ハイフン有無で表示対応変更 if($isbncnt == 0){ if ($isbnlen == 9){ $isbn = "$isbn$isbndigit"; }else{ $isbn = substr($isbn,0,9); $isbn = "$isbn$isbndigit"; }; }elsif($isbncnt == 3){ $isbn = substr($isbn,0,11); $isbn = "$isbn-$isbndigit"; }elsif($isbncnt == 2){ $isbn = "$isbn-$isbndigit"; }; $view = $isbn; if($isbnfth eq $isbndigit){ $msg = " is O.K."; }else{ $msg = " is failed"; }; } #--------------------------------------------------- sub ccheck { # C-CODE チェック $len = length $ccodec; if ($len ne "4"){$view="C-CODE Length is FAILED.";&html;exit;}; $han=substr($ccodec,0,1); $hak=substr($ccodec,1,1); $nai=substr($ccodec,2,2); if($han eq 0){$hanc="一般";} elsif($han eq 1){$hanc="教養";} elsif($han eq 2){$hanc="実用";} elsif($han eq 3){$hanc="専門";} elsif($han eq 4){$hanc="存在しません";} elsif($han eq 5){$hanc="婦人";} elsif($han eq 6){$hanc="学参I(小・中学生対象)";} elsif($han eq 7){$hanc="学参II(高校生対象)";} elsif($han eq 8){$hanc="児童(中学生以下対象)";} elsif($han eq 9){$hanc="存在しません";}; if($hak eq 0){$hakc="単行本";} elsif($hak eq 1){$hakc="文庫本";} elsif($hak eq 2){$hakc="新書版";} elsif($hak eq 3){$hakc="全集・双書";} elsif($hak eq 4){$hakc="存在しません";} elsif($hak eq 5){$hakc="事・辞典";} elsif($hak eq 6){$hakc="図鑑";} elsif($hak eq 7){$hakc="絵本";} elsif($hak eq 8){$hakc="マイクロ・点字・混合・カセット";} elsif($hak eq 9){$hakc="存在しません";}; open(CHK,"code.dat"); @cchk=; close(CHK); foreach $cchk(@cchk){ ($num,$naico)=split(/,/,$cchk); if($num eq $nai){$naic = $naico;}; }; if ($naic eq ""){$naic="該当はありません";}; $view = $view ."

C" .$han . $hak .$nai ."
販売対象:" .$hanc ."
発行形態:" .$hakc ."
内容コード:" .$naic; }; #--------------------------------------------------- sub html{ if ($chk eq "FTH"){$end = "ISBN CREATED";} elsif ($chk eq "CCODE"){$end = "C-CODE CREATED";} else {$end = "ISBN CHECKED";}; print "Content-type: text/html\n\n"; print <<"_HTML_"; ISBN

$FORM{'ISBN'}$msg
$view


$end by $owner _HTML_ ; } #--------------------------------------------------- sub txt{ print "$view"; } #--------------------------------------------------- sub end{ print "Content-type: text/html\n\n"; print <<"_HTML_"; ISBN

不正な記入、もしくは未記入があります。

$msg


by $owner _HTML_ ; exit; }