#! /usr/bin/perl
#
# mkhtmldir DIR TITLE
#
# Used to create a new web page in the Topical Core.  Fiddles templates,
# up lists, and such things to generate a boilerplate index.shtml file
# in the new directory DIR, which will become part of the URL.
# TITLE should be the name of the page as the user will see it.

die "Usage: mkhtmldir DIR TITLE" if ( $#ARGV != 1 );

die "$ARGV[0]: File already exists" if ( -f $ARGV[0] || -d $ARGV[0]);

mkdir($ARGV[0], 0777)
    || die "$ARGV[0]: Can't create directory\n";

sub editTemplate {
    local($in, $out) = @_;
    open(IN, "<$in");
    open(OUT, ">$out");
    while (<IN>) {
	if (m!^</CENTER>$!) {
	    $MyUrl = "$CurrentUrl/$ARGV[0]/index.shtml";
	    print OUT "<BR><B>Up:</B> <A HREF=\"$MyUrl\">$ARGV[1]</A>\n";
	}
	($CurrentUrl) = (m!<BR><B>Up:</B> <A HREF="([^"]*)/index.shtml">!);
        print OUT;
        }
    close(IN);
    close(OUT);
}

sub editIndex {
    local($in, $out) = @_;
    open(IN, "<$in");
    open(OUT, ">$out");
    while (<IN>) {
	s!Title!$ARGV[1]!;
	s!/MyUrl!$MyUrl!;
        print OUT;
        }
    close(IN);
    close(OUT);
}

&editTemplate("Template.shtml", "$ARGV[0]/Template.shtml");

&editIndex("Template.shtml", "$ARGV[0]/index.shtml");

system "touch $ARGV[0]/list_of_children";
