#!/usr/bin/perl -w # quick validator as Subversion pre-commit hook # Copyright 2007 Kenshi Muto use strict; use Text::Iconv; exit(0) if (@ARGV < 2); my(@targets) = qw(MirrorsJP.list blosxom/ include/ src/); my($svnlook) = "/usr/bin/svnlook"; my($repos) = $ARGV[0]; my($txn) = $ARGV[1]; my(@files); my($status) = ""; my($converter_euc) = Text::Iconv->new("EUC-JP", "EUC-JP"); open(P, "$svnlook changed $repos -t $txn |"); while(

) { if (/^U/ || /^A/) { # update or new chomp; my($flag, $file) = split(/\s+/, $_, 2); next if ($file =~ /\/$/); # directory my($go) = 0; foreach my $t (@targets) { if ($file =~ /^$t/) { $go = 1; last; } } next if ($go == 0); push(@files, $file); } } close(P); foreach my $file (@files) { open(P, "$svnlook cat $repos $file -t $txn |"); my($line) = 1; while (

) { if ($status !~ /:encoding:/) { $converter_euc->convert($_); if (!defined($converter_euc->retval)) { print STDERR "$file (-): The encoding must be EUC-JP.\n"; $status .= ":encoding:" if ($status !~ /:encoding:/); } } if ($file =~ /^blosxom\/.*\.d$/) { # Check blosxom articles if ($line == 2 && !/^\s*$/) { print STDERR "$file ($line): Insert a newline at line 2.\n"; $status .= ":newline:"; } if (/\[%/ || /%\]/) { print STDERR "$file ($line): You can't use TT tag [% %] in a blog article.\n"; $status .= ":TT:" if ($status !~ /:TT:/); } if (/\&/g) { my($post) = $'; if ($post !~ /^\#\d+;/ && $post !~ /^[a-z0-9]+;/) { print STDERR "$file ($line): & should be replaced with '&' entity.\n"; $status .= ":amp:" if ($status !~ /:amp:/); } } } $line++; } close(P); } ($status eq "") ? exit(0) : exit(1);