X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/9cf9f118998a7635485e13863d1bc16c1486bb05..bf982b40ca8495e7a8d14513aedcc2fe15f09a93:/uip/dp.c diff --git a/uip/dp.c b/uip/dp.c index 8245f60a..cf8f9b14 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -14,7 +14,6 @@ #define NDATES 100 #define WIDTH 78 -#define WBUFSIZ BUFSIZ #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>" @@ -46,16 +45,12 @@ static int process (char *, int); int main (int argc, char **argv) { - int datep = 0, width = 0, status = 0; + int datep = 0, width = -1, status = 0; char *cp, *form = NULL, *format = NULL, *nfs; char buf[BUFSIZ], **argp, **arguments; char *dates[NDATES]; - setlocale(LC_ALL, ""); - 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; @@ -109,13 +104,16 @@ main (int argc, char **argv) /* get new format string */ nfs = new_fs (form, format, FORMAT); - if (width == 0) { - if ((width = sc_width ()) < WIDTH / 2) + if (width == -1) { + if ((width = sc_width ()) < WIDTH / 2) { + /* Default: width of the terminal, but at least WIDTH/2. */ width = WIDTH / 2; + } width -= 2; + } else if (width == 0) { + /* Unlimited width. */ + width = INT_MAX; } - if (width > WBUFSIZ) - width = WBUFSIZ; fmt_compile (nfs, &fmt, 1); dat[0] = 0; @@ -138,7 +136,8 @@ static int process (char *date, int length) { int status = 0; - char buffer[WBUFSIZ + 1]; + charstring_t scanl = + charstring_create (length < NMH_BUFSIZ ? length : NMH_BUFSIZ); register struct comp *cptr; cptr = fmt_findcomp ("text"); @@ -147,8 +146,9 @@ process (char *date, int length) free(cptr->c_text); cptr->c_text = getcpy(date); } - fmt_scan (fmt, buffer, sizeof buffer - 1, length, dat, NULL); - fputs (buffer, stdout); + fmt_scan (fmt, scanl, length, dat, NULL); + fputs (charstring_buffer (scanl), stdout); + charstring_free (scanl); return status; }