From: Ed A. <ep...@us...> - 2003-08-29 21:16:42
|
Update of /cvsroot/xmltv/xmltv/filter In directory sc8-pr-cvs1:/tmp/cvs-serv12755/filter Modified Files: tv_grep.in Log Message: Added --not option to tv_grep. It negates the following predicate. Not yet thoroughly tested. Index: tv_grep.in =================================================================== RCS file: /cvsroot/xmltv/xmltv/filter/tv_grep.in,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** tv_grep.in 17 Aug 2003 09:06:37 -0000 1.35 --- tv_grep.in 29 Aug 2003 21:16:06 -0000 1.36 *************** *** 126,130 **** B<EXPR1 --or EXPR2>, B<EXPR1 -or EXPR2> ! 'Not' is not yet implemented. =head1 SEE ALSO --- 126,133 ---- B<EXPR1 --or EXPR2>, B<EXPR1 -or EXPR2> ! B<--not EXPR>, B<-not EXPR>, B<! EXPR> ! ! Of these, 'not' binds tightest, affecting the following predicate ! only. 'and' is next, and 'or' binds loosest. =head1 SEE ALSO *************** *** 233,237 **** --channel-id --channel-name --on-after --on-before --eval ! --and --or)); # Add the autogenerated options. We add even those which aren't --- 236,240 ---- --channel-id --channel-name --on-after --on-before --eval ! --and --or --not)); # Add the autogenerated options. We add even those which aren't *************** *** 248,251 **** --- 251,255 ---- my ($output, $regexp, $ended_options, @filenames); + my $not = 0; # next arg expected to be a predicate, and negated while (@ARGV) { my $arg = shift @ARGV; *************** *** 292,296 **** } ! # Logical operators --and and --or. if ($arg eq '-and' or (defined $lo and $lo eq '--and')) { next; --- 296,305 ---- } ! # Logical operators --and, --or and --not. --not binds the ! # most tightly, and affects only the following predicate. ! # --and is next and binds together predicates in a ! # conjunction. --or binds loosest and joins together two ! # conjunctions. ! # if ($arg eq '-and' or (defined $lo and $lo eq '--and')) { next; *************** *** 316,319 **** --- 325,358 ---- next; } + elsif ($arg eq '!' or $arg eq '-not' + or (defined $lo and $lo eq '--not')) { + $not = 1; + die "$arg requires a predicate following" if not @ARGV; + next; + } + + # Called to add a predicate to the current conjunction, taking + # account of any preceding 'not'. + # + my $add_to_prog_conj = sub( $ ) { + my $pred = shift; + if ($not) { + push @curr_prog_conj, sub { not $pred->(@_) }; + } + else { + push @curr_prog_conj, $pred; + } + }; + + # Similarly for channel filtering. + my $add_to_chan_conj = sub( $ ) { + my $pred = shift; + if ($not) { + push @curr_chan_conj, sub { not $pred->(@_) }; + } + else { + push @curr_chan_conj, $pred; + } + }; # See if it's a predicate. *************** *** 330,334 **** die "-e $code failed for some reason"; } ! push @curr_prog_conj, $pred; next; } --- 369,374 ---- die "-e $code failed for some reason"; } ! $add_to_prog_conj->($pred); ! $not = 0; next; } *************** *** 342,346 **** if not defined $pd; t 'parsed date argument: ' . d $pd; ! push @curr_prog_conj, sub { on_after($pd) }; next; } --- 382,387 ---- if not defined $pd; t 'parsed date argument: ' . d $pd; ! $add_to_prog_conj->(sub { on_after($pd) }); ! $not = 0; next; } *************** *** 354,358 **** if not defined $pd; t 'parsed date argument: ' . d $pd; ! push @curr_prog_conj, sub { on_before($pd) }; next; } --- 395,400 ---- if not defined $pd; t 'parsed date argument: ' . d $pd; ! $add_to_prog_conj->(sub { on_before($pd) }); ! $not = 0; next; } *************** *** 365,370 **** # has 'id'. # ! push @curr_prog_conj, sub { $_->{channel} eq $id }; ! push @curr_chan_conj, sub { $_->{id} eq $id }; next; } --- 407,413 ---- # has 'id'. # ! $add_to_prog_conj->(sub { $_->{channel} eq $id }); ! $add_to_chan_conj->(sub { $_->{id} eq $id }); ! $not = 0; next; } *************** *** 380,385 **** # in the channels. # ! push @curr_prog_conj, sub { $ch_name{$regexp}->{$_->{channel}} }; ! push @curr_chan_conj, sub { $ch_name{$regexp}->{$_->{id}} }; push @ch_regexps, $regexp; next; --- 423,429 ---- # in the channels. # ! $add_to_prog_conj->(sub { $ch_name{$regexp}->{$_->{channel}} }); ! $add_to_chan_conj->(sub { $ch_name{$regexp}->{$_->{id}} }); ! $not = 0; push @ch_regexps, $regexp; next; *************** *** 415,421 **** } else { die "bad arg type $arg_type" } ! push @curr_prog_conj, $s; next; } } --- 459,472 ---- } else { die "bad arg type $arg_type" } ! $add_to_prog_conj->($s); ! $not = 0; next; } + + # It wasn't a predicate. Just check that the previous option + # wasn't --not, since that requires a predicate to follow. + # + die "argument '$arg' follows 'not', but isn't a predicate" + if $not; } |