Skip to content

Commit

Permalink
#31 show position correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 19, 2023
1 parent 17173b1 commit 687ea73
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
26 changes: 21 additions & 5 deletions bibcop.pl
Expand Up @@ -98,7 +98,7 @@ sub check_capitalization {
if (not $words[$pos - 2] =~ /^.*:$/) {
next;
}
return "The minor word in the '$tag' must be upper-cased, becuase it follows the colon"
return "The minor word in the '$tag' must be upper-cased, because it follows the colon"
}
if (exists $minors{lc($word)}) {
if ($pos eq 1) {
Expand All @@ -107,10 +107,10 @@ sub check_capitalization {
if ($words[$pos - 2] =~ /^.*:$/) {
next;
}
return "All minor words in the '$tag' must be lower-cased, while '$word' (no.$pos) is not"
return "All minor words in the '$tag' must be lower-cased, while @{[as_position($pos)]} word '$word' is not"
}
if ($word =~ /^[a-z].*/) {
return "All major words in the '$tag' must be capitalized, while '$word' (no.$pos) is not"
return "All major words in the '$tag' must be capitalized, while @{[as_position($pos)]} word '$word' is not"
}
}
}
Expand All @@ -137,10 +137,10 @@ sub check_author {
next;
}
if (not $a =~ /^[A-Z][^ .]+( [A-Z][^ .]+)*(,( [A-Z][^ ]+)+)?$/) {
return "The format of the $pos-th 'author' is wrong, use something like 'Knuth, Donald E. and Duane, Bibby'"
return "The format of @{[as_position($pos)]} 'author' is wrong, use something like 'Knuth, Donald E. and Duane, Bibby'"
}
if ($author =~ /.*[A-Z]([ ,]|$).*/) {
return "A shortened name must have a tailing dot in $pos-th 'author', as in 'Knuth, Donald E.'"
return "A shortened name must have a tailing dot in @{[as_position($pos)]} 'author', as in 'Knuth, Donald E.'"
}
}
}
Expand Down Expand Up @@ -709,6 +709,22 @@ sub clean_tex {
return $tex;
}

# Turn a number into a position, like 1 -> 1st, 2 -> 2nd, 3 -> 3rd, 4 -> 4th, and so on.
sub as_position {
my ($i) = @_;
my $txt;
if ($i == 1) {
$txt = '1st';
} elsif ($i == 2) {
$txt = '2nd';
} elsif ($i == 3) {
$txt = '3rd';
} else {
$txt = "${i}th";
}
return "the $txt";
}

# Take a bibentry and print all its tags as a comma-separated string.
sub listed_tags {
my (%entry) = @_;
Expand Down
2 changes: 1 addition & 1 deletion testfiles/bibtex.luatex.tlg
Expand Up @@ -4,7 +4,7 @@ LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while the 6th word 'To' is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
bibcop: 3 problem(s) found
Expand Down
2 changes: 1 addition & 1 deletion testfiles/bibtex.tlg
Expand Up @@ -4,7 +4,7 @@ LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed.
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while the 6th word 'To' is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
bibcop: 3 problem(s) found
Expand Down
2 changes: 1 addition & 1 deletion testfiles/bibtex.xetex.tlg
Expand Up @@ -4,7 +4,7 @@ LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed.
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while the 6th word 'To' is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
bibcop: 3 problem(s) found
Expand Down

0 comments on commit 687ea73

Please sign in to comment.