summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2011-03-07 01:35:34 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2011-03-07 01:35:34 +0000
commite309b62a5156d70d03157abded5836eccaa56b7a (patch)
tree44a05144b8164f480fe009d9b9b7ed168d629e47 /usr.bin
parentc59e5e6dbdacdeef70d0b723a5087e77503d2ee0 (diff)
Clean up date handling,
as a first step to get rid of the frequent petty warnings in this area: - always store dates as strings, not as seconds since the Epoch - for input, try the three most common formats everywhere - for unrecognized format, just pass the date though verbatim - when there is no date at all, still use the current date Originally triggered by a one-line patch from Tim van der Molen, <tbvdm at xs4all dot nl>, which is included here. Feedback and OK on manual parts from jmc@. "please check this in" kristaps@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/libmandoc.h8
-rw-r--r--usr.bin/mandoc/main.c5
-rw-r--r--usr.bin/mandoc/man.c6
-rw-r--r--usr.bin/mandoc/man.h5
-rw-r--r--usr.bin/mandoc/man_html.c10
-rw-r--r--usr.bin/mandoc/man_term.c12
-rw-r--r--usr.bin/mandoc/man_validate.c35
-rw-r--r--usr.bin/mandoc/mandoc.c75
-rw-r--r--usr.bin/mandoc/mandoc.h5
-rw-r--r--usr.bin/mandoc/mdoc.c7
-rw-r--r--usr.bin/mandoc/mdoc.h4
-rw-r--r--usr.bin/mandoc/mdoc_html.c7
-rw-r--r--usr.bin/mandoc/mdoc_term.c16
-rw-r--r--usr.bin/mandoc/mdoc_validate.c29
-rw-r--r--usr.bin/mandoc/out.h4
15 files changed, 107 insertions, 121 deletions
diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h
index c066e6db9c3..8d74af567be 100644
--- a/usr.bin/mandoc/libmandoc.h
+++ b/usr.bin/mandoc/libmandoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmandoc.h,v 1.8 2011/01/03 22:27:21 schwarze Exp $ */
+/* $Id: libmandoc.h,v 1.9 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -25,11 +25,7 @@ char *mandoc_strdup(const char *);
void *mandoc_malloc(size_t);
void *mandoc_realloc(void *, size_t);
char *mandoc_getarg(char **, mandocmsg, void *, int, int *);
-time_t mandoc_a2time(int, const char *);
-#define MTIME_CANONICAL (1 << 0)
-#define MTIME_REDUCED (1 << 1)
-#define MTIME_MDOCDATE (1 << 2)
-#define MTIME_ISO_8601 (1 << 3)
+char *mandoc_normdate(char *, mandocmsg, void *, int, int);
int mandoc_eos(const char *, size_t, int);
int mandoc_hyph(const char *, const char *);
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 3f26a6ce6a9..7f1fdf08aa5 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.72 2011/02/06 17:33:20 schwarze Exp $ */
+/* $Id: main.c,v 1.73 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -113,7 +113,8 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"no title in document",
"document title should be all caps",
"unknown manual section",
- "cannot parse date argument",
+ "date missing, using today's date",
+ "cannot parse date, using it verbatim",
"prologue macros out of order",
"duplicate prologue macro",
"macro not allowed in prologue",
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index ece070e374c..9eba4001fee 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.55 2011/02/10 00:06:30 schwarze Exp $ */
+/* $Id: man.c,v 1.56 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -142,8 +142,8 @@ man_free1(struct man *man)
free(man->meta.title);
if (man->meta.source)
free(man->meta.source);
- if (man->meta.rawdate)
- free(man->meta.rawdate);
+ if (man->meta.date)
+ free(man->meta.date);
if (man->meta.vol)
free(man->meta.vol);
if (man->meta.msec)
diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h
index 4c8bd5e4fc2..0fdf892ea9b 100644
--- a/usr.bin/mandoc/man.h
+++ b/usr.bin/mandoc/man.h
@@ -1,4 +1,4 @@
-/* $Id: man.h,v 1.34 2011/01/16 02:56:47 schwarze Exp $ */
+/* $Id: man.h,v 1.35 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -75,8 +75,7 @@ enum man_type {
*/
struct man_meta {
char *msec; /* `TH' section (1, 3p, etc.) */
- time_t date; /* `TH' normalised date */
- char *rawdate; /* raw `TH' date */
+ char *date; /* `TH' normalised date */
char *vol; /* `TH' volume */
char *title; /* `TH' title (e.g., FOO) */
char *source; /* `TH' source (e.g., GNU) */
diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c
index 046e22af34d..41550ff5048 100644
--- a/usr.bin/mandoc/man_html.c
+++ b/usr.bin/mandoc/man_html.c
@@ -1,4 +1,4 @@
-/* $Id: man_html.c,v 1.34 2011/01/17 00:15:19 schwarze Exp $ */
+/* $Id: man_html.c,v 1.35 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -330,12 +330,6 @@ man_root_post(MAN_ARGS)
{
struct htmlpair tag[3];
struct tag *t, *tt;
- char b[DATESIZ];
-
- if (m->rawdate)
- strlcpy(b, m->rawdate, DATESIZ);
- else
- time2a(m->date, b, DATESIZ);
PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
PAIR_CLASS_INIT(&tag[1], "foot");
@@ -353,7 +347,7 @@ man_root_post(MAN_ARGS)
PAIR_CLASS_INIT(&tag[0], "foot-date");
print_otag(h, TAG_TD, 1, tag);
- print_text(h, b);
+ print_text(h, m->date);
print_stagq(h, tt);
PAIR_CLASS_INIT(&tag[0], "foot-os");
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index 6fb2154fb85..8e583015732 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.64 2011/01/25 12:35:07 schwarze Exp $ */
+/* $Id: man_term.c,v 1.65 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -939,24 +939,18 @@ print_man_nodelist(DECL_ARGS)
static void
print_man_foot(struct termp *p, const void *arg)
{
- char buf[DATESIZ];
const struct man_meta *meta;
meta = (const struct man_meta *)arg;
term_fontrepl(p, TERMFONT_NONE);
- if (meta->rawdate)
- strlcpy(buf, meta->rawdate, DATESIZ);
- else
- time2a(meta->date, buf, DATESIZ);
-
term_vspace(p);
term_vspace(p);
term_vspace(p);
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
- p->rmargin = p->maxrmargin - term_strlen(p, buf);
+ p->rmargin = p->maxrmargin - term_strlen(p, meta->date);
p->offset = 0;
/* term_strlen() can return zero. */
@@ -974,7 +968,7 @@ print_man_foot(struct termp *p, const void *arg)
p->rmargin = p->maxrmargin;
p->flags &= ~TERMP_NOBREAK;
- term_word(p, buf);
+ term_word(p, meta->date);
term_flushln(p);
}
diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c
index 3c1e91f809f..f6321084eb9 100644
--- a/usr.bin/mandoc/man_validate.c
+++ b/usr.bin/mandoc/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.40 2011/01/17 00:15:19 schwarze Exp $ */
+/* $Id: man_validate.c,v 1.41 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -187,8 +187,9 @@ check_root(CHKARGS)
*/
m->meta.title = mandoc_strdup("unknown");
- m->meta.date = time(NULL);
m->meta.msec = mandoc_strdup("1");
+ m->meta.date = mandoc_normdate(NULL,
+ m->msg, m->data, n->line, n->pos);
}
return(1);
@@ -370,6 +371,7 @@ static int
post_TH(CHKARGS)
{
const char *p;
+ int line, pos;
if (m->meta.title)
free(m->meta.title);
@@ -379,12 +381,13 @@ post_TH(CHKARGS)
free(m->meta.source);
if (m->meta.msec)
free(m->meta.msec);
- if (m->meta.rawdate)
- free(m->meta.rawdate);
+ if (m->meta.date)
+ free(m->meta.date);
- m->meta.title = m->meta.vol = m->meta.rawdate =
+ line = n->line;
+ pos = n->pos;
+ m->meta.title = m->meta.vol = m->meta.date =
m->meta.msec = m->meta.source = NULL;
- m->meta.date = 0;
/* ->TITLE<- MSEC DATE SOURCE VOL */
@@ -412,24 +415,12 @@ post_TH(CHKARGS)
/* TITLE MSEC ->DATE<- SOURCE VOL */
- /*
- * Try to parse the date. If this works, stash the epoch (this
- * is optimal because we can reformat it in the canonical form).
- * If it doesn't parse, isn't specified at all, or is an empty
- * string, then use the current date.
- */
-
if (n)
n = n->next;
- if (n && n->string && *n->string) {
- m->meta.date = mandoc_a2time
- (MTIME_ISO_8601, n->string);
- if (0 == m->meta.date) {
- man_nmsg(m, n, MANDOCERR_BADDATE);
- m->meta.rawdate = mandoc_strdup(n->string);
- }
- } else
- m->meta.date = time(NULL);
+ if (n)
+ pos = n->pos;
+ m->meta.date = mandoc_normdate(n ? n->string : NULL,
+ m->msg, m->data, line, pos);
/* TITLE MSEC DATE ->SOURCE<- VOL */
diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c
index 92bd1a3454b..d2d94366ade 100644
--- a/usr.bin/mandoc/mandoc.c
+++ b/usr.bin/mandoc/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.21 2011/01/03 22:27:21 schwarze Exp $ */
+/* $Id: mandoc.c,v 1.22 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -27,8 +27,10 @@
#include "mandoc.h"
#include "libmandoc.h"
-static int a2time(time_t *, const char *, const char *);
+#define DATESIZE 32
+static int a2time(time_t *, const char *, const char *);
+static char *time2a(time_t);
int
mandoc_special(char *p)
@@ -376,38 +378,55 @@ a2time(time_t *t, const char *fmt, const char *p)
}
-/*
- * 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)
+static char *
+time2a(time_t t)
{
- time_t t;
+ struct tm tm;
+ char buf[DATESIZE];
+ char *p;
+ size_t nsz, rsz;
+ int isz;
- if (MTIME_MDOCDATE & flags) {
- if (0 == strcmp(p, "$" "Mdocdate$"))
- return(time(NULL));
- if (a2time(&t, "$" "Mdocdate: %b %d %Y $", p))
- return(t);
- }
+ localtime_r(&t, &tm);
- if (MTIME_CANONICAL & flags || MTIME_REDUCED & flags)
- if (a2time(&t, "%b %d, %Y", p))
- return(t);
+ p = buf;
+ rsz = DATESIZE;
- if (MTIME_ISO_8601 & flags)
- if (a2time(&t, "%Y-%m-%d", p))
- return(t);
+ if (0 == (nsz = strftime(p, rsz, "%B ", &tm)))
+ return(NULL);
- if (MTIME_REDUCED & flags) {
- if (a2time(&t, "%d, %Y", p))
- return(t);
- if (a2time(&t, "%Y", p))
- return(t);
- }
+ p += (int)nsz;
+ rsz -= nsz;
- return(0);
+ if (-1 == (isz = snprintf(p, rsz, "%d, ", tm.tm_mday)))
+ return(NULL);
+
+ p += isz;
+ rsz -= isz;
+
+ return(strftime(p, rsz, "%Y", &tm) ? buf : NULL);
+}
+
+
+char *
+mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos)
+{
+ char *out;
+ time_t t;
+
+ if (NULL == in || '\0' == *in ||
+ 0 == strcmp(in, "$" "Mdocdate$")) {
+ (*msg)(MANDOCERR_NODATE, data, ln, pos, NULL);
+ time(&t);
+ }
+ else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&
+ !a2time(&t, "%b %d, %Y", in) &&
+ !a2time(&t, "%Y-%m-%d", in)) {
+ (*msg)(MANDOCERR_BADDATE, data, ln, pos, NULL);
+ t = 0;
+ }
+ out = t ? time2a(t) : NULL;
+ return(mandoc_strdup(out ? out : in));
}
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 32056ddaece..1c749031d66 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.33 2011/02/10 00:06:30 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.34 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -50,7 +50,8 @@ enum mandocerr {
MANDOCERR_NOTITLE, /* no title in document */
MANDOCERR_UPPERCASE, /* document title should be all caps */
MANDOCERR_BADMSEC, /* unknown manual section */
- MANDOCERR_BADDATE, /* cannot parse date argument */
+ MANDOCERR_NODATE, /* date missing, using today's date */
+ MANDOCERR_BADDATE, /* cannot parse date, using it verbatim */
MANDOCERR_PROLOGOOO, /* prologue macros out of order */
MANDOCERR_PROLOGREP, /* duplicate prologue macro */
MANDOCERR_BADPROLOG, /* macro not allowed in prologue */
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index a89d82a4bf5..79dffc42cb9 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.79 2011/02/10 00:06:30 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.80 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -314,8 +314,9 @@ mdoc_macro(MACRO_PROT_ARGS)
m->meta.vol = mandoc_strdup("LOCAL");
if (NULL == m->meta.os)
m->meta.os = mandoc_strdup("LOCAL");
- if (0 == m->meta.date)
- m->meta.date = time(NULL);
+ if (NULL == m->meta.date)
+ m->meta.date = mandoc_normdate(NULL,
+ m->msg, m->data, line, ppos);
m->flags |= MDOC_PBODY;
}
diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h
index f495fa0c16f..b442033e82e 100644
--- a/usr.bin/mandoc/mdoc.h
+++ b/usr.bin/mandoc/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.43 2011/01/30 17:41:59 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.44 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -231,7 +231,7 @@ struct mdoc_meta {
char *msec; /* `Dt' section (1, 3p, etc.) */
char *vol; /* `Dt' volume (implied) */
char *arch; /* `Dt' arch (i386, etc.) */
- time_t date; /* `Dd' normalised date */
+ char *date; /* `Dd' normalised date */
char *title; /* `Dt' title (FOO, etc.) */
char *os; /* `Os' system (OpenBSD, etc.) */
char *name; /* leading `Nm' name */
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index 05f636d3008..dbe71377153 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.52 2011/02/06 22:56:45 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.53 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -488,9 +488,6 @@ mdoc_root_post(MDOC_ARGS)
{
struct htmlpair tag[3];
struct tag *t, *tt;
- char b[DATESIZ];
-
- time2a(m->date, b, DATESIZ);
PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
PAIR_CLASS_INIT(&tag[1], "foot");
@@ -510,7 +507,7 @@ mdoc_root_post(MDOC_ARGS)
PAIR_CLASS_INIT(&tag[0], "foot-date");
print_otag(h, TAG_TD, 1, tag);
- print_text(h, b);
+ print_text(h, m->date);
print_stagq(h, tt);
PAIR_CLASS_INIT(&tag[0], "foot-os");
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 8eae39aa0a1..6a9da38df1e 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.129 2011/02/06 22:56:45 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.130 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -404,7 +404,6 @@ print_mdoc_node(DECL_ARGS)
static void
print_mdoc_foot(struct termp *p, const void *arg)
{
- char buf[DATESIZ], os[BUFSIZ];
const struct mdoc_meta *m;
m = (const struct mdoc_meta *)arg;
@@ -419,24 +418,21 @@ print_mdoc_foot(struct termp *p, const void *arg)
* SYSTEM DATE SYSTEM
*/
- time2a(m->date, buf, DATESIZ);
- strlcpy(os, m->os, BUFSIZ);
-
term_vspace(p);
p->offset = 0;
p->rmargin = (p->maxrmargin -
- term_strlen(p, buf) + term_len(p, 1)) / 2;
+ term_strlen(p, m->date) + term_len(p, 1)) / 2;
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
- term_word(p, os);
+ term_word(p, m->os);
term_flushln(p);
p->offset = p->rmargin;
- p->rmargin = p->maxrmargin - term_strlen(p, os);
+ p->rmargin = p->maxrmargin - term_strlen(p, m->os);
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
- term_word(p, buf);
+ term_word(p, m->date);
term_flushln(p);
p->offset = p->rmargin;
@@ -444,7 +440,7 @@ print_mdoc_foot(struct termp *p, const void *arg)
p->flags &= ~TERMP_NOBREAK;
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
- term_word(p, os);
+ term_word(p, m->os);
term_flushln(p);
p->offset = 0;
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 5f61829cb60..cabaef49858 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,6 +1,7 @@
-/* $Id: mdoc_validate.c,v 1.88 2011/02/06 17:33:21 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.89 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -135,7 +136,7 @@ static v_post posts_bx[] = { post_bx, NULL };
static v_post posts_bool[] = { ebool, NULL };
static v_post posts_eoln[] = { post_eoln, NULL };
static v_post posts_defaults[] = { post_defaults, NULL };
-static v_post posts_dd[] = { ewarn_ge1, post_dd, post_prol, NULL };
+static v_post posts_dd[] = { post_dd, post_prol, NULL };
static v_post posts_dl[] = { post_literal, bwarn_ge1, NULL };
static v_post posts_dt[] = { post_dt, post_prol, NULL };
static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
@@ -216,7 +217,7 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, posts_text }, /* Xr */
{ NULL, posts_text }, /* %A */
{ NULL, posts_text }, /* %B */ /* FIXME: can be used outside Rs/Re. */
- { NULL, posts_text }, /* %D */ /* FIXME: check date with mandoc_a2time(). */
+ { NULL, posts_text }, /* %D */
{ NULL, posts_text }, /* %I */
{ NULL, posts_text }, /* %J */
{ NULL, posts_text }, /* %N */
@@ -910,7 +911,7 @@ static int
pre_dt(PRE_ARGS)
{
- if (0 == mdoc->meta.date || mdoc->meta.os)
+ if (NULL == mdoc->meta.date || mdoc->meta.os)
mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO);
if (mdoc->meta.title)
@@ -923,7 +924,7 @@ static int
pre_os(PRE_ARGS)
{
- if (NULL == mdoc->meta.title || 0 == mdoc->meta.date)
+ if (NULL == mdoc->meta.title || NULL == mdoc->meta.date)
mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO);
if (mdoc->meta.os)
@@ -1962,23 +1963,21 @@ post_dd(POST_ARGS)
char buf[DATESIZE];
struct mdoc_node *n;
- n = mdoc->last;
+ if (mdoc->meta.date)
+ free(mdoc->meta.date);
- if (NULL == n->child) {
- mdoc->meta.date = time(NULL);
+ n = mdoc->last;
+ if (NULL == n->child || '\0' == n->child->string[0]) {
+ mdoc->meta.date = mandoc_normdate(NULL,
+ mdoc->msg, mdoc->data, n->line, n->pos);
return(1);
}
if ( ! concat(mdoc, buf, n->child, DATESIZE))
return(0);
- mdoc->meta.date = mandoc_a2time
- (MTIME_MDOCDATE | MTIME_CANONICAL, buf);
-
- if (0 == mdoc->meta.date) {
- mdoc_nmsg(mdoc, n, MANDOCERR_BADDATE);
- mdoc->meta.date = time(NULL);
- }
+ mdoc->meta.date = mandoc_normdate(buf,
+ mdoc->msg, mdoc->data, n->line, n->pos);
return(1);
}
diff --git a/usr.bin/mandoc/out.h b/usr.bin/mandoc/out.h
index de7021c7f37..ee7f422fa64 100644
--- a/usr.bin/mandoc/out.h
+++ b/usr.bin/mandoc/out.h
@@ -1,4 +1,4 @@
-/* $Id: out.h,v 1.8 2011/01/30 16:05:29 schwarze Exp $ */
+/* $Id: out.h,v 1.9 2011/03/07 01:35:33 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -17,8 +17,6 @@
#ifndef OUT_H
#define OUT_H
-#define DATESIZ 24
-
__BEGIN_DECLS
struct roffcol {