Take multiple files if -w argument is supplied.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4172 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
44f3f11068
commit
cc984f9d7c
@ -18,19 +18,21 @@ my $opt_write = $args{'w'};
|
||||
my $argc = $#ARGV + 1;
|
||||
my $scriptname = $0;
|
||||
|
||||
($argc == 1) or die <<END;
|
||||
(($argc == 1) or ($argc >= 1 and $opt_write)) or die <<END;
|
||||
Usage:
|
||||
$scriptname sourcefile [>outfile]
|
||||
Print formatted output to STDOUT or outfile.
|
||||
Warning: do not use the same file for both.
|
||||
Warning: do not use the same file for outfile.
|
||||
|
||||
$scriptname -w sourcefile
|
||||
Writes to the file in-place.
|
||||
$scriptname -w sourcefile(s)
|
||||
Writes to the file(s) in-place.
|
||||
Warning: backup your file(s) first or use clean version control files.
|
||||
END
|
||||
|
||||
# TODO: operate on multiple files
|
||||
my ($infile) = @ARGV;
|
||||
|
||||
sub parse($)
|
||||
{
|
||||
my ($infile) = @_;
|
||||
my @lines;
|
||||
|
||||
open(INPUT, $infile) or die "Couldn't open $infile for reading: $!\n";
|
||||
@ -76,7 +78,7 @@ while (<INPUT>) {
|
||||
}
|
||||
close(INPUT);
|
||||
|
||||
$opt_write or exit;
|
||||
$opt_write or return;
|
||||
|
||||
open(OUTPUT, ">$infile") or die "Couldn't open $infile for writing: $!\n";
|
||||
foreach my $line (@lines)
|
||||
@ -84,3 +86,11 @@ foreach my $line (@lines)
|
||||
print OUTPUT $line."\n";
|
||||
}
|
||||
close(OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
foreach my $infile (@ARGV)
|
||||
{
|
||||
parse($infile);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user