=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.154 retrieving revision 1.160 diff -u -p -r1.154 -r1.160 --- mandoc/mdoc_validate.c 2011/01/25 15:46:05 1.154 +++ mandoc/mdoc_validate.c 2011/03/17 09:22:39 1.160 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.154 2011/01/25 15:46:05 kristaps Exp $ */ +/* $Id: mdoc_validate.c,v 1.160 2011/03/17 09:22:39 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -74,6 +74,7 @@ static void check_args(struct mdoc *, struct mdoc_nod static int concat(struct mdoc *, char *, const struct mdoc_node *, size_t); +static enum mdoc_sec a2sec(const char *); static int ebool(POST_ARGS); static int berr_ge1(POST_ARGS); @@ -104,6 +105,7 @@ static int post_eoln(POST_ARGS); static int post_it(POST_ARGS); static int post_lb(POST_ARGS); static int post_nm(POST_ARGS); +static int post_ns(POST_ARGS); static int post_os(POST_ARGS); static int post_ignpar(POST_ARGS); static int post_prol(POST_ARGS); @@ -139,7 +141,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 }; @@ -148,6 +150,7 @@ static v_post posts_lb[] = { post_lb, NULL }; static v_post posts_nd[] = { berr_ge1, NULL }; static v_post posts_nm[] = { post_nm, NULL }; static v_post posts_notext[] = { ewarn_eq0, NULL }; +static v_post posts_ns[] = { post_ns, NULL }; static v_post posts_os[] = { post_os, post_prol, NULL }; static v_post posts_rs[] = { post_rs, NULL }; static v_post posts_sh[] = { post_ignpar, hwarn_ge1, bwarn_ge1, post_sh, NULL }; @@ -219,7 +222,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 */ @@ -249,7 +252,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Fx */ { NULL, NULL }, /* Ms */ { NULL, posts_notext }, /* No */ - { NULL, posts_notext }, /* Ns */ + { NULL, posts_ns }, /* Ns */ { NULL, NULL }, /* Nx */ { NULL, NULL }, /* Ox */ { NULL, NULL }, /* Pc */ @@ -319,6 +322,30 @@ static const enum mdoct rsord[RSORD_MAX] = { MDOC__U }; +static const char * const secnames[SEC__MAX] = { + NULL, + "NAME", + "LIBRARY", + "SYNOPSIS", + "DESCRIPTION", + "IMPLEMENTATION NOTES", + "RETURN VALUES", + "ENVIRONMENT", + "FILES", + "EXIT STATUS", + "EXAMPLES", + "DIAGNOSTICS", + "COMPATIBILITY", + "ERRORS", + "SEE ALSO", + "STANDARDS", + "HISTORY", + "AUTHORS", + "CAVEATS", + "BUGS", + "SECURITY CONSIDERATIONS", + NULL +}; int mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) @@ -336,6 +363,8 @@ mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) /* FALLTHROUGH */ case (MDOC_TBL): /* FALLTHROUGH */ + case (MDOC_EQN): + /* FALLTHROUGH */ case (MDOC_ROOT): return(1); default: @@ -365,6 +394,8 @@ mdoc_valid_post(struct mdoc *mdoc) switch (mdoc->last->type) { case (MDOC_TEXT): /* FALLTHROUGH */ + case (MDOC_EQN): + /* FALLTHROUGH */ case (MDOC_TBL): return(1); case (MDOC_ROOT): @@ -913,7 +944,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) @@ -926,7 +957,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) @@ -1744,6 +1775,15 @@ post_rs(POST_ARGS) } static int +post_ns(POST_ARGS) +{ + + if (MDOC_LINE & mdoc->last->flags) + mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNNS); + return(1); +} + +static int post_sh(POST_ARGS) { @@ -1806,7 +1846,7 @@ post_sh_head(POST_ARGS) if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ)) return(0); - sec = mdoc_str2sec(buf); + sec = a2sec(buf); /* The NAME should be first. */ @@ -1956,24 +1996,22 @@ 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); + mdoc->meta.date = mandoc_normdate(buf, + mdoc->msg, mdoc->data, n->line, n->pos); - if (0 == mdoc->meta.date) { - mdoc_nmsg(mdoc, n, MANDOCERR_BADDATE); - mdoc->meta.date = time(NULL); - } - return(1); } @@ -2114,7 +2152,8 @@ post_bx(POST_ARGS) n = mdoc->last->child; if (n && NULL != (n = n->next)) - *n->string = toupper((unsigned char)*n->string); + *n->string = (char)toupper + ((unsigned char)*n->string); return(1); } @@ -2239,5 +2278,17 @@ concat(struct mdoc *m, char *p, const struct mdoc_node } return(1); +} + +static enum mdoc_sec +a2sec(const char *p) +{ + int i; + + for (i = 0; i < (int)SEC__MAX; i++) + if (secnames[i] && 0 == strcmp(p, secnames[i])) + return((enum mdoc_sec)i); + + return(SEC_CUSTOM); }