#!/usr/local/bin/perl5 # # FILE # search.cgi # # CONTENTS # Perl script that processes a search request to the RISC library database. # # AUTHOR # Andreas Neubacher, Wolfgang St"ocher # # VERSION # $Id: search.cgi,v 1.17 97/06/16 15:18:01 aneubach Exp $ # # Modified by Jebelean to list the reports as needed by the Dean BEGIN { push(@INC, "/home/info/www/library/DataBase"); } require "RiscCGI.pm"; require "Msql.pm"; require "RiscLib.pm"; use RiscLibMisc; ############################################################################## # 1. GLOBAL VARIABLES ############################################################################## # 0 ... "Context-type:" line was written $NEED_CONTENTTYPE = 1; # Associate field names with BibTeX field names. %BFTABLE = ( 'abstract' => 'abstract', 'address' => 'address', 'annote' => 'annote', 'chapter' => 'chapter', 'edition' => 'edition', 'howpublished' => 'howpublished', 'institution' => 'institution', 'isbn' => 'isbn', 'journal' => 'journal', 'month' => 'month', 'note' => 'note', 'number' => 'number', 'organization' => 'organization', 'pages' => 'pages', 'publisher' => 'publisher', 'school' => 'school', 'series' => 'series', 'sponsor' => 'sponsor', 'title' => 'bibref', 'type' => 'type', 'url' => 'url', 'volume' => 'volume', 'year' => 'year', 'fname' => 'author', 'lname' => 'author' ); # Define an ordering on fields for output. @FORDER = ( 'bibkey', 'fname', 'lname', 'title', 'container', 'journal', 'volume', 'number', 'pages', 'chapter', 'edition', 'type', 'series', 'publisher', 'institution', 'organization', 'school', 'address', 'month', 'year', 'sponsor', 'url', 'isbn', 'abstract', 'keywords', 'annote', 'note', 'howpublished', 'location', 'owner', 'source', 'reftype' ); # Other undef($LIBRARY); undef(@LOCATIONS); undef(@OWNERS); undef(@SOURCES); undef(@REFTYPES); ############################################################################## # 2. PARSE ARGUMENTS ############################################################################## %QUERY_ARRAY = RiscCGI::Args(); ############################################################################## # 3. INITIALIZE ############################################################################## # # 3.1. Get global parameters # $OUTFORMAT = $QUERY_ARRAY{"OF"}; # Output format delete($QUERY_ARRAY{"OF"}); $NO_HEADER_FOOTER = $QUERY_ARRAY{"NOHF"}; # With/without header and footer delete($QUERY_ARRAY{"NOHF"}); # # 3.2. Open database # $LIBRARY = Msql->connect; if (!$LIBRARY) { ErrorPage("SERIOUS: Could not connect to mSQL server!!!"); exit 0; } $LIBRARY->selectdb("Library"); if (!$LIBRARY) { ErrorPage("SERIOUS: Could not open 'Library' database!!!"); exit 0; } # # 3.3. Read various tables # # 3.3.1. Locations $query = "SELECT locations, label FROM locations"; $qh = RiscLib::QueryXN($query); ($key, $val) = $qh->fetchrow; while (!IsEmpty($key)) { $LOCATIONS[$key] = $val; ($key, $val) = $qh->fetchrow; } # 3.3.2. Owners $query = "SELECT owners, label FROM owners"; $qh = RiscLib::QueryXN($query); ($key, $val) = $qh->fetchrow; while (!IsEmpty($key)) { $OWNERS[$key] = $val; ($key, $val) = $qh->fetchrow; } # 3.3.3. Reftypes (entrytypes) $query = "SELECT entrytypes, label FROM entrytypes"; $qh = RiscLib::QueryXN($query); ($key, $val) = $qh->fetchrow; while (!IsEmpty($key)) { $REFTYPES[$key] = $val; ($key, $val) = $qh->fetchrow; } # 3.3.4. Sources $query = "SELECT sources, label FROM sources"; $qh = RiscLib::QueryXN($query); ($key, $val) = $qh->fetchrow; while (!IsEmpty($key)) { $SOURCES[$key] = $val; ($key, $val) = $qh->fetchrow; } ############################################################################## # 4. LOCATE ENTRIES ############################################################################## # # 4.1. Build query string from parameters # $connect_and = 1; # Logical connective should be "AND". This # could come from a CGI parameter. undef($from); undef(%queries); while (($field, $val) = each(%QUERY_ARRAY)) { # 4.1.1. Ignore empty parameters if (IsEmpty($val)) { next; } # 4.1.2. "refkey" parameter: Ignore other parameters if ($field eq "refkey") { undef(%queries); $queries{0} = "SELECT DISTINCT refkey FROM bibref " . "WHERE bibref.refkey = $val"; last; } # 4.1.3. "Pattern" parameter: Ignore other parameters if ($field eq "Pattern") { undef(%queries); $queries{0} = "SELECT DISTINCT refkey FROM " . $FTABLE{"title"} . " WHERE title like " . Msql->quote($val); $queries{1} = "SELECT DISTINCT refkey FROM " . $FTABLE{"abstract"} . " WHERE abstract like " . Msql->quote($val); $queries{2} = "SELECT DISTINCT refkey FROM " . $FTABLE{"annote"} . " WHERE annote like " . Msql->quote($val); $queries{3} = "SELECT DISTINCT refkey FROM " . $FTABLE{"keywords"} . " WHERE keywords like " . Msql->quote($val); $connect_and = 0; last; } # 4.1.4. Other parameter: One query for each table $from = $FTABLE{$field}; if (defined($queries{$from})) { $queries{$from} .= ($connect_and ? " AND " : " OR "); } else { $queries{$from} .= "SELECT DISTINCT refkey FROM " . $from . " WHERE "; } if ($TTABLE{$field}) { $queries{$from} .= "$field = $val"; } else { $queries{$from} .= "$field like " . Msql->quote($val); } } #print "Content-type: text/plain\n\n"; $NEED_CONTENTTYPE = 0; #print "QUERY:\n\n"; #while (($from, $query) = each(%queries)) { # print $from . ": " . $query . "\n"; #} #exit 0; # # 4.2. Do queries # undef(%refkeys); undef(%tmprefkeys); while (($from, $query) = each(%queries)) { # 4.2.1. Do query $qh = RiscLib::QueryX($query); # 4.2.2. Process all resulting refkeys ($brefkey, @tmp) = $qh->fetchrow; while (!IsEmpty($brefkey)) { if ($connect_and) { if (!defined(%refkeys) || defined($refkeys{$brefkey})) { $tmprefkeys{$brefkey} = 1; } } else { $refkeys{$brefkey} = 1; } ($brefkey, @tmp) = $qh->fetchrow; } # 4.2.3. Special handling for "AND" connection if ($connect_and) { %refkeys = %tmprefkeys; undef(%tmprefkeys); } } ############################################################################## # 5. WRITE ENTRIES DEPENDING ON OUTPUT FORMAT ############################################################################## # # 5.1. Write header # if ($OUTFORMAT == 1) { if (!$NO_HEADER_FOOTER) { # print "Content-type: text/x-bibtex\n\n"; $NEED_CONTENTTYPE = 0; } } elsif ($OUTFORMAT == 3) { if (!$NO_HEADER_FOOTER) { # print "Content-type: text/plain\n\n"; $NEED_CONTENTTYPE = 0; } } else { if (!$NO_HEADER_FOOTER) { # print "Content-type: text/html\n\n"; $NEED_CONTENTTYPE = 0; # RiscCGI::Header("Extracted data from RISC-Linz library database", # $ADMIN_MAILTO, # "Search in RISC-Linz library database"); $RISCHEADER_IS_SET = 1; } } # # 5.2. Write entries # if (!defined(%refkeys)) { print "No matching entries found.\n"; } if ($OUTFORMAT == 0) { foreach $brefkey (keys %refkeys) { WriteEntry0($brefkey); } } elsif ($OUTFORMAT == 2) { # get titles into hash-table my (%TitleTable, $qh); foreach $brefkey (keys %refkeys) { $query = 'SELECT DISTINCT title FROM ' . $FTABLE{"title"} . ' WHERE refkey = ' . $brefkey; $qh = RiscLib::QueryX($query); $TitleTable{($qh->fetchrow)[0]} = $brefkey; } print "
\n"; foreach $title (sort(keys %TitleTable)) { WriteEntry2($TitleTable{$title}); } print "
\n" } elsif ($OUTFORMAT == 3) { # get titles into hash-table my (%TitleTable, $qh); foreach $brefkey (keys %refkeys) { $query = 'SELECT DISTINCT title FROM ' . $FTABLE{"title"} . ' WHERE refkey = ' . $brefkey; $qh = RiscLib::QueryX($query); $TitleTable{($qh->fetchrow)[0]} = $brefkey; } foreach $title (sort(keys %TitleTable)) { WriteEntry3($TitleTable{$title}); } } elsif ($OUTFORMAT == 4) { # Get numbers into hash-table my (%NumberTable, $qh); foreach $brefkey (keys %refkeys) { $query = 'SELECT DISTINCT number FROM ' . $FTABLE{"number"} . ' WHERE refkey = ' . $brefkey; $qh = RiscLib::QueryX($query); $NumberTable{($qh->fetchrow)[0]} = $brefkey; } print "
\n"; foreach $number (sort(keys %NumberTable)) { WriteEntry4($NumberTable{$number}); } print "
\n" } elsif ($OUTFORMAT == 5) { print "
\n"; foreach $brefkey (keys %refkeys) { WriteEntry5($brefkey); } print "
\n"; } else { print "Sorry, this format (#$OUTFORMAT) is not supported.\n"; } # # 5.3. Write footer # if ($OUTFORMAT != 1 && $OUTFORMAT != 3 && !$NO_HEADER_FOOTER) { RiscCGI::Footer($ADMIN_LINK, $HTTP_REFERER); } ############################################################################## # 6. FINISH ############################################################################## 0; ############################################################################## #F WriteEntry0($refkey) . . . . . . . . . . . . . Write an entry (full, HTML) # # $refkey: Internal reference key (integer). # # Every field related to reference key `$refkey' is written in HTML format. # sub WriteEntry0 { # # 1. Initialize # local ($refkey) = @_; my ($table, $fstring, $query, @fields, @vals, $qh, $author, $fn, $ln, $i, %vals, %i, %qh); if (defined($cont)) { print "
\n"; } else { $cont = 1; } print "Internal reference key: $refkey\n
"; # # 2. Process all tables and collect data # while (($table, $fstring) = each(%IFTABLE)) { # 2.1. Read fields $query = 'SELECT DISTINCT ' . $fstring . ' FROM ' . $table . ' WHERE refkey = ' . $refkey; $qh = RiscLib::QueryX($query); if ($qh->numrows <= 0) { next; } # 2.2. Write fields @fields = split(', ', $fstring); # 2.2.1. "author" table: special processing if ($table eq "author") { $qh{$fields[0]} = $qh; next; } # 2.2.2. Other tables: write fields @vals = $qh->fetchrow; for ($i=0; $i<=$#fields; $i++) { if (!IsEmpty($vals[$i]) && !($fields[$i] eq "month" && $vals[$i] == 0)) { $vals{$fields[$i]} = $vals[$i]; $i{$fields[$i]} = $i; $qh{$fields[$i]} = $qh; } } } # # 3. Print data # foreach $i (@FORDER) { if (defined($vals{$i}) || defined($qh{$i})) { if ($i eq "fname" || $i eq "lname") { print "\n
author\n
"; WriteParseAuthorHTML($i, $qh{$i}); } else { print "\n
$i\n
"; WriteFieldHTML($i, $vals{$i}, $i{$i}, $qh{$i}); } } } # # 4. Finish # print "
"; } ############################################################################## #F WriteEntry2($refkey) . . . . Write an entry (brief list with links, HTML) # # $refkey: Internal reference key (integer). # # Every field related to reference key `$refkey' is written in HTML format. # # REMARKS # * Title might be passed as additional argument to speed things up. # * Doesn't need as much generality as "WriteEntry0". # sub WriteEntry2 { # # 1. Initialize # local ($refkey) = @_; my ($table, $fstring, $query, $bibkey, @fields, @vals, @lORDER, $qh, $author, $fn, $ln, $i, %vals, %i, %qh, %lINFO); # # 2. give bibtex reference with link to full display # $query = 'SELECT DISTINCT bibkey FROM bibref WHERE refkey = ' . $refkey; $qh = RiscLib::QueryXN($query); ($bibkey) = $qh->fetchrow; print "
$bibkey:
\n
"; # # 3. collect data on authors and title # %lINFO = ('bibref' => 'title', 'author' => 'fname, lname' ); while (($table, $fstring) = each(%lINFO)) { # 3.1. Read fields $query = 'SELECT DISTINCT ' . $fstring . ' FROM ' . $table . ' WHERE refkey = ' . $refkey; $qh = RiscLib::QueryX($query); if ($qh->numrows <= 0) { next; } # 3.2. Write fields @fields = split(', ', $fstring); # 2.2.1. "author" table: special processing if ($table eq "author") { $qh{$fields[0]} = $qh; next; } # 3.2.2. Other tables: write fields @vals = $qh->fetchrow; for ($i=0; $i<=$#fields; $i++) { if (!IsEmpty($vals[$i]) && !($fields[$i] eq "month" && $vals[$i] == 0)) { $vals{$fields[$i]} = $vals[$i]; $i{$fields[$i]} = $i; $qh{$fields[$i]} = $qh; } } } # # 4. Print data # @lORDER = ("title", "fname", "lname"); foreach $i (@lORDER) { if (defined($vals{$i}) || defined($qh{$i})) { if ($i eq "fname" || $i eq "lname") { print " ("; WriteAuthorHTML($i, $qh{$i}); print ")"; } else { print ""; WriteFieldHTML($i, &tex2html($vals{$i})); print ""; } } } # # 5. Finish # print "\n
\n"; } ############################################################################## #F WriteEntry3($refkey) . . . . . . . . . Write an entry (brief list, ASCII) # # $refkey: Internal reference key (integer). # # Every field related to reference key `$refkey' is written in HTML format. # # REMARKS # * Title might be passed as additional argument to speed things up. # * Doesn't need as much generality as "WriteEntry0". # sub WriteEntry3 { # # 1. Initialize # local ($refkey) = @_; my ($table, $fstring, $query, $bibkey, @fields, @vals, @lORDER, $qh, $author, $fn, $ln, $i, %vals, %i, %qh, %lINFO); # # 2. Bibtex reference # # $query = 'SELECT DISTINCT bibkey FROM bibref WHERE refkey = ' . $refkey; # $qh = RiscLib::QueryXN($query); # ($bibkey) = $qh->fetchrow; # print "[$bibkey] "; # # 3. Collect data on authors and title # %lINFO = ($FTABLE{"title"} => 'title', $FTABLE{"fname"} => 'fname, lname' ); while (($table, $fstring) = each(%lINFO)) { # 3.1. Read fields $query = 'SELECT DISTINCT ' . $fstring . ' FROM ' . $table . ' WHERE refkey = ' . $refkey; $qh = RiscLib::QueryX($query); if ($qh->numrows <= 0) { next; } # 3.2. Write fields @fields = split(', ', $fstring); # 2.2.1. "author" table: special processing if ($table eq "author") { $qh{$fields[0]} = $qh; next; } # 3.2.2. Other tables: write fields @vals = $qh->fetchrow; for ($i=0; $i<=$#fields; $i++) { if (!IsEmpty($vals[$i]) && !($fields[$i] eq "month" && $vals[$i] == 0)) { $vals{$fields[$i]} = $vals[$i]; $i{$fields[$i]} = $i; $qh{$fields[$i]} = $qh; } } } # # 4. Print data # @lORDER = ("fname", "lname", "title"); foreach $i (@lORDER) { if (defined($vals{$i}) || defined($qh{$i})) { if ($i eq "fname" || $i eq "lname") { print "("; WriteAuthorASCII($i, $qh{$i}); print ") "; } else { print '"'; WriteFieldASCII($i, $vals{$i}, $i{$i}); print '" '; } } } # # 5. Finish # print "\n"; } ############################################################################## #F WriteEntry4($refkey) . . . . Write an entry (brief list with links, HTML) # # $refkey: Internal reference key (integer). # # Every field related to reference key `$refkey' is written in HTML format. # # REMARKS # * Number might be passed as additional argument to speed things up. # * Doesn't need as much generality as "WriteEntry0". # sub WriteEntry4 { # # 1. Initialize # local ($refkey) = @_; my ($table, $fstring, $query, $number, @fields, @vals, @lORDER, $qh, $author, $fn, $ln, $i, %vals, %i, %qh); # # 2. Give report number with link to full display # $query = "SELECT DISTINCT number FROM $FTABLE{number} WHERE refkey = $refkey"; $qh = RiscLib::QueryXN($query); ($number) = $qh->fetchrow; print "
$number: "; # # 3. Collect data on authors and title # %lINFO = ($FTABLE{"title"} => 'title', $FTABLE{"fname"} => 'fname, lname'); while (($table, $fstring) = each(%lINFO)) { # 3.1. Read fields $query = 'SELECT DISTINCT ' . $fstring . ' FROM ' . $table . ' WHERE refkey = ' . $refkey; $qh = RiscLib::QueryX($query); if ($qh->numrows <= 0) { next; } # 3.2. Store fields @fields = split(', ', $fstring); # 3.2.1. "author" table: special processing if ($table eq "author") { $qh{$fields[0]} = $qh; next; } # 3.2.2. Other tables: store fields @vals = $qh->fetchrow; for ($i=0; $i<=$#fields; $i++) { if (!IsEmpty($vals[$i]) && !($fields[$i] eq "month" && $vals[$i] == 0)) { $vals{$fields[$i]} = $vals[$i]; $i{$fields[$i]} = $i; $qh{$fields[$i]} = $qh; } } } # # 4. Print data # @lORDER = ("fname", "lname", "title"); foreach $i (@lORDER) { if (defined($vals{$i}) || defined($qh{$i})) { if ($i eq "fname" || $i eq "lname") { WriteAuthorHTML($i, $qh{$i}); print "
\n
"; } else { print ""; WriteFieldHTML($i, &tex2html($vals{$i})); print ""; } } } # # 5. Finish # print "\n
\n"; } ############################################################################## #F WriteEntry5($refkey) . . . . . . . Write an entry (nice formatting, HTML) # # $refkey: Internal reference key (integer). # # most interesting fields are given in tables # sub WriteEntry5 { # # 1. Initialize # local ($refkey) = @_; my ($query, $bibkey, $title, $year, $howpublished, $reftype, $abstract, $number, $sponsor, $qh); # # 2. make queries and get data # $query = 'SELECT DISTINCT title, year FROM bibref WHERE refkey = ' . $refkey; $qh = RiscLib::QueryXN($query); ($title, $year) = $qh->fetchrow; $query = "SELECT DISTINCT number FROM $FTABLE{number} WHERE refkey = $refkey"; $qh = RiscLib::QueryX($query); if ($qh->numrows > 0) { $number = ($qh->fetchrow)[0]; } $query = "SELECT DISTINCT howpublished FROM $FTABLE{howpublished} WHERE refkey = $refkey"; $qh = RiscLib::QueryX($query); if ($qh->numrows > 0) { $howpublished = ($qh->fetchrow)[0]; } # # 3. show data # print "\#. "; # authors $query = 'SELECT DISTINCT fname, lname FROM author WHERE refkey = ' . $refkey; $qh = RiscLib::QueryX($query); if ($qh->numrows <= 0) { print "Unknown"; } else { WriteAuthorHTML('fname',$qh); } print " ($year) \n"; print "\"" . $title . "\""; print "\nRISC-Report $number"; print "\n\n"; } ############################################################################## #F WriteParseAuthorHTML($field, $qh) . . . . . Write the author field (HTML) # # $field: Fieldname string, must be "fname" or "lname"). # $qh : Query handle. Must be non-zero. # # The field data for author is written in HTML format such that it # can be parsed again. # sub WriteParseAuthorHTML { # # 1. Initialize # local($field, $qh) = @_; my(@vals, $fn, $ln); # # 2. Write fields # # Author undef($author); @vals = $qh->fetchrow; do { if (defined($ln)) { print " +
\n"; } if ($field eq "fname") { $fn = $vals[0]; $ln = $vals[1]; } else { $ln = $vals[0]; $fn = $vals[1]; } print $ln . "; " . $fn; @vals = $qh->fetchrow; } while ($#vals >= 0); } ############################################################################## #F WriteAuthorHTML($field, $qh) . . . . . . . Write the author field (HTML) # # $field: Fieldname string, must be "fname" or "lname"). # $qh : Query handle. Must be non-zero. # # The field data for author (fname, lname) is written in HTML format. # sub WriteAuthorHTML { # # 1. Initialize # local($field, $qh) = @_; my(@vals, $fn, $ln); # # 2. Write fields # # Author undef($author); @vals = $qh->fetchrow; do { if (defined($ln)) { print ", "; } if ($field eq "fname") { $fn = $vals[0]; $ln = $vals[1]; } else { $ln = $vals[0]; $fn = $vals[1]; } &tex2html($fn); &tex2html($ln); print $fn . " " . $ln; @vals = $qh->fetchrow; } while ($#vals >= 0); } ############################################################################## #F WriteFieldHTML($field, $val, $i, $qh) . . . . . . . Write a field (HTML) # # $field: Fieldname string. # $val : Field value. # $i : Index of field value in array returned by "`$qh'->fetchrow". # $qh : Query handle. Must be non-zero. # # The field data is written in HTML format. # sub WriteFieldHTML { # # 1. Initialize # local($field, $val, $i, $qh) = @_; # # 2. Write fields # # Container if ($field eq "container") { print 'search.cgi?refkey=' . $val . ''; } # Location elsif ($field eq "location") { print &LocationHTML($val); } # Month elsif ($field eq "month") { print &MonthHTML($val); } # Owner elsif ($field eq "owner") { print &OwnerHTML($val); } # Reftype elsif ($field eq "reftype") { print &RefTypeHTML($val); } # Source elsif ($field eq "source") { print &SourceHTML($val); } # Sponsor elsif ($field eq "sponsor") { print SponsorsHTML(GetArray($val, $i, $qh)); } # URL elsif ($field eq "url") { print UrlsHTML(GetArray($val, $i, $qh)); } else { print $val; } } ############################################################################## #F $html = LocationHTML($val) . . . generate HTML output from database entry # . . . . . . . . . . . . . . . . . . . . . . . . . . . for field 'location' # # $val : database entry. # $html : String in HTML format representing `$val'. # sub LocationHTML { return $LOCATIONS[$_[0]]; } ############################################################################## #F $html = MonthHTML($val) . . . . generate HTML output from database entry # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . for field 'month' # # $val : database entry. # $html : String in HTML format representing `$val'. # sub MonthHTML { return $MONTHS[$_[0]]; } ############################################################################## #F $html = OwnerHTML($val) . . . . generate HTML output from database entry # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . for field 'owner' # # $val : database entry. # $html : String in HTML format representing `$val'. # sub OwnerHTML { return $OWNERS[$_[0]]; } ############################################################################## #F $html = RefTypeHTML($val) . . . generate HTML output from database entry # . . . . . . . . . . . . . . . . . . . . . . . . . . . . for field 'reftype' # # $val : database entry. # $html : String in HTML format representing `$val'. # sub RefTypeHTML { return $REFTYPES[$_[0]]; } ############################################################################## #F $html = SourceHTML($val) . . . . generate HTML output from database entry # . . . . . . . . . . . . . . . . . . . . . . . . . . . . for field 'source' # # $val : database entry. # $html : String in HTML format representing `$val'. # sub SourceHTML { return $SOURCES[$_[0]]; } ############################################################################## #F $html = SponsorsHTML(@val) . . generate HTML output from database entries # . . . . . . . . . . . . . . . . . . . . . . . . . . . . for field `sponsor' # # @val : Array of database entries. # $html : String in HTML format representing `@val'. # sub SponsorsHTML { local(@val) = @_; my($html, $i); foreach $i (@val) { if (defined($html)) { $html = $html . ";\n"; } $html = $html . tex2html($i); } return $html; } ############################################################################## #F $html = UrlsHTML(@val) . . . . generate HTML output from database entries # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . for field `url' # # @val : Array of database entries. # $html : String in HTML format representing `@val'. # sub UrlsHTML { local(@val) = @_; my($html, $i); foreach $i (@val) { if (defined($html)) { $html = $html . ",\n"; } $html = $html . '' . $i . ''; } return $html; } ############################################################################## #F WriteAuthorASCII($field, $qh) . . . . . . Write the author field (ASCII) # # $field: Fieldname string, must be "fname" or "lname"). # $qh : Query handle. Must be non-zero. # # The field data for author (fname, lname) is written in ASCII format. # sub WriteAuthorASCII { # # 1. Initialize # local($field, $qh) = @_; my(@vals, $fn, $ln); # # 2. Write fields # # Author undef($author); @vals = $qh->fetchrow; do { if (defined($ln)) { print ", "; } if ($field eq "fname") { $fn = $vals[0]; $ln = $vals[1]; } else { $ln = $vals[0]; $fn = $vals[1]; } print $fn . " " . $ln; @vals = $qh->fetchrow; } while ($#vals >= 0); } ############################################################################## #F WriteFieldASCII($field, $val, $i) . . . . . . . . . Write a field (ASCII) # # $field: Fieldname string. # $val : Field value. # $i : Index of field value in array returned by "`$qh'->fetchrow". # # The field data is written in ASCII format. # sub WriteFieldASCII { # # 1. Initialize # local($field, $val, $i) = @_; # # 2. Write fields # # Container if ($field eq "container") { print 'in [refkey=' . $val . ']'; } # Location elsif ($field eq "location") { print $LOCATIONS[$val]; } # Month elsif ($field eq "month") { print $MONTHS[$val]; } # Owner elsif ($field eq "owner") { print $OWNERS[$val]; } # Source elsif ($field eq "source") { print $SOURCES[$val]; } # Reftype elsif ($field eq "reftype") { print $REFTYPES[$val]; } # URL elsif ($field eq "url") { print '"' . $val . '"'; } else { print $val; } } ############################################################################## #F @a = GetArray($val, $i, $qh) . . . read values from database into an array # # $val: Value in `$i'-th field of first row of `$qh'. # $i: Index of field to be read from rows of `$qh'. # $qh: Query handle. Must be non-zero. Starts at *second* row. # @a: Array containing the values in the `$i'-th fields of the rows of # `$qh'. The first element of the array contains `$val'. # sub GetArray { local($val, $i, $qh) = @_; my(@row, @a); do { push(@a, $val); if ($qh != 0) { @row = $qh->fetchrow; $val = $row[$i]; } } while ($#row >= 0); return @a; } ############################################################################## #F RiscReport($reftype) . . check whether `$reftype' indicates a RISC Report # # $reftype : database entry for reference type. # sub RiscReport { local($ref) = $_[0]; return ($ref == 14 || $ref eq "riscreport"); } ############################################################################## #F tex2html($str) . . . . . . . . . convert 'umlauts' and other special chars # # $str: string to be converted. # sub tex2html { local($str) = @_; $str =~ s/{\\\"([AOUaou])}/&\1uml;/g; $str =~ s/\\\"([AOUaou])/&\1uml;/g; $str =~ s/\\\"{([AOUaou])}/&\1uml;/g; $str =~ s/{\\\"([AOUaou])}/&\1uml;/g; $str =~ s/\\\"(s\\ |s\s|{s})/ß /g; $str =~ s/(\\ss(\\ |\s))|({\\ss})|(\\ss{})/ß/g; $_[0]=$str; }