eval 'exec /usr/dist/exe/perl -S $0 ${1+"$@"} '
  if 0;

$page = 0;
$started = 0;

while (<>) {
	$line++;
	if (/<page>/) {
		&endit(0);
		$page++;
		&startit();
	} elsif (/<mycode>/) {
		if ($mode != 1) {
			print "Missing /mycode $line\n";
		}
		$mode=3;
		print FILE "<pre>\n";
	} elsif (/<.mycode>/) {
		if ($mode != 3) {
			print "Missing mycode $line\n";
		}
		$mode = 1;
		print FILE "</pre>\n";
	} elsif ($mode==0) {
		$mode=1;
		print FILE "<table border=0 cellspacing=0 cellpadding=0 width=100%>\n";
		print FILE "<tr valign=top>\n";
		print FILE "<td width=60%>\n";
		print FILE "<h2>\n";
		print FILE $_;
		print FILE "</h2>\n";
		print FILE "</td>\n";
		print FILE "<td width=5%>\n";
		print FILE "<a href=\"page1.html\">Start</a>\n";
		print FILE "</td>\n";
		if ($page != 1) {
			print FILE "<td width=5%>\n";
			print FILE "<a href=\"page".($page-1).".html\">Prev</a>\n";
			print FILE "</td>\n";
		}
		print FILE "<td width=5%>\n";
		print FILE "<a href=\"page".($page+1).".html\">Next</a>\n";
		print FILE "</td>\n";
		print FILE "</tr></table>\n";
		print FILE "<img src=\"rule11.gif\" alt=\"\"><p>\n";
	} else {
		print FILE $_;
	}
}

&endit(1);

sub startit {
		open("FILE",">page".$page.".html") || die("can't open page");
		print FILE "<html><head><title>Page $page</title></head>\n";
		print FILE "<body bgcolor=white>\n";
		$started = 1;
		$mode=0;
}

sub endit {
	local($last) = @_;
	if ($started) {
		if ($mode != 1) {
			print "bad mode "+$mode+"\n";
		}
		print FILE "<p>\n";
		print FILE "</body></html>\n";
		close(FILE);
	}
}
