X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fap.c;h=80ce8a3fa43ac7087c2d18971979e48fc8fa13bb;hb=cc5e28c08443d3bb105034d1c00520d0c0f4b5b3;hp=843ece4e973808271eb90fd61064815e3cd27c41;hpb=dee387b53ab0d42922f857b60d6f980c9e79d16f;p=mmh diff --git a/uip/ap.c b/uip/ap.c index 843ece4..80ce8a3 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -2,7 +2,9 @@ /* * ap.c -- parse addresses 822-style * - * $Id$ + * 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 @@ -40,11 +42,6 @@ static struct format *fmt; static int dat[5]; /* - * prototypes - */ -int sc_width (void); /* from termsbr.c */ - -/* * static prototypes */ static int process (char *, int, int); @@ -85,10 +82,10 @@ main (int argc, char **argv) snprintf (buf, sizeof(buf), "%s [switches] addrs ...", invo_name); print_help (buf, switches, 1); - done (1); + done (0); case VERSIONSW: print_version (invo_name); - done (1); + done (0); case FORMSW: if (!(form = *argp++) || *form == '-') @@ -136,7 +133,7 @@ main (int argc, char **argv) if (width > WBUFSIZ) width = WBUFSIZ; fmt_norm = normalize; - fmt_compile (nfs, &fmt); + fmt_compile (nfs, &fmt, 1); dat[0] = 0; dat[1] = 0; @@ -147,7 +144,9 @@ main (int argc, char **argv) for (addrp = 0; addrs[addrp]; addrp++) status += process (addrs[addrp], width, normalize); - return done (status); + fmt_free (fmt, 1); + done (status); + return 1; } struct pqpair { @@ -185,17 +184,26 @@ process (char *arg, int length, int norm) } for (p = pq.pq_next; p; p = q) { - FINDCOMP (cptr, "text"); - if (cptr) + cptr = fmt_findcomp ("text"); + if (cptr) { + if (cptr->c_text) + free(cptr->c_text); cptr->c_text = p->pq_text; - FINDCOMP (cptr, "error"); - if (cptr) + p->pq_text = NULL; + } + cptr = fmt_findcomp ("error"); + if (cptr) { + if (cptr->c_text) + free(cptr->c_text); cptr->c_text = p->pq_error; + p->pq_error = NULL; + } - fmt_scan (fmt, buffer, length, dat); + fmt_scan (fmt, buffer, sizeof buffer - 1, length, dat); fputs (buffer, stdout); - free (p->pq_text); + if (p->pq_text) + free (p->pq_text); if (p->pq_error) free (p->pq_error); q = p->pq_next;