version 1.103, 2014/08/01 17:40:34 |
version 1.106, 2014/08/10 23:54:41 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#ifdef HAVE_CONFIG_H |
|
#include "config.h" |
#include "config.h" |
#endif |
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
|
|
|
typedef int (*v_check)(CHKARGS); |
typedef int (*v_check)(CHKARGS); |
|
|
struct man_valid { |
|
v_check *pres; |
|
v_check *posts; |
|
}; |
|
|
|
static int check_eq0(CHKARGS); |
static int check_eq0(CHKARGS); |
static int check_eq2(CHKARGS); |
static int check_eq2(CHKARGS); |
static int check_le1(CHKARGS); |
static int check_le1(CHKARGS); |
static int check_ge2(CHKARGS); |
|
static int check_le5(CHKARGS); |
static int check_le5(CHKARGS); |
static int check_head1(CHKARGS); |
|
static int check_par(CHKARGS); |
static int check_par(CHKARGS); |
static int check_part(CHKARGS); |
static int check_part(CHKARGS); |
static int check_root(CHKARGS); |
static int check_root(CHKARGS); |
static void check_text(CHKARGS); |
static int check_text(CHKARGS); |
|
|
static int post_AT(CHKARGS); |
static int post_AT(CHKARGS); |
static int post_IP(CHKARGS); |
static int post_IP(CHKARGS); |
Line 64 static int post_ft(CHKARGS); |
|
Line 55 static int post_ft(CHKARGS); |
|
static int post_nf(CHKARGS); |
static int post_nf(CHKARGS); |
static int post_TH(CHKARGS); |
static int post_TH(CHKARGS); |
static int post_UC(CHKARGS); |
static int post_UC(CHKARGS); |
static int pre_sec(CHKARGS); |
static int post_UR(CHKARGS); |
|
|
static v_check posts_at[] = { post_AT, NULL }; |
static v_check man_valids[MAN_MAX] = { |
static v_check posts_br[] = { post_vs, check_eq0, NULL }; |
post_vs, /* br */ |
static v_check posts_eq0[] = { check_eq0, NULL }; |
post_TH, /* TH */ |
static v_check posts_eq2[] = { check_eq2, NULL }; |
NULL, /* SH */ |
static v_check posts_fi[] = { check_eq0, post_fi, NULL }; |
NULL, /* SS */ |
static v_check posts_ft[] = { post_ft, NULL }; |
NULL, /* TP */ |
static v_check posts_ip[] = { post_IP, NULL }; |
check_par, /* LP */ |
static v_check posts_le1[] = { check_le1, NULL }; |
check_par, /* PP */ |
static v_check posts_nf[] = { check_eq0, post_nf, NULL }; |
check_par, /* P */ |
static v_check posts_par[] = { check_par, NULL }; |
post_IP, /* IP */ |
static v_check posts_part[] = { check_part, NULL }; |
NULL, /* HP */ |
static v_check posts_sp[] = { post_vs, check_le1, NULL }; |
NULL, /* SM */ |
static v_check posts_th[] = { check_ge2, check_le5, post_TH, NULL }; |
NULL, /* SB */ |
static v_check posts_uc[] = { post_UC, NULL }; |
NULL, /* BI */ |
static v_check posts_ur[] = { check_head1, check_part, NULL }; |
NULL, /* IB */ |
static v_check pres_sec[] = { pre_sec, NULL }; |
NULL, /* BR */ |
|
NULL, /* RB */ |
static const struct man_valid man_valids[MAN_MAX] = { |
NULL, /* R */ |
{ NULL, posts_br }, /* br */ |
NULL, /* B */ |
{ NULL, posts_th }, /* TH */ |
NULL, /* I */ |
{ pres_sec, NULL }, /* SH */ |
NULL, /* IR */ |
{ pres_sec, NULL }, /* SS */ |
NULL, /* RI */ |
{ NULL, NULL }, /* TP */ |
check_eq0, /* na */ |
{ NULL, posts_par }, /* LP */ |
post_vs, /* sp */ |
{ NULL, posts_par }, /* PP */ |
post_nf, /* nf */ |
{ NULL, posts_par }, /* P */ |
post_fi, /* fi */ |
{ NULL, posts_ip }, /* IP */ |
NULL, /* RE */ |
{ NULL, NULL }, /* HP */ |
check_part, /* RS */ |
{ NULL, NULL }, /* SM */ |
NULL, /* DT */ |
{ NULL, NULL }, /* SB */ |
post_UC, /* UC */ |
{ NULL, NULL }, /* BI */ |
check_le1, /* PD */ |
{ NULL, NULL }, /* IB */ |
post_AT, /* AT */ |
{ NULL, NULL }, /* BR */ |
NULL, /* in */ |
{ NULL, NULL }, /* RB */ |
post_ft, /* ft */ |
{ NULL, NULL }, /* R */ |
check_eq2, /* OP */ |
{ NULL, NULL }, /* B */ |
post_nf, /* EX */ |
{ NULL, NULL }, /* I */ |
post_fi, /* EE */ |
{ NULL, NULL }, /* IR */ |
post_UR, /* UR */ |
{ NULL, NULL }, /* RI */ |
NULL, /* UE */ |
{ NULL, posts_eq0 }, /* na */ |
NULL, /* ll */ |
{ NULL, posts_sp }, /* sp */ |
|
{ NULL, posts_nf }, /* nf */ |
|
{ NULL, posts_fi }, /* fi */ |
|
{ NULL, NULL }, /* RE */ |
|
{ NULL, posts_part }, /* RS */ |
|
{ NULL, NULL }, /* DT */ |
|
{ NULL, posts_uc }, /* UC */ |
|
{ NULL, posts_le1 }, /* PD */ |
|
{ NULL, posts_at }, /* AT */ |
|
{ NULL, NULL }, /* in */ |
|
{ NULL, posts_ft }, /* ft */ |
|
{ NULL, posts_eq2 }, /* OP */ |
|
{ NULL, posts_nf }, /* EX */ |
|
{ NULL, posts_fi }, /* EE */ |
|
{ NULL, posts_ur }, /* UR */ |
|
{ NULL, NULL }, /* UE */ |
|
{ NULL, NULL }, /* ll */ |
|
}; |
}; |
|
|
|
|
int |
int |
man_valid_pre(struct man *man, struct man_node *n) |
|
{ |
|
v_check *cp; |
|
|
|
switch (n->type) { |
|
case MAN_TEXT: |
|
/* FALLTHROUGH */ |
|
case MAN_ROOT: |
|
/* FALLTHROUGH */ |
|
case MAN_EQN: |
|
/* FALLTHROUGH */ |
|
case MAN_TBL: |
|
return(1); |
|
default: |
|
break; |
|
} |
|
|
|
if (NULL == (cp = man_valids[n->tok].pres)) |
|
return(1); |
|
for ( ; *cp; cp++) |
|
if ( ! (*cp)(man, n)) |
|
return(0); |
|
return(1); |
|
} |
|
|
|
int |
|
man_valid_post(struct man *man) |
man_valid_post(struct man *man) |
{ |
{ |
|
struct man_node *n; |
v_check *cp; |
v_check *cp; |
|
|
if (MAN_VALID & man->last->flags) |
n = man->last; |
|
if (n->flags & MAN_VALID) |
return(1); |
return(1); |
man->last->flags |= MAN_VALID; |
n->flags |= MAN_VALID; |
|
|
switch (man->last->type) { |
switch (n->type) { |
case MAN_TEXT: |
case MAN_TEXT: |
check_text(man, man->last); |
return(check_text(man, n)); |
return(1); |
|
case MAN_ROOT: |
case MAN_ROOT: |
return(check_root(man, man->last)); |
return(check_root(man, n)); |
case MAN_EQN: |
case MAN_EQN: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MAN_TBL: |
case MAN_TBL: |
return(1); |
return(1); |
default: |
default: |
break; |
cp = man_valids + n->tok; |
|
return(*cp ? (*cp)(man, n) : 1); |
} |
} |
|
|
if (NULL == (cp = man_valids[man->last->tok].posts)) |
|
return(1); |
|
for ( ; *cp; cp++) |
|
if ( ! (*cp)(man, man->last)) |
|
return(0); |
|
|
|
return(1); |
|
} |
} |
|
|
static int |
static int |
Line 197 check_root(CHKARGS) |
|
Line 139 check_root(CHKARGS) |
|
man->meta.hasbody = 1; |
man->meta.hasbody = 1; |
|
|
if (NULL == man->meta.title) { |
if (NULL == man->meta.title) { |
mandoc_msg(MANDOCERR_TH_MISSING, man->parse, |
mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse, |
n->line, n->pos, NULL); |
n->line, n->pos, NULL); |
|
|
/* |
/* |
Line 205 check_root(CHKARGS) |
|
Line 147 check_root(CHKARGS) |
|
* implication, date and section also aren't set). |
* implication, date and section also aren't set). |
*/ |
*/ |
|
|
man->meta.title = mandoc_strdup("unknown"); |
man->meta.title = mandoc_strdup(""); |
man->meta.msec = mandoc_strdup("1"); |
man->meta.msec = mandoc_strdup(""); |
man->meta.date = man->quick ? mandoc_strdup("") : |
man->meta.date = man->quick ? mandoc_strdup("") : |
mandoc_normdate(man->parse, NULL, n->line, n->pos); |
mandoc_normdate(man->parse, NULL, n->line, n->pos); |
} |
} |
Line 214 check_root(CHKARGS) |
|
Line 156 check_root(CHKARGS) |
|
return(1); |
return(1); |
} |
} |
|
|
static void |
static int |
check_text(CHKARGS) |
check_text(CHKARGS) |
{ |
{ |
char *cp, *p; |
char *cp, *p; |
|
|
if (MAN_LITERAL & man->flags) |
if (MAN_LITERAL & man->flags) |
return; |
return(1); |
|
|
cp = n->string; |
cp = n->string; |
for (p = cp; NULL != (p = strchr(p, '\t')); p++) |
for (p = cp; NULL != (p = strchr(p, '\t')); p++) |
mandoc_msg(MANDOCERR_FI_TAB, man->parse, |
mandoc_msg(MANDOCERR_FI_TAB, man->parse, |
n->line, n->pos + (p - cp), NULL); |
n->line, n->pos + (p - cp), NULL); |
|
return(1); |
} |
} |
|
|
#define INEQ_DEFINE(x, ineq, name) \ |
#define INEQ_DEFINE(x, ineq, name) \ |
Line 243 check_##name(CHKARGS) \ |
|
Line 186 check_##name(CHKARGS) \ |
|
INEQ_DEFINE(0, ==, eq0) |
INEQ_DEFINE(0, ==, eq0) |
INEQ_DEFINE(2, ==, eq2) |
INEQ_DEFINE(2, ==, eq2) |
INEQ_DEFINE(1, <=, le1) |
INEQ_DEFINE(1, <=, le1) |
INEQ_DEFINE(2, >=, ge2) |
|
INEQ_DEFINE(5, <=, le5) |
INEQ_DEFINE(5, <=, le5) |
|
|
static int |
static int |
check_head1(CHKARGS) |
post_UR(CHKARGS) |
{ |
{ |
|
|
if (MAN_HEAD == n->type && 1 != n->nchild) |
if (MAN_HEAD == n->type && 1 != n->nchild) |
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, |
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, |
n->pos, "line arguments eq 1 (have %d)", n->nchild); |
n->pos, "line arguments eq 1 (have %d)", n->nchild); |
|
|
return(1); |
return(check_part(man, n)); |
} |
} |
|
|
static int |
static int |
Line 311 post_ft(CHKARGS) |
|
Line 253 post_ft(CHKARGS) |
|
} |
} |
|
|
static int |
static int |
pre_sec(CHKARGS) |
|
{ |
|
|
|
if (MAN_BLOCK == n->type) |
|
man->flags &= ~MAN_LITERAL; |
|
return(1); |
|
} |
|
|
|
static int |
|
check_part(CHKARGS) |
check_part(CHKARGS) |
{ |
{ |
|
|
Line 387 post_TH(CHKARGS) |
|
Line 320 post_TH(CHKARGS) |
|
struct man_node *nb; |
struct man_node *nb; |
const char *p; |
const char *p; |
|
|
|
check_le5(man, n); |
|
|
free(man->meta.title); |
free(man->meta.title); |
free(man->meta.vol); |
free(man->meta.vol); |
free(man->meta.source); |
free(man->meta.source); |
Line 414 post_TH(CHKARGS) |
|
Line 349 post_TH(CHKARGS) |
|
} |
} |
} |
} |
man->meta.title = mandoc_strdup(n->string); |
man->meta.title = mandoc_strdup(n->string); |
} else |
} else { |
man->meta.title = mandoc_strdup(""); |
man->meta.title = mandoc_strdup(""); |
|
mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse, |
|
nb->line, nb->pos, "TH"); |
|
} |
|
|
/* TITLE ->MSEC<- DATE SOURCE VOL */ |
/* TITLE ->MSEC<- DATE SOURCE VOL */ |
|
|
Line 423 post_TH(CHKARGS) |
|
Line 361 post_TH(CHKARGS) |
|
n = n->next; |
n = n->next; |
if (n && n->string) |
if (n && n->string) |
man->meta.msec = mandoc_strdup(n->string); |
man->meta.msec = mandoc_strdup(n->string); |
else |
else { |
man->meta.msec = mandoc_strdup(""); |
man->meta.msec = mandoc_strdup(""); |
|
mandoc_vmsg(MANDOCERR_MSEC_MISSING, man->parse, |
|
nb->line, nb->pos, "TH %s", man->meta.title); |
|
} |
|
|
/* TITLE MSEC ->DATE<- SOURCE VOL */ |
/* TITLE MSEC ->DATE<- SOURCE VOL */ |
|
|
|
|
post_nf(CHKARGS) |
post_nf(CHKARGS) |
{ |
{ |
|
|
|
check_eq0(man, n); |
|
|
if (MAN_LITERAL & man->flags) |
if (MAN_LITERAL & man->flags) |
mandoc_msg(MANDOCERR_NF_SKIP, man->parse, |
mandoc_msg(MANDOCERR_NF_SKIP, man->parse, |
n->line, n->pos, "nf"); |
n->line, n->pos, "nf"); |
|
|
post_fi(CHKARGS) |
post_fi(CHKARGS) |
{ |
{ |
|
|
|
check_eq0(man, n); |
|
|
if ( ! (MAN_LITERAL & man->flags)) |
if ( ! (MAN_LITERAL & man->flags)) |
mandoc_msg(MANDOCERR_FI_SKIP, man->parse, |
mandoc_msg(MANDOCERR_FI_SKIP, man->parse, |
n->line, n->pos, "fi"); |
n->line, n->pos, "fi"); |
Line 567 post_AT(CHKARGS) |
|
Line 512 post_AT(CHKARGS) |
|
static int |
static int |
post_vs(CHKARGS) |
post_vs(CHKARGS) |
{ |
{ |
|
|
|
if (n->tok == MAN_br) |
|
check_eq0(man, n); |
|
else |
|
check_le1(man, n); |
|
|
if (NULL != n->prev) |
if (NULL != n->prev) |
return(1); |
return(1); |