Re: [mmh] scan and pick (was: How "modern" are you willing to go?)
Hoi. [2016-09-18 13:21] Philipp Takacs > [2016-09-09 19:45] Philipp Takacs > > It wouldn't be that complicate. We would to replace the > > > > > printf("%s\n", m_name(msgnum)); > > > > with a call to scan() and add the ``-format'' switch. > > > > In other words pick supports only the format '=%(msg)' at > > the moment. If we have a format switch in pick we could replace > > scan by a symlink to pick. Philipp convinced me with the pick and scan merge. We should go for it. > I have implemented this to have a code example we can discouse > not only an idea. The patch is attached. Thanks for the patch to get a better picture of the change! Before you commit it, there's some cleanup to do, e.g.: > +void printmsg(FILE *f, struct msgs *mp, int msgnum, char *fmtstr, int width); Prototypes without argument names. > + if (strcmp(invo_name,"scan")==0) { Space after comma missing. Should we prepare it in a branch? (As there are several parts to change: pick, scan, format files, manpages, ...) Am I right, that the combination: scan `pick -sub foo` can be replaced by this single call to pick/scan: pick -form scan.meillo -sub foo Or maybe even by: scan -sub foo Do we then still need the -list switch? It could be replaced by `pick -form scan.msgnum'. Anyway, ... I do start to like the pick/scan merge. :-) meillo
Re: [mmh] scan and pick (was: How "modern" are you willing to go?)
[2016-12-28 22:03] Philipp Takacs > > part text/plain2140 > [2016-09-20 16:56] Dmitry Bogatov > > Seems, symlink replacement of 'scan' is not part of this patch, isn't it? > > No, I have written this patch to have some code to discuss > and get a response from markus what he thinks now about merging > scan and pick. Thats why I have focused on the actuall code not > on the buildsystem changes. Hello. Got caught by `buildsystem' keyword. Here is my repository, which among other, migrated build system to Automake. You may be interested: https://anonscm.debian.org/cgit/users/kaction-guest/fork/mmh.git/' -- X-Web-Site: https://sinsekvu.github.io | Note that I process my email in batch, Accept-Languages: eo,ru,en | at most once every 24 hours. If matter Accept: text/plain, text/x-diff| is urgent, you have my phone number. pgpiHZopDMNP1.pgp Description: PGP signature
Re: [mmh] scan and pick (was: How "modern" are you willing to go?)
[2016-09-20 16:56] Dmitry Bogatov > Seems, symlink replacement of 'scan' is not part of this patch, isn't it? No, I have written this patch to have some code to discuss and get a response from markus what he thinks now about merging scan and pick. Thats why I have focused on the actuall code not on the buildsystem changes. > > [2016-09-09 19:45] Philipp Takacs > > --- a/uip/pick.c > > +++ b/uip/pick.c > > @@ -83,10 +89,12 @@ static int listsw = -1; > > > > void putzero_done(); > > > > +void printmsg(FILE *f, struct msgs *mp, int msgnum, char *fmtstr, int wid > th); > > static? Yes. > > > -if (atexit(putzero_done) != 0) { > > + if (atexit(putzero_done) != 0) { > > adios(EX_OSERR, NULL, "atexit failed"); > > } > > Seems to fix spacing error, but it probably belong to another patch. Yes this will be part of an other commit, I have just seen it and fixed it. > > @@ -271,8 +299,10 @@ main(int argc, char **argv) > > if (msgnum > hi) > > hi = msgnum; > > > > - if (listsw) > > - printf("%s\n", m_name(msgnum)); > > + if (listsw) { > > + printmsg(fp, mp, msgnum, fmtstr, width > ); > > + /* printf("%s\n", m_name(msgnum)); */ > > + } > > Commented code? Will be removed on the final commit. > > +void printmsg(FILE *f, struct msgs *mp, int msgnum, char *fmtstr, int wid > th) > > +{ > > + 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; > > Why cases > > #define SCNMSG 1 /* message just fine*/ > #define SCNERR (-1) /* error message*/ > > are merged? I have more or less just copied the code from uip/scan.c (line 209). The cases are merged there, too. I have looked a bit into it now. It's because, if scan() fails there is nothing we can do about it. Philipp
Re: [mmh] scan and pick (was: How "modern" are you willing to go?)
> [2016-09-09 19:45] Philipp Takacs > > It wouldn't be that complicate. We would to replace the > > > > > printf("%s\n", m_name(msgnum)); > > > > with a call to scan() and add the ``-format'' switch. > > > > I have implemented this to have a code example we can discouse > not only an idea. The patch is attached. Thank for you work. > > In other words pick supports only the format '=%(msg)' at > > the moment. If we have a format switch in pick we could replace > > scan by a symlink to pick. Seems, symlink replacement of 'scan' is not part of this patch, isn't it? > --- a/uip/pick.c > +++ b/uip/pick.c > @@ -83,10 +89,12 @@ static int listsw = -1; > > void putzero_done(); > > +void printmsg(FILE *f, struct msgs *mp, int msgnum, char *fmtstr, int width); static? > -if (atexit(putzero_done) != 0) { > + if (atexit(putzero_done) != 0) { > adios(EX_OSERR, NULL, "atexit failed"); > } Seems to fix spacing error, but it probably belong to another patch. > @@ -271,8 +299,10 @@ main(int argc, char **argv) > if (msgnum > hi) > hi = msgnum; > > - if (listsw) > - printf("%s\n", m_name(msgnum)); > + if (listsw) { > + printmsg(fp, mp, msgnum, fmtstr, width); > + /* printf("%s\n", m_name(msgnum)); */ > + } Commented code? > +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; Why cases #define SCNMSG 1 /* message just fine*/ #define SCNERR (-1) /* error message*/ are merged?
Re: [mmh] scan and pick (was: How "modern" are you willing to go?)
[2016-09-09 19:45] Philipp Takacs > It wouldn't be that complicate. We would to replace the > > > printf("%s\n", m_name(msgnum)); > > with a call to scan() and add the ``-format'' switch. > > In other words pick supports only the format '=%(msg)' at > the moment. If we have a format switch in pick we could replace > scan by a symlink to pick. I have implemented this to have a code example we can discouse not only an idea. The patch is attached. Philipp diff --git a/uip/Makefile.in b/uip/Makefile.in index e7e7b46..cd43aaa 100644 --- a/uip/Makefile.in +++ b/uip/Makefile.in @@ -172,8 +172,8 @@ new: new.o $(LOCALLIBS) 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 diff --git a/uip/pick.c b/uip/pick.c index 4cb33fb..10f79ef 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #ifdef HAVE_SYS_TIME_H # include @@ -63,9 +65,13 @@ static struct swit switches[] = { { "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 } }; @@ -83,10 +89,12 @@ static int listsw = -1; void putzero_done(); +void printmsg(FILE *f, struct msgs *mp, int msgnum, char *fmtstr, int width); + 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]; @@ -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 *form = NULL; + char *fmtstr; FILE *fp; -if (atexit(putzero_done) != 0) { + if (atexit(putzero_done) != 0) { adios(EX_OSERR, NULL, "atexit failed"); } @@ -109,6 +119,10 @@ main(int argc, char **argv) arguments = getarguments(invo_name, argc, argv, 1); argp = arguments; + if (strcmp(invo_name,"scan")==0) { + form = scanformat; + } + while ((cp = *argp++)) { if (*cp == '-') { if (*++cp == '-') { @@ -193,6 +207,18 @@ main(int argc, char **argv) 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 == '@') { @@ -205,6 +231,8 @@ main(int argc, char **argv) } vec[vecp] = NULL; + fmtstr = new_fs(form, "pick.default"); + /* ** If we didn't specify which messages to search, ** then search the whole folder. @@ -271,8 +299,10 @@ main(int argc, char **argv) if (msgnum > hi) hi = msgnum; -if (listsw) - printf("%s\n", m_name(msgnum)); +if (listsw) { + printmsg(fp, mp, msgnum, fmtstr, width); + /* printf("%s\n", m_name(msgnum)); */ +} } else { /* if it doesn't match, then unselect it */ unset_selected(mp, msgnum); @@ -320,6 +350,30 @@ putzero_done() printf("0\n"); } +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