+ return(1);
+ }
+
+ return(mdoc_err(mdoc, "macro parameters too long"));
+}
+
+
+static int
+post_dt(struct mdoc *mdoc)
+{
+ int i;
+ char *p;
+ struct mdoc_node *n;
+
+ assert(MDOC_ELEM == mdoc->last->type);
+ assert(MDOC_Dt == mdoc->last->tok);
+
+ assert(NULL == mdoc->meta.title);
+
+ for (i = 0, n = mdoc->last->child; n; n = n->next, i++) {
+ assert(MDOC_TEXT == n->type);
+ p = n->data.text.string;
+
+ switch (i) {
+ case (0):
+ mdoc->meta.title = xstrdup(p);
+ break;
+ case (1):
+ mdoc->meta.msec = mdoc_atomsec(p);
+ if (MSEC_DEFAULT != mdoc->meta.msec)
+ break;
+ return(mdoc_nerr(mdoc, n, "invalid parameter syntax"));
+ case (2):
+ mdoc->meta.vol = mdoc_atovol(p);
+ if (VOL_DEFAULT != mdoc->meta.vol)
+ break;
+ mdoc->meta.arch = mdoc_atoarch(p);
+ if (ARCH_DEFAULT != mdoc->meta.arch)
+ break;
+ return(mdoc_nerr(mdoc, n, "invalid parameter syntax"));
+ default:
+ return(mdoc_nerr(mdoc, n, "too many parameters"));
+ }
+ }
+
+ if (NULL == mdoc->meta.title)
+ mdoc->meta.title = xstrdup("untitled");
+ return(1);
+}
+
+
+static int
+post_os(struct mdoc *mdoc)
+{
+ char buf[64];
+
+ assert(MDOC_ELEM == mdoc->last->type);
+ assert(MDOC_Os == mdoc->last->tok);
+ assert(NULL == mdoc->meta.os);
+
+ if ( ! xstrlcats(buf, mdoc->last->child, 64))
+ return(mdoc_err(mdoc, "macro parameters too long"));
+
+ mdoc->meta.os = xstrdup(buf[0] ? buf : "local");
+ mdoc->sec_lastn = mdoc->sec_last = SEC_BODY;
+ return(1);
+}
+
+
+static int
+post_dd(struct mdoc *mdoc)
+{
+ char date[64];
+ size_t sz;
+ char *p;
+ struct mdoc_node *n;
+
+ assert(MDOC_ELEM == mdoc->last->type);
+ assert(MDOC_Dd == mdoc->last->tok);
+
+ n = mdoc->last->child;
+ assert(0 == mdoc->meta.date);
+ date[0] = 0;
+
+ sz = 64;
+
+ for ( ; 0 == mdoc->meta.date && n; n = n->next) {
+ assert(MDOC_TEXT == n->type);
+ p = n->data.text.string;
+
+ if (xstrcmp(p, "$Mdocdate: January 19 2009 $")) {
+ mdoc->meta.date = time(NULL);
+ continue;
+ } else if (xstrcmp(p, "$")) {
+ mdoc->meta.date = mdoc_atotime(date);
+ continue;
+ } else if (xstrcmp(p, "$Mdocdate:"))
+ continue;
+
+ if ( ! xstrlcat(date, n->data.text.string, sz))
+ return(mdoc_nerr(mdoc, n, "invalid parameter syntax"));
+ if (n->next && ! xstrlcat(date, " ", sz))
+ return(mdoc_nerr(mdoc, n, "invalid parameter syntax"));