X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fpick.c;h=93a240068b4044069aee161b1ad1f608e35b1f16;hp=a4f61bdcd9c939e08911995bc198cb26e1db67e4;hb=240013872c392fe644bd4f79382d9f5314b4ea60;hpb=a485ed478abbd599d8c9aab48934e7a26733ecb1 diff --git a/uip/pick.c b/uip/pick.c index a4f61bd..93a2400 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -1,10 +1,10 @@ /* - * pick.c -- search for messages by content - * - * 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. - */ +** pick.c -- search for messages by content +** +** 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. +*/ #include #include @@ -65,10 +65,10 @@ static struct swit switches[] = { static int listsw = -1; -static void putzero_done (int) NORETURN; +static void putzero_done(int) NORETURN; int -main (int argc, char **argv) +main(int argc, char **argv) { int publicsw = -1, zerosw = 1, seqp = 0, vecp = 0; int lo, hi, msgnum; @@ -84,12 +84,12 @@ main (int argc, char **argv) #ifdef LOCALE setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); + invo_name = mhbasename(argv[0]); /* read user profile/context */ context_read(); - arguments = getarguments (invo_name, argc, argv, 1); + arguments = getarguments(invo_name, argc, argv, 1); argp = arguments; while ((cp = *argp++)) { @@ -98,24 +98,23 @@ main (int argc, char **argv) vec[vecp++] = --cp; goto pattern; } - switch (smatch (cp, switches)) { + switch (smatch(cp, switches)) { case AMBIGSW: - ambigsw (cp, switches); + ambigsw(cp, switches); listsw = 0; /* HACK */ - done (1); + done(1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + adios(NULL, "-%s unknown", cp); case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); + snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); + print_help(buf, switches, 1); listsw = 0; /* HACK */ - done (1); + done(1); case VERSIONSW: print_version(invo_name); listsw = 0; /* HACK */ - done (1); + done(1); case CCSW: case DATESW: @@ -128,12 +127,13 @@ main (int argc, char **argv) case SRCHSW: vec[vecp++] = --cp; pattern: - if (!(cp = *argp++))/* allow -xyz arguments */ - adios (NULL, "missing argument to %s", argp[-2]); + if (!(cp = *argp++)) /* allow -xyz arguments */ + adios(NULL, "missing argument to %s", + argp[-2]); vec[vecp++] = cp; continue; case OTHRSW: - adios (NULL, "internal error!"); + adios(NULL, "internal error!"); case ANDSW: case ORSW: @@ -145,14 +145,15 @@ main (int argc, char **argv) case SEQSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + adios(NULL, "missing argument to %s", + argp[-2]); /* check if too many sequences specified */ if (seqp >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); + adios(NULL, "too many sequences (more than %d) specified", NUMATTRS); - if (!seq_nameok (cp)) - done (1); + if (!seq_nameok(cp)) + done(1); seqs[seqp++] = cp; continue; @@ -179,89 +180,92 @@ main (int argc, char **argv) } if (*cp == '+' || *cp == '@') { if (folder) - adios (NULL, "only one folder at a time!"); + adios(NULL, "only one folder at a time!"); else - folder = pluspath (cp); + folder = pluspath(cp); } else - app_msgarg(&msgs, cp); + app_msgarg(&msgs, cp); } vec[vecp] = NULL; - if (!context_find ("path")) - free (path ("./", TFOLDER)); + if (!context_find("path")) + free(path("./", TFOLDER)); /* - * If we didn't specify which messages to search, - * then search the whole folder. - */ + ** If we didn't specify which messages to search, + ** then search the whole folder. + */ if (!msgs.size) app_msgarg(&msgs, "all"); if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); + folder = getfolder(1); + maildir = m_maildir(folder); - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); + if (chdir(maildir) == NOTOK) + adios(maildir, "unable to change directory to"); /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); + if (!(mp = folder_read(folder))) + adios(NULL, "unable to read folder %s", folder); /* check for empty folder */ if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); + adios(NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ + if (!m_convert(mp, msgs.msgs[msgnum])) + done(1); + seq_setprev(mp); /* set the previous-sequence */ /* - * If we aren't saving the results to a sequence, - * we default to list the results. - */ + ** If we aren't saving the results to a sequence, + ** we default to list the results. + */ if (listsw == -1) listsw = !seqp; if (publicsw == 1 && is_readonly(mp)) - adios (NULL, "folder %s is read-only, so -public not allowed", folder); + adios(NULL, "folder %s is read-only, so -public not allowed", + folder); - if (!pcompile (vec, NULL)) - done (1); + if (!pcompile(vec, NULL)) + done(1); lo = mp->lowsel; hi = mp->hghsel; - /* If printing message numbers to standard out, force line buffering on. - */ + /* + ** If printing message numbers to standard out, + ** force line buffering on. + */ if (listsw) - setvbuf (stdout, NULL, _IOLBF, 0); + 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. - */ + ** Scan through all the SELECTED messages and check for a + ** match. If the message does not match, then unselect it. + */ for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL) - admonish (cp, "unable to read message"); - if (fp && pmatches (fp, msgnum, 0L, 0L)) { + if (is_selected(mp, msgnum)) { + if ((fp = fopen(cp = m_name(msgnum), "r")) == NULL) + admonish(cp, "unable to read message"); + if (fp && pmatches(fp, msgnum, 0L, 0L)) { if (msgnum < lo) lo = msgnum; if (msgnum > hi) hi = msgnum; if (listsw) - printf ("%s\n", m_name (msgnum)); + printf("%s\n", m_name(msgnum)); } else { /* if it doesn't match, then unselect it */ - unset_selected (mp, msgnum); + unset_selected(mp, msgnum); mp->numsel--; } if (fp) - fclose (fp); + fclose(fp); } } @@ -269,37 +273,37 @@ main (int argc, char **argv) mp->hghsel = hi; if (mp->numsel <= 0) - adios (NULL, "no messages match specification"); + adios(NULL, "no messages match specification"); seqs[seqp] = NULL; /* - * Add the matching messages to sequences - */ + ** Add the matching messages to sequences + */ for (seqp = 0; seqs[seqp]; seqp++) - if (!seq_addsel (mp, seqs[seqp], publicsw, zerosw)) - done (1); + if (!seq_addsel(mp, seqs[seqp], publicsw, zerosw)) + done(1); /* - * Print total matched if not printing each matched message number. - */ + ** Print total matched if not printing each matched message number. + */ if (!listsw) { - printf ("%d hit%s\n", mp->numsel, mp->numsel == 1 ? "" : "s"); + printf("%d hit%s\n", mp->numsel, mp->numsel == 1 ? "" : "s"); } - context_replace (pfolder, folder); /* update current folder */ - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); + context_replace(pfolder, folder); /* update current folder */ + seq_save(mp); /* synchronize message sequences */ + context_save(); /* save the context file */ + folder_free(mp); /* free folder/message structure */ + done(0); return 1; } static void -putzero_done (int status) +putzero_done(int status) { - if (listsw && status && !isatty (fileno (stdout))) - printf ("0\n"); - exit (status); + if (listsw && status && !isatty(fileno(stdout))) + printf("0\n"); + exit(status); }