#!/usr/local/bin/perl
#################################################
#pnuts version 0.4 part of the WN server package
#################################################
# for more info, see http://hopf.math.nwu.edu/docs/utility.html#pnuts
# Modified by Stefan Kramer for use with Pine Technical Notes
# Last modified on 1995 Nov. 02
require "getopts.pl";
# Edit to specify what should appear as text of navigation bar. Note:
# If the HTML files processed by PNUTS will be converted to plain-text files,
# the PNUTS-generated link text will probably be stripped out, so this
# text should be unique (i.e., not expected to occur elsewhere in text).
# This is the original link appearance, without graphic buttons
# $prevw="Previous";
# $nextw="Next";
# $upw="Up one level";
# $topw="Table of Contents";
# $searchw="Search";
# $indexw="Index";
$prevw='';
$nextw='';
$upw=''; # not needed and don't have a graphic for UP
$topw='';
$searchw='';
$indexw=''; # no index here and no graphic for it
$VERSION = "0.4";
&Getopts('s:i:');
$search = $opt_s if $opt_s ne "";
$index = $opt_i if $opt_i ne "";
$file = shift;
$marker = "";
open( LIST, "<$file") || die "Can't open file: $!";
$nextfile = ;
print $nextfile;
chop( $nextfile);
$top = $nextfile;
while ( &getnextfile() ) {
$curcopy = $currentfile."~";
rename( $currentfile, $curcopy)
|| die "Can't rename file: $currentfile";
open( OLDCURR, "<$curcopy" ) || die "Can't open file: $!";
open( NEWCURR, ">$currentfile" ) || die "Can't open file: $!";
while ( $line = ) {
if ( $line =~ "^$marker") {
&pnutline();
}
else {
print NEWCURR $line;
}
}
close( OLDCURR);
close( NEWCURR);
}
close( LIST);
exit(0);
sub pnutline {
printf( NEWCURR "$marker");
printf( NEWCURR "
");
if ( $previous ) {
printf( NEWCURR " $prevw", $previous);
}
if ( $nextfile ) {
printf( NEWCURR " $nextw", $nextfile);
}
if ( $up[$curlevel - 1] ) {
printf( NEWCURR " $upw",
$up[$curlevel-1]);
}
if ( $top && ( $top ne $currentfile) ) {
printf( NEWCURR " $topw", $top);
}
if ( $search ) {
printf( NEWCURR " $searchw", $search);
}
if ( $index ) {
printf( NEWCURR " $indexw", $index);
}
printf( NEWCURR "\n");
}
sub getnextfile {
if ( $nextfile eq "") {
return 0;
}
$previous = $currentfile;
$up[$curlevel] = $currentfile;
$currentfile = $nextfile;
while ( 1 ) {
($nextfile = ) || ($nextfile = "");
$nextfile =~ s/(\t*)//;
last if $nextfile eq "";
print $nextfile;
chop( $nextfile);
if ( -d $nextfile ) {
print "$nextfile is directory, ignoring it\n";
next;
}
last;
}
$curlevel = $nextlevel;
$nextlevel = length( $1);
return 1;
}