#!/usr/bin/env perl use strict; my ($proc,$vers,$dt) = '$Id: bib2html 160145 2023-07-13 11:58:58Z vinc17/cventin $' =~ /^.Id: (\S+) (\d+) (\d{4}-\d\d-\d\d \d\d:\d\d:\d\d)Z/ or die; my %s = ( 'jan' => 'January', 'feb' => 'February', 'mar' => 'March', 'apr' => 'April', 'may' => 'May', 'jun' => 'June', 'jul' => 'July', 'aug' => 'August', 'sep' => 'September', 'oct' => 'October', 'nov' => 'November', 'dec' => 'December', 'preprint' => 'Preprint', 'submitted' => 'Submitted', 'toappear' => 'To appear', 'rr' => 'Research report', 'tr' => 'Technical report', 'abstract' => 'Abstract only', ); my $date = "{,\n{*month }*year}"; my $amy = "{,\n*address}$date"; my $vol = "{,\nvolume *volume}"; my $pages = "{,\npage *page}{,\npages *pages}"; my $edbt = "In {*editor, editor,\n}*booktitle$vol$pages"; my %format = ( 'article' => "*journal{,\n{*volume}{(*number)}{:*pages}}$date.", 'book' => "*publisher$amy.", 'incollection' => "$edbt.\n*publisher$amy.", 'inproceedings' => "$edbt$amy.{\n*publisher.}", 'misc' => "{*type,\n}{*month }*year.", 'phdthesis' => "PhD thesis{,\n*school}$amy.", 'techreport' => "*type *number{,\n*institution}$amy.", ); $format{unpublished} = $format{misc}; my $hal= 'HAL'; my (%a,$acronyms,%acr); # Note: use the html root element instead of dl, though dl should have # been sufficient. This is necessary in order to use the xhtml namespace, # as only the html element may have an xmlns attribute (the XHTML DTD is # designed very poorly IMHO). print < V. Lefèvre's Publications
EOF while (<>) { if (/^%a\{(.+)}\s*=\s*(\S+)\s*$/) { $a{$1} = $2; next; } if (/^%acronym\{([A-Z]+)}\s*=\s*"(.+)"\s*$/) { $acr{$1} = $2; $acronyms = join '|', keys %acr; next; } if (/^(.Id:.*)/) { print "\n"; next; } my ($type,$key) = /^@(\w+)\{(\w+),\s*$/ or next; print "
[$key]
\n"; my %entry = %{&getentry($type)}; if ($entry{'type'} eq '' && $entry{'note'} =~ /^preprint$/i) { $entry{'type'} = 'Preprint'; delete $entry{'note'}; } print "
\n"; my @authors; foreach (split /\s+and\s+/, $entry{'author'}) { my $url = $a{$_}; s/\. /. /g; push @authors, defined $url ? "$_" : "$_"; } @authors and print "", @authors > 1 ? join("\nand\n", join(",\n", @authors[0..$#authors-1]), $authors[$#authors]) : $authors[0], ".\n"; $_ = $entry{'title'}; defined $_ and print defined $entry{'url'} ? "$_.\n" : "$_.\n"; my $format = $format{$entry{'A'}}; defined $format or die "$proc: unknown type $entry{A}\n"; my $c = 0; my (@f,@s); while ($format ne '') { if ($format =~ s/^\{//s) { $c++; $f[$c] = 0; $s[$c] = ''; next; } if ($format =~ s/^\}//s) { $f[$c--] and $s[$c] .= $s[$c+1], $f[$c]++; next; } if ($format =~ s/^\*([a-z]+)//s) { my $type = $1; $_ = $entry{$type}; if (defined $_) { my $e = $type =~ /title|journal/ ? 'cite' : 'span'; $f[$c]++; $s[$c] .= "<$e class=\"$type\">$_"; } else { $c or die "$proc: undefined entry $1"; } next; } $format =~ s/^(.)//s or die "$proc: internal error"; $s[$c] .= $1; } $entry{'editor'} =~ / and / and $s[0] =~ s/(, editor),/$1s,/; print "$s[0]\n"; $_ = $entry{'note'}; if (defined $_) { s!''(.*?)''!$1!g; substr($_,-1) eq '.' or $_ .= '.'; print "$_\n"; } # [DOI] Use https://doi.org, but still support dx.doi.org in input # as https://www.doi.org/doi_handbook/3_Resolution.html#3.7.3 says: # "https://doi.org is preferred, but the earlier syntax dx.doi.org # remains fully supported". my $doi = $entry{'doi'}; defined $doi and print < DOI: $doi EOF my $altlinks; $altlinks .= "[$hal-Inria". " / $hal]\n" if defined $entry{'hal_id'}; foreach (split / +/, $entry{'other-url'}) { $altlinks .= &altlink($_) unless defined $doi and m!^https?://(dx\.)?\Qdoi.org/$doi\E$!; } $altlinks .= &altlink($entry{'abstract-url'}, 'abstract'); $altlinks .= &altlink($entry{'ri-url'}, 'citeseer'); my $nlinks = $altlinks =~ tr/[//; $nlinks and print "
\nAlternative link", ($nlinks > 1 ? 's' : ''), ":\n$altlinks"; print "
\n\n"; } print < EOF sub getentry { my $entry = { 'A' => lc($_[0]) }; my $n = 1; while (<>) { /^\s*\}\s*$/ and return $entry; $n or die "$proc: missing comma\n"; /^\s*([-\w]+)\s*=\s*(\S.*?)(,?)\s*$/ or next; my ($k,$v) = (lc($1),$2); $n = $3; $k eq 'page' and die "$proc: invalid key 'page'"; $k eq 'pages' && $v =~ /^.\s*\d+\s*.$/ and $k = 'page'; if ($v !~ s/^\{(.*)\}$/$1/ && $v !~ s/^"(.*)"$/$1/) { defined $s{$v} or die "$proc: $v undefined"; $v = $s{$v}; } $v =~ s/---/—/g; $v =~ s/--/–/g; $v =~ s!\{($acronyms)\}!{$1}!g; $k eq 'title' and substr($v, substr($v,0,1) ne '{') =~ s/(\{.*?\}|\$.*?\$|.)/lcfirst($1)/eg; $v =~ s!\\emph\{(.*?)\}!$1!g; $v =~ s!\\mathbb\{(.*?)\}!$1!g; $v =~ s!\\texttt\{(.*?)\}!$1!g; $v =~ s!\^(\{.*?\}|.)!$1!g; $v =~ s!~! !g; $v =~ tr/{}$//d; $entry->{$k} = $v; } die "$proc: unexpected EOF"; } sub altlink { my ($url,$txt) = @_; return if $url eq ''; if ($txt eq '') { $url =~ /\.pdf$/i and $txt = 'PDF'; $url =~ /\.ps(\.|$)/i and $txt = 'postscript'; index($url,'http://doi.ieeecomputersociety.org/') == 0 and $txt = 'IEEE Computer Society'; index($url,'http://www.springerlink.com/content/') == 0 and $txt = 'online version'; $txt eq '' and die "$proc: unknown link type for URL $url\n"; } return <$txt] EOF }