summaryrefslogtreecommitdiff
path: root/doc/tech-notes/pnuts.4tech-notes
blob: 33e8d49f08fd78e1ad5c4edf685d8b9e14f9c54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/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="<b>Previous</b>";
# $nextw="<b>Next</b>";
# $upw="<b>Up one level</b>";
# $topw="<b>Table of Contents</b>";
# $searchw="<b>Search</b>";
# $indexw="<b>Index</b>";

$prevw='<IMG SRC="../graphics/BPprev.gif" ALT="[Previous]">';
$nextw='<IMG SRC="../graphics/BPnext.gif" ALT="[Next]">';
$upw=''; # not needed and don't have a graphic for UP
$topw='<IMG SRC="../graphics/BPtoc.gif" ALT="[Table of Contents]">';
$searchw='<IMG SRC="../graphics/BPsearch.gif" ALT="[Search]">';
$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 = "<!-- pnuts -->";


	open( LIST, "<$file") || die "Can't open file: $!";


	$nextfile = <LIST>;
	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 = <OLDCURR>) {
			if ( $line =~ "^$marker") {
				&pnutline();
			}
			else {
				print NEWCURR $line;
			}
		}
		close( OLDCURR);
		close( NEWCURR);
	}


close( LIST);
exit(0);

sub pnutline {
	printf( NEWCURR  "$marker");
	printf( NEWCURR "<P><HR>");
	if ( $previous ) {
		printf( NEWCURR " <a href=\"%s\">$prevw</a>", $previous);
	}
	if ( $nextfile ) {
		printf( NEWCURR  " <a href=\"%s\">$nextw</a>", $nextfile);
	}
	if ( $up[$curlevel - 1] ) {
		printf( NEWCURR  " <a href=\"%s\">$upw</a>",
				$up[$curlevel-1]);
	}
	if ( $top && ( $top ne $currentfile) ) {
		printf( NEWCURR  " <a href=\"%s\">$topw</a>", $top);
	}
	if ( $search ) {
		printf( NEWCURR  " <a href=\"%s\">$searchw</a>", $search);
	}
	if ( $index ) {
		printf( NEWCURR  " <a href=\"%s\">$indexw</a>", $index);
	}
	printf( NEWCURR "\n");
}

sub getnextfile {
	if ( $nextfile eq "") {
		return 0;
	}
	$previous = $currentfile;
	$up[$curlevel] = $currentfile;

	$currentfile = $nextfile;
	while ( 1 ) {
		($nextfile = <LIST>) || ($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;
}