Commit c9adf651 authored by Tom Barbette's avatar Tom Barbette

Merge remote-tracking branch 'kohler_click/master'

parents 63bc8da9 a4604141
......@@ -695,6 +695,7 @@ LIBOBJS
freebsd_includedir
freebsd_srcdir
FINDELEMFLAGS
all_element_groups
element_groups
linux_srcdir
linux_builddir
......@@ -7544,12 +7545,15 @@ else
fi
for i in `(cd $srcdir/elements; ls | sed '/^CVS$/d;/^bsdmodule$/d;/^linuxmodule$/d;/^ns$/d;/^userlevel$/d;/^minios$/d')`; do
all_element_groups=
for i in `(cd $srcdir/elements; ls | sed '/^CVS$/d;/^\.git/d;/^bsdmodule$/d;/^linuxmodule$/d;/^ns$/d;/^userlevel$/d;/^minios$/d')`; do
enableval=`eval 'echo $'"enable_$i"`
test "x$enable_all_elements" = xyes -a "x$enableval" '!=' xno && enableval=yes
test -d "$srcdir/elements/$i" -a "$enableval" = "yes" && element_groups="$element_groups $i"
test -d "$srcdir/elements/$i" && all_element_groups="$all_element_groups$i "
done
FINDELEMFLAGS=
if test "x$enable_skip_elements" != xno -a "x$enable_skip_elements" != xyes; then
FINDELEMFLAGS="-x '$enable_skip_elements'"
......
......@@ -617,11 +617,14 @@ ELEMENTS_ARG_ENABLE(wifi, [include wifi elements and support], NO)
AC_ARG_ENABLE(experimental, [AS_HELP_STRING([--enable-experimental], [enable experimental elements in normal groups])], :, enable_experimental=no)
AC_ARG_ENABLE(skip-elements, [AS_HELP_STRING([--enable-skip-elements=ELTS], [disable comma-separated elements])], :, enable_skip_elements=no)
for i in `(cd $srcdir/elements; ls | sed '/^CVS$/d;/^bsdmodule$/d;/^linuxmodule$/d;/^ns$/d;/^userlevel$/d;/^minios$/d')`; do
all_element_groups=
for i in `(cd $srcdir/elements; ls | sed '/^CVS$/d;/^\.git/d;/^bsdmodule$/d;/^linuxmodule$/d;/^ns$/d;/^userlevel$/d;/^minios$/d')`; do
enableval=`eval 'echo $'"enable_$i"`
test "x$enable_all_elements" = xyes -a "x$enableval" '!=' xno && enableval=yes
test -d "$srcdir/elements/$i" -a "$enableval" = "yes" && element_groups="$element_groups $i"
test -d "$srcdir/elements/$i" && all_element_groups="$all_element_groups$i "
done
AC_SUBST([all_element_groups])
FINDELEMFLAGS=
if test "x$enable_skip_elements" != xno -a "x$enable_skip_elements" != xyes; then
......
......@@ -89,6 +89,22 @@ doxygen:
-e "s#^GENERATE_LATEX.*#GENERATE_LATEX = NO#" \
< $(srcdir)/Doxyfile | (cd $(top_srcdir); doxygen -)
MAN2MARKDOWN_ARGS = --xlink click.1=Userlevel --xlink click.o.8=Linuxmodule --xlink click.5=Language \
--xlink elements.n=Elements
MARKDOWN_PROVISIONS = userlevel linuxmodule ns @all_element_groups@ experimental \
smpclick int64 dpdk linux netmap pcap umultithread
install-man-markdown:
@if test -z "$(O)"; then echo 1>&2; echo "Run 'make install-man-markdown O=OUTPUTDIRECTORY'" 1>&2; echo 1>&2; false; fi
for i in click-align click-combine click-devirtualize click-fastclassifier click-flatten click-install click-mkmindriver click-pretty click-uncombine click-undead click-uninstall click-xform; do \
$(PERL) $(srcdir)/man2html --markdown -l $(MAN2MARKDOWN_ARGS) $(srcdir)/$$i.1 -d $(O) -o $(O)/$$i.md; \
done
$(PERL) $(srcdir)/man2html --markdown $(MAN2MARKDOWN_ARGS) -l $(srcdir)/click.1 -d $(O) -o $(O)/Userlevel.md
$(PERL) $(srcdir)/man2html --markdown $(MAN2MARKDOWN_ARGS) -l $(srcdir)/click.5 -d $(O) -o $(O)/Language.md
$(PERL) $(srcdir)/man2html --markdown $(MAN2MARKDOWN_ARGS) -l $(srcdir)/click.o.8 -d $(O) -o $(O)/Linuxmodule.md
$(PERL) $(srcdir)/man2html --markdown $(MAN2MARKDOWN_ARGS) -l $(srcdir)/elementdoc.7 -d $(O) -o $(O)/Elementdoc.md
echo $(MARKDOWN_PROVISIONS) | $(top_builddir)/bin/click-buildtool findelem -r "$(MARKDOWN_PROVISIONS)" -p $(top_srcdir) | $(PERL) $(top_srcdir)/click-mkelemmap -r "$(PROVISIONS)" -t "userlevel linuxmodule ns" -p "$(top_srcdir)" -Iinclude -s "`cd $(top_srcdir) && pwd`" | $(PERL) $(srcdir)/click-elem2man -d $(O) --markdown -l -p $(top_srcdir) -
always:
@:
......@@ -99,4 +115,4 @@ distclean: clean
.PHONY: all clean distclean always \
install install-man uninstall uninstall-man \
doxygen
doxygen install-man-markdown
......@@ -673,7 +673,7 @@ my(%markdown_podentities) =
'verbar' => '|', 'eq' => '=', 'star' => '*', 'lparen' => '(',
'rparen' => ')', 'lbrack' => '[', 'rbrack' => ']', 'lbrace' => '{',
'rbrace' => '}' );
my($markdown_sensitive_char) = "[&\\[\\]#*_~&`]";
my($markdown_sensitive_char) = "[&\\[\\]#*_~`]";
my($markdown_was_short_item) = 0;
sub markdown_unentity ($) {
......@@ -750,6 +750,10 @@ sub markdownize_text ($$) {
# remove self references
$t =~ s{\[$PrimaryElement\]\($PrimaryElement\)}{$PrimaryElement}g;
# quote colons that look like emoji escapes, and numbers that look like lists
$t =~ s{:(?=[-+_a-z0-9]+:)}{\\:}ig;
$t =~ s{^(\d+)\. }{$1\\. }mg;
$t;
}
......@@ -763,9 +767,9 @@ sub markdownize ($$) {
my(@x) = split(/(^ .*$)/m, $t);
my($o, $i) = '';
for ($i = 0; $i < @x; $i += 2) {
if ($x[$i]) {
if ($x[$i] && $x[$i] ne "\n") {
$o .= markdownize_text($x[$i], $indent);
$o .= "\n" if $o !~ /\n\Z/;
$o =~ s{\n*\z}{\n\n};
}
if ($x[$i+1]) {
$o .= $indent . " " . $x[$i+1] . "\n";
......@@ -804,9 +808,10 @@ sub markdown_do_section ($$$) {
}
if ($name eq 'head1') {
print OUT "\n## ", markdownize($args, ""), " ##\n\n";
$section_name = markdownize($args, "");
print OUT "\n", $section_name, "\n", ("-" x length($section_name)), "\n\n";
} elsif ($name eq 'head2') {
print OUT "\n### ", markdownize($args, ""), " ###\n\n";
print OUT "\n### ", markdownize($args, ""), "\n\n";
} elsif ($name eq 'over') {
if ($args =~ /^\s*(\d+)\s*$/s) {
push @Over, $1;
......@@ -815,18 +820,21 @@ sub markdown_do_section ($$$) {
print STDERR "click-elem2man: $Filename: bad arguments to '=over'\n";
}
} elsif ($name eq 'item') {
print OUT (" " x ($nover ? $nover - 1 : 0)), "* ";
my($bullet) = (" " x ($nover ? $nover - 1 : 0)) . "* ";
my($itemtext) = markdownize($args, "");
if (length($itemtext) <= 40 && $text !~ /\S\n\n+\S/) {
print OUT $itemtext, " — ";
if (length($itemtext) <= 70) {
my($is_short_item) = $text !~ /\S\n\n+\S/;
print OUT "\n" if !$is_short_item && $markdown_was_short_item;
print OUT $bullet, $itemtext, " —\n";
$text =~ s{\A\n+}{};
$text =~ s{\n+\z}{};
$closer = "\n";
$nover = 0;
$markdown_was_short_item = 1;
if ($is_short_item) {
$text =~ s{\n+\z}{};
$closer = "\n";
$nover = 0;
$markdown_was_short_item = 1;
}
} else {
print OUT "\n" if $markdown_was_short_item;
print OUT $itemtext, "\n\n";
print OUT $bullet, $itemtext, "\n\n";
}
} elsif ($name eq 'back') {
my($overarg);
......@@ -864,13 +872,9 @@ sub markdown_do_section ($$$) {
$markdown_was_short_item = 0;
return;
} elsif ($name eq 'name!') {
print OUT <<"EOD;";
# $args Element Documentation #
## NAME ##
**$args** $text
EOD;
$s = "$args Element Documentation";
print OUT $s, "\n", "=" x length($s), "\n\nNAME\n----\n\n",
"**$args** — $text\n";
return;
} elsif ($name eq 'end!') {
print OUT "\n\nGenerated by click-elem2man from <code>$Filename</code> on $today.\n";
......@@ -886,9 +890,9 @@ sub markdown_elementlist ($@) {
my($sec) = shift @_;
my($t);
if ($sec eq "Alphabetical") {
$t = "## Alphabetically ##\n\n";
$t = "Alphabetical list\n-----------------\n\n";
} else {
$t = "### $sec ###\n\n";
$t = "$sec\n" . ("-" x length($sec)) . "\n\n";
}
foreach $_ (sort { lc($a) cmp lc($b) } @_) {
my($os) = $all_outsections{$_};
......@@ -1157,8 +1161,7 @@ sub process_comment ($$$) {
print STDERR "Uninstalled $main_outname\n" if $verbose;
unlink($main_outname);
open(OUT, ">/dev/null");
} elsif ($gzip ? open(OUT, "|gzip -9 >$main_outname")
: open(OUT, ">$main_outname")) {
} elsif ($gzip ? open(OUT, "|-", "gzip -9 >'$main_outname~'") : open(OUT, ">", $main_outname . "~")) {
print STDERR "Writing to $main_outname\n" if $verbose;
} else {
print STDERR "$main_outname: $!\n";
......@@ -1309,6 +1312,27 @@ sub process_comment ($$$) {
# close output file & make links if appropriate
if ($filename_func) {
close OUT;
if ($gzip ? open(INX, "-|", "gzcat", $main_outname) : open(INX, "<", $main_outname)) {
$gzip ? open(OUTX, "-|", "gzcat", $main_outname . "~") : open(OUTX, "<", $main_outname . "~");
local($/) = undef;
my($in) = <INX>;
my($out) = <OUTX>;
close INX;
close OUTX;
if (defined($in) && defined($out) && $in ne "" && $out ne "") {
$in =~ s{\nGenerated by click-elem2man[^\n]*\n+\z}{};
$out =~ s{\nGenerated by click-elem2man[^\n]*\n+\z}{};
if ($in eq $out) {
unlink($main_outname . "~");
print STDERR "No changes to $main_outname\n" if $verbose;
return;
}
}
}
rename("$main_outname~", $main_outname);
for ($i = 1; $i < @outfiles; $i++) {
my($outname) = &$filename_func($outfiles[$i], $outsections[$i], 0);
print STDERR "Unlinking $outname\n" if $verbose;
......@@ -1335,7 +1359,10 @@ sub process_file ($;$) {
if ($filename ne "<stdin>") {
$filename = "include/$1" if !-e $filename && $filename =~ /^<(.*)>$/s;
$filename = "$PREFIX/$filename" if !-e $filename && defined($PREFIX);
return if !-e $filename;
if (!-e $filename) {
print STDERR "$filename: Not found\n";
return;
}
}
print STDERR "Found $filename\n" if $verbose;
if (!defined($text)) {
......@@ -1685,9 +1712,15 @@ sub markdown_filename_func ($$$) {
if ($destroy) {
();
} elsif ($sec eq $man_section) {
"$directory/" . lc($name) . ".md$gzip";
if ($name eq "elements") {
return "$directory/Elements.md$gzip";
} elsif ($name =~ /^elements-(.*)$/) {
return "$directory/" . ucfirst($1) . "-Elements.md$gzip";
} else {
return "$directory/" . $name . ".md$gzip";
}
} else {
"$directory/" . lc($name) . "-$sec.md$gzip";
return "$directory/" . $name . "-$sec.md$gzip";
}
}
......@@ -1790,8 +1823,13 @@ sub one_summary ($@) {
}
}
my($a) = $name;
$a =~ s{([+\&\#\"\000-\037\177-\377])}{sprintf("%%%02X", ord($1))}eg;
$a =~ tr/ /+/;
if ($output_type eq "markdown") {
$a =~ s{[^a-zA-Z0-9_]+}{-}g;
$a = lc($a);
} else {
$a =~ s{([+\&\#\"\000-\037\177-\377])}{sprintf("%%%02X", ord($1))}eg;
$a =~ tr/ /+/;
}
my($x) = $name;
$x =~ s{ }{&nbsp;}g;
if (@elts) {
......@@ -1822,7 +1860,21 @@ sub write_elementlist ($$) {
return;
}
print OUT <<"EOD;";
if ($output_type eq "markdown") {
my($title);
if ($enamebase eq "elements") {
$title = "Elements";
} elsif ($enamebase eq "elements-click") {
$title = "Click Elements";
} elsif ($enamebase =~ /^elements-(.*)$/) {
$title = ucfirst($1) . " Package Elements";
} else {
$title = ucfirst($title);
}
print OUT $title, "\n", ("=" x length($title)), "\n\n",
"This page lists Click element classes that have manual page documentation.\n\n";
} else {
print OUT <<"EOD;";
.\\" -*- mode: nroff -*-
.\\" Generated by 'click-elem2man'
$nroff_prologue
......@@ -1832,6 +1884,7 @@ $enamebase \- documented Click element classes
.SH "DESCRIPTION"
This page lists all Click element classes that have manual page documentation.
EOD;
}
$Text = "";
%el_generated = ();
......@@ -1848,13 +1901,18 @@ EOD;
one_summary('Miscellaneous', grep { !$el_generated{$_} } @all_outfiles);
my($links) = join("&nbsp;- ", @Links);
print OUT <<"EOD;";
if ($output_type eq "markdown") {
print OUT "**By function:** ", $links, "\n\n";
print OUT "**[Alphabetical list](#alphabetical-list)**\n\n";
} else {
print OUT <<"EOD;";
.\\"html <p><a href="#BY+FUNCTION"><b>By Function</b></a>:
.\\"html $links<br>
.\\"html <a href="#ALPHABETICAL+LIST"><b>Alphabetical List</b></a></p>
.SH \"BY FUNCTION\"
EOD;
}
print OUT ".SH \"BY FUNCTION\"\n";
print OUT $Text;
print OUT &$elementlist_func("Alphabetical", @all_outfiles);
......
......@@ -7,7 +7,7 @@ $pp_pos = 0;
sub pp_open ($$$) {
local($o, $f, $c) = @_;
if ($pp_pos > 0) {
$pp_pos++;
print STDERR ' ';
......@@ -16,10 +16,10 @@ sub pp_open ($$$) {
$pp_pos = 0;
}
}
$pp_pos += length($o.$f.$c);
print STDERR $o, $f;
push(@pp_closers, $c);
}
......@@ -42,7 +42,7 @@ Try `man2html --help' for more information.\n";
sub help () {
print STDERR <<'EOD;';
`Man2html' translates UNIX manual pages into HTML.
'Man2html' translates UNIX manual pages into HTML.
Usage: man2html [-l] [-t TEMPLATE] [MANFILE] [HTMLFILE]
man2html -d DIR [-l] [-t TEMPLATE] MANFILES...
......@@ -54,9 +54,11 @@ Options:
output file.
-d, --directory DIR Place generated HTML files in directory DIR.
-l, --link Make hyperlinks for manual page crossreferences.
-m, --marker A@B Hyperlinks to current manual page `<a>text</a>'
replaced with `AtextB'.
-o, --output OUTFILE
-m, --marker A@B Hyperlinks to current manual page `<a>text</a>`
replaced with `AtextB`.
--no-recursive Do not search subdirectories.
--markdown Generate Markdown output.
-f, --force Ignore file errors.
-h, --help Print this message and exit.
......@@ -65,107 +67,125 @@ EOD;
exit 0;
}
undef $directory;
undef $template;
undef $output_file;
$self_link_marker = "";
$self_link_post_marker = "";
my($directory, $template, $ouptut_file);
my $self_link_marker = "";
my $self_link_post_marker = "";
my $replace = 0;
my %hyperlink_man;
@files = ();
$links = 0;
$recursive = 1;
$force = 0;
my $markdown = 0;
$QUOTES = 0;
while (@ARGV) {
$_ = shift;
if (/^-/) {
if (/^-$/) {
push @files, "";
} elsif (/^-d$/ || /^--directory$/) {
die if defined $directory || @ARGV == 0;
$directory = shift;
} elsif (/^-d(.*)$/ || /^--directory=(.*)$/) {
die if defined $directory;
$directory = $1;
} elsif (/^--no-recursive$/) {
$recursive = 0;
} elsif (/^-f$/ || /^--force$/) {
$force = 1;
} elsif (/^-t$/ || /^--template$/) {
die if defined $template || @ARGV == 0;
$template = shift;
} elsif (/^-t(.*)$/ || /^--template=(.*)$/) {
die if defined $template;
$template = $1;
} elsif (/^-r$/ || /^--replace$/) {
die if defined $template || @ARGV == 0;
$template = $output_file = shift;
} elsif (/^-r(.*)$/ || /^--replace=(.*)$/) {
die if defined $template;
$template = $output_file = $1;
} elsif (/^-l$/ || /^--links$/) {
$links = 1;
} elsif (/^-h$/ || /^--help$/) {
help;
} elsif (/^-m$/ || /^--marker$/) {
die if $self_link_marker || @ARGV == 0;
$self_link_marker = shift;
} elsif (/^-m(.*)$/ || /^--marker=(.*)$/) {
die if $self_link_marker;
$self_link_marker = $1;
$_ = shift;
if (/^-/) {
if (/^-$/) {
push @files, "";
} elsif (/^-d$/ || /^--directory$/) {
die if defined $directory || @ARGV == 0;
$directory = shift;
} elsif (/^-d(.*)$/ || /^--directory=(.*)$/) {
die if defined $directory;
$directory = $1;
} elsif (/^--no-recursive$/) {
$recursive = 0;
} elsif (/^-f$/ || /^--force$/) {
$force = 1;
} elsif (/^-t$/ || /^--template$/) {
die if defined $template || @ARGV == 0;
$template = shift;
} elsif (/^-t(.*)$/ || /^--template=(.*)$/) {
die if defined $template;
$template = $1;
} elsif (/^-r$/ || /^--replace$/) {
die if defined $template || @ARGV == 0;
$template = $output_file = shift;
} elsif (/^-r(.*)$/ || /^--replace=(.*)$/) {
die if defined $template;
$template = $output_file = $1;
} elsif (/^-l$/ || /^--links$/) {
$links = 1;
} elsif (/^-h$/ || /^--help$/) {
help;
} elsif (/^--(?:markd|markdo|markdow|markdown)$/) {
$markdown = 1;
} elsif (/^-m$/ || /^--marker$/) {
die if $self_link_marker || @ARGV == 0;
$self_link_marker = shift;
} elsif (/^-m(.*)$/ || /^--marker=(.*)$/) {
die if $self_link_marker;
$self_link_marker = $1;
} elsif (/^--xlink$/) {
die if @ARGV == 0 || $ARGV[0] !~ /\A(\S+)=(.*)/;
$hyperlink_man{$1} = "$2.html";
shift;
} elsif (/^--xlink=(\S+)=(.*)$/) {
$hyperlink_man{$1} = "$2.html";
} elsif (/^-o$/ || /^--output$/) {
die if $output_file || @ARGV == 0;
$output_file = shift;
} elsif (/^-o(.*)$/ || /^--output=(.*)$/) {
die if $output_file;
$output_file = $1;
} else {
print STDERR "man2html: unrecognized option `$_'\n";
usage;
}
} else {
print STDERR "man2html: unrecognized option `$_'\n";
usage;
push @files, $_;
}
} else {
push @files, $_;
}
}
if (@files > 2 && !defined $directory) {
die "more than one file and no \`--directory'";
die "more than one file and no \`--directory'";
}
if (@files != 1 && defined $output_file) {
die "--replace requires exactly one input file";
die "--replace/--output requires exactly one input file";
}
if (@files == 0) {
push @files, '';
}
@ffiles = @files; @files = ();
foreach $dir (@ffiles) {
if ($dir ne '' && -d $dir && $recursive) {
if (opendir(DIR, $dir)) {
push @files, map { "$dir/$_" } grep(/[^.].*.[1-9ln]/, readdir DIR);
closedir DIR;
if ($dir ne '' && -d $dir && $recursive) {
if (opendir(DIR, $dir)) {
push @files, map { "$dir/$_" } grep(/[^.].*.[1-9ln]/, readdir DIR);
closedir DIR;
} else {
print "$dir: $!\n";
}
} else {
print "$dir: $!\n";
push @files, $dir;
}
} else {
push @files, $dir;
}
}
$output_dir = $directory if defined($directory);
$output_dir = $1 if !defined($output_dir) && defined($output_file) && $output_file =~ m|^(.*)/[^/]*$|;
my $linksuffix = $markdown ? "md" : "html";
if (defined $output_dir) {
opendir(DIR, $output_dir) || die "$output_dir: $!\n";
foreach $i (grep { /^([^.].*\..*)\.html$/ } readdir(DIR)) {
$hyperlink_man{substr($i, 0, -5)} = 1;
}
opendir(DIR, $output_dir) || die "$output_dir: $!\n";
foreach $i (grep { /^([^.].*(?:\.[1-9n])?)\.$linksuffix$/ } readdir(DIR)) {
my($f) = $i;
$f =~ s{\.(?:html|md)}{};
$hyperlink_man{$f} = $f . ".html";
}
}
foreach $i (@files) {
$i =~ m{([^/]*)$}s;
$hyperlink_man{$1} = 1;
$i =~ m{([^/]*)$}s;
$hyperlink_man{$1} = $i . ".html";
}
if (defined $template) {
open T, $template || die "$template: $!\n";
undef $/;
$template = <T>;
close T;
$/ = "\n";
open T, $template || die "$template: $!\n";
undef $/;
$template = <T>;
close T;
$/ = "\n";
}
if ($self_link_marker =~ /^(.*)\@(.*)$/) {
($self_link_marker, $self_link_post_marker) = ($1, $2);
($self_link_marker, $self_link_post_marker) = ($1, $2);
}
......@@ -176,50 +196,55 @@ sub error {
sub get_line () {
if (@pushed_lines) {
$_ = shift @pushed_lines;
return defined($_);
$_ = shift @pushed_lines;
return defined($_);
} else {
$_ = <IN>;
return 1 if /^\.\\\"/;
return 0 if !defined($_);
s/\\\\/\300/g;
s/\\[|&]/\377/g;
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
s/\\e/&backsl;/g;
s/\\([-+])/\1/g;
s{\\%( *)}{"<tt>&nbsp;</tt>" x length($1)}eg;
s/\\\(em/&sp;--&sp;/g;
s/\\\(bu/*/g;
s/\\~/&nbsp;/g;
s#\\f\(CW#<T>#gx;
s#\\f\(BI#<Q>#gx;
s#\\f([RPIB])#<\1>#gx;
s#\\s-1#<SMALL>#gx;
s#\\s0#<NORMAL>#gx;
s#\\ #&nbsp;#g;
s/\\\*\((..)/$STR{$1}/eg;
s/\\\*(.)/$STR{$1}/eg;
s/\\".*//;
tr/\300/\\/;
return 1;
$_ = <IN>;
return 1 if /^\.\\\"/;
return 0 if !defined($_);
s/\\\\/\300/g;
s/\\[|&]/\377/g;
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
s/\\e/&backsl;/g;
s/\\([-+])/\1/g;
s{\\%( *)}{"<tt>&nbsp;</tt>" x length($1)}eg;
s/\\\(em/—/g;
s/\\\(bu/*/g;
s/\\\(lq/“/g;
s/\\\(rq/”/g;
s/\\\(oq/‘/g;
s/\\\(cq/’/g;
s/\\\(co/©/g;
s/\\~/&nbsp;/g;
s#\\f\(CW#<T>#gx;
s#\\f\(BI#<Q>#gx;
s#\\f([RPIB])#<\1>#gx;
s#\\s-1#<SMALL>#gx;
s#\\s0#<NORMAL>#gx;
s#\\ #&nbsp;#g;
s/\\\*\((..)/$STR{$1}/eg;
s/\\\*(.)/$STR{$1}/eg;
s/\\".*//;
tr/\300/\\/;
return 1;
}
}
sub get_args () {
@args = (undef);
while (/\S/) {
if (/\A\s*"((?:[^"]|"")*)(?:"|\z)(.*)/) {
my($x) = $1;
$_ = $2;
$x =~ s/\"\"/\"/g;
$x =~ s{( +)}{'<tt>&nbsp;</tt>' x length($1)}eg;
push @args, $x;
} elsif (/^\s*(\S+)(.*)/) {
push @args, $1;
$_ = $2;
}
if (/\A\s*"((?:[^"]|"")*)(?:"|\z)(.*)/) {
my($x) = $1;
$_ = $2;
$x =~ s/\"\"/\"/g;
$x =~ s{( +)}{'<tt>&nbsp;</tt>' x length($1)}eg;
push @args, $x;
} elsif (/^\s*(\S+)(.*)/) {
push @args, $1;
$_ = $2;
}
}
}
......@@ -235,19 +260,19 @@ sub call ($$) {
my($n, $t) = @_;
$_ = $t;
if ($n =~ /^[A-Za-z_0-9]+$/) {
eval "&dot_$n();";
eval "&dot_$n();";
} elsif ($n =~ /^\\\"/) {
'';
'';
}
}
sub o ($) {
my($x) = $_[0];
if ($QUOTES) {
$x =~ s/``/&#8220;/g;
$x =~ s/''/&#8221;/g;
$x =~ s/\`/&#8216;/g;
$x =~ s/\'/&#8217;/g;
$x =~ s/``/“/g;
$x =~ s/''/”/g;
$x =~ s/\`/‘/g;
$x =~ s/\'/’/g;
}
$T .= $x;
}
......@@ -255,13 +280,13 @@ sub o ($) {
sub line ($) {
$_ = $_[0];
if (/^[\.\']\s*(\w\S?)\s*(.*)/) {
call($1, $2);
call($1, $2);
} elsif (/^\.\\\"html\s+(.*)/) {
$T .= $1 . "\n";
$no_prologue = 1 if /DOCTYPE/;
$T .= $1 . "\n";
$no_prologue = 1 if /DOCTYPE/;
} elsif (/^[.\']\s*$/ || /^[.\']\\\"/) {
} else {
o($_);
o($_);
}
}
......@@ -282,14 +307,14 @@ sub dot_de {
my($subname, $sub, $save);
($subname) = /^(..?)/;
while (get_line) {
last if /^\.\./;
push @$save, $_;
last if /^\.\./;
push @$save, $_;
}
return if $NO_OVERRIDE{$subname};
$DEFS{$subname} = $save;
eval "sub dot_$subname {
get_args;
unshift \@pushed_lines, map(&expand_args(\$_), \@{\$DEFS{'$subname'}});
get_args;
unshift \@pushed_lines, map(&expand_args(\$_), \@{\$DEFS{'$subname'}});
}";
}
......@@ -297,15 +322,15 @@ sub dot_if {
my($test, $what);
my($X) = $_;
get_line, $X .= $_ if $X =~ /\\$/;
if ($X =~ /\\{/) {
get_line, $X .= $_ while $X !~ /\\}/;
($test, $what) = ($X =~ /^(\S+)\s+\\{\\?(.*)\\}/s);
$what .= "\n";
if ($X =~ /\\\{/) {
get_line, $X .= $_ while $X !~ /\\}/;
($test, $what) = ($X =~ /^(\S+)\s+\\\{\\?(.*)\\\}/s);
$what .= "\n";
} else {
($test, $what) = ($X =~ /^(\S+)\s+(.*)/s);
($test, $what) = ($X =~ /^(\S+)\s+(.*)/s);
}
if (defined($test) && $test ne 'n') {
unshift @pushed_lines, split(/\n/, $what);
unshift @pushed_lines, split(/\n/, $what);
}
}
......@@ -313,20 +338,20 @@ sub dot_ie {
my($test, $what);
my($X) = $_;
get_line, $X .= $_ if $X =~ /\\$/;
if ($X =~ /\\{/) {
get_line, $X .= $_ while $X !~ /\\}/;
($test, $what) = ($X =~ /^(\S+)\s+\\{\\?(.*)\\}/s);
$what .= "\n";
if ($X =~ /\\\{/) {
get_line, $X .= $_ while $X !~ /\\}/;
($test, $what) = ($X =~ /^(\S+)\s+\\\{\\?(.*)\\}/s);
$what .= "\n";
} else {
($test, $what) = ($X =~ /^(\S+)\s+(.*)/s);
($test, $what) = ($X =~ /^(\S+)\s+(.*)/s);
}
if (defined($test) && $test ne 'n') {
o("<sup>ie succ</sup>");
unshift @pushed_lines, split(/\n/, $what);
o("<sup>ie succ</sup>");
unshift @pushed_lines, split(/\n/, $what);
} else {
get_line;
s/^([.\']\s*)el/$1if t /;
unshift @pushed_lines, $_;
get_line;
s/^([.\']\s*)el/$1if t /;
unshift @pushed_lines, $_;
}
}
......@@ -335,16 +360,16 @@ sub dot_br {
}
my(%dot_TS_aligns) = ( 'c' => "center",
'r' => "right",
'l' => "left" ); # XXX
'r' => "right",
'l' => "left" ); # XXX
sub dot_TS {
my(@lines);
while (get_line) {
last if /^\.TE/;
push @lines, $_;
last if /^\.TE/;
push @lines, $_;