- /* first-time only initialization */
- if (!scanl) {
- if (width == 0) {
- if ((width = sc_width ()) < WIDTH/2)
- width = WIDTH/2;
- else if (width > MAXSCANL)
- width = MAXSCANL;
- }
- dat[3] = slwidth = width;
- if ((scanl = (char *) malloc((size_t) (slwidth + 2) )) == NULL)
- adios (NULL, "unable to malloc scan line (%d bytes)", slwidth+2);
- if (outnum)
- umask(~m_gmprot());
-
- /* Compile format string */
- ncomps = fmt_compile (nfs, &fmt) + 1;
-
-#ifdef JLR
- fmt_top = fmt;
-#endif /* JLR */
- FINDCOMP(bodycomp, "body");
- FINDCOMP(datecomp, "date");
- FINDCOMP(cptr, "folder");
- if (cptr && folder)
- cptr->c_text = folder;
- FINDCOMP(cptr, "encrypted");
- if (!cptr)
- if ((cptr = (struct comp *) calloc (1, sizeof(*cptr)))) {
- cptr->c_name = "encrypted";
- cptr->c_next = wantcomp[i = CHASH (cptr->c_name)];
- wantcomp[i] = cptr;
- ncomps++;
- }
- FINDCOMP (cptr, "dtimenow");
- if (cptr)
- cptr->c_text = getcpy(dtimenow (0));
- nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *));
- if (nxtbuf == NULL)
- adios (NULL, "unable to allocate component buffers");
- used_buf = (struct comp **) calloc((size_t) (ncomps+1),
- sizeof(struct comp *));
- if (used_buf == NULL)
- adios (NULL, "unable to allocate component buffer stack");
- used_buf += ncomps+1; *--used_buf = 0;
- rlwidth = bodycomp && (width > SBUFSIZ) ? width : SBUFSIZ;
- for (i = ncomps; i--; )
- if ((*nxtbuf++ = malloc(rlwidth)) == NULL)
- adios (NULL, "unable to allocate component buffer");
- }
-
- /*
- * each-message initialization
- */
- nxtbuf = compbuffers;
- savecomp = used_buf;
- tmpbuf = *nxtbuf++;
- dat[0] = innum ? innum : outnum;
- dat[1] = curflg;
- dat[4] = unseen;
-
- /*
- * 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) {
- if (ferror(inb)) {
- advise("read", "unable to"); /* "read error" */
- return SCNFAT;
- } else {
- return SCNEOF;
- }
- }
-
- if (outnum) {
- if (outnum > 0) {
- scnmsg = m_name (outnum);
- if (*scnmsg == '?') /* msg num out of range */
- return SCNNUM;
- } else {
- scnmsg = "/dev/null";
+ /* first-time only initialization */
+ if (!scanl) {
+ if (incing)
+ umask(~m_gmprot());
+
+ if (fmtstr) {
+ if (width == 0) {
+ if ((width = sc_width()) < WIDTH/2)
+ width = WIDTH/2;
+ else if (width > MAXSCANL)
+ width = MAXSCANL;
+ }
+ dat[3] = slwidth = width;
+ scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH *
+ (slwidth + 2)); /* probably for \n and \0 */
+ /* Compile format string */
+ ncomps = fmt_compile(fmtstr, &fmt) + 1;
+ FINDCOMP(datecomp, "date");
+ } else {
+ ncomps = 1;
+ datecomp = NULL;
+ }
+
+ nxtbuf = compbuffers = (char **) calloc((size_t) ncomps,
+ sizeof(char *));
+ if (!nxtbuf)
+ adios(NULL, "unable to allocate component buffers");
+ used_buf = (struct comp **) calloc((size_t) (ncomps+1),
+ sizeof(struct comp *));
+ if (!used_buf)
+ adios(NULL, "unable to allocate component buffer stack");
+ /* NULL-terminate array */
+ used_buf += ncomps;
+ *used_buf = NULL;
+ /* allocate space for the items */
+ for (i = ncomps; i--; )
+ *nxtbuf++ = mh_xmalloc(SBUFSIZ);