#!/usr/local/bin/perl -w eval 'exec /usr/local/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell use strict; use Getopt::Long; use HTTP::Status; use LWP::Simple; use Unicode::Map; my $emptyMap = 0; my $numWarnings = 0; my $numErrors = 0; my %opt = ( ); main: { $|=1; _getOptions ( ); _mirror ( ); _summarizeResult ( ); exit $numErrors; } sub _getOptions { GetOptions ( \%opt, "update" ); if ( !$opt{"update"} ) { usage ( ); } } sub usage { print <ids() ) { _mirrorOne ( $_ ); } } } sub _mirrorOne { my ($id) = @_; print "Processing \"$id\": "; $id = $emptyMap -> id ( $_ ); my $srcURL = $emptyMap -> srcURL ( $id ); my $srcCopy = $emptyMap -> src ( $id ); if ( !$srcCopy ) { print "Error!\n"; print "! No 'src:' entry for this charset in file 'REGISTRY'!\n"; $numErrors++; return; } if ( !_mkFilePath($srcCopy) ) { print "Error!\n"; print "Couldn't create directory! ($!)\n"; $numErrors++; return; } if ( !$srcURL ) { print "Warning!\n"; print <0 ) { my $msg; $msg = "$numErrors error"; $msg .= "s" if $numErrors>1; $msg .= ", $numWarnings warning" if $numWarnings>0; $msg .= "s" if $numWarnings>1; $msg .= "."; print "Error! Encountered $msg\n"; } else { my $msg; $msg = "$numWarnings warning"; $msg .= "s" if $numWarnings>1; $msg .= "."; print "Warning! Possible trouble! $msg\n"; } } ## ## Utilities ## sub _mkFilePath { my ( $filePath ) = @_; my $file = substr ( $filePath, rindex($filePath,"/")+1 ); my $path = $filePath; $path =~ s/$file$//; _mkPath ( $path ); } sub _mkPath { my ( $path ) = @_; my $current = ""; for (grep {$_} split /\//, $path) { $current .= "/$_"; if ( !-d $current ) { if ( !_mkdir($current) ) { return 0; } } } 1} sub _mkdir { my ( $path ) = @_; if ( !-d $path ) { if ( !mkdir ($path, 0777 ) ) { return 0; } } 1}