version 1.83, 2009/03/13 13:56:13 |
version 1.85, 2009/03/16 23:37:28 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the |
* purpose with or without fee is hereby granted, provided that the |
|
|
#define POST_ARGS struct mdoc *mdoc |
#define POST_ARGS struct mdoc *mdoc |
|
|
enum merr { |
enum merr { |
|
EPRINT, |
ENODATA, |
ENODATA, |
ENOPROLOGUE, |
ENOPROLOGUE, |
ELINE, |
ELINE, |
|
|
|
|
/* Utility checks. */ |
/* Utility checks. */ |
|
|
static int nwarn(struct mdoc *, |
static int pwarn(struct mdoc *, int, int, enum mwarn); |
const struct mdoc_node *, enum mwarn); |
static int perr(struct mdoc *, int, int, enum merr); |
static int nerr(struct mdoc *, |
|
const struct mdoc_node *, enum merr); |
|
static int check_parent(PRE_ARGS, int, enum mdoc_type); |
static int check_parent(PRE_ARGS, int, enum mdoc_type); |
static int check_msec(PRE_ARGS, ...); |
static int check_msec(PRE_ARGS, ...); |
static int check_sec(PRE_ARGS, ...); |
static int check_sec(PRE_ARGS, ...); |
static int check_stdarg(PRE_ARGS); |
static int check_stdarg(PRE_ARGS); |
static int check_text(struct mdoc *, |
static int check_text(struct mdoc *, int, int, const char *); |
int, int, const char *); |
|
static int check_argv(struct mdoc *, |
static int check_argv(struct mdoc *, |
const struct mdoc_node *, |
const struct mdoc_node *, |
const struct mdoc_argv *); |
const struct mdoc_argv *); |
Line 151 static int post_sh_body(POST_ARGS); |
|
Line 149 static int post_sh_body(POST_ARGS); |
|
static int post_sh_head(POST_ARGS); |
static int post_sh_head(POST_ARGS); |
static int post_st(POST_ARGS); |
static int post_st(POST_ARGS); |
|
|
|
#define mwarn(m, t) nwarn((m), (m)->last, (t)) |
|
#define merr(m, t) nerr((m), (m)->last, (t)) |
|
#define nwarn(m, n, t) pwarn((m), (n)->line, (n)->pos, (t)) |
|
#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t)) |
|
|
static v_pre pres_an[] = { pre_an, NULL }; |
static v_pre pres_an[] = { pre_an, NULL }; |
static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; |
static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; |
static v_pre pres_bl[] = { pre_bl, NULL }; |
static v_pre pres_bl[] = { pre_bl, NULL }; |
Line 310 const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 313 const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Bro */ |
{ NULL, NULL }, /* Bro */ |
{ NULL, NULL }, /* Brc */ |
{ NULL, NULL }, /* Brc */ |
{ NULL, posts_text }, /* %C */ |
{ NULL, posts_text }, /* %C */ |
|
{ NULL, NULL }, /* Es */ |
|
{ NULL, NULL }, /* En */ |
|
{ NULL, NULL }, /* Dx */ |
}; |
}; |
|
|
|
|
int |
int |
mdoc_valid_pre(struct mdoc *mdoc, |
mdoc_valid_pre(struct mdoc *mdoc, |
const struct mdoc_node *node) |
const struct mdoc_node *n) |
{ |
{ |
v_pre *p; |
v_pre *p; |
int line, pos; |
int line, pos; |
const char *tp; |
const char *tp; |
|
|
if (MDOC_TEXT == node->type) { |
if (MDOC_TEXT == n->type) { |
tp = node->string; |
tp = n->string; |
line = node->line; |
line = n->line; |
pos = node->pos; |
pos = n->pos; |
return(check_text(mdoc, line, pos, tp)); |
return(check_text(mdoc, line, pos, tp)); |
} |
} |
|
|
if ( ! check_args(mdoc, node)) |
if ( ! check_args(mdoc, n)) |
return(0); |
return(0); |
if (NULL == mdoc_valids[node->tok].pre) |
if (NULL == mdoc_valids[n->tok].pre) |
return(1); |
return(1); |
for (p = mdoc_valids[node->tok].pre; *p; p++) |
for (p = mdoc_valids[n->tok].pre; *p; p++) |
if ( ! (*p)(mdoc, node)) |
if ( ! (*p)(mdoc, n)) |
return(0); |
return(0); |
return(1); |
return(1); |
} |
} |
Line 371 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 377 mdoc_valid_post(struct mdoc *mdoc) |
|
} |
} |
|
|
|
|
#define merr(m, t) nerr((m), (m)->last, (t)) |
|
static int |
static int |
nerr(struct mdoc *m, const struct mdoc_node *n, enum merr type) |
perr(struct mdoc *m, int line, int pos, enum merr type) |
{ |
{ |
char *p; |
char *p; |
|
|
p = NULL; |
p = NULL; |
|
|
switch (type) { |
switch (type) { |
|
case (EPRINT): |
|
p = "invalid character"; |
|
break; |
case (ENESTDISP): |
case (ENESTDISP): |
p = "displays may not be nested"; |
p = "displays may not be nested"; |
break; |
break; |
Line 417 nerr(struct mdoc *m, const struct mdoc_node *n, enum m |
|
Line 424 nerr(struct mdoc *m, const struct mdoc_node *n, enum m |
|
p = "default name not yet set"; |
p = "default name not yet set"; |
break; |
break; |
} |
} |
|
|
assert(p); |
assert(p); |
return(mdoc_nerr(m, n, p)); |
return(mdoc_perr(m, line, pos, p)); |
} |
} |
|
|
|
|
#define mwarn(m, t) nwarn((m), (m)->last, (t)) |
|
static int |
static int |
nwarn(struct mdoc *m, const struct mdoc_node *n, enum mwarn type) |
pwarn(struct mdoc *m, int line, int pos, enum mwarn type) |
{ |
{ |
char *p; |
char *p; |
enum mdoc_warn c; |
enum mdoc_warn c; |
|
|
c = WARN_SYNTAX; |
c = WARN_SYNTAX; |
p = NULL; |
p = NULL; |
|
|
switch (type) { |
switch (type) { |
case (WBADMSEC): |
case (WBADMSEC): |
p = "inappropriate manual section"; |
p = "inappropriate manual section"; |
Line 484 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
Line 488 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
break; |
break; |
} |
} |
assert(p); |
assert(p); |
return(mdoc_nwarn(m, n, c, p)); |
return(mdoc_pwarn(m, line, pos, c, p)); |
} |
} |
|
|
|
|
Line 685 check_text(struct mdoc *mdoc, int line, int pos, const |
|
Line 689 check_text(struct mdoc *mdoc, int line, int pos, const |
|
{ |
{ |
size_t c; |
size_t c; |
|
|
/* XXX - indicate deprecated escapes \*(xx and \*x. */ |
/* FIXME: indicate deprecated escapes \*(xx and \*x. */ |
|
/* FIXME: don't allow tabs unless in literal mode. */ |
|
|
for ( ; *p; p++) { |
for ( ; *p; p++) { |
if ( ! isprint((u_char)*p) && '\t' != *p) |
if ('\t' != *p && ! isprint((u_char)*p)) |
return(mdoc_perr(mdoc, line, pos, |
return(perr(mdoc, line, pos, EPRINT)); |
"invalid non-printing character")); |
|
if ('\\' != *p) |
if ('\\' != *p) |
continue; |
continue; |
if ((c = mdoc_isescape(p))) { |
if ((c = mdoc_isescape(p))) { |