From b7345052cafdcd4bef23b1a1822675bc5659accf Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Thu, 15 Nov 2012 15:53:24 -0500 Subject: [PATCH] Beginnings of conversion of code to new format interface. --- uip/ap.c | 22 ++++++++++++++++------ uip/dp.c | 12 ++++++++---- uip/fmtdump.c | 5 ++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/uip/ap.c b/uip/ap.c index fdb47e2..80ce8a3 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -133,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; @@ -144,6 +144,7 @@ main (int argc, char **argv) for (addrp = 0; addrs[addrp]; addrp++) status += process (addrs[addrp], width, normalize); + fmt_free (fmt, 1); done (status); return 1; } @@ -183,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, 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; diff --git a/uip/dp.c b/uip/dp.c index 95a7163..b915845 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -117,7 +117,7 @@ main (int argc, char **argv) } if (width > WBUFSIZ) width = WBUFSIZ; - fmt_compile (nfs, &fmt); + fmt_compile (nfs, &fmt, 1); dat[0] = 0; dat[1] = 0; @@ -129,6 +129,7 @@ main (int argc, char **argv) status += process (dates[datep], width); context_save (); /* save the context file */ + fmt_free (fmt, 1); done (status); return 1; } @@ -141,9 +142,12 @@ process (char *date, int length) char buffer[WBUFSIZ + 1]; register struct comp *cptr; - FINDCOMP (cptr, "text"); - if (cptr) - cptr->c_text = date; + cptr = fmt_findcomp ("text"); + if (cptr) { + if (cptr->c_text) + free(cptr->c_text); + cptr->c_text = getcpy(date); + } fmt_scan (fmt, buffer, sizeof buffer - 1, length, dat); fputs (buffer, stdout); diff --git a/uip/fmtdump.c b/uip/fmtdump.c index d69fb8c..eb5608e 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -100,9 +100,12 @@ main (int argc, char **argv) * Get new format string. Must be before chdir(). */ nfs = new_fs (form, format, FORMAT); - (void) fmt_compile(nfs, &fmt); + (void) fmt_compile(nfs, &fmt, 1); fmt_dump(fmt); + + fmt_free(fmt); + done(0); return 1; } -- 1.7.10.4