#!/usr/bin/perl # Generate site V2. # Perl script to generate my web site from a load of # simple ascii source chunks. use strict; my ($page, $chunk, @pages); # number of pages. my $total=16; # build index page copy_file( "header.src", "../index.html" ); $chunk="[ Next ]\n"; append_chunk( "../index.html", $chunk ); append_file( "secondchunk.src", "../index.html" ); append_file( "index.src" , "../index.html" ); for(my $i=0; $i<$total; $i++ ){ $page=$i+1; print"building $page \b.html\n"; print"adding header to $page\n"; copy_file( "header.src", "../" . $page . ".html" ); if( $i eq "0" ){ $chunk="[ Previous ]\n"; append_chunk( "../".$page.".html", $chunk ); } else { $chunk="[ Previous ]\n"; append_chunk( "../".$page.".html", $chunk ); } $chunk="[ Home ]\n"; append_chunk( "../".$page.".html", $chunk ); if( $i ne ($total-1) ){ $chunk="[ Next ]\n"; append_chunk( "../".$page.".html", $chunk ); } append_file( "secondchunk.src", "../".$page.".html" ); print"adding body to $page\n"; append_file( $page.".src" , "../" . $page . ".html" ); print"adding next, previous buttons"; $chunk="
\n
\n"; append_chunk( "../" . $page . ".html" , $chunk ); if( $i eq "0" ){ $chunk="[ Previous ]\n"; append_chunk( "../".$page.".html", $chunk ); } else { $chunk="[ Previous ]\n"; append_chunk( "../".$page.".html", $chunk ); } $chunk="[ Top ]\n"; append_chunk( "../".$page.".html", $chunk ); $chunk="[ Home ]\n"; append_chunk( "../".$page.".html", $chunk ); if( $i ne ($total-1) ){ $chunk="[ Next ]\n"; append_chunk( "../".$page.".html", $chunk ); } $chunk="
\n"; append_chunk( "../".$page.".html", $chunk ); print"adding footer to $page\n"; append_file( "footer.src", "../" . $page . ".html" ); print"adding link to index\n"; $chunk="
  • $page
    \n"; append_chunk( "../index.html", $chunk ); } $chunk="
    \n
    \n"; append_chunk( "../index.html" , $chunk ); $chunk="[ Next ]\n
    "; append_chunk( "../index.html", $chunk ); print"adding footer to index\n"; append_file( "footer.src", "../index.html" ); print "chmodding\n"; system "chmod a+r ../*"; system "chmod a+r ../graphs/*"; system "chmod a+r ../scripts/*"; # copy_file( in, out ) is a function # to copy one file to another. sub copy_file { my( $filein, $fileout ) = @_; open( IN, $filein ) || die "Cant open $filein for reading: $!"; open( OUT, ">" . $fileout ) || die "Cant open $fileout for writing: $!"; while( ){ print OUT $_; } close( IN ) || die "Cant close $filein: $!"; close( OUT ) || die "Cant close $fileout: $!"; } # append_file( in, out ) is a function to # append one file to the end of another. sub append_file { my( $filein, $fileout ) = @_; open( IN, $filein ) || die "Cant open $filein for reading: $!"; open( OUT, ">>" . $fileout ) || die "Cant open $fileout for appending: $!"; while( ){ print OUT $_; } close( IN ) || die "Cant close $filein: $!"; close( OUT ) || die "Cant close $fileout: $!"; } # append_chunk( file, chunk ) is a function # to append a chunk to file. sub append_chunk { my( $file, $chunk ) = @_; open( OUT, ">>" . $file ) || die "Cant open $file for appending: $!"; print OUT "$chunk"; close( OUT ) || die "Cant close $file: $!"; }