=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/out.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/mandoc/out.c 2009/10/21 19:13:51 1.1 --- src/usr.bin/mandoc/out.c 2009/10/27 21:40:07 1.2 *************** *** 1,4 **** ! /* $Id: out.c,v 1.1 2009/10/21 19:13:51 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: out.c,v 1.2 2009/10/27 21:40:07 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * *************** *** 16,28 **** */ #include #include #include #include #include "out.h" - /* * Convert a `scaling unit' to a consistent form, or fail. Scaling * units are documented in groff.7, mdoc.7, man.7. --- 16,30 ---- */ #include + #include #include #include #include + #include + #include #include "out.h" /* * Convert a `scaling unit' to a consistent form, or fail. Scaling * units are documented in groff.7, mdoc.7, man.7. *************** *** 117,119 **** --- 119,164 ---- 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); + } +