? apropos ? config.h ? config.log ? demandoc ? foo.1 ? foo.1.html ? mandoc ? mandoc.core ? mandocdb ? patch.txt ? preconv ? roff.bak.7 Index: libmandoc.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v retrieving revision 1.28 diff -u -p -r1.28 libmandoc.h --- libmandoc.h 28 Jul 2011 14:17:11 -0000 1.28 +++ libmandoc.h 3 Nov 2011 15:33:05 -0000 @@ -45,7 +45,6 @@ void mandoc_msg(enum mandocerr, struct void mandoc_vmsg(enum mandocerr, struct mparse *, int, int, const char *, ...); char *mandoc_getarg(struct mparse *, char **, int, int *); -char *mandoc_normdate(struct mparse *, char *, int, int); int mandoc_eos(const char *, size_t, int); int mandoc_getcontrol(const char *, int *); int mandoc_strntoi(const char *, size_t, int); Index: libmdoc.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmdoc.h,v retrieving revision 1.77 diff -u -p -r1.77 libmdoc.h --- libmdoc.h 18 Sep 2011 14:14:15 -0000 1.77 +++ libmdoc.h 3 Nov 2011 15:33:05 -0000 @@ -125,6 +125,7 @@ const char *mdoc_a2st(const char *); const char *mdoc_a2arch(const char *); const char *mdoc_a2vol(const char *); const char *mdoc_a2msec(const char *); +char *mdoc_normdate(struct mparse *, char *, int, int); int mdoc_valid_pre(struct mdoc *, struct mdoc_node *); int mdoc_valid_post(struct mdoc *); enum margverr mdoc_argv(struct mdoc *, int, enum mdoct, Index: man.7 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.7,v retrieving revision 1.111 diff -u -p -r1.111 man.7 --- man.7 26 Sep 2011 23:07:31 -0000 1.111 +++ man.7 3 Nov 2011 15:33:05 -0000 @@ -549,11 +549,7 @@ The recommended .Ar date format is .Sy YYYY-MM-DD -as specified in the ISO-8601 standard; -if the argument does not conform, it is printed verbatim. -If the -.Ar date -is empty or not specified, the current date is used. +as specified in the ISO-8601 standard. The optional .Ar source string specifies the organisation providing the utility. Index: man.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.h,v retrieving revision 1.59 diff -u -p -r1.59 man.h --- man.h 6 Oct 2011 22:29:12 -0000 1.59 +++ man.h 3 Nov 2011 15:33:05 -0000 @@ -68,7 +68,7 @@ enum man_type { struct man_meta { char *msec; /* `TH' section (1, 3p, etc.) */ - char *date; /* `TH' normalised date */ + char *date; /* `TH' free-form date */ char *vol; /* `TH' volume */ char *title; /* `TH' title (e.g., FOO) */ char *source; /* `TH' source (e.g., GNU) */ Index: man_validate.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_validate.c,v retrieving revision 1.76 diff -u -p -r1.76 man_validate.c --- man_validate.c 16 Oct 2011 12:20:34 -0000 1.76 +++ man_validate.c 3 Nov 2011 15:33:05 -0000 @@ -201,8 +201,7 @@ check_root(CHKARGS) m->meta.title = mandoc_strdup("unknown"); m->meta.msec = mandoc_strdup("1"); - m->meta.date = mandoc_normdate - (m->parse, NULL, n->line, n->pos); + m->meta.date = mandoc_strdup(""); } return(1); @@ -417,8 +416,8 @@ post_TH(CHKARGS) n = n->next; if (n) pos = n->pos; - m->meta.date = mandoc_normdate - (m->parse, n ? n->string : NULL, line, pos); + + m->meta.date = mandoc_strdup(n ? n->string : ""); /* TITLE MSEC DATE ->SOURCE<- VOL */ Index: mandoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.c,v retrieving revision 1.60 diff -u -p -r1.60 mandoc.c --- mandoc.c 24 Oct 2011 20:30:57 -0000 1.60 +++ mandoc.c 3 Nov 2011 15:33:06 -0000 @@ -33,10 +33,6 @@ #include "mandoc.h" #include "libmandoc.h" -#define DATESIZE 32 - -static int a2time(time_t *, const char *, const char *); -static char *time2a(time_t); static int numescape(const char *); /* @@ -548,82 +544,6 @@ mandoc_getarg(struct mparse *parse, char mandoc_msg(MANDOCERR_EOLNSPACE, parse, ln, *pos, NULL); return(start); -} - -static int -a2time(time_t *t, const char *fmt, const char *p) -{ - struct tm tm; - char *pp; - - memset(&tm, 0, sizeof(struct tm)); - - pp = NULL; -#ifdef HAVE_STRPTIME - pp = strptime(p, fmt, &tm); -#endif - if (NULL != pp && '\0' == *pp) { - *t = mktime(&tm); - return(1); - } - - return(0); -} - -static char * -time2a(time_t t) -{ - struct tm *tm; - char *buf, *p; - size_t ssz; - int isz; - - tm = localtime(&t); - - /* - * Reserve space: - * up to 9 characters for the month (September) + blank - * up to 2 characters for the day + comma + blank - * 4 characters for the year and a terminating '\0' - */ - p = buf = mandoc_malloc(10 + 4 + 4 + 1); - - if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm))) - goto fail; - p += (int)ssz; - - if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday))) - goto fail; - p += isz; - - if (0 == strftime(p, 4 + 1, "%Y", tm)) - goto fail; - return(buf); - -fail: - free(buf); - return(NULL); -} - -char * -mandoc_normdate(struct mparse *parse, char *in, int ln, int pos) -{ - char *out; - time_t t; - - if (NULL == in || '\0' == *in || - 0 == strcmp(in, "$" "Mdocdate$")) { - mandoc_msg(MANDOCERR_NODATE, parse, 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)) { - mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL); - t = 0; - } - out = t ? time2a(t) : NULL; - return(out ? out : mandoc_strdup(in)); } int Index: mdoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v retrieving revision 1.196 diff -u -p -r1.196 mdoc.c --- mdoc.c 30 Sep 2011 00:13:28 -0000 1.196 +++ mdoc.c 3 Nov 2011 15:33:06 -0000 @@ -102,6 +102,8 @@ static int mdoc_preptext(struct mdoc #endif static int mdoc_ptext(struct mdoc *, int, char *, int); static int mdoc_pmacro(struct mdoc *, int, char *, int); +static int a2time(time_t *, const char *, const char *); +static char *time2a(time_t); const struct mdoc_node * mdoc_node(const struct mdoc *m) @@ -333,7 +335,7 @@ mdoc_macro(MACRO_PROT_ARGS) if (NULL == m->meta.os) m->meta.os = mandoc_strdup("LOCAL"); if (NULL == m->meta.date) - m->meta.date = mandoc_normdate + m->meta.date = mdoc_normdate (m->parse, NULL, line, ppos); m->flags |= MDOC_PBODY; } @@ -985,3 +987,80 @@ mdoc_isdelim(const char *p) return(DELIM_NONE); } + +char * +mdoc_normdate(struct mparse *parse, char *in, int ln, int pos) +{ + char *out; + time_t t; + + if (NULL == in || '\0' == *in || + 0 == strcmp(in, "$" "Mdocdate$")) { + mandoc_msg(MANDOCERR_NODATE, parse, 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)) { + mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL); + t = 0; + } + out = t ? time2a(t) : NULL; + return(out ? out : mandoc_strdup(in)); +} + +static int +a2time(time_t *t, const char *fmt, const char *p) +{ + struct tm tm; + char *pp; + + memset(&tm, 0, sizeof(struct tm)); + + pp = NULL; +#ifdef HAVE_STRPTIME + pp = strptime(p, fmt, &tm); +#endif + if (NULL != pp && '\0' == *pp) { + *t = mktime(&tm); + return(1); + } + + return(0); +} + +static char * +time2a(time_t t) +{ + struct tm *tm; + char *buf, *p; + size_t ssz; + int isz; + + tm = localtime(&t); + + /* + * Reserve space: + * up to 9 characters for the month (September) + blank + * up to 2 characters for the day + comma + blank + * 4 characters for the year and a terminating '\0' + */ + p = buf = mandoc_malloc(10 + 4 + 4 + 1); + + if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm))) + goto fail; + p += (int)ssz; + + if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday))) + goto fail; + p += isz; + + if (0 == strftime(p, 4 + 1, "%Y", tm)) + goto fail; + return(buf); + +fail: + free(buf); + return(NULL); +} + Index: mdoc_validate.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v retrieving revision 1.177 diff -u -p -r1.177 mdoc_validate.c --- mdoc_validate.c 16 Oct 2011 12:20:34 -0000 1.177 +++ mdoc_validate.c 3 Nov 2011 15:33:06 -0000 @@ -1990,7 +1990,7 @@ post_dd(POST_ARGS) n = mdoc->last; if (NULL == n->child || '\0' == n->child->string[0]) { - mdoc->meta.date = mandoc_normdate + mdoc->meta.date = mdoc_normdate (mdoc->parse, NULL, n->line, n->pos); return(1); } @@ -2002,7 +2002,7 @@ post_dd(POST_ARGS) } assert(c); - mdoc->meta.date = mandoc_normdate + mdoc->meta.date = mdoc_normdate (mdoc->parse, buf, n->line, n->pos); return(1);