aboutsummaryrefslogtreecommitdiffstats
path: root/perl-v2/bibtex-entry.cgi
blob: 8c166fa5a3919fa414ecb1dd8ed8ffca73e82be8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/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 <tt>pdos.bib</tt>!");
$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 ``<tt>$_</tt>''
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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">

<!-- Generated by `bibtex-entry.cgi'
  -- (c) Eddie Kohler 1999-2000 -->

<title>PDOS Publications Search Results</title>

<link rel="stylesheet" type="text/css" href="$css_dir/main.css">
<link rel="stylesheet" type="text/css" href="$css_dir/pubs.css">

</head>
<body bgcolor="#ffffff" text="#000000" link="#bb0000" vlink="#990099"
alink="#ff9900" marginheight="0" marginwidth="0">

<table cellspacing="0" cellpadding="0" border="0" align="center">

<tr valign="top">
<td rowspan="8" width="134"><div align="right"><a href="/"><img
src="/img/pdostab.gif" width="134" height="61" border="0" 
alt="PDOS Home"></a></div></td> 
<td rowspan="8" width="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
width="1" height="1" alt=""></td>
<td bgcolor="#ffffcc"><p><br></p></td>
<td bgcolor="#ffffcc"><p><br></p></td>
<td bgcolor="#ffffcc"><p><br></p></td>
<td rowspan="4" width="8" bgcolor="#ffffcc"><img src="/img/emptydot.gif"
width="8" height="1" alt=""></td>
<td rowspan="6" width="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
width="1" height="1" alt=""></td>
</tr>

<tr valign="top">
<td bgcolor="#ffffcc"><p>&nbsp;&nbsp;<a href="http://web.mit.edu/">MIT</a>&nbsp;&gt;&nbsp;<a href="http://www.lcs.mit.edu/">LCS</a>&nbsp;&gt;&nbsp;<a href="/">PDOS&nbsp;Home</a>&nbsp;&gt;&nbsp;</p></td>
<td bgcolor="#ffffcc"><p><a href="$main_dir/pubs.html">Publications</a>&nbsp;&gt;&nbsp;</p></td>
<td bgcolor="#ffffcc"><p><b>BibTeX&nbsp;entry</b></p></td>
</tr>

<tr valign="top">
<td bgcolor="#ffffcc"><p><br></p></td>
<td bgcolor="#ffffcc"><p class="crumbbreadth">
<a href="$main_dir/projects.html">Projects</a><br>
<a href="$main_dir/people.html">People</a><br>
<a href="$main_dir/software.html">Software</a></p></td>
<td bgcolor="#ffffcc"><p class="crumbbreadth">
<a href="$main_dir/pubs.html">By subject</a><br>
<a href="/cgi-bin/pubs-date.cgi">By date</a><br>
</p></td>
</tr>

<tr valign="top">
<td colspan="2" height="8" bgcolor="#ffffcc"><img src="/img/emptydot.gif"
width="1" height="8" alt=""></td>
<td height="8" bgcolor="#ffffcc"><img src="/img/emptydot.gif"
width="100" height="8" alt=""></td>
</tr>

<tr valign="top">
<td colspan="4" height="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
width="1" height="1" alt=""></td>
</tr>

<tr valign="top">
<td rowspan="2" colspan="3" bgcolor="#ccffff"><form action="/cgi-bin/pubs-date.cgi"
method="get"><strong>&nbsp;Publication
search:</strong><small>&nbsp;&nbsp;<input type=entry
name=match size=15> <input type=submit
value="Go"><br></small></form></td>

<td width="8" bgcolor="#ccffff"><img src="/img/emptydot.gif"
width="8" height="1" alt=""></td>
</tr>

<tr valign="bottom">
<td rowspan="2" colspan="2" width="9" height="9" bgcolor="#ccffff" background="/img/nineborder.gif"><img src="/img/whitecorner.gif" width="9" height="9" alt=""></td>
</tr>

<tr valign="top">
<td colspan="3" height="1" bgcolor="#92a6a4"><img src="/img/emptydot.gif"
width="1" height="1" alt=""></td>
</tr>
    
</table>


<table cellspacing="0" cellpadding="0" border="0" width="100%">

<tr valign="top">
<td width="15%" height="24"><br></td>
</tr>

<tr valign="top">
<td></td>

<td width="70%">

EOD;

$type = ($bibtex_key ? "<tt>`$bibtex_key'</tt>" : "all entries");
print "<h1>BibTeX entry server: results for $type</h1>\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 "<p>There is no PDOS paper with key `<tt>$bibtex_key</tt>'.\n";
  undef $k;
} else {
  $k = `cat pdos.bib`;
}
if (defined $k) {
  $k =~ s/&/&amp;/g;
  $k =~ s/</&lt;/g;
  $k =~ s/>/&gt;/g;
  print "<p><pre>$k</pre>\n";
}


print <<"EOD;";
</td>

<td width="15%"><br></td>

</tr>
</table>

</body>
</html>
EOD;