#!/usr/bin/perl -w # # hpp.pl HTML preprocessor # Copyright 2001 Mark Paschal # # See accompanying LICENSE file for software license. # # Sorry for the lack of comments. use strict; my %defines; my $firstFile = shift(@ARGV) || die("Syntax: perl \\\hpp.pl \n"); (undef, undef, undef, undef, undef, undef, undef, undef, undef, $defines{'modifiedTime'}, $defines{'createdTime'}, undef) = stat($firstFile); my @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); my (undef, $min, $hour, $mday, $mon, $year, undef) = localtime($defines{'modifiedTime'}); $year += 1900; $min = "0$min" if $min < 10; $defines{'modifiedTime'} = "$hour:$min $mday $months[$mon] $year"; (undef, $min, $hour, $mday, $mon, $year, undef) = localtime($defines{'createdTime'}); $year += 1900; $min = "0$min" if $min < 10; $defines{'createdTime'} = "$hour:$min $mday $months[$mon] $year"; sub processFile { my $filename = shift || die("No file to process!\n"); my @lines; open(File, "<$filename") || die("Could not open file $filename for reading: $!\n"); @lines = ; foreach my $line (@lines) { processLine($line); }; } sub processLine { my $line = shift; $line =~ s/%(.+?)%/$defines{$1} if defined($defines{$1})/ge; if ($line =~ /^#include (.+?)\n/o) { processFile($1); } elsif ($line =~ /^#define (\S+?) (.+?)\n/o) { $defines{$1} = $2; } elsif ($line =~ /^#do (.+?)\n/o) { print (eval $1); } else { print $line; }; } processFile($firstFile); exit();