<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">### File: html2.2.pl
### Language definitions for HTML 2.2 (Tables)
### Written by Marcus E. Hennecke &lt;marcush@leland.stanford.edu&gt;
### Version 0.4,  February 2, 1996

## Revisions:
##	TKM  Tom Miller &lt;tkm@eos.ncsu.edu&gt;

## Copyright (C) 1995 by Marcus E. Hennecke
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

if ($HTML_OPTIONS =~ /table/) {
    $DOCTYPE = '';
    $STRICT_HTML = 0;
}

### The following routines do tables

$content_mark = "&lt;cellcontents&gt;";

## Since the do_env_tabular subroutine does all the work, there is
## nothing left to do.
#sub do_env_table {
#    local($_) = @_;
#    &amp;get_next_optional_argument;
#    $_ = &amp;translate_commands(&amp;translate_environments($_));
#    $_;
#}

#sub do_env_tablestar {
#    local($_) = @_;
#    &amp;get_next_optional_argument;
#    $_ = &amp;translate_commands(&amp;translate_environments($_));
#    $_;
#}

### Define the multicolumn command
# Modifies the $colspec and $colspan variables of the tabular subroutine
sub do_cmd_multicolumn {
    local($_) = @_;
    local($dmy1,$dmy2,$dmy3,$dmy4);
    s/$next_pair_pr_rx//o;
    $colspan = 0+$2;
    $colspec =~ /^&lt;([A-Z]+)/;
    local($celltag) = $1;
    s/$next_pair_pr_rx//o;
    ($dmy1,$dmy2,$dmy3,$dmy4,$colspec) = &amp;translate_colspec($2, $celltag);
    s/$next_pair_pr_rx//o;
    $2;
}

