version 1.272, 2015/02/06 01:07:22 |
version 1.277, 2015/02/10 08:05:30 |
|
|
v_post post; |
v_post post; |
}; |
}; |
|
|
static void check_count(struct mdoc *, enum mdoc_type, |
|
enum check_ineq, int); |
|
static void check_text(struct mdoc *, int, int, char *); |
static void check_text(struct mdoc *, int, int, char *); |
static void check_argv(struct mdoc *, |
static void check_argv(struct mdoc *, |
struct mdoc_node *, struct mdoc_argv *); |
struct mdoc_node *, struct mdoc_argv *); |
Line 67 static enum mdoc_sec a2sec(const char *); |
|
Line 65 static enum mdoc_sec a2sec(const char *); |
|
static size_t macro2len(enum mdoct); |
static size_t macro2len(enum mdoct); |
static void rewrite_macro2len(char **); |
static void rewrite_macro2len(char **); |
|
|
static void bwarn_ge1(POST_ARGS); |
|
static void ewarn_eq1(POST_ARGS); |
|
static void ewarn_ge1(POST_ARGS); |
|
|
|
static void post_an(POST_ARGS); |
static void post_an(POST_ARGS); |
static void post_at(POST_ARGS); |
static void post_at(POST_ARGS); |
static void post_bf(POST_ARGS); |
static void post_bf(POST_ARGS); |
Line 93 static void post_fn(POST_ARGS); |
|
Line 87 static void post_fn(POST_ARGS); |
|
static void post_fname(POST_ARGS); |
static void post_fname(POST_ARGS); |
static void post_fo(POST_ARGS); |
static void post_fo(POST_ARGS); |
static void post_hyph(POST_ARGS); |
static void post_hyph(POST_ARGS); |
static void post_hyphtext(POST_ARGS); |
|
static void post_ignpar(POST_ARGS); |
static void post_ignpar(POST_ARGS); |
static void post_it(POST_ARGS); |
static void post_it(POST_ARGS); |
static void post_lb(POST_ARGS); |
static void post_lb(POST_ARGS); |
Line 151 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 144 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Ev */ |
{ NULL, NULL }, /* Ev */ |
{ pre_std, post_ex }, /* Ex */ |
{ pre_std, post_ex }, /* Ex */ |
{ NULL, post_fa }, /* Fa */ |
{ NULL, post_fa }, /* Fa */ |
{ NULL, ewarn_ge1 }, /* Fd */ |
{ NULL, NULL }, /* Fd */ |
{ NULL, NULL }, /* Fl */ |
{ NULL, NULL }, /* Fl */ |
{ NULL, post_fn }, /* Fn */ |
{ NULL, post_fn }, /* Fn */ |
{ NULL, NULL }, /* Ft */ |
{ NULL, NULL }, /* Ft */ |
Line 168 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 161 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Va */ |
{ NULL, NULL }, /* Va */ |
{ NULL, post_vt }, /* Vt */ |
{ NULL, post_vt }, /* Vt */ |
{ NULL, NULL }, /* Xr */ |
{ NULL, NULL }, /* Xr */ |
{ NULL, ewarn_ge1 }, /* %A */ |
{ NULL, NULL }, /* %A */ |
{ NULL, post_hyphtext }, /* %B */ /* FIXME: can be used outside Rs/Re. */ |
{ NULL, post_hyph }, /* %B */ /* FIXME: can be used outside Rs/Re. */ |
{ NULL, ewarn_ge1 }, /* %D */ |
{ NULL, NULL }, /* %D */ |
{ NULL, ewarn_ge1 }, /* %I */ |
{ NULL, NULL }, /* %I */ |
{ NULL, ewarn_ge1 }, /* %J */ |
{ NULL, NULL }, /* %J */ |
{ NULL, post_hyphtext }, /* %N */ |
{ NULL, post_hyph }, /* %N */ |
{ NULL, post_hyphtext }, /* %O */ |
{ NULL, post_hyph }, /* %O */ |
{ NULL, ewarn_ge1 }, /* %P */ |
{ NULL, NULL }, /* %P */ |
{ NULL, post_hyphtext }, /* %R */ |
{ NULL, post_hyph }, /* %R */ |
{ NULL, post_hyphtext }, /* %T */ /* FIXME: can be used outside Rs/Re. */ |
{ NULL, post_hyph }, /* %T */ /* FIXME: can be used outside Rs/Re. */ |
{ NULL, ewarn_ge1 }, /* %V */ |
{ NULL, NULL }, /* %V */ |
{ NULL, NULL }, /* Ac */ |
{ NULL, NULL }, /* Ac */ |
{ NULL, NULL }, /* Ao */ |
{ NULL, NULL }, /* Ao */ |
{ NULL, NULL }, /* Aq */ |
{ NULL, NULL }, /* Aq */ |
Line 240 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 233 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Brq */ |
{ NULL, NULL }, /* Brq */ |
{ NULL, NULL }, /* Bro */ |
{ NULL, NULL }, /* Bro */ |
{ NULL, NULL }, /* Brc */ |
{ NULL, NULL }, /* Brc */ |
{ NULL, ewarn_ge1 }, /* %C */ |
{ NULL, NULL }, /* %C */ |
{ pre_obsolete, post_es }, /* Es */ |
{ pre_obsolete, post_es }, /* Es */ |
{ pre_obsolete, post_en }, /* En */ |
{ pre_obsolete, post_en }, /* En */ |
{ NULL, NULL }, /* Dx */ |
{ NULL, NULL }, /* Dx */ |
{ NULL, ewarn_ge1 }, /* %Q */ |
{ NULL, NULL }, /* %Q */ |
{ NULL, post_par }, /* br */ |
{ NULL, post_par }, /* br */ |
{ NULL, post_par }, /* sp */ |
{ NULL, post_par }, /* sp */ |
{ NULL, ewarn_eq1 }, /* %U */ |
{ NULL, NULL }, /* %U */ |
{ NULL, NULL }, /* Ta */ |
{ NULL, NULL }, /* Ta */ |
{ NULL, NULL }, /* ll */ |
{ NULL, NULL }, /* ll */ |
}; |
}; |
Line 367 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 360 mdoc_valid_post(struct mdoc *mdoc) |
|
} |
} |
|
|
static void |
static void |
check_count(struct mdoc *mdoc, enum mdoc_type type, |
|
enum check_ineq ineq, int val) |
|
{ |
|
const char *p; |
|
|
|
if (mdoc->last->type != type) |
|
return; |
|
|
|
switch (ineq) { |
|
case CHECK_LT: |
|
p = "less than "; |
|
if (mdoc->last->nchild < val) |
|
return; |
|
break; |
|
case CHECK_GT: |
|
p = "more than "; |
|
if (mdoc->last->nchild > val) |
|
return; |
|
break; |
|
case CHECK_EQ: |
|
p = ""; |
|
if (val == mdoc->last->nchild) |
|
return; |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
mandoc_vmsg(MANDOCERR_ARGCWARN, mdoc->parse, mdoc->last->line, |
|
mdoc->last->pos, "want %s%d children (have %d)", |
|
p, val, mdoc->last->nchild); |
|
} |
|
|
|
static void |
|
bwarn_ge1(POST_ARGS) |
|
{ |
|
check_count(mdoc, MDOC_BODY, CHECK_GT, 0); |
|
} |
|
|
|
static void |
|
ewarn_eq1(POST_ARGS) |
|
{ |
|
check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1); |
|
} |
|
|
|
static void |
|
ewarn_ge1(POST_ARGS) |
|
{ |
|
check_count(mdoc, MDOC_ELEM, CHECK_GT, 0); |
|
} |
|
|
|
static void |
|
check_args(struct mdoc *mdoc, struct mdoc_node *n) |
check_args(struct mdoc *mdoc, struct mdoc_node *n) |
{ |
{ |
int i; |
int i; |
Line 927 post_lb(POST_ARGS) |
|
Line 867 post_lb(POST_ARGS) |
|
const char *stdlibname; |
const char *stdlibname; |
char *libname; |
char *libname; |
|
|
check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1); |
|
n = mdoc->last->child; |
n = mdoc->last->child; |
assert(MDOC_TEXT == n->type); |
assert(MDOC_TEXT == n->type); |
|
|
Line 980 post_fn(POST_ARGS) |
|
Line 919 post_fn(POST_ARGS) |
|
static void |
static void |
post_fo(POST_ARGS) |
post_fo(POST_ARGS) |
{ |
{ |
|
const struct mdoc_node *n; |
|
|
check_count(mdoc, MDOC_HEAD, CHECK_EQ, 1); |
n = mdoc->last; |
bwarn_ge1(mdoc); |
|
if (mdoc->last->type == MDOC_HEAD && mdoc->last->nchild) |
if (n->type != MDOC_HEAD) |
post_fname(mdoc); |
return; |
|
|
|
if (n->child == NULL) { |
|
mandoc_msg(MANDOCERR_FO_NOHEAD, mdoc->parse, |
|
n->line, n->pos, "Fo"); |
|
return; |
|
} |
|
if (n->child != n->last) { |
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
|
n->child->next->line, n->child->next->pos, |
|
"Fo ... %s", n->child->next->string); |
|
while (n->child != n->last) |
|
mdoc_node_delete(mdoc, n->last); |
|
} |
|
|
|
post_fname(mdoc); |
} |
} |
|
|
static void |
static void |
Line 1072 post_nd(POST_ARGS) |
|
Line 1027 post_nd(POST_ARGS) |
|
static void |
static void |
post_d1(POST_ARGS) |
post_d1(POST_ARGS) |
{ |
{ |
|
struct mdoc_node *n; |
|
|
bwarn_ge1(mdoc); |
n = mdoc->last; |
|
|
|
if (n->type != MDOC_BODY) |
|
return; |
|
|
|
if (n->child == NULL) |
|
mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, |
|
n->line, n->pos, "D1"); |
|
|
post_hyph(mdoc); |
post_hyph(mdoc); |
} |
} |
|
|
static void |
static void |
post_literal(POST_ARGS) |
post_literal(POST_ARGS) |
{ |
{ |
|
struct mdoc_node *n; |
|
|
bwarn_ge1(mdoc); |
n = mdoc->last; |
|
|
/* |
if (n->type != MDOC_BODY) |
* The `Dl' (note "el" not "one") and `Bd' macros unset the |
return; |
* MDOC_LITERAL flag as they leave. Note that `Bd' only sets |
|
* this in literal mode, but it doesn't hurt to just switch it |
|
* off in general since displays can't be nested. |
|
*/ |
|
|
|
if (MDOC_BODY == mdoc->last->type) |
if (n->child == NULL) |
mdoc->flags &= ~MDOC_LITERAL; |
mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, |
|
n->line, n->pos, mdoc_macronames[n->tok]); |
|
|
|
if (n->tok == MDOC_Bd && |
|
n->norm->Bd.type != DISP_literal && |
|
n->norm->Bd.type != DISP_unfilled) |
|
return; |
|
|
|
mdoc->flags &= ~MDOC_LITERAL; |
} |
} |
|
|
static void |
static void |
Line 1252 post_it(POST_ARGS) |
|
Line 1221 post_it(POST_ARGS) |
|
i++; |
i++; |
|
|
if (i < cols || i > cols + 1) |
if (i < cols || i > cols + 1) |
mandoc_vmsg(MANDOCERR_ARGCOUNT, |
mandoc_vmsg(MANDOCERR_BL_COL, |
mdoc->parse, nit->line, nit->pos, |
mdoc->parse, nit->line, nit->pos, |
"columns == %d (have %d)", cols, i); |
"%d columns, %d cells", cols, i); |
break; |
break; |
default: |
default: |
abort(); |
abort(); |
Line 1488 post_bl(POST_ARGS) |
|
Line 1457 post_bl(POST_ARGS) |
|
return; |
return; |
} |
} |
|
|
bwarn_ge1(mdoc); |
|
|
|
nchild = nbody->child; |
nchild = nbody->child; |
while (NULL != nchild) { |
if (nchild == NULL) { |
|
mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse, |
|
nbody->line, nbody->pos, "Bl"); |
|
return; |
|
} |
|
while (nchild != NULL) { |
if (nchild->tok == MDOC_It || |
if (nchild->tok == MDOC_It || |
(nchild->tok == MDOC_Sm && |
(nchild->tok == MDOC_Sm && |
nchild->next != NULL && |
nchild->next != NULL && |
Line 1555 post_bk(POST_ARGS) |
|
Line 1527 post_bk(POST_ARGS) |
|
n = mdoc->last; |
n = mdoc->last; |
|
|
if (n->type == MDOC_BLOCK && n->body->child == NULL) { |
if (n->type == MDOC_BLOCK && n->body->child == NULL) { |
mandoc_msg(MANDOCERR_MACRO_EMPTY, |
mandoc_msg(MANDOCERR_BLK_EMPTY, |
mdoc->parse, n->line, n->pos, "Bk"); |
mdoc->parse, n->line, n->pos, "Bk"); |
mdoc_node_delete(mdoc, n); |
mdoc_node_delete(mdoc, n); |
} |
} |
Line 1749 post_rs(POST_ARGS) |
|
Line 1721 post_rs(POST_ARGS) |
|
static void |
static void |
post_hyph(POST_ARGS) |
post_hyph(POST_ARGS) |
{ |
{ |
struct mdoc_node *n, *nch; |
struct mdoc_node *nch; |
char *cp; |
char *cp; |
|
|
n = mdoc->last; |
for (nch = mdoc->last->child; nch != NULL; nch = nch->next) { |
switch (n->type) { |
if (nch->type != MDOC_TEXT) |
case MDOC_HEAD: |
|
if (MDOC_Sh == n->tok || MDOC_Ss == n->tok) |
|
break; |
|
return; |
|
case MDOC_BODY: |
|
if (MDOC_D1 == n->tok || MDOC_Nd == n->tok) |
|
break; |
|
return; |
|
case MDOC_ELEM: |
|
break; |
|
default: |
|
return; |
|
} |
|
|
|
for (nch = n->child; nch; nch = nch->next) { |
|
if (MDOC_TEXT != nch->type) |
|
continue; |
continue; |
cp = nch->string; |
cp = nch->string; |
if ('\0' == *cp) |
if (*cp == '\0') |
continue; |
continue; |
while ('\0' != *(++cp)) |
while (*(++cp) != '\0') |
if ('-' == *cp && |
if (*cp == '-' && |
isalpha((unsigned char)cp[-1]) && |
isalpha((unsigned char)cp[-1]) && |
isalpha((unsigned char)cp[1])) |
isalpha((unsigned char)cp[1])) |
*cp = ASCII_HYPH; |
*cp = ASCII_HYPH; |
Line 1783 post_hyph(POST_ARGS) |
|
Line 1739 post_hyph(POST_ARGS) |
|
} |
} |
|
|
static void |
static void |
post_hyphtext(POST_ARGS) |
|
{ |
|
|
|
ewarn_ge1(mdoc); |
|
post_hyph(mdoc); |
|
} |
|
|
|
static void |
|
post_ns(POST_ARGS) |
post_ns(POST_ARGS) |
{ |
{ |
|
|
|
|
post_sh_see_also(POST_ARGS) |
post_sh_see_also(POST_ARGS) |
{ |
{ |
const struct mdoc_node *n; |
const struct mdoc_node *n; |
const char *name, *sec; |
const char *name, *sec; |
const char *lastname, *lastsec, *lastpunct; |
const char *lastname, *lastsec, *lastpunct; |
int cmp; |
int cmp; |
|
|
Line 2069 post_ignpar(POST_ARGS) |
|
Line 2017 post_ignpar(POST_ARGS) |
|
{ |
{ |
struct mdoc_node *np; |
struct mdoc_node *np; |
|
|
post_hyph(mdoc); |
switch (mdoc->last->type) { |
|
case MDOC_HEAD: |
if (MDOC_BODY != mdoc->last->type) |
post_hyph(mdoc); |
return; |
return; |
|
case MDOC_BODY: |
|
break; |
|
default: |
|
return; |
|
} |
|
|
if (NULL != (np = mdoc->last->child)) |
if (NULL != (np = mdoc->last->child)) |
if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) { |
if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) { |