diff options
-rw-r--r-- | man_html.c | 10 | ||||
-rw-r--r-- | man_term.c | 10 | ||||
-rw-r--r-- | mdoc_html.c | 12 | ||||
-rw-r--r-- | mdoc_term.c | 14 | ||||
-rw-r--r-- | out.c | 47 | ||||
-rw-r--r-- | out.h | 5 |
6 files changed, 64 insertions, 34 deletions
@@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.11 2009/10/18 19:03:36 kristaps Exp $ */ +/* $Id: man_html.c,v 1.12 2009/10/22 18:55:32 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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%"); @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.42 2009/10/21 03:31:49 kristaps Exp $ */ +/* $Id: man_term.c,v 1.43 2009/10/22 18:55:32 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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 69623baf..74d06cff 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.35 2009/10/20 05:45:21 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.36 2009/10/22 18:55:32 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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 ad4e0640..d427c1d0 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.93 2009/10/19 15:18:30 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.94 2009/10/22 18:55:32 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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); } @@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.5 2009/10/18 19:02:10 kristaps Exp $ */ +/* $Id: out.c,v 1.6 2009/10/22 18:55:32 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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); +} + @@ -1,4 +1,4 @@ -/* $Id: out.h,v 1.5 2009/10/18 19:02:11 kristaps Exp $ */ +/* $Id: out.h,v 1.6 2009/10/22 18:55:33 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -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 |