[scripts] AggSetCoord: -I option (backup suffix)

This commit is contained in:
Matteo Cypriani 2013-07-31 12:59:47 -04:00
parent 1307ac6dc5
commit e56a718b22
1 changed files with 16 additions and 5 deletions

View File

@ -10,7 +10,7 @@ owlps-aggsetcoord - set the coordinates in an aggregation CSV file
B<owlps-aggsetcoord>
[ B<-h> | B<-V> ]
[ B<-v> ]
[ B<-i> ]
[ B<-i> | B<-I> <I<suffix>> ]
[ B<-c> <I<coordinates>> [ B<-l> <I<line_selection>> ] ]
[ B<-m> <I<mac>> ]
[ <I<aggregation_file>> ]
@ -72,6 +72,12 @@ Turn on verbose mode (displays a trace on the standard error).
Modify the input file in-place. The original file is saved with suffix ".orig".
=item B<-I> <I<suffix>>
Same as B<-i>, but the original file is suffixed with I<suffix> instead of
".orig". If both B<-i> and B<-I> are used, the latter has precedence over the
former. If I<suffix> is an empty string, this option is ignored.
=item B<-c> <I<coordinates>>
Apply I<coordinates> to every positioning request with default X, Y and Z. A
@ -145,6 +151,9 @@ my $output_handle = *STDOUT;
# Names of the temporary and final output files
my ($tmp_output_file, $output_file);
# Suffix with which the original file is saved
my $backup_suffix;
# Verbose mode
my $verbose;
@ -339,7 +348,7 @@ sub apply_interpolation($$$$$$) {
## Option parsing ##
$Getopt::Std::STANDARD_HELP_VERSION = 1;
use constant OPTIONS => 'c:hil:m:vV';
use constant OPTIONS => 'c:hiI:l:m:vV';
my %options;
if (!getopts(OPTIONS, \%options)) {
HELP_MESSAGE(*STDERR);
@ -359,12 +368,14 @@ if ($options{'V'}) {
$verbose = $options{'v'};
$new_coordinates = $options{'c'};
$backup_suffix = $options{'I'};
$selected_mac = $options{'m'};
if ($options{'i'}) {
if ($options{'i'} || $backup_suffix) {
if (@ARGV != 1) {
die "One and only one file name must be provided when using -i";
die "One and only one file name must be provided when using -i or -I";
}
$backup_suffix ||= ".orig";
$output_file = $ARGV[0];
($output_handle, $tmp_output_file) =
tempfile(
@ -631,7 +642,7 @@ if (defined($output_file)) {
or die "Can't close the output file handle: $!";
# Backup the original file
my $newname = "$output_file.orig";
my $newname = $output_file . $backup_suffix;
move($output_file, $newname)
or die "Can't move \"$output_file\" to \"$newname\": $!";