From: David Levine Date: Sat, 22 Dec 2012 17:51:21 +0000 (-0600) Subject: Changed bufsz argument of m_getfld() to be in-out instead of in. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/869b0d5dc814215b72b1899cf82073d13bb65a97?ds=sidebyside;hp=-c Changed bufsz argument of m_getfld() to be in-out instead of in. This allowed removal of the msg_count global, in turn allowing removal of sbr/m_msgdef.c --- 869b0d5dc814215b72b1899cf82073d13bb65a97 diff --git a/Makefile.am b/Makefile.am index 27ffdfbb..54d37c2c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -499,7 +499,7 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/base64.c \ sbr/showfile.c sbr/signals.c sbr/smatch.c \ sbr/snprintb.c sbr/ssequal.c sbr/strcasecmp.c \ sbr/strindex.c sbr/trimcpy.c sbr/uprf.c sbr/vfgets.c \ - sbr/fmt_def.c sbr/m_msgdef.c sbr/mf.c sbr/utils.c \ + sbr/fmt_def.c sbr/mf.c sbr/utils.c \ sbr/m_mktemp.c sbr/getansreadline.c config/config.c \ config/version.c diff --git a/h/mh.h b/h/mh.h index f29379ea..fb05fa7d 100644 --- a/h/mh.h +++ b/h/mh.h @@ -251,8 +251,6 @@ struct msgs { #define MS_MMDF 3 /* string mmdlm2 */ #define MS_MSH 4 /* whacko msh */ -extern int msg_count; /* m_getfld() indicators */ - #define NOUSE 0 /* draft being re-used */ #define TFOLDER 0 /* path() given a +folder */ diff --git a/h/prototypes.h b/h/prototypes.h index c40e5634..619be910 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -76,7 +76,7 @@ char *m_backup (char *); int m_convert (struct msgs *, char *); char *m_draft (char *, char *, int, int *); void m_eomsbr (int (*)(int)); -int m_getfld (int, unsigned char[NAMESZ], unsigned char *, int, FILE *); +int m_getfld (int, unsigned char[NAMESZ], unsigned char *, int *, FILE *); int m_gmprot (void); char *m_maildir (char *); char *m_mailpath (char *); diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 91a1d8cc..e80da57b 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -151,8 +151,8 @@ Outputs ======= name: header field name (array of size NAMESZ=999) buf: either a header field body or message body +bufsz: number of characters loaded into buf (return value): message parse state on return from function -(global) int msg_count: number of characters loaded into buf Functions (part of Inputs, really) ========= @@ -212,18 +212,11 @@ Subsequent calls provide the state returned by the previous call. Along the way, I thought of these possible interface changes that we might want to consider before rototilling the internals: -1) To remove a global: - Change bufsz to be in-out instead of in, and therefore int * instead of - int, and use that instead of global msg_count. There are only 3 call - sites that use msg_count so it wouldn't take much effort to remove use of - it. Of course, all call sites would have to change to provide an int * - instead of an int. Some now pass constants. - -2) To remove the state argument from the signature: +1) To remove the state argument from the signature: Given the Current usage and Restriction above, the state variable could be removed from the signature and just retained internally. -3) To remove the Restriction above: +2) To remove the Restriction above: One approach would be for m_getfld() to retain multiple copies of that state, one per iob that it sees. Another approach would be for the caller to store it in an opaque struct, the address of which is passed @@ -244,14 +237,6 @@ static unsigned char *locc(int, unsigned char *, unsigned char); static unsigned char **pat_map; -/* - * defined in sbr/m_msgdef.c = 0 - * This is a disgusting hack for "inc" so it can know how many - * characters were stuffed in the buffer on the last call - * (see comments in uip/scansbr.c). - */ -extern int msg_count; - static int msg_style = MS_DEFAULT; /* @@ -294,13 +279,13 @@ extern int _filbuf(FILE*); int m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, - int bufsz, FILE *iob) + int *bufsz, FILE *iob) { register unsigned char *bp, *cp, *ep, *sp; register int cnt, c, i, j; if ((c = Getc(iob)) < 0) { - msg_count = 0; + *bufsz = 0; *buf = 0; return FILEEOF; } @@ -312,7 +297,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, if (c >= 0) ungetc(c, iob); } - msg_count = 0; + *bufsz = 0; *buf = 0; return FILEEOF; } @@ -334,7 +319,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, if (c >= 0) ungetc(c, iob); } - msg_count = 0; + *bufsz = 0; *buf = 0; return FILEEOF; } @@ -411,7 +396,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, /* See if buf can hold this line, since we were assuming * we had a buffer of NAMESZ, not bufsz. */ /* + 1 for the newline */ - if (bufsz < j + 1) { + if (*bufsz < j + 1) { /* No, it can't. Oh well, guess we'll blow up. */ *cp = *buf = 0; advise (NULL, "eol encountered in field \"%s\"", name); @@ -450,7 +435,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, * characters up to the end of this field (newline * followed by non-blank) or bufsz-1 characters. */ - cp = buf; i = bufsz-1; + cp = buf; i = *bufsz-1; for (;;) { #ifdef LINUX_STDIO cnt = (long) iob->_IO_read_end - (long) iob->_IO_read_ptr; @@ -565,7 +550,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, * we assume that we were called to copy directly into * the output buffer and we don't add an eos. */ - i = (bufsz < 0) ? -bufsz : bufsz-1; + i = (*bufsz < 0) ? -*bufsz : *bufsz-1; #ifdef LINUX_STDIO bp = (unsigned char *) --iob->_IO_read_ptr; cnt = (long) iob->_IO_read_end - (long) iob->_IO_read_ptr; @@ -654,8 +639,8 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, iob->_cnt -= c; iob->_ptr += c; #endif - if (bufsz < 0) { - msg_count = c; + if (*bufsz < 0) { + *bufsz = c; return (state); } cp = buf + c; @@ -666,7 +651,7 @@ m_getfld (int state, unsigned char name[NAMESZ], unsigned char *buf, } finish: *cp = 0; - msg_count = cp - buf; + *bufsz = cp - buf; return (state); } diff --git a/sbr/m_msgdef.c b/sbr/m_msgdef.c deleted file mode 100644 index 9520012d..00000000 --- a/sbr/m_msgdef.c +++ /dev/null @@ -1,17 +0,0 @@ - -/* - * m_msgdef.c -- some defines for sbr/m_getfld.c - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ - -#include - -/* - * disgusting hack for "inc" so it can know how many characters - * were stuffed in the buffer on the last call (see comments - * in uip/scansbr.c) - */ -int msg_count = 0; diff --git a/sbr/readconfig.c b/sbr/readconfig.c index 1ddd648f..0efc9a5e 100644 --- a/sbr/readconfig.c +++ b/sbr/readconfig.c @@ -59,7 +59,8 @@ readconfig (struct node **npp, FILE *ib, char *file, int ctx) } for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), ib)) { + int fieldsz = sizeof field; + switch (state = m_getfld (state, name, field, &fieldsz, ib)) { case FLD: case FLDPLUS: case FLDEOF: @@ -70,7 +71,8 @@ readconfig (struct node **npp, FILE *ib, char *file, int ctx) if (state == FLDPLUS) { cp = getcpy (field); while (state == FLDPLUS) { - state = m_getfld (state, name, field, sizeof(field), ib); + fieldsz = sizeof field; + state = m_getfld (state, name, field, &fieldsz, ib); cp = add (field, cp); } np->n_field = trimcpy (cp); diff --git a/sbr/seq_read.c b/sbr/seq_read.c index 985c61e8..3cf8ad89 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -77,14 +77,16 @@ seq_public (struct msgs *mp) /* Use m_getfld to scan sequence file */ for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), fp)) { + int fieldsz = sizeof field; + switch (state = m_getfld (state, name, field, &fieldsz, fp)) { case FLD: case FLDPLUS: case FLDEOF: if (state == FLDPLUS) { cp = getcpy (field); while (state == FLDPLUS) { - state = m_getfld (state, name, field, sizeof(field), fp); + fieldsz = sizeof field; + state = m_getfld (state, name, field, &fieldsz, fp); cp = add (field, cp); } seq_init (mp, getcpy (name), trimcpy (cp)); diff --git a/uip/distsbr.c b/uip/distsbr.c index afd4e419..bbaeaf51 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -46,9 +46,9 @@ distout (char *drft, char *msgnam, char *backup) lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ cpydata (hdrfd, fileno (ofp), msgnam, drft); - for (state = FLD, resent = NULL;;) - switch (state = - m_getfld (state, name, buffer, sizeof buffer, ifp)) { + for (state = FLD, resent = NULL;;) { + int buffersz = sizeof buffer; + switch (state = m_getfld (state, name, buffer, &buffersz, ifp)) { case FLD: case FLDPLUS: case FLDEOF: @@ -65,8 +65,8 @@ distout (char *drft, char *msgnam, char *backup) resent = add (buffer, resent); fprintf (ofp, "%s: %s", name, buffer); while (state == FLDPLUS) { - state = m_getfld (state, name, - buffer, sizeof buffer, ifp); + buffersz = sizeof buffer; + state = m_getfld (state, name, buffer, &buffersz, ifp); resent = add (buffer, resent); fputs (buffer, ofp); } @@ -99,6 +99,7 @@ distout (char *drft, char *msgnam, char *backup) default: adios (NULL, "getfld() returned %d", state); } + } process: ; fclose (ifp); fflush (ofp); @@ -151,9 +152,9 @@ ready_msg (char *msgnam) adios (NULL, "no file descriptors -- you lose big"); unlink (tmpfil); - for (state = FLD;;) - switch (state = - m_getfld (state, name, buffer, sizeof buffer, ifp)) { + for (state = FLD;;) { + int buffersz = sizeof buffer; + switch (state = m_getfld (state, name, buffer, &buffersz, ifp)) { case FLD: case FLDPLUS: case FLDEOF: @@ -161,8 +162,8 @@ ready_msg (char *msgnam) fprintf (ofp, "Prev-"); fprintf (ofp, "%s: %s", name, buffer); while (state == FLDPLUS) { - state = m_getfld (state, name, - buffer, sizeof buffer, ifp); + buffersz = sizeof buffer; + state = m_getfld (state, name, buffer, &buffersz, ifp); fputs (buffer, ofp); } if (state == FLDEOF) @@ -185,8 +186,8 @@ ready_msg (char *msgnam) unlink (tmpfil); fprintf (ofp, "\n%s", buffer); while (state == BODY) { - state = m_getfld (state, name, - buffer, sizeof buffer, ifp); + buffersz = sizeof buffer; + state = m_getfld (state, name, buffer, &buffersz, ifp); fputs (buffer, ofp); } case FILEEOF: @@ -199,6 +200,7 @@ ready_msg (char *msgnam) default: adios (NULL, "getfld() returned %d", state); } + } process: ; fclose (ifp); fclose (ofp); diff --git a/uip/forwsbr.c b/uip/forwsbr.c index 86255857..534c2b05 100644 --- a/uip/forwsbr.c +++ b/uip/forwsbr.c @@ -87,7 +87,8 @@ build_form (char *form, char *digest, int *dat, char *from, char *to, */ for (state = FLD;;) { - state = m_getfld(state, name, msgbuf, sizeof(msgbuf), tmp); + int msg_count = sizeof msgbuf; + state = m_getfld(state, name, msgbuf, &msg_count, tmp); switch (state) { case FLD: case FLDPLUS: @@ -101,14 +102,15 @@ build_form (char *form, char *digest, int *dat, char *from, char *to, if (i != -1) { char_read += msg_count; while (state == FLDPLUS) { - state = m_getfld(state, name, msgbuf, - sizeof(msgbuf), tmp); + msg_count = sizeof msgbuf; + state = m_getfld(state, name, msgbuf, &msg_count, tmp); fmt_appendcomp(i, name, msgbuf); char_read += msg_count; } } while (state == FLDPLUS) - state = m_getfld(state, name, msgbuf, sizeof(msgbuf), tmp); + msg_count = sizeof msgbuf; + state = m_getfld(state, name, msgbuf, &msg_count, tmp); break; case LENERR: diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index ec2c195a..c7164b32 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -163,7 +163,8 @@ build_mime (char *infile, int directives) * the new MIME message. */ for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, in)) { case FLD: case FLDPLUS: case FLDEOF: @@ -179,8 +180,10 @@ build_mime (char *infile, int directives) /* ignore any Content-Type fields in the header */ if (!mh_strcasecmp (name, TYPE_FIELD)) { - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), in); + while (state == FLDPLUS) { + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); + } goto finish_field; } @@ -190,7 +193,8 @@ build_mime (char *infile, int directives) /* if necessary, get rest of field */ while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); vp = add (buf, vp); /* add to previous value */ } diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index 5f7777d0..59e27914 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -383,8 +383,9 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen) for (state = FLD;;) { int result; char *cp, *dp; + int bufsz = sizeof buf; - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + switch (state = m_getfld (state, name, buf, &bufsz, fp)) { case FLD: case FLDPLUS: case FLDEOF: @@ -394,7 +395,8 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen) else { cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); cp = add (buf, cp); } } diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 45d99b03..2c241714 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1015,14 +1015,16 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) } for (state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, fp)) { case FLD: case FLDPLUS: bucket = fmt_addcomptext(name, buf); for (ip = ignores; *ip; ip++) if (!mh_strcasecmp (name, *ip)) { while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); fmt_appendcomp(bucket, name, buf); } break; @@ -1044,7 +1046,8 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) if (c1 == NULL) c1 = add_queue (&msghd, &msgtl, name, buf, 0); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); c1->c_text = add (buf, c1->c_text); fmt_appendcomp(bucket, name, buf); } @@ -1083,8 +1086,9 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) strncpy (holder.c_text, buf, sizeof(buf)); while (state == BODY) { putcomp (c1, &holder, BODYCOMP); + bufsz = sizeof buf; state = m_getfld (state, name, holder.c_text, - sizeof(buf), fp); + &bufsz, fp); } free (holder.c_text); holder.c_text = NULL; @@ -1838,8 +1842,9 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp) */ while (state == BODY) { + int bufsz2 = bufsz; write(fdinput[1], buf, strlen(buf)); - state = m_getfld(state, name, buf, bufsz, fp); + state = m_getfld(state, name, buf, &bufsz2, fp); } /* diff --git a/uip/mhparse.c b/uip/mhparse.c index 8cfa8998..ea5400e0 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -276,7 +276,8 @@ get_content (FILE *in, char *file, int toplevel) * content into a linked list. */ for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, in)) { case FLD: case FLDPLUS: case FLDEOF: @@ -288,7 +289,8 @@ get_content (FILE *in, char *file, int toplevel) /* if necessary, get rest of field */ while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); vp = add (buf, vp); /* add to previous value */ } diff --git a/uip/msh.c b/uip/msh.c index b3aa3a10..36286e0b 100644 --- a/uip/msh.c +++ b/uip/msh.c @@ -1005,15 +1005,17 @@ readid (int msgnum) return Msgs[msgnum].m_bboard_id; zp = msh_ready (msgnum, 0); - for (state = FLD;;) - switch (state = m_getfld (state, name, buf, sizeof(buf), zp)) { + for (state = FLD;;) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, zp)) { case FLD: case FLDEOF: case FLDPLUS: if (!mh_strcasecmp (name, BBoard_ID)) { bp = getcpy (buf); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), zp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, zp); bp = add (buf, bp); } i = atoi (bp); @@ -1024,13 +1026,15 @@ readid (int msgnum) continue; } while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), zp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, zp); if (state != FLDEOF) continue; default: return 0; } + } } diff --git a/uip/mshcmds.c b/uip/mshcmds.c index 5f571b49..c2a8a3cf 100644 --- a/uip/mshcmds.c +++ b/uip/mshcmds.c @@ -2435,8 +2435,9 @@ is_nontext (int msgnum) fp = msh_ready (msgnum, 1); - for (state = FLD;;) - switch (state = m_getfld (state, name, buf, sizeof buf, fp)) { + for (state = FLD;;) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, fp)) { case FLD: case FLDPLUS: case FLDEOF: @@ -2449,7 +2450,8 @@ is_nontext (int msgnum) cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof buf, fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); cp = add (buf, cp); } bp = cp; @@ -2552,7 +2554,8 @@ out: if (!mh_strcasecmp (name, ENCODING_FIELD)) { cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof buf, fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); cp = add (buf, cp); } for (bp = cp; isspace (*bp); bp++) @@ -2576,8 +2579,10 @@ out: * Just skip the rest of this header * field and go to next one. */ - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), fp); + while (state == FLDPLUS) { + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); + } break; /* @@ -2587,6 +2592,7 @@ out: default: return 0; } + } } @@ -2742,14 +2748,16 @@ get_fields (char *datesw, char *subjsw, int msgnum, struct Msg *msgp) zp = msh_ready (msgnum, 0); for (state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof buf, zp)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, zp)) { case FLD: case FLDEOF: case FLDPLUS: if (!mh_strcasecmp (name, datesw)) { bp = getcpy (buf); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof buf, zp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, zp); bp = add (buf, bp); } if ((tw = dparsetime (bp)) == NULL) @@ -2766,7 +2774,8 @@ get_fields (char *datesw, char *subjsw, int msgnum, struct Msg *msgp) else if (subjsw && !mh_strcasecmp(name, subjsw)) { bp = getcpy (buf); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof buf, zp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, zp); bp = add (buf, bp); } msgp->m_scanl = sosmash(subjsw, bp); @@ -2775,8 +2784,10 @@ get_fields (char *datesw, char *subjsw, int msgnum, struct Msg *msgp) else subjsw = (char *)0;/* subject done, need date */ } else { - while (state == FLDPLUS) /* flush this one */ - state = m_getfld (state, name, buf, sizeof buf, zp); + while (state == FLDPLUS) { /* flush this one */ + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, zp); + } } continue; diff --git a/uip/new.c b/uip/new.c index 10854dc9..198207a8 100644 --- a/uip/new.c +++ b/uip/new.c @@ -105,15 +105,16 @@ get_msgnums(char *folder, char *sequences[]) /* copied from seq_read.c:seq_public */ for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), fp)) { + int fieldsz = sizeof field; + switch (state = m_getfld (state, name, field, &fieldsz, fp)) { case FLD: case FLDPLUS: case FLDEOF: if (state == FLDPLUS) { cp = getcpy (field); while (state == FLDPLUS) { - state = m_getfld (state, name, field, - sizeof(field), fp); + fieldsz = sizeof field; + state = m_getfld (state, name, field, &fieldsz, fp); cp = add (field, cp); } diff --git a/uip/picksbr.c b/uip/picksbr.c index 91893e3c..d03e72be 100644 --- a/uip/picksbr.c +++ b/uip/picksbr.c @@ -947,7 +947,8 @@ plist fseek (fp, start, SEEK_SET); for (state = FLD, bp = NULL;;) { - switch (state = m_getfld (state, name, buf, sizeof buf, fp)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, fp)) { case FLD: case FLDEOF: case FLDPLUS: @@ -955,7 +956,8 @@ plist free (bp), bp = NULL; bp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof buf, fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); bp = add (buf, bp); } if (!mh_strcasecmp (name, n->n_datef)) diff --git a/uip/post.c b/uip/post.c index 6b078619..ffc9de80 100644 --- a/uip/post.c +++ b/uip/post.c @@ -579,14 +579,16 @@ main (int argc, char **argv) hdrtab = msgstate == NORMAL ? NHeaders : RHeaders; for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, in)) { case FLD: case FLDEOF: case FLDPLUS: compnum++; cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); cp = add (buf, cp); } putfmt (name, cp, out); @@ -603,7 +605,8 @@ main (int argc, char **argv) break; fprintf (out, "\n%s", buf); while (state == BODY) { - state = m_getfld (state, name, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); fputs (buf, out); } break; diff --git a/uip/prompter.c b/uip/prompter.c index 795e4724..6b540dbc 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -209,7 +209,8 @@ main (int argc, char **argv) * Loop through the lines of the draft skeleton. */ for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), in)) { + int fieldsz = sizeof field; + switch (state = m_getfld (state, name, field, &fieldsz, in)) { case FLD: case FLDEOF: case FLDPLUS: @@ -226,8 +227,8 @@ main (int argc, char **argv) printf ("%s:%s", name, field); fprintf (out, "%s:%s", name, field); while (state == FLDPLUS) { - state = - m_getfld (state, name, field, sizeof(field), in); + fieldsz = sizeof field; + state = m_getfld (state, name, field, &fieldsz, in); printf ("%s", field); fprintf (out, "%s", field); } @@ -293,7 +294,8 @@ abort: if (!rapid && !sigint) printf ("%s", field); } while (state == BODY && - (state = m_getfld (state, name, field, sizeof(field), in))); + (fieldsz = sizeof field, + state = m_getfld (state, name, field, &fieldsz, in))); if (prepend || !body) break; else diff --git a/uip/rcvdist.c b/uip/rcvdist.c index d3f36caa..fd58396a 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -193,21 +193,25 @@ rcvdistout (FILE *inb, char *form, char *addrs) cptr->c_text = addrs; for (state = FLD;;) { - switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) { + int msg_count = SBUFSIZ; + switch (state = m_getfld (state, name, tmpbuf, &msg_count, inb)) { case FLD: case FLDPLUS: i = fmt_addcomptext(name, tmpbuf); if (i != -1) { char_read += msg_count; while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + msg_count = SBUFSIZ; + state = m_getfld (state, name, tmpbuf, &msg_count, inb); fmt_appendcomp(i, name, tmpbuf); char_read += msg_count; } } - while (state == FLDPLUS) - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + while (state == FLDPLUS) { + msg_count = SBUFSIZ; + state = m_getfld (state, name, tmpbuf, &msg_count, inb); + } break; case LENERR: diff --git a/uip/replsbr.c b/uip/replsbr.c index 3dbc3031..dc3c4f8c 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -132,7 +132,8 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, * pick any interesting stuff out of msg "inb" */ for (state = FLD;;) { - state = m_getfld (state, name, tmpbuf, sizeof(tmpbuf), inb); + int msg_count = sizeof tmpbuf; + state = m_getfld (state, name, tmpbuf, &msg_count, inb); switch (state) { case FLD: case FLDPLUS: @@ -147,15 +148,17 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, if (i != -1) { char_read += msg_count; while (state == FLDPLUS) { - state = m_getfld(state, name, tmpbuf, - sizeof(tmpbuf), inb); + msg_count= sizeof tmpbuf; + state = m_getfld(state, name, tmpbuf, &msg_count, inb); fmt_appendcomp(i, name, tmpbuf); char_read += msg_count; } } - while (state == FLDPLUS) - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + while (state == FLDPLUS) { + msg_count= sizeof tmpbuf; + state = m_getfld (state, name, tmpbuf, &msg_count, inb); + } break; case LENERR: diff --git a/uip/scansbr.c b/uip/scansbr.c index 232a4190..a023e914 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -68,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; @@ -162,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; @@ -184,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: @@ -215,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); } @@ -229,8 +233,8 @@ 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) { @@ -264,7 +268,8 @@ body:; } while (state == BODY) { - state = m_getfld(state, name, tmpbuf, rlwidth, inb); + bufsz = rlwidth; + state = m_getfld(state, name, tmpbuf, &bufsz, inb); FPUTS(tmpbuf); } goto finished; diff --git a/uip/sendsbr.c b/uip/sendsbr.c index dfd974f4..a7dc0ea5 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -603,7 +603,8 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) * as well as locate the beginning of the message body. */ for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buffer, sizeof(buffer), in)) { + int bufsz = sizeof buffer; + switch (state = m_getfld (state, name, buffer, &bufsz, in)) { case FLD: case FLDPLUS: case FLDEOF: @@ -613,8 +614,10 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) * This header field is discarded. */ if (!mh_strcasecmp (name, "Message-ID")) { - while (state == FLDPLUS) - state = m_getfld (state, name, buffer, sizeof(buffer), in); + while (state == FLDPLUS) { + bufsz = sizeof buffer; + state = m_getfld (state, name, buffer, &bufsz, in); + } } else if (uprf (name, XXX_FIELD_PRF) || !mh_strcasecmp (name, VRSN_FIELD) || !mh_strcasecmp (name, "Subject") @@ -638,7 +641,8 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) dp = add (concat (name, ":", buffer, NULL), dp); while (state == FLDPLUS) { - state = m_getfld (state, name, buffer, sizeof(buffer), in); + bufsz = sizeof buffer; + state = m_getfld (state, name, buffer, &bufsz, in); dp = add (buffer, dp); } } else { @@ -648,7 +652,8 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) */ cp = add (concat (name, ":", buffer, NULL), cp); while (state == FLDPLUS) { - state = m_getfld (state, name, buffer, sizeof(buffer), in); + bufsz = sizeof buffer; + state = m_getfld (state, name, buffer, &bufsz, in); cp = add (buffer, cp); } } diff --git a/uip/show.c b/uip/show.c index 84942164..ad750462 100644 --- a/uip/show.c +++ b/uip/show.c @@ -353,7 +353,8 @@ is_nontext (char *msgnam) return 0; for (state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, fp)) { case FLD: case FLDPLUS: case FLDEOF: @@ -366,7 +367,8 @@ is_nontext (char *msgnam) cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); cp = add (buf, cp); } bp = cp; @@ -469,7 +471,8 @@ out: if (!mh_strcasecmp (name, ENCODING_FIELD)) { cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); cp = add (buf, cp); } for (bp = cp; isspace (*bp); bp++) @@ -493,8 +496,10 @@ out: * Just skip the rest of this header * field and go to next one. */ - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), fp); + while (state == FLDPLUS) { + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); + } break; /* diff --git a/uip/slocal.c b/uip/slocal.c index 869fa17f..5eadea45 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -740,13 +740,15 @@ parse (int fd) * a lookup table. */ for (i = 0, state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), in)) { + int fieldsz = sizeof field; + switch (state = m_getfld (state, name, field, &fieldsz, in)) { case FLD: case FLDEOF: case FLDPLUS: lp = add (field, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, field, sizeof(field), in); + fieldsz = sizeof field; + state = m_getfld (state, name, field, &fieldsz, in); lp = add (field, lp); } for (p = hdrs; p->p_name; p++) { @@ -1424,21 +1426,25 @@ suppress_duplicates (int fd, char *file) rewind (in); for (state = FLD;;) { - state = m_getfld (state, name, buf, sizeof(buf), in); + int bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); switch (state) { case FLD: case FLDPLUS: case FLDEOF: /* Search for the message ID */ if (mh_strcasecmp (name, "Message-ID")) { - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), in); + while (state == FLDPLUS) { + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); + } continue; } cp = add (buf, NULL); while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, in); cp = add (buf, cp); } key.dptr = trimcpy (cp); diff --git a/uip/sortm.c b/uip/sortm.c index 024fcf5c..95c76b5f 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -371,7 +371,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg) return (0); } for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, nam, buf, sizeof(buf), in)) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, nam, buf, &bufsz, in)) { case FLD: case FLDEOF: case FLDPLUS: @@ -379,7 +380,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg) if (!mh_strcasecmp (nam, datesw)) { datecomp = add (buf, datecomp); while (state == FLDPLUS) { - state = m_getfld (state, nam, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, nam, buf, &bufsz, in); datecomp = add (buf, datecomp); } if (!subjsort || subjcomp) @@ -387,15 +389,18 @@ get_fields (char *datesw, int msg, struct smsg *smsg) } else if (subjsort && !mh_strcasecmp (nam, subjsort)) { subjcomp = add (buf, subjcomp); while (state == FLDPLUS) { - state = m_getfld (state, nam, buf, sizeof(buf), in); + bufsz = sizeof buf; + state = m_getfld (state, nam, buf, &bufsz, in); subjcomp = add (buf, subjcomp); } if (datecomp) break; } else { /* just flush this guy */ - while (state == FLDPLUS) - state = m_getfld (state, nam, buf, sizeof(buf), in); + while (state == FLDPLUS) { + bufsz = sizeof buf; + state = m_getfld (state, nam, buf, &bufsz, in); + } } continue; diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 38905372..a56446f8 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -941,8 +941,9 @@ check_draft (char *msgnam) if ((fp = fopen (msgnam, "r")) == NULL) return 0; - for (state = FLD;;) - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + for (state = FLD;;) { + int bufsz = sizeof buf; + switch (state = m_getfld (state, name, buf, &bufsz, fp)) { case FLD: case FLDPLUS: case FLDEOF: @@ -955,8 +956,10 @@ check_draft (char *msgnam) fclose (fp); return 0; } - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), fp); + while (state == FLDPLUS) { + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); + } break; case BODY: @@ -969,7 +972,8 @@ check_draft (char *msgnam) return 1; } - state = m_getfld (state, name, buf, sizeof(buf), fp); + bufsz = sizeof buf; + state = m_getfld (state, name, buf, &bufsz, fp); } while (state == BODY); /* and fall... */ @@ -977,6 +981,7 @@ check_draft (char *msgnam) fclose (fp); return 0; } + } }