From: Eric Gillespie Date: Sat, 12 Mar 2016 05:15:46 +0000 (-0500) Subject: Implement the -reverse option to pick(1) to change the search order. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/00cfba08b276c3566cdc7d268965a6fc80c441df Implement the -reverse option to pick(1) to change the search order. --- diff --git a/man/pick.man b/man/pick.man index 000da224..9d7cdcf5 100644 --- a/man/pick.man +++ b/man/pick.man @@ -10,6 +10,8 @@ pick \- search for messages by content .B pick .RI [ +folder ] .RI [ msgs ] +.RB [ \-reverse +\&...] .RB [ \-and \&...] .RB [ \-or @@ -177,6 +179,20 @@ will also honor a specification of the form \*(lq\-dd\*(rq, which means \*(lqdd days ago\*(rq. .PP +Use the +.BR \-reverse +switch to make +.B pick +find matching messages in reverse order, working from the highest message +number down to the lowest. This can be useful in for searching recent +messages in large folders, for example, +.PP +.RS 5 +.nf +pick\0\-reverse\0\-from\0frated\0|\0xargs\0\-n1\0scan +.fi +.RE +.PP .B Pick supports complex boolean operations on the searching primitives with the diff --git a/test/pick/test-pick b/test/pick/test-pick index 858d8e75..ca19bb88 100755 --- a/test/pick/test-pick +++ b/test/pick/test-pick @@ -49,6 +49,12 @@ run_test 'pick -not -subject message.8 last:5' '7 10 11' +# Test -reverse. +run_test 'pick -reverse -not -subject message.8 last:5' '11 +10 +9 +7' + # Test -lbrace, -rbrace. run_test 'pick -subject message.12 -and -subject message.3 -or -from Test4' '4' run_test 'pick -subject message.12 -and -lbrace -subject message.3 -rbrace' \ diff --git a/uip/pick.c b/uip/pick.c index d29799b7..fba190a2 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -13,6 +13,7 @@ #include #define PICK_SWITCHES \ + X("reverse", 0, REVSW) \ X("and", 0, ANDSW) \ X("or", 0, ORSW) \ X("not", 0, NOTSW) \ @@ -67,6 +68,7 @@ main (int argc, char **argv) struct msgs *mp, *mp2; register FILE *fp; int debug = 0; + int reverse = 0; if (nmh_init(argv[0], 1)) { return 1; } @@ -104,6 +106,10 @@ main (int argc, char **argv) listsw = 0; /* HACK */ done (0); + case REVSW: + reverse = 1; + continue; + case CCSW: case DATESW: case FROMSW: @@ -231,7 +237,9 @@ main (int argc, char **argv) * match. If there is NOT a match, then add it to a list to * remove from the final sequence (it will make sense later) */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + for (msgnum = reverse ? mp->hghsel : mp->lowsel; + reverse ? msgnum >= mp->lowsel : msgnum <= mp->hghsel; + msgnum += reverse ? -1 : 1) { if (is_selected (mp, msgnum)) { if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL) admonish (cp, "unable to read message");