X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/df6971a59e8d01dcfe605bbac949b7d4b3ab0a92..fbcd71b31868c9969836b00a90a0bf32b13111ef:/uip/dp.c?ds=inline diff --git a/uip/dp.c b/uip/dp.c index 4e9c5cb8..67eef061 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -18,19 +18,20 @@ #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>" -static struct swit switches[] = { -#define FORMSW 0 - { "form formatfile", 0 }, -#define FMTSW 1 - { "format string", 5 }, -#define WIDTHSW 2 - { "width columns", 0 }, -#define VERSIONSW 3 - { "version", 0 }, -#define HELPSW 4 - { "help", 0 }, - { NULL, 0 } -}; +#define DP_SWITCHES \ + X("form formatfile", 0, FORMSW) \ + X("format string", 5, FMTSW) \ + X("width columns", 0, WIDTHSW) \ + X("version", 0, VERSIONSW) \ + X("help", 0, HELPSW) \ + +#define X(sw, minchars, id) id, +DEFINE_SWITCH_ENUM(DP); +#undef X + +#define X(sw, minchars, id) { sw, minchars, id }, +DEFINE_SWITCH_ARRAY(DP, switches); +#undef X static struct format *fmt; @@ -74,10 +75,10 @@ main (int argc, char **argv) snprintf (buf, sizeof(buf), "%s [switches] dates ...", 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 == '-') @@ -117,7 +118,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 +130,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,10 +143,13 @@ process (char *date, int length) char buffer[WBUFSIZ + 1]; register struct comp *cptr; - FINDCOMP (cptr, "text"); - if (cptr) - cptr->c_text = date; - fmt_scan (fmt, buffer, length, dat); + 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, NULL); fputs (buffer, stdout); return status;