From 869295358540c06765b31f853e55b6d6d2e5a99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 11 Dec 2020 00:24:14 +0100 Subject: mht, mht.1: Remove strict arities Now, superfluous or missing arguments will be silently ignored. Furthermore, only one definition of the same request is allowed. But on the upside, the system is a whole lot simpler and can be made even more flexible in the future than before. --- mht | 73 +++++++++++++++++++++++++----------------------------------------- mht.1 | 74 +++++++++++++++++++++---------------------------------------------- 2 files changed, 50 insertions(+), 97 deletions(-) diff --git a/mht b/mht index 105423b..adb8c36 100755 --- a/mht +++ b/mht @@ -22,47 +22,33 @@ my $opel = ''; # currently opened block element # 1.2.1 Contiguous elements my %ctels = ( - Qp_0 => '
{

%

}
', + Qp => '
{

%

}
', ); # 1.2.2 Block elements my %blels = ( - Pp_0 => '

%

', - Pr_0 => '
%
', - Sh_0 => '

%

', - Sh_1 => '%', - Ti_0 => '%', + Hh => '%', + Pp => '

%

', + Pr => '
%
', + Sh => '

%

', + Ti => '%', ); # 1.2.3 Inline elements my %inels = ( - Au_1 => '', - Bd_1 => '\\$1', - Bd_2 => '\\$1\\$2', - Bd_3 => '\\$3\\$1\\$2', - br_0 => '
', - Cd_1 => '\\$1', - Cd_2 => '\\$1\\$2', - Cd_3 => '\\$3\\$1\\$2', - Cs_1 => '', - Da_0 => '', - Em_1 => '\\$1', - Em_2 => '\\$1\\$2', - Em_3 => '\\$3\\$1\\$2', - Hy_2 => '\\$1', - Im_2 => '\\$2', - It_1 => '\\$1', - It_2 => '\\$1\\$2', - It_3 => '\\$3\\$1\\$2', - St_1 => '\\$1', - St_2 => '\\$1\\$2', - St_3 => '\\$3\\$1\\$2', - Tt_1 => '\\$1', - Tt_2 => '\\$1\\$2', - Tt_3 => '\\$3\\$1\\$2', - Ul_1 => '\\$1', - Ul_2 => '\\$1\\$2', - Ul_3 => '\\$3\\$1\\$2', + Au => '', + Bd => '\\$3\\$1\\$2', + br => '
', + Cd => '\\$3\\$1\\$2', + Cs => '', + Da => '', + Em => '\\$3\\$1\\$2', + Hy => '\\$4\\$1\\$3', + Im => '\\$2', + It => '\\$3\\$1\\$2', + St => '\\$3\\$1\\$2', + Tt => '\\$3\\$1\\$2', + Ul => '\\$3\\$1\\$2', ); @@ -73,21 +59,20 @@ sub request { my ($el, $args) = @_; my @argv = quotewords('\s+', 0, $args); my $n = @argv; - my $elkey = "${el}_$n"; - if (exists $blels{$elkey} or exists $ctels{$elkey}) { + if (exists $blels{$el} or exists $ctels{$el}) { # Clear empty line buffer $empty = ''; # Close currently open block element, open new my ($base, $prestart, $newpostclose) = ('', '', ''); - if (exists $ctels{$elkey}) { - $base = $ctels{$elkey}; + if (exists $ctels{$el}) { + $base = $ctels{$el}; $prestart = prestart($base); $newpostclose = postclose($base); $base = inner($base); } else { - $base = $blels{$elkey}; + $base = $blels{$el}; } my $start = start($base); my $newclose = interpol(_close($base), @argv) . "\n"; @@ -102,8 +87,8 @@ sub request { print interpol($start, @argv) . "\n"; $opel = $el; - } elsif (exists $inels{$elkey}) { - print interpol($inels{$elkey}, @argv) . "\n"; + } elsif (exists $inels{$el}) { + print interpol($inels{$el}, @argv) . "\n"; } else { print STDERR "Error: $el/$n not implemented\n"; exit 1; @@ -113,12 +98,8 @@ sub request { # 1.3.2 Interpolate \$n parameters sub interpol { my $s = shift; - my $i = 1; - my $arg; - while ($arg = shift) { - $s =~ s/\\\$$i/$arg/g; - $i++; - } + no warnings qw/uninitialized/; + $s =~ s/\\\$(\d+)/$_[$1-1]/g; return $s; } diff --git a/mht.1 b/mht.1 index 75ab3c2..f1bb73c 100644 --- a/mht.1 +++ b/mht.1 @@ -26,8 +26,8 @@ As such, it supports only a subset of the standard troff requests. .Pp This section describes the various types of requests supported by .Nm . -On the left side are the name and arity of each request, separated by a slash. -On the right side is the HTML expansion of each request. +On the left side is the name of the request. +On the right side is the HTML expansion. .Pp In the HTML expansion of all element requests, a backslash and a dollar sign followed by a number (e.g. \\$1) signify a parameter expansion. .Pp @@ -36,79 +36,51 @@ In block element requests, a percent sign (%) signifies the lines following the Finally, in contiguous element requests, whatever text is on the outside of the area delimited by braces ({...}) is removed when two of the same contiguous element requests are placed next to one another. .Ss Standard troff requests .Bl -tag -.It Sy \&br/0 +.It Sy \&br
.El .Ss Contiguous element requests .Bl -tag -.It Sy \&Qp/0 +.It Sy \&Qp
{

%

}
.El .Ss Block element requests .Bl -tag -.It Sy \&Pp/0 +.It Sy \&Hh +% +.It Sy \&Pp

%

-.It Sy \&Pr/0 +.It Sy \&Pr
%
-.It Sy \&Sh/0 +.It Sy \&Sh

%

-.It Sy \&Sh/1 -% -.It Sy \&Ti/0 +.It Sy \&Ti % .Ss Inline element requests .Bl -tag -.It Sy \&Au/1 +.It Sy \&Au -.It Sy \&Bd/1 -\\$1 -.It Sy \&Bd/2 -\\$1\\$2 -.It Sy \&Bd/3 +.It Sy \&Bd \\$3\\$1\\$2 -.It Sy \&br/0 -
-.It Sy \&Cd/1 -\\$1 -.It Sy \&Cd/2 -\\$1\\$2 -.It Sy \&Cd/3 +.It Sy \&Cd \\$3\\$1\\$2 -.It Sy \&Cs/1 +.It Sy \&Cs -.It Sy \&Em/1 -\\$1 -.It Sy \&Em/2 -\\$1\\$2 -.It Sy \&Em/3 +.It Sy \&Da + +.It Sy \&Em \\$3\\$1\\$2 -.It Sy \&Hy/2 +.It Sy \&Hy \\$1 -.It Sy \&Im/2 +.It Sy \&Im \\$2 -.It Sy \&It/1 -\\$1 -.It Sy \&It/2 -\\$1\\$2 -.It Sy \&It/3 +.It Sy \&It \\$3\\$1\\$2 -.It Sy \&St/1 -\\$1 -.It Sy \&St/2 -\\$1\\$2 -.It Sy \&St/3 +.It Sy \&St \\$3\\$1\\$2 -.It Sy \&Tt/1 -\\$1 -.It Sy \&Tt/2 -\\$1\\$2 -.It Sy \&Tt/3 +.It Sy \&Tt \\$3\\$1\\$2 -.It Sy \&Ul/1 -\\$1 -.It Sy \&Ul/2 -\\$1\\$2 -.It Sy \&Ul/3 +.It Sy \&Ul \\$3\\$1\\$2 .El . -- cgit v1.2.3