#!/usr/bin/perl # CGI script: PDOS publication BibTeX entry # Eddie Kohler, June 10, 1999 use lib '/home/am3/httpd/htdocs/pdosbib'; #use lib '/u/eddietwo/www/pdos/pdosbib'; use BibTeX; use PDOSCGI; %initial_strings = ('jan' => 'January', 'feb' => 'February', 'mar' => 'March', 'apr' => 'April', 'may' => 'May', 'jun' => 'June', 'jul' => 'July', 'aug' => 'August', 'sep' => 'September', 'oct' => 'October', 'nov' => 'November', 'dec' => 'December'); open(BIB, "$pdos_bib_dir/pdos.bib") || error_exit("Can't open pdos.bib!"); $e = BibTeX::parse(*BIB, %initial_strings); close BIB; ##### # PROCESS_QUERY sub process_query ($) { my($q) = $_[0]; while ($q =~ /^\&?([^\&]+)(.*)/) { $_ = url_translate($1); $q = $2; if (/^key=(.*)$/) { $bibtex_key = $1; } else { error_exit('Bad Query', <<"EOD;"); I don't understand part of your query -- specifically, the ``$_'' part. EOD; } } } ## # INITIALIZATION & READING $index_url = "http://$ENV{'SERVER_NAME'}$ENV{'REQUEST_URI'}"; $index_url =~ s#/[^/]+$#/#; &process_query($ENV{'QUERY_STRING'}) if exists $ENV{'QUERY_STRING'}; print <<"EOD;"; Content-type: text/html PDOS Publications Search Results
PDOS Home




  MIT > LCS > PDOS Home > 

Publications > 

BibTeX entry


Projects
People
Software

By subject
By date

 Publication search:  

EOD; $type = ($bibtex_key ? "`$bibtex_key'" : "all entries"); print "

BibTeX entry server: results for $type

\n"; sub break_lines ($$) { my($t, $l) = @_; my($s, $f, $p, $x) = (0, 0, 0, ""); while ($p < length $t) { if (substr($t, $p, 1) =~ /\s/) { $s = $p; } elsif ($f + $l <= $p && $s > $f) { $x .= substr($t, $f, $s - $f) . "\n"; $s = $f = $s + 1; } $p++; } $x .= substr($t, $f); $x; } if ($bibtex_key && $e->{$bibtex_key}) { $d = BibTeX::expand($e, $bibtex_key); $k = "\@" . $d->{'_type'} . "{" . $bibtex_key . ",\n"; foreach $i ('title', 'author', 'journal', 'booktitle', 'school', 'institution', 'organization', 'volume', 'number', 'year', 'month', 'address', 'chapter', 'edition', 'pages', 'editor', 'howpublished', 'key', 'publisher', 'type', 'note') { if (exists $d->{$i}) { $k .= break_lines(" " . $i . " = {" . $d->{$i} . "},\n", 80); } } $k .= "}\n"; } elsif ($bibtex_key) { print "

There is no PDOS paper with key `$bibtex_key'.\n"; undef $k; } else { $k = `cat pdos.bib`; } if (defined $k) { $k =~ s/&/&/g; $k =~ s//>/g; print "

$k
\n"; } print <<"EOD;";

EOD;