texlive[69395] trunk: bibcop (12jan24)

commits+karl at tug.org commits+karl at tug.org
Fri Jan 12 22:42:39 CET 2024


Revision: 69395
          https://tug.org/svn/texlive?view=revision&revision=69395
Author:   karl
Date:     2024-01-12 22:42:38 +0100 (Fri, 12 Jan 2024)
Log Message:
-----------
bibcop (12jan24)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/bibcop/bibcop.pl
    trunk/Master/texmf-dist/doc/bibtex/bibcop/bibcop.pdf
    trunk/Master/texmf-dist/doc/man/man1/bibcop.1
    trunk/Master/texmf-dist/doc/man/man1/bibcop.man1.pdf
    trunk/Master/texmf-dist/scripts/bibcop/bibcop.pl
    trunk/Master/texmf-dist/source/bibtex/bibcop/bibcop.dtx
    trunk/Master/texmf-dist/tex/latex/bibcop/bibcop.sty

Modified: trunk/Build/source/texk/texlive/linked_scripts/bibcop/bibcop.pl
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/bibcop/bibcop.pl	2024-01-12 00:44:04 UTC (rev 69394)
+++ trunk/Build/source/texk/texlive/linked_scripts/bibcop/bibcop.pl	2024-01-12 21:42:38 UTC (rev 69395)
@@ -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;
@@ -301,7 +302,7 @@
       }
     }
     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}"
       }
     }
@@ -513,6 +514,52 @@
   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);
@@ -566,10 +613,15 @@
   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;
   }
@@ -841,6 +893,10 @@
   }
 }
 
+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" .
@@ -861,7 +917,7 @@
     "      --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) {
@@ -874,41 +930,7 @@
     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);

Modified: trunk/Master/texmf-dist/doc/bibtex/bibcop/bibcop.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/man/man1/bibcop.1
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/bibcop.1	2024-01-12 00:44:04 UTC (rev 69394)
+++ trunk/Master/texmf-dist/doc/man/man1/bibcop.1	2024-01-12 21:42:38 UTC (rev 69395)
@@ -1,4 +1,4 @@
-.TH bibcop 1 "2024-01-11"
+.TH bibcop 1 "2024-01-12"
 .SH NAME
 bibcop \- Style Checker and Fixer of BibTeX Files (.bib)
 .SH SYNOPSIS

Modified: trunk/Master/texmf-dist/doc/man/man1/bibcop.man1.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/scripts/bibcop/bibcop.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/bibcop/bibcop.pl	2024-01-12 00:44:04 UTC (rev 69394)
+++ trunk/Master/texmf-dist/scripts/bibcop/bibcop.pl	2024-01-12 21:42:38 UTC (rev 69395)
@@ -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;
@@ -301,7 +302,7 @@
       }
     }
     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}"
       }
     }
@@ -513,6 +514,52 @@
   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);
@@ -566,10 +613,15 @@
   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;
   }
@@ -841,6 +893,10 @@
   }
 }
 
+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" .
@@ -861,7 +917,7 @@
     "      --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) {
@@ -874,41 +930,7 @@
     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);

Modified: trunk/Master/texmf-dist/source/bibtex/bibcop/bibcop.dtx
===================================================================
--- trunk/Master/texmf-dist/source/bibtex/bibcop/bibcop.dtx	2024-01-12 00:44:04 UTC (rev 69394)
+++ trunk/Master/texmf-dist/source/bibtex/bibcop/bibcop.dtx	2024-01-12 21:42:38 UTC (rev 69395)
@@ -50,7 +50,7 @@
 %<package>\NeedsTeXFormat{LaTeX2e}
 %<package>\ProvidesPackage{bibcop}
 %<*package>
-[2024-01-11 0.0.16 Style Checker of Bibliography Files]
+[2024-01-12 0.0.17 Style Checker of Bibliography Files]
 %</package>
 %<*driver>
 \documentclass{ltxdoc}

Modified: trunk/Master/texmf-dist/tex/latex/bibcop/bibcop.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/bibcop/bibcop.sty	2024-01-12 00:44:04 UTC (rev 69394)
+++ trunk/Master/texmf-dist/tex/latex/bibcop/bibcop.sty	2024-01-12 21:42:38 UTC (rev 69395)
@@ -31,7 +31,7 @@
 
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{bibcop}
-[2024-01-11 0.0.16 Style Checker of Bibliography Files]
+[2024-01-12 0.0.17 Style Checker of Bibliography Files]
 
 
 



More information about the tex-live-commits mailing list.