version 1.104, 2014/08/01 21:24:17 |
version 1.113, 2015/02/06 11:54:36 |
|
|
/* $Id$ */ |
/* $OpenBSD$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@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 above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
* 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> |
|
|
|
|
|
|
#define CHKARGS struct man *man, struct man_node *n |
#define CHKARGS struct man *man, struct man_node *n |
|
|
typedef int (*v_check)(CHKARGS); |
typedef void (*v_check)(CHKARGS); |
|
|
static int check_eq0(CHKARGS); |
static void check_par(CHKARGS); |
static int check_eq2(CHKARGS); |
static void check_part(CHKARGS); |
static int check_le1(CHKARGS); |
static void check_root(CHKARGS); |
static int check_ge2(CHKARGS); |
static void check_text(CHKARGS); |
static int check_le5(CHKARGS); |
|
static int check_par(CHKARGS); |
|
static int check_part(CHKARGS); |
|
static int check_root(CHKARGS); |
|
static int check_text(CHKARGS); |
|
|
|
static int post_AT(CHKARGS); |
static void post_AT(CHKARGS); |
static int post_IP(CHKARGS); |
static void post_IP(CHKARGS); |
static int post_vs(CHKARGS); |
static void post_vs(CHKARGS); |
static int post_fi(CHKARGS); |
static void post_fi(CHKARGS); |
static int post_ft(CHKARGS); |
static void post_ft(CHKARGS); |
static int post_nf(CHKARGS); |
static void post_nf(CHKARGS); |
static int post_TH(CHKARGS); |
static void post_OP(CHKARGS); |
static int post_UC(CHKARGS); |
static void post_TH(CHKARGS); |
static int post_UR(CHKARGS); |
static void post_UC(CHKARGS); |
|
static void post_UR(CHKARGS); |
|
|
static v_check man_valids[MAN_MAX] = { |
static v_check man_valids[MAN_MAX] = { |
post_vs, /* br */ |
post_vs, /* br */ |
Line 82 static v_check man_valids[MAN_MAX] = { |
|
Line 76 static v_check man_valids[MAN_MAX] = { |
|
NULL, /* I */ |
NULL, /* I */ |
NULL, /* IR */ |
NULL, /* IR */ |
NULL, /* RI */ |
NULL, /* RI */ |
check_eq0, /* na */ |
|
post_vs, /* sp */ |
post_vs, /* sp */ |
post_nf, /* nf */ |
post_nf, /* nf */ |
post_fi, /* fi */ |
post_fi, /* fi */ |
Line 90 static v_check man_valids[MAN_MAX] = { |
|
Line 83 static v_check man_valids[MAN_MAX] = { |
|
check_part, /* RS */ |
check_part, /* RS */ |
NULL, /* DT */ |
NULL, /* DT */ |
post_UC, /* UC */ |
post_UC, /* UC */ |
check_le1, /* PD */ |
NULL, /* PD */ |
post_AT, /* AT */ |
post_AT, /* AT */ |
NULL, /* in */ |
NULL, /* in */ |
post_ft, /* ft */ |
post_ft, /* ft */ |
check_eq2, /* OP */ |
post_OP, /* OP */ |
post_nf, /* EX */ |
post_nf, /* EX */ |
post_fi, /* EE */ |
post_fi, /* EE */ |
post_UR, /* UR */ |
post_UR, /* UR */ |
Line 103 static v_check man_valids[MAN_MAX] = { |
|
Line 96 static v_check man_valids[MAN_MAX] = { |
|
}; |
}; |
|
|
|
|
int |
void |
man_valid_post(struct man *man) |
man_valid_post(struct man *man) |
{ |
{ |
struct man_node *n; |
struct man_node *n; |
Line 111 man_valid_post(struct man *man) |
|
Line 104 man_valid_post(struct man *man) |
|
|
|
n = man->last; |
n = man->last; |
if (n->flags & MAN_VALID) |
if (n->flags & MAN_VALID) |
return(1); |
return; |
n->flags |= MAN_VALID; |
n->flags |= MAN_VALID; |
|
|
switch (n->type) { |
switch (n->type) { |
case MAN_TEXT: |
case MAN_TEXT: |
return(check_text(man, n)); |
check_text(man, n); |
|
break; |
case MAN_ROOT: |
case MAN_ROOT: |
return(check_root(man, n)); |
check_root(man, n); |
|
break; |
case MAN_EQN: |
case MAN_EQN: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MAN_TBL: |
case MAN_TBL: |
return(1); |
break; |
default: |
default: |
cp = man_valids + n->tok; |
cp = man_valids + n->tok; |
return(*cp ? (*cp)(man, n) : 1); |
if (*cp) |
|
(*cp)(man, n); |
|
break; |
} |
} |
} |
} |
|
|
static int |
static void |
check_root(CHKARGS) |
check_root(CHKARGS) |
{ |
{ |
|
|
Line 142 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 150 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); |
} |
} |
|
|
return(1); |
|
} |
} |
|
|
static int |
static void |
check_text(CHKARGS) |
check_text(CHKARGS) |
{ |
{ |
char *cp, *p; |
char *cp, *p; |
|
|
if (MAN_LITERAL & man->flags) |
if (MAN_LITERAL & man->flags) |
return(1); |
return; |
|
|
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) \ |
static void |
static int \ |
post_OP(CHKARGS) |
check_##name(CHKARGS) \ |
{ |
{ \ |
|
if (n->nchild ineq (x)) \ |
if (n->nchild == 0) |
return(1); \ |
mandoc_msg(MANDOCERR_OP_EMPTY, man->parse, |
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \ |
n->line, n->pos, "OP"); |
"line arguments %s %d (have %d)", \ |
else if (n->nchild > 2) { |
#ineq, (x), n->nchild); \ |
n = n->child->next->next; |
return(1); \ |
mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, |
|
n->line, n->pos, "OP ... %s", n->string); |
|
} |
} |
} |
|
|
INEQ_DEFINE(0, ==, eq0) |
static void |
INEQ_DEFINE(2, ==, eq2) |
|
INEQ_DEFINE(1, <=, le1) |
|
INEQ_DEFINE(2, >=, ge2) |
|
INEQ_DEFINE(5, <=, le5) |
|
|
|
static int |
|
post_UR(CHKARGS) |
post_UR(CHKARGS) |
{ |
{ |
|
|
if (MAN_HEAD == n->type && 1 != n->nchild) |
if (n->type == MAN_HEAD && n->child == NULL) |
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, |
mandoc_vmsg(MANDOCERR_UR_NOHEAD, man->parse, |
n->pos, "line arguments eq 1 (have %d)", n->nchild); |
n->line, n->pos, "UR"); |
|
check_part(man, n); |
return(check_part(man, n)); |
|
} |
} |
|
|
static int |
static void |
post_ft(CHKARGS) |
post_ft(CHKARGS) |
{ |
{ |
char *cp; |
char *cp; |
int ok; |
int ok; |
|
|
if (0 == n->nchild) |
if (0 == n->nchild) |
return(1); |
return; |
|
|
ok = 0; |
ok = 0; |
cp = n->child->string; |
cp = n->child->string; |
Line 248 post_ft(CHKARGS) |
|
Line 237 post_ft(CHKARGS) |
|
n->line, n->pos, "ft %s", cp); |
n->line, n->pos, "ft %s", cp); |
*cp = '\0'; |
*cp = '\0'; |
} |
} |
|
|
if (1 < n->nchild) |
|
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, |
|
n->pos, "want one child (have %d)", n->nchild); |
|
|
|
return(1); |
|
} |
} |
|
|
static int |
static void |
check_part(CHKARGS) |
check_part(CHKARGS) |
{ |
{ |
|
|
if (MAN_BODY == n->type && 0 == n->nchild) |
if (n->type == MAN_BODY && n->child == NULL) |
mandoc_msg(MANDOCERR_ARGCWARN, man->parse, n->line, |
mandoc_msg(MANDOCERR_BLK_EMPTY, man->parse, |
n->pos, "want children (have none)"); |
n->line, n->pos, man_macronames[n->tok]); |
|
|
return(1); |
|
} |
} |
|
|
static int |
static void |
check_par(CHKARGS) |
check_par(CHKARGS) |
{ |
{ |
|
|
Line 293 check_par(CHKARGS) |
|
Line 274 check_par(CHKARGS) |
|
default: |
default: |
break; |
break; |
} |
} |
|
|
return(1); |
|
} |
} |
|
|
static int |
static void |
post_IP(CHKARGS) |
post_IP(CHKARGS) |
{ |
{ |
|
|
Line 315 post_IP(CHKARGS) |
|
Line 294 post_IP(CHKARGS) |
|
default: |
default: |
break; |
break; |
} |
} |
return(1); |
|
} |
} |
|
|
static int |
static void |
post_TH(CHKARGS) |
post_TH(CHKARGS) |
{ |
{ |
struct man_node *nb; |
struct man_node *nb; |
const char *p; |
const char *p; |
|
|
check_ge2(man, n); |
|
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 354 post_TH(CHKARGS) |
|
Line 329 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 363 post_TH(CHKARGS) |
|
Line 341 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 */ |
|
|
Line 386 post_TH(CHKARGS) |
|
Line 367 post_TH(CHKARGS) |
|
|
|
if (n && (n = n->next)) |
if (n && (n = n->next)) |
man->meta.source = mandoc_strdup(n->string); |
man->meta.source = mandoc_strdup(n->string); |
|
else if (man->defos != NULL) |
|
man->meta.source = mandoc_strdup(man->defos); |
|
|
/* TITLE MSEC DATE SOURCE ->VOL<- */ |
/* TITLE MSEC DATE SOURCE ->VOL<- */ |
/* If missing, use the default VOL name for MSEC. */ |
/* If missing, use the default VOL name for MSEC. */ |
Line 396 post_TH(CHKARGS) |
|
Line 379 post_TH(CHKARGS) |
|
(NULL != (p = mandoc_a2msec(man->meta.msec)))) |
(NULL != (p = mandoc_a2msec(man->meta.msec)))) |
man->meta.vol = mandoc_strdup(p); |
man->meta.vol = mandoc_strdup(p); |
|
|
|
if (n != NULL && (n = n->next) != NULL) |
|
mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, |
|
n->line, n->pos, "TH ... %s", n->string); |
|
|
/* |
/* |
* Remove the `TH' node after we've processed it for our |
* Remove the `TH' node after we've processed it for our |
* meta-data. |
* meta-data. |
*/ |
*/ |
man_node_delete(man, man->last); |
man_node_delete(man, man->last); |
return(1); |
|
} |
} |
|
|
static int |
static void |
post_nf(CHKARGS) |
post_nf(CHKARGS) |
{ |
{ |
|
|
check_eq0(man, n); |
if (man->flags & MAN_LITERAL) |
|
|
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"); |
|
|
man->flags |= MAN_LITERAL; |
man->flags |= MAN_LITERAL; |
return(1); |
|
} |
} |
|
|
static int |
static void |
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"); |
|
|
man->flags &= ~MAN_LITERAL; |
man->flags &= ~MAN_LITERAL; |
return(1); |
|
} |
} |
|
|
static int |
static void |
post_UC(CHKARGS) |
post_UC(CHKARGS) |
{ |
{ |
static const char * const bsd_versions[] = { |
static const char * const bsd_versions[] = { |
Line 467 post_UC(CHKARGS) |
|
Line 447 post_UC(CHKARGS) |
|
|
|
free(man->meta.source); |
free(man->meta.source); |
man->meta.source = mandoc_strdup(p); |
man->meta.source = mandoc_strdup(p); |
return(1); |
|
} |
} |
|
|
static int |
static void |
post_AT(CHKARGS) |
post_AT(CHKARGS) |
{ |
{ |
static const char * const unix_versions[] = { |
static const char * const unix_versions[] = { |
Line 505 post_AT(CHKARGS) |
|
Line 484 post_AT(CHKARGS) |
|
|
|
free(man->meta.source); |
free(man->meta.source); |
man->meta.source = mandoc_strdup(p); |
man->meta.source = mandoc_strdup(p); |
return(1); |
|
} |
} |
|
|
static int |
static void |
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; |
|
|
switch (n->parent->tok) { |
switch (n->parent->tok) { |
case MAN_SH: |
case MAN_SH: |
Line 538 post_vs(CHKARGS) |
|
Line 511 post_vs(CHKARGS) |
|
default: |
default: |
break; |
break; |
} |
} |
|
|
return(1); |
|
} |
} |