Skip to content

Commit

Permalink
synchronized texlive 69407.
Browse files Browse the repository at this point in the history
  • Loading branch information
clerkma committed Jan 13, 2024
1 parent 207e068 commit 70e85cf
Showing 1 changed file with 60 additions and 38 deletions.
98 changes: 60 additions & 38 deletions texlive/texk/texlive/linked_scripts/bibcop/bibcop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# 2024-01-11 0.0.16
# 2024-01-12 0.0.17
package bibcop;

use warnings;
use strict;
use File::Basename;

# Hash of incoming command line arguments.
my %args = map { $_ => 1 } @ARGV;
Expand Down Expand Up @@ -301,7 +302,7 @@ sub check_typography {
}
}
foreach my $s (@space_before) {
if ($value =~ /^.*[^\{\s]\Q$s\E.*$/) {
if ($value =~ /^.*[^\{\s\\]\Q$s\E.*$/) {
return "In the '$tag', put a space before the $symbols{$s}"
}
}
Expand Down Expand Up @@ -513,6 +514,52 @@ sub process_entry {
return @errors;
}

# Fix one entry.
sub entry_fix {
my (%entry) = @_;
if (not exists $entry{':type'}) {
error("I don't know what to do with an entry without a type");
}
my $type = $entry{':type'};
if (not exists $blessed{$type}) {
error("I don't know what to do with \@$type type of BibTeX entry");
}
if (not exists $entry{':name'}) {
error("I don't know what to do with an entry without a name");
}
my $tags = $blessed{$type};
my %allowed = map { $_ => 1 } @$tags;
my @lines;
foreach my $tag (keys %entry) {
if ($tag =~ /^:/) {
next;
}
if (not exists $allowed{$tag} and not exists $allowed{$tag . '?'}) {
next;
}
my $value = clean_tex($entry{$tag});
my $fixer = "fix_$tag";
my $fixed = $value;
if (defined &{$fixer}) {
no strict 'refs';
$value = $fixer->($value);
}
if ($tag =~ /title|booktitle|journal/) {
$value = '{' . $value . '}';
}
if (not $value eq '') {
push(@lines, " $tag = {$value},");
}
}
my $fixed = "\@$type\{$entry{':name'},\n";
my @sorted = sort @lines;
foreach my $line (@sorted) {
$fixed = $fixed . $line . "\n";
}
$fixed = $fixed . "}\n\n";
return $fixed;
}

sub fix_author {
my ($value) = @_;
my @authors = split(/\s+and\s+/, $value);
Expand Down Expand Up @@ -566,10 +613,15 @@ sub fix_pages {
if ($value =~ /^[1-9][0-9]*$/) {
return $value;
}
if ($value eq '') {
return $value;
}
my ($left, $right) = split(/---|--|-|–|—|\s/, $value);
$left //= $right;
if ($left eq '') {
$left = $right;
}
$right //= $left;
if ($right eq '') {
$right = $left;
}
Expand Down Expand Up @@ -841,6 +893,10 @@ sub fail {
}
}

if (not basename($0) eq 'bibcop.pl') {
return 1;
}

if (@ARGV+0 eq 0 or exists $args{'--help'} or exists $args{'-?'}) {
info("Bibcop is a Style Checker of BibTeX Files\n\n" .
"Usage:\n" .
Expand All @@ -861,7 +917,7 @@ sub fail {
" --latex Report errors in LaTeX format using \\PackageWarningNoLine command\n\n" .
"If any issues, report to GitHub: https://github.com/yegor256/bibcop");
} elsif (exists $args{'--version'} or exists $args{'-v'}) {
info('0.0.16 2024-01-11');
info('0.0.17 2024-01-12');
} else {
my ($file) = grep { not($_ =~ /^-.*$/) } @ARGV;
if (not $file) {
Expand All @@ -874,41 +930,7 @@ sub fail {
my $fixed = '';
for my $i (0..(@entries+0 - 1)) {
my %entry = %{ $entries[$i] };
my $type = $entry{':type'};
if (not exists $blessed{$type}) {
error("I don't know what to do with \@$type type of BibTeX entry");
}
if (not exists $entry{':name'}) {
error("I don't know what to do with an entry without a name");
}
my $tags = $blessed{$entry{':type'}};
my %allowed = map { $_ => 1 } @$tags;
my @lines;
foreach my $tag (keys %entry) {
if ($tag =~ /^:/) {
next;
}
if (not exists $allowed{$tag} and not exists $allowed{$tag . '?'}) {
next;
}
my $value = clean_tex($entry{$tag});
my $fixer = "fix_$tag";
my $fixed = $value;
if (defined &{$fixer}) {
no strict 'refs';
$value = $fixer->($value);
}
if ($tag =~ /title|booktitle|journal/) {
$value = '{' . $value . '}';
}
push(@lines, " $tag = {$value},");
}
$fixed = $fixed . "\@$type\{$entry{':name'},\n";
my @sorted = sort @lines;
foreach my $line (@sorted) {
$fixed = $fixed . $line . "\n";
}
$fixed = $fixed . "}\n\n";
$fixed = $fixed . entry_fix(%entry);
}
if (exists $args{'-i'} or exists $args{'--in-place'}) {
open(my $out, '>', $file) or error('Cannot open file for writing: ' . $file);
Expand Down

0 comments on commit 70e85cf

Please sign in to comment.