#!/usr/bin/perl -w # vim: set sw=4 ts=4 si et: # Copyright: GPL # Written by Guido Socher # use strict; use vars qw($opt_h); use Getopt::Std; my $head; my $content; my $bfile; my $ver="version 0.4"; # &getopts("h")||die "ERROR: No such option. -h for help.n"; &help if ($opt_h); &help unless ($ARGV[0]); open(SKEL,$ARGV[0])||die "ERROR con not read $ARGV[0]\n"; while(){ print; if (/macro\s+insert\s+boxes/){ foreach $bfile (&boxfiles(&basedir($ARGV[0]))){ &readboxtemplate($bfile); print "\n\n \n"; print " \n \n \n"; print " \n
\n"; print " \n"; print " $head\n \n"; print "
\n$content\n
\n\n"; print "\n\n"; } } if (/macro\s+insert\s+body/){ foreach $bfile (&bodyfiles(&basedir($ARGV[0]))){ open(BODY,$bfile)||die "ERROR con not read $bfile\n"; $content=join("",); close BODY; print "\n
\n"; print "$content\n"; print "\n"; } } } close SKEL; #-------- # get files which match the name body from the directory #-------- sub bodyfiles($){ my $dir=shift; my @result; my $file; opendir(DIR,$dir)||die "ERROR: can not read directory $dir\n"; foreach $file (readdir(DIR)){ if ($file=~/body.+html/){ $file="$dir/$file"; push(@result,$file); } } closedir DIR; die "ERROR: no files with name SOMETHING.body.SOMETHING.html in directoy $dir\n" unless(@result); return(sort @result); } #-------- # get files which match the name box from the directory #-------- sub boxfiles($){ my $dir=shift; my @result; my $file; opendir(DIR,$dir)||die "ERROR: can not read directory $dir\n"; foreach $file (readdir(DIR)){ if ($file=~/box.+html/){ $file="$dir/$file"; push(@result,$file); } } closedir DIR; die "ERROR: no files with name SOMETHING.box.SOMETHING.html in directoy $dir\n" unless(@result); return(sort @result); } #-------- # get the base dir from a file name #-------- sub basedir($){ my $file=shift; if ($file=~m|(.+)/|){ return($1); }else{ return("."); } } #-------- # read a box template and take

...

as box header and # all text that follows as box content. # Writes to the global vaiables $head and $content #-------- sub readboxtemplate($){ my $file=shift; my $dat; open(BOX,$file)||die "ERROR con not read $file\n"; $dat=join("",); close BOX; if ($dat=~ m/<[hH]2>(.+?)<\/[hH]2>/s){ $head=$1; $content=$'; }else{ die "ERROR: $file does not start with

...

\n"; } } #-------- sub help{ print STDERR "lfpagecomposer -- a simple macro expander for LinuxFocus index pages. lfpagecomposer takes a skeleton file as argument and inserts the content of all *body*.html files in the same directory after the line in the skeleton. lfpagecomposer looks also for in the skeleton file and generates boxes form the files *box*.html files. These box files must have a

...

at the beginning. This will be put into the box header and the text after into the box body. The *body*.html and *box*.html files are processed in alphabetical order (same order as \"ls *body*.html *box*.html\"). USAGE: lfpagecomposer [-h] skeletonfile.html EXAMPLE: lfpagecomposer skel.html > index.html The homepage of lfpagecomposer can be reached form http://www.linuxfocus.org/developer/Guido/ $ver \n"; exit; } __END__