From: Harlan Stenn Date: Mon, 6 Feb 2012 06:04:15 +0000 (+0000) Subject: autogen translator updates X-Git-Tag: NTP_4_2_7P269~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f57bfbbc25008c4245a934a033c79cf8fd0d8574;p=thirdparty%2Fntp.git autogen translator updates bk: 4f2f6d5fPOmNLtJpgtHOAlRZJnTPig --- diff --git a/sntp/ag-tpl/mdoc2man b/sntp/ag-tpl/mdoc2man deleted file mode 100755 index f1aa1384b..000000000 --- a/sntp/ag-tpl/mdoc2man +++ /dev/null @@ -1,301 +0,0 @@ -#! /usr/local/bin/bash - -## mdoc2man -- script to convert mdoc-isms to man-isms -## -## Time-stamp: "2011-05-30 14:17:42 bkorb" -## -## This file is part of AutoOpts, a companion to AutoGen. -## AutoOpts is free software. -## AutoOpts is Copyright (c) 1992-2011 Bruce Korb - all rights reserved -## -## AutoOpts is available under any one of two licenses. The license -## in use must be one of these two and the choice is under the control -## of the user of the license. -## -## The GNU Lesser General Public License, version 3 or later -## See the files "COPYING.lgplv3" and "COPYING.gplv3" -## -## The Modified Berkeley Software Distribution License -## See the file "COPYING.mbsd" -## -## These files have the following md5sums: -## -## 43b91e8ca915626ed3818ffb1b71248b COPYING.gplv3 -## 06a1a2e4760c90ea5e1dad8dfaac4d39 COPYING.lgplv3 -## 66a5cedaf62c4b2637025f049f9b826f COPYING.mbsd - -## This "library" converts mdoc-isms into man-isms. It gets included -## by the man page template at the point where mdoc-isms might start appearing -## and then "emit-man-text" is invoked when all the text has been assembled. -## -## Display the command line prototype, -## based only on the argument processing type. -## -## And run the entire output through "sed" to convert mdoc-isms - -# /bin/sh on Solaris is too horrible for words -# -case "$0" in -/bin/sh ) test -x /usr/xpg4/bin/sh && exec /usr/xpg4/bin/sh ${1+"$@"} ;; -esac - -parent_pid=$$ -prog=`basename $0 .sh` -NmName= - -die() { - echo "$prog error: $*" >&2 - ps -p ${AG_pid:-999999999} >/dev/null 2>&1 && \ - kill -TERM ${AG_pid} - kill -TERM $parent_pid - sleep 1 - kill -9 $parent_pid - sleep 1 - exit 1 -} - - -# One function for each mdoc structure. -# -do_nest_enum() { - do_enum -} - -do_enum() { - echo '.in +4' - local ix=1 - - while IFS='' read -r line - do - case "${line}" in - .It* ) printf '.ti -4\n%d\n\t' $ix - ix=`expr $ix + 1` - ;; - - .Bl' '*enum* ) do_nest_enum ;; - .Bl' '*tag* ) do_nest_tag ;; - .Bl' '*bullet* ) do_nest_bullet ;; - .Bd' '* ) do_nest_block ;; - .Op' '* ) do_nest_optional ;; - .Fl' '* ) do_nest_flag ;; - .Ar' '* ) do_nest_arg ;; - - .El* ) echo '.in -4' - return 0 ;; - - * ) echo "$line" ;; - esac - done - die "EOF reached processing '.Bl -enum'" -} - -do_nest_tag() { - echo '.in +4' - while IFS='' read -r line - do - case "${line}" in - .It* ) printf '.ti -4\n.IR ' - echo ${line#.It} ;; - - .Bl' '*enum* ) do_nest_enum ;; - .Bl' '*tag* ) do_nest_tag ;; - .Bl' '*bullet* ) do_nest_bullet ;; - .Bd' '* ) do_nest_block ;; - .Op' '* ) do_nest_optional ;; - .Fl' '* ) do_nest_flag ;; - .Ar' '* ) do_nest_arg ;; - - .El* ) echo '.in -4' - return 0 ;; - - * ) echo "$line" ;; - esac - done - die "EOF reached processing '.Bl -tag'" -} - -do_tag() { - while IFS='' read -r line - do - case "${line}" in - .It* ) printf '.TP\n.BR ' - echo ${line#.It} ;; - - .Bl' '*enum* ) do_nest_enum ;; - .Bl' '*tag* ) do_nest_tag ;; - .Bl' '*bullet* ) do_nest_bullet ;; - .Bd' '* ) do_nest_block ;; - .Op' '* ) do_nest_optional ;; - .Fl' '* ) do_nest_flag ;; - .Ar' '* ) do_nest_arg ;; - .El* ) return 0 ;; - * ) echo "$line" ;; - esac - done - die "EOF reached processing '.Bl -tag'" -} - -do_nest_bullet() { - do_bullet -} - -do_bullet() { - echo '.in +4' - while IFS='' read -r line - do - case "${line}" in - .It* ) printf '.ti -4\n\\fB*\\fP\n' - echo ${line#.It} - ;; - - .Bl' '*enum* ) do_nest_enum ;; - .Bl' '*tag* ) do_nest_tag ;; - .Bl' '*bullet* ) do_nest_bullet ;; - .Bd' '* ) do_nest_block ;; - .Op' '* ) do_nest_optional ;; - .Fl' '* ) do_nest_flag ;; - .Ar' '* ) do_nest_arg ;; - - .El* ) echo '.in -4' - return 0 ;; - - * ) echo "$line" ;; - esac - done - die "EOF reached processing '.Bl -bullet'" -} - -do_nest_block() { - do_block -} - -do_block() { - printf '.br\n.in +4\n.nf\n' - while IFS='' read -r line - do - case "${line}" in - .B* ) die ".Bx command nested within .Bd" ;; - - .Ed* ) echo .in -4 - echo .fi - return 0 ;; - - * ) echo "$line" ;; - esac - done - die "EOF reached processing '.Bd'" -} - -do_nest_optional() { - do_optional -} - -do_optional() { - set -- $line - shift - local text='[' - while test $# -gt 0 - do - case "X$1" in - X... ) - text="${text} \"\\fI$1\\fR\"" - shift - ;; - X\\* ) - text="${text} \"\\fI$1\\fR\"" - shift - ;; - XAr ) - text="${text} \"\\fI$2\\fR\"" - shift 2 || die "Ar command had no argument" - ;; - XCm ) - text="${text} \"\\fI$2\\fR\"" - shift 2 || die "Cm command had no argument" - ;; - XFl ) - text="${text} \\fB-$2\\fR" - shift 2 || die "Fl command had no argument" - ;; - * ) text="${text} \"$2\"" - m1="$1" - shift 2 || die "<${m1}> command had no argument: <$line>" - ;; - esac - done - echo "${text} ]" -} - -do_nest_flag() { - do_flag -} - -do_flag() { - echo ${line#.Fl} -} - -do_nest_arg() { - do_arg -} - -do_arg() { - line=`echo ${line} | sed 's/^.Ar *//'` - echo "\\fI${line}\\fR" -} - -do_NmName() { - # do we want to downcase the line first? Yes... - set -- `echo ${line#.Nm} | \ - sed -e 's/-/\\-/g' \ - -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` - NmNameSfx= - - if test $# -gt 0 - then case "$1" in - [A-Za-z]* ) - NmName=$1 - shift - ;; - esac - - test $# -gt 0 && NmNameSfx=" $*" - fi - echo ".B $NmName$NmNameSfx" -} - -do_line() { - case "${line}" in - .Bl' '*enum* ) do_enum ;; - .Bl' '*tag* ) do_tag ;; - .Bl' '*bullet* ) do_bullet ;; - .Bd' '* ) do_block ;; - .Op' '* ) do_optional ;; - .Fl' '* ) do_flag ;; - .Ar' '* ) do_arg ;; - .Nm' '* ) do_NmName ;; - .Nm ) do_NmName ;; - * ) echo "$line" ;; - esac - return 0 -} - - - -easy_fixes=' -s/^\.Sh/.SH/ -s/^\.Em/.I/ -s/^\.Pp/.PP/ -s/^.in *\\-/.in -/ -' - -readonly easy_fixes -set -f - -{ - while IFS='' read -r line - do - do_line - done -} | sed "${easy_fixes}" - -exit 0 diff --git a/sntp/ag-tpl/mdoc2mdoc b/sntp/ag-tpl/mdoc2mdoc deleted file mode 100755 index 5722b9ae2..000000000 --- a/sntp/ag-tpl/mdoc2mdoc +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -cat diff --git a/sntp/ag-tpl/texi2man b/sntp/ag-tpl/texi2man new file mode 100755 index 000000000..20e6cacdf --- /dev/null +++ b/sntp/ag-tpl/texi2man @@ -0,0 +1,63 @@ +#! /usr/local/bin/bash + +## texi2man.sh -- script to convert texi-isms to man page isms +## +## Time-stamp: "2011-01-28 13:09:24 bkorb" +## Author: Jim Van Zandt +## +## This file is part of AutoOpts, a companion to AutoGen. +## AutoOpts is free software. +## AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved +## +## AutoOpts is available under any one of two licenses. The license +## in use must be one of these two and the choice is under the control +## of the user of the license. +## +## The GNU Lesser General Public License, version 3 or later +## See the files "COPYING.lgplv3" and "COPYING.gplv3" +## +## The Modified Berkeley Software Distribution License +## See the file "COPYING.mbsd" +## +## These files have the following md5sums: +## +## 43b91e8ca915626ed3818ffb1b71248b COPYING.gplv3 +## 06a1a2e4760c90ea5e1dad8dfaac4d39 COPYING.lgplv3 +## 66a5cedaf62c4b2637025f049f9b826f COPYING.mbsd + +## This "library" converts texi-isms into man-isms. It gets included +## by the man page template at the point where texi-isms might start appearing +## and then "emit-man-text" is invoked when all the text has been assembled. +## +## Display the command line prototype, +## based only on the argument processing type. +## +## And run the entire output through "sed" to convert texi-isms + +sed \ + -e 's;@code{\([^}]*\)};\\fB\1\\fP;g' \ + -e 's;@var{\([^}]*\)};\\fB\1\\fP;g' \ + -e 's;@samp{\([^}]*\)};\\fB\1\\fP;g' \ + -e 's;@option{\([^}]*\)};\\fB\1\\fP;g' \ + -e 's;@i{\([^}]*\)};\\fI\1\\fP;g' \ + -e 's;@file{\([^}]*\)};\\fI\1\\fP;g' \ + -e 's;@emph{\([^}]*\)};\\fI\1\\fP;g' \ + -e 's;@strong{\([^}]*\)};\\fB\1\\fP;g' \ + -e 's/@\([{}]\)/\1/g' \ + -e 's,^\$\*$,.br,' \ + -e '/@ *example/,/@ *end *example/s/^/ /' \ + -e 's/^ *@ *example/.nf/' \ + -e 's/^ *@ *end *example/.fi/' \ + -e '/^ *@ *noindent/d' \ + -e '/^ *@ *enumerate/d' \ + -e 's/^ *@ *end *enumerate/.br/' \ + -e '/^ *@ *table/d' \ + -e 's/^ *@ *end *table/.br/' \ + -e 's/^@item \(.*\)/.sp\ +.IR "\1"/' \ + -e 's/^@item/.sp 1/' \ + -e 's/\*\([a-zA-Z0-9:~=_ -]*\)\*/\\fB\1\\fP/g' \ + -e 's/``\([a-zA-Z0-9:~+=_ -]*\)'"''"'/\\(lq\1\\(rq/g' \ + -e "s/^'/\\'/" \ + -e 's/^@\*/.br/' \ + -e 's/ -/ \\-/g;s/^\.in \\-/.in -/' diff --git a/sntp/ag-tpl/texi2mdoc b/sntp/ag-tpl/texi2mdoc new file mode 100755 index 000000000..2f37189a7 --- /dev/null +++ b/sntp/ag-tpl/texi2mdoc @@ -0,0 +1,182 @@ +#! /usr/local/bin/bash + +## texi2mdoc.sh -- script to convert texi-isms to mdoc-isms +## +## Time-stamp: "2011-03-30 15:13:15 bkorb" +## +## This file is part of AutoOpts, a companion to AutoGen. +## AutoOpts is free software. +## AutoOpts is Copyright (c) 1992-2011 Bruce Korb - all rights reserved +## +## AutoOpts is available under any one of two licenses. The license +## in use must be one of these two and the choice is under the control +## of the user of the license. +## +## The GNU Lesser General Public License, version 3 or later +## See the files "COPYING.lgplv3" and "COPYING.gplv3" +## +## The Modified Berkeley Software Distribution License +## See the file "COPYING.mbsd" +## +## These files have the following md5sums: +## +## 43b91e8ca915626ed3818ffb1b71248b COPYING.gplv3 +## 06a1a2e4760c90ea5e1dad8dfaac4d39 COPYING.lgplv3 +## 66a5cedaf62c4b2637025f049f9b826f COPYING.mbsd + +## This "library" converts texi-isms into man-isms. It gets included +## by the man page template at the point where texi-isms might start appearing +## and then "emit-man-text" is invoked when all the text has been assembled. +## +## Display the command line prototype, +## based only on the argument processing type. +## +## And run the entire output through "sed" to convert texi-isms + +# /bin/sh on Solaris is too horrible for words +# +case "$0" in +/bin/sh ) test -x /usr/xpg4/bin/sh && exec /usr/xpg4/bin/sh ${1+"$@"} ;; +esac + +parent_pid=$$ +prog=`basename $0 .sh` + +die() { + echo "$prog error: $*" >&2 + kill -TERM $parent_pid + sleep 1 + kill -9 $parent_pid + sleep 1 + exit 1 +} + +do_example() { + echo '.Bd -literal -offset indent' + res=0 + + while : + do + IFS='' read -r line || die "incomplete example" + case "$line" in + '@end '*example ) break ;; + esac + + do_line + done + echo '.Ed' + return $res +} + +do_noindent() { + return 0 +} + +do_enumerate() { + echo '.Bl -enum -compact' + + while : + do + IFS='' read -r line || die "incomplete enumerate" + case "$line" in + '@end '*enumerate ) break ;; + esac + + do_line + done + echo '.El' + + return $res +} + +do_end() { + die "Improper ending: $line" +} + +do_table() { + echo '.Bl -tag -width 8n' + + while : + do + IFS='' read -r line || die "incomplete table" + case "$line" in + '@end '*table ) break ;; + esac + + do_line + done + echo '.El' + + return $res +} + +do_itemize() { + echo '.Bl -bullet -compact' + + while : + do + IFS='' read -r line || die "incomplete itemize" + case "$line" in + '@end '*itemize ) break ;; + esac + + do_line + done + echo '.El' + + return $res +} + +do_item() { + echo "$line" | sed 's/@item/.It/' +} + +do_line() { + case "${line}" in + '@*' ) echo .br ;; + '' ) echo .sp ;; + '@'[{}]* ) echo "${line}" | sed 's/@\([{}]\)/\1/g' ;; + '@'* ) + typ=`echo "$line" | egrep '@[a-z]*\{'` + test ${#typ} -gt 0 && echo "$line" && return 0 + typ=`echo "$line" | sed 's/@ *//;s/[^a-z].*//'` + eval do_${typ} || die "do_${typ} failed" + ;; + + * ) + echo "$line" + ;; + esac + return 0 +} + +fixfont=' +s;@code{\([^}]*\)};\\fB\1\\fP;g +s;@var{\([^}]*\)};\\fB\1\\fP;g +s;@samp{\([^}]*\)};\\fB\1\\fP;g +s;@option{\([^}]*\)};\\fB\1\\fP;g +s;@i{\([^}]*\)};\\fI\1\\fP;g +s;@file{\([^}]*\)};\\fI\1\\fP;g +s;@emph{\([^}]*\)};\\fI\1\\fP;g +s;@strong{\([^}]*\)};\\fB\1\\fP;g +s;@pxref{\([^}]*\)};see: \1;g +s;@xref{\([^}]*\)};see: \1;g +s/@\([{@}]\)/\1/g +s,^[@$]\*$,.br, +s/\*\([a-zA-Z0-9:~=_ -]*\)\*/\\fB\1\\fP/g +s/``\([a-zA-Z0-9:~+=_ -]*\)'\'\''/\\(lq\1\\(rq/g +s/\([^\\]\)-/\1\\-/g +s/\([^\\]\)-/\1\\-/g +/^\.\(Bl\|Bd\|in\) /s/ \\-/ -/g'" +s/^'/\\'/ +/^$/d" +readonly fixfont + +{ + while IFS='' read -r line + do + do_line + done +} | sed "${fixfont}" + +exit 0 diff --git a/sntp/ag-tpl/texi2plain b/sntp/ag-tpl/texi2plain new file mode 100755 index 000000000..043fd8400 --- /dev/null +++ b/sntp/ag-tpl/texi2plain @@ -0,0 +1,62 @@ +#! /usr/local/bin/bash + +## texi2plain -- script to convert texi-isms to plain text +## +## Time-stamp: "2011-01-28 13:09:24 bkorb" +## Author: Jim Van Zandt +## +## This file is part of AutoOpts, a companion to AutoGen. +## AutoOpts is free software. +## AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved +## +## AutoOpts is available under any one of two licenses. The license +## in use must be one of these two and the choice is under the control +## of the user of the license. +## +## The GNU Lesser General Public License, version 3 or later +## See the files "COPYING.lgplv3" and "COPYING.gplv3" +## +## The Modified Berkeley Software Distribution License +## See the file "COPYING.mbsd" +## +## These files have the following md5sums: +## +## 43b91e8ca915626ed3818ffb1b71248b COPYING.gplv3 +## 06a1a2e4760c90ea5e1dad8dfaac4d39 COPYING.lgplv3 +## 66a5cedaf62c4b2637025f049f9b826f COPYING.mbsd + +## This script converts texi-isms into plain text. Its original usage is to +## process command-line argument document and detail text. +## +## We leave any unrecognized tokens alone - this way we have an easier time +## finding them so we can fix them. + +sed \ + -e 's;@code{\([^}]*\)};\1;g' \ + -e 's;@var{\([^}]*\)};\1;g' \ + -e 's;@samp{\([^}]*\)};\1;g' \ + -e 's;@option{\([^}]*\)};\1;g' \ + -e 's;@i{\([^}]*\)};\1;g' \ + -e 's;@file{\([^}]*\)};\1;g' \ + -e 's;@emph{\([^}]*\)};\1;g' \ + -e 's;@strong{\([^}]*\)};\1;g' + +# Tags from texi2man that we probably do not need: +# -e 's/@\([{}]\)/\1/g' \ +# -e 's,^\$\*$,.br,' \ +# -e '/@ *example/,/@ *end *example/s/^/ /' \ +# -e 's/^ *@ *example/.nf/' \ +# -e 's/^ *@ *end *example/.fi/' \ +# -e '/^ *@ *noindent/d' \ +# -e '/^ *@ *enumerate/d' \ +# -e 's/^ *@ *end *enumerate/.br/' \ +# -e '/^ *@ *table/d' \ +# -e 's/^ *@ *end *table/.br/' \ +# -e 's/^@item \(.*\)/.sp\ +#.IR "\1"/' \ +# -e 's/^@item/.sp 1/' \ +# -e 's/\*\([a-zA-Z0-9:~=_ -]*\)\*/\\fB\1\\fP/g' \ +# -e 's/``\([a-zA-Z0-9:~+=_ -]*\)'"''"'/\\(lq\1\\(rq/g' \ +# -e "s/^'/\\'/" \ +# -e 's/^@\*/.br/' \ +# -e 's/ -/ \\-/g;s/^\.in \\-/.in -/' diff --git a/sntp/ag-tpl/texi2txt b/sntp/ag-tpl/texi2txt new file mode 100755 index 000000000..4825e35cc --- /dev/null +++ b/sntp/ag-tpl/texi2txt @@ -0,0 +1,81 @@ +#! /usr/local/bin/perl + +# Author: Harlan Stenn + +# texi2txt: translate texi tokens into displayable text. +# This means: +# - overstrikes (boldface) +# - underscores (italics) + +use strict; +use warnings; + +my $oc = 3; # Number of times to overstrike +my $BS = chr(8); # backspace character + +# For each character in $src: +# - emit the character, a BS, and the character, $oc times (total) +sub OverStrike ($$$) { + my ($pre, $src, $post) = @_; + my @src = split(//, $src); + my $tgt; + + # We don't need to overstrike any BS chars. + for my $c ( @src ) { + $tgt = $tgt.$c; + if ($BS ne $c) { + for (my $i = $oc; $i > 0; $i--) { + $tgt = $tgt.$BS.$c; + } + } + } + + return "$pre$tgt$post"; +}; + +# For each character in $src: +# - emit an underscore, a BS, and the character. +sub UnderLine ($$$) { + my ($pre, $src, $post) = @_; + my @src = split(//, $src); + my $tgt; + + # We don't need to underline any BS chars. + for my $c ( @src ) { + if ($BS eq $c) { + $tgt = $tgt.$c; + } else { + $tgt = $tgt."_".$BS.$c; + } + } + + return "$pre$tgt$post"; +}; + +sub ProcessToken ($) { #line + my ($line) = @_; + $_ = $line; + + my $oldline; + do { + $oldline = $_; + + $_ = UnderLine($1,$3,$4) + if (/(.*)@(i|file|emph){([^}]*)}(.*)/); + } + + $_ = OverStrike($1,$3,$4) + if (/(.*)@(code|var|option|samp|strong){([^}]*)}(.*)/); + + } until ($_ eq $oldline); + + return $_; +} + +### Main program + +while () +{ + chomp; + print ProcessToken($_)."\n"; +};