#include <unistd.h>
#include <locale.h>
#include <sysexits.h>
+#include <h/scansbr.h>
+#include <h/fmt_scan.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
{ "list", 0 },
#define NLISTSW 21
{ "nolist", 2 },
-#define VERSIONSW 22
+#define FORMATSW 22
+ { "format format", 0 },
+#define WIDTHSW 23
+ { "width columns", 0 },
+#define VERSIONSW 24
{ "Version", 0 },
-#define HELPSW 23
+#define HELPSW 25
{ "help", 0 },
{ NULL, 0 }
};
void putzero_done();
+static void printmsg(FILE *, struct msgs *, int, char *, int);
+
int
main(int argc, char **argv)
{
- int publicsw = -1, zerosw = 1, vecp = 0;
+ int publicsw = -1, zerosw = 1, vecp = 0, width = 0;
unsigned int seqp = 0;
int lo, hi, msgnum;
char *maildir, *folder = NULL, buf[100];
char *seqs[NUMATTRS + 1], *vec[MAXARGS];
struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
+ char *form = NULL;
+ char *fmtstr;
FILE *fp;
- if (atexit(putzero_done) != 0) {
+ if (atexit(putzero_done) != 0) {
adios(EX_OSERR, NULL, "atexit failed");
}
arguments = getarguments(invo_name, argc, argv, 1);
argp = arguments;
+ if (strcmp(invo_name, "scan")==0) {
+ form = scanformat;
+ }
+
while ((cp = *argp++)) {
if (*cp == '-') {
if (*++cp == '-') {
case NLISTSW:
listsw = 0;
continue;
+ case FORMATSW:
+ if (!(form = *argp++) || *form == '-') {
+ adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
+ }
+ continue;
+ case WIDTHSW:
+ if (!(cp = *argp++) || *cp == '-') {
+ adios(EX_USAGE, NULL, "missing argument to %s",
+ argp[-2]);
+ }
+ width = atoi(cp);
+ continue;
}
}
if (*cp == '+' || *cp == '@') {
}
vec[vecp] = NULL;
+ fmtstr = new_fs(form, "pick.default");
+
/*
** If we didn't specify which messages to search,
** then search the whole folder.
if (msgnum > hi)
hi = msgnum;
- if (listsw)
- printf("%s\n", m_name(msgnum));
+ if (listsw) {
+ printmsg(fp, mp, msgnum, fmtstr, width);
+ }
} else {
/* if it doesn't match, then unselect it */
unset_selected(mp, msgnum);
printf("0\n");
}
+static void
+printmsg(FILE *f, struct msgs *mp, int msgnum, char *fmtstr, int width)
+{
+ int seqnum;
+ int state;
+ boolean unseen = FALSE;
+
+ fseek(f, 0L, SEEK_SET);
+
+ seqnum = seq_getnum(mp, seq_unseen);
+ unseen = in_sequence(mp, seqnum, msgnum);
+
+ switch (state = scan(f, msgnum, SCN_FOLD, fmtstr,
+ width, msgnum==mp->curmsg, unseen)) {
+ case SCNMSG:
+ case SCNERR:
+ break;
+ case SCNEOF:
+ advise(NULL, "message %d: empty", msgnum);
+ break;
+ default:
+ adios(EX_SOFTWARE, NULL, "scan() botch(%d)", state);
+ }
+}
+
static struct swit parswit[] = {
#define PRAND 0