#!/usr/local/bin/perl $[ = 1; # set array base to 1 $dome = 0; line: while (<>) { chop; # strip record separator @Fld = split(' ', $_, 9999); procline: if (/^\.TH/) { $str=$Fld[3]; for ($i=4;$i <= $#Fld; $i++) { $str .= " " . $Fld[$i]; } $str = &htmlify($str); printf("%s : %s

%s : %s

\n", $Fld[2],$str,$Fld[2], $str); next line; } if (/^\.SY/) { # $i = $_ =~ "\"" && ($RLENGTH = length($&), $RSTART = length($`)+1); # $str = substr($_, $i + 1, length($_) - $i - 1); $str = substr($_,5); $str = &htmlify($str); printf "[##:##] %s

\n", $str; next line; } if (/^\.EX/) { $str = substr($_, 5); printf "
[##:##] %s

\n", &htmlify($str); next line; } if (/^\.L/) { @a = split('[: ",.]+'); $str = &anchor($a[3]); $str = ("$str $a[4]"); printf("
%s\n", $str); next line; } if (/^\.s3/) { printf (("

\n")); next line; } if (/^\.s1/) {printf (("


\n")); next line; } if (/^\.br/) { printf "
\n"; next line; } if (/^\.(FI|fi)/) { printf (("

\n")); $dome = 0; next line; } if (/^\.(NF|nf)/) { printf (("

\n")); $dome = 1; next line;    }

    if ($dome == 1) {
	@a = split('[: ",.]+');

	for ($i = 2; $i <= $#a ; ($i)++) {       
	    printf("%s",&anchor($a[$i]));
	    for ($j = 0; $j < 20 - length($a[$i]); $j++) {
		printf(" ");
	    }
	}
        printf("\n");
	while (<>) {
	    chop;	# strip record separator
	    @a = split('[: ,.]+');
	    @Fld = split(' ', $_, 9999);
	    if (/^\./) { goto procline; }
	    for ($i = 2; $i <= $#a ; ($i)++) {       
		printf("%s",&anchor($a[$i]));
		for ($j = 0; $j < 20 - length($a[$i]); $j++) {
		    printf(" ");
		}
	    }
	    printf("\n");
	}
	next line;
    }

    if (/^\.SA/) {
	@a = split('[: ",.]+');

	printf("See also : %s\n",&anchor($a[3]) );
	for ($i = 4; $i <= $#a ; ($i)++) {       
	    printf(", %s\n",&anchor($a[$i]));
	}

	while (<>) {
	    chop;	# strip record separator
	    @a = split('[: ,.]+');
	    @Fld = split(' ', $_, 9999);
	    if (/^\./) { goto procline; }
	    for ($i = 1; $i <= $#a ; ($i)++) {       
		printf(", %s\n",&anchor($a[$i]));
	    }
	}
	    
	exit(0);
    }
	    
    if (/^\./) {	next line; }

    if (/^(See also|See Also|see also)/) {
	@a = split('[: ,.]+');

	printf("See also : %s\n",&anchor($a[3]) );
	for ($i = 4; $i <= $#a ; ($i)++) {       
	    printf(", %s\n",&anchor($a[$i]));
	}

	while (<>) {
	    chop;	# strip record separator
	    @a = split('[: ,.]+');
	    @Fld = split(' ', $_, 9999);
	    if (/^\./) { goto procline; }
	    for ($i = 1; $i <= $#a ; ($i)++) {       
		printf(", %s\n",&anchor($a[$i]));
	    }
	}
	    
	exit(0);
    }
	    
    printf "%s\n", &htmlify($_);
}

#sub anchor {
#    local($_) = @_;
#    $file = $_ . ".t";
#    if (-r $file) {
#	return ("" . $_ . "");
#    } else {
#	return ( " " . $_ . " ");
#    }
#}

sub anchor {
    local($_) = @_;
    local(@file,$file);
    $file = $_ . ".t";
#    if (-r $file) {
    if (1) {
      $file =~ s/.t$/.html/;
      return ("$_");
    } else {
	@file = <$_*t>;
	if (@file) {
	  warn "Expanding $_ to $file[$[]\n";
	  $file[$[] =~ s/.t$/.html/;
	  return ("$_");
	} else {
	  warn "Unable to link $_\n";
	  return ( "$_");
	}
    }
}

    
# Translate HTML special characters into escape sequences
sub htmlify {
        local($_) = @_;
	s/^\"(.*)\"$/$1/;
	s/\\&//g;		# a nothing character
        s/\&/&/g;
        s/\/>/g;
	while (@a = /(\\\*Q)([A-Za-z0-9\-\.]+)(\\\*U)/) {
	    /(\\\*Q)([A-Za-z\-]+)(\\\*U)/;
	    $_ = $` . &anchor($a[2]) . $';
	}
	while (@a = /(\\\*Q)(\"info )([A-Za-z0-9\-\.]+)(\\\*U)/) {
	    /(\\\*Q)(\"info )([\w\-\.]+)(\\\*U)/;
	    $_ = $` . "\"info " . &anchor($a[3]) . $';
	}
	while (@a = /(\"info )([A-Za-z0-9\-\.]+)/) {
	    /(\"info )([\w\-\.]+)/;
	    $_ = $` . "\"info " . &anchor($a[2]) . $';
	}
        s/\\\*Q//g;
        s/\\\*U/<\/em>/g;
        s/\\fI//g;
        s/\\fR/<\/em><\/em>/g;
        s/\\fB//g;
        s/\\fP/<\/strong><\/em>/g;
	s/\\\*\(bF//g;	# bold font
	s/\\\*\(pF/<\/strong><\/em>/g; # pica font
	s/\\\*\(nF/<\/strong><\/em>/g; # normal font
	s/\\\*\(iF//g;	# italic font
	s/\\\(mu/x/g;		# multiply symbol
	s/\\ / /g;		# should be non breaking space
        return $_;
}

#sub htmlify {
#    local($str) = @_;
#    $str;
#}