| 4 |
## $Id$ |
## $Id$ |
| 5 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
| 6 |
## $Log$ |
## $Log$ |
| 7 |
|
## Revision 1.2 2003/02/01 06:44:08 joko |
| 8 |
|
## + added option and implementation for '--in-type=pathlist' |
| 9 |
|
## |
| 10 |
## Revision 1.1 2003/02/01 02:56:03 joko |
## Revision 1.1 2003/02/01 02:56:03 joko |
| 11 |
## + initial commit |
## + initial commit |
| 12 |
## |
## |
| 39 |
|
|
| 40 |
use Data::Dumper; |
use Data::Dumper; |
| 41 |
use Getopt::Easy; |
use Getopt::Easy; |
| 42 |
|
#use Data::Storage::Handler::File qw( s2f ); |
| 43 |
|
use Data::Storage::Handler::File; |
| 44 |
|
|
| 45 |
|
|
| 46 |
# ---------------------------------------- |
# ---------------------------------------- |
| 47 |
package main; |
package main; |
| 52 |
|
|
| 53 |
my $defaults = { |
my $defaults = { |
| 54 |
options => { |
options => { |
| 55 |
'in-type' => 'content', |
'in-type' => 'stdin', |
| 56 |
#'in-type' => 'pathlist', |
#'in-type' => 'pathlist', |
| 57 |
#'regex' => '.*', |
#'regex' => '.*', |
| 58 |
}, |
}, |
| 80 |
|
|
| 81 |
sub replace { |
sub replace { |
| 82 |
|
|
| 83 |
if ($settings->{options}->{'in-type'} eq 'content') { |
if ($settings->{options}->{'in-type'} eq 'stdin') { |
| 84 |
my @buffer; |
my @buffer; |
| 85 |
my $pattern = $settings->{options}->{regex}; |
my $pattern = $settings->{options}->{regex}; |
| 86 |
while (<STDIN>) { |
while (<STDIN>) { |
| 91 |
} |
} |
| 92 |
|
|
| 93 |
} elsif ($settings->{options}->{'in-type'} eq 'pathlist') { |
} elsif ($settings->{options}->{'in-type'} eq 'pathlist') { |
| 94 |
die("not implemented yet!"); |
#die("not implemented yet!"); |
| 95 |
|
my $pattern = $settings->{options}->{regex}; |
| 96 |
|
while (<STDIN>) { |
| 97 |
|
chomp; |
| 98 |
|
print "modifying $_: "; |
| 99 |
|
my $file = Data::Storage::Handler::File->new( path => $_ ); |
| 100 |
|
#print Dumper($file), "\n"; |
| 101 |
|
#print Dumper($file->toString()), "\n"; |
| 102 |
|
#exit; |
| 103 |
|
#print "replacing...", "\n"; |
| 104 |
|
|
| 105 |
|
if ($file->matches($pattern)) { |
| 106 |
|
print "MATCH - "; |
| 107 |
|
|
| 108 |
|
if (my $suffix_backup = $settings->{options}->{backup}) { |
| 109 |
|
if ($suffix_backup eq '1') { $suffix_backup = 'bak'; } |
| 110 |
|
#print "made backup of original-file"; |
| 111 |
|
$file->backup( { suffix => $suffix_backup } ); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
if ($settings->{options}->{infile}) { |
| 115 |
|
print "replaced infile"; |
| 116 |
|
die("not yet implemented"); |
| 117 |
|
|
| 118 |
|
} elsif ($settings->{options}->{overwrite}) { |
| 119 |
|
print "overwritten"; |
| 120 |
|
$file->save(); |
| 121 |
|
|
| 122 |
|
} elsif (my $suffix = $settings->{options}->{suffix}) { |
| 123 |
|
print "suffixed with $suffix"; |
| 124 |
|
$file->addSuffix($suffix); |
| 125 |
|
$file->save(); |
| 126 |
|
|
| 127 |
|
} else { |
| 128 |
|
print "no action (e.g. --infile|--suffix=tmp) applied"; |
| 129 |
|
} |
| 130 |
|
#exit; |
| 131 |
|
|
| 132 |
|
} else { |
| 133 |
|
print "NO match - not touched"; |
| 134 |
|
} |
| 135 |
|
#print; |
| 136 |
|
print "\n"; |
| 137 |
|
#print Dumper($content), "\n"; |
| 138 |
|
|
| 139 |
|
#print "writing ....", "\n"; |
| 140 |
|
#exit; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
} |
} |