version 1.11, 2009/06/17 09:41:00 |
version 1.22, 2009/07/06 11:05:29 |
|
|
#include <string.h> |
#include <string.h> |
|
|
#include "libmdoc.h" |
#include "libmdoc.h" |
|
#include "libmandoc.h" |
|
|
/* FIXME: .Bl -diag can't have non-text children in HEAD. */ |
/* FIXME: .Bl -diag can't have non-text children in HEAD. */ |
/* TODO: ignoring Pp (it's superfluous in some invocations). */ |
/* TODO: ignoring Pp (it's superfluous in some invocations). */ |
|
|
ELISTTYPE, |
ELISTTYPE, |
EDISPTYPE, |
EDISPTYPE, |
EMULTIDISP, |
EMULTIDISP, |
|
ESECNAME, |
EMULTILIST, |
EMULTILIST, |
EARGREP, |
EARGREP, |
EBOOL, |
EBOOL, |
ENESTDISP |
ECOLMIS, |
|
ENESTDISP, |
|
ENOWIDTH, |
|
EMISSWIDTH, |
|
EWRONGMSEC, |
|
ESECOOO, |
|
ESECREP, |
|
EBADSTAND, |
|
ENAMESECINC, |
|
ENOMULTILINE, |
|
EMULTILINE, |
|
ENOLINE, |
|
EPROLOOO, |
|
EPROLREP, |
|
EARGVAL, |
|
EBADSEC, |
|
EBADMSEC |
}; |
}; |
|
|
enum mwarn { |
|
WPRINT, |
|
WNOWIDTH, |
|
WMISSWIDTH, |
|
WESCAPE, |
|
WDEPESC, |
|
WDEPCOL, |
|
WWRONGMSEC, |
|
WSECOOO, |
|
WSECREP, |
|
WBADSTAND, |
|
WNAMESECINC, |
|
WNOMULTILINE, |
|
WMULTILINE, |
|
WLINE, |
|
WNOLINE, |
|
WPROLOOO, |
|
WPROLREP, |
|
WARGVAL, |
|
WBADSEC, |
|
WBADMSEC |
|
}; |
|
|
|
typedef int (*v_pre)(PRE_ARGS); |
typedef int (*v_pre)(PRE_ARGS); |
typedef int (*v_post)(POST_ARGS); |
typedef int (*v_post)(POST_ARGS); |
|
|
|
|
v_post *post; |
v_post *post; |
}; |
}; |
|
|
static int pwarn(struct mdoc *, int, int, enum mwarn); |
static int perr(struct mdoc *, int, int, enum merr, int); |
static int perr(struct mdoc *, int, int, 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, ...); |
Line 97 static int err_child_gt(struct mdoc *, const char *, i |
|
Line 91 static int err_child_gt(struct mdoc *, const char *, i |
|
static int warn_child_gt(struct mdoc *, const char *, int); |
static int warn_child_gt(struct mdoc *, const char *, int); |
static int err_child_eq(struct mdoc *, const char *, int); |
static int err_child_eq(struct mdoc *, const char *, int); |
static int warn_child_eq(struct mdoc *, const char *, int); |
static int warn_child_eq(struct mdoc *, const char *, int); |
static int count_child(struct mdoc *); |
|
static int warn_print(struct mdoc *, int, int); |
static int warn_print(struct mdoc *, int, int); |
static int warn_count(struct mdoc *, const char *, |
static int warn_count(struct mdoc *, const char *, |
int, const char *, int); |
int, const char *, int); |
Line 116 static int pre_fd(PRE_ARGS); |
|
Line 109 static int pre_fd(PRE_ARGS); |
|
static int pre_it(PRE_ARGS); |
static int pre_it(PRE_ARGS); |
static int pre_lb(PRE_ARGS); |
static int pre_lb(PRE_ARGS); |
static int pre_os(PRE_ARGS); |
static int pre_os(PRE_ARGS); |
static int pre_prologue(PRE_ARGS); |
|
static int pre_rv(PRE_ARGS); |
static int pre_rv(PRE_ARGS); |
static int pre_sh(PRE_ARGS); |
static int pre_sh(PRE_ARGS); |
static int pre_ss(PRE_ARGS); |
static int pre_ss(PRE_ARGS); |
Line 138 static int post_args(POST_ARGS); |
|
Line 130 static int post_args(POST_ARGS); |
|
static int post_at(POST_ARGS); |
static int post_at(POST_ARGS); |
static int post_bf(POST_ARGS); |
static int post_bf(POST_ARGS); |
static int post_bl(POST_ARGS); |
static int post_bl(POST_ARGS); |
|
static int post_bl_head(POST_ARGS); |
static int post_it(POST_ARGS); |
static int post_it(POST_ARGS); |
static int post_nm(POST_ARGS); |
static int post_nm(POST_ARGS); |
static int post_root(POST_ARGS); |
static int post_root(POST_ARGS); |
Line 148 static int post_st(POST_ARGS); |
|
Line 141 static int post_st(POST_ARGS); |
|
|
|
#define vwarn(m, t) nwarn((m), (m)->last, (t)) |
#define vwarn(m, t) nwarn((m), (m)->last, (t)) |
#define verr(m, t) nerr((m), (m)->last, (t)) |
#define verr(m, t) nerr((m), (m)->last, (t)) |
#define nwarn(m, n, t) pwarn((m), (n)->line, (n)->pos, (t)) |
#define nwarn(m, n, t) perr((m), (n)->line, (n)->pos, (t), 0) |
#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t)) |
#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t), 1) |
|
|
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 }; |
static v_pre pres_cd[] = { pre_cd, NULL }; |
static v_pre pres_cd[] = { pre_cd, NULL }; |
static v_pre pres_dd[] = { pre_prologue, pre_dd, NULL }; |
static v_pre pres_dd[] = { pre_dd, NULL }; |
static v_pre pres_d1[] = { pre_display, NULL }; |
static v_pre pres_d1[] = { pre_display, NULL }; |
static v_pre pres_dt[] = { pre_prologue, pre_dt, NULL }; |
static v_pre pres_dt[] = { pre_dt, NULL }; |
static v_pre pres_er[] = { pre_er, NULL }; |
static v_pre pres_er[] = { pre_er, NULL }; |
static v_pre pres_ex[] = { pre_ex, NULL }; |
static v_pre pres_ex[] = { pre_ex, NULL }; |
static v_pre pres_fd[] = { pre_fd, NULL }; |
static v_pre pres_fd[] = { pre_fd, NULL }; |
static v_pre pres_it[] = { pre_it, NULL }; |
static v_pre pres_it[] = { pre_it, NULL }; |
static v_pre pres_lb[] = { pre_lb, NULL }; |
static v_pre pres_lb[] = { pre_lb, NULL }; |
static v_pre pres_os[] = { pre_prologue, pre_os, NULL }; |
static v_pre pres_os[] = { pre_os, NULL }; |
static v_pre pres_rv[] = { pre_rv, NULL }; |
static v_pre pres_rv[] = { pre_rv, NULL }; |
static v_pre pres_sh[] = { pre_sh, NULL }; |
static v_pre pres_sh[] = { pre_sh, NULL }; |
static v_pre pres_ss[] = { pre_ss, NULL }; |
static v_pre pres_ss[] = { pre_ss, NULL }; |
Line 174 static v_post posts_wtext[] = { ewarn_ge1, NULL }; |
|
Line 167 static v_post posts_wtext[] = { ewarn_ge1, NULL }; |
|
static v_post posts_notext[] = { eerr_eq0, NULL }; |
static v_post posts_notext[] = { eerr_eq0, NULL }; |
static v_post posts_wline[] = { bwarn_ge1, herr_eq0, NULL }; |
static v_post posts_wline[] = { bwarn_ge1, herr_eq0, NULL }; |
static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL }; |
static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL }; |
static v_post posts_bl[] = { herr_eq0, bwarn_ge1, post_bl, NULL }; |
static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL }; |
static v_post posts_it[] = { post_it, NULL }; |
static v_post posts_it[] = { post_it, NULL }; |
static v_post posts_in[] = { ewarn_eq1, NULL }; |
static v_post posts_in[] = { ewarn_eq1, NULL }; |
static v_post posts_ss[] = { herr_ge1, NULL }; |
static v_post posts_ss[] = { herr_ge1, NULL }; |
Line 377 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 370 mdoc_valid_post(struct mdoc *mdoc) |
|
|
|
|
|
static int |
static int |
perr(struct mdoc *m, int line, int pos, enum merr type) |
perr(struct mdoc *m, int line, int pos, enum merr type, int iserr) |
{ |
{ |
char *p; |
char *p; |
|
|
p = NULL; |
p = NULL; |
|
|
switch (type) { |
switch (type) { |
case (ETOOLONG): |
case (ETOOLONG): |
p = "text argument too long"; |
p = "text argument too long"; |
Line 413 perr(struct mdoc *m, int line, int pos, enum merr type |
|
Line 407 perr(struct mdoc *m, int line, int pos, enum merr type |
|
case (EDISPTYPE): |
case (EDISPTYPE): |
p = "missing display type"; |
p = "missing display type"; |
break; |
break; |
|
case (ESECNAME): |
|
p = "the NAME section must come first"; |
|
break; |
case (ELINE): |
case (ELINE): |
p = "expected line arguments"; |
p = "expected line arguments"; |
break; |
break; |
Line 422 perr(struct mdoc *m, int line, int pos, enum merr type |
|
Line 419 perr(struct mdoc *m, int line, int pos, enum merr type |
|
case (ENODATA): |
case (ENODATA): |
p = "document has no data"; |
p = "document has no data"; |
break; |
break; |
|
case (ECOLMIS): |
|
p = "column syntax style mismatch"; |
|
break; |
case (EATT): |
case (EATT): |
p = "expected valid AT&T symbol"; |
p = "expected valid AT&T symbol"; |
break; |
break; |
case (ENAME): |
case (ENAME): |
p = "default name not yet set"; |
p = "default name not yet set"; |
break; |
break; |
} |
case (ENOWIDTH): |
assert(p); |
|
return(mdoc_perr(m, line, pos, p)); |
|
} |
|
|
|
|
|
static int |
|
pwarn(struct mdoc *m, int line, int pos, enum mwarn type) |
|
{ |
|
char *p; |
|
enum mdoc_warn c; |
|
|
|
c = WARN_SYNTAX; |
|
p = NULL; |
|
switch (type) { |
|
case (WBADMSEC): |
|
p = "inappropriate manual section"; |
|
c = WARN_COMPAT; |
|
break; |
|
case (WBADSEC): |
|
p = "inappropriate document section"; |
|
c = WARN_COMPAT; |
|
break; |
|
case (WARGVAL): |
|
p = "argument value suggested"; |
|
c = WARN_COMPAT; |
|
break; |
|
case (WPROLREP): |
|
p = "prologue macros repeated"; |
|
c = WARN_COMPAT; |
|
break; |
|
case (WPROLOOO): |
|
p = "prologue macros out-of-order"; |
|
c = WARN_COMPAT; |
|
break; |
|
case (WDEPCOL): |
|
p = "deprecated column argument syntax"; |
|
c = WARN_COMPAT; |
|
break; |
|
case (WNOWIDTH): |
|
p = "superfluous width argument"; |
p = "superfluous width argument"; |
break; |
break; |
case (WMISSWIDTH): |
case (EMISSWIDTH): |
p = "missing width argument"; |
p = "missing width argument"; |
break; |
break; |
case (WPRINT): |
case (EWRONGMSEC): |
p = "invalid character"; |
p = "document section in wrong manual section"; |
break; |
break; |
case (WESCAPE): |
case (ESECOOO): |
p = "invalid escape sequence"; |
p = "document section out of conventional order"; |
break; |
break; |
case (WDEPESC): |
case (ESECREP): |
p = "deprecated special-character escape"; |
p = "document section repeated"; |
break; |
break; |
case (WNOLINE): |
case (EBADSTAND): |
p = "suggested no line arguments"; |
p = "unknown standard"; |
break; |
break; |
case (WLINE): |
case (ENAMESECINC): |
p = "suggested line arguments"; |
p = "NAME section contents incomplete/badly-ordered"; |
break; |
break; |
case (WMULTILINE): |
case (ENOMULTILINE): |
|
p = "suggested no multi-line arguments"; |
|
break; |
|
case (EMULTILINE): |
p = "suggested multi-line arguments"; |
p = "suggested multi-line arguments"; |
break; |
break; |
case (WNOMULTILINE): |
case (ENOLINE): |
p = "suggested no multi-line arguments"; |
p = "suggested no line arguments"; |
break; |
break; |
case (WWRONGMSEC): |
case (EPROLOOO): |
p = "document section in wrong manual section"; |
p = "prologue macros out-of-order"; |
c = WARN_COMPAT; |
|
break; |
break; |
case (WSECOOO): |
case (EPROLREP): |
p = "document section out of conventional order"; |
p = "prologue macros repeated"; |
break; |
break; |
case (WSECREP): |
case (EARGVAL): |
p = "document section repeated"; |
p = "argument value suggested"; |
break; |
break; |
case (WBADSTAND): |
case (EBADMSEC): |
p = "unknown standard"; |
p = "inappropriate manual section"; |
break; |
break; |
case (WNAMESECINC): |
case (EBADSEC): |
p = "NAME section contents incomplete/badly-ordered"; |
p = "inappropriate document section"; |
break; |
break; |
} |
} |
|
|
assert(p); |
assert(p); |
return(mdoc_pwarn(m, line, pos, c, p)); |
|
|
if (iserr) |
|
return(mdoc_perr(m, line, pos, p)); |
|
|
|
return(mdoc_pwarn(m, line, pos, p)); |
} |
} |
|
|
|
|
static int |
static int |
warn_print(struct mdoc *m, int ln, int pos) |
warn_print(struct mdoc *m, int ln, int pos) |
{ |
{ |
if (MDOC_IGN_CHARS & m->pflags) |
|
return(pwarn(m, ln, pos, WPRINT)); |
return(perr(m, ln, pos, EPRINT, ! (MDOC_IGN_CHARS & m->pflags))); |
return(perr(m, ln, pos, EPRINT)); |
|
} |
} |
|
|
|
|
Line 530 warn_count(struct mdoc *m, const char *k, |
|
Line 497 warn_count(struct mdoc *m, const char *k, |
|
int want, const char *v, int has) |
int want, const char *v, int has) |
{ |
{ |
|
|
return(mdoc_warn(m, WARN_SYNTAX, |
return(mdoc_warn(m, "suggests %s %s %d (has %d)", |
"suggests %s %s %d (has %d)", v, k, want, has)); |
v, k, want, has)); |
} |
} |
|
|
|
|
Line 545 err_count(struct mdoc *m, const char *k, |
|
Line 512 err_count(struct mdoc *m, const char *k, |
|
} |
} |
|
|
|
|
static inline int |
|
count_child(struct mdoc *mdoc) |
|
{ |
|
int i; |
|
struct mdoc_node *n; |
|
|
|
for (i = 0, n = mdoc->last->child; n; n = n->next, i++) |
|
/* Do nothing */ ; |
|
|
|
return(i); |
|
} |
|
|
|
|
|
/* |
/* |
* Build these up with macros because they're basically the same check |
* Build these up with macros because they're basically the same check |
* for different inequalities. Yes, this could be done with functions, |
* for different inequalities. Yes, this could be done with functions, |
Line 568 count_child(struct mdoc *mdoc) |
|
Line 522 count_child(struct mdoc *mdoc) |
|
static int \ |
static int \ |
lvl##_child_##name(struct mdoc *mdoc, const char *p, int sz) \ |
lvl##_child_##name(struct mdoc *mdoc, const char *p, int sz) \ |
{ \ |
{ \ |
int i; \ |
if (mdoc->last->nchild ineq sz) \ |
if ((i = count_child(mdoc)) ineq sz) \ |
|
return(1); \ |
return(1); \ |
return(lvl##_count(mdoc, #ineq, sz, p, i)); \ |
return(lvl##_count(mdoc, #ineq, sz, p, mdoc->last->nchild)); \ |
} |
} |
|
|
#define CHECK_BODY_DEFN(name, lvl, func, num) \ |
#define CHECK_BODY_DEFN(name, lvl, func, num) \ |
Line 628 check_stdarg(PRE_ARGS) |
|
Line 581 check_stdarg(PRE_ARGS) |
|
if (n->args && 1 == n->args->argc) |
if (n->args && 1 == n->args->argc) |
if (MDOC_Std == n->args->argv[0].arg) |
if (MDOC_Std == n->args->argv[0].arg) |
return(1); |
return(1); |
return(nwarn(mdoc, n, WARGVAL)); |
return(nwarn(mdoc, n, EARGVAL)); |
} |
} |
|
|
|
|
Line 652 check_sec(PRE_ARGS, ...) |
|
Line 605 check_sec(PRE_ARGS, ...) |
|
} |
} |
|
|
va_end(ap); |
va_end(ap); |
return(nwarn(mdoc, n, WBADSEC)); |
return(nwarn(mdoc, n, EBADSEC)); |
} |
} |
|
|
|
|
Line 674 check_msec(PRE_ARGS, ...) |
|
Line 627 check_msec(PRE_ARGS, ...) |
|
} |
} |
|
|
va_end(ap); |
va_end(ap); |
return(nwarn(mdoc, n, WBADMSEC)); |
return(nwarn(mdoc, n, EBADMSEC)); |
} |
} |
|
|
|
|
Line 719 check_argv(struct mdoc *m, const struct mdoc_node *n, |
|
Line 672 check_argv(struct mdoc *m, const struct mdoc_node *n, |
|
static int |
static int |
check_text(struct mdoc *mdoc, int line, int pos, const char *p) |
check_text(struct mdoc *mdoc, int line, int pos, const char *p) |
{ |
{ |
size_t c; |
int c; |
|
|
for ( ; *p; p++) { |
for ( ; *p; p++, pos++) { |
if ('\t' == *p) { |
if ('\t' == *p) { |
if ( ! (MDOC_LITERAL & mdoc->flags)) |
if ( ! (MDOC_LITERAL & mdoc->flags)) |
if ( ! warn_print(mdoc, line, pos)) |
if ( ! warn_print(mdoc, line, pos)) |
Line 733 check_text(struct mdoc *mdoc, int line, int pos, const |
|
Line 686 check_text(struct mdoc *mdoc, int line, int pos, const |
|
if ('\\' != *p) |
if ('\\' != *p) |
continue; |
continue; |
|
|
c = mdoc_isescape(p); |
c = mandoc_special(p); |
if (c) { |
if (c) { |
/* See if form is deprecated. */ |
p += c - 1; |
if ('*' == p[1]) |
pos += c - 1; |
if ( ! pwarn(mdoc, line, pos, WDEPESC)) |
|
return(0); |
|
p += (int)c - 1; |
|
continue; |
continue; |
} |
} |
if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) |
if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) |
return(perr(mdoc, line, pos, EESCAPE)); |
return(perr(mdoc, line, pos, EESCAPE, 1)); |
if ( ! pwarn(mdoc, line, pos, WESCAPE)) |
if ( ! perr(mdoc, line, pos, EESCAPE, 0)) |
return(0); |
return(0); |
} |
} |
|
|
Line 794 pre_display(PRE_ARGS) |
|
Line 744 pre_display(PRE_ARGS) |
|
static int |
static int |
pre_bl(PRE_ARGS) |
pre_bl(PRE_ARGS) |
{ |
{ |
int pos, col, type, width, offset; |
int pos, type, width, offset; |
|
|
if (MDOC_BLOCK != n->type) |
if (MDOC_BLOCK != n->type) |
return(1); |
return(1); |
Line 803 pre_bl(PRE_ARGS) |
|
Line 753 pre_bl(PRE_ARGS) |
|
|
|
/* Make sure that only one type of list is specified. */ |
/* Make sure that only one type of list is specified. */ |
|
|
type = offset = width = col = -1; |
type = offset = width = -1; |
|
|
/* LINTED */ |
/* LINTED */ |
for (pos = 0; pos < (int)n->args->argc; pos++) |
for (pos = 0; pos < (int)n->args->argc; pos++) |
Line 832 pre_bl(PRE_ARGS) |
|
Line 782 pre_bl(PRE_ARGS) |
|
if (-1 != type) |
if (-1 != type) |
return(nerr(mdoc, n, EMULTILIST)); |
return(nerr(mdoc, n, EMULTILIST)); |
type = n->args->argv[pos].arg; |
type = n->args->argv[pos].arg; |
col = pos; |
|
break; |
break; |
case (MDOC_Width): |
case (MDOC_Width): |
if (-1 != width) |
if (-1 != width) |
Line 859 pre_bl(PRE_ARGS) |
|
Line 808 pre_bl(PRE_ARGS) |
|
|
|
switch (type) { |
switch (type) { |
case (MDOC_Tag): |
case (MDOC_Tag): |
if (-1 == width && ! nwarn(mdoc, n, WMISSWIDTH)) |
if (-1 == width && ! nwarn(mdoc, n, EMISSWIDTH)) |
return(0); |
return(0); |
break; |
break; |
case (MDOC_Column): |
case (MDOC_Column): |
Line 869 pre_bl(PRE_ARGS) |
|
Line 818 pre_bl(PRE_ARGS) |
|
case (MDOC_Inset): |
case (MDOC_Inset): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Item): |
case (MDOC_Item): |
if (-1 != width && ! nwarn(mdoc, n, WNOWIDTH)) |
if (-1 != width && ! nwarn(mdoc, n, ENOWIDTH)) |
return(0); |
return(0); |
break; |
break; |
default: |
default: |
break; |
break; |
} |
} |
|
|
/* |
|
* General validation of fields. |
|
*/ |
|
|
|
switch (type) { |
|
case (MDOC_Column): |
|
assert(col >= 0); |
|
if (0 == n->args->argv[col].sz) |
|
break; |
|
if ( ! nwarn(mdoc, n, WDEPCOL)) |
|
return(0); |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 1019 pre_cd(PRE_ARGS) |
|
Line 952 pre_cd(PRE_ARGS) |
|
|
|
|
|
static int |
static int |
pre_prologue(PRE_ARGS) |
|
{ |
|
|
|
return(check_sec(mdoc, n, SEC_PROLOGUE, SEC_CUSTOM)); |
|
} |
|
|
|
|
|
static int |
|
pre_dt(PRE_ARGS) |
pre_dt(PRE_ARGS) |
{ |
{ |
|
|
if (0 == mdoc->meta.date || mdoc->meta.os) |
if (0 == mdoc->meta.date || mdoc->meta.os) |
if ( ! nwarn(mdoc, n, WPROLOOO)) |
if ( ! nwarn(mdoc, n, EPROLOOO)) |
return(0); |
return(0); |
if (mdoc->meta.title) |
if (mdoc->meta.title) |
if ( ! nwarn(mdoc, n, WPROLREP)) |
if ( ! nwarn(mdoc, n, EPROLREP)) |
return(0); |
return(0); |
return(1); |
return(1); |
} |
} |
Line 1045 pre_os(PRE_ARGS) |
|
Line 970 pre_os(PRE_ARGS) |
|
{ |
{ |
|
|
if (NULL == mdoc->meta.title || 0 == mdoc->meta.date) |
if (NULL == mdoc->meta.title || 0 == mdoc->meta.date) |
if ( ! nwarn(mdoc, n, WPROLOOO)) |
if ( ! nwarn(mdoc, n, EPROLOOO)) |
return(0); |
return(0); |
if (mdoc->meta.os) |
if (mdoc->meta.os) |
if ( ! nwarn(mdoc, n, WPROLREP)) |
if ( ! nwarn(mdoc, n, EPROLREP)) |
return(0); |
return(0); |
return(1); |
return(1); |
} |
} |
Line 1059 pre_dd(PRE_ARGS) |
|
Line 984 pre_dd(PRE_ARGS) |
|
{ |
{ |
|
|
if (mdoc->meta.title || mdoc->meta.os) |
if (mdoc->meta.title || mdoc->meta.os) |
if ( ! nwarn(mdoc, n, WPROLOOO)) |
if ( ! nwarn(mdoc, n, EPROLOOO)) |
return(0); |
return(0); |
if (mdoc->meta.date) |
if (mdoc->meta.date) |
if ( ! nwarn(mdoc, n, WPROLREP)) |
if ( ! nwarn(mdoc, n, EPROLREP)) |
return(0); |
return(0); |
return(1); |
return(1); |
} |
} |
Line 1079 post_bf(POST_ARGS) |
|
Line 1004 post_bf(POST_ARGS) |
|
|
|
head = mdoc->last->head; |
head = mdoc->last->head; |
|
|
if (NULL == mdoc->last->args) { |
if (mdoc->last->args && head->child) |
if (NULL == head->child || |
return(mdoc_err(mdoc, "one argument expected")); |
MDOC_TEXT != head->child->type) |
else if (mdoc->last->args) |
return(mdoc_err(mdoc, "text argument expected")); |
return(1); |
|
|
p = head->child->string; |
if (NULL == head->child || MDOC_TEXT != head->child->type) |
if (0 == strcmp(p, "Em")) |
return(mdoc_err(mdoc, "text argument expected")); |
return(1); |
|
else if (0 == strcmp(p, "Li")) |
|
return(1); |
|
else if (0 == strcmp(p, "Sm")) |
|
return(1); |
|
return(mdoc_nerr(mdoc, head->child, "invalid font")); |
|
} |
|
|
|
if (head->child) |
p = head->child->string; |
return(mdoc_err(mdoc, "one argument expected")); |
|
|
|
return(1); |
if (0 == strcmp(p, "Em")) |
|
return(1); |
|
else if (0 == strcmp(p, "Li")) |
|
return(1); |
|
else if (0 == strcmp(p, "Sm")) |
|
return(1); |
|
|
|
return(mdoc_nerr(mdoc, head->child, "invalid font mode")); |
} |
} |
|
|
|
|
Line 1207 post_it(POST_ARGS) |
|
Line 1131 post_it(POST_ARGS) |
|
switch (type) { |
switch (type) { |
case (MDOC_Tag): |
case (MDOC_Tag): |
if (NULL == mdoc->last->head->child) |
if (NULL == mdoc->last->head->child) |
if ( ! vwarn(mdoc, WLINE)) |
if ( ! vwarn(mdoc, ELINE)) |
return(0); |
return(0); |
break; |
break; |
case (MDOC_Hang): |
case (MDOC_Hang): |
Line 1218 post_it(POST_ARGS) |
|
Line 1142 post_it(POST_ARGS) |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Diag): |
case (MDOC_Diag): |
if (NULL == mdoc->last->head->child) |
if (NULL == mdoc->last->head->child) |
if ( ! vwarn(mdoc, WLINE)) |
if ( ! vwarn(mdoc, ELINE)) |
return(0); |
return(0); |
if (NULL == mdoc->last->body->child) |
if (NULL == mdoc->last->body->child) |
if ( ! vwarn(mdoc, WMULTILINE)) |
if ( ! vwarn(mdoc, EMULTILINE)) |
return(0); |
return(0); |
break; |
break; |
case (MDOC_Bullet): |
case (MDOC_Bullet): |
Line 1234 post_it(POST_ARGS) |
|
Line 1158 post_it(POST_ARGS) |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Item): |
case (MDOC_Item): |
if (mdoc->last->head->child) |
if (mdoc->last->head->child) |
if ( ! vwarn(mdoc, WNOLINE)) |
if ( ! vwarn(mdoc, ENOLINE)) |
return(0); |
return(0); |
if (NULL == mdoc->last->body->child) |
if (NULL == mdoc->last->body->child) |
if ( ! vwarn(mdoc, WMULTILINE)) |
if ( ! vwarn(mdoc, EMULTILINE)) |
return(0); |
return(0); |
break; |
break; |
case (MDOC_Column): |
case (MDOC_Column): |
if (NULL == mdoc->last->head->child) |
if (NULL == mdoc->last->head->child) |
if ( ! vwarn(mdoc, WLINE)) |
if ( ! vwarn(mdoc, ELINE)) |
return(0); |
return(0); |
if (mdoc->last->body->child) |
if (mdoc->last->body->child) |
if ( ! vwarn(mdoc, WNOMULTILINE)) |
if ( ! vwarn(mdoc, ENOMULTILINE)) |
return(0); |
return(0); |
c = mdoc->last->child; |
c = mdoc->last->child; |
for (i = 0; c && MDOC_HEAD == c->type; c = c->next) |
for (i = 0; c && MDOC_HEAD == c->type; c = c->next) |
Line 1263 post_it(POST_ARGS) |
|
Line 1187 post_it(POST_ARGS) |
|
|
|
|
|
static int |
static int |
|
post_bl_head(POST_ARGS) |
|
{ |
|
int i; |
|
const struct mdoc_node *n; |
|
|
|
n = mdoc->last->parent; |
|
assert(n->args); |
|
|
|
for (i = 0; i < (int)n->args->argc; i++) |
|
if (n->args->argv[i].arg == MDOC_Column) |
|
break; |
|
|
|
if (i == (int)n->args->argc) |
|
return(1); |
|
|
|
if (n->args->argv[i].sz && mdoc->last->child) |
|
return(nerr(mdoc, n, ECOLMIS)); |
|
|
|
return(1); |
|
} |
|
|
|
|
|
static int |
post_bl(POST_ARGS) |
post_bl(POST_ARGS) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
|
|
if (MDOC_HEAD == mdoc->last->type) |
|
return(post_bl_head(mdoc)); |
if (MDOC_BODY != mdoc->last->type) |
if (MDOC_BODY != mdoc->last->type) |
return(1); |
return(1); |
if (NULL == mdoc->last->child) |
if (NULL == mdoc->last->child) |
Line 1313 post_root(POST_ARGS) |
|
Line 1262 post_root(POST_ARGS) |
|
|
|
if (NULL == mdoc->first->child) |
if (NULL == mdoc->first->child) |
return(verr(mdoc, ENODATA)); |
return(verr(mdoc, ENODATA)); |
if (SEC_PROLOGUE == mdoc->lastnamed) |
if ( ! (MDOC_PBODY & mdoc->flags)) |
return(verr(mdoc, ENOPROLOGUE)); |
return(verr(mdoc, ENOPROLOGUE)); |
|
|
if (MDOC_BLOCK != mdoc->first->child->type) |
if (MDOC_BLOCK != mdoc->first->child->type) |
Line 1331 post_st(POST_ARGS) |
|
Line 1280 post_st(POST_ARGS) |
|
|
|
if (mdoc_a2st(mdoc->last->child->string)) |
if (mdoc_a2st(mdoc->last->child->string)) |
return(1); |
return(1); |
return(vwarn(mdoc, WBADSTAND)); |
return(vwarn(mdoc, EBADSTAND)); |
} |
} |
|
|
|
|
Line 1363 post_sh_body(POST_ARGS) |
|
Line 1312 post_sh_body(POST_ARGS) |
|
*/ |
*/ |
|
|
if (NULL == (n = mdoc->last->child)) |
if (NULL == (n = mdoc->last->child)) |
return(vwarn(mdoc, WNAMESECINC)); |
return(vwarn(mdoc, ENAMESECINC)); |
|
|
for ( ; n && n->next; n = n->next) { |
for ( ; n && n->next; n = n->next) { |
if (MDOC_ELEM == n->type && MDOC_Nm == n->tok) |
if (MDOC_ELEM == n->type && MDOC_Nm == n->tok) |
continue; |
continue; |
if (MDOC_TEXT == n->type) |
if (MDOC_TEXT == n->type) |
continue; |
continue; |
if ( ! vwarn(mdoc, WNAMESECINC)) |
if ( ! vwarn(mdoc, ENAMESECINC)) |
return(0); |
return(0); |
} |
} |
|
|
if (MDOC_ELEM == n->type && MDOC_Nd == n->tok) |
if (MDOC_ELEM == n->type && MDOC_Nd == n->tok) |
return(1); |
return(1); |
return(vwarn(mdoc, WNAMESECINC)); |
return(vwarn(mdoc, ENAMESECINC)); |
} |
} |
|
|
|
|
Line 1394 post_sh_head(POST_ARGS) |
|
Line 1343 post_sh_head(POST_ARGS) |
|
* certain manual sections. |
* certain manual sections. |
*/ |
*/ |
|
|
assert(MDOC_Sh == mdoc->last->tok); |
|
|
|
/* This is just concat() inlined, which is irritating. */ |
|
|
|
buf[0] = 0; |
buf[0] = 0; |
|
|
for (n = mdoc->last->child; n; n = n->next) { |
for (n = mdoc->last->child; n; n = n->next) { |
|
/* XXX - copied from compact(). */ |
assert(MDOC_TEXT == n->type); |
assert(MDOC_TEXT == n->type); |
|
|
if (strlcat(buf, n->string, 64) >= 64) |
if (strlcat(buf, n->string, 64) >= 64) |
return(nerr(mdoc, n, ETOOLONG)); |
return(nerr(mdoc, n, ETOOLONG)); |
if (NULL == n->next) |
if (NULL == n->next) |
Line 1411 post_sh_head(POST_ARGS) |
|
Line 1359 post_sh_head(POST_ARGS) |
|
|
|
sec = mdoc_atosec(buf); |
sec = mdoc_atosec(buf); |
|
|
/* The NAME section should always be first. */ |
/* |
|
* Check: NAME should always be first, CUSTOM has no roles, |
|
* non-CUSTOM has a conventional order to be followed. |
|
*/ |
|
|
if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec) |
if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed) |
return(vwarn(mdoc, WSECOOO)); |
return(verr(mdoc, ESECNAME)); |
if (SEC_CUSTOM == sec) |
if (SEC_CUSTOM == sec) |
return(1); |
return(1); |
|
|
/* Check for repeated or out-of-order sections. */ |
|
|
|
if (sec == mdoc->lastnamed) |
if (sec == mdoc->lastnamed) |
return(vwarn(mdoc, WSECREP)); |
return(vwarn(mdoc, ESECREP)); |
if (sec < mdoc->lastnamed) |
if (sec < mdoc->lastnamed) |
return(vwarn(mdoc, WSECOOO)); |
return(vwarn(mdoc, ESECOOO)); |
|
|
/* Check particular section/manual section conventions. */ |
/* |
|
* Check particular section/manual conventions. LIBRARY can |
|
* only occur in msec 2, 3 (TODO: are there more of these?). |
|
*/ |
|
|
switch (sec) { |
switch (sec) { |
case (SEC_LIBRARY): |
case (SEC_LIBRARY): |
Line 1435 post_sh_head(POST_ARGS) |
|
Line 1386 post_sh_head(POST_ARGS) |
|
case (3): |
case (3): |
break; |
break; |
default: |
default: |
return(vwarn(mdoc, WWRONGMSEC)); |
return(vwarn(mdoc, EWRONGMSEC)); |
} |
} |
break; |
break; |
default: |
default: |