From 1ffbe7a8c1d955c20e175c4751b15459ac10b229 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 30 Jul 2013 14:29:36 -0400 Subject: [PATCH] [scripts] AggSetCoord: -l option (select lines) --- scripts/owlps-aggsetcoord.pl | 40 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/scripts/owlps-aggsetcoord.pl b/scripts/owlps-aggsetcoord.pl index 789c458..ade4ac0 100755 --- a/scripts/owlps-aggsetcoord.pl +++ b/scripts/owlps-aggsetcoord.pl @@ -10,7 +10,7 @@ owlps-aggsetcoord - set the coordinates in an aggregation CSV file B [ B<-h> | B<-V> ] [ B<-v> ] -[ B<-c> > ] +[ B<-c> > [ B<-l> > ] ] [ B<-m> > ] [ > ] @@ -49,17 +49,6 @@ diff tools such as I to visualise the differences between the input file and the result and make sure it corresponds to what was expected. -=head1 LIMITATIONS - -=over 3 - -=item * -It is not yet possible to choose an interval of lines to work on: the whole file -is treated. - -=back - - =head1 OPTIONS =over 7 @@ -82,6 +71,13 @@ Apply I to every positioning request with default X, Y and Z. A line in which at least one of the three coordinates is set to a non-default value will be left untouched. I is a string "X;Y;Z". +=item B<-l> > + +Skip lines that are not part of the selection pattern I, which +is evaluated as a Perl numeric list. For example, "3, 5, 8..10" will select the +lines 3, 5, 8, 9 and 10; "1..25,42..45" will select the lines 1 to 25 and 42 to +77. This works only with the B<-c> option. + =item B<-m> > Work only on positioning requests transmitted by MAC address I. @@ -136,6 +132,10 @@ use constant BASE_COORD => "0.00"; # Verbose mode my $verbose; +# List of the lines to work on (will stay undefined if all the lines have to be +# worked on) +my %selected_lines; + # Selected transmitter's MAC address (will stay undefined if -m was not used) my $selected_mac; @@ -317,7 +317,7 @@ sub apply_interpolation($$$$$$) { ## Option parsing ## $Getopt::Std::STANDARD_HELP_VERSION = 1; -use constant OPTIONS => 'c:hm:vV'; +use constant OPTIONS => 'c:hl:m:vV'; my %options; if (!getopts(OPTIONS, \%options)) { HELP_MESSAGE(*STDERR); @@ -343,6 +343,12 @@ if (defined($new_coordinates)) { ($new_x, $new_y, $new_z) = split_point_3d($new_coordinates); } +# Register the selected lines +if (defined($options{'l'})) { + die "-l option requires -c option!" if (!defined($new_coordinates)); + $selected_lines{$_} = 1 foreach eval $options{'l'}; +} + ## Main loop: read lines ## @@ -409,6 +415,13 @@ while ($cur_line = <>) { # option): we print it immediately (we are sure not to have any previous # lines in memory, since we don't do that in this mode) if (defined($new_coordinates)) { + # Skip the line if it is not part of the selected lines + if (%selected_lines and !$selected_lines{$line_nb}) { + trace("Line not selected: skipped.\n"); + print $cur_line; + next; + } + # If the current line is fully incomplete, we reconstitute it with the # new coordinates if (is_blank($x, $y, $z)) { @@ -428,6 +441,7 @@ while ($cur_line = <>) { else { print $cur_line; } + # In either case, jump to the next line next; }