-
Notifications
You must be signed in to change notification settings - Fork 36
/
biber
executable file
·598 lines (448 loc) · 17.9 KB
/
biber
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#!/usr/bin/perl
use 5.014000;
use strict;
use warnings;
use constant {
EXIT_OK => 0,
EXIT_ERROR => 2
};
use Carp;
use IPC::Cmd qw( can_run run );
use Log::Log4perl qw(:no_extra_logdie_message);
use Log::Log4perl::Level;
use POSIX qw(strftime);
use Biber;
use Biber::Utils;
use File::Spec;
use Pod::Usage;
use List::AllUtils qw( first );
use Getopt::Long qw/:config no_ignore_case/;
my $opts = {};
GetOptions(
$opts,
'bibencoding=s', # legacy alias for input_encoding
'bblencoding=s', # legacy alias for output_encoding
'bblsafechars', # legacy alias for output_safechars
'bblsafecharsset=s', # legacy alias for output_safecharsset
'cache',
'collate|C',
'collate_options|c=s',
'configfile|g=s',
'convert_control',
'dot_include:s@',
'decodecharsset=s',
'debug|D',
'fastsort|f',
'fixinits',
'help|h|?',
'input_encoding|e=s',
'listsep=s',
'mincrossrefs|m=s',
'logfile=s',
'namesep=s',
'noconf',
'nodieonerror',
'nolog',
'nostdmacros',
'onlylog',
'others_string=s',
'outfile=s', # legacy alias for output_file
'outformat=s', # legacy alias for output_format
'output_directory=s',
'output_encoding|E=s',
'output_file|O=s',
'output_format=s',
'output_safechars',
'output_safecharsset=s',
'quiet|q+',
'recodedata=s',
'sortcase=s',
'sortfirstinits=s',
'sortlocale|l=s',
'sortupper=s',
'ssl-nointernalca',
'ssl-noverify-host',
'tool',
'tool_datatype=s',
'trace|T',
'u', # alias for input_encoding=UTF-8
'U', # alias for output_encoding=UTF-8
'validate_config',
'validate_control',
'validate_datamodel|V',
'version|v',
'wraplines|w'
) or pod2usage(-verbose => 0,
-exitval => EXIT_ERROR);
# verbose > 1 uses external perldoc, this doesn't work with PAR::Packer binaries
# so use "-noperldoc" to use built-in POD::Text
if (exists $opts->{'help'}) {
pod2usage(-verbose => 2, -noperldoc => 1, -exitval => EXIT_OK);
}
if (exists $opts->{'version'}) {
my $v = "biber version: $Biber::Config::VERSION";
$v .= ' (beta)' if $Biber::Config::BETA_VERSION;
say "$v";
exit EXIT_OK;
}
if (exists $opts->{'cache'}) {
if (my $cache = $ENV{PAR_TEMP}) {
$cache =~ s|//|/|og; # Sanitise path in case it worries people
say $cache;
}
else {
say "No cache - you are not running the PAR::Packer executable version of biber";
}
exit EXIT_OK;
}
# Catch this situation early
unless (@ARGV) {
pod2usage(-verbose => 0,
-exitval => EXIT_ERROR);
}
# Sanitise collate option if fastsort is specified
if ($opts->{fastsort}) {
delete $opts->{collate};
}
# Resolve some option shortcuts and legacyaliases
if (my $o = $opts->{bibencoding}) {
$opts->{input_encoding} = $o;
delete $opts->{bibencoding};
}
if (my $o = $opts->{bblencoding}) {
$opts->{output_encoding} = $o;
delete $opts->{bblencoding};
}
if (my $o = $opts->{bblsafechars}) {
$opts->{output_safechars} = $o;
delete $opts->{bblsafechars};
}
if (my $o = $opts->{bblsafecharsset}) {
$opts->{output_safecharsset} = $o;
delete $opts->{bblsafecharsset};
}
if (my $o = $opts->{outfile}) {
$opts->{output_file} = $o;
delete $opts->{outfile};
}
if (my $o = $opts->{outformat}) {
$opts->{output_format} = $o;
delete $opts->{outformat};
}
if ($opts->{u}) {
$opts->{input_encoding} = 'UTF-8';
delete $opts->{u};
}
if ($opts->{U}) {
$opts->{output_encoding} = 'UTF-8';
delete $opts->{U};
}
# Check the outformat option
if (my $of = $opts->{output_format}) {
unless ($opts->{output_format} =~ /\A(?:bbl|dot)\z/xms) {
say STDERR "Biber: Unknown output format '$of', must be one of 'bbl', 'dot'";
exit EXIT_ERROR;
}
}
# Check the dot_include option
if (exists($opts->{dot_include}) and (not exists($opts->{output_format})
or (exists($opts->{output_format}) and
$opts->{output_format} ne 'dot'))) {
say STDERR "Biber: DOT output format specified but output format is not DOT!";
exit EXIT_ERROR;
}
if (exists($opts->{dot_include})) {
$opts->{dot_include} = {map {lc($_) => 1} split(/,/,join(',',@{$opts->{dot_include}}))};
my @suboptions = ( 'section', 'field', 'crossref', 'xref', 'xdata', 'related' );
foreach my $g (keys %{$opts->{dot_include}}) {
unless (first {$_ eq lc($g)} @suboptions) {
say STDERR "Biber: '$g' is an invalid output type for DOT output";
exit EXIT_ERROR;
}
}
}
# Create Biber object, passing command-line options
my $biber = Biber->new(%$opts);
# get the logger object
my $logger = Log::Log4perl::get_logger('main');
my $screen = Log::Log4perl::get_logger('screen');
my $logfile = Log::Log4perl::get_logger('logfile');
my $outfile;
my $time_string = strftime "%a %b %e, %Y, %H:%M:%S", localtime;
$logfile->info("=== $time_string");
my $bcf = Biber::Config->getoption('bcf');
if (Biber::Config->getoption('output_file')) {
$outfile = Biber::Config->getoption('output_file')
}
else {
if (Biber::Config->getoption('output_format') eq 'dot') { # .dot output
$outfile = $bcf =~ s/bcf$/dot/r;
}
elsif (Biber::Config->getoption('tool')) {
if (Biber::Config->getoption('tool_datatype') eq 'bibtex') { # tool .bib output
$outfile = $ARGV[0] =~ s/.bib$/_bibertool.bib/r;
}
}
else { # .bbl output
$outfile = $bcf =~ s/bcf$/bbl/r;
}
}
# Set the .bbl path to the output dir, if specified
if (my $outdir = Biber::Config->getoption('output_directory')) {
my (undef, undef, $file) = File::Spec->splitpath($outfile);
$outfile = File::Spec->catfile($outdir, $file)
}
# Fake some necessary .bcf parts if in tool mode
if (Biber::Config->getoption('tool')) {
$biber->tool_mode_setup;
}
else {
# parse the .bcf control file
$biber->parse_ctrlfile($bcf);
}
# Postprocess biber options now that they are all read from the various places
Biber::Config->postprocess_biber_opts;
# Check to see if the .bcf set debug=1. If so, increase logging level
# We couldn't set this on logger init as the .bcf hadn't been read then
if (Biber::Config->getoption('debug')) {
$logger->level($DEBUG);
}
if (Biber::Config->getoption('trace')) {
$logger->trace("\n###########################################################\n",
"############# Dump of initial config object: ##############\n",
Data::Dump::pp($Biber::Config::CONFIG), "\n",
"############# Dump of initial biber object: ###############\n",
$biber->_stringdump,
"\n###########################################################")
}
# Set the output class. Should be a subclass of Biber::Output::Base
if (Biber::Config->getoption('output_format') eq 'dot') { # .dot output
require Biber::Output::dot;
$biber->set_output_obj(Biber::Output::dot->new());
}
elsif (Biber::Config->getoption('tool')) {
require Biber::Output::tool;
$biber->set_output_obj(Biber::Output::tool->new());
}
else { # .bbl output
require Biber::Output::bbl;
$biber->set_output_obj(Biber::Output::bbl->new());
}
# Do all the real work
$biber->prepare;
if (Biber::Config->getoption('trace')) {
$logger->trace("\n###########################################################\n",
"############# Dump of final config object: ################\n",
Data::Dump::pp($Biber::Config::CONFIG), "\n",
"############# Dump of final biber object: #################\n",
$biber->_stringdump,
"\n###########################################################")
}
# Get reference to output object
my $biberoutput = $biber->get_output_obj;
# Set the output target
$biberoutput->set_output_target_file($outfile);
# Write the output to the target
$biberoutput->output;
$biber->display_problems;
exit EXIT_OK;
__END__
=pod
=encoding utf8
=head1 NAME
C<biber> - A bibtex replacement for users of biblatex
=head1 SYNOPSIS
biber [options] file[.bcf]
Creates "file.bbl" using control file "file.bcf" (".bcf" extension is
optional). Normaly use with biblatex requires no options as they are
all set in biblatex and passed via the ".bcf" file
Please run "biber --help" for option details
=head1 DESCRIPTION
C<biber> provides a replacement of the bibtex processor for users of biblatex.
=head1 OPTIONS
=over 4
=item B<--cache>
If running as a PAR::Packer binary, show the cache location and exit.
=item B<--collate|-C>
Sort with C<Unicode::Collate> instead of the built-in sort function.
This is the default.
=item B<--collate_options|-c [options]>
Options to pass to the C<Unicode::Collate> object used for sorting
(default is 'level => "4", variable => "non-ignorable"').
See C<perldoc Unicode::Collate> for details.
=item B<--configfile|-g [file]>
Use F<file> as configuration file for C<biber>.
The default is the first file found among
F<biber.conf> in the current directory, C<$HOME/.biber.conf>,
or else the output of C<kpsewhich biber.conf>.
=item B<--convert_control>
Converts the F<.bcf> control file into html using an XSLT transform. Can
be useful for debugging. File is named by appending C<.html>
to F<.bcf> file.
=item B<--decodecharsset=[recode set name]>
The set of characters included in the conversion routine when decoding
LaTeX macros into UTF-8 (which happens when B<--bblencoding|-E> is set to
UTF-8). Set to "full" to try harder with a much larger set or "base" to
use a smaller basic set. Default is "base". You may want to try "full"
if you have less common UTF-8 characters in your data source. The recode
sets are defined in the reencoding data file which can be customised.
See the --recodedata option and the PDF manual.
=item B<--debug|-D>
Turn on debugging for C<biber>.
=item B<--dot_include=section,field,xdata,crossref,xref,related>
Specifies the element to include in GraphViz DOT output format if the output format is 'dot'.
You can also choose to display crossref, xref, xdata and/or related entry connections.
The default if not specified is C<--dot_include=section,xdata,crossref,xref>.
=item B<--fastsort|-f>
Use Perl's sort instead of C<Unicode::Collate> for sorting. Also uses
OS locale definitions (which may be broken for some languages ...).
=item B<--fixinits>
Try to fix broken multiple initials when they have no space between them in BibTeX
data sources. That is, "A.B. Clarke" becomes "A. B. Clarke" before name parsing.
This can slightly mess up things like "{U.K. Government}" and other esoteric cases.
=item B<--help|-h>
Show this help message.
=item B<--input_encoding|-e [encoding]>
Specify the encoding of the data source file(s). Default is "UTF-8"
Normally it's not necessary to set this as it's passed via the
.bcf file from biblatex's setting of the same name.
See "perldoc Encode::Supported" for a list of supported encodings.
The legacy option B<--bibencoding> is supported as an alias.
=item B<--logfile [file]>
Use F<file.blg> as the name of the logfile.
=item B<--listsep=[sep]>
Use F<sep> as the separator for BibTeX data source list fields. Defaults to BibTeX's usual
'and'.
=item B<--mincrossrefs|-m [number]>
Set threshold for crossrefs.
=item B<--namesep=[sep]>
Use F<sep> as the separator for BibTeX data source name fields. Defaults to BibTeX's usual
'and'.
=item B<--noconf>
Don't look for a configfile.
=item B<--nodieonerror>
Don't exit on errors, just log and continue as far as possible.
This can be useful if the error is something from, for example, the underlying
BibTeX parsing C library which can complain about parsing errors which can be ignored.
=item B<--nolog>
Do not write any logfile.
=item B<--nostdmacros>
Don't automatically define any standard macros like month abbreviations.
If you also define these yourself, this option can be used to suppress
macro redefinition warnings.
=item B<--onlylog>
Do not write any message to screen.
=item B<--others_string=[string]>
Use F<string> as the final name in a name field which implies "et al". Defaults to BibTeX's usual
'others'.
=item B<--output_file|-O [file]>
Output to F<file> instead of F<basename.bbl>
F<file> is relative to B<--output_directory>, if set (absolute
paths in this case are stripped to filename only). F<file> can
be absolute if B<--output_directory> is not set.
The legacy option B<--outfile> is supported as an alias.
=item B<--output_format=bbl|dot>
Biber output format. Default if not specified is of course, F<bbl>. Use F<dot>
to output a GraphViz DOT file instead of F<.bbl>. This is a directed graph of
the bibliography data showing entries and, as requested, sections and fields.
You must process this file with C<dot>, e.g. C<dot -Tsvg test.dot -o test.svg> to
render the graph. See the B<--dot_include> option to select what is included in
the DOT output.
The legacy option B<--outformat> is supported as an alias.
=item B<--output_directory [directory]>
Files (F<.bbl> and F<.blg>) are output to directory F<directory> instead
of the current directory. Input files are also looked for in F<directory>
before current directory.
=item B<--output_encoding|-E [encoding]>
Specify the encoding of the output C<.bbl> file. Default is "UTF-8".
Normally it's not necessary to set this as it's passed via biblatex
from the inputenc package setting.
See C<perldoc Encode::Supported> for a list of supported encodings.
The legacy option B<--bblencoding> is supported as an alias.
=item B<--output_safechars>
Try to convert UTF-8 chars into LaTeX macros when writing the output.
This can prevent unknown char errors when using PDFLaTeX and inputenc
as this doesn't understand all of UTF-8. Note, it is better to switch
to XeTeX or LuaTeX to avoid this situation. By default uses the
--output_safecharsset "base" set of characters.
The legacy option B<--bblsafechars> is supported as an alias.
=item B<--output_safecharsset=[recode set name]>
The set of characters included in the conversion routine for
--output_safechars. Set to "full" to try harder with a much
larger set or "base" to use a basic set. Default is "base" which is
fine for most use cases. You may need to load more macro packages to
deal with the results of "full" (Dings, Greek characters, special
symbols etc.). The recode sets are defined in the reencoding data file which
can be customised. See the --recodedata option and the PDF manual.
The legacy option B<--bblsafecharsset> is supported as an alias.
=item B<--quiet|-q>
Log only errors. If this option is used more than once, don't even log errors.
=item B<--recodedata=[file]>
The data file to use for the reencoding between UTF-8 and LaTeX macros. It defines
the sets specified with the --bblsafecharsset and --decodecharsset options.
It defaults to F<recode_data.xml> in the same directory as Biber's F<Recode.pm> module.
See the PDF documentation for the format of this file. If this option is
used, then F<file> should be somewhere C<kpsewhich> can find it.
=item B<--sortcase=true|false>
Case-sensitive sorting (default is true).
=item B<--sortfirstinits=true|false>
When sorting names, use only the first name initials, not full first name. Some people expect
the biblatex B<firstinits> option to do this but it needs to be a separate option in case
users, for example, need to show only initials but sort with full first names (default is false).
=item B<--sortlocale|-l [locale]>
Set the locale to be used for sorting. With default sorting
(B<--collate|-C>), the locale is used to add CLDR
tailoring to the sort (if available for the locale). With
B<--fastsort|-f> this sets the OS locale for sorting.
=item B<--sortupper=true|false>
Whether to sort uppercase before lowercase when using
default sorting (B<--collate|-C>). When
using B<--fastsort|-f>, your OS collation locale determines
this and this option is ignored (default is true).
=item B<--ssl-nointernalca>
Don't try to use the default Mozilla CA certificates when using HTTPS to fetch remote data.
This assumes that the user will set one of the perl LWP::UserAgent module environment variables
to find the CA certs.
=item B<--ssl-noverify-host>
Turn off host verification when using HTTPS to fetch remote data sources.
You may need this if the SSL certificate is self-signed for example.
=item B<--tool>
Run in tool mode. In this mode, biber takes a config file and a data source, applies the source
mapping steps in the config file to the data source and writes a new datasource. Essentially,
this allows you to change your data sources using biber's mapping semantics.
=item B<--tool_datatype=[datatype]>
Datatype of the data file to be processes in tool mode. Defaults to C<bibtex>.
=item B<--trace|T>
Turn on tracing. Also turns on B<--debug|d> and additionally provides a lot of low-level tracing
information in the log.
=item B<-u>
Alias for B<--input_encoding=UTF-8>
=item B<-U>
Alias for B<--output_encoding=UTF-8>
=item B<--validate_config>
Schema validate the biber config file.
=item B<--validate_control>
Schema validate the F<.bcf> biblatex control file.
=item B<--validate_datamodel|-V>
Validate the data against a data model.
=item B<--version|-v>
Display version number.
=item B<--wraplines|-w>
Wrap lines in the F<.bbl> file.
=back
=head1 AUTHOR
François Charette, C<firmicus at ankabut.net>E<10>
Philip Kime, C<Philip at kime.org.uk>
=head1 BUGS & DOCUMENTATION
To see the full documentation, run B<texdoc biber> or get the F<biber.pdf>
manual from SourceForge.
Please report any bugs or feature requests on our sourceforge tracker at
L<https://sourceforge.net/tracker2/?func=browse&group_id=228270>.
=head1 COPYRIGHT & LICENSE
Copyright 2009-2013 François Charette and Philip Kime, all rights reserved.
This module is free software. You can redistribute it and/or
modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.
=cut