diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-10-22 18:55:32 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-10-22 18:55:32 +0000 |
commit | f26f75bb32fa1474ee83fcff787b6423c44189cf (patch) | |
tree | 44c7e29c549509bc9e5fd633afed4b360a966dbd | |
parent | ee228d79036122b2d0284854cd2e94526fd838b9 (diff) | |
download | mandoc-f26f75bb32fa1474ee83fcff787b6423c44189cf.tar.gz |
Fixed maddening mismatch between groff and strftime mismatch of day ("%e"). Noted by Ulrich Sporlein.
-rw-r--r-- | man_html.c | 8 | ||||
-rw-r--r-- | man_term.c | 8 | ||||
-rw-r--r-- | mdoc_html.c | 10 | ||||
-rw-r--r-- | mdoc_term.c | 12 | ||||
-rw-r--r-- | out.c | 45 | ||||
-rw-r--r-- | out.h | 3 |
6 files changed, 58 insertions, 28 deletions
@@ -281,15 +281,11 @@ man_root_pre(MAN_ARGS) static void man_root_post(MAN_ARGS) { - struct tm tm; struct htmlpair tag[2]; struct tag *t, *tt; - char b[BUFSIZ]; + char b[DATESIZ]; - (void)localtime_r(&m->date, &tm); - - if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm)) - err(EXIT_FAILURE, "strftime"); + time2a(m->date, b, DATESIZ); PAIR_CLASS_INIT(&tag[0], "footer"); bufcat_style(h, "width", "100%"); @@ -909,13 +909,9 @@ print_body(DECL_ARGS) static void print_foot(struct termp *p, const struct man_meta *meta) { - struct tm *tm; - char buf[BUFSIZ]; + char buf[DATESIZ]; - tm = localtime(&meta->date); - - if (0 == strftime(buf, p->rmargin, "%B %e, %Y", tm)) - (void)strlcpy(buf, "(invalid date)", BUFSIZ); + time2a(meta->date, buf, DATESIZ); term_vspace(p); diff --git a/mdoc_html.c b/mdoc_html.c index dc7b1200..d0c2ff7c 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -456,10 +456,11 @@ print_mdoc_node(MDOC_ARGS) static void mdoc_root_post(MDOC_ARGS) { - struct tm tm; struct htmlpair tag[2]; struct tag *t, *tt; - char b[BUFSIZ]; + char b[DATESIZ]; + + time2a(m->date, b, DATESIZ); /* * XXX: this should use divs, but in Firefox, divs with nested @@ -467,11 +468,6 @@ mdoc_root_post(MDOC_ARGS) * below. So I use tables, instead. */ - (void)localtime_r(&m->date, &tm); - - if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm)) - err(EXIT_FAILURE, "strftime"); - PAIR_CLASS_INIT(&tag[0], "footer"); bufcat_style(h, "width", "100%"); PAIR_STYLE_INIT(&tag[1], h); diff --git a/mdoc_term.c b/mdoc_term.c index 789d3454..c59c42b6 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -347,8 +347,8 @@ print_node(DECL_ARGS) static void print_foot(DECL_ARGS) { - struct tm *tm; - char *buf, *os; + char buf[DATESIZ]; + char *os; /* * Output the footer in new-groff style, that is, three columns @@ -358,15 +358,10 @@ print_foot(DECL_ARGS) * SYSTEM DATE SYSTEM */ - if (NULL == (buf = malloc(p->rmargin))) - err(EXIT_FAILURE, "malloc"); if (NULL == (os = malloc(p->rmargin))) err(EXIT_FAILURE, "malloc"); - tm = localtime(&m->date); - - if (0 == strftime(buf, p->rmargin, "%B %e, %Y", tm)) - err(EXIT_FAILURE, "strftime"); + time2a(m->date, buf, DATESIZ); (void)strlcpy(os, m->os, p->rmargin); @@ -398,7 +393,6 @@ print_foot(DECL_ARGS) p->rmargin = p->maxrmargin; p->flags = 0; - free(buf); free(os); } @@ -16,9 +16,11 @@ */ #include <sys/types.h> +#include <assert.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "out.h" @@ -117,3 +119,46 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) return(1); } + + +/* + * Correctly writes the time in nroff form, which differs from standard + * form in that a space isn't printed in lieu of the extra %e field for + * single-digit dates. + */ +void +time2a(time_t t, char *dst, size_t sz) +{ + struct tm tm; + char buf[5]; + char *p; + size_t nsz; + + assert(sz > 1); + localtime_r(&t, &tm); + + p = dst; + nsz = 0; + + dst[0] = '\0'; + + if (0 == (nsz = strftime(p, sz, "%B ", &tm))) + return; + + p += (int)nsz; + sz -= nsz; + + if (0 == strftime(buf, sizeof(buf), "%e, ", &tm)) + return; + + nsz = strlcat(p, buf + (' ' == buf[0] ? 1 : 0), sz); + + if (nsz >= sz) + return; + + p += (int)nsz; + sz -= nsz; + + (void)strftime(p, sz, "%Y", &tm); +} + @@ -17,6 +17,8 @@ #ifndef OUT_H #define OUT_H +#define DATESIZ 24 + __BEGIN_DECLS enum roffscale { @@ -52,6 +54,7 @@ struct roffsu { int a2roffsu(const char *, struct roffsu *, enum roffscale); +void time2a(time_t, char *, size_t); __END_DECLS |