From 87c49bd96602bf44aaf255adc237a22236c1290b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 10 Nov 2020 23:30:56 +0100 Subject: support multiple authors; show full names in reflist --- rf.pl | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'rf.pl') diff --git a/rf.pl b/rf.pl index b2fe726..86345dd 100644 --- a/rf.pl +++ b/rf.pl @@ -28,7 +28,11 @@ while (<>) { if ($fld eq 'a') { $i++ if not $author_last; push @lines, ".R! $i"; - $refs[$i]{$fld} = $def; + if (defined $refs[$i]{a}) { + $refs[$i]{a} = "; $def"; + } else { + $refs[$i]{a} = $def; + } $author_last = 1; next; } elsif ($fld =~ /[cdnpqtwy]/) { @@ -75,7 +79,7 @@ for (@lines) { # Reference definition if (/^\.R! (\d+)/) { - print fmt($format_list, $1) . "\n"; + print fmt($format_list, $1, 1) . "\n"; next; } @@ -85,13 +89,13 @@ for (@lines) { } sub fmt { - my ($fmt, $i) = @_; + my ($fmt, $i, $full) = @_; my %ref = %{$refs[$i]}; for my $fld (split //, 'acdnpqtwy') { if ($ref{$fld}) { no warnings; my $val = $ref{$fld}; - $val = fmta($val) if $fld eq 'a'; + $val = fmta($val) if $fld eq 'a' and not $full; $fmt =~ s/\{(.*?)%$fld(.*?)}/$1$val$3/g; $fmt =~ s/%$fld/$val/g; } else { @@ -107,13 +111,18 @@ sub fmt { } sub fmta { - my ($name) = @_; - if ($name =~ /(.*?),/) { - return $1; - } else { - $name =~ s/(.*?)\s/$1/; - return $name; + my ($a) = @_; + my $r; + for my $name (split /; /, $a) { + if ($name =~ /(.*?),/) { + $r .= ", $1"; + } else { + $name =~ s/(.*?)\s/$1/; + return ", $name"; + } } + $r =~ s/^, //; + return $r; } sub likeness { -- cgit v1.2.3