From 8689371fa9a194c15c79be8933c6af01faf7be64 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 23 Dec 2009 22:30:18 +0000 Subject: sync to 1.9.13: minor fixes: correctness/functionality: - bugfix: properly ignore lines with only a dot in -man - bugfix: .Bl -ohang doesn't allow -width, warn about this - improve date string handling by new function mandoc_a2time - some HTML improvements - significant documentation additions in man.7 and mdoc.7 portability: - replace __dead by __attribute__((noreturn)) - bugfix: correct .Dx rendering - some more library names for NetBSD simplicity: - replace hand-rolled putchar(3)-loops by fwrite(3) - replace single-character printf(3) by putchar(3) --- usr.bin/mandoc/mandoc.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'usr.bin/mandoc/mandoc.c') diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index 5d2b2a2c890..3e0b0f549fd 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.4 2009/12/22 23:58:00 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.5 2009/12/23 22:30:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -21,9 +21,13 @@ #include #include #include +#include #include "libmandoc.h" +static int a2time(time_t *, const char *, const char *); + + int mandoc_special(const char *p) { @@ -163,3 +167,57 @@ mandoc_strdup(const char *ptr) return(p); } + + +static int +a2time(time_t *t, const char *fmt, const char *p) +{ + struct tm tm; + char *pp; + + memset(&tm, 0, sizeof(struct tm)); + + pp = strptime(p, fmt, &tm); + if (NULL != pp && '\0' == *pp) { + *t = mktime(&tm); + return(1); + } + + return(0); +} + + +/* + * Convert from a manual date string (see mdoc(7) and man(7)) into a + * date according to the stipulated date type. + */ +time_t +mandoc_a2time(int flags, const char *p) +{ + time_t t; + + if (MTIME_MDOCDATE & flags) { + if (0 == strcmp(p, "$" "Mdocdate$")) + return(time(NULL)); + if (a2time(&t, "$" "Mdocdate: %b %d %Y $", p)) + return(t); + } + + if (MTIME_CANONICAL & flags || MTIME_REDUCED & flags) + if (a2time(&t, "%b %d, %Y", p)) + return(t); + + if (MTIME_ISO_8601 & flags) + if (a2time(&t, "%Y-%m-%d", p)) + return(t); + + if (MTIME_REDUCED & flags) { + if (a2time(&t, "%d, %Y", p)) + return(t); + if (a2time(&t, "%Y", p)) + return(t); + } + + return(0); +} + -- cgit v1.2.3