# HG changeset patch # User Steve Kemp # Date 1209758685 -3600 # Node ID 9e79fe60ad479bb0d40f879f05222ee907bae85e # Parent 37668661af766120d65e8817c46f6a76d465a614 Added to repository diff -r 37668661af76 -r 9e79fe60ad47 bin/check-titles --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/check-titles Fri May 02 21:04:45 2008 +0100 @@ -0,0 +1,91 @@ +#!/usr/bin/perl -w +# +# A simple utility which will process each "*.txt" file inside a named +# directory. +# +# Any entries with a duplicate title will be alerted. +# +# Steve +# + +use strict; +use warnings; + + +# +# Get the directory and ensure it exists. +# +my $dir = shift; +die "Usage: $0 directory" unless ( defined($dir) ); +die "Not a directory : $dir" unless ( -d $dir ); + + +# +# The hash of arrays +# +my $titles; + + +# +# Find the files. +# +foreach my $file ( sort( glob( $dir . "/*" ) ) ) +{ + + # + # Skip non-files + # + next if ( -d $file ); + next if ( $file =~ /~$/ ); + + # + # Title for this entry. + # + my $title = undef; + + # + # Read each file, and look for the title. + # + open( IN, "<", $file ) + or die "Failed to read $file - $!"; + foreach my $line () + { + $title = $2 + if ( !defined($title) + && ( $line =~ /^(Subject|Title):(.*)/i ) ); + + } + close(IN); + + # + # Get current entries we might have found with + # this title; and add on the new one. + # + my $a = $titles->{ $title }; + push( @$a, $file ); + $titles->{ $title } = $a; +} + + +# +# Now look for dupes +# +my $fail = 0; +foreach my $title ( keys %$titles ) +{ + my $a = $titles->{ $title }; + + if ( ( scalar @$a ) > 1 ) + { + print "Title: $title\n"; + foreach my $file (@$a) + { + print "\t" . $file . "\n"; + } + + $fail = 1; + } +} + + +exit($fail);