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 | |
parent | c71a898216c4bcfa0c5195df857b2aa09a9636a4 (diff) | |
download | rf-987c3b5a6e0b6a800c354725d214d71e5098c1d8.tar.gz |
Change multi-line format specification syntax
-rwxr-xr-x | rf | 44 | ||||
-rw-r--r-- | rf.1 | 29 |
2 files changed, 34 insertions, 39 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) @@ -233,24 +233,24 @@ of the authors, you can use the special syntax, with an uppercase instead of lowercase .Sq a . . -.Ss Special backslash behavior -.Bl -enum -.It -A backslash at the end of a format line acts as a line continuation marker. -The newline after the backslash is preserved. -.It -For format macros describing citations, a backslash immediately following the macro name will cause the reference be joined to the preceding line. -.El +.Ss Multiple lines +If no argument is given to a format macro, then +.Nm +will read the format specification from the following lines until a line containing +.Sq .. +is encountered, signifying the end of the multi-line format specification. .Pp -Anywhere else in the line, backslashes are preserved literally. +Within a multi-line format spefication, use the escapes \\$2 and \\$3 +to interpolate (respectively) any suffix and prefix given to the citation macro. .Pp -By using backslashes, you can implement footnote-based citations. -For example, using the ms macro package: +For example, the following multi-line format specification implements footnote references: .Bd -literal -offset indent -\&.Fx\\ \\**\\ -\&.FS\\ -%a, {\\fI%t\\fR}, {\\*Q%q\\*U}, %y.\\ +\&.Fx +\\$3\\**\\$2 +\&.FS +%a, {\\fI%t\\fR}, {\\*Q%q\\*U}, %y. \&.FE +\&.. .Ed . .Ss Automatic cleanup @@ -311,7 +311,6 @@ will output the following source code: \&.SH Previous work - \&.LP Davidson (1991) |