add -format to pick
authorPhilipp Takacs <philipp@bureaucracy.de>
Fri, 9 Sep 2016 21:06:37 +0000 (23:06 +0200)
committerPhilipp Takacs <satanist@fsmi.uka.de>
Thu, 25 May 2017 13:43:41 +0000 (15:43 +0200)
this leads to remove scan

etc/Makefile.in
etc/pick.default [new file with mode: 0644]
man/pick.man1
uip/Makefile.in
uip/pick.c

index aa0aa25..7b2934e 100644 (file)
@@ -32,7 +32,7 @@ STATIC_FILES = components digestcomps distcomps forwcomps \
                replcomps replgroupcomps scan.MMDDYY scan.YYYYMMDD \
                scan.nmh scan.mailx scan.nomime scan.size scan.time \
                scan.timely scan.unseen scan.meillo scan.default \
                replcomps replgroupcomps scan.MMDDYY scan.YYYYMMDD \
                scan.nmh scan.mailx scan.nomime scan.size scan.time \
                scan.timely scan.unseen scan.meillo scan.default \
-               mhn.defaults repllistcomps
+               mhn.defaults repllistcomps pick.default
 
 # ========= DEPENDENCIES FOR BUILDING ==========
 
 
 # ========= DEPENDENCIES FOR BUILDING ==========
 
diff --git a/etc/pick.default b/etc/pick.default
new file mode 100644 (file)
index 0000000..0ab1bed
--- /dev/null
@@ -0,0 +1 @@
+%(msg)
index 076f99d..4f223df 100644 (file)
@@ -39,6 +39,10 @@ pick \- select messages by content
 .IR date ]
 .RB [ \-datefield
 .IR field ]
 .IR date ]
 .RB [ \-datefield
 .IR field ]
+.RB [ \-format
+.IR formatfile ]
+.RB [ \-width
+.IR columns ]
 .RB [ \-sequence
 .I name
 \&...]
 .RB [ \-sequence
 .I name
 \&...]
index e7e7b46..cd43aaa 100644 (file)
@@ -172,8 +172,8 @@ new: new.o $(LOCALLIBS)
 packf: packf.o dropsbr.o $(LOCALLIBS)
        $(LINK) packf.o dropsbr.o $(LINKLIBS)
 
 packf: packf.o dropsbr.o $(LOCALLIBS)
        $(LINK) packf.o dropsbr.o $(LINKLIBS)
 
-pick: pick.o $(LOCALLIBS)
-       $(LINK) pick.o $(LINKLIBS)
+pick: pick.o scansbr.o termsbr.o $(LOCALLIBS)
+       $(LINK) pick.o scansbr.o termsbr.o $(LINKLIBS) $(TERMLIB)
 
 print-mimetype: print-mimetype.sh
        cp $(srcdir)/print-mimetype.sh print-mimetype
 
 print-mimetype: print-mimetype.sh
        cp $(srcdir)/print-mimetype.sh print-mimetype
index 4cb33fb..3e250a7 100644 (file)
@@ -12,6 +12,8 @@
 #include <unistd.h>
 #include <locale.h>
 #include <sysexits.h>
 #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>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -63,9 +65,13 @@ static struct swit switches[] = {
        { "list", 0 },
 #define NLISTSW  21
        { "nolist", 2 },
        { "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 },
        { "Version", 0 },
-#define HELPSW  23
+#define HELPSW  25
        { "help", 0 },
        { NULL, 0 }
 };
        { "help", 0 },
        { NULL, 0 }
 };
@@ -83,10 +89,12 @@ static int listsw = -1;
 
 void putzero_done();
 
 
 void putzero_done();
 
+static void printmsg(FILE *, struct msgs *, int, char *, int);
+
 int
 main(int argc, char **argv)
 {
 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];
        unsigned int seqp = 0;
        int lo, hi, msgnum;
        char *maildir, *folder = NULL, buf[100];
@@ -94,9 +102,11 @@ main(int argc, char **argv)
        char *seqs[NUMATTRS + 1], *vec[MAXARGS];
        struct msgs_array msgs = { 0, 0, NULL };
        struct msgs *mp;
        char *seqs[NUMATTRS + 1], *vec[MAXARGS];
        struct msgs_array msgs = { 0, 0, NULL };
        struct msgs *mp;
+       char *form = NULL;
+       char *fmtstr;
        FILE *fp;
 
        FILE *fp;
 
-        if (atexit(putzero_done) != 0) {
+       if (atexit(putzero_done) != 0) {
                adios(EX_OSERR, NULL, "atexit failed");
        }
 
                adios(EX_OSERR, NULL, "atexit failed");
        }
 
@@ -109,6 +119,10 @@ main(int argc, char **argv)
        arguments = getarguments(invo_name, argc, argv, 1);
        argp = arguments;
 
        arguments = getarguments(invo_name, argc, argv, 1);
        argp = arguments;
 
+       if (strcmp(invo_name, "scan")==0) {
+               form = scanformat;
+       }
+
        while ((cp = *argp++)) {
                if (*cp == '-') {
                        if (*++cp == '-') {
        while ((cp = *argp++)) {
                if (*cp == '-') {
                        if (*++cp == '-') {
@@ -193,6 +207,18 @@ main(int argc, char **argv)
                        case NLISTSW:
                                listsw = 0;
                                continue;
                        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 == '@') {
                        }
                }
                if (*cp == '+' || *cp == '@') {
@@ -205,6 +231,8 @@ main(int argc, char **argv)
        }
        vec[vecp] = NULL;
 
        }
        vec[vecp] = NULL;
 
+       fmtstr = new_fs(form, "pick.default");
+
        /*
        ** 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.
@@ -271,8 +299,9 @@ main(int argc, char **argv)
                                if (msgnum > hi)
                                        hi = msgnum;
 
                                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);
                        } else {
                                /* if it doesn't match, then unselect it */
                                unset_selected(mp, msgnum);
@@ -320,6 +349,31 @@ putzero_done()
                printf("0\n");
 }
 
                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
 
 static struct swit parswit[] = {
 #define PRAND   0