#!/usr/bin/perl # cuecatisbn.pl, version 0.11 # copyright (C) 2000 Sujal Shah # # this is a modified version of isbn.pl found at # http://freshmeat.net/projects/isbn.pl/homepage/ # # it now loops over STDIN expecting output from the # cuecat kernel driver for linux (basically # cat /dev/scanners/cuecat). # # The original copyright and comments are maintained below # #------------------------------------------------------------ # # isbn.pl, version 0.1 # copyright (C) 2000 Dan Chudnov # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # About this script: # # get_bookinfo() will grab a book record from the Library of Congress # catalog based on an incoming ISBN. This function is intended for use # in other packages, such as barcode reader drivers, to provide users # of thoese tools with the extensive cataloging metadata librarians # have created over the years. The data returned is in the MARC format, # the heavily used, ancient metadata standard originally based on library # catalog cards, which is extensively documented at: # http://lcweb.loc.gov/marc/marc.html # # Z39.50, the not-quite-so-ancient-as-MARC-but-still-kinda-crusty # query/retrieval protocol in general use in library catalogs, is # extensively documented at http://lcweb.loc.gov/z3950/agency/ # # Zeta, the perl module which handles Z39.50 queries below, is available # at http://zeta.tlcpi.finsiel.it/z3950/zetaperl/ # # Instructions for querying Library of Congres via Z39.50 are available # at http://lcweb.loc.gov/z3950/lcserver.html # # Dan Chudnov # The C Programming Language, 2nd ed. my $isbn1 = "0131103628"; # Programming Perl my $isbn2 = "0937175641"; # The UNIX philosophy / Mike Gancarz. my $isbn3 = "1555581234"; # Small is Beautiful my $isbn4 = "0061361224"; while () { $value = 0; chop; $arg = $_; (undef, undef, $isbn) = split (',', $arg); $isbn =~ s/978(\d{9}).*/$1/; $checkisbn = $isbn; for ($i=2; $i < 11; $i++) { $tip = chop $checkisbn; $value = $value + ($tip * $i); } $check = 11 - ($value % 11); if ($check eq "10") { $check = "X"; } $isbn = $isbn . $check; print "$isbn \n\n"; my @record = get_bookinfo( $isbn ); foreach my $line ( @record ) { print "$line\n"; } } sub get_bookinfo { use Zeta; use strict; #$Zeta::VERBOSE = 1; my $isbn = shift; # values provided by LC at url above my $hostname = "z3950.loc.gov"; my $port = 7090; my $id = "isbn"; my $status; my $reason; my $result; my $newid; # Connect to LC Z39.50 port my $zc = Zeta::Connection::New ( $hostname, $port ); if (!$zc) { die "Z39.50 connection to LC failed.\n"; } else { ( $status, $reason, $result, $newid ) = $zc->Init ($id); } #print "connection: $status, $reason, $result, $newid\n"; my $found; my $info; my $database = "Voyager"; my $resultset = "default"; my $query = "1=7 $isbn"; ( $status, $reason, $found, $info ) = $zc->Search ( $database, $resultset, $query ); my $returned; my @record; my $howmany = "10"; my $start = "1"; my $format = "B"; my $syntax = ""; ( $status, $reason, $returned, @record ) = $zc->Present ( $resultset, $howmany, $start, $format, $syntax ); ( $status, $reason ) = $zc->Close("1"); #print "exiting get_bookinfo, $status: $reason\n"; return @record; }