diff options
author | John Ankarström <john@ankarstrom.se> | 2021-01-04 17:03:41 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-01-04 17:03:41 +0100 |
commit | 987c3b5a6e0b6a800c354725d214d71e5098c1d8 (patch) | |
tree | 5d31f20caae446db37003b36627f5b0def8d1966 /rf | |
parent | c71a898216c4bcfa0c5195df857b2aa09a9636a4 (diff) | |
download | rf-987c3b5a6e0b6a800c354725d214d71e5098c1d8.tar.gz |
Change multi-line format specification syntax
Diffstat (limited to 'rf')
-rwxr-xr-x | rf | 44 |
1 files changed, 20 insertions, 24 deletions
@@ -7,8 +7,8 @@ use warnings; my %fmt; $fmt{r} = '%a {(%y)}. {\fI%t\fR}. {\*Q%q\*U}. %n, %d. %c: %p. {Available: %w}'; -$fmt{f} = "\n(%A %y)"; -$fmt{x} = "\n(%y)"; +$fmt{f} = "(%A %y)"; +$fmt{x} = "(%y)"; # Internal variables @@ -21,16 +21,19 @@ while (<>) { chomp; # Format specification - if (/^\.F([rfx])(\\?) +(.*)/) { - my ($type, $join, $rest) = ($1, $2, $3); - $rest = "\n$rest" if not $join; - while (not eof()) { - last if not $rest =~ s/\\$//; - $rest .= "\n" . <>; - chomp $rest; + if (/^\.F([rfx])( +.*)?/) { + my ($type, $def) = ($1, $2); + if ($def) { + $def =~ s/^ +//; + } else { + $def = ''; + while (<>) { + last if /^\.\.$/; + $def .= $_; + } } - chomp $rest; - $fmt{$type} = $rest; + chomp $def; + $fmt{$type} = $def; next; } @@ -69,11 +72,9 @@ for (my $i = $#lines; $i >= 0; $i--) { if (/^\.R([fx]) +(.*)/) { my ($fld, $rest) = ($1, $2, $3); - $inlref = 1; - # find potential prefix/suffix my ($suffix, $prefix); - if ($rest =~ s/ ([.,?!:;\])]) ?([\[(])?$//) { + if ($rest =~ s/ ([.,?!:;\])]+) ?([\[(]*)$//) { ($suffix, $prefix) = ($1, $2); } @@ -131,9 +132,10 @@ for (my $i = $#lines; $i >= 0; $i--) { $prefix = '' if not $prefix; $suffix = '' if not $suffix; push @r, "\n"; - if ($n != 0) { - push @r, substr($fmt, index($fmt, "\n")); - push @r, $prefix . substr($fmt, 0, index($fmt, "\n")) . "$suffix"; + if ($n > 0) { + my %affix = (2 => $suffix, 3 => $prefix); + $fmt =~ s/\\\$([23])/$affix{$1}/g; + push @r, $fmt; } else { push @r, "$prefix$fmt$suffix"; } @@ -142,16 +144,10 @@ for (my $i = $#lines; $i >= 0; $i--) { # non-rf line - # whether or not to include a final newline depends on the - # format of the inline reference on the line below - if (!$inlref) { - push @r, "\n"; - } - + push @r, "\n"; push @r, $_; $refblock = 0; - $inlref = 0; } # Third pass (print the result) |