version 1.248, 2014/09/11 23:53:30 |
version 1.258, 2014/11/27 23:40:19 |
Line 70 static void check_args(struct mdoc *, struct mdoc_nod |
|
Line 70 static void check_args(struct mdoc *, struct mdoc_nod |
|
static int child_an(const struct mdoc_node *); |
static int child_an(const struct mdoc_node *); |
static enum mdoc_sec a2sec(const char *); |
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 int ebool(POST_ARGS); |
|
static int berr_ge1(POST_ARGS); |
static int berr_ge1(POST_ARGS); |
static int bwarn_ge1(POST_ARGS); |
static int bwarn_ge1(POST_ARGS); |
static int ewarn_eq0(POST_ARGS); |
static int ewarn_eq0(POST_ARGS); |
Line 88 static int post_bf(POST_ARGS); |
|
Line 88 static int post_bf(POST_ARGS); |
|
static int post_bk(POST_ARGS); |
static int post_bk(POST_ARGS); |
static int post_bl(POST_ARGS); |
static int post_bl(POST_ARGS); |
static int post_bl_block(POST_ARGS); |
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_block_tag(POST_ARGS); |
static int post_bl_head(POST_ARGS); |
static int post_bl_head(POST_ARGS); |
static int post_bx(POST_ARGS); |
static int post_bx(POST_ARGS); |
Line 100 static int post_en(POST_ARGS); |
|
Line 99 static int post_en(POST_ARGS); |
|
static int post_es(POST_ARGS); |
static int post_es(POST_ARGS); |
static int post_eoln(POST_ARGS); |
static int post_eoln(POST_ARGS); |
static int post_ex(POST_ARGS); |
static int post_ex(POST_ARGS); |
|
static int post_fa(POST_ARGS); |
|
static int post_fn(POST_ARGS); |
|
static int post_fname(POST_ARGS); |
static int post_fo(POST_ARGS); |
static int post_fo(POST_ARGS); |
static int post_hyph(POST_ARGS); |
static int post_hyph(POST_ARGS); |
static int post_hyphtext(POST_ARGS); |
static int post_hyphtext(POST_ARGS); |
Line 119 static int post_sh_head(POST_ARGS); |
|
Line 121 static int post_sh_head(POST_ARGS); |
|
static int post_sh_name(POST_ARGS); |
static int post_sh_name(POST_ARGS); |
static int post_sh_see_also(POST_ARGS); |
static int post_sh_see_also(POST_ARGS); |
static int post_sh_authors(POST_ARGS); |
static int post_sh_authors(POST_ARGS); |
|
static int post_sm(POST_ARGS); |
static int post_st(POST_ARGS); |
static int post_st(POST_ARGS); |
static int post_vt(POST_ARGS); |
static int post_vt(POST_ARGS); |
static int pre_an(PRE_ARGS); |
static int pre_an(PRE_ARGS); |
Line 157 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 160 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Er */ |
{ NULL, NULL }, /* Er */ |
{ NULL, NULL }, /* Ev */ |
{ NULL, NULL }, /* Ev */ |
{ pre_std, post_ex }, /* Ex */ |
{ pre_std, post_ex }, /* Ex */ |
{ NULL, NULL }, /* Fa */ |
{ NULL, post_fa }, /* Fa */ |
{ NULL, ewarn_ge1 }, /* Fd */ |
{ NULL, ewarn_ge1 }, /* Fd */ |
{ NULL, NULL }, /* Fl */ |
{ NULL, NULL }, /* Fl */ |
{ NULL, NULL }, /* Fn */ |
{ NULL, post_fn }, /* Fn */ |
{ NULL, NULL }, /* Ft */ |
{ NULL, NULL }, /* Ft */ |
{ NULL, NULL }, /* Ic */ |
{ NULL, NULL }, /* Ic */ |
{ NULL, ewarn_eq1 }, /* In */ |
{ NULL, ewarn_eq1 }, /* In */ |
Line 196 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 199 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Bq */ |
{ NULL, NULL }, /* Bq */ |
{ NULL, NULL }, /* Bsx */ |
{ NULL, NULL }, /* Bsx */ |
{ NULL, post_bx }, /* Bx */ |
{ NULL, post_bx }, /* Bx */ |
{ NULL, ebool }, /* Db */ |
{ pre_obsolete, NULL }, /* Db */ |
{ NULL, NULL }, /* Dc */ |
{ NULL, NULL }, /* Dc */ |
{ NULL, NULL }, /* Do */ |
{ NULL, NULL }, /* Do */ |
{ NULL, NULL }, /* Dq */ |
{ NULL, NULL }, /* Dq */ |
Line 206 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 209 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Eo */ |
{ NULL, NULL }, /* Eo */ |
{ NULL, NULL }, /* Fx */ |
{ NULL, NULL }, /* Fx */ |
{ NULL, NULL }, /* Ms */ |
{ NULL, NULL }, /* Ms */ |
{ NULL, ewarn_eq0 }, /* No */ |
{ NULL, NULL }, /* No */ |
{ NULL, post_ns }, /* Ns */ |
{ NULL, post_ns }, /* Ns */ |
{ NULL, NULL }, /* Nx */ |
{ NULL, NULL }, /* Nx */ |
{ NULL, NULL }, /* Ox */ |
{ NULL, NULL }, /* Ox */ |
Line 223 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 226 static const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Sc */ |
{ NULL, NULL }, /* Sc */ |
{ NULL, NULL }, /* So */ |
{ NULL, NULL }, /* So */ |
{ NULL, NULL }, /* Sq */ |
{ NULL, NULL }, /* Sq */ |
{ NULL, ebool }, /* Sm */ |
{ NULL, post_sm }, /* Sm */ |
{ NULL, post_hyph }, /* Sx */ |
{ NULL, post_hyph }, /* Sx */ |
{ NULL, NULL }, /* Sy */ |
{ NULL, NULL }, /* Sy */ |
{ NULL, NULL }, /* Tn */ |
{ NULL, NULL }, /* Tn */ |
Line 350 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 353 mdoc_valid_post(struct mdoc *mdoc) |
|
case MDOC_ROOT: |
case MDOC_ROOT: |
return(post_root(mdoc)); |
return(post_root(mdoc)); |
default: |
default: |
|
|
|
/* |
|
* Closing delimiters are not special at the |
|
* beginning of a block, opening delimiters |
|
* are not special at the end. |
|
*/ |
|
|
|
if (n->child != NULL) |
|
n->child->flags &= ~MDOC_DELIMC; |
|
if (n->last != NULL) |
|
n->last->flags &= ~MDOC_DELIMO; |
|
|
|
/* Call the macro's postprocessor. */ |
|
|
p = mdoc_valids[n->tok].post; |
p = mdoc_valids[n->tok].post; |
return(*p ? (*p)(mdoc) : 1); |
return(*p ? (*p)(mdoc) : 1); |
} |
} |
Line 594 pre_bl(PRE_ARGS) |
|
Line 611 pre_bl(PRE_ARGS) |
|
mdoc->parse, argv->line, |
mdoc->parse, argv->line, |
argv->pos, "Bl -width %s", |
argv->pos, "Bl -width %s", |
argv->value[0]); |
argv->value[0]); |
|
rewrite_macro2len(argv->value); |
n->norm->Bl.width = argv->value[0]; |
n->norm->Bl.width = argv->value[0]; |
break; |
break; |
case MDOC_Offset: |
case MDOC_Offset: |
Line 608 pre_bl(PRE_ARGS) |
|
Line 626 pre_bl(PRE_ARGS) |
|
mdoc->parse, argv->line, |
mdoc->parse, argv->line, |
argv->pos, "Bl -offset %s", |
argv->pos, "Bl -offset %s", |
argv->value[0]); |
argv->value[0]); |
|
rewrite_macro2len(argv->value); |
n->norm->Bl.offs = argv->value[0]; |
n->norm->Bl.offs = argv->value[0]; |
break; |
break; |
default: |
default: |
Line 742 pre_bd(PRE_ARGS) |
|
Line 761 pre_bd(PRE_ARGS) |
|
case MDOC_File: |
case MDOC_File: |
mandoc_msg(MANDOCERR_BD_FILE, mdoc->parse, |
mandoc_msg(MANDOCERR_BD_FILE, mdoc->parse, |
n->line, n->pos, NULL); |
n->line, n->pos, NULL); |
return(0); |
break; |
case MDOC_Offset: |
case MDOC_Offset: |
if (0 == argv->sz) { |
if (0 == argv->sz) { |
mandoc_msg(MANDOCERR_ARG_EMPTY, |
mandoc_msg(MANDOCERR_ARG_EMPTY, |
Line 755 pre_bd(PRE_ARGS) |
|
Line 774 pre_bd(PRE_ARGS) |
|
mdoc->parse, argv->line, |
mdoc->parse, argv->line, |
argv->pos, "Bd -offset %s", |
argv->pos, "Bd -offset %s", |
argv->value[0]); |
argv->value[0]); |
|
rewrite_macro2len(argv->value); |
n->norm->Bd.offs = argv->value[0]; |
n->norm->Bd.offs = argv->value[0]; |
break; |
break; |
case MDOC_Compact: |
case MDOC_Compact: |
Line 999 post_eoln(POST_ARGS) |
|
Line 1019 post_eoln(POST_ARGS) |
|
} |
} |
|
|
static int |
static int |
|
post_fname(POST_ARGS) |
|
{ |
|
const struct mdoc_node *n; |
|
const char *cp; |
|
size_t pos; |
|
|
|
n = mdoc->last->child; |
|
pos = strcspn(n->string, "()"); |
|
cp = n->string + pos; |
|
if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*'))) |
|
mandoc_msg(MANDOCERR_FN_PAREN, mdoc->parse, |
|
n->line, n->pos + pos, n->string); |
|
return(1); |
|
} |
|
|
|
static int |
|
post_fn(POST_ARGS) |
|
{ |
|
|
|
post_fname(mdoc); |
|
post_fa(mdoc); |
|
return(1); |
|
} |
|
|
|
static int |
post_fo(POST_ARGS) |
post_fo(POST_ARGS) |
{ |
{ |
|
|
hwarn_eq1(mdoc); |
hwarn_eq1(mdoc); |
bwarn_ge1(mdoc); |
bwarn_ge1(mdoc); |
|
if (mdoc->last->type == MDOC_HEAD && mdoc->last->nchild) |
|
post_fname(mdoc); |
return(1); |
return(1); |
} |
} |
|
|
static int |
static int |
|
post_fa(POST_ARGS) |
|
{ |
|
const struct mdoc_node *n; |
|
const char *cp; |
|
|
|
for (n = mdoc->last->child; n != NULL; n = n->next) { |
|
for (cp = n->string; *cp != '\0'; cp++) { |
|
/* Ignore callbacks and alterations. */ |
|
if (*cp == '(' || *cp == '{') |
|
break; |
|
if (*cp != ',') |
|
continue; |
|
mandoc_msg(MANDOCERR_FA_COMMA, mdoc->parse, |
|
n->line, n->pos + (cp - n->string), |
|
n->string); |
|
break; |
|
} |
|
} |
|
return(1); |
|
} |
|
|
|
static int |
post_vt(POST_ARGS) |
post_vt(POST_ARGS) |
{ |
{ |
const struct mdoc_node *n; |
const struct mdoc_node *n; |
Line 1107 post_defaults(POST_ARGS) |
|
Line 1176 post_defaults(POST_ARGS) |
|
if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "...")) |
if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "...")) |
return(0); |
return(0); |
break; |
break; |
case MDOC_Li: |
|
if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "")) |
|
return(0); |
|
break; |
|
case MDOC_Pa: |
case MDOC_Pa: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MDOC_Mt: |
case MDOC_Mt: |
Line 1284 post_bl_block(POST_ARGS) |
|
Line 1349 post_bl_block(POST_ARGS) |
|
if ( ! post_bl_block_tag(mdoc)) |
if ( ! post_bl_block_tag(mdoc)) |
return(0); |
return(0); |
assert(n->norm->Bl.width); |
assert(n->norm->Bl.width); |
} else if (NULL != n->norm->Bl.width) { |
|
if ( ! post_bl_block_width(mdoc)) |
|
return(0); |
|
assert(n->norm->Bl.width); |
|
} |
} |
|
|
for (ni = n->body->child; ni; ni = ni->next) { |
for (ni = n->body->child; ni; ni = ni->next) { |
Line 1327 post_bl_block(POST_ARGS) |
|
Line 1388 post_bl_block(POST_ARGS) |
|
return(1); |
return(1); |
} |
} |
|
|
static int |
/* |
post_bl_block_width(POST_ARGS) |
* If the argument of -offset or -width is a macro, |
|
* replace it with the associated default width. |
|
*/ |
|
void |
|
rewrite_macro2len(char **arg) |
{ |
{ |
size_t width; |
size_t width; |
int i; |
|
enum mdoct tok; |
enum mdoct tok; |
struct mdoc_node *n; |
|
char buf[24]; |
|
|
|
n = mdoc->last; |
if (*arg == NULL) |
|
return; |
/* |
else if ( ! strcmp(*arg, "Ds")) |
* Calculate the real width of a list from the -width string, |
|
* which may contain a macro (with a known default width), a |
|
* literal string, or a scaling width. |
|
* |
|
* If the value to -width is a macro, then we re-write it to be |
|
* the macro's width as set in share/tmac/mdoc/doc-common. |
|
*/ |
|
|
|
if (0 == strcmp(n->norm->Bl.width, "Ds")) |
|
width = 6; |
width = 6; |
else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->Bl.width))) |
else if ((tok = mdoc_hash_find(*arg)) == MDOC_MAX) |
return(1); |
return; |
else |
else |
width = macro2len(tok); |
width = macro2len(tok); |
|
|
/* The value already exists: free and reallocate it. */ |
free(*arg); |
|
mandoc_asprintf(arg, "%zun", width); |
assert(n->args); |
|
|
|
for (i = 0; i < (int)n->args->argc; i++) |
|
if (MDOC_Width == n->args->argv[i].arg) |
|
break; |
|
|
|
assert(i < (int)n->args->argc); |
|
|
|
(void)snprintf(buf, sizeof(buf), "%un", (unsigned int)width); |
|
free(n->args->argv[i].value[0]); |
|
n->args->argv[i].value[0] = mandoc_strdup(buf); |
|
|
|
/* Set our width! */ |
|
n->norm->Bl.width = n->args->argv[i].value[0]; |
|
return(1); |
|
} |
} |
|
|
static int |
static int |
Line 1385 post_bl_block_tag(POST_ARGS) |
|
Line 1423 post_bl_block_tag(POST_ARGS) |
|
* Calculate the -width for a `Bl -tag' list if it hasn't been |
* Calculate the -width for a `Bl -tag' list if it hasn't been |
* provided. Uses the first head macro. NOTE AGAIN: this is |
* provided. Uses the first head macro. NOTE AGAIN: this is |
* ONLY if the -width argument has NOT been provided. See |
* ONLY if the -width argument has NOT been provided. See |
* post_bl_block_width() for converting the -width string. |
* rewrite_macro2len() for converting the -width string. |
*/ |
*/ |
|
|
sz = 10; |
sz = 10; |
Line 1584 post_bk(POST_ARGS) |
|
Line 1622 post_bk(POST_ARGS) |
|
} |
} |
|
|
static int |
static int |
ebool(struct mdoc *mdoc) |
post_sm(struct mdoc *mdoc) |
{ |
{ |
struct mdoc_node *nch; |
struct mdoc_node *nch; |
enum mdoct tok; |
|
|
|
tok = mdoc->last->tok; |
|
nch = mdoc->last->child; |
nch = mdoc->last->child; |
|
|
if (NULL == nch) { |
if (nch == NULL) { |
if (MDOC_Sm == tok) |
mdoc->flags ^= MDOC_SMOFF; |
mdoc->flags ^= MDOC_SMOFF; |
|
return(1); |
return(1); |
} |
} |
|
|
check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_LT, 2); |
assert(nch->type == MDOC_TEXT); |
|
|
assert(MDOC_TEXT == nch->type); |
if ( ! strcmp(nch->string, "on")) { |
|
mdoc->flags &= ~MDOC_SMOFF; |
if (0 == strcmp(nch->string, "on")) { |
|
if (MDOC_Sm == tok) |
|
mdoc->flags &= ~MDOC_SMOFF; |
|
return(1); |
return(1); |
} |
} |
if (0 == strcmp(nch->string, "off")) { |
if ( ! strcmp(nch->string, "off")) { |
if (MDOC_Sm == tok) |
mdoc->flags |= MDOC_SMOFF; |
mdoc->flags |= MDOC_SMOFF; |
|
return(1); |
return(1); |
} |
} |
|
|
mandoc_vmsg(MANDOCERR_SM_BAD, |
mandoc_vmsg(MANDOCERR_SM_BAD, |
mdoc->parse, nch->line, nch->pos, |
mdoc->parse, nch->line, nch->pos, |
"%s %s", mdoc_macronames[tok], nch->string); |
"%s %s", mdoc_macronames[mdoc->last->tok], nch->string); |
return(mdoc_node_relink(mdoc, nch)); |
return(mdoc_node_relink(mdoc, nch)); |
} |
} |
|
|
Line 1937 post_sh_see_also(POST_ARGS) |
|
Line 1968 post_sh_see_also(POST_ARGS) |
|
mdoc->parse, n->line, n->pos, |
mdoc->parse, n->line, n->pos, |
"%s(%s) after %s(%s)", name, |
"%s(%s) after %s(%s)", name, |
sec, lastname, lastsec); |
sec, lastname, lastsec); |
else if (cmp == 0 && strcmp(lastname, name) > 0) |
else if (cmp == 0 && |
|
strcasecmp(lastname, name) > 0) |
mandoc_vmsg(MANDOCERR_XR_ORDER, |
mandoc_vmsg(MANDOCERR_XR_ORDER, |
mdoc->parse, n->line, n->pos, |
mdoc->parse, n->line, n->pos, |
"%s after %s", name, lastname); |
"%s after %s", name, lastname); |