# bull_html - Creates the HTML files for Multics inspection on an Internet serves
# by Bernard Nivelet, December 2005 plus recommendations of Tom Van Vleck in March 2006
#
# perl bullhtml.pl Multics_files_root html trace >result.txt

$now_string = localtime();
print "$now_string\n\n";


 $version = "1.7";

 my $Multics_files_root = shift; # Directory containing Multics files
 my $html = shift; # Directory that will contain html files 
 my $trace= shift; # 1 if tracing required, 0 otherwise

 my $DIR_HTML = 'fh0000'; # initialize indirect filehandle

 die "$Multics_files_root not a directory" if !-d $Multics_files_root; # check that $Multics_files_root is a dir
 die "$html not a directory" if !-d $html; # check that $html is a dir

					if($trace==1){
						print "bull_html $version\n\n";
					}

 if( !opendir($DIR_HTML, $html) ){ # creates $html and $DIR_HTML FILEHANDLE
	mkdir($html);
 }

 &checkdir($Multics_files_root, 0, $html, $DIR_HTML, $trace);

 closedir($DIR_HTML);

 exit(0);

# ================================================================
# recursive routine to process directories
# &checkdir($dirname, $level, $html, $DIR_HTML, $trace);
# ignores files beginning with dot

sub checkdir {
 my $dir = shift;
 my $level= shift;
 my $html= shift;
 my $DIR_HTML= shift;
 my $trace=shift;

 my $first_dir=0;
 my $first_file=0;
 my $f;
 my $object_name;


 $object_name = DirName($dir, "5F");
						if ( $trace==1 ){
							print "\nEnter $dir and create $html/$object_name\n\n";
						}

 $DIR_HTML++;
 open($DIR_HTML, ">$html/$object_name.html") || die "can't write $html/$object_name.html";
 binmode $DIR_HTML; # For Windows, write file as bytes.

 print $DIR_HTML "<html>\n";

 print $DIR_HTML "<head>\n";
 print $DIR_HTML "<title>Multics Internet Server</title>\n";
 print $DIR_HTML "<meta http-equiv='Content-Type' content='text/html;  charset=iso-8859-1'></meta>\n";
 print $DIR_HTML "<style type='text/css'>\n";
 print $DIR_HTML "<!-->\n";
 print $DIR_HTML ".fil a:link {color: green;}\n";
 print $DIR_HTML ".fil a:visited {color: gray;}\n";
 print $DIR_HTML ".fil a:hover {background-color: pink; color: black;}\n";
 print $DIR_HTML ".fil a:active {color: green;}\n";
 print $DIR_HTML ".dir a:link {color: maroon;}\n";
 print $DIR_HTML ".dir a:visited {color: gray;}\n";
 print $DIR_HTML ".dir a:hover {background-color: pink; color: black;}\n";
 print $DIR_HTML ".dir a:active {color: maroon;}\n";
 print $DIR_HTML "-->\n";
 print $DIR_HTML "</style>\n";
 print $DIR_HTML "</head>\n";

 print $DIR_HTML "<body>\n";

 print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='0'>\n";

 print $DIR_HTML "<TR>\n";

 print $DIR_HTML "<td width='57'><a target=_blank href='$html/'>\n";
 print $DIR_HTML "<img src='Logos/logo-MIT.gif' width='90.545' height='48' border='0' alt='$html'></a></td>\n";	# </img>

 print $DIR_HTML "<td><FONT SIZE='6' color='Navy' face='arial'>";
 print $DIR_HTML "<p align='center' class='heading' ><b><i>Multics Internet Server</i></b> </p></FONT></td>\n";

 print $DIR_HTML "<td width='112'><a target=_blank  href='$html/'\n>";
 print $DIR_HTML "<img src='Logos/logo-Bull.jpeg' width='175' height='70' border='0' alt='$html/'></a></td>\n";	# </img>

 print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='0' >\n";
 print $DIR_HTML "<tr><td class=block VALIGN=MIDDLE WIDTH='100%' BGCOLOR='#EAE2BB'>\n"; # BGCOLOR='#EAE2BB' beige
 	$object_name = DirName($dir, "3E");
 print $DIR_HTML "<FONT SIZE='4' color='Purple' face='arial'>\n";
 print $DIR_HTML "<p align='center' class='heading'><b>DIRECTORY $object_name</b></p>";
 print $DIR_HTML "</FONT></TD></TR></table>\n";

 print $DIR_HTML "</TR></table>\n";

						if ( $trace==1 ){
							print "Opendir data $dir\n";
						}
 opendir(DH, "$dir");
 my(@allfiles) = grep !/^\./, readdir DH;
 closedir DH;

 foreach $f (@allfiles) {

	if (-f "$dir/$f") { # if it's a file
		if( index($f,".html")>0 ){
			unlink($f);
		}else{
			if ($first_file==0){
				if($first_dir!=0){
					$first_dir=0;
				#	print $DIR_HTML "</FONT></ul>";
					print $DIR_HTML "</ul>";
				}
				print $DIR_HTML "<FONT SIZE=3 color=Green face='arial'>\n";
 				print $DIR_HTML "<h3><a name='Files :'>Files :</a></h3></FONT>\n";
				print $DIR_HTML "<ul class='fil'>\n";
			}
			$first_file++;
						if ( $trace==1 ){
							print "href data file  $dir/$f\n";
						}
			print $DIR_HTML "<li> <a href=$dir/$f> $f </a></li>\n";
		}

	} elsif (-d "$dir/$f") { # if it's a directory

		if ($first_dir==0){
			if($first_file!=0){
				$first_file=0;
				print $DIR_HTML "</ul>";
			}
			print $DIR_HTML "<FONT SIZE=3 color=Maroon face='arial'>\n";
			print $DIR_HTML "<h3><a name='Directories :'>Directories :</a></h3></FONT>\n";
			print $DIR_HTML "<ul class='dir'>\n";
		}
		$first_dir++;
						if ( $trace==1 ){
							print "Call checkdir       $dir/$f\n";
						}
		$object_name = DirName("$dir/$f", "5F");
		print $DIR_HTML "<li><a class='doc' href='$object_name.html'> $f </a></li>\n";

		&checkdir("$dir/$f", $level+1, $html, $DIR_HTML, $trace);

						if ( $trace==1 ){
							print "Return checkdir     $dir/$f\n\n";
						}

	} else {
		# not file, not dir, ignore
	}
 } # foreach

 print $DIR_HTML "</FONT></ul>\n\n";

 if ($level == 0){
	print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='5' >\n";
	print $DIR_HTML "<tr><td class='block' VALIGN='MIDDLE' WIDTH='100%' BGCOLOR='#EAE2BB'>\n"; # BGCOLOR='#EAE2BB' beige
	print $DIR_HTML "<FONT SIZE='4' color='Navy' face='arial'>\n";
	print $DIR_HTML "<p align='center' class='heading'><b><i>INSTRUCTIONS for USE</i></b></p>";
	print $DIR_HTML "</FONT></TD></TR></table>\n";

	print $DIR_HTML "<FONT SIZE='2' face='arial'>\n";
	print $DIR_HTML "<p>\n";
	print $DIR_HTML "At the top of the page is the name of the <font size=4 color=Purple><b>current directory</b></font>\n";
	print $DIR_HTML " .</p>\n";
	print $DIR_HTML "<p>Underneath, could appear the two titles <font size=3 color=Green><b>Files</b></font>\n";
	print $DIR_HTML " or <font size='3' color='Maroon'><b>Directories</b></font> .\n";
	print $DIR_HTML "</p>\n";

	print $DIR_HTML "Under <font size='3' color='Green'><b>Files</b></font>\n";
	print $DIR_HTML ", if present, appear the names of the files contained in the current directory . Depending on the type of the file as viewed by the user file system, \n";
	print $DIR_HTML "<font size='3'><i>when clicking on the name of the file</font></i>, four types of action could happen :</p>\n";
	print $DIR_HTML "<ul><ul><font size='3'><i>\n";
	print $DIR_HTML "<li>The automatic display of the content of this file .</li>\n";
	print $DIR_HTML "<li>The automatic display of the content of this file by an editor ( Wordpad or Word if  you use Windows ) .</li>\n";
	print $DIR_HTML "<li>The automatic display of a window asking two questions :</li>\n";
	print $DIR_HTML "<ul>\n";
	print $DIR_HTML "<li>Either to display the file  by an editor ( Wordpad or Word if  you use Windows ) ;</li>\n";
	print $DIR_HTML "<li>Or to copy the file somewhere in the user system .</li>\n";
	print $DIR_HTML "</ul>\n";
	print $DIR_HTML "</i></font></ul></ul>\n";
	print $DIR_HTML "If needed, binary files can be always copied somewhere to be analized using some byte editor like Hexplorer .\n";

	print $DIR_HTML "<p>Under <font size='3' color='Maroo'n><b>Directories</b></font> , if present, appear the \n";
	print $DIR_HTML "names of the directories contained in the current directory . Remember that Multics directories have been reorganized in three types \n";
	print $DIR_HTML "of directories :</p>\n";
	print $DIR_HTML "<ul>\n";
	print $DIR_HTML "<li>Multics directories, restricted to the ASCII files contained in the original Multics directory;</li>\n";
	print $DIR_HTML "<li>binaries directories containing the binary files of the upper Multics directory ;</li>\n";
	print $DIR_HTML "<li>damaged directories containing the damaged files of the upper Multics directory ( due to conversion or disk errors at Calgary ) .</li>\n";
	print $DIR_HTML "</ul>\n";
	print $DIR_HTML "<ul><ul><font size='3'><i>\n";
	print $DIR_HTML "<li>Clicking on a directory reference will display the content of this new directory .</li>\n";
	print $DIR_HTML "</i></font></ul></ul>\n";

	print $DIR_HTML "<p>To return to the upper directory, use your browser's BACK function ( if you use Internet Explorer under Windows, click as usual on the left arrow \n";
	print $DIR_HTML "at the left up corner ) .</p>\n";

	print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='5' >\n";
	print $DIR_HTML "<tr><td class='block' VALIGN='MIDDLE' WIDTH='100%' BGCOLOR='#EAE2BB'>\n"; # BGCOLOR='#EAE2BB' beige
	print $DIR_HTML "<FONT SIZE='4' color='Navy' face='arial'>\n";

	print $DIR_HTML "<P align='center' class='heading'><b><i>HISTORICAL BACK GROUND</i></b></P>";
	print $DIR_HTML "</FONT></TD></TR></table>\n";
	print $DIR_HTML "<FONT SIZE='2' face='arial'>\n";
	print $DIR_HTML "<ul>\n";
	print $DIR_HTML "<li>This edition of the Multics software materials and documentation is provided and donated to Massachusetts Institute of Technology \n";
	print $DIR_HTML "by Group BULL including BULL HN Information Systems Inc. as a contribution to computer science knowledge .</li>\n";
	print $DIR_HTML "<li>This donation is made also to give evidence of the common contributions of Massachusetts Institute of Technology, \n";
	print $DIR_HTML "Bell Laboratories, General Electric, Honeywell Information Systems Inc., Honeywell BULL Inc., Groupe BULL \n";
	print $DIR_HTML "and BULL HN Information Systems Inc. to the development of this operating system .</li>\n";
	print $DIR_HTML "<li>Multics development was initiated by Massachusetts Institute of Technology Project MAC (1963-1970) , renamed \n";
	print $DIR_HTML "the MIT Laboratory for Computer Science and Artificial Intelligence in the mid 1970s ,  under the leadership of Professor \n";
	print $DIR_HTML "Fernando Jose Corbato. Users consider that Multics provided the best software architecture for managing computer hardware \n";
	print $DIR_HTML " properly and for executing programs. Many subsequent operating systems incorporated Multics principles. </li>\n";
	print $DIR_HTML "<li>Multics was distributed in 1975 to 2000 by Group Bull in Europe , and in the U.S. by Bull HN Information Systems Inc., \n";
	print $DIR_HTML "as successor in interest by change in name only to Honeywell Bull Inc. and Honeywell Information Systems Inc. .</li>\n";
	print $DIR_HTML "<li><FONT SIZE='2' color='Navy' face='arial'><b><i>To know more</i></b></FONT>, \n";
	print $DIR_HTML "look at <A HREF='http://www.multicians.org/multics.html'><b>Multicians</b></A> .</li>\n";
	print $DIR_HTML "</ul>\n";
	print $DIR_HTML "</FONT>";

	print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='5' >\n";
	print $DIR_HTML "<tr><td class='block' VALIGN='MIDDLE' WIDTH='100%' BGCOLOR='#EAE2BB'>\n"; # BGCOLOR='#EAE2BB' beige
	print $DIR_HTML "<FONT SIZE='4' color='Navy' face='arial'>\n";
	print $DIR_HTML "<P align='center' class='heading'><b><i>ACKNOWLEDGEMENTS</i></b></P>\n";
	print $DIR_HTML "</FONT></TD></TR></table>\n";

	print $DIR_HTML "<FONT SIZE='2' face='arial'>\n";

	print $DIR_HTML "<p>The decision to retrocede the Multics Sources from Bull to MIT was made by \n";
	print $DIR_HTML "Didier LAMOUCHE, President of Bull .</p>\n";
	print $DIR_HTML "<p>The decision to create this Internet site was made by Jerry  GROCHOW , \n";
	print $DIR_HTML "Senior IT Executive at MIT (Cambridge, MA) .</p>\n";

	print $DIR_HTML "The following Bull Managers have made possible the positive decision making on this project: \n";
	print $DIR_HTML "<ul>\n";
	print $DIR_HTML "<li>Gerard ROUCAIROL, Group Bull Chief Scientist, (Les Clayes-sous-Bois, France) .</li>\n";
	print $DIR_HTML "<li>Herve MOUREN, President of Bull Systems, (Les Clayes-sous-Bois, France) .</li>\n";
	print $DIR_HTML "<li>Matthew FOXTON, Group Bull VP for Communication, (Les Clayes-sous-Bois, France) .</li>\n";
	print $DIR_HTML "<li>Christian LOYAU, Group Bull General Counsel, (Les Clayes-sous-Bois, France) .</li>\n";
	print $DIR_HTML "<li>Henry PFAHL, GCOS Product Lines Director, (Les Clayes-sous-Bois, France) .</li>\n";
	print $DIR_HTML "<li>Bob FOWLER, Director, Customer Support & Quality, Bull HN Information Systems (Phoenix, AZ) .</li>\n";
	print $DIR_HTML "<li>Tom MAHER, Bull HN General Counsel, (Billerica, MA) .</li>\n";
	print $DIR_HTML "<li>Guy PROUD, Director of GCOS Development for Bull, (Phoenix, AZ, and Les Clayes-sous-Bois, France) .</li>\n"; 
	print $DIR_HTML "</ul>\n";

	print $DIR_HTML "The achievement of this project would not be possible without the involvement of the following Engineers :\n";
	print $DIR_HTML "<ul>\n";
	print $DIR_HTML "<li>Tom VAN VLECK, Multicians site Manager, whose constant help to this project have made it to\n";
	print $DIR_HTML " succeed. Tom has brought all his expertise on Multics, and also a large programmatic \n";
	print $DIR_HTML "support in Perl to process the 14 384 files of Mutltics \n";
	print $DIR_HTML "Sources presented here and in HTML to create this server. Great thanks to Tom.</li>\n";
	print $DIR_HTML "<li>David SCHROTH, who saved on a DAT the entire Multics Sources before the shutdown of \n";
	print $DIR_HTML "the last Multics system running in CGI (Calgary, Canada). Whitout his intervention, Multics \n";
	print $DIR_HTML "Sources would be lost. Special thanks to Dave and CGI.</li>\n";
	print $DIR_HTML "<li>Henrik CZAJA, SuperSelect engineer, who kept the DAT for two years .Thanks to Henrick .</li>\n";
	print $DIR_HTML "<li>Jacky BOULAY, Systems Operation, Bull Engineering, (Les Clayes-sous-Bois, France), who \n";
	print $DIR_HTML " created the CDs from the David DAT . Thanks to Jacky .</li>\n";
	print $DIR_HTML "<li>Alain LEMOINE, Systems Operation, Bull Engineering, (Les Clayes-sous-Bois, France), who helped \n";
	print $DIR_HTML "to correct characters changes by Windows from Unix . Thanks to Alain .</li>\n";
	print $DIR_HTML "<li>Patrick BIENATI, Systems Operation, Bull Engineering, (Les Clayes-sous-Bois, France), who helped \n";
	print $DIR_HTML " in making the final delivered material   . Thanks to Patrick .</li>\n";
	print $DIR_HTML "</ul>\n";

	print $DIR_HTML "</FONT>";

	print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='5' >\n";
	print $DIR_HTML "<tr><td class='block' VALIGN='MIDDLE' WIDTH='100%' BGCOLOR='#EAE2BB'>\n"; # BGCOLOR='#EAE2BB' beige
	print $DIR_HTML "<FONT SIZE='4' color='Navy' face='arial'>\n";
	print $DIR_HTML "<P align='center' class='heading'><b><i>COPYRIGHT</i></b></P>";
	print $DIR_HTML "</FONT></TD></TR></table>\n";
	print $DIR_HTML "<FONT SIZE=2 face='arial'>\n";
	print $DIR_HTML "<p>\n";
	print $DIR_HTML "Permission to use, copy, modify, and distribute these programs and their documentation \n";
	print $DIR_HTML "for any purpose and without fee is hereby granted, provided that this copyright notice and the above historical background \n";
	print $DIR_HTML "appear in all copies and that both the copyright notice and historical background and this permission notice appear \n";
	print $DIR_HTML "in supporting documentation, and that the names of MIT, HIS, BULL or BULL HN not be used in advertising or publicity \n";
	print $DIR_HTML "pertaining to distribution of the programs without specific prior written permission.\n";
	print $DIR_HTML "</p>\n";
	print $DIR_HTML "<ul>";

	print $DIR_HTML "<li>Copyright 1972 by the Massachusetts Institute of Technology and \n";
	print $DIR_HTML "Honeywell Information Systems Inc.</li>\n";
	print $DIR_HTML "<li>Copyright 2006 by Bull HN Information Systems Inc.</li>\n";
	print $DIR_HTML "<li>Copyright 2006 by Bull SAS</li>\n";

	print $DIR_HTML "<li>All Rights Reserved</li>\n";
	print $DIR_HTML "</ul></FONT>";

	print $DIR_HTML "<table width='100%' border='0' cellspacing='0' cellpadding='0' >\n";
	print $DIR_HTML "<tr><td class='block' VALIGN='MIDDLE' WIDTH='100%' BGCOLOR='#EAE2BB'>\n"; # BGCOLOR='#EAE2BB' beige	
	print $DIR_HTML "<FONT SIZE='3' color='Navy' face='arial'>\n";
	print $DIR_HTML "<p align='center' class='heading'><b><i>AUTHOR</i></b></p>";
	print $DIR_HTML "</FONT></TD></TR></table>\n";
#	print $DIR_HTML "<P></p>";
	print $DIR_HTML "<p>This Project was realized by Bernard NIVELET, retired Director from Bull -- Strategy, Engineering and Sales --  \n";
	print $DIR_HTML "(Les Clayes-sous-Bois, France) .</p>\n";
	print $DIR_HTML "<p>Please, if any remarks, send them to <a HREF='mailto:bernard.nivelet\@wanadoo.fr'>him</a> .</p>\n";

 }

 print $DIR_HTML "</BODY>\n</HTML>\n";

 close($DIR_HTML);

} # checkdir

