aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-11 01:43:39 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-11 01:43:39 +0100
commit1cd3a3d6c7fb6899b88b65694841cabc00d10fc1 (patch)
tree5b1697d2331bc6a01b76e5a52378a583ce296b1d
parent87c49bd96602bf44aaf255adc237a22236c1290b (diff)
downloadrf-1cd3a3d6c7fb6899b88b65694841cabc00d10fc1.tar.gz
polish
-rwxr-xr-x[-rw-r--r--]rf.pl35
1 files changed, 27 insertions, 8 deletions
diff --git a/rf.pl b/rf.pl
index 86345dd..7696921 100644..100755
--- a/rf.pl
+++ b/rf.pl
@@ -7,7 +7,7 @@ use warnings;
my $format_full = '(%a %y)';
my $format_extra = '(%y)';
-my $format_list = '%a (%y). %t. %q. %n, %d. %c: %p.';
+my $format_list = '%a (%y). %t. %q. %n, %d. %c: %p. {Available: %w.}';
# Internal variables
@@ -46,7 +46,9 @@ while (<>) {
push @lines, $_;
}
+$i = -1;
for (@lines) {
+ $i++;
# Inline reference
if (/^\.R([fx]) +(.*)/) {
my ($fld, $def) = ($1, $2);
@@ -55,18 +57,32 @@ for (@lines) {
my $winner = 0;
my @words = split /\s/, $def;
my @points;
+
+ # replace '' with preceding word
+ for (@words) {
+ if ($_ eq "''") {
+ $_ = $lines[$i-1];
+ $_ =~ s/^.*\s(\S+)\s*$/$1/;
+ }
+ }
+
for (my $i = 0; $i < scalar @refs; $i++) {
$points[$i] = 0 if not defined $points[$i];
- $points[$i] += 7 if likeness($refs[$i]{a}, @words);
- $points[$i] += 4 if likeness($refs[$i]{y}, @words);
- $points[$i] += 1 if likeness($refs[$i]{t}, @words);
- $points[$i] += 1 if likeness($refs[$i]{q}, @words);
+ $points[$i] += 100 if likeness($refs[$i]{a}, @words);
+ $points[$i] += 50 if likeness($refs[$i]{y}, @words);
+ $points[$i] += 1 * likeness($refs[$i]{t}, @words);
+ $points[$i] += 1 * likeness($refs[$i]{q}, @words);
$winner = $i if $points[$i] > $points[$winner];
}
+
if (not defined $winner) {
- print STDERR "Reference '$def' could not be resolved.\n";
+ print STDERR "Error: Reference '$def' could not be resolved.\n";
exit 1;
}
+ if ($points[$winner] < 11) {
+ print STDERR "Warning: Guessing that reference '$def' refers to " . fmt($format_full, $winner) . ".\n";
+ }
+
if ($fld eq 'f') {
no warnings;
print $prefix . fmt($format_full, $winner) . "$suffix\n";
@@ -105,6 +121,8 @@ sub fmt {
}
}
$fmt =~ s/ +/ /g;
+ $fmt =~ s/([(]) */$1/;
+ $fmt =~ s/ *([.,)])/$1/;
$fmt =~ s/^ *//;
$fmt =~ s/ *$//;
return $fmt;
@@ -127,9 +145,10 @@ sub fmta {
sub likeness {
my ($string, @strings) = @_;
+ my $r = 0;
return 0 if not defined $string;
for (@strings) {
- return 1 if index($string, $_) != -1;
+ $r += 1 if index($string, $_) != -1;
}
- return 0;
+ return $r;
}