summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/bibcop/bibcop.pl
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-12-14 03:01:10 +0000
committerNorbert Preining <norbert@preining.info>2022-12-14 03:01:10 +0000
commit4a68164a544897aa6fc54b5eb61b23135e44d4df (patch)
tree73f3a85754eb5c5bea7e0ea5986b135a8d5236bf /macros/latex/contrib/bibcop/bibcop.pl
parent7b8bd496c62a5a8e18fb7a038217d4118c02b1e2 (diff)
CTAN sync 202212140301
Diffstat (limited to 'macros/latex/contrib/bibcop/bibcop.pl')
-rwxr-xr-xmacros/latex/contrib/bibcop/bibcop.pl74
1 files changed, 44 insertions, 30 deletions
diff --git a/macros/latex/contrib/bibcop/bibcop.pl b/macros/latex/contrib/bibcop/bibcop.pl
index 3fa1444b92..8b900bbc35 100755
--- a/macros/latex/contrib/bibcop/bibcop.pl
+++ b/macros/latex/contrib/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;