summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-12-13 21:08:43 +0000
committerKarl Berry <karl@freefriends.org>2022-12-13 21:08:43 +0000
commit76fbbeea8ed397248b62a749f2d8a22ea8aad062 (patch)
tree4b76501c0e09ea652abfbe80869e8d2d1f5c5f0c /Master/texmf-dist/scripts
parent37acdfb25ae9a280366c6ee994127edc42badf9b (diff)
bibcop (13dec22)
git-svn-id: svn://tug.org/texlive/trunk@65265 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-xMaster/texmf-dist/scripts/bibcop/bibcop.pl74
1 files changed, 44 insertions, 30 deletions
diff --git a/Master/texmf-dist/scripts/bibcop/bibcop.pl b/Master/texmf-dist/scripts/bibcop/bibcop.pl
index 3fa1444b92c..8b900bbc35e 100755
--- a/Master/texmf-dist/scripts/bibcop/bibcop.pl
+++ b/Master/texmf-dist/scripts/bibcop/bibcop.pl
@@ -26,6 +26,9 @@ package bibcop;
use warnings;
use strict;
+# Hash of incoming command line arguments.
+my %args = map { $_ => 1 } @ARGV;
+
# If you want to add an extra check, just create a new procedure
# named as "check_*".
@@ -237,6 +240,17 @@ sub check_volume {
}
}
+# Check the right format of the 'number.'
+sub check_number {
+ my (%item) = @_;
+ if (exists $item{'number'}) {
+ my $number = $item{'number'};
+ if (not $item{'number'} =~ /^[1-9][0-9]*$/) {
+ return "The format of the 'number' is wrong"
+ }
+ }
+}
+
# Check the right format of the 'pages.'
sub check_pages {
my (%item) = @_;
@@ -387,8 +401,9 @@ sub only_words {
sub clean_tex {
my ($tex) = @_;
$tex =~ s/\s+/ /g;
- $tex =~ s/^\{+//g;
- $tex =~ s/\}+$//g;
+ $tex =~ s/^\s+//g;
+ $tex =~ s/\s+$//g;
+ while ($tex =~ s/^\{(.+)\}$/$1/g) {};
return $tex;
}
@@ -406,7 +421,32 @@ sub listed_keys {
return '(' . join(', ', @sorted) . ')';
}
-my %args = map { $_ => 1 } @ARGV;
+# Print ERROR message to the console and die.
+sub error {
+ my ($txt) = @_;
+ print $txt . "\n";
+ exit 1;
+}
+
+# Print DEBUG message to the console.
+sub debug {
+ my ($txt) = @_;
+ if (exists $args{'--latex'}) {
+ print '% ';
+ }
+ print $txt . "\n";
+}
+
+# Print INFO message to the console.
+sub warning {
+ my ($txt) = @_;
+ if (exists $args{'--latex'}) {
+ print "\\PackageWarningNoLine{bibcop}{$txt}\n";
+ } else {
+ print $txt . "\n";
+ }
+}
+
if (@ARGV+0 eq 0 or exists $args{'--help'}) {
debug("Bibcop is a Style Checker of .bib Files\n" .
"Usage: bibcop [<options>] <.bib file path>\n" .
@@ -415,7 +455,7 @@ if (@ARGV+0 eq 0 or exists $args{'--help'}) {
" --fix Fix the errors and print a new version of the .bib file to the console\n" .
" --latex Report errors in LaTeX format using \\PackageWarningNoLine command");
} elsif (exists $args{'--version'}) {
- debug('0.0.2');
+ debug('0.0.3');
} else {
my ($file) = grep { not($_ =~ /^--.*$/) } @ARGV;
open(my $fh, '<', $file);
@@ -463,30 +503,4 @@ if (@ARGV+0 eq 0 or exists $args{'--help'}) {
}
}
-# Print ERROR message to the console and die.
-sub error {
- my ($txt) = @_;
- print $txt . "\n";
- exit 1;
-}
-
-# Print DEBUG message to the console.
-sub debug {
- my ($txt) = @_;
- if (exists $args{'--latex'}) {
- print '% ';
- }
- print $txt . "\n";
-}
-
-# Print INFO message to the console.
-sub warning {
- my ($txt) = @_;
- if (exists $args{'--latex'}) {
- print "\\PackageWarningNoLine{bibcop}{$txt}\n";
- } else {
- print $txt . "\n";
- }
-}
-
1;