diff options
Diffstat (limited to 'Master/texmf-dist/scripts/crossrefware/bibzbladd.pl')
-rwxr-xr-x | Master/texmf-dist/scripts/crossrefware/bibzbladd.pl | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl b/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl index f348cd4b946..b946766fdf9 100755 --- a/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl +++ b/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl @@ -8,12 +8,23 @@ bibzbladd.pl - add Zbl numbers to papers in a given bib file =head1 SYNOPSIS -bibzbladd [B<-f>] [B<-o> I<output>] I<bib_file> +bibzbladd [-d] [B<-f>] [B<-e> 1|0] [B<-o> I<output>] I<bib_file> =head1 OPTIONS =over 4 +=item B<-d> + +Debug mode + +=item B<-e> + +If 1 (default), add an empty zblnumber if a zbl cannot be found. This +prevents repeated searches for the same entries if you add new entries +to the file. Calling C<-e 0> suppresses this behavior. + + =item B<-f> Force searching for Zbl numbers even if the entry already has one. @@ -41,7 +52,7 @@ Boris Veytsman =head1 COPYRIGHT AND LICENSE -Copyright (C) 2014-2016 Boris Veytsman +Copyright (C) 2014-2017 Boris Veytsman This is free software. You may redistribute copies of it under the terms of the GNU General Public License @@ -63,10 +74,11 @@ use BibTeX::Parser; use Getopt::Std; use URI::Escape; use LWP::UserAgent; +$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; -my $USAGE="USAGE: $0 [-f] [-o output] file\n"; +my $USAGE="USAGE: $0 [-d] [-e 1|0] [-f] [-o output] file\n"; my $VERSION = <<END; -bibzbladd v2.0 +bibzbladd v2.1 This is free software. You may redistribute copies of it under the terms of the GNU General Public License http://www.gnu.org/licenses/gpl.html. There is NO WARRANTY, to the @@ -74,7 +86,7 @@ extent permitted by law. $USAGE END my %opts; -getopts('fo:hV',\%opts) or die $USAGE; +getopts('de:fo:hV',\%opts) or die $USAGE; if ($opts{h} || $opts{V}){ print $VERSION; @@ -97,6 +109,13 @@ if ($opts{o}) { my $forceSearch=$opts{f}; +my $forceEmpty = 1; +if (exists $opts{e}) { + $forceEmpty = $opts{e}; +} + +my $debug = $opts{d}; + my $input= IO::File->new($inputfile) or die "Cannot find BibTeX file $inputfile\n$USAGE\n"; my $output = IO::File->new("> $outputfile") or @@ -118,19 +137,24 @@ while (my $entry = $parser->next ) { print STDERR "Skipping this entry\n"; next; } - if (!($entry->type() eq 'ARTICLE')) { - print $output $entry->raw_bibtex(), "\n\n"; - next; - } if ($entry->has('zblnumber') && !$forceSearch) { print $output $entry->raw_bibtex(), "\n\n"; + if ($debug) { + print STDERR "DEBUG: entry ", $entry->key(), + " has zblnumber ", $entry->field('zblnumber'), + " and no forced search is requested\n"; + } next; } # Now we have an entry with no Zbl. Let us get to work. + if ($debug) { + print STDERR "DEBUG: Searching for zbl number for entry ", + $entry->key, "\n"; + } my $zbl = GetZbl($entry, $userAgent, $mirror); - if (length($zbl)) { + if (length($zbl) || $forceEmpty) { $entry->field('zblnumber',$zbl); } print $output $entry->to_string(), "\n\n"; @@ -154,12 +178,26 @@ sub GetZbl { my $string=uri_escape_utf8($entry->to_string()); + if ($debug) { + print STDERR "DEBUG: query: $mirror?bibtex=$string\n" ; + } my $response = $userAgent->get("$mirror?bibtex=$string"); + if ($debug) { + print STDERR "DEBUG: response: ", + $response->decoded_content, "\n"; + } + if ($response->decoded_content =~ /^\s*"zbl_id":\s*"(.*)",\s*$/m) { + if ($debug) { + print STDERR "DEBUG: got zbl: $1\n", + } return $1; } else { + if ($debug) { + print STDERR "DEBUG: Did not get zbl\n", + } return (""); } |