#! /usr/bin/perl # # This is a simple texi2html converter # # Why I wrote it? # # I wanted to have a small navigational TOC in front of each section and subsection. # I have spent more than a day hunting on information how to do it using texi2html # # I produced this program in 2 hours. (July 26, 2001. 8:06 to 10:03am) # # (Later I extended it, so that took some more time.) # # It is not as functional as the original texi2html, but does what I want. # # Peter Verhas # # sub getitoc { my $p = shift; my $i,$r; return $ITOC{$p} if defined $ITOC{$p}; $r = $p; $p = lc $p; $p =~ s/\W//g; return $ITOC{$p} if defined $ITOC{$p}; for $i (@TOCI){ my $k = lc $TOC{$i}; $k =~ s/\W//; # if( $k eq $p ){ print "Warning: $r is sloppy. It is supposed to be $TOC{$i}\n"; } return $i if $k eq $p; } $p = lc $r; $p =~ s/\s.*$//; $p =~ s/\W.*$//; for $i (@TOCI){ my $k = lc $TOC{$i}; $k =~ s/\s.*$//; $k =~ s/\W.*$//; # if( $k eq $p ){ "Warning: $r is sloppy. It is supposed to be $TOC{$i}\n"; } return $i if $k eq $p; } # print "Warning: xref $r is not defined\n"; return undef; } sub rtfizee { my $line = shift; my $filext = shift; $filext = 'html' unless defined $filext; $line =~ s[\@\@][SAVEALLDOUBLESOBAKA]g; $line =~ s[\\][SAVEALLDBACKSLASH]g; $line =~ s[\@file\{(.*?)\}][\`\{\\f1\\fs18 $1\}\']g; $line =~ s[\@code\{(.*?)\}][\{\\f1\\fs18 $1\}]g; $line =~ s[\@var\{(.*?)\}][\{\\f1\\fs18 $1\}]g; $line =~ s[\@command\{(.*?)\}][\{\\f1\\fs18 $1\}]g; $line =~ s[\@acronym\{(.*?)\}][\{\\f1\\fs18 $1\}]g; $line =~ s[\@b\{(.*?)\}][\{\\b\\f0\\fs18 $1\}]g; $line =~ s[\@strong\{(.*?)\}][\{\\i\\f0\\fs18 $1\}]g; $line =~ s[\@emph\{(.*?)\}][\{\\i\\f0\\fs18 $1\}]g; $line =~ s[\@option\{(.*?)\}][\`{\\f1\\fs18 $1\}\']g; $line =~ s[\@itemize][]g; $line =~ s[\@end\s+itemize][]g; $line =~ s[\@item][]g; $line =~ s[\@\{][\\\{]g; $line =~ s[\@\}][\\\}]g; $line =~ s[\@\$][\$]g; my @linarr = split /\n/ , $line; my $verbatim = 0; for $L ( @linarr ){ if( $L =~ /\@example/ ){ if( $verbatim ){ print $errs; die "Doubled verbatim"; } $errs = ''; $verbatim = 1; $L = "\{\\f1\\fs18"; next; } if( $L =~ /\@end\s+example/ ){ if( ! $verbatim ){ die "Unopened verbatim"; } $L = "\}\n"; $verbatim = 0; next; } if( $verbatim ){ $errs .= $L . "\n"; $L = "$L\\par"; } } if( $verbatim ){ die "unclosed verbatim"; } $line = join("\n",@linarr); # $line =~ s[\@example][\{\\f1\\fs18 ]g; # $line =~ s[\@end\s+example][\\par\}]g; # $line =~ s[\;][\\;]g; if( $filext eq '#' ){ while( $line =~ m[\@xref\{(.*?)\}] ){ my $itoc = &getitoc($1); $line =~ s[\@xref\{(.*?)\}][$1]; } }else{ while( $line =~ m[\@xref\{(.*?)\}] ){ my $itoc = &getitoc($1); $line =~ s[\@xref\{(.*?)\}][$1]; } } $line =~ s[\@uref\{(.*?),(.*?)\}][$2]g; $line =~ s[\@uref\{(.*?)\}][$1]g; $line =~ s[\@email\{(.*?)\}][\{\\f1\\fs18 $1\}]g; $line =~ s[SAVEALLDOUBLESOBAKA][\@]g; $line =~ s[SAVEALLDBACKSLASH][\\\\]g; $line =~ s/\n\n/\n\\par\\par\n/g; $line; } sub htmlizee { my $line = shift; my $filext = shift; $filext = 'html' unless defined $filext; $line =~ s[\@\@][SAVEALLDOUBLESOBAKA]g; $line =~ s[\&][\&]g; $line =~ s[\<][\<]g; $line =~ s[\>][\>]g; $line =~ s[\@file\{(.*?)\}][\`$1\']g; $line =~ s[\@code\{(.*?)\}][$1]g; $line =~ s[\@var\{(.*?)\}][$1]g; $line =~ s[\@command\{(.*?)\}][$1]g; $line =~ s[\@acronym\{(.*?)\}][$1]g; $line =~ s[\@b\{(.*?)\}][$1]g; $line =~ s[\@strong\{(.*?)\}][$1]g; $line =~ s[\@emph\{(.*?)\}][$1]g; $line =~ s[\@option\{(.*?)\}][\`$1\']g; $line =~ s[\@itemize][
]g; $line =~ s[\@end\s+example][]g; $line =~ s[\@\{][\{]g; $line =~ s[\@\}][\}]g; $line =~ s[\@\$][\$]g; if( $filext eq '#' ){ while( $line =~ m[\@xref\{(.*?)\}] ){ my $itoc = &getitoc($1); $line =~ s[\@xref\{(.*?)\}][$1]; } }else{ while( $line =~ m[\@xref\{(.*?)\}] ){ my $itoc = &getitoc($1); $line =~ s[\@xref\{(.*?)\}][$1]; } } $line =~ s[\@uref\{(.*?),(.*?)\}][$2]g; $line =~ s[\@uref\{(.*?)\}][$1]g; $line =~ s[\@email\{(.*?)\}][$1]g; $line =~ s[SAVEALLDOUBLESOBAKA][\@]g; $line =~ s/\n\n/\n\
\n/g;
$line;
}
$infile = shift;
$outfile = shift;
open(F,$infile) or die "Can not open input file $infile";
@lines =