From 3b3fce55d2ac12d0bb1770df88d866bca9e42bb9 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 6 Oct 2017 20:19:34 +0000 Subject: latex2man (6oct17) git-svn-id: svn://tug.org/texlive/trunk@45484 c570f23f-e606-0410-a88d-b1316a301751 --- .../texlive/linked_scripts/latex2man/latex2man | 94 +++++++++++----------- 1 file changed, 49 insertions(+), 45 deletions(-) (limited to 'Build') diff --git a/Build/source/texk/texlive/linked_scripts/latex2man/latex2man b/Build/source/texk/texlive/linked_scripts/latex2man/latex2man index 52e741e475c..07f8d6c6fbe 100755 --- a/Build/source/texk/texlive/linked_scripts/latex2man/latex2man +++ b/Build/source/texk/texlive/linked_scripts/latex2man/latex2man @@ -1,9 +1,10 @@ #!/usr/bin/env perl +#!/usr/bin/perl -w # Project: Documentation Tools # Descr: Latex --> MAN-page (groff -man), HTML and TexInfo; # Language: PERL (>= 5.0) # Author: Dr. Jürgen Vollmer, Juergen.Vollmer@informatik-vollmer.de -# $Id: latex2man,v 1.163 2017/04/13 14:25:56 vollmer Exp $ +# $Id: latex2man,v 1.175 2017/10/06 17:19:31 vollmer Exp $ # # Copyright (C) 1998 Dr. Juergen Vollmer # Am Rennbuckel 21, D-76185 Karlsruhe, Germany @@ -19,15 +20,15 @@ require 5.0004_03; use Getopt::Std; - +no warnings 'once'; # use strict 'vars'; $CMD=`basename $0`; chop ($CMD); $gen_date = `date`; chomp $gen_date; # date when the output was generated sub date2str; -$VERSION = "1.25"; -$DATE = date2str ('$Date: 2017/04/13 14:25:56 $' =~ m|(\d+/\d+/\d+)|); +$VERSION = "1.26"; +$DATE = date2str ('$Date: 2017/10/06 17:19:31 $' =~ m|(\d+/\d+/\d+)|); $tmp = "/tmp/$CMD.$$"; @@ -35,6 +36,8 @@ $tmp = "/tmp/$CMD.$$"; # check option and arguments ################################################################## +$opt_D = 0; +$opt_M = 0; getopts('o:t:c:VhMHTLC:D:a:'); # -D1: write each read line -D2: write each word sub usage @@ -127,6 +130,7 @@ $DestFile = $ARGV[1]; # global variables # $Prefix is used to construct procedure and variable names +$Prefix = ""; if ($opt_M) { $Prefix = "man"; } @@ -156,7 +160,7 @@ $inside_verb = 0; # true, if inside a verbatim environment $inside_table = 0; # true, if inside a table environment $first_column = 0; # true, if this is the first column in a table row $columns = 0; # nr of columns in the current table -$enum_nr = 0; # current number of an enumeration +# $enum_nr = 0; # current number of an enumeration $nesting = 0; # count recursive calls of interpret_word $section_cnt = 0; # Index into $sections #$sections[0] # Array of all sections @@ -723,7 +727,7 @@ sub manDescriptionEnd { if ($manRS) { Print '\n.RE\n'; - $manRS == 0; + $manRS = 0; } if ($list_nest > 1) { Print '\n.RE\n'; @@ -742,7 +746,7 @@ sub manItemEnd { if ($manRS) { Print '\n.RE\n'; - $manRS == 0; + $manRS = 0; } if ($list_nest > 1) { Print '\n.RE\n'; @@ -754,7 +758,7 @@ sub manEnumEnd { if ($manRS) { Print '\n.RE\n'; - $manRS == 0; + $manRS = 0; } if ($list_nest > 1) { Print '\n.RE\n'; @@ -1188,7 +1192,7 @@ sub texiVerbatimEnd sub texiVerbatimLine { - s/({|}|@| )/@\1/g; + s/(\{|\}|@| )/\@$1/g; chop; print DEST ".$_\@*\n"; } @@ -1326,7 +1330,7 @@ sub interpret_word last SWITCH; }; # LaTeX macros with two arguments - /\\([a-zA-Z]+){([^}]*)}{([^}]*)}/ + /\\([a-zA-Z]+)\{([^}]*)\}\{([^}]*)\}/ && do {$s=$`;$m=$1;$a1=$2;$a2=$3;$r=$'; #' check_Macro2 $m; interpret_word $s; @@ -1340,7 +1344,7 @@ sub interpret_word last SWITCH; }; # Special Handling of Email and URL LaTeX macros with one argument - /\\(URL|Email){([^}]*)}/ && ($opt_H) + /\\(URL|Email)\{([^}]*)\}/ && ($opt_H) && do {$s=$`;$m=$1;$a1=$2;$r=$'; #' interpret_word $s; PrintM $Macro2a->{$m}; @@ -1353,7 +1357,7 @@ sub interpret_word last SWITCH; }; # LaTeX macros with one argument - /\\([a-zA-Z]+){([^}]*)}/ && do {$s=$`;$m=$1;$a1=$2;$r=$'; #' + /\\([a-zA-Z]+)\{([^}]*)\}/ && do {$s=$`;$m=$1;$a1=$2;$r=$'; #' check_Macro1 $m; interpret_word $s; PrintM $Macro1a->{$m}; @@ -1513,15 +1517,15 @@ sub interpret_line if (/\\item/) { my $cnt1 = tr/[/[/; my $cnt2 = tr/]/]/; - $join = $cnt1 != $cnt2 | $cnt1 == 0; + $join = $cnt1 != $cnt2 || $cnt1 == 0; $kind = 1; } elsif (/\\verb/) { my $cnt = tr/+/+/; $join = $cnt % 2 != 0; $kind = 3; } else { - my @x = $_ =~ /[^\\]{/g; - my @y = $_ =~ /[^\\]}/g; + my @x = $_ =~ /[^\\]\{/g; + my @y = $_ =~ /[^\\]\}/g; $join = $#x != $#y; $kind = 2; } @@ -1681,7 +1685,7 @@ sub emit_LaTeX my $line = $_; chop $line; print "--- \`$line'\n"; } - if (/^\s*\\input{([^}]*)}\s*/) { + if (/^\s*\\input\{([^}]*)\}\s*/) { # handle \input{fn} my $fn = $1; printf DEST "%%%%%%%%%%%%%%%%%% start of \\input{%s}\n", $fn; @@ -1733,7 +1737,7 @@ sub emit_NonLaTeX my $line = $_; chop $line; print "--- \`$line'\n"; } - if (/^\s*\\input{([^}]*)}\s*/) { + if (/^\s*\\input\{([^}]*)\}\s*/) { # handle \input{fn} my $fn = $1; if ($opt_M) { @@ -1762,7 +1766,7 @@ sub emit_NonLaTeX next if ($skip[-1] == 1); if ($inside_verb) { - if (/^\s*\\end{verbatim}/) { + if (/^\s*\\end\{verbatim\}/) { if ($started == 1) { &{$Prefix . "VerbatimEnd"}; $inside_verb = 0; @@ -1774,8 +1778,8 @@ sub emit_NonLaTeX } # remove {, } around Umlaute - s/{(\\".)}/\1/g; # " - s/{(\\ss)}/\1/g; + s/\{(\\".)\}/$1/g; # " + s/\{(\\ss)\}/$1/g; # normalize special characters s/\\"a/ä/g; @@ -1791,19 +1795,19 @@ sub emit_NonLaTeX $rcs_date,$rcs_time,$rcs_owner,$rcs_status,$rcs_locker) = split(/\s/,$1); $date = date2str ($rcs_date); $Macro->{'today'} = $date; - } elsif (/^\s*\\setDate{\\rcsInfoLongDate}/) { + } elsif (/^\s*\\setDate\{\\rcsInfoLongDate\}/) { $Macro->{'Date'} = $date; - } elsif (/^\s*\\setDate{\\today}/) { + } elsif (/^\s*\\setDate\{\\today\}/) { $Macro->{'Date'} = $date; - } elsif (/^\s*\\setDate{([^}]*)}/) { + } elsif (/^\s*\\setDate\{([^}]*)\}/) { $date = $1; $date =~ s/~/$Macro->{'~'}/g; $Macro->{'Date'} = $date; - } elsif (/^\s*\\setVersion{([^}]*)}/) { + } elsif (/^\s*\\setVersion\{([^}]*)\}/) { $version = $1; - $versin =~ s/~/$Macro->{'~'}/g; + $version =~ s/~/$Macro->{'~'}/g; $Macro->{'Version'} = $version; - } elsif (/^\s*\\begin{Name}{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}{([^}]*)}/) { + } elsif (/^\s*\\begin\{Name\}\{([^}]*)\}\{([^}]*)\}\{([^}]*)\}\{([^}]*)\}\{([^}]*)\}/) { $section = "Name"; $chapter = $1; $name = $2; @@ -1812,90 +1816,90 @@ sub emit_NonLaTeX $tool = $4; $title = $5; $rest = $'; #' - $started = 1; + $started = 1; $sections[0] = $section; $section_cnt = 0; &{$Prefix . "Start"} ($name, $chapter, $author, $tool, $title); &{$Prefix . "NameStart"} ($name, $chapter, $author, $tool, $title); - } elsif (/^\s*\\end{Name}/) { + } elsif (/^\s*\\end\{Name\}/) { &{$Prefix . "NameEnd"} ($name, $chapter, $author, $tool); - } elsif (/^\s*\\begin{Table}(\[([^]]*)\])?{([^}]*)}/) { + } elsif (/^\s*\\begin\{Table\}(\[([^]]*)\])?\{([^}]*)\}/) { # \begin{Table}[width]{columns} if ($started == 1) { $columns = $3; - $column = $_[0]; + # $column = $_[0]; $inside_table = 1; $first_column = 1; &{$Prefix . "TableStart"} ($columns, $2); } - } elsif (/^\s*\\end{Table}/) { + } elsif (/^\s*\\end\{Table\}/) { if ($started == 1) { $inside_table = 0; $first_column = 0; &{$Prefix . "TableEnd"} ($columns); } - } elsif (/^\s*\\begin{Description}(\[[^]]*\])?/) { + } elsif (/^\s*\\begin\{Description\}(\[[^]]*\])?/) { if ($started == 1) { $list_nest++; $cur_list[$list_nest] = 'descr'; $item_nr[$list_nest] = 0; &{$Prefix . "DescriptionStart"}; } - } elsif (/^\s*\\end{Description}/) { + } elsif (/^\s*\\end\{Description\}/) { if ($started == 1) { &{$Prefix . "DescriptionEnd"}; $list_nest--; } - } elsif (/^\s*\\begin{description}/) { + } elsif (/^\s*\\begin\{description\}/) { if ($started == 1) { $list_nest++; $cur_list[$list_nest] = 'descr'; $item_nr[$list_nest] = 0; &{$Prefix . "DescriptionStart"}; } - } elsif (/^\s*\\end{description}/) { + } elsif (/^\s*\\end\{description\}/) { if ($started == 1) { &{$Prefix . "DescriptionEnd"}; $list_nest--; } - } elsif (/^\s*\\begin{center}/) { + } elsif (/^\s*\\begin\{center\}/) { if ($started == 1) { &{$Prefix . "CenterStart"}; } - } elsif (/^\s*\\end{center}/) { + } elsif (/^\s*\\end\{center\}/) { if ($started == 1) { &{$Prefix . "CenterEnd"}; } - } elsif (/^\s*\\begin{enumerate}/) { + } elsif (/^\s*\\begin\{enumerate\}/) { if ($started == 1) { $list_nest++; $cur_list[$list_nest] = 'enum'; $item_nr[$list_nest] = 0; &{$Prefix . "EnumStart"} ; } - } elsif (/^\s*\\end{enumerate}/) { + } elsif (/^\s*\\end\{enumerate\}/) { if ($started == 1) { &{$Prefix . "EnumEnd"} ; $list_nest--; } - } elsif (/^\s*\\begin{itemize}/) { + } elsif (/^\s*\\begin\{itemize\}/) { if ($started == 1) { $list_nest++; $cur_list[$list_nest] = 'item'; $item_nr[$list_nest] = 0; &{$Prefix . "ItemStart"} ; } - } elsif (/^\s*\\end{itemize}/) { + } elsif (/^\s*\\end\{itemize\}/) { if ($started == 1) { &{$Prefix . "ItemEnd"} ; $list_nest--; } - } elsif (/^\s*\\begin{verbatim}/) { + } elsif (/^\s*\\begin\{verbatim\}/) { if ($started == 1) { &{$Prefix . "VerbatimStart"}; $inside_verb = 1; } - } elsif (/^\s*\\(subsubsection|subsection|section){([^}]*)}/) { + } elsif (/^\s*\\(subsubsection|subsection|section)\{([^}]*)\}/) { $kind = $1; $section = $2; $section_cnt ++; @@ -1904,9 +1908,9 @@ sub emit_NonLaTeX if ($started == 1) { &{$Prefix . "Section"} ($section_cnt, $kind, $section); } - } elsif (/^\s*\\LatexManEnd/) { + } elsif (/^\s*\\LatexManEnd/ || /^\s*\\end\{document\}/) { last; - } elsif (/^\s*((\\begin{Name|Table|Description})|(\\(sub)?section))/) { + } elsif (/^\s*((\\begin\{Name|Table|Description\})|(\\(sub)?section))/) { die "$CMD: in line $.\n " . "Arguments of $1 are not contained in a single " . "line.\n " . -- cgit v1.2.3