#!/usr/bin/perl

=head1 NAME

changecities.pl -- analyze DB changelog to substitute cities

=head1 SYNOPSIS

changecities.pl B<-c> ChangeLog -d <directory>

=head1 DESCRIPTION

The program looks at all html files in the I<directory> and substitutes 
C<tour=oldcity> by C<tour=newcity> for each line like
  oldcity -> newcity

in the ChangeLog

=over 4

=item B<-c> ChangeLog

Location of the ChangeLog file

=item B<-d> directory

Directory of html files

=back

=head1 AUTHOR

Boris Veytsman

=head1 $Id: changecities.pl,v 1.2 2000/10/17 15:33:46 boris Exp $

=cut

    use strict;
use vars qw($opt_c $opt_d);
use Getopt::Std;

getopts('c:d:') or die "Wrong arguemnts";
open (CHANGELOG, $opt_c) or die "Cannot open ChangeLog $opt_c";
chdir $opt_d or die "Cannot chdir to $opt_d";
while (<CHANGELOG>) {
    chomp;
    next unless (/->/);
    m/^\s*(\S*)\.txt\s*->\s*(\S*)\.txt/ or print "Bad line: $_";
    my $oldname=$1;
    my $newname=$2;
    print "Changing $oldname to $newname\n";
    open(FILES, "grep -l \'tour=$oldname\' *.html|");
    while(<FILES>) {
	chomp;
	my $file = $_;
	print "CONVERTING $file.";
	`perl -iorig -p -e 's/tour=$oldname/tour=$newname/g' $file`;
	print "..\n";
    }
}

