=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.151 retrieving revision 1.157 diff -u -p -r1.151 -r1.157 --- mandoc/mdoc_validate.c 2011/01/03 23:53:51 1.151 +++ mandoc/mdoc_validate.c 2011/02/09 09:18:15 1.157 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.151 2011/01/03 23:53:51 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.157 2011/02/09 09:18:15 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -78,7 +78,6 @@ static int concat(struct mdoc *, char *, static int ebool(POST_ARGS); static int berr_ge1(POST_ARGS); static int bwarn_ge1(POST_ARGS); -static int eerr_ge1(POST_ARGS); static int ewarn_eq0(POST_ARGS); static int ewarn_eq1(POST_ARGS); static int ewarn_ge1(POST_ARGS); @@ -96,6 +95,7 @@ static int post_bl_block(POST_ARGS); static int post_bl_block_width(POST_ARGS); static int post_bl_block_tag(POST_ARGS); static int post_bl_head(POST_ARGS); +static int post_bx(POST_ARGS); static int post_dd(POST_ARGS); static int post_dt(POST_ARGS); static int post_defaults(POST_ARGS); @@ -104,6 +104,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); @@ -135,6 +136,7 @@ static v_post posts_bd[] = { post_literal, hwarn_eq0, static v_post posts_bf[] = { hwarn_le1, post_bf, NULL }; static v_post posts_bk[] = { hwarn_eq0, bwarn_ge1, NULL }; static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL }; +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 }; @@ -147,6 +149,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 }; @@ -154,11 +157,10 @@ static v_post posts_sp[] = { ewarn_le1, NULL }; static v_post posts_ss[] = { post_ignpar, hwarn_ge1, bwarn_ge1, NULL }; static v_post posts_st[] = { post_st, NULL }; static v_post posts_std[] = { post_std, NULL }; -static v_post posts_text[] = { eerr_ge1, NULL }; +static v_post posts_text[] = { ewarn_ge1, NULL }; static v_post posts_text1[] = { ewarn_eq1, NULL }; static v_post posts_vt[] = { post_vt, NULL }; static v_post posts_wline[] = { bwarn_ge1, NULL }; -static v_post posts_wtext[] = { ewarn_ge1, NULL }; static v_pre pres_an[] = { pre_an, NULL }; static v_pre pres_bd[] = { pre_display, pre_bd, pre_literal, pre_par, NULL }; static v_pre pres_bl[] = { pre_bl, pre_par, NULL }; @@ -190,21 +192,21 @@ const struct valids mdoc_valids[MDOC_MAX] = { { pres_bl, posts_bl }, /* Bl */ { NULL, NULL }, /* El */ { pres_it, posts_it }, /* It */ - { NULL, posts_text }, /* Ad */ + { NULL, NULL }, /* Ad */ { pres_an, posts_an }, /* An */ { NULL, posts_defaults }, /* Ar */ - { NULL, posts_text }, /* Cd */ + { NULL, NULL }, /* Cd */ { NULL, NULL }, /* Cm */ { NULL, NULL }, /* Dv */ - { pres_er, posts_text }, /* Er */ + { pres_er, NULL }, /* Er */ { NULL, NULL }, /* Ev */ { pres_std, posts_std }, /* Ex */ { NULL, NULL }, /* Fa */ - { pres_fd, posts_wtext }, /* Fd */ + { pres_fd, posts_text }, /* Fd */ { NULL, NULL }, /* Fl */ - { NULL, posts_text }, /* Fn */ - { NULL, posts_wtext }, /* Ft */ - { NULL, posts_text }, /* Ic */ + { NULL, NULL }, /* Fn */ + { NULL, NULL }, /* Ft */ + { NULL, NULL }, /* Ic */ { NULL, posts_text1 }, /* In */ { NULL, posts_defaults }, /* Li */ { NULL, posts_nd }, /* Nd */ @@ -216,7 +218,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_st }, /* St */ { NULL, NULL }, /* Va */ { NULL, posts_vt }, /* Vt */ - { NULL, posts_wtext }, /* Xr */ + { 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(). */ @@ -237,7 +239,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Bo */ { NULL, NULL }, /* Bq */ { NULL, NULL }, /* Bsx */ - { NULL, NULL }, /* Bx */ + { NULL, posts_bx }, /* Bx */ { NULL, posts_bool }, /* Db */ { NULL, NULL }, /* Dc */ { NULL, NULL }, /* Do */ @@ -247,9 +249,9 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Em */ { NULL, NULL }, /* Eo */ { NULL, NULL }, /* Fx */ - { NULL, posts_text }, /* Ms */ + { NULL, NULL }, /* Ms */ { NULL, posts_notext }, /* No */ - { NULL, posts_notext }, /* Ns */ + { NULL, posts_ns }, /* Ns */ { NULL, NULL }, /* Nx */ { NULL, NULL }, /* Ox */ { NULL, NULL }, /* Pc */ @@ -266,9 +268,9 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* So */ { NULL, NULL }, /* Sq */ { NULL, posts_bool }, /* Sm */ - { NULL, posts_text }, /* Sx */ - { NULL, posts_text }, /* Sy */ - { NULL, posts_text }, /* Tn */ + { NULL, NULL }, /* Sx */ + { NULL, NULL }, /* Sy */ + { NULL, NULL }, /* Tn */ { NULL, NULL }, /* Ux */ { NULL, NULL }, /* Xc */ { NULL, NULL }, /* Xo */ @@ -284,7 +286,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_eoln }, /* Ud */ { NULL, posts_lb }, /* Lb */ { NULL, posts_notext }, /* Lp */ - { NULL, posts_text }, /* Lk */ + { NULL, NULL }, /* Lk */ { NULL, posts_defaults }, /* Mt */ { NULL, NULL }, /* Brq */ { NULL, NULL }, /* Bro */ @@ -336,6 +338,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 +369,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): @@ -434,12 +440,6 @@ bwarn_ge1(POST_ARGS) } static int -eerr_ge1(POST_ARGS) -{ - return(check_count(mdoc, MDOC_ELEM, CHECK_ERROR, CHECK_GT, 0)); -} - -static int ewarn_eq0(POST_ARGS) { return(check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0)); @@ -1079,12 +1079,11 @@ post_vt(POST_ARGS) /* * The Vt macro comes in both ELEM and BLOCK form, both of which * have different syntaxes (yet more context-sensitive - * behaviour). ELEM types must have a child; BLOCK types, + * behaviour). ELEM types must have a child, which is already + * guaranteed by the in_line parsing routine; BLOCK types, * specifically the BODY, should only have TEXT children. */ - if (MDOC_ELEM == mdoc->last->type) - return(eerr_ge1(mdoc)); if (MDOC_BODY != mdoc->last->type) return(1); @@ -1228,19 +1227,12 @@ post_an(POST_ARGS) struct mdoc_node *np; np = mdoc->last; - if (AUTH__NONE != np->norm->An.auth && np->child) { + if (AUTH__NONE == np->norm->An.auth) { + if (0 == np->child) + check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0); + } else if (np->child) check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0); - return(1); - } - /* - * FIXME: make this ewarn and make sure that the front-ends - * don't print the arguments. - */ - if (AUTH__NONE != np->norm->An.auth || np->child) - return(1); - - mdoc_nmsg(mdoc, np, MANDOCERR_NOARGS); return(1); } @@ -1681,8 +1673,8 @@ post_rs(POST_ARGS) break; if (i < RSORD_MAX) { - if (MDOC__J == rsord[i]) - mdoc->last->norm->Rs.child_J = nn; + if (MDOC__J == rsord[i] || MDOC__B == rsord[i]) + mdoc->last->norm->Rs.quote_T++; next = nn->next; continue; } @@ -1758,6 +1750,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) { @@ -2111,6 +2112,24 @@ post_prol(POST_ARGS) mdoc_node_delete(mdoc, mdoc->last); if (mdoc->meta.title && mdoc->meta.date && mdoc->meta.os) mdoc->flags |= MDOC_PBODY; + + return(1); +} + +static int +post_bx(POST_ARGS) +{ + struct mdoc_node *n; + + /* + * Make `Bx's second argument always start with an uppercase + * letter. Groff checks if it's an "accepted" term, but we just + * uppercase blindly. + */ + + n = mdoc->last->child; + if (n && NULL != (n = n->next)) + *n->string = toupper((unsigned char)*n->string); return(1); }