X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0a032eea07f6d77ac6ea4d5a39c9491c34358058..ec173fd2c:/uip/picksbr.c?ds=sidebyside diff --git a/uip/picksbr.c b/uip/picksbr.c index e8d6435d..c11fba62 100644 --- a/uip/picksbr.c +++ b/uip/picksbr.c @@ -1,15 +1,22 @@ -/* - * picksbr.c -- routines to help pick along... +/* picksbr.c -- routines to help pick along... * * 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 -#include -#include -#include +#include "h/mh.h" +#include "picksbr.h" +#include "sbr/dtime.h" +#include "sbr/dtime.h" +#include "sbr/m_getfld.h" +#include "sbr/smatch.h" +#include "sbr/fmt_rfc2047.h" +#include "sbr/brkstring.h" +#include "sbr/ambigsw.h" +#include "sbr/error.h" +#include "h/tws.h" +#include "h/utils.h" #ifdef HAVE_SYS_TIME_H # include @@ -63,7 +70,7 @@ DEFINE_SWITCH_ARRAY(PARSE, parswit); #define STAR 01 -#define LBSIZE 1024 +#define LBSIZE NMH_BUFSIZ #define ESIZE 1024 @@ -117,7 +124,7 @@ static unsigned char cc[] = { #define pinform if (!talked++) inform struct nexus { - int (*n_action)(); + int (*n_action)(struct nexus *n, FILE *fp, int msgnum, long start, long stop); union { /* for {OR,AND,NOT}action */ @@ -181,13 +188,19 @@ static struct nexus *parse(void); static struct nexus *nexp1(void); static struct nexus *nexp2(void); static struct nexus *nexp3(void); -static struct nexus *newnexus(int (*)()); +static struct nexus *newnexus(int (*action)(struct nexus *n, + FILE *fp, int msgnum, long start, long stop)); -static int ORaction(); -static int ANDaction(); -static int NOTaction(); -static int GREPaction(); -static int TWSaction(); +static int ORaction(struct nexus *n, FILE *fp, int msgnum, + long start, long stop); +static int ANDaction(struct nexus *n, FILE *fp, int msgnum, + long start, long stop); +static int NOTaction(struct nexus *n, FILE *fp, int msgnum, + long start, long stop); +static int GREPaction(struct nexus *n, FILE *fp, int msgnum, + long start, long stop); +static int TWSaction(struct nexus *n, FILE *fp, int msgnum, + long start, long stop); int @@ -199,7 +212,7 @@ pcompile (char **vec, char *date) talked = 0; if ((head = parse ()) == NULL) - return (talked ? 0 : 1); + return !talked; if (*argp) { inform("%s unexpected", *argp); @@ -454,7 +467,8 @@ nexp3 (void) static struct nexus * -newnexus (int (*action)()) +newnexus(int (*action)(struct nexus *n, FILE *fp, int msgnum, + long start, long stop)) { struct nexus *p; @@ -464,15 +478,6 @@ newnexus (int (*action)()) } -#define args(a) a, fp, msgnum, start, stop -#define params args (n) -#define plist \ - struct nexus *n; \ - FILE *fp; \ - int msgnum; \ - long start, \ - stop; - int pmatches (FILE *fp, int msgnum, long start, long stop, int debug) { @@ -482,7 +487,7 @@ pmatches (FILE *fp, int msgnum, long start, long stop, int debug) if (!talked++ && debug) PRaction (head, 0); - return (*head->n_action) (args (head)); + return (*head->n_action)(head, fp, msgnum, start, stop); } @@ -522,36 +527,35 @@ PRaction (struct nexus *n, int level) dasctime (&n->n_tws, TW_NULL)); return; } - fprintf (stderr, "UNKNOWN(0x%x)\n", - (unsigned int)(unsigned long) (*n->n_action)); + + generic_pointer gp; + gp.f = (void (*)(void))n->n_action; + fprintf(stderr, "UNKNOWN(%p)\n", gp.v); } static int -ORaction (params) -plist +ORaction(struct nexus *n, FILE *fp, int msgnum, long start, long stop) { - if ((*n->n_L_child->n_action) (args (n->n_L_child))) + if ((*n->n_L_child->n_action)(n->n_L_child, fp, msgnum, start, stop)) return 1; - return (*n->n_R_child->n_action) (args (n->n_R_child)); + return (*n->n_R_child->n_action)(n->n_R_child, fp, msgnum, start, stop); } static int -ANDaction (params) -plist +ANDaction(struct nexus *n, FILE *fp, int msgnum, long start, long stop) { - if (!(*n->n_L_child->n_action) (args (n->n_L_child))) + if (!(*n->n_L_child->n_action)(n->n_L_child, fp, msgnum, start, stop)) return 0; - return (*n->n_R_child->n_action) (args (n->n_R_child)); + return (*n->n_R_child->n_action)(n->n_R_child, fp, msgnum, start, stop); } static int -NOTaction (params) -plist +NOTaction(struct nexus *n, FILE *fp, int msgnum, long start, long stop) { - return (!(*n->n_L_child->n_action) (args (n->n_L_child))); + return (!(*n->n_L_child->n_action)(n->n_L_child, fp, msgnum, start, stop)); } @@ -646,24 +650,25 @@ cerror: ; static int -GREPaction (params) -plist +GREPaction(struct nexus *n, FILE *fp, int msgnum, long start, long stop) { - int c, body, lf; + int c; + bool body; + bool lf; long pos = start; char *p1, *p2, *ebp, *cbp; char ibuf[BUFSIZ]; NMH_UNUSED (msgnum); fseek (fp, start, SEEK_SET); - body = 0; + body = false; ebp = cbp = ibuf; for (;;) { if (body && n->n_header) return 0; p1 = linebuf; p2 = cbp; - lf = 0; + lf = false; for (;;) { if (p2 >= ebp) { if (fgets (ibuf, sizeof ibuf, fp) == NULL @@ -682,21 +687,18 @@ plist --p2; break; } - else - lf = 0; + lf = false; } if (c == '\n') { if (body) break; - else { - if (lf) { - body++; - break; - } - lf++; - /* Unfold by skipping the newline. */ - c = 0; - } + if (lf) { + body = true; + break; + } + lf = true; + /* Unfold by skipping the newline. */ + c = 0; } if (c && p1 < &linebuf[LBSIZE - 1]) *p1++ = c; @@ -709,7 +711,7 @@ plist /* Attempt to decode as a MIME header. If it's the last header, body will be 1 and lf will be at least 1. */ - if ((body == 0 || lf > 0) && + if ((!body || lf) && decode_rfc2047 (linebuf, decoded_linebuf, sizeof decoded_linebuf)) { p1 = decoded_linebuf; } @@ -804,7 +806,7 @@ advance (char *alp, char *aep) do { lp--; if (advance ((char *) lp, (char *) ep)) - return (1); + return 1; } while (lp > curlp); return 0; @@ -823,14 +825,14 @@ cclass (unsigned char *aset, int ac, int af) set = aset; if ((c = ac) == 0) - return (0); + return 0; n = *set++; while (n--) if (*set++ == c || set[-1] == cc[c]) - return (af); + return af; - return (!af); + return !af; } @@ -842,7 +844,7 @@ tcompile (char *ap, struct tws *tb, int isafter) if ((tw = tws_parse (ap, isafter)) == NULL) return 0; - twscopy (tb, tw); + *tb = *tw; return 1; } @@ -929,27 +931,27 @@ tws_special (char *ap) static int -TWSaction (params) -plist +TWSaction(struct nexus *n, FILE *fp, int msgnum, long start, long stop) { int state; char *bp; - char buf[BUFSIZ], name[NAMESZ]; + char buf[NMH_BUFSIZ], name[NAMESZ]; struct tws *tw; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; NMH_UNUSED (stop); fseek (fp, start, SEEK_SET); + gstate = m_getfld_state_init(fp); for (bp = NULL;;) { int bufsz = sizeof buf; - switch (state = m_getfld (&gstate, name, buf, &bufsz, fp)) { + switch (state = m_getfld2(&gstate, name, buf, &bufsz)) { case FLD: case FLDPLUS: - mh_xfree(bp); + free(bp); bp = mh_xstrdup(buf); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, name, buf, &bufsz, fp); + state = m_getfld2(&gstate, name, buf, &bufsz); bp = add (buf, bp); } if (!strcasecmp (name, n->n_datef)) @@ -962,11 +964,11 @@ plist case FMTERR: if (state == LENERR || state == FMTERR) inform("format error in message %d", msgnum); - mh_xfree(bp); + free(bp); return 0; default: - adios (NULL, "internal error -- you lose"); + die("internal error -- you lose"); } break; } @@ -979,6 +981,6 @@ plist state = n->n_after ? (twsort (tw, &n->n_tws) > 0) : (twsort (tw, &n->n_tws) < 0); - mh_xfree(bp); + free(bp); return state; }