aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/out.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-10-22 18:55:32 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-10-22 18:55:32 +0000
commitcd3461ed2decce6e980d3a4c93c615bd8f4cb5c0 (patch)
treed62af90d1db9db8f0dd241d06a9e221234572467 /out.c
parent97e702f1687ec3975b215d6ea566bf1d6aca30a8 (diff)
downloadmandoc-cd3461ed2decce6e980d3a4c93c615bd8f4cb5c0.tar.gz
mandoc-cd3461ed2decce6e980d3a4c93c615bd8f4cb5c0.tar.zst
mandoc-cd3461ed2decce6e980d3a4c93c615bd8f4cb5c0.zip
Fixed maddening mismatch between groff and strftime mismatch of day ("%e"). Noted by Ulrich Sporlein.
Diffstat (limited to 'out.c')
-rw-r--r--out.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/out.c b/out.c
index 73689b39..78abc5dc 100644
--- a/out.c
+++ b/out.c
@@ -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);
+}
+