#! /usr/local/bin/perl
# This is a CGI-script that generates a search form and some shortcuts link
# for searching a preprint archive.
#
# Adding new preprints are straightforward, and so is adding a new year
# of preprints. Preprints are stored in directories named after the year
# they belong to, like 1997, 1998 etc. In these directories, the preprints
# are stored under names like '14.ps' or '14.ps.gz', with "14" being the
# preprint number for that year, and "ps" and "ps.gz" could be *any* extension
# for some format. A line of data must also be put in the file 'index' in
# the year directory.
#
# The files 'index' for each year is a tab-separated text file with
# one line per preprint containing four fields: number, authors, title,
# and comment.
# * The number field could also contain some flags 'L', 'M' and
# 'MS' before the number. Ex: LM07 or MS32.
# * The authors field can contain several names, which then should be
# separated by commas.
# * The title field contains the preprint title
# * The comment is to mention if it is published, etc. and will be typeset
# differently from the title.
#
# To add a new year, just create a directory named fo that year, e.g. 2001,
# and put a file 'index' in it. It will then be automatically found by
# this program.
# Some extra features:
#
# * If a line ends with a backslash "\", then the line is assumed to
# continue on the next line
# * Abstract could be named like '05.abs.tex', '12.abs.dvi' to be
# recognized and will give the link a nicer formatting.
#
# Changes
# 2007-05-04 fors@chalmers.se Changed the staff and adress URL.
require "Lib/cgi-lib.pl";
sub defaults {
$indexfil="index";
%formatnamn = (
"ps.gz" => "Gzipped PS",
"ps" => "PostScript",
"txt" => "Text",
"pdf" => "PDF",
"pdf.gz" => "Gzipped PDF",
"abs.html"=> "Abstract",
"abs.txt" => "Abstract",
"abs.ps" => "Abstract (PS)",
"abs.dvi" => "Abstract (Dvi)",
"abs.tex" => "Abstract (TeX)"
);
$dir=".";
opendir(DIR,$dir);
@p_yeardirs = (reverse sort grep {/^[0-9]+$/ &&
-d "$dir/$_" && -r "$dir/$_/$indexfil"}
readdir(DIR));
$dir="Doctoral";
opendir(DIR,$dir);
@d_yeardirs = (reverse sort grep {/^[0-9]+$/ &&
-d "$dir/$_" && -r "$dir/$_/$indexfil"}
readdir(DIR));
}
MAIN:
{
&defaults;
&PrintTemplateTop;
print qq*
Welcome to the archive of Preprints:
"BLÅ SERIEN"
This archieve is searchable. Enter a word to search for in author,
title or preprint number. Leave the field blank to obtain the
complete archive. (Search hints)
\n
The archive is maintained by Setta Aspström
<setta at math dot chalmers dot se>.
To contact an author, see the
staff list, to see if they are currently working here, and our
address.
"
" means that the preprint file was
added to the archive during the last two weeks.\n!;
# Form completely printed. now, print result, if any
if(&ReadParse(*input)) {
$NoTable++ if $input{"typ"} eq "listed";
PAPER: {
if($input{"preprints"} eq "true") {
$dir=".";
$type="Preprints";
$searchfor= $input{"find"};
$years=$input{"p_year"} or $years = join("\0",@p_yeardirs) ;
last PAPER;
}
if($input{"doc"} eq "true") {
$dir="Doctoral";
$type="Doctoral Dissertations";
$years= join("\0",@d_yeardirs);
last PAPER;
}
}
#DEBUGLINE
# print "Year = $years
";
# print "Type=$type
";
$years =~ tr/0-9\0//cd; # years should only contain numbers
@searchyears=split(/\0/,$years);
#DEBUGLINES for years
#$foo=1;
#for $apa (@searchyears) {
#print "YEAR:$foo:$apa
";
##$foo++;
#}
#DEBUGLINE
#print "Searchfor 1 = $searchfor
" if $searchfor;
$searchfor = $input{"find2"} if !$searchfor;
$plural = "s" if @searchyears >=2;
print "
\n";
print qq!
! unless $NoTable;
print qq!!;
print "$type for year$plural ",join(', ',@searchyears);
print ", matching '$searchfor'" if $searchfor;
$searchfor =~ s![;{}/\(\)]!.!g; # Avoid dangerous characters in search
print"\n";
print" |
\n" unless $NoTable;
for $year (@searchyears) {
$antal=0;
opendir(DIR,"$dir/$year");
open(FIL,"<$dir/$year/$indexfil");
@filer = grep {/^[0-9]+\./} readdir(DIR);
$rad="";
LINE: while($rad .= ) {
chomp($rad);
# Check if line is continued
if ( substr($rad,-1) eq "\\") {
substr($rad,-1)= " ";
next LINE;
}
if ($rad =~ m/$searchfor/i ) {
$antal++;
if ($antal==1) {
if($NoTable) {
YearHeaderNoTable($year);
} else {
YearHeader($year);
}
}
($nr,$namn,$titel,$publicerad)=split(/[ \t]*\t[ \t]*/,$rad,4);
$nr =~ tr/0-9//cd; # remove misc flags in $nr
if ($nr) {
$namn =~ s/\s*,\s*/
/g unless $NoTable;
$namn =~ s/^\s*(.*?)\s*$/$1/; #trim white space in names
$namn =~ s/\s+/ /g; # Use non-breaking spaces in names
# Check for avilable files (in any format)
$new=0;
foreach $fil (grep {/^$nr\..+/} @filer){
$fil =~ m/^[0-9]+\.(.*)/;
$format=$formatnamn{$1} or $format=$1;
$new++ if((-M "$dir/$year/$fil") <14);
push(@link, "$format");
}
push(@link,qq!
!) if($new);
if($NoTable) {
print qq![$year:$nr] !;
print qq!$namn, !;
print qq!$titel!;
print qq!,
$publicerad! if $publicerad;
print " ",join(', ',@link),"";
} else {
print qq!
!;
print join(' ',@link)." | ";
print qq!$year:$nr | \n!;
print qq!$namn | \n!;
print qq!$titel!;
print qq!
$publicerad! if $publicerad;
print qq! |
\n!;
}
}
}
$rad=""; undef @link; # Clear som variables;
}
}
print "
";
}
&PrintTemplateEnd;
}
sub YearHeader {
print qq!@_ |
\n
Format | No | Author(s) | Titl
e |
!;
}
sub YearHeaderNoTable {
print qq!@_
\n!;
}
sub PrintTemplateTop {
print &PrintHeader;
print <
Mathematics: Preprints
EOT
}
sub PrintTemplateEnd {
print qq%
Script last modified 2007-05-04 09.04 by
Patrick Forsberg
%;
}