version 1.285, 2015/04/02 22:48:17 |
version 1.291, 2015/04/23 16:17:44 |
|
|
#include "roff.h" |
#include "roff.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "libmandoc.h" |
#include "libmandoc.h" |
|
#include "roff_int.h" |
#include "libmdoc.h" |
#include "libmdoc.h" |
|
|
/* FIXME: .Bl -diag can't have non-text children in HEAD. */ |
/* FIXME: .Bl -diag can't have non-text children in HEAD. */ |
|
|
#define PRE_ARGS struct mdoc *mdoc, struct roff_node *n |
#define PRE_ARGS struct roff_man *mdoc, struct roff_node *n |
#define POST_ARGS struct mdoc *mdoc |
#define POST_ARGS struct roff_man *mdoc |
|
|
enum check_ineq { |
enum check_ineq { |
CHECK_LT, |
CHECK_LT, |
|
|
v_post post; |
v_post post; |
}; |
}; |
|
|
static void check_text(struct mdoc *, int, int, char *); |
static void check_text(struct roff_man *, int, int, char *); |
static void check_argv(struct mdoc *, |
static void check_argv(struct roff_man *, |
struct roff_node *, struct mdoc_argv *); |
struct roff_node *, struct mdoc_argv *); |
static void check_args(struct mdoc *, struct roff_node *); |
static void check_args(struct roff_man *, struct roff_node *); |
static int child_an(const struct roff_node *); |
static int child_an(const struct roff_node *); |
static enum roff_sec a2sec(const char *); |
static enum roff_sec a2sec(const char *); |
static size_t macro2len(int); |
static size_t macro2len(int); |
Line 293 static const char * const secnames[SEC__MAX] = { |
|
Line 294 static const char * const secnames[SEC__MAX] = { |
|
|
|
|
|
void |
void |
mdoc_valid_pre(struct mdoc *mdoc, struct roff_node *n) |
mdoc_valid_pre(struct roff_man *mdoc, struct roff_node *n) |
{ |
{ |
v_pre p; |
v_pre p; |
|
|
Line 319 mdoc_valid_pre(struct mdoc *mdoc, struct roff_node *n) |
|
Line 320 mdoc_valid_pre(struct mdoc *mdoc, struct roff_node *n) |
|
} |
} |
|
|
void |
void |
mdoc_valid_post(struct mdoc *mdoc) |
mdoc_valid_post(struct roff_man *mdoc) |
{ |
{ |
struct roff_node *n; |
struct roff_node *n; |
v_post p; |
v_post p; |
Line 362 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 363 mdoc_valid_post(struct mdoc *mdoc) |
|
} |
} |
|
|
static void |
static void |
check_args(struct mdoc *mdoc, struct roff_node *n) |
check_args(struct roff_man *mdoc, struct roff_node *n) |
{ |
{ |
int i; |
int i; |
|
|
Line 375 check_args(struct mdoc *mdoc, struct roff_node *n) |
|
Line 376 check_args(struct mdoc *mdoc, struct roff_node *n) |
|
} |
} |
|
|
static void |
static void |
check_argv(struct mdoc *mdoc, struct roff_node *n, struct mdoc_argv *v) |
check_argv(struct roff_man *mdoc, struct roff_node *n, struct mdoc_argv *v) |
{ |
{ |
int i; |
int i; |
|
|
Line 384 check_argv(struct mdoc *mdoc, struct roff_node *n, str |
|
Line 385 check_argv(struct mdoc *mdoc, struct roff_node *n, str |
|
} |
} |
|
|
static void |
static void |
check_text(struct mdoc *mdoc, int ln, int pos, char *p) |
check_text(struct roff_man *mdoc, int ln, int pos, char *p) |
{ |
{ |
char *cp; |
char *cp; |
|
|
Line 904 post_fo(POST_ARGS) |
|
Line 905 post_fo(POST_ARGS) |
|
n->child->next->line, n->child->next->pos, |
n->child->next->line, n->child->next->pos, |
"Fo ... %s", n->child->next->string); |
"Fo ... %s", n->child->next->string); |
while (n->child != n->last) |
while (n->child != n->last) |
mdoc_node_delete(mdoc, n->last); |
roff_node_delete(mdoc, n->last); |
} |
} |
|
|
post_fname(mdoc); |
post_fname(mdoc); |
Line 968 post_nm(POST_ARGS) |
|
Line 969 post_nm(POST_ARGS) |
|
if (NULL != mdoc->meta.name) |
if (NULL != mdoc->meta.name) |
return; |
return; |
|
|
mdoc_deroff(&mdoc->meta.name, n); |
deroff(&mdoc->meta.name, n); |
|
|
if (NULL == mdoc->meta.name) |
if (NULL == mdoc->meta.name) |
mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse, |
mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse, |
Line 1046 post_defaults(POST_ARGS) |
|
Line 1047 post_defaults(POST_ARGS) |
|
return; |
return; |
|
|
nn = mdoc->last; |
nn = mdoc->last; |
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = ROFF_NEXT_CHILD; |
|
|
switch (nn->tok) { |
switch (nn->tok) { |
case MDOC_Ar: |
case MDOC_Ar: |
mdoc_word_alloc(mdoc, nn->line, nn->pos, "file"); |
roff_word_alloc(mdoc, nn->line, nn->pos, "file"); |
mdoc_word_alloc(mdoc, nn->line, nn->pos, "..."); |
roff_word_alloc(mdoc, nn->line, nn->pos, "..."); |
break; |
break; |
case MDOC_Pa: |
case MDOC_Pa: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MDOC_Mt: |
case MDOC_Mt: |
mdoc_word_alloc(mdoc, nn->line, nn->pos, "~"); |
roff_word_alloc(mdoc, nn->line, nn->pos, "~"); |
break; |
break; |
default: |
default: |
abort(); |
abort(); |
Line 1074 post_at(POST_ARGS) |
|
Line 1075 post_at(POST_ARGS) |
|
|
|
n = mdoc->last; |
n = mdoc->last; |
if (n->child == NULL) { |
if (n->child == NULL) { |
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = ROFF_NEXT_CHILD; |
mdoc_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX"); |
roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX"); |
mdoc->last = n; |
mdoc->last = n; |
return; |
return; |
} |
} |
Line 1246 post_bl_block(POST_ARGS) |
|
Line 1247 post_bl_block(POST_ARGS) |
|
mdoc->parse, nc->line, nc->pos, |
mdoc->parse, nc->line, nc->pos, |
"%s before It", |
"%s before It", |
mdoc_macronames[nc->tok]); |
mdoc_macronames[nc->tok]); |
mdoc_node_delete(mdoc, nc); |
roff_node_delete(mdoc, nc); |
} else |
} else |
break; |
break; |
nc = ni->body->last; |
nc = ni->body->last; |
Line 1268 rewrite_macro2len(char **arg) |
|
Line 1269 rewrite_macro2len(char **arg) |
|
return; |
return; |
else if ( ! strcmp(*arg, "Ds")) |
else if ( ! strcmp(*arg, "Ds")) |
width = 6; |
width = 6; |
else if ((tok = mdoc_hash_find(*arg)) == MDOC_MAX) |
else if ((tok = mdoc_hash_find(*arg)) == TOKEN_NONE) |
return; |
return; |
else |
else |
width = macro2len(tok); |
width = macro2len(tok); |
Line 1357 post_bl_head(POST_ARGS) |
|
Line 1358 post_bl_head(POST_ARGS) |
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, |
nch->line, nch->pos, "Bl ... %s", nch->string); |
nch->line, nch->pos, "Bl ... %s", nch->string); |
while (nch != NULL) { |
while (nch != NULL) { |
mdoc_node_delete(mdoc, nch); |
roff_node_delete(mdoc, nch); |
nch = nh->child; |
nch = nh->child; |
} |
} |
return; |
return; |
Line 1398 post_bl_head(POST_ARGS) |
|
Line 1399 post_bl_head(POST_ARGS) |
|
argv->value[i++] = nch->string; |
argv->value[i++] = nch->string; |
nch->string = NULL; |
nch->string = NULL; |
nnext = nch->next; |
nnext = nch->next; |
mdoc_node_delete(NULL, nch); |
roff_node_delete(NULL, nch); |
} |
} |
nh->nchild = 0; |
nh->nchild = 0; |
nh->child = NULL; |
nh->child = NULL; |
Line 1497 post_bk(POST_ARGS) |
|
Line 1498 post_bk(POST_ARGS) |
|
if (n->type == ROFFT_BLOCK && n->body->child == NULL) { |
if (n->type == ROFFT_BLOCK && n->body->child == NULL) { |
mandoc_msg(MANDOCERR_BLK_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); |
roff_node_delete(mdoc, n); |
} |
} |
} |
} |
|
|
static void |
static void |
post_sm(struct mdoc *mdoc) |
post_sm(struct roff_man *mdoc) |
{ |
{ |
struct roff_node *nch; |
struct roff_node *nch; |
|
|
Line 1561 post_root(POST_ARGS) |
|
Line 1562 post_root(POST_ARGS) |
|
/* Check that we begin with a proper `Sh'. */ |
/* Check that we begin with a proper `Sh'. */ |
|
|
n = mdoc->first->child; |
n = mdoc->first->child; |
while (n != NULL && mdoc_macros[n->tok].flags & MDOC_PROLOGUE) |
while (n != NULL && n->tok != TOKEN_NONE && |
|
mdoc_macros[n->tok].flags & MDOC_PROLOGUE) |
n = n->next; |
n = n->next; |
|
|
if (n == NULL) |
if (n == NULL) |
Line 1585 post_st(POST_ARGS) |
|
Line 1587 post_st(POST_ARGS) |
|
if (NULL == (p = mdoc_a2st(nch->string))) { |
if (NULL == (p = mdoc_a2st(nch->string))) { |
mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse, |
mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse, |
nch->line, nch->pos, "St %s", nch->string); |
nch->line, nch->pos, "St %s", nch->string); |
mdoc_node_delete(mdoc, n); |
roff_node_delete(mdoc, n); |
} else { |
} else { |
free(nch->string); |
free(nch->string); |
nch->string = mandoc_strdup(p); |
nch->string = mandoc_strdup(p); |
Line 1632 post_rs(POST_ARGS) |
|
Line 1634 post_rs(POST_ARGS) |
|
|
|
/* |
/* |
* Remove this child from the chain. This somewhat |
* Remove this child from the chain. This somewhat |
* repeats mdoc_node_unlink(), but since we're |
* repeats roff_node_unlink(), but since we're |
* just re-ordering, there's no need for the |
* just re-ordering, there's no need for the |
* full unlink process. |
* full unlink process. |
*/ |
*/ |
Line 1764 post_sh_name(POST_ARGS) |
|
Line 1766 post_sh_name(POST_ARGS) |
|
mandoc_msg(MANDOCERR_NAMESEC_ND, |
mandoc_msg(MANDOCERR_NAMESEC_ND, |
mdoc->parse, n->line, n->pos, NULL); |
mdoc->parse, n->line, n->pos, NULL); |
break; |
break; |
case MDOC_MAX: |
case TOKEN_NONE: |
if (hasnm) |
if (hasnm) |
break; |
break; |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
Line 1881 post_sh_head(POST_ARGS) |
|
Line 1883 post_sh_head(POST_ARGS) |
|
|
|
secname = NULL; |
secname = NULL; |
sec = SEC_CUSTOM; |
sec = SEC_CUSTOM; |
mdoc_deroff(&secname, mdoc->last); |
deroff(&secname, mdoc->last); |
sec = NULL == secname ? SEC_CUSTOM : a2sec(secname); |
sec = NULL == secname ? SEC_CUSTOM : a2sec(secname); |
|
|
/* The NAME should be first. */ |
/* The NAME should be first. */ |
Line 2005 post_ignpar(POST_ARGS) |
|
Line 2007 post_ignpar(POST_ARGS) |
|
mdoc->parse, np->line, np->pos, |
mdoc->parse, np->line, np->pos, |
"%s after %s", mdoc_macronames[np->tok], |
"%s after %s", mdoc_macronames[np->tok], |
mdoc_macronames[mdoc->last->tok]); |
mdoc_macronames[mdoc->last->tok]); |
mdoc_node_delete(mdoc, np); |
roff_node_delete(mdoc, np); |
} |
} |
|
|
if (NULL != (np = mdoc->last->last)) |
if (NULL != (np = mdoc->last->last)) |
Line 2014 post_ignpar(POST_ARGS) |
|
Line 2016 post_ignpar(POST_ARGS) |
|
np->line, np->pos, "%s at the end of %s", |
np->line, np->pos, "%s at the end of %s", |
mdoc_macronames[np->tok], |
mdoc_macronames[np->tok], |
mdoc_macronames[mdoc->last->tok]); |
mdoc_macronames[mdoc->last->tok]); |
mdoc_node_delete(mdoc, np); |
roff_node_delete(mdoc, np); |
} |
} |
} |
} |
|
|
Line 2047 pre_par(PRE_ARGS) |
|
Line 2049 pre_par(PRE_ARGS) |
|
mdoc->last->line, mdoc->last->pos, |
mdoc->last->line, mdoc->last->pos, |
"%s before %s", mdoc_macronames[mdoc->last->tok], |
"%s before %s", mdoc_macronames[mdoc->last->tok], |
mdoc_macronames[n->tok]); |
mdoc_macronames[n->tok]); |
mdoc_node_delete(mdoc, mdoc->last); |
roff_node_delete(mdoc, mdoc->last); |
} |
} |
|
|
static void |
static void |
Line 2080 post_par(POST_ARGS) |
|
Line 2082 post_par(POST_ARGS) |
|
mdoc->last->line, mdoc->last->pos, |
mdoc->last->line, mdoc->last->pos, |
"%s after %s", mdoc_macronames[mdoc->last->tok], |
"%s after %s", mdoc_macronames[mdoc->last->tok], |
mdoc_macronames[np->tok]); |
mdoc_macronames[np->tok]); |
mdoc_node_delete(mdoc, mdoc->last); |
roff_node_delete(mdoc, mdoc->last); |
} |
} |
|
|
static void |
static void |
Line 2130 post_dd(POST_ARGS) |
|
Line 2132 post_dd(POST_ARGS) |
|
} |
} |
|
|
datestr = NULL; |
datestr = NULL; |
mdoc_deroff(&datestr, n); |
deroff(&datestr, n); |
if (mdoc->quick) |
if (mdoc->quick) |
mdoc->meta.date = datestr; |
mdoc->meta.date = datestr; |
else { |
else { |
Line 2139 post_dd(POST_ARGS) |
|
Line 2141 post_dd(POST_ARGS) |
|
free(datestr); |
free(datestr); |
} |
} |
out: |
out: |
mdoc_node_delete(mdoc, n); |
roff_node_delete(mdoc, n); |
} |
} |
|
|
static void |
static void |
Line 2224 post_dt(POST_ARGS) |
|
Line 2226 post_dt(POST_ARGS) |
|
nn->line, nn->pos, "Dt ... %s", nn->string); |
nn->line, nn->pos, "Dt ... %s", nn->string); |
|
|
out: |
out: |
mdoc_node_delete(mdoc, n); |
roff_node_delete(mdoc, n); |
} |
} |
|
|
static void |
static void |
Line 2265 post_os(POST_ARGS) |
|
Line 2267 post_os(POST_ARGS) |
|
|
|
free(mdoc->meta.os); |
free(mdoc->meta.os); |
mdoc->meta.os = NULL; |
mdoc->meta.os = NULL; |
mdoc_deroff(&mdoc->meta.os, n); |
deroff(&mdoc->meta.os, n); |
if (mdoc->meta.os) |
if (mdoc->meta.os) |
goto out; |
goto out; |
|
|
Line 2290 post_os(POST_ARGS) |
|
Line 2292 post_os(POST_ARGS) |
|
#endif /*!OSNAME*/ |
#endif /*!OSNAME*/ |
|
|
out: |
out: |
mdoc_node_delete(mdoc, n); |
roff_node_delete(mdoc, n); |
} |
} |
|
|
/* |
/* |
Line 2313 post_ex(POST_ARGS) |
|
Line 2315 post_ex(POST_ARGS) |
|
return; |
return; |
} |
} |
|
|
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = ROFF_NEXT_CHILD; |
mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name); |
roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name); |
mdoc->last = n; |
mdoc->last = n; |
} |
} |
|
|