# Since hlines are taken care of in the tabular environment, they
# don't need to do anything. Ideally, this routine should never be
# called anyway. clines are not yet supported.
sub do_cmd_hline {
    $_[$[];
}
sub do_cmd_cline {
    $_[$[] =~ s/$next_pair_pr_rx//o;
    $_[$[];
}

# Attempts to convert latex lengths into some HTML equivalent. This
# can only be an attempt until browsers start implementing units.
# The returned values are: The length according to Netscape (in pixels
# or percent) and the length according to HTML 3.0.
sub convert_length {
    local($_) = @_;
    local(%scale) = ("in",72,"pt",72.27/72,"pc",12,"mm",72/25.4,"cm",72/2.54,"\\hsize",100);
    local(%units) = ("in","in","pt","pt","pc","pi","mm","mm","cm","cm","\\hsize","%");
    local($pxs,$len);
    if ( /([0-9.]+)(in|pt|pc|mm|cm|\\hsize)/ ) {
	$pxs = int($1 * $scale{$2} + 0.5);
	$len = $1 . $units{$2};
	if ( $2 eq "\\hsize" ) {
	    $pxs .= '\%';
	};
    };
    ($pxs,$len);
}

# Translates LaTeX column specifications to HTML. Again, Netscape
# needs some extra work with its width attributes in the &lt;td&gt; tags.
sub translate_colspec {
    local($colspec,$celltag) = @_;
    local($cellopen) = "&lt;$celltag VALIGN=BASELINE ALIGN";
    local($cellclose) = "&lt;/$celltag&gt;";
    local($htmlcolspec,$len,$pts,@colspec,$char,$cols,$repeat);
    local($frames,$rules,$prefix);

    $frames  = "l" if ( $colspec =~ s/^\|+// );
    $frames .= "r" if ( $colspec =~ s/\|+$// );
    $rules = "c" if ( $colspec =~ /\|/ );

    $htmlcolspec = "&lt;COLGROUP&gt;" if ( $rules );

    $cols = 0;
    while ( length($colspec) &gt; 0 ) {
	$char = substr($colspec,0,1);
	$colspec = substr($colspec,1);
	if ( $char eq "c" ) {
	    $htmlcolspec .= "&lt;COL ALIGN=CENTER&gt;";
	    push(@colspec,"$cellopen=CENTER NOWRAP&gt;$content_mark$cellclose");
	    $cols++;
	} elsif ( $char eq "l" ) {
	    $htmlcolspec .= "&lt;COL ALIGN=LEFT&gt;";
	    push(@colspec,"$cellopen=LEFT NOWRAP&gt;$content_mark$cellclose");
	    $cols++;
	} elsif ( $char eq "r" ) {
	    $htmlcolspec .= "&lt;COL ALIGN=RIGHT&gt;";
	    push(@colspec,"$cellopen=RIGHT NOWRAP&gt;$content_mark$cellclose");
	    $cols++;
	} elsif ( $char eq "p" ) {
	    $colspec =~ s/$next_pair_rx//;
	    ($pts,$len) = &amp;convert_length($2);
	    if ( $pts ) {
		$width = " WIDTH=\"$pts\"";
		$htmlcolspec .= "&lt;COL ALIGN=JUSTIFY WIDTH=\"$len\"&gt;";
	    } else {
		$width = "";
		$htmlcolspec .= "&lt;COL ALIGN=JUSTIFY&gt;";
	    };
	    push(@colspec,"$cellopen=LEFT$width&gt;$content_mark$cellclose");
	    $cols++;
	} elsif ( $char eq "|" ) {
	    $htmlcolspec .= "&lt;COLGROUP&gt;";
	} elsif ( $char eq "@" ) {
	    $htmlcolspec .= "&lt;COL ALIGN=CENTER&gt;";
	    $colspec =~ s/$next_pair_rx//;
	    $cols++;
	    if ( $#colspec &lt; 0 ) {
		$prefix .= "$cellopen=CENTER NOWRAP&gt;" .
		    &amp;translate_commands($2) . $cellclose;
	    } else {
		$colspec[$#colspec] .= "$cellopen=CENTER NOWRAP&gt;" .
		    &amp;translate_commands($2) . $cellclose;
	    }
	} elsif ( $char eq "*" ) {
	    $colspec =~ s/$next_pair_rx//;
	    $repeat = $2;
	    $colspec =~ s/$next_pair_rx//;
	    $colspec = "$2"x$repeat . $colspec;
	};
    };

    $colspec[0] = $prefix . $colspec[0];
    ($htmlcolspec,$frames,$rules,$cols,@colspec);
}

%frameoptions = ( "l", "LHS", "r", "RHS", "lr", "VSIDES",
		  "t", "ABOVE", "b", "BELOW", "tb", "HSIDES",
		  "lt", "BOX", "rt", "BOX", "lrt", "BOX",
		  "lb", "BOX", "rb", "BOX", "lrb", "BOX", 
		  "ltb", "BOX", "rtb", "BOX", "lrtb", "BOX");

# tabularstar simply calls tabular but with an extra argument---the
# width.
sub do_env_tabularstar {
    local($_) = @_;
    s/$next_pair_rx//;
    local($pts,$len) = &amp;convert_length($2);
    &amp;do_env_tabular($_," width=$pts");
}

sub do_env_tabular {
    local($_) = @_;
    &amp;get_next_optional_argument;
    s/$next_pair_rx//;
    local($colspec) = $2;
    s/\\\\\s*\[([^]]+)\]/\\\\/g;  # TKM - get rid of [N.n pc] on end of rows...
    s/\\newline\s*\[([^]]+)\]/\\newline/g;
    s/\n\s*\n/\n/g;	# Remove empty lines (otherwise will have paragraphs!)
    local($i,@colspec,$char,$cols,$cell,$htmlcolspec,$frames,$rules);
    local(@rows,@cols,$border);
    local($colspan,$cellcount);

    $border = ""; $frame = "";
    ($htmlcolspec,$frames,$rules,$cols,@colspec) =
	&amp;translate_colspec($colspec, 'TD');

    $frames .= "t" if ( s/^\s*\\hline// );
    $frames .= "b" if ( s/\\hline\s*$// );
    $rules .= "r" if ( /\\[ch]line/ );

    if ( $frames || $rules ) {
	$border = " BORDER";
	$rule = " RULES=NONE";
	$frame = " FRAME=$frameoptions{$frames}" if ($frames);
	$rule = " RULES=GROUPS" if ($rules);
    };

    @rows = split(/\\\\/);
    $#rows-- if ( $rows[$#rows] =~ /^\s*$/ );
    local($return) = "&lt;TABLE COLS=$cols$border$frame$rule$_[1]&gt;\n";
    $return .= "$htmlcolspec\n";
    $return .= "&lt;TBODY&gt;\n" if ( $rules =~ /r/ );
    foreach (@rows) {
	if ( s/^(\s*\\hline\s*)+//g ) {
	    $return .= "&lt;/TBODY&gt;&lt;TBODY&gt;\n";
	};
	$return .= "&lt;TR&gt;";
	@cols = split(/$html_specials{'&amp;'}/o);
	for ( $i = 0; $i &lt;= $#colspec; $i++ ) {
	    $colspec = $colspec[$i];
	    $colspan = 0;
	    # May modify $colspec
	    $cell = &amp;translate_commands(&amp;translate_environments(shift(@cols)));
	    if ( $colspan ) {
		for ( $cellcount = 0; $colspan &gt; 0; $colspan-- ) {
		    $colspec[$i++] =~ s/&lt;TD/$cellcount++;"&lt;TD"/ge;
		}
		$i--;
		$colspec =~ s/&gt;$content_mark/ COLSPAN=$cellcount$&amp;/;
	    };
	    $colspec =~ s/$content_mark/$cell/;
	    $return .= $colspec;
	};
	$return .= "&lt;/TR&gt;\n";
    };
    $return .= "&lt;/TBODY&gt;\n" if ( $rules =~ /r/ );
    if ($capenv &amp;&amp; $captions) {
        $return .= "&lt;CAPTION ALIGN=BOTTOM&gt;$captions&lt;/CAPTION&gt;";
	$captions = "";
    }
    $return .= "&lt;/TABLE&gt;\n";
    $return;
}

1;
</pre></body></html>