#!/usr/bin/perl -w # Copyright © 2000-2010 Jamie Zawinski . # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation. No representations are made about the suitability of this # software for any purpose. It is provided "as is" without express or # implied warranty. # # Created: 28-Nov-00. # # This script generates/updates the template wrapper and menu contents on # all of the DNA Lounge pages. It goes like this: # # - read the target file, and extract the "content" portions of it # (the sections between "RIGHT_START and RIGHT_END", etc.) # - take the template file, and insert the content into it; # - generate a menu for the target file, and splice that in too; # - write the result out to the target file. # # In this way, we ensure that any changes to the template file always get # pushed down into every file that uses it. require 5; use diagnostics; use strict; use bytes; my $progname = $0; $progname =~ s@.*/@@g; my $version = q{ $Revision: 1.114 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; BEGIN { my $exec_dir = $0; $exec_dir =~ s@/[^/]*$@@; push @INC, $exec_dir; } use Menuify; sub usage() { print STDERR "usage: $progname [--verbose] [--validate] [--debug] " . "[--template file] [--base URL] [ files-to-update...]\n"; exit 1; } sub menuify($); sub menuify($) { my ($file) = @_; if (-d $file) { local *DIR; return if ($file =~ m@\bbackstage/specs$@s); #### Kludge. opendir (DIR, "$file") || error ("$file: $!"); print STDERR "$progname: reading dir $file/\n" if ($DNA::Menuify::verbose > 1); my @files = sort readdir (DIR); closedir DIR; foreach my $f (@files) { next if ($f =~ m/^\./s); next if ($f eq 'CVS'); $f = "$file/$f" unless ($file eq '.'); next unless ($f =~ m/\.html$/s || -d $f); menuify ($f); } } else { return if ($file =~ m@\butils/template\.html$@s); #### Kludge. my $body = ''; { local *IN; open(IN, "<$file") || error ("$file: $!"); local $/ = undef; # read entire file $body = ; close IN; } DNA::Menuify::write_file ($file, $body); } } sub error($) { my ($err) = @_; print STDERR "$progname: $err\n"; exit 1; } sub main() { $DNA::Menuify::verbose++; my @files; while ($#ARGV >= 0) { $_ = shift @ARGV; if (m/^--?verbose$/) { $DNA::Menuify::verbose++; } elsif (m/^-v+$/) { $DNA::Menuify::verbose += length($_)-1; } elsif (m/^--?quiet$/) { $DNA::Menuify::verbose = 0; } elsif (m/^--?debug$/) { $DNA::Menuify::debug++; } elsif (m/^--?base$/) { $DNA::Menuify::base_url = shift @ARGV; } elsif (m/^--?template$/) { $DNA::Menuify::template_file = shift @ARGV; } elsif (m/^--?validate$/) { $DNA::Menuify::validate++; } elsif (m/^-./) { usage; } else { push @files, $_; } } usage unless ($#files >= 0); foreach my $f (@files) { $f =~ s@/+$@@s; menuify ($f); } } main(); exit 0;