]> diplodocus.org Git - nmh/blobdiff - uip/mhlsbr.c
Add missing functions for manipulating component text.
[nmh] / uip / mhlsbr.c
index 8cd5c34a8d266f9f0b5c0e1af65b6a6a617b98af..6e0f90d4e4d2aa02b645010fa1b7f23ac8a10fac 100644 (file)
@@ -1108,17 +1108,17 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
     dat[2] = filesize;
     dat[3] = sizeof(buffer) - 1;
     dat[4] = 0;
-    fmt_compile (c1->c_nfs, &c1->c_fmt);
+    fmt_compile (c1->c_nfs, &c1->c_fmt, 1);
 
     if (!(c1->c_flags & ADDRFMT)) {
-       FINDCOMP (cptr, "text");
+       cptr = fmt_findcomp ("text");
        if (cptr)
-           cptr->c_text = ap;
+           cptr->c_text = getcpy (ap);
        if ((cp = strrchr(ap, '\n')))   /* drop ending newline */
            if (!cp[1])
                *cp = 0;
 
-       fmt_scan (c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
+       fmt_scan (c1->c_fmt, buffer, sizeof buffer - 1, sizeof buffer - 1, dat);
        /* Don't need to append a newline, dctime() already did */
        c2->c_text = getcpy (buffer);
 
@@ -1142,14 +1142,18 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
     }
 
     for (p = pq.pq_next; p; p = q) {
-       FINDCOMP (cptr, "text");
-       if (cptr)
+       cptr = fmt_findcomp ("text");
+       if (cptr) {
            cptr->c_text = p->pq_text;
-       FINDCOMP (cptr, "error");
-       if (cptr)
+           p->pq_text = NULL;
+       }
+       cptr = fmt_findcomp ("error");
+       if (cptr) {
            cptr->c_text = p->pq_error;
+           p->pq_error = NULL;
+       }
 
-       fmt_scan (c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
+       fmt_scan (c1->c_fmt, buffer, sizeof buffer - 1, sizeof buffer - 1, dat);
        if (*buffer) {
            if (c2->c_text)
                c2->c_text = add (",\n", c2->c_text);
@@ -1158,7 +1162,8 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2)
            c2->c_text = add (buffer, c2->c_text);
        }
 
-       free (p->pq_text);
+       if (p->pq_text)
+           free (p->pq_text);
        if (p->pq_error)
            free (p->pq_error);
        q = p->pq_next;
@@ -1217,7 +1222,7 @@ free_queue (struct mcomp **head, struct mcomp **tail)
        if (c1->c_nfs)
            free (c1->c_nfs);
        if (c1->c_fmt)
-           free ((char *) c1->c_fmt);
+           fmt_free (c1->c_fmt, 1);
        if (c1->c_f_args) {
            struct arglist *a1, *a2;
            for (a1 = c1->c_f_args; a1; a1 = a2) {
@@ -1684,7 +1689,7 @@ compileargs (struct mcomp *c1, char *nfs)
     struct comp *cptr;
     unsigned int i;
 
-    i = fmt_compile(nfs, &fmt);
+    i = fmt_compile(nfs, &fmt);
 
     /*
      * Search through and mark any components that are address components
@@ -1945,7 +1950,7 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, FILE *fp)
 
        for (a = c1->c_f_args, i = 1; a != NULL; a = a->a_next, i++) {
            args[i] = mh_xmalloc(BUFSIZ);
-           fmt_scan(a->a_fmt, args[i], BUFSIZ, dat);
+           fmt_scan(a->a_fmt, args[i], BUFSIZ - 1, BUFSIZ, dat);
            /*
             * fmt_scan likes to put a trailing newline at the end of the
             * format string.  If we have one, get rid of it.