#! /usr/bin/perl # gen-type-map.pl # See http://nicku.org/manual/content-negotiation.html # For each file named on the command line, # skip with error message unless extension is .s?html # create a symbolic link from e.g., foo.shtml to foo.sxhtml # or from foo.html to foo.xhtml # create the file foo.var which is the correct type map file for foo # Copyright (C) 2006 Nick Urbanik # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use warnings; use strict; sub check_filename($) { my ( $filename ) = @_; return 1 if $filename =~ m{\.s?html$}xms; warn "Expected a filename with the extension .shtml or .html ", "but $filename does not match; skipping it.\n"; return; } sub link_xml_filename($) { my ( $htmlname ) = @_; ( my $xmlname = $htmlname ) =~ s{\.(s?)html$}{.$1xhtml}xms; if ( -e $xmlname and not -l $xmlname ) { warn "$xmlname exists but is not a symbolic link\n"; return; } if ( -l $xmlname ) { unlink $xmlname or die "unable to unlink $xmlname: $!"; warn "Re-created a symbolic link $htmlname, $xmlname: ", "Deleted old link.\n"; } symlink $htmlname, $xmlname or warn "Unable to symlink $htmlname, $xmlname: $!" and return; return 1; } sub make_map_file($) { my ( $htmlname ) = @_; ( my $basename = $htmlname ) =~ s{\.(s?)html$}{}xms; my $ssi = $1; my $mapname = $basename . '.var'; if ( -e $mapname ) { warn "Map file $mapname exists, not overwriting.\n"; return; } open my $map_fh, '>', $mapname or die "Unable to open $mapname for writing: $!"; print $map_fh <