version 1.105, 2014/08/06 15:09:05 |
version 1.112, 2015/02/06 09:38:43 |
|
|
/* $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, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> |
|
|
* 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_eq2(CHKARGS); |
static int check_eq2(CHKARGS); |
static void check_le5(CHKARGS); |
static int check_le1(CHKARGS); |
static void check_par(CHKARGS); |
static int check_le5(CHKARGS); |
static void check_part(CHKARGS); |
static int check_par(CHKARGS); |
static void check_root(CHKARGS); |
static int check_part(CHKARGS); |
static void check_text(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_TH(CHKARGS); |
static int post_UC(CHKARGS); |
static void post_UC(CHKARGS); |
static int post_UR(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 81 static v_check man_valids[MAN_MAX] = { |
|
Line 77 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 89 static v_check man_valids[MAN_MAX] = { |
|
Line 84 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 */ |
Line 102 static v_check man_valids[MAN_MAX] = { |
|
Line 97 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 110 man_valid_post(struct man *man) |
|
Line 105 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 154 check_root(CHKARGS) |
|
Line 153 check_root(CHKARGS) |
|
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) \ |
#define INEQ_DEFINE(x, ineq, name) \ |
static int \ |
static void \ |
check_##name(CHKARGS) \ |
check_##name(CHKARGS) \ |
{ \ |
{ \ |
if (n->nchild ineq (x)) \ |
if (n->nchild ineq (x)) \ |
return(1); \ |
return; \ |
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \ |
mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \ |
"line arguments %s %d (have %d)", \ |
"line arguments %s %d (have %d)", \ |
#ineq, (x), n->nchild); \ |
#ineq, (x), n->nchild); \ |
return(1); \ |
|
} |
} |
|
|
INEQ_DEFINE(0, ==, eq0) |
|
INEQ_DEFINE(2, ==, eq2) |
INEQ_DEFINE(2, ==, eq2) |
INEQ_DEFINE(1, <=, le1) |
|
INEQ_DEFINE(5, <=, le5) |
INEQ_DEFINE(5, <=, le5) |
|
|
static int |
static void |
post_UR(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); |
|
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 246 post_ft(CHKARGS) |
|
Line 238 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 291 check_par(CHKARGS) |
|
Line 275 check_par(CHKARGS) |
|
default: |
default: |
break; |
break; |
} |
} |
|
|
return(1); |
|
} |
} |
|
|
static int |
static void |
post_IP(CHKARGS) |
post_IP(CHKARGS) |
{ |
{ |
|
|
Line 313 post_IP(CHKARGS) |
|
Line 295 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; |
Line 389 post_TH(CHKARGS) |
|
Line 370 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 404 post_TH(CHKARGS) |
|
Line 387 post_TH(CHKARGS) |
|
* 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 470 post_UC(CHKARGS) |
|
Line 446 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 508 post_AT(CHKARGS) |
|
Line 483 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 541 post_vs(CHKARGS) |
|
Line 510 post_vs(CHKARGS) |
|
default: |
default: |
break; |
break; |
} |
} |
|
|
return(1); |
|
} |
} |