version 1.268, 2015/02/04 18:03:47 |
version 1.282, 2015/02/23 13:31:04 |
|
|
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 hwarn_eq0(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 94 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 152 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 */ |
{ NULL, NULL }, /* Ic */ |
{ NULL, NULL }, /* Ic */ |
{ NULL, ewarn_eq1 }, /* In */ |
{ NULL, NULL }, /* In */ |
{ NULL, post_defaults }, /* Li */ |
{ NULL, post_defaults }, /* Li */ |
{ NULL, post_nd }, /* Nd */ |
{ NULL, post_nd }, /* Nd */ |
{ NULL, post_nm }, /* Nm */ |
{ NULL, post_nm }, /* Nm */ |
Line 168 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 160 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, post_st }, /* St */ |
{ NULL, post_st }, /* St */ |
{ NULL, NULL }, /* Va */ |
{ NULL, NULL }, /* Va */ |
{ NULL, post_vt }, /* Vt */ |
{ NULL, post_vt }, /* Vt */ |
{ NULL, ewarn_ge1 }, /* 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 241 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 306 mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) |
|
Line 298 mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) |
|
|
|
switch (n->type) { |
switch (n->type) { |
case MDOC_TEXT: |
case MDOC_TEXT: |
check_text(mdoc, n->line, n->pos, n->string); |
if (n->sec != SEC_SYNOPSIS || n->parent->tok != MDOC_Fd) |
|
check_text(mdoc, n->line, n->pos, n->string); |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MDOC_TBL: |
case MDOC_TBL: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
Line 333 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 326 mdoc_valid_post(struct mdoc *mdoc) |
|
n = mdoc->last; |
n = mdoc->last; |
if (n->flags & MDOC_VALID) |
if (n->flags & MDOC_VALID) |
return; |
return; |
n->flags |= MDOC_VALID; |
n->flags |= MDOC_VALID | MDOC_ENDED; |
|
|
switch (n->type) { |
switch (n->type) { |
case MDOC_TEXT: |
case MDOC_TEXT: |
Line 368 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 361 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 |
|
hwarn_eq0(POST_ARGS) |
|
{ |
|
check_count(mdoc, MDOC_HEAD, CHECK_EQ, 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 483 pre_display(PRE_ARGS) |
|
Line 417 pre_display(PRE_ARGS) |
|
static void |
static void |
pre_bl(PRE_ARGS) |
pre_bl(PRE_ARGS) |
{ |
{ |
struct mdoc_node *np; |
|
struct mdoc_argv *argv, *wa; |
struct mdoc_argv *argv, *wa; |
int i; |
int i; |
enum mdocargt mdoclt; |
enum mdocargt mdoclt; |
enum mdoc_list lt; |
enum mdoc_list lt; |
|
|
if (MDOC_BLOCK != n->type) { |
if (n->type != MDOC_BLOCK) |
if (ENDBODY_NOT != n->end) { |
|
assert(n->pending); |
|
np = n->pending->parent; |
|
} else |
|
np = n->parent; |
|
|
|
assert(np); |
|
assert(MDOC_BLOCK == np->type); |
|
assert(MDOC_Bl == np->tok); |
|
return; |
return; |
} |
|
|
|
/* |
/* |
* First figure out which kind of list to use: bind ourselves to |
* First figure out which kind of list to use: bind ourselves to |
Line 676 pre_bl(PRE_ARGS) |
|
Line 599 pre_bl(PRE_ARGS) |
|
static void |
static void |
pre_bd(PRE_ARGS) |
pre_bd(PRE_ARGS) |
{ |
{ |
struct mdoc_node *np; |
|
struct mdoc_argv *argv; |
struct mdoc_argv *argv; |
int i; |
int i; |
enum mdoc_disp dt; |
enum mdoc_disp dt; |
|
|
pre_literal(mdoc, n); |
pre_literal(mdoc, n); |
|
|
if (MDOC_BLOCK != n->type) { |
if (n->type != MDOC_BLOCK) |
if (ENDBODY_NOT != n->end) { |
|
assert(n->pending); |
|
np = n->pending->parent; |
|
} else |
|
np = n->parent; |
|
|
|
assert(np); |
|
assert(MDOC_BLOCK == np->type); |
|
assert(MDOC_Bd == np->tok); |
|
return; |
return; |
} |
|
|
|
for (i = 0; n->args && i < (int)n->args->argc; i++) { |
for (i = 0; n->args && i < (int)n->args->argc; i++) { |
argv = n->args->argv + i; |
argv = n->args->argv + i; |
Line 864 post_bf(POST_ARGS) |
|
Line 776 post_bf(POST_ARGS) |
|
* element, which contains the goods. |
* element, which contains the goods. |
*/ |
*/ |
|
|
if (MDOC_HEAD != mdoc->last->type) { |
np = mdoc->last; |
if (ENDBODY_NOT != mdoc->last->end) { |
if (MDOC_HEAD != np->type) |
assert(mdoc->last->pending); |
|
np = mdoc->last->pending->parent->head; |
|
} else if (MDOC_BLOCK != mdoc->last->type) { |
|
np = mdoc->last->parent->head; |
|
} else |
|
np = mdoc->last->head; |
|
|
|
assert(np); |
|
assert(MDOC_HEAD == np->type); |
|
assert(MDOC_Bf == np->tok); |
|
return; |
return; |
} |
|
|
|
np = mdoc->last; |
|
assert(MDOC_BLOCK == np->parent->type); |
assert(MDOC_BLOCK == np->parent->type); |
assert(MDOC_Bf == np->parent->tok); |
assert(MDOC_Bf == np->parent->tok); |
|
|
Line 934 post_lb(POST_ARGS) |
|
Line 834 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); |
|
|
if (NULL == (stdlibname = mdoc_a2lib(n->string))) |
if (NULL == (stdlibname = mdoc_a2lib(n->string))) |
mandoc_asprintf(&libname, |
mandoc_asprintf(&libname, |
"library \\(lq%s\\(rq", n->string); |
"library \\(Lq%s\\(Rq", n->string); |
else |
else |
libname = mandoc_strdup(stdlibname); |
libname = mandoc_strdup(stdlibname); |
|
|
Line 987 post_fn(POST_ARGS) |
|
Line 886 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 1079 post_nd(POST_ARGS) |
|
Line 994 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; |
|
|
if (mdoc->last->tok == MDOC_Bd) |
n = mdoc->last; |
hwarn_eq0(mdoc); |
|
bwarn_ge1(mdoc); |
|
|
|
/* |
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 1174 post_at(POST_ARGS) |
|
Line 1101 post_at(POST_ARGS) |
|
static void |
static void |
post_an(POST_ARGS) |
post_an(POST_ARGS) |
{ |
{ |
struct mdoc_node *np; |
struct mdoc_node *np, *nch; |
|
|
np = mdoc->last; |
np = mdoc->last; |
if (AUTH__NONE == np->norm->An.auth) { |
nch = np->child; |
if (0 == np->child) |
if (np->norm->An.auth == AUTH__NONE) { |
check_count(mdoc, MDOC_ELEM, CHECK_GT, 0); |
if (nch == NULL) |
} else if (np->child) |
mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse, |
check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0); |
np->line, np->pos, "An"); |
|
} else if (nch != NULL) |
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
|
nch->line, nch->pos, "An ... %s", nch->string); |
} |
} |
|
|
static void |
static void |
Line 1258 post_it(POST_ARGS) |
|
Line 1188 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 1414 post_bl_block_tag(POST_ARGS) |
|
Line 1344 post_bl_block_tag(POST_ARGS) |
|
static void |
static void |
post_bl_head(POST_ARGS) |
post_bl_head(POST_ARGS) |
{ |
{ |
struct mdoc_node *np, *nn, *nnp; |
struct mdoc_node *nbl, *nh, *nch, *nnext; |
struct mdoc_argv *argv; |
struct mdoc_argv *argv; |
int i, j; |
int i, j; |
|
|
if (LIST_column != mdoc->last->norm->Bl.type) { |
nh = mdoc->last; |
/* FIXME: this should be ERROR class... */ |
|
hwarn_eq0(mdoc); |
if (nh->norm->Bl.type != LIST_column) { |
|
if ((nch = nh->child) == NULL) |
|
return; |
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
|
nch->line, nch->pos, "Bl ... %s", nch->string); |
|
while (nch != NULL) { |
|
mdoc_node_delete(mdoc, nch); |
|
nch = nh->child; |
|
} |
return; |
return; |
} |
} |
|
|
Line 1430 post_bl_head(POST_ARGS) |
|
Line 1368 post_bl_head(POST_ARGS) |
|
* lists where they're argument values following -column. |
* lists where they're argument values following -column. |
*/ |
*/ |
|
|
if (mdoc->last->child == NULL) |
if (nh->child == NULL) |
return; |
return; |
|
|
np = mdoc->last->parent; |
nbl = nh->parent; |
assert(np->args); |
for (j = 0; j < (int)nbl->args->argc; j++) |
|
if (nbl->args->argv[j].arg == MDOC_Column) |
for (j = 0; j < (int)np->args->argc; j++) |
|
if (MDOC_Column == np->args->argv[j].arg) |
|
break; |
break; |
|
|
assert(j < (int)np->args->argc); |
assert(j < (int)nbl->args->argc); |
|
|
/* |
/* |
* Accommodate for new-style groff column syntax. Shuffle the |
* Accommodate for new-style groff column syntax. Shuffle the |
Line 1448 post_bl_head(POST_ARGS) |
|
Line 1384 post_bl_head(POST_ARGS) |
|
* column field. Then, delete the head children. |
* column field. Then, delete the head children. |
*/ |
*/ |
|
|
argv = np->args->argv + j; |
argv = nbl->args->argv + j; |
i = argv->sz; |
i = argv->sz; |
argv->sz += mdoc->last->nchild; |
argv->sz += nh->nchild; |
argv->value = mandoc_reallocarray(argv->value, |
argv->value = mandoc_reallocarray(argv->value, |
argv->sz, sizeof(char *)); |
argv->sz, sizeof(char *)); |
|
|
mdoc->last->norm->Bl.ncols = argv->sz; |
nh->norm->Bl.ncols = argv->sz; |
mdoc->last->norm->Bl.cols = (void *)argv->value; |
nh->norm->Bl.cols = (void *)argv->value; |
|
|
for (nn = mdoc->last->child; nn; i++) { |
for (nch = nh->child; nch != NULL; nch = nnext) { |
argv->value[i] = nn->string; |
argv->value[i++] = nch->string; |
nn->string = NULL; |
nch->string = NULL; |
nnp = nn; |
nnext = nch->next; |
nn = nn->next; |
mdoc_node_delete(NULL, nch); |
mdoc_node_delete(NULL, nnp); |
|
} |
} |
|
nh->nchild = 0; |
mdoc->last->nchild = 0; |
nh->child = NULL; |
mdoc->last->child = NULL; |
|
} |
} |
|
|
static void |
static void |
Line 1490 post_bl(POST_ARGS) |
|
Line 1424 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 1552 post_bl(POST_ARGS) |
|
Line 1489 post_bl(POST_ARGS) |
|
static void |
static void |
post_bk(POST_ARGS) |
post_bk(POST_ARGS) |
{ |
{ |
|
struct mdoc_node *n; |
|
|
hwarn_eq0(mdoc); |
n = mdoc->last; |
bwarn_ge1(mdoc); |
|
|
if (n->type == MDOC_BLOCK && n->body->child == NULL) { |
|
mandoc_msg(MANDOCERR_BLK_EMPTY, |
|
mdoc->parse, n->line, n->pos, "Bk"); |
|
mdoc_node_delete(mdoc, n); |
|
} |
} |
} |
|
|
static void |
static void |
Line 1636 post_st(POST_ARGS) |
|
Line 1579 post_st(POST_ARGS) |
|
n = mdoc->last; |
n = mdoc->last; |
nch = n->child; |
nch = n->child; |
|
|
if (NULL == nch) { |
|
mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse, |
|
n->line, n->pos, mdoc_macronames[n->tok]); |
|
mdoc_node_delete(mdoc, n); |
|
return; |
|
} |
|
|
|
assert(MDOC_TEXT == nch->type); |
assert(MDOC_TEXT == nch->type); |
|
|
if (NULL == (p = mdoc_a2st(nch->string))) { |
if (NULL == (p = mdoc_a2st(nch->string))) { |
Line 1752 post_rs(POST_ARGS) |
|
Line 1688 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 1786 post_hyph(POST_ARGS) |
|
Line 1706 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_name(POST_ARGS) |
post_sh_name(POST_ARGS) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
int hasnm, hasnd; |
|
|
/* |
hasnm = hasnd = 0; |
* Warn if the NAME section doesn't contain the `Nm' and `Nd' |
|
* macros (can have multiple `Nm' and one `Nd'). Note that the |
|
* children of the BODY declaration can also be "text". |
|
*/ |
|
|
|
if (NULL == (n = mdoc->last->child)) { |
for (n = mdoc->last->child; n != NULL; n = n->next) { |
mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, |
switch (n->tok) { |
mdoc->last->line, mdoc->last->pos, "empty"); |
case MDOC_Nm: |
return; |
hasnm = 1; |
|
break; |
|
case MDOC_Nd: |
|
hasnd = 1; |
|
if (n->next != NULL) |
|
mandoc_msg(MANDOCERR_NAMESEC_ND, |
|
mdoc->parse, n->line, n->pos, NULL); |
|
break; |
|
default: |
|
mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, |
|
n->line, n->pos, mdoc_macronames[n->tok]); |
|
break; |
|
} |
} |
} |
|
|
for ( ; n && n->next; n = n->next) { |
if ( ! hasnm) |
if (MDOC_ELEM == n->type && MDOC_Nm == n->tok) |
mandoc_msg(MANDOCERR_NAMESEC_NONM, mdoc->parse, |
continue; |
mdoc->last->line, mdoc->last->pos, NULL); |
if (MDOC_TEXT == n->type) |
if ( ! hasnd) |
continue; |
mandoc_msg(MANDOCERR_NAMESEC_NOND, mdoc->parse, |
mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, |
mdoc->last->line, mdoc->last->pos, NULL); |
n->line, n->pos, mdoc_macronames[n->tok]); |
|
} |
|
|
|
assert(n); |
|
if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok) |
|
return; |
|
|
|
mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, |
|
n->line, n->pos, mdoc_macronames[n->tok]); |
|
} |
} |
|
|
static void |
static void |
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 2072 post_ignpar(POST_ARGS) |
|
Line 1984 post_ignpar(POST_ARGS) |
|
{ |
{ |
struct mdoc_node *np; |
struct mdoc_node *np; |
|
|
check_count(mdoc, MDOC_HEAD, CHECK_GT, 0); |
switch (mdoc->last->type) { |
post_hyph(mdoc); |
case MDOC_HEAD: |
|
post_hyph(mdoc); |
if (MDOC_BODY != mdoc->last->type) |
|
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) { |
Line 2134 post_par(POST_ARGS) |
|
Line 2050 post_par(POST_ARGS) |
|
{ |
{ |
struct mdoc_node *np; |
struct mdoc_node *np; |
|
|
if (mdoc->last->tok == MDOC_sp) |
np = mdoc->last; |
check_count(mdoc, MDOC_ELEM, CHECK_LT, 2); |
|
else |
|
check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0); |
|
|
|
if (MDOC_ELEM != mdoc->last->type && |
if (np->tok == MDOC_sp) { |
MDOC_BLOCK != mdoc->last->type) |
if (np->nchild > 1) |
return; |
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
|
np->child->next->line, np->child->next->pos, |
|
"sp ... %s", np->child->next->string); |
|
} else if (np->child != NULL) |
|
mandoc_vmsg(MANDOCERR_ARG_SKIP, |
|
mdoc->parse, np->line, np->pos, "%s %s", |
|
mdoc_macronames[np->tok], np->child->string); |
|
|
if (NULL == (np = mdoc->last->prev)) { |
if (NULL == (np = mdoc->last->prev)) { |
np = mdoc->last->parent; |
np = mdoc->last->parent; |
Line 2237 post_dt(POST_ARGS) |
|
Line 2156 post_dt(POST_ARGS) |
|
mdoc->meta.vol = NULL; |
mdoc->meta.vol = NULL; |
mdoc->meta.arch = NULL; |
mdoc->meta.arch = NULL; |
|
|
/* First check that all characters are uppercase. */ |
/* Mandatory first argument: title. */ |
|
|
if (NULL != (nn = n->child)) |
nn = n->child; |
for (p = nn->string; *p; p++) { |
if (nn == NULL || *nn->string == '\0') { |
if (toupper((unsigned char)*p) == *p) |
|
continue; |
|
mandoc_vmsg(MANDOCERR_TITLE_CASE, |
|
mdoc->parse, nn->line, |
|
nn->pos + (p - nn->string), |
|
"Dt %s", nn->string); |
|
break; |
|
} |
|
|
|
/* No argument: msec and arch remain NULL. */ |
|
|
|
if (NULL == (nn = n->child)) { |
|
mandoc_msg(MANDOCERR_DT_NOTITLE, |
mandoc_msg(MANDOCERR_DT_NOTITLE, |
mdoc->parse, n->line, n->pos, "Dt"); |
mdoc->parse, n->line, n->pos, "Dt"); |
mdoc->meta.title = mandoc_strdup("UNTITLED"); |
mdoc->meta.title = mandoc_strdup("UNTITLED"); |
mdoc->meta.vol = mandoc_strdup("LOCAL"); |
} else { |
goto out; |
mdoc->meta.title = mandoc_strdup(nn->string); |
|
|
|
/* Check that all characters are uppercase. */ |
|
|
|
for (p = nn->string; *p != '\0'; p++) |
|
if (islower((unsigned char)*p)) { |
|
mandoc_vmsg(MANDOCERR_TITLE_CASE, |
|
mdoc->parse, nn->line, |
|
nn->pos + (p - nn->string), |
|
"Dt %s", nn->string); |
|
break; |
|
} |
} |
} |
|
|
/* One argument: msec and arch remain NULL. */ |
/* Mandatory second argument: section. */ |
|
|
mdoc->meta.title = mandoc_strdup( |
if (nn != NULL) |
'\0' == nn->string[0] ? "UNTITLED" : nn->string); |
nn = nn->next; |
|
|
if (NULL == (nn = nn->next)) { |
if (nn == NULL) { |
mandoc_vmsg(MANDOCERR_MSEC_MISSING, |
mandoc_vmsg(MANDOCERR_MSEC_MISSING, |
mdoc->parse, n->line, n->pos, |
mdoc->parse, n->line, n->pos, |
"Dt %s", mdoc->meta.title); |
"Dt %s", mdoc->meta.title); |
mdoc->meta.vol = mandoc_strdup("LOCAL"); |
mdoc->meta.vol = mandoc_strdup("LOCAL"); |
goto out; |
goto out; /* msec and arch remain NULL. */ |
} |
} |
|
|
/* Handles: `.Dt TITLE SEC' |
mdoc->meta.msec = mandoc_strdup(nn->string); |
* title = TITLE, |
|
* volume = SEC is msec ? format(msec) : SEC, |
|
* msec = SEC is msec ? atoi(msec) : 0, |
|
* arch = NULL |
|
*/ |
|
|
|
|
/* Infer volume title from section number. */ |
|
|
cp = mandoc_a2msec(nn->string); |
cp = mandoc_a2msec(nn->string); |
if (cp) { |
if (cp == NULL) { |
mdoc->meta.vol = mandoc_strdup(cp); |
|
mdoc->meta.msec = mandoc_strdup(nn->string); |
|
} else { |
|
mandoc_vmsg(MANDOCERR_MSEC_BAD, mdoc->parse, |
mandoc_vmsg(MANDOCERR_MSEC_BAD, mdoc->parse, |
nn->line, nn->pos, "Dt ... %s", nn->string); |
nn->line, nn->pos, "Dt ... %s", nn->string); |
mdoc->meta.vol = mandoc_strdup(nn->string); |
mdoc->meta.vol = mandoc_strdup(nn->string); |
mdoc->meta.msec = mandoc_strdup(nn->string); |
} else |
} |
mdoc->meta.vol = mandoc_strdup(cp); |
|
|
/* Handle an optional architecture */ |
/* Optional third argument: architecture. */ |
|
|
if ((nn = nn->next) != NULL) { |
if ((nn = nn->next) == NULL) |
for (p = nn->string; *p; p++) |
goto out; |
*p = tolower((unsigned char)*p); |
|
mdoc->meta.arch = mandoc_strdup(nn->string); |
|
} |
|
|
|
/* Ignore any subsequent parameters... */ |
for (p = nn->string; *p != '\0'; p++) |
/* FIXME: warn about subsequent parameters. */ |
*p = tolower((unsigned char)*p); |
|
mdoc->meta.arch = mandoc_strdup(nn->string); |
|
|
|
/* Ignore fourth and later arguments. */ |
|
|
|
if ((nn = nn->next) != NULL) |
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
|
nn->line, nn->pos, "Dt ... %s", nn->string); |
|
|
out: |
out: |
mdoc_node_delete(mdoc, n); |
mdoc_node_delete(mdoc, n); |
} |
} |