eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q' if 0;
($whatami = $0) =~ s|.*/||; $isatty = -t STDIN;
$index = 0; $cgibin = 0; $shortfiles = 0; $single = 0;
$host = ''; $updir = ''; $dir = 'tcsh'; $cgifile = 'tcsh.cgi'; $cgibindir = 'cgi-bin'; $headerfile = 'header'; $indexfile = 'index'; $listsfile = 'lists'; $outfile = 'tcsh.man'; $script = $whatami; $topfile = 'top';
%inline_me = ('NAME', 1,
'SYNOPSIS', 1);
%link_me = ('Editor commands', 'I',
'Builtin commands', 'I',
'Special aliases', 'I',
'Special shell variables', 'B',
'ENVIRONMENT', 'B',
'FILES', 'I');
while ($ if ($first =~ /[CdDGh]/) { shift;
$arg = $rest ne '' ? $rest : $ARGV[0] ne '' ? shift :
&usage("$whatami: -$first requires an argument.\n");
} elsif ($rest ne '') {
$ARGV[0] = "-$rest";
} else {
shift;
}
if ($first eq '1') { $single = 1; }
elsif ($first eq 'c') { $cgibin = 1; }
elsif ($first eq 'C') { $cgibindir = $arg; }
elsif ($first eq 'd') { $updir = $arg; }
elsif ($first eq 'D') { $dir = $arg; }
elsif ($first eq 'G') { $cgifile = $arg; }
elsif ($first eq 'h') { $host = $arg; }
elsif ($first eq 'i') { $index = 1; }
elsif ($first eq 's') { $shortfiles = 1; }
elsif ($first eq 'u') { &usage(0); }
else { &usage("$whatami: -$first is not an option.\n"); }
}
if (@ARGV == 0) {
if ($isatty) {
$infile = $outfile; } else {
$infile = 'STDIN'; }
} elsif (@ARGV == 1) {
$infile = $ARGV[0];
} else {
&usage("$whatami: Please specify one and only one file.\n");
}
$index = $index || $cgibin;
if ($cgibin && ! $host) {
die "$whatami: Must specify host with -h if using -c.\n";
}
$html = $shortfiles ? 'htm' : 'html'; $dir .= ".$html"; $headerfile .= ".$html"; $topfile .= ".$html"; $indexfile .= ".$html"; $listsfile .= ".$html";
unless ($infile eq 'STDIN') {
die "$whatami: $infile doesn't exist!\n" unless -e $infile;
die "$whatami: $infile is unreadable!\n" unless -r _;
die "$whatami: $infile is empty!\n" unless -s _;
}
if (-e $dir) {
-d _ || die "$whatami: $dir is not a directory!\n";
-r _ && -w _ && -x _ || die "$whatami: $dir is inaccessible!\n"
} else {
mkdir($dir, 0755) || die "$whatami: Can't create $dir!\n";
}
if ($infile eq 'STDIN') {
@man = <STDIN>;
} else {
open(MAN, $infile) || die "$whatami: Error opening $infile!\n";
@man = <MAN>;
close MAN;
}
open(MAN, ">$dir/$outfile") || die "$whatami: Can't open $dir/$outfile!\n";
print MAN @man;
close MAN;
(system("cp $0 $dir") >> 8) && die "$whatami: Can't copy $0 to $dir!\n";
system("rm -f $dir/$indexfile"); (system("ln -s $topfile $dir/$indexfile") >> 8)
&& die "$whatami: Can't link $topfile to $dir/$indexfile!\n";
$comment = 0; @sectionlines = (0); @sectiontypes = (0); @sectiontexts = ('Header'); @sectionfiles = ($headerfile); %name = (); @name = () if $index; $font = '';
$line = 0;
foreach (@man) {
if (/^\.ig/) { $comment = 1;
} elsif (/^\.\./) { $comment = 0;
} elsif (! $comment) {
s/\\-/-/g; s/\\^//g; # \^
s/^\\'/'/; # leading ' escape
s/^\\(\s)/$1/; s/\\(e|\\)/\\/g;
s/&/&\;/g;
s/>/>\;/g;
s/</<\;/g;
if (/^\.TH\s+(\w+)\s+(\w+)\s+\"([^\"]*)\"\s+\"([^\"]*)\"/) {
$title = "$1($2) $4 ($3) $1($2)";
}
if (($type, $text) = /^\.S([HS])\s+\"?([^\"]*)\"?/) {
push(@sectionlines, $line); push(@sectiontypes, $type eq 'H' ? 0 : 1); $text =~ s/\s*$//; # Remove trailing whitespace
push(@sectiontexts, $text); $text =~ s/\s*\(\+\)$//; # Remove (+)
if ($shortfiles) {
$file = $ } else {
$file = $text; $file =~ s/[\s\/]+/_/g; }
$file .= ".$html" unless $single;
push(@sectionfiles, $file); $name{"$text B"} = ($single ? '#' : '') . $file;
push(@name, "$text\t" . $name{"$text B"}) if $index;
$font = $link_me{$text};
}
&make_name(*name, *font, *file, *index, *_) if $font;
}
$line++;
}
open(TOP, ">$dir/$topfile");
select TOP;
print <<EOP;
<HEAD>
<TITLE>$title</TITLE>
</HEAD>
<BODY>
<A NAME="top"></A>
<H1>$title</H1>
<HR>
EOP
$action = $cgibin ? "http://$host/$cgibindir/$cgifile" : $cgifile;
print <<EOP if $index;
<FORM METHOD="GET" ACTION="$action">
Go directly to a section, command or variable: <INPUT NAME="input">
</FORM>
EOP
print <<EOP;
<H2>
EOP
foreach $section (1 .. $ if ($sectiontypes[$section - 1] < $sectiontypes[$section]) {
print "</H2> <menu>\n"; } elsif ($sectiontypes[$section - 1] > $sectiontypes[$section]) {
print "</menu> <H2>\n"; }
if ($inline_me{$sectiontexts[$section]}) {
print "$sectiontexts[$section]\n";
print "</H2> <menu>\n"; &printsectionbody(*man, *sectionlines, *section, *name);
print "</menu> <H2>\n"; } else {
print "<A HREF=\"", $single ? '#' : '',
"$sectionfiles[$section]\">$sectiontexts[$section]</A><BR>\n";
}
}
print <<EOP;
</H2>
EOP
print "<HR>\n" if $single;
foreach $section (0 .. $
next if $inline_me{$sectiontexts[$section]};
if ($single) {
print <<EOP if $section; <H2><A NAME="$sectionfiles[$section]">$sectiontexts[$section]</A></H2>
<menu>
EOP
&printsectionbody(*man, *sectionlines, *section, *name);
print <<EOP if $section; <A HREF="#top">Table of Contents</A>
</menu>
EOP
} else {
$pointers = "<A HREF=\"$topfile\">Up</A>";
$pointers .= "\n<A HREF=\"$sectionfiles[$section + 1]\">Next</A>"
if ($section < $ ! $inline_me{$sectiontexts[$section + 1]};
$pointers .= "\n<A HREF=\"$sectionfiles[$section - 1]\">Previous</A>"
if ($section > 1) && ! $inline_me{$sectiontexts[$section - 1]};
open(OUT, ">$dir/$sectionfiles[$section]");
select OUT;
print <<EOP;
<HEAD>
<TITLE>$sectiontexts[$section]</TITLE>
</HEAD>
<BODY>
$pointers
<H2>$sectiontexts[$section]</H2>
EOP
&printsectionbody(*man, *sectionlines, *section, *name);
print <<EOP;
$pointers
</BODY>
EOP
}
}
select TOP unless $single;
print <<EOP;
</H2>
<HR>
Here are the <A HREF="$outfile">nroff manpage</A> (175K)
from which this HTML version was generated,
the <A HREF="$script">Perl script</A> which did the conversion
and the <A HREF="ftp://ftp.astron.com/pub/tcsh/">
complete source code</A> for <I>tcsh</I>.
<HR>
<I>tcsh</I> is maintained by
Christos Zoulas <A HREF="mailto:christos\@gw.com"><christos\@gw.com></A>
and the <A HREF="$listsfile"><I>tcsh</I> maintainers' mailing list</A>.
Dave Schweisguth <A HREF="mailto:dcs\@proton.chem.yale.edu"><dcs\@proton.chem.yale.edu></A>
wrote the manpage and the HTML conversion script.
</BODY>
EOP
close TOP;
### Make lists page
open(LISTS, ">$dir/$listsfile");
select LISTS;
while(($_ = <DATA>) ne "END\n") { # Text stored after __END__
s/TOPFILEHERE/$topfile/;
print;
}
close LISTS;
### Make search script
if ($index) {
# URL of $dir; see comments in search script
$root = $cgibin
? "'http://$host/" . ($updir ? "$updir/" : '') . "$dir/'"
: '"http://$ENV{\'SERVER_NAME\'}:$ENV{\'SERVER_PORT\'}" . (($_ = $ENV{\'SCRIPT_NAME\'}) =~ s|[^/]*$||, $_)';
$name = join("',\n'", @name);
open(TOP, ">$dir/$cgifile");
select TOP;
while(($_ = <DATA>) ne "END\n") { s/ROOTHERE/$root/;
s/NAMEHERE/$name/;
s/TOPFILEHERE/$topfile/;
print;
}
close TOP;
chmod(0755, "$dir/$cgifile") ||
die "$whatami: Can't chmod 0755 $dir/$cgifile!\n";
warn "$whatami: Don't forget to move $dir/$cgifile to /$cgibindir.\n"
if $cgibin;
}
exit;
sub printsectionbody {
local(*man, *sectionlines, *sline, *name) = @_; local($sfirst, $slast, @paralines, @paratypes, $comment, $dl, $pline,
$comment, $pfirst, $plast, @para, @tag, $changeindent);
$sfirst = $sectionlines[$sline] + 1;
if ($sline == $ $slast = $ } else {
$slast = $sectionlines[$sline + 1] - 1;
}
if ($man[$sfirst] =~ /^\.[PIT]P/) {
@paralines = ();
@paratypes = ();
} else {
@paralines = ($sfirst - 1); @paratypes = ('P');
}
$comment = 0;
foreach ($sfirst .. $slast) {
if ($man[$_] =~ /^\.ig/) { $comment = 1;
} elsif ($man[$_] =~ /^\.\./) { $comment = 0;
} elsif (! $comment && $man[$_] =~ /^\.([PIT])P/) {
push(@paralines, $_);
push(@paratypes, $1);
}
}
$changeindent = 0;
$dl = 0;
foreach $pline (0 .. $
@para = ();
$comment = 0;
$pfirst = $paralines[$pline] + 1;
if ($pline == $ $plast = $slast;
} else {
$plast = $paralines[$pline + 1] - 1;
}
foreach (@man[$pfirst .. $plast]) {
if (/^\.ig/) { if ($comment == 0) {
$comment = 2;
push(@para, "<!--\n");
} elsif ($comment == 1) {
$comment = 2;
} elsif ($comment == 2) {
s/--/-/g; push(@para, $_);
}
} elsif (/^\.\./) { if ($comment == 0) {
;
} elsif ($comment == 1) {
;
} elsif ($comment == 2) {
$comment = 1;
}
} elsif (/^\.\\\"/) { if ($comment == 0) {
$comment = 1;
push(@para, "<!--\n");
s/^\.\\\"//;
} elsif ($comment == 1) {
s/^\.\\\"//;
} elsif ($comment == 2) {
;
}
s/--/-/g; push(@para, $_);
} else { if ($comment == 0) {
;
} elsif ($comment == 1) {
$comment = 0;
push(@para, "-->\n");
} elsif ($comment == 2) {
s/--/-/g; }
unless ($comment) {
if (/^\.TH/) { next;
} elsif (/^\.PD/) { next;
} elsif (/^\.RS/) { $changeindent++;
next;
} elsif (/^\.RE/) { $changeindent--;
next;
}
s/^\.br.*/<BR>/;
s/^\\&\;//; # leading dot escape; save until
&make_hrefs(*name, *_);
}
push(@para, $_);
}
}
push(@para, "-->\n") if $comment;
if ($paratypes[$pline] eq 'P') {
&font(*para);
print @para;
} elsif ($paratypes[$pline] eq 'I') {
&font(*para);
print "<menu>\n",
@para,
"</menu>\n";
} else { @tag = shift(@para);
&font(*tag);
&font(*para);
print "<DL compact>\n" unless $dl;
print "<DT>\n",
@tag,
"<DD>\n",
@para;
if ($pline == $ $dl = 0; print "</DL>\n";
} else {
$dl = 1; }
}
print "<P>\n";
while ($changeindent > 0) {
print "<menu>\n";
$changeindent--;
}
while ($changeindent < 0) {
print "</menu>\n";
$changeindent++;
}
}
1;
}
sub make_name {
local(*name, *font, *file, *index, *line) = @_;
local($text);
if (($text) = ($line =~ /^\.[BI]\s+([^\s\\]+)/)) {
if (
$text !~ /^-/ && (length($text) > 1 || $text =~ /^[%:@]$/) && ! $name{"$text $font"} ) {
$name{"$text $font"} = ($single ? '' : $file) . "#$text";
push(@name, "$text\t" . $name{"$text $font"}) if $index;
$line =~ s/^(\.[BI]\s+)([^\s\\]+)/$1<A NAME=\"$text\">$2<\/A>/;
}
}
$line;
}
sub make_hrefs {
local(*name, *line) = @_;
local(@pieces, $piece);
@pieces = split(/(\\f[BI][^\\]*\\fR)/, $line);
$piece = 0;
foreach (@pieces) {
if (/\\f([BI])([^\\]*)\\fR/
&& substr($pieces[$piece + 1], 0, 1) ne '(') {
$key = "$2 $1";
if ($name{$key}) { s/(\\f[BI])([^\\]*)(\\fR)/$1<A HREF=\"$name{$key}\">$2<\/A>$3/;
}
}
$piece++;
}
$line = join('', @pieces);
}
sub font {
local(*para) = @_;
local($i, $j, @begin, @end, $part, @pieces, $bold, $italic);
return 0 if $
$i = 0;
@begin = ();
@end = ();
foreach (@para) {
push(@begin, $i + 1) if /^-->/ || /^<BR>/;
push(@end, $i - 1) if /^<!--/ || /^<BR>/;
$i++;
}
if ($para[0] =~ /^<!--/ || $para[0] =~ /^<BR>/) {
shift(@end);
} else {
unshift(@begin, 0); }
if ($para[$ pop(@begin);
} else {
push(@end, $ }
$bold = $italic = 0;
foreach $i (0 .. $ $* = 1;
$part = join('', @para[$begin[$i] .. $end[$i]]);
$part =~ s/^\.([BI])\s+(.*)$/\\f$1$2\\fR/g; @pieces = split(/(\\f[BIR])/, $part);
$part = '';
foreach $j (@pieces) {
if ($j eq '\fB') {
if ($italic) {
$italic = 0;
$part .= '</I>';
}
unless ($bold) {
$bold = 1;
$part .= '<B>';
}
} elsif ($j eq '\fI') {
if ($bold) {
$bold = 0;
$part .= '</B>';
}
unless ($italic) {
$italic = 1;
$part .= '<I>';
}
} elsif ($j eq '\fR') {
if ($bold) {
$bold = 0;
$part .= '</B>';
} elsif ($italic) {
$italic = 0;
$part .= '</I>';
}
} else {
$part .= $j;
}
}
$* = 0;
if ($end[$i] == $ if ($bold) {
$bold = 0;
$part =~ s/(\n)?$/<\/B>$1\n/;
} elsif ($italic) {
$italic = 0;
$part =~ s/(\n)?$/<\/I>$1\n/;
}
}
foreach $j ($begin[$i] .. $end[$i]) {
$part =~ s/^([^\n]*(\n|$))//;
$para[$j] = $1;
}
}
$para[$end[$ $para[$end[$}
sub usage {
local ($message) = $_[0];
warn $message if $message;
warn <<EOP;
Usage: $whatami [-1icsu] [-C dir] [-d dir] [-h host] [file]
Without [file], reads from tcsh.man or stdin.
-1 Makes a single page instead of a table of contents and sections
-i Makes a CGI searchable index script, tcsh.html/tcsh.cgi, intended
for a server which respects the .cgi extension in any directory.
-c Like -i, but the CGI script is intended for a server which wants
scripts in /cgi-bin (or some other privileged directory separate
from the rest of the HTML) and must be moved there by hand.
-C dir Uses /dir instead of /cgi-bin as the CGI bin dir.
Meaningless without -c.
-d dir Uses /dir/tcsh.html instead of /tcsh.html as the HTML dir.
Meaningless without -c.
-D dir Uses /dir.html instead of /tcsh.html as the HTML dir.
Meaningless without -c.
-G name Uses name instead of tcsh.cgi as the name of the CGI script.
Meaningless without -c or -i.
-h host Uses host as the host:port part of the URL to the entry point.
Meaningless without -c.
-s Filenames are shorter (max 8 + 3) but less descriptive.
-u This message
EOP
exit !! $message;
}
__END__
<HEAD>
<TITLE>The tcsh mailing lists</TITLE>
</HEAD>
<BODY>
<A HREF="TOPFILEHERE">Up</A>
<H2>The <I>tcsh</I> mailing lists</H2>
There are three <I>tcsh</I> mailing lists:
<DL>
<DT>
<I>tcsh@mx.gw.com</I>
<DD>
The <I>tcsh</I> maintainers and testers' mailing list.
<DT>
<I>tcsh-diffs@mx.gw.com</I>
<DD>
The same as <I>tcsh@mx.gw.com</I>, plus diffs for each new
patchlevel of <I>tcsh</I>.
<DT>
<I>tcsh-bugs@mx.gw.com</I>
<DD>
Bug reports.
</DL>
You can subscribe to any of these lists by sending mail to
<I><A HREF="mailto:listserv@mx.gw.com">listserv@mx.gw.com</A></I> with the
text "subscribe <list name> <your name>" on a line by
itself in the body. <list name> is the name of the mailing list,
without "@mx.gw.com", and <your name> is your real name, not your
email address. You can also ask the list server for help by sending
only the word "help".
<P>
<A HREF="TOPFILEHERE">Up</A>
</BODY>
END
#!/bin/sh
# Emulate #!/usr/local/bin/perl on systems without #!
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q' if 0;
# Setup
# Location: doesn't work with relative URLs, so we need to know where to find
$root = ROOTHERE;
$topfile = 'TOPFILEHERE';
@name = (
'NAMEHERE'
);
$input = $ENV{'QUERY_STRING'};
$input =~ s/^input=//;
$input =~ s/\+/ /g;
print "Status: 302 Found\n";
if ($input ne '' && ($key = (grep(/^$input/, @name))[0] ||
(grep(/^$input/i, @name))[0] ||
(grep( /$input/i, @name))[0] )) {
$key =~ /\t([^\t]*)$/;
print "Location: $root$1\n\n";
} else {
print "Location: $root$topfile\n\n";
}
END