X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fpick.c;h=24e6862c818044380967287968d773da005c94ba;hb=a01a41d031c796b526329a4170eb23f0ac93b949;hp=8fd294ee140fc85caf6e17e1641cc8fe87bc4065;hpb=174d375bb4b9bcaa0c3f28c422216f68703494a8;p=mmh diff --git a/uip/pick.c b/uip/pick.c index 8fd294e..24e6862 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -2,9 +2,7 @@ /* * pick.c -- search for messages by content * - * $Id$ - * - * This code is Copyright (c) 2002, by the authors of nmh. See the + * This code is Copyright (c) 2002, 2008, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. */ @@ -68,6 +66,7 @@ static struct swit switches[] = { static int listsw = -1; +static void putzero_done (int) NORETURN; int main (int argc, char **argv) @@ -81,6 +80,8 @@ main (int argc, char **argv) struct msgs *mp; register FILE *fp; + done=putzero_done; + #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -150,6 +151,10 @@ main (int argc, char **argv) /* check if too many sequences specified */ if (seqp >= NUMATTRS) adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); + + if (!seq_nameok (cp)) + done (1); + seqs[seqp++] = cp; continue; case PUBLSW: @@ -177,7 +182,7 @@ main (int argc, char **argv) if (folder) adios (NULL, "only one folder at a time!"); else - folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); + folder = pluspath (cp); } else app_msgarg(&msgs, cp); } @@ -230,6 +235,11 @@ main (int argc, char **argv) lo = mp->lowsel; hi = mp->hghsel; + /* If printing message numbers to standard out, force line buffering on. + */ + if (listsw) + setvbuf (stdout, NULL, _IOLBF, 0); + /* * Scan through all the SELECTED messages and check for a * match. If the message does not match, then unselect it. @@ -243,6 +253,9 @@ main (int argc, char **argv) lo = msgnum; if (msgnum > hi) hi = msgnum; + + if (listsw) + printf ("%s\n", m_name (msgnum)); } else { /* if it doesn't match, then unselect it */ unset_selected (mp, msgnum); @@ -269,13 +282,9 @@ main (int argc, char **argv) done (1); /* - * Print the name of all the matches + * Print total matched if not printing each matched message number. */ - if (listsw) { - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum)) - printf ("%s\n", m_name (msgnum)); - } else { + if (!listsw) { printf ("%d hit%s\n", mp->numsel, mp->numsel == 1 ? "" : "s"); } @@ -283,15 +292,15 @@ main (int argc, char **argv) seq_save (mp); /* synchronize message sequences */ context_save (); /* save the context file */ folder_free (mp); /* free folder/message structure */ - return done (0); + done (0); + return 1; } -int -done (int status) +static void +putzero_done (int status) { if (listsw && status && !isatty (fileno (stdout))) printf ("0\n"); exit (status); - return 1; /* dead code to satisfy the compiler */ }