X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ef15ffef47e7fc7d5716ce1c2ebccef17ed6e10e..dbd0fa0a56a222bd118fea627eba53e5d9811d01:/uip/scansbr.c diff --git a/uip/scansbr.c b/uip/scansbr.c index d1868451..f863e9b7 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -14,11 +14,6 @@ #include #include -#ifdef _FSTDIO -# define _ptr _p /* Gag */ -# define _cnt _w /* Wretch */ -#endif - #define MAXSCANL 256 /* longest possible scan line */ /* @@ -65,7 +60,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, int unseen, char *folder, long size, int noisy) { int i, compnum, encrypted, state; - unsigned char *cp, *tmpbuf; + unsigned char *cp, *tmpbuf, *startbody; char **nxtbuf; char *saved_c_text = NULL; struct comp *cptr; @@ -73,6 +68,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, char *scnmsg = NULL; FILE *scnout = NULL; char name[NAMESZ]; + int bufsz; static int rlwidth, slwidth; static size_t scanl_size; @@ -93,7 +89,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, umask(~m_gmprot()); /* Compile format string */ - ncomps = fmt_compile (nfs, &fmt, 1) + 1; + ncomps = fmt_compile (nfs, &fmt, 1) + 2; bodycomp = fmt_findcomp("body"); datecomp = fmt_findcomp("date"); @@ -158,6 +154,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, nxtbuf = compbuffers; savecomp = used_buf; tmpbuf = *nxtbuf++; + startbody = NULL; dat[0] = innum ? innum : outnum; dat[1] = curflg; dat[4] = unseen; @@ -166,7 +163,8 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, * Get the first field. If the message is non-empty * and we're doing an "inc", open the output file. */ - if ((state = m_getfld (FLD, name, tmpbuf, rlwidth, inb)) == FILEEOF) { + bufsz = rlwidth; + if ((state = m_getfld (FLD, name, tmpbuf, &bufsz, inb)) == FILEEOF) { if (ferror(inb)) { advise("read", "unable to"); /* "read error" */ return SCNFAT; @@ -188,7 +186,8 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, } /* scan - main loop */ - for (compnum = 1; ; state = m_getfld (state, name, tmpbuf, rlwidth, inb)) { + for (compnum = 1; ; + bufsz = rlwidth, state = m_getfld (state, name, tmpbuf, &bufsz, inb)) { switch (state) { case FLD: case FLDPLUS: @@ -219,7 +218,8 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, } while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, rlwidth, inb); + bufsz = rlwidth; + state = m_getfld (state, name, tmpbuf, &bufsz, inb); if (outnum) FPUTS (tmpbuf); } @@ -233,51 +233,44 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, */ if ((i = strlen(tmpbuf)) < rlwidth) { - state = m_getfld (state, name, tmpbuf + i, - rlwidth - i, inb); + bufsz = rlwidth - i; + state = m_getfld (state, name, tmpbuf + i, &bufsz, inb); } + if (! outnum) { state = FILEEOF; /* stop now if scan cmd */ + if (bodycomp && startbody == NULL) + startbody = tmpbuf; goto finished; } if (putc ('\n', scnout) == EOF) DIEWRERR(); FPUTS (tmpbuf); /* - * performance hack: some people like to run "inc" on - * things like net.sources or large digests. We do a - * copy directly into the output buffer rather than - * going through an intermediate buffer. + * The previous code here used to call m_getfld() using + * pointers to the underlying output stdio buffers to + * avoid the extra copy. Tests by Markus Schnalke show + * no noticable performance loss on larger mailboxes + * if we incur an extra copy, and messing around with + * internal stdio buffers is becoming more and more + * unportable as times go on. So from now on just deal + * with the overhead of an extra copy. * - * We need the amount of data m_getfld found & don't - * want to do a strlen on the long buffer so there's - * a hack in m_getfld to save the amount of data it - * returned in the global "msg_count". + * Subtle change - with the previous code tmpbuf wasn't + * used, so we could reuse it for the {body} component. + * Now since we're using tmpbuf as our read buffer we + * need to save the beginning of the body for later. + * See the above (and below) use of startbody. */ body:; + if (bodycomp && startbody == NULL) { + startbody = tmpbuf; + tmpbuf = *nxtbuf++; + } + while (state == BODY) { -#ifdef LINUX_STDIO - if (scnout->_IO_write_ptr == scnout->_IO_write_end) { -#elif defined(__DragonFly__) - if (((struct __FILE_public *)scnout)->_w <= 0) { -#else - if (scnout->_cnt <= 0) { -#endif - if (fflush(scnout) == EOF) - DIEWRERR (); - } -#ifdef LINUX_STDIO - state = m_getfld(state, name, scnout->_IO_write_ptr, - (long)scnout->_IO_write_ptr-(long)scnout->_IO_write_end , inb); - scnout->_IO_write_ptr += msg_count; -#elif defined(__DragonFly__) - state = m_getfld( state, name, ((struct __FILE_public *)scnout)->_p, -(((struct __FILE_public *)scnout)->_w), inb ); - ((struct __FILE_public *)scnout)->_w -= msg_count; - ((struct __FILE_public *)scnout)->_p += msg_count; -#else - state = m_getfld( state, name, scnout->_ptr, -(scnout->_cnt), inb ); - scnout->_cnt -= msg_count; - scnout->_ptr += msg_count; -#endif + bufsz = rlwidth; + state = m_getfld(state, name, tmpbuf, &bufsz, inb); + FPUTS(tmpbuf); } goto finished; @@ -318,7 +311,7 @@ finished: /* Save and restore buffer so we don't trash our dynamic pool! */ if (bodycomp) { saved_c_text = bodycomp->c_text; - bodycomp->c_text = tmpbuf; + bodycomp->c_text = startbody; } if (size)