#!/usr/bin/env perl # The MIT License (MIT) # # Copyright (c) 2011-2015 Ismaël Bouya http://www.normalesup.org/~bouya/ # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. use BibTeX::Parser; use IO::File; use utf8; use strict; use open ':utf8'; sub parse_config_file { my ($config_line, $Name, $Value, $Config); (my $File, $Config) = @_; if (!open (CONFIG, "$File")) { print "ERROR: Config file not found : $File"; exit(0); } my $multiline = 0; while () { $config_line=$_; chop ($config_line); $config_line =~ s/^\s*//; $config_line =~ s/\s*$//; if ( ($config_line !~ /^#/) && ($config_line ne "") ){ if ($multiline) { $$Config{$Name} =~ s/\\$//; $$Config{$Name} .= $config_line; } else { ($Name, $Value) = split (/\s*=\s*/, $config_line); $Value =~ s/^~/$ENV{"HOME"}/; $$Config{$Name} = $Value; } $multiline = ($$Config{$Name} =~ /\\$/); } } close(CONFIG); } my %Config; &parse_config_file ($ENV{"HOME"}."/.parse_bibtex_html.rc", \%Config); my $biblio = $Config{"biblio"}; my $entete = $Config{"entete"}; my $avant = $Config{"avant"}; my $milieu = $Config{"milieu"}; my $apres = $Config{"apres"}; my $html = $Config{"html"}; my $dossier = $Config{"dossier"}; my $dossierweb = $Config{"dossier_web"}; # http://webdesign.about.com/library/bl_htmlcodes.htm sub echap { my $t = shift or return; $t =~ s/&/&/g; $t =~ s//>/g; $t =~ s/--/—/g; $t =~ s/{?\\'a}?/á/g; $t =~ s/{?\\`a}?/à/g; $t =~ s/{?\\"a}?/ä/g; $t =~ s/{?\\r A}?/Å/g; $t =~ s/{?\\'e}?/é/g; $t =~ s/{?\\`e}?/è/g; $t =~ s/{?\\'E}?/É/g; $t =~ s/{?\\"e}?/ë/g; $t =~ s/{?\\\^i}?/î/g; $t =~ s/{?\\"i}?/ï/g; $t =~ s/{?\\"o}?/ö/g; $t =~ s/{?\\"o}?/ö/g; $t =~ s/{?\\=o}?/ō/g; $t =~ s/{?\\o}?/ø/g; $t =~ s/{?\\"u}?/ü/g; $t =~ s/{?\\'u}?/ú/g; $t =~ s/{?\\~n}?/ñ/g; $t =~ s/{?\\c{?c}?}? ?/ç/g; $t =~ s/{?\\'{?c}?}? ?/ć/g; $t =~ s/{?\\v{? ?s}?}? ?/š/g; $t =~ s/{?\^({[^}]+}|.)}?/$1<\/sup>/g; $t =~ s/{(.*)}/$1/g; return $t; } open F, ">".$milieu; opendir(DIR, $dossier); my @FILES = readdir(DIR); my $fh = IO::File->new($biblio); my $parser = BibTeX::Parser->new($fh); print F "\t"; close F; exec "cat $entete $avant $milieu $apres 1> $html" or die "$!\n";