Use numeric registers to handle conditionals instead of trying

to do it all with text processing.
This commit is contained in:
Todd C. Miller
2010-05-25 16:13:04 -04:00
parent 5dd8e98ec7
commit 807d1313a5
13 changed files with 217 additions and 158 deletions

View File

@@ -1,23 +1,32 @@
#!/usr/bin/perl -p
BEGIN {
%tags = ( 'a', '@BAMAN@', 'c', '@LCMAN@', 'r', '@SEMAN@', 't', '@SEMAN@');
$t = undef;
%tags = ( 'a', 'BA', 'c', 'LC', 'r', 'SL', 't', 'SL');
$cond = -1;
}
if (/^\.IP(.*-([acrt]))?/) {
$t = $1 ? $tags{$2} : undef;
} elsif (/-a.*auth_type/) {
$_ = $tags{'a'} . $_;
# Initialize the numeric register we use for conditionals
if ($cond == -1) {
$_ = ".nr SL \@SEMAN\@\n.nr BA \@BAMAN\@\n.nr LC \@LCMAN\@\n.\\\"\n$_";
$cond = 0;
}
# Add conditionals
if (/^\.IP.*-([acrt])/) {
$_ = ".if \\n($tags{$1} \\{\\\n$_";
$cond = 1;
} elsif ($cond && /^\.(Sh|SS|IP|PP)/) {
$_ = "\\}\n$_";
$cond = 0;
}
if (/-a.*auth_type/) {
$_ = ".if \\n($tags{'a'} $_";
} elsif (/(-c.*class.*\||login_cap)/) {
$_ = $tags{'c'} . $_;
$_ = ".if \\n($tags{'c'} $_";
} elsif (/-r.*role.*-t.*type/) {
$_ = $tags{'r'} . $_;
$_ = ".if \\n($tags{'r'} $_";
}
# Fix up broken pod2man formatting of F<@foo@/bar>
s/\\fI\\f(\(C)?I\@([^\@]*)\\fI\@/\\fI\@$2\@/g;
# comment out Compile-time-specific lines in DESCRIPTION
if ($t) {
$_ = $t . $_;
}