#!/usr/local/bin/perl
sub man
{
print << ;
# -------Description--------------------------------------
#
# generate literature references list in HTML-format
# from BibTeX-format. allows you to keep an organized
# virtual bookshelf with only few additions to your
# BibTeX-references.
#
# + uses title, author and year field to display
# information from reference
# + uses nice icons :-)
# + uses comma separated entries in field 'topics'
# to categorize references
# + uses URL in field 'sourceURL' to hyperlink the
# title to the source
# + uses URL in field 'url' to hyperlink the book icon
# to a local copy (same field is used by bibsearch.pl
# and contains a full URL; bookshelf changes this to
# a relative URL, if it starts with users html-home)
# + the resulting page provides a link to the BibTeX-file
# + each entry may be linked to its BibTeX-reference
# + the script also
# + converts german special characters
# + converts occurrences of \$\\Pi\$ in titles
# + removes {}, \\em, \\bf and enclosing ""
# + topics may be grouped into hierarchies based on
# comments in the BibTex-source:
# % TOPICS
# % group1 : topic1, topic2, topic3
# % group2 : group1, topic4
# % ENDTOPICS
#
# - no real parser for BibTeX
# + multi-line fields allowed for author and title
# - important fields should be terminated by ','
# (year or topics as last field in entry will do ;-)
# - entries have to be delimited by empty lines
# +- text following empty line and not starting with
# @...{ is ignored (if e.g. an abstract field
# contains empty lines, insert spaces there)
#
}
require 'getopts.pl';
sub usage
{
print << ;
#
# bookshelf [-hmscitlobT]
#
# -------Options------------------------------------------
#
# -h : help (print this usage info)
# -m : man (print longer usage info)
# -e : edit BibTeX source file
# -s : split HTML (generate directory
# with one file per topic)
# -c : classes (rudimentary support for supercategories)
# -i : info (link each entry to its BibTeX-reference)
# -t : text (no icons, implies -l)
# -l : show only one hyperlink per reference
# (url overrules sourceURL)
# -o name: output to name.html (name/ with -s)
# -b name: input from name
# -T text: title (use text instead of Virtual Bookshelf)
#
# -------Defaults-----------------------------------------
#
# BibTeX : \$HOME/public_html/bib/bookshelf.bib
# HTML : \$HOME/public_html/bib/bookshelf.html
# topics directory (for -s): \$HOME/public_html/bib/bookshelf/
# reference-file (for -i): \$HOME/public_html/bib/bibtex.html
#
}
# -d reserved for debugging purposes
do Getopts('u:o:b:T:cistlhmkde');
if ($opt_h) { &usage(); exit; }
if ($opt_m) { &usage(); &man(); exit; }
$user = $opt_u || $ENV{'USER'};
@pwent = getpwnam($user);
die "unknown user $user" unless @pwent;
$username = $pwent[6];
$username =~ s/,.*$//; # get rid of these (where do they come from??)
$userdir = $pwent[7];
##--- variable settings ---------------------
# you will certainly need to customize here..
chop($DATE = `date`);
chop($pwd = `pwd`);
$localhome = "$userdir/webpages";
$mailbase = "ukc.ac.uk";
$wwwbase = "http://www.cs.ukc.ac.uk/people/staff/";
$webhome = "$wwwbase/$user";
# please don't rely on my icons directory ;-)
# use your own, *local* collection
$iconsdir1 = "$webhome/icons";
if ($opt_b)
{
$bibdir = $pwd;
$bibtex = $opt_b;
}
else
{
$bibdir = "$localhome/bib";
$bibtex = "bookshelf.bib";
}
if ($opt_e)
{
$EDITOR = $ENV{'EDITOR'};
if ($EDITOR =~ /%d.*%s/)
{ $EDITOR = sprintf($EDITOR,1,"$bibdir/$bibtex") }
else { $EDITOR = "$EDITOR $bibdir/$bibtex" }
exec($EDITOR);
}
if ($opt_o)
{
$shelfdir = $pwd;
$bookshelf = "$opt_o.html";
$bookdir = "$opt_o" if $opt_s;
}
else
{
$shelfdir = "$localhome/bib";
$bookdir = "bookshelf" if $opt_s;
$bookshelf = "bookshelf.html";
}
$INFO_FILE = "bibtex.html";
$shelftitle = $opt_T || "$username 's Virtual Bookshelf";
$PI = "";
$PLUS = "";
$LAMBDA = "";
$FAST = "";
$shelfpic = "";
$littleshelf = "";
$book_read = "";
$book_empty = "";
$info = "";
#$info = "";
##--- no need to customize below?? ----------
if ($opt_i)
{
chdir($shelfdir);
open(INFO,"> $INFO_FILE") || die "cannot write $INFO_FILE\n$!";
print INFO <BibTeX
HEADER
chdir($bibdir);
open(BIB,"$bibtex") || die $!;
$/='';
$*=1;
while()
{
if (/^@[^{]*{\s*([^,]*)\s*,/) { print INFO "% $1