#!/usr/bin/perl # isbncheck: ISBN 13 validation checker # generated by femc.org # ver 1.0 2005/08/17 10桁版 # ver 1.5 2005/08/19 13桁版 # ver 1.7 2005/08/24 省略対応版 $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'}; $forth=$FORM{'forth'}; $hanbai=$FORM{'hanbai'}; $hakkou=$FORM{'hakkou'}; $code=$FORM{'CODE'}; $chk=$FORM{'CHK'}; $isbn =~s/\+//g; $isbnhead = 978; #headnumberは978に設定 if ($chk eq "FTH"){ if ($first eq "" or $second eq "" or $third eq "" or $forth eq ""){ &end; }else{ $isbn = "$first-$second-$third-$forth"; ✓ $view = "$first-$second-$third-$forth-$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; }; #978を省略すると想定される初期対応 if($isbn =~ /^978/){ }elsif($isbn =~ /-/){ $isbn = $isbnhead . "-" . $isbn; }else{ $isbn = $isbnhead . $isbn; }; #長さとハイフンチェック $isbnw = $isbn; $isbnw =~ s/-//g; $isbncnt = ($isbn =~ tr/-//); $isbnlen = length($isbnw); if ($isbnlen < 12){ $msg = "ISBN length short";&end;exit; }elsif($isbnlen > 13){ $msg = "ISBN length over";&end;exit; }elsif($isbncnt eq 1 or $isbncnt eq 2){ $msg = "ISBN hyphen is few";&end;exit; }elsif($isbncnt eq 3 and $isbnlen eq 13){ $msg = "ISBN hyphen is few & length over";&end;exit; }; foreach $cnt (0..11){ #substrの関係上0から11までまわす。 $isbnw{$cnt} = substr($isbnw,$cnt,1); if($cnt % 2 == 0){ #cntが奇数のときは偶数桁、偶数のときは奇数桁 $isbnodd = $isbnodd + $isbnw{$cnt}; }else{ $isbneven = $isbneven + $isbnw{$cnt}; }; }; #foreach end $isbndigit = $isbnodd + ($isbneven * 3); $isbndigit = 10 - substr($isbndigit,-1); if($isbndigit eq 10){ $isbndigit = "0"; }; $isbnfth = substr($isbnw,12,1); } #--------------------------------------------------- sub hyphen{#ハイフン有無で表示対応変更 if($isbncnt == 0){ if ($isbnlen == 12){ $isbn13 = "$isbn$isbndigit"; }else{ $isbn = substr($isbn,0,12); $isbn13 = "$isbn$isbndigit"; }; }elsif($isbncnt == 4){ $isbn = substr($isbn,0,15); $isbn13 = "$isbn-$isbndigit"; }elsif($isbncnt == 3){ $isbn13 = "$isbn-$isbndigit"; }; $view = $isbn13; 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 end{ print "Content-type: text/html\n\n"; print <<"_HTML_"; ISBN

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

$msg


by $owner _HTML_ ; exit; }