From: Harlan Stenn Date: Thu, 3 Jan 2013 11:36:26 +0000 (+0000) Subject: Refactor and enhance mdoc2texi X-Git-Tag: NTP_4_2_7P344~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=263a50dac63e7de0a8d7cc9561bab775bf2f9edf;p=thirdparty%2Fntp.git Refactor and enhance mdoc2texi bk: 50e56d3aMSEF0PCZ3UmUQwZMhW724w --- diff --git a/ChangeLog b/ChangeLog index ebadf4076..7897ec9f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +* Refactor and enhance mdoc2texi. +* Make sure agtexi-file.tpl defines label-str. * Cleanup to ntp.conf.def. * Upgrade to autogen-5.17 and libopts-37.0.12. (4.2.7p343) 2013/01/02 Released by Harlan Stenn diff --git a/sntp/ag-tpl/agtexi-file.tpl b/sntp/ag-tpl/agtexi-file.tpl index 3ff415023..8b7fe59dd 100644 --- a/sntp/ag-tpl/agtexi-file.tpl +++ b/sntp/ag-tpl/agtexi-file.tpl @@ -4,9 +4,6 @@ texi # Documentation template # -# Time-stamp: "2012-08-11 08:33:08 bkorb" -# Author: Bruce Korb -# # This file is part of AutoOpts, a companion to AutoGen. # AutoOpts is free software. # AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved @@ -82,7 +79,10 @@ coded-prog-name)=] program.[= (name-copyright) =] @menu [= (out-push-new) (out-suspend "menu") - (out-push-new) =][=# + (out-push-new) =][= + (define label-str (string-append + program-name " help/usage Something")) + =][=# @c = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =][= diff --git a/sntp/ag-tpl/mdoc2texi b/sntp/ag-tpl/mdoc2texi index d9b5710f9..d6aacf0e9 100755 --- a/sntp/ag-tpl/mdoc2texi +++ b/sntp/ag-tpl/mdoc2texi @@ -1,52 +1,62 @@ -#! /usr/local/bin/perl +#! /usr/bin/perl use strict; -print STDERR "XXX: In the local mdoc2texi\n"; # XXX - -my ($optlist,$oldoptlist); -my ($literal); my ($line); -my ($count,$tableitemcount); +my ($bdEd); +my ($blCf,$blEl,@blEl,$blIt,@blIt); my ($progName); -my (@words, $retval,$columnline); -my ($extArg); +my (@words,$wc); +my ($extArg,$ns,$sm,$wantspace); +my ($noNl); +my ($ref,$refCount); my (%anchor, $aCount); $aCount = 0; - -$optlist = 0; ### 1 = bullet, 2 = enum, 3 = tag, 4 = item/column -$oldoptlist = 0; -$extArg = 0; +$noNl = 0; +$ns = 0; # .Ns (no spaces from here to first parameter) +$sm = 1; # Spacing mode +$extArg = 0; # Extended Arguments - disable NLs. +$ref = 0; +$refCount = 0; ### # -# We don't know what order we'll see .Sx +# We don't know what order we'll see .Sx # # Whenever we find one, we look it up. # If it doesn't exist we assign it an anchor name. # Regardless, we "return" the anchor name, as we're either going # to define the anchor point using '@anchor{anchor-1}' or reference # the anchor using something like '@xref{anchor-1,,whatever}' -# +# ### while ($line = ) { - if ($line !~ /^\./) + chomp $line; + + $wc = 0; + + if ($line =~ /^\./) + { + $line =~ s/^\.//; + @words = split(/\s+/, $line); + parseMacro(); + } + else { print $line; - print ".br\n" # XXX: What is .br? - if ($literal); # $literal is never 'true'... - next; } - next - if ($line =~ /^\.\\"/); - - $line = ParseMacro($line); - print($line) - if (defined $line); + if ($noNl) + { + $noNl = 0; + } + elsif (!$extArg) + { + print "\n"; + } } sub Anchor ($) @@ -59,8 +69,8 @@ sub Anchor ($) if (!exists $anchor{$string}) { - ++$aCount; - $anchor{$string} = "anchor-$aCount"; + ++$aCount; + $anchor{$string} = "anchor-$aCount"; } return $anchor{$string}; @@ -70,324 +80,418 @@ sub Handle_An { # We should eventually support -nosplit and -split. # Usage: .An ... - # .An "Joe Author" Joe Author - # .An "Joe Author" Joe Author, - # .An "Joe Author" Aq user@site Joe Author - # .An "Joe Author" ) ) , Joe Author)), + # .An "Joe Author" Joe Author + # .An "Joe Author" , Joe Author, + # .An "Joe Author" Aq user@site Joe Author + # .An "Joe Author" ) ) , Joe Author)), do { - if ($words[0] =~ /^"/) + parseQuote(\@words) if ($words[0] =~ /^"/); + print shift @words; # XXX: Spaces? + } while scalar(@words); + + # Anything else should be punctuation. + while ($_ = shift @words) + { + print; + } + + print "\@*"; +} + +sub Handle_Bd +{ + # Must end with a .Ed. + # Bd {-literal | -filled | -unfilled | -ragged | -centered} + # [-offset ] [-file ] [-compact] + + my ($bd); + + if ($words[0] eq '-literal') # Literal font display. + { + $bd = "\@verbatim"; + $bdEd = "\@end verbatim"; + } + elsif ($words[0] eq '-filled') # Filled display (R/L justified) + { + die "Handle_Bd: -filled not supported.\n"; + $bd = "\@table \@asis"; + $bdEd = "\@end table"; + } + elsif ($words[0] eq '-unfilled') # Display as typed. + { + die "Handle_Bd: -unfilled not supported.\n"; + $bd = "\@table \@asis"; + $bdEd = "\@end table"; + } + elsif ($words[0] eq '-ragged') # Left-justified only. + { + die "Handle_Bd: -ragged not supported.\n"; + $bd = "\@table \@asis"; + $bdEd = "\@end table"; + } + elsif ($words[0] eq '-centered') # Center each line. + { + die "Handle_Bd: -centered not supported.\n"; + $bd = "\@table \@asis"; + $bdEd = "\@end table"; + } + else + { + die "Handle_Bd: Unknown list type <$words[0]>\n"; + } + + shift @words; + + while ($_ = shift @words) + { + if (/^-file$/) { - print parseQuote(\@words); + die "Handle_Bd: -file not supported.\n"; } - else + elsif (/^-offset$/) { - print "$words[0]"; + die "Handle_Bd: -offset not supported.\n"; + $_ = shift @words; + if (/^left$/) + { + } + elsif (/^center$/) + { + } + elsif (/^indent$/) + { + } + elsif (/^indent-two$/) + { + } + elsif (/^right$/) + { + } + else + { + die "Handle_Bd: Unexpected value for -offset: <$_>\n"; + } } - shift @words; - } while scalar(@words); - print "@*"; + else + { + die "Handle_Bd: unexpected argument: <$_>\n"; + } + } + print $bd; } sub Handle_Bl { - if ($words[0] eq '-bullet') + # Must end with a .El. May be nested, including inside displays. + # + # .Bl {-hang | -ohang | -tag | -diag | -inset} [-width ] \ + # [-offset ] + # .Bl -column [-offset ] ... + # .Bl {-item | -enum [-nested] | -bullet | -hyphen | -dash} \ + # [-offset ] [-compact] + # "-offset indent" uses a standard indent. + # -compact suppresses insertion of vertical space before the list and + # between the list items. + my ($inMulti); + + # For nesting, save needed context: + # $blEl + # $blIt + unshift @blEl, $blEl; + unshift @blIt, $blIt; + + $blEl = "blEl - XXX!"; + $blIt = ""; # Would undef be easier? + + $inMulti = 0; + if ($words[0] eq '-hang') # hanging tags { - if (!$optlist) - { - $optlist = 1; # bullet - $retval .= "\@itemize \@bullet\n" ; - print "$retval"; - return 1; - } - else - { - $retval .= "\@itemize \@minus\n"; - print $retval; - $oldoptlist = 1; - return 1; - } + print "\@table \@asis"; + $blEl = "\@end table"; } - if ($words[0] eq '-enum') + elsif ($words[0] eq '-ohang') # tag on its own line, no indent { - if (!$optlist) - { - $optlist = 2; # enum - $retval .= "\@enumerate\n" ; - print "$retval"; - return 1; - } - else - { - $retval .= "\@enumerate\n"; - print $retval; - $oldoptlist = 2; - return 1; - } + print "\@table \@asis"; + $blEl = "\@end table"; } - if ($words[0] eq '-tag') + elsif ($words[0] eq '-tag') # like hang. { - $optlist = 3; # tag - $retval .= "\@table \@samp\n"; - print "$retval"; - return 1; + print "\@table \@asis"; + $blEl = "\@end table"; } - if ($words[0] eq '-column') + elsif ($words[0] eq '-diag') # man (4) diagnostic list - inset { - $optlist = 4; # column - $retval = "\@multitable \@columnfractions ";#\.20 \.20 \.20\n"; - #print $retval; - $columnline = "\@headitem "; - #print $retval; - foreach(@words) - { - if (!/^"./ && !/-column/ && !/indent/ && !/-offset/) - { - $_ =~ s/\"//g; - - $retval .= "\.20 "; - if (!$count) - { - $columnline .= $_; - } - else - { - $columnline .= " \@tab ".$_; - } - $count++; - } - } - print $retval."\n"; - print $columnline; - return 1; + print "\@table \@asis"; + $blEl = "\@end table"; + } + elsif ($words[0] eq '-inset') # inset list - See the mdoc page. + { + print "\@table \@asis"; + $blEl = "\@end table"; + } + elsif ($words[0] eq '-column') # Multiple columns + { + print "\@multitable\n"; # XXX Set $wc to 0? + $blEl = "\@end multitable"; + $blCf = "\@columnfractions"; + $inMulti = 1; + } + elsif ($words[0] eq '-item') # Item with no list markers + { + print "\@table \@asis"; + $blEl = "\@end table"; + } + elsif ($words[0] eq '-enum') # Enumerated (numbered) list + { + print "\@itemize \@enumerate"; + $blEl = "\@end enumerate"; + } + elsif ($words[0] eq '-bullet') # Bullet list + { + print "\@itemize \@bullet"; + $blEl = "\@end itemize"; } + elsif ($words[0] eq '-hyphen') # dash/hyphen list + { + # What would be better? Maybe a 2 column table... + print "\@itemize \@bullet"; + $blEl = "\@end itemize"; + $blIt = "-"; # @minus ? + } + elsif ($words[0] eq '-dash') # dash/hyphen list + { + # What would be better? Maybe a 2 column table... + print "\@itemize \@bullet"; + $blEl = "\@end itemize"; + $blIt = "-"; # @minus ? + } + else + { + die "Handle_Bl: Unknown list type <$words[0]>\n"; + } + + shift @words; - return 0; + while ($_ = shift @words) + { + if (/^-width$/) + { + # Maybe some day we will do something with the value... + parseQuote(\@words) if ($words[0] =~ /^"/); + shift @words; + } + elsif (/^-offset$/) + { + # Maybe some day we will do something with the value... + shift @words; + } + elsif (/^-compact$/) + { + # No argument expected + } + elsif ($inMulti) # -column width + { + # Maybe some day we will do something with the value... + $blCf .= " .2"; + } + else + { + die "Handle_Bl: unexpected argument: <$_>\n"; + } + } + + if ($blCf ne "") + { + print $blCf; # The \n below used to be here... + $blCf = ""; + } + + print "\n"; + $wc = 0; } -sub Handle_It +sub Handle_Comment { - if ($optlist == 3) # tag + # print STDERR "In Handle_Comment\n"; + while ($_ = shift @words) { - $retval .= "\@item ".$words[0]."\n"; - print $retval; - return 1; } - elsif ($optlist == 4 ) # column/Item list + + $noNl = 1; # No newline needed. +} + +sub Handle_It +{ + # .It Li "sntp ntpserver.somewhere" + + # print STDERR "Handle_It: looking at <", join(" ",@words), ">\n"; # XXX + # die "Handle_It: \$wc was $wc, not 0.\n" if ($wc); + + print "\@item"; + if ($blIt ne "") { - if (!$tableitemcount) - { - $tableitemcount = 1; - return 1; - } - else - { - foreach(@words) - { - if (/^Li$/) - { - print "\n\@item "; - return 0; - } - elsif (/^Ta$/) - { - print "\n\@tab "; - return 0; - } - else - { - print $_; - return 0; - } - } - return 1; - } + print " $blIt"; + # Assert @words is empty? } else { - print "\@item\n"; + do + { + # print STDERR "Handle_It: looking at <", join(" ",@words), ">\n"; # XXX + parseMacro(); + } while scalar(@words); } - return 0; } -sub Handle_El +sub Handle_D { - if ($oldoptlist) + # .D1 Fl abcdefg -abcdefg<> # 1 line of indented text + # .Dl % ls \-l /etc % ls -l /etc # 1 indented literal text line + + if (/^D1$/) { - if ($oldoptlist == 1) - { - $oldoptlist = 0; - $retval .= "\@end itemize\n"; - print $retval; - } - elsif ($oldoptlist == 2) - { - $oldoptlist = 0; - $retval .= "\@end enumerate\n"; - print $retval; - } + print "\@example\n"; + $wc = 0; + parseMacro(); + print "\n\@end example"; } - else + elsif (/^Dl$/) { - if ($optlist == 1) - { - $oldoptlist = 0; - $retval .= "\@end itemize\n"; - print $retval; - } - elsif ($optlist == 2) - { - $oldoptlist = 0; - $retval .= "\@end enumerate\n"; - print $retval; - } - elsif ($optlist == 3) - { - $oldoptlist = 0; - $retval .= "\@end table\n"; - print $retval; - } - elsif ($optlist = 4) - { - $count = 0; - $columnline = ''; - $oldoptlist = 0; - $optlist = 0; - $tableitemcount = 0; - $retval .= "\n\@end multitable\n"; - print $retval; - } - else + print "\@example\n"; + while ($_ = shift @words) { - die "optlist <$optlist> was not expected."; + s/\\//; + print "$_ "; } - $optlist = 0; + print "\n\@end example"; } + else + { + die "Handle_D(): Unexpected mode: <$_>\n"; + } +} + +sub Handle_Ed +{ + print $bdEd; +} + +sub Handle_El +{ + print $blEl; + + $blIt = shift @blIt; + $blEl = shift @blEl; } sub Handle_Em { # Usage: .Em stuff - # .Em word word - # .Em or Ap ing or'ing + # .Em word word + # .Em or Ap ing or'ing # print '@emph{'; - do { - print shift @words; - } while (@words > 0 && $words[0] !~ /^[[:punct:]]$/); + parseMacro(); # XXX: Might we get a leading space? print "}"; + # On the assumption that the rest is punctuation... while ($_ = shift @words) { print; } - - print "\n"; } -sub Handle_ArCmFlIc +sub Handle_ArCmFlIcLi { # .Ar wants an italic code font, texi uses @kbd for that. # .Cm is .Fl but no '-'. # Usage: .Fl ... # - # .Fl - - # .Fl cfv -cfv - # .Fl cfv . -cfv. - # .Cm cfv . cfv. - # .Fl s v t -s -v -t - # .Fl - , --, - # .Fl xyz ) , -xyz), - # .Fl | - | - # .Ic "do while {...}" do while {...} + # .Fl - + # .Fl cfv -cfv + # .Fl cfv . -cfv. + # .Cm cfv . cfv. + # .Fl s v t -s -v -t + # .Fl - , --, + # .Fl xyz ) , -xyz), + # .Fl | - | + # .Ic "do while {...}" do while {...} + # .Li M1 M2 ; M1 M2>; # - my ($dash, $didOne, $font, $spacing); - - s/^\.//; + my ($dash, $didOne, $font, $fontE); $dash = (/^Fl$/) ? "-" : ""; - $font = (/^Ar$/) ? "\@kbd{" : "\@code{"; + $font = (/^Ar$/) ? "\@kbd{" : "\@code{"; # } + $fontE = '}'; $didOne = 0; - $spacing = 1; do { -#print STDERR "Handle_ArCmFlIc: top of loop, seeing <$words[0]>\n"; # XXX - - if (0) - { - } - elsif ($words[0] eq '|') + if ($words[0] eq '|') { -#print STDERR "Handle_ArCmFlIc: |\n"; # XXX - print " " if $didOne && $spacing; - print '@code{', $dash, '} ' if ($dash ne ""); + print " " if $didOne && $sm && !$ns; + print $font, $dash, $fontE, ' ' if ($dash ne ""); print "$words[0]"; + $ns = 0; } elsif ($words[0] eq '-') { -#print STDERR "Handle_ArCmFlIc: -\n"; # XXX - print " " if $didOne && $spacing; - print '@code{', $dash, $words[0], '}'; + print " " if $didOne && $sm && !$ns; + print $font, $dash, $words[0], $fontE; + $ns = 0; } - elsif ($words[0] =~ /^"/) - { -#print STDERR "Handle_ArCmFlIc: Quoted string...\n"; # XXX - print " " if $didOne && $spacing; - print '@code{'; - print $dash if ($dash ne ""); # Do we need this? - parseQuote(\@words); - print $words[0]; - print '}'; - } - elsif ($words[0] eq 'Ar') # Argument + elsif ($words[0] =~ /^"/) + { + print " " if $didOne && $sm && !$ns; + print $font; + print $dash if ($dash ne ""); # Do we need this? + parseQuote(\@words); + print $words[0]; + print $fontE; + $ns = 0; + } + elsif ($words[0] eq 'Ar') # Argument { -#print STDERR "Handle_ArCmFlIc: Ar\n"; # XXX - $font = '@kbd{'; # slanted tty + $font = '@kbd{'; # } slanted tty } - elsif ($words[0] eq 'Ic') # Interactive/internal command + elsif ($words[0] eq 'Ic') # Interactive/internal command { -#print STDERR "Handle_ArCmFlIc: Ic\n"; # XXX - $font = '@code{'; + $font = '@code{'; # } } elsif ($words[0] eq 'Xc') { -#print STDERR "Handle_ArCmFlIc: Xc\n"; # XXX - $spacing = 1; + $sm = 1; } elsif ($words[0] eq 'Xo') { -#print STDERR "Handle_ArCmFlIc: Xo\n"; # XXX - $spacing = 0; + $sm = 0; } - elsif ($words[0] =~ /^[[:punct:]]$/) + elsif ($words[0] =~ /^[[:punct:]]$/) { -#print STDERR 'Handle_ArCmFlIc: punctuation',"\n"; # XXX - # print " " if $didOne && $spacing; print $words[0]; } - else # Should be empty or a word + else # Should be empty or a word { -#print STDERR "Handle_ArCmFlIc: emitting <$words[0]>\n"; # XXX - print " " if $didOne && $spacing; - print '@code{'; - print $dash if ($dash ne ""); # Do we need this? - print $words[0]; - print '}'; + print " " if $didOne && $sm && !$ns; + print $font; + print $dash if ($dash ne ""); # Do we need this? + $words[0] =~ s/\\&//; + print $words[0]; + print $fontE; + $ns = 0; } shift @words; $didOne = 1; - } while scalar(@words); -#print STDERR "Handle_ArCmFlIc: done\n"; # XXX - print " "; + } while (scalar(@words) && $words[0] ne "Op"); } sub Handle_Fn { # Usage: .Fn [] ... - # .Fn getchar getchar() - # .Fn strlen ) , strlen()), - # .Fn align "char *pt" , alignchar *pt), + # .Fn getchar getchar() + # .Fn strlen ) , strlen()), + # .Fn align "char *pt" , alignchar *pt), # my ($didArg, $isOpen); @@ -398,30 +502,32 @@ sub Handle_Fn $didArg = 0; while ($_ = shift @words) { - if ($words[0] =~ /^"/) { - # assert $isOpen == 1 - print '@code{, }' if ($didArg); - parseQuote(\@words); - print '@emph{', $words[0], "}"; - $didArg = 1; - } else { - print ")" if ($isOpen); - $isOpen = 0; - print $words[0]; - } + if ($words[0] =~ /^"/) { + # assert $isOpen == 1 + if ($didArg) + { + print '@code{,}', (($sm) ? ' ' : ''); # Ignore $ns here + } + parseQuote(\@words); + print '@emph{', $words[0], "}"; + $didArg = 1; + $ns = 0; + } else { + print ")" if ($isOpen); + $isOpen = 0; + print $words[0]; + } } - - print "\n"; } sub Handle_Nm { # Usage: .Nm [] ... # - # .Nm groff_mdoc groff_mdoc - # .Nm \-mdoc -mdoc - # .Nm foo ) ) , foo)), - # .Nm : groff_mdoc: + # .Nm groff_mdoc groff_mdoc + # .Nm \-mdoc -mdoc + # .Nm foo ) ) , foo)), + # .Nm : groff_mdoc: # if (!defined $progName) { @@ -447,17 +553,26 @@ sub Handle_Nm { print; } - print "\n"; +} + +sub Handle_Ns +{ + # Usage: .Pf ... + # .Pa ntpkey_cert_ Ns Ar hostname + # + # Suppress whitespace between "here" and the first parameter + + $wc = 0; # This might be ok... } sub Handle_Op { # Usage: .Op [