From e5579d23f1d5dcfaf9b7ecb2819e3a0f0b2ab3fa Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Sun, 28 May 2017 14:49:52 +0200 Subject: [PATCH] port -file switch to pick now scan can full replaced by pick --- uip/pick.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/uip/pick.c b/uip/pick.c index 464a734..25bd6b6 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -73,9 +73,11 @@ static struct swit switches[] = { { "width columns", 0 }, #define THREADSW 24 { "thread", 0 }, -#define VERSIONSW 25 +#define FILESW 25 + { "file file", 0 }, +#define VERSIONSW 26 { "Version", 0 }, -#define HELPSW 26 +#define HELPSW 27 { "help", 0 }, { NULL, 0 } }; @@ -100,6 +102,7 @@ static int pcompile(char **, char *); static int pmatches(FILE *, int); static struct nexus * createonethread(char *); static struct nexus * createpickthread(char *); +static void scan_mbox(char *, char *, int); static int listsw = -1; @@ -122,6 +125,7 @@ main(int argc, char **argv) char *form = NULL; char *fmtstr; FILE *fp; + char *file = NULL; if (atexit(putzero_done) != 0) { adios(EX_OSERR, NULL, "atexit failed"); @@ -237,6 +241,15 @@ main(int argc, char **argv) } width = atoi(cp); continue; + case FILESW: + if (!(cp = *argp++) || (cp[0] == '-' && cp[1])) { + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + } + if (strcmp(file = cp, "-")!=0) { + file = mh_xstrdup(expanddir(cp)); + } + continue; } } if (*cp == '+' || *cp == '@') { @@ -251,6 +264,21 @@ main(int argc, char **argv) fmtstr = new_fs(form, "pick.default"); + if (file) { + if (folder) { + adios(EX_USAGE, NULL, "\"+folder\" not allowed with -file"); + } + if (msgs.size) { + adios(EX_USAGE, NULL, "\"msgs\" not allowed with -file"); + } + if (vecp) { + adios(EX_USAGE, NULL, "section arguments not allowed with -file"); + } + + scan_mbox(file, fmtstr, width); + exit(EX_OK); + } + /* ** If we didn't specify which messages to search, ** then search the whole folder. @@ -363,6 +391,29 @@ main(int argc, char **argv) return 0; } +static void +scan_mbox(char *file, char *fmtstr, int width) +{ + FILE *in; + int msgnum; + int state; + + if (strcmp(file, "-") == 0) { + in = stdin; + file = "stdin"; + } else if (!(in = fopen(file, "r"))) { + adios(EX_IOERR, file, "unable to open"); + } + + for (msgnum = 1; ;msgnum++) { + state = scan(in, msgnum, SCN_MBOX, fmtstr, width, 0, 0); + if (state != SCNMSG) { + break; + } + } + fclose(in); +} + void putzero_done() -- 1.7.10.4