| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Script to localize newlines |
| 4 |
|
| 5 |
use 5.005; |
| 6 |
use strict; |
| 7 |
use Getopt::Long; |
| 8 |
use File::Spec; |
| 9 |
use File::Find::Rule; |
| 10 |
use File::LocalizeNewlines; |
| 11 |
|
| 12 |
use vars qw{$VERSION}; |
| 13 |
BEGIN { |
| 14 |
$VERSION = '1.12'; |
| 15 |
} |
| 16 |
|
| 17 |
# Create the filter |
| 18 |
my $filter = File::Find::Rule->file->not_binary->writable; |
| 19 |
|
| 20 |
# Handle options |
| 21 |
my $QUIET = ''; |
| 22 |
my $SKIPSVN = ''; |
| 23 |
GetOptions( quiet => \$QUIET, svn => \$SKIPSVN ); |
| 24 |
|
| 25 |
# Check the target |
| 26 |
my $target = @ARGV ? $ARGV[0] : File::Spec->curdir; |
| 27 |
unless ( -e $target ) { |
| 28 |
bail("Cannot localize '$target', does not exist"); |
| 29 |
} |
| 30 |
|
| 31 |
# Create the localizer |
| 32 |
if ( $SKIPSVN ) { |
| 33 |
$filter = File::Find::Rule->or( |
| 34 |
File::Find::Rule->name('.svn')->directory->discard->prune, |
| 35 |
$filter, |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
my $localizer = File::LocalizeNewlines->new( |
| 40 |
filter => $filter, |
| 41 |
$QUIET ? () : ( verbose => 1 ), |
| 42 |
) or bail("Failed to create localizer"); |
| 43 |
|
| 44 |
# Run the localization |
| 45 |
$localizer->localize( $target ); |
| 46 |
|
| 47 |
exit(0); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
##################################################################### |
| 54 |
# Support Functions |
| 55 |
|
| 56 |
sub bail ($) { |
| 57 |
print "$_[0]\n"; |
| 58 |
exit(255); |
| 59 |
} |