#!/usr/local/bin/perl # # Special features: # 1) The item # # if it occurs on a line all by itself, causes # this perlscript to chop files here. The filename # will be as specified. The other_words # will be used as the title. If neither the # filename nor the other_words are present, then # this script makes up filenames using numbers, e.g., # gri1.html, gri2.html. If the filename is ".", # then this same naming scheme is used, but the titles # are used. # 2) If the item all # by itself is encountered. This is a kludge because # xmosaic refuses to skip comments if a
 item is
#    contained within them.
#
$debug = 0;

$num_files = 1;
die "Need 2 arg (eg chop_into_subfiles gri.hml \"The Gri graphing language\")" if ($#ARGV != 1);

$basefile = "gri";
#$file = "$basefile$num_files.html";
$file = "index.html";
$basetitle = $ARGV[1];
$title = $basetitle;
$marginnote[0] = "Gri";
$#ARGV = 0;			# Dumb way to ignore
print STDOUT "$file " if $debug;
if (open (OUT, ">", "$file")) { #|| die "Cannot open $file";
$file_list[$num_files++] = $file;

$name_of_top_node = "index.html#Top";


print OUT "\n";
print OUT "\n";
print OUT "\n";
print OUT "$title\n";
print OUT "\n";
print OUT "\n";
print OUT "\n";
print OUT "";
print OUT "\n";



#$body_start = "";
#$body_start = "";

# Colors below from Mozilla page as of 2001-mar-05.
$body_start = "";

print OUT "$body_start\n";

while(<>) {
    # Skip comment blocks (kludge; see above)
    if (/^\s*\s*$/;
        }
	$_ = <>;
    }
    if (/^\s*$/) {
        $file = (length($1) > 0 && $1 ne ".")
	    ? $1 : "$basefile$num_files.html";
	if (length($2) > 0) {
	    $title = $2;
	} else {
	    $title = $basetitle;
	}
        if (length($3) > 0) {
	    $marginnote[$num_files] = $3;
	}
        $titleList{$file} = $title;
        print OUT "
\"navigation
";
	close OUT;
	open (OUT, ">$file") || die "Cannot open $file";
	$file_list[$num_files++] = $file;
        print OUT "\n";
	print OUT "\n";
	print OUT "\n";
        print OUT "$title\n";
	print OUT "";
        print OUT "\n";
	print OUT "$body_start\n";
        print "Creating $file\n" if $debug;
    }
    print OUT;
} 
close OUT;

for ($i = 1; $i < $num_files; $i++) {
    $file = $file_list[$i];
    $ofile = "$file.pass2";
    open (IN, "$file") || die "Cannot open $file";
    open (PASS2, ">$ofile") || die "Cannot open $ofile";
    print "$file " if $debug;
    $node_parent = "";
    $need_to_find_parent = 1;
    while() {
        if (/\s*href\s*=\s*"#([^"]*)/i) {
            $key = $1;		# suck out key
	    $key =~ s/ //g;	# despace key
	    s,href\s*=\s*"#[^"]*,href="$ref{$key},;	# replace key with what is keyed to
            s,="#,=",;
        } elsif (/
	    $key = $1;
	    $key =~ s/ //g;
	    s,"[^"]*","$key",;
       }
       if ($need_to_find_parent && /a href="([^"]*)">parent/) {
           $need_to_find_parent = 0;
           $node_parent = $1;
       }
       # Do not print those 'Navigation' things
       if (!/^Navigation<\/b>:/ 
	   && !/next<\/a>,/
	   && !/previous<\/a>,/
	   && !/parent<\/a>/) {
	   print PASS2 if (!/href=""/);
       }
    }
    print "." if $debug;
    close IN;
    close PASS2;
    open (PASS3, ">$file.pass3") || die "Cannot open $file.pass3";
    open (PASS2, "$file.pass2")  || die "Cannot open $file.pass2";
    $need_table_cmd = 1;
    while() {
        if (/^<\s*a\s*name="(.*)"\s*>/ && $need_table_cmd) {
            $need_table_cmd = 0;
            print PASS3;
	    $this_chapter = $marginnote[$i];
	    if ($this_chapter eq "") {
		$this_chapter = "Gri";
	    }
	    #print STDERR "[$file]\n";
	    print PASS3 "
\"navigation

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
"; print "file $file\n" if $debug; if ($file ne "index.html") { print PASS3 "\n"; print PASS3 "\"$name_of_top_node\"\n"; if ($node_parent ne "") { print PASS3 "\"$node_parent\"\n"; } print PASS3 "\"$titleList{$file_list[$i-1]}\"\n"; print PASS3 "\"$titleList{$file_list[$i+1]}\"\n" if $file_list[$i+1] ne ""; print PASS3 "\n"; print PASS3 "\n"; print PASS3 "\"$name_of_top_node\"\n"; print PASS3 "\"$titleList{$file_list[$i+1]}\"\n\n" if $file_list[$i+1] ne ""; } } else { print PASS3; } } close(PASS2); print PASS3 " "; close(PASS3); rename("$file.pass3", "$file"); print ".\n" if $debug; } }