#!/usr/bin/perl

##############################################################################
# This program will rewrite Michels webpages to make then use the CSS style  #
# Sheets. It takes as it's only argument a kist of the files you would like  #
# to rewrite. It requires the exsistence of a template file (see below)      #
##############################################################################

$filelist = $ARGV[0];

open FILELIST, $filelist or die "can't open file list\n";



while($file =<FILELIST>){
	chomp($file);
	$fulltext = "";
	open FILE, $file or die "Can't open file $file\n";
	while ($line = <FILE>){
		
		$fulltext = $fulltext.$line;
	}
	$fulltext =~ /(<h1>.*)<\/font>/s;
	$betweenbody = $1;

	$fulltext =~ /<title>(.*)<\/title>/s;
	$title = $1;

	$fulltext =~ /<a href="\.\.\/">(.*)<h3>(.*)<\/h3>/s;
	$bread = $2;
	$betweenbody =~ s/<hr>//;
	$betweenbody =~ s/\.html/\.shtml/g;

	open TEMPLATE, "/hepuser/igable/public_html/atlas/assets/template/simplepagewrapper.shtml" or die "Can't find template";
	
	$shtmlfile = $file;
	$shtmlfile =~ s/\.html/\.shtml/;
	open SHTMLFILE , ">".$shtmlfile or die "Can't open $shtmlfile\n";

	while($templine = <TEMPLATE>){
		$templine =~ s/BREAD/$bread/;
		$templine =~ s/TITLE/$title/;
		$templine =~ s/MAINTEXT/$betweenbody/;
		print SHTMLFILE $templine;
	}
}

	
		