# ================================================================
sub DirName {
	my $dir = shift;
	my $char_rep = shift;

	my $p=0;
	my $object_name;
	my $sub;

	if( (substr($dir,0,3) eq "c:/") || (substr($dir,0,3) eq "c:\\") ){
		$sub = substr($dir,3);
	}else{
		$sub= $dir;
	}
	if( (substr($sub,0,39) eq "Multics_Internet_Server/Multics_Sources") || (substr($sub,0,39) eq "Multics_Internet_Server\\Multics_Sources") ){
		$object_name=substr($sub,39);
	}else{
		$object_name=$sub;
	}
	if( (substr($object_name,0,1) eq "/") || (substr($object_name,0,1) eq "\\") ){
		$object_name=substr($object_name,1);
	}

	my $dl=length($object_name);
	if ($dl == 0){
		$object_name="Multics_sources";
	}else{
		while( ($p<$dl) && ($p>=0) ){
			$p=index($object_name, "/", $p);
			if( $p >= 0 ){
				vec($object_name, $p, 8) = hex($char_rep);
				$p+=1;
			}
		}
		$p=0;
		while( ($p<$dl) && ($p>=0) ){
			$p=index($object_name, "\\", $p);
			if( $p >= 0 ){
				vec($object_name, $p, 8) = hex($char_rep);
				$p+=1;
			}
		}
		$p=0;
		while( ($p<$dl) && ($p>=0) ){
			$p=index($object_name, ".", $p);
			if( $p >= 0 ){
				vec($object_name, $p, 8) = hex($char_rep);
				$p+=1;
			}
		}
	}

 return $object_name

} # end DirName

# ================================================================
