#!/usr/local/bin/perl5 # # USAGE # read STAIRSFILE # # DESCRIPTION # Perl script that reads a STAIRS library database file ############################################################################## # 2. PARSE ARGUMENTS ############################################################################## # # 2.3. Process arguments # if ($#ARGV >= 0) { $STAIRS = shift(@ARGV); } else { do usage (); exit $ERR_ARGS; } ############################################################################## # 4. READ STAIRS FILE, STORE ENTRIES IN DATABASE ############################################################################## # # 4.1. Open file # open(STAIRS, "<$STAIRS") or die "Can't open file '$STAIRS'!"; # # 4.2. Loop over records # $_ = ; while (defined($_)) { # 4.2.1. Initialize record entry data $ai = 0; $author = ''; $label = ''; $title = ''; $year = ''; # owner flag: 0 undefined; 1 uni; 2 not uni $flag = 0; # book flag; 0 no, 1 yes $bookflag = 0; # 4.2.2. Collect record entry data do { ($field, $data) = ReadField(); if ($field =~ /AUTHOR/) { # print $data; print "\n"; if(IsEmpty($author)) { $author = $data; } else { $author .= '; ' . $data; } } elsif ($field =~ /OWNER/) { if ($data =~ /uchber/i) { $flag = 2; } elsif ($data =~ /isc/i) { $flag = 2; } elsif ($data =~ /math/i || $data =~ /bib/) { $flag = 1; } else { $flag = 2; } } elsif ($field =~ /CLASS/) { if(($data =~ /ook/i) || ($data =~ /roceedings/)) { $bookflag = 1; } else { $bookflag = 0; }; } elsif ($field =~ /YEAR/) { $year = int($data); } elsif ($field =~ /TITLE/) { if(IsEmpty($author)) { $title = $data; } else { $title .= ' ' . $data; } } elsif ($field =~ /LABEL/) { $label = $data; } # print $_; } while (!IsEmpty($_) || /:NICK/); # 4.2.3. Store entry PrintEntry(); } # # 4.3. Close file # close(STAIRS); print "\nDone.\n"; 0; ############################################################################## # PrintEntry() prints only books and proceedings from math library # sub PrintEntry { if(($flag == 1) && (!IsEmpty($label)) && ($bookflag == 1)) { print $label; print " ("; print $year; print ") "; print $author; print ": "; print $title; print "\n"; } } ############################################################################## #F ($f, $d) = ReadField() . . . . . . . . . . . . . . . . . Read STAIRS field # # $f: Field label # $d: Field data # sub ReadField { my ($f, $d); if (!/^\s*:[A-Z]/) { $_ = ; return (undef, undef); } s/^\s*://; chop; ($f, $d) = split(/\./, $_, 2); while (1) { $_ = ; if (IsEmpty($_) || /^\s*:[A-Z]/) { return ($f, $d); } chop; $d .= ' ' . $_; } } ############################################################################## #F $t = IsEmpty($str) . . . . . . . . . . . . . . Check string for emptyness # # $str: A string. # $t : 1 if "$str" is undefined, empty, or consists only of whitespace, # 0 otherwise. # sub IsEmpty { local ($str) = @_; return (!defined($str) || $str =~ /^\s*$/s); }