#!perl

# Parse additional *.html files useing parse.pl

require 'parse.pl';

die "Cannot open TOC: $!\n"
	unless open(TOC, "TOC");
while(<TOC>) {
	if(/FEATURE_/) {
#		s/#feature/cmd.html$1/;
#	Decorate string as it gets HTML'ed when included later
		s:<.*?>::g;
		$features .= '<LI>' . $_;
	}
}
close TOC;

$ref = {
	'appendix' => sub { '<A HREF="appendix.html#' . lc($_[0]) . "\">"; }
	, 'cmd' => sub { '<A HREF="cmd.html#' . lc($_[0].$_[1]) . '">'; }
	, 'main' => sub { my $n = shift;
		$n =~ s/^[_-]+//g;
		return '<A HREF="#-' . lc($n) . "\">"; }
	, 'section' => sub { "\n<H3>" . ucfirst(lc($_[0])) . "</H3>\n"; }
	, 'subsection' => sub { "\n<H4>" . $_[0] . "</H4>\n"; }
};
readCmdList($ref);

foreach $file ('FreeCOM.html') {
	die "Cannot open '$file': $!\n"
		unless open(IN, $file);
	die "Cannot create '../$file': $!\n"
		unless open(HTML, ">../$file");
	&parseEBNF($ref);
	close HTML;
	close IN;
}

$ref = {
	'appendix' => sub { '<A HREF="#' . lc($_[0]) . "\">"; }
	, 'cmd' => sub { '<A HREF="cmd.html#' . lc($_[0].$_[1]) . '">'; }
	, 'main' => sub { my $n = shift;
		$n =~ s/^[_-]+//g;
		return '<A HREF="FreeCOM.html#-' . lc($n) . "\">"; }
	, 'section' => sub { "\n<H3>" . ucfirst(lc($_[0])) . "</H3>\n"; }
	, 'subsection' => sub { "\n<H4>" . $_[0] . "</H4>\n"; }
};
readCmdList($ref);

foreach $file ('appendix.html') {
	die "Cannot open '$file': $!\n"
		unless open(IN, $file);
	die "Cannot create '../$file': $!\n"
		unless open(HTML, ">../$file");
	&parseEBNF($ref);
	close HTML;
	close IN;
}

