X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1691e80890e5d8ba258c51c214a3e91880e1db2b..bf58e45a34dcf8300098abff38c4e7393152f365:/uip/dp.c?ds=inline diff --git a/uip/dp.c b/uip/dp.c index 0041198a..dabdd74c 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -2,12 +2,14 @@ /* * dp.c -- parse dates 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 #include -#include +#include #define NDATES 100 @@ -16,29 +18,25 @@ #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", 4 }, - { 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; static int dat[5]; -/* - * prototypes - */ -int sc_width (void); /* from termsbr.c */ - /* * static prototypes */ @@ -53,13 +51,7 @@ main (int argc, char **argv) char buf[BUFSIZ], **argp, **arguments; char *dates[NDATES]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -77,10 +69,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 == '-') @@ -120,7 +112,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; @@ -132,7 +124,9 @@ main (int argc, char **argv) status += process (dates[datep], width); context_save (); /* save the context file */ + fmt_free (fmt, 1); done (status); + return 1; } @@ -143,10 +137,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;