]> diplodocus.org Git - nmh/blobdiff - uip/picksbr.c
Dynamically allocate space for the output of fmt_scan(), using
[nmh] / uip / picksbr.c
index 7b64f819c0994df2d1da55a1a8b1b3462c8f82bb..74834f4eaa8ae5700f34e093dc59f1fc1c431fe5 100644 (file)
@@ -157,7 +157,6 @@ struct nexus {
 #define        n_tws    un.st3.un_tws
 
 static int talked;
-static int pdebug = 0;
 
 static char *datesw;
 static char **argp;
@@ -195,11 +194,6 @@ static int TWSaction();
 int
 pcompile (char **vec, char *date)
 {
-    register char *cp;
-
-    if ((cp = getenv ("MHPDEBUG")) && *cp)
-       pdebug++;
-
     argp = vec;
     if ((datesw = date) == NULL)
        datesw = "date";
@@ -474,12 +468,12 @@ newnexus (int (*action)())
                    stop;
 
 int
-pmatches (FILE *fp, int msgnum, long start, long stop)
+pmatches (FILE *fp, int msgnum, long start, long stop, int debug)
 {
     if (!head)
        return 1;
 
-    if (!talked++ && pdebug)
+    if (!talked++ && debug)
        PRaction (head, 0);
 
     return (*head->n_action) (args (head));
@@ -562,8 +556,8 @@ gcompile (struct nexus *n, char *astr)
     int cclcnt;
     register unsigned char *ep, *dp, *sp, *lastep = 0;
 
-    dp = (ep = n->n_expbuf) + sizeof n->n_expbuf;
-    sp = astr;
+    dp = (ep = (unsigned char *) n->n_expbuf) + sizeof n->n_expbuf;
+    sp = (unsigned char *) astr;
     if (*sp == '^') {
        n->n_circf = 1;
        sp++;
@@ -802,7 +796,7 @@ advance (char *alp, char *aep)
        star: 
                do {
                    lp--;
-                   if (advance (lp, ep))
+                   if (advance ((char *) lp, (char *) ep))
                        return (1);
                } while (lp > curlp);
                return 0;
@@ -895,19 +889,19 @@ tws_special (char *ap)
     register struct tws *tw;
 
     time (&clock);
-    if (!mh_strcasecmp (ap, "today"))
+    if (!strcasecmp (ap, "today"))
        return dlocaltime (&clock);
-    if (!mh_strcasecmp (ap, "yesterday")) {
+    if (!strcasecmp (ap, "yesterday")) {
        clock -= (long) (60 * 60 * 24);
        return dlocaltime (&clock);
     }
-    if (!mh_strcasecmp (ap, "tomorrow")) {
+    if (!strcasecmp (ap, "tomorrow")) {
        clock += (long) (60 * 60 * 24);
        return dlocaltime (&clock);
     }
 
     for (i = 0; tw_ldotw[i]; i++)
-       if (!mh_strcasecmp (ap, tw_ldotw[i]))
+       if (!strcasecmp (ap, tw_ldotw[i]))
            break;
     if (tw_ldotw[i]) {
        if ((tw = dlocaltime (&clock)) == NULL)
@@ -934,28 +928,28 @@ plist
     register char *bp;
     char buf[BUFSIZ], name[NAMESZ];
     register struct tws *tw;
+    m_getfld_state_t gstate = 0;
     NMH_UNUSED (stop);
 
     fseek (fp, start, SEEK_SET);
-    for (state = FLD, bp = NULL;;) {
-       switch (state = m_getfld (state, name, buf, sizeof buf, fp)) {
+    for (bp = NULL;;) {
+       int bufsz = sizeof buf;
+       switch (state = m_getfld (&gstate, name, buf, &bufsz, fp)) {
            case FLD: 
-           case FLDEOF: 
            case FLDPLUS: 
                if (bp != NULL)
                    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 (&gstate, name, buf, &bufsz, fp);
                    bp = add (buf, bp);
                }
-               if (!mh_strcasecmp (name, n->n_datef))
+               if (!strcasecmp (name, n->n_datef))
                    break;
-               if (state != FLDEOF)
-                   continue;
+               continue;
 
            case BODY: 
-           case BODYEOF: 
            case FILEEOF: 
            case LENERR: 
            case FMTERR: 
@@ -970,6 +964,7 @@ plist
        }
        break;
     }
+    m_getfld_state_destroy (&gstate);
 
     if ((tw = dparsetime (bp)) == NULL)
        advise (NULL, "unable to parse %s field in message %d, matching...",