355b4669e025ff377602b6fc7caaf30dbc218371jacobs/* $OpenBSD$ */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Copyright (c) 2010, 2012-2016 Ingo Schwarze <schwarze@openbsd.org>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Permission to use, copy, modify, and distribute this software for any
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * purpose with or without fee is hereby granted, provided that the above
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * copyright notice and this permission notice appear in all copies.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "config.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <sys/types.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <assert.h>
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India"#include <ctype.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <errno.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <limits.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdarg.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <stdlib.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <string.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include <time.h>
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "mandoc_aux.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "mandoc.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "roff.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "man.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "libmandoc.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "roff_int.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#include "libman.h"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs#define CHKARGS struct roff_man *man, struct roff_node *n
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobstypedef void (*v_check)(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void check_par(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void check_part(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void check_root(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void check_text(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void post_AT(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void post_IP(CHKARGS);
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India"static void post_vs(CHKARGS);
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India"static void post_ft(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void post_OP(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void post_TH(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void post_UC(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void post_UR(CHKARGS);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic v_check man_valids[MAN_MAX] = {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_vs, /* br */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_TH, /* TH */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* SH */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* SS */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* TP */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_par, /* LP */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_par, /* PP */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_par, /* P */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_IP, /* IP */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* HP */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* SM */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* SB */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* BI */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* IB */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* BR */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* RB */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* R */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* B */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* I */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* IR */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* RI */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_vs, /* sp */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* nf */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* fi */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* RE */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_part, /* RS */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* DT */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_UC, /* UC */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* PD */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_AT, /* AT */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* in */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_ft, /* ft */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_OP, /* OP */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* EX */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* EE */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs post_UR, /* UR */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* UE */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs NULL, /* ll */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs};
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsvoid
355b4669e025ff377602b6fc7caaf30dbc218371jacobsman_node_validate(struct roff_man *man)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs struct roff_node *n;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs v_check *cp;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs n = man->last;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs man->last = man->last->child;
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India" while (man->last != NULL) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs man_node_validate(man);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (man->last == n)
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India" man->last = man->last->child;
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India" else
355b4669e025ff377602b6fc7caaf30dbc218371jacobs man->last = man->last->next;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs man->last = n;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs man->next = ROFF_NEXT_SIBLING;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs switch (n->type) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case ROFFT_TEXT:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_text(man, n);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case ROFFT_ROOT:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_root(man, n);
37acf26adb79d43bb16f72774829c6f4655d0cc4"Nagaraj Yedathore - Sun Microsystems - Bangalore India" break;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case ROFFT_EQN:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs case ROFFT_TBL:
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India break;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India default:
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India cp = man_valids + n->tok;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (*cp)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India (*cp)(man, n);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (man->last == n)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India man_state(man, n);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India break;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India }
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India}
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiastatic void
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiacheck_root(CHKARGS)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India{
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (NULL == man->first->child)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_msg(MANDOCERR_DOC_EMPTY, man->parse,
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India n->line, n->pos, NULL);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India else
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India man->meta.hasbody = 1;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (NULL == man->meta.title) {
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse,
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India n->line, n->pos, NULL);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India /*
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India * If a title hasn't been set, do so now (by
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India * implication, date and section also aren't set).
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India */
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India man->meta.title = mandoc_strdup("");
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India man->meta.msec = mandoc_strdup("");
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India man->meta.date = man->quick ? mandoc_strdup("") :
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_normdate(man->parse, NULL, n->line, n->pos);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India }
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India}
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiastatic void
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiacheck_text(CHKARGS)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India{
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India char *cp, *p;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (MAN_LITERAL & man->flags)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India return;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India cp = n->string;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India for (p = cp; NULL != (p = strchr(p, '\t')); p++)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_msg(MANDOCERR_FI_TAB, man->parse,
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India n->line, n->pos + (p - cp), NULL);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India}
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiastatic void
355b4669e025ff377602b6fc7caaf30dbc218371jacobspost_OP(CHKARGS)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India{
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (n->child == NULL)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_msg(MANDOCERR_OP_EMPTY, man->parse,
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India n->line, n->pos, "OP");
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India else if (n->child->next != NULL && n->child->next->next != NULL) {
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India n = n->child->next->next;
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse,
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India n->line, n->pos, "OP ... %s", n->string);
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India }
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India}
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiastatic void
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore Indiapost_UR(CHKARGS)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India{
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India if (n->type == ROFFT_HEAD && n->child == NULL)
3ac6dcfa0bf841831d4cfde190aa15173622957csonam gupta - Sun Microsystems - Bangalore India mandoc_vmsg(MANDOCERR_UR_NOHEAD, man->parse,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs n->line, n->pos, "UR");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs check_part(man, n);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs}
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsstatic void
355b4669e025ff377602b6fc7caaf30dbc218371jacobspost_ft(CHKARGS)
355b4669e025ff377602b6fc7caaf30dbc218371jacobs{
char *cp;
int ok;
if (n->child == NULL)
return;
ok = 0;
cp = n->child->string;
switch (*cp) {
case '1':
case '2':
case '3':
case '4':
case 'I':
case 'P':
case 'R':
if ('\0' == cp[1])
ok = 1;
break;
case 'B':
if ('\0' == cp[1] || ('I' == cp[1] && '\0' == cp[2]))
ok = 1;
break;
case 'C':
if ('W' == cp[1] && '\0' == cp[2])
ok = 1;
break;
default:
break;
}
if (0 == ok) {
mandoc_vmsg(MANDOCERR_FT_BAD, man->parse,
n->line, n->pos, "ft %s", cp);
*cp = '\0';
}
}
static void
check_part(CHKARGS)
{
if (n->type == ROFFT_BODY && n->child == NULL)
mandoc_msg(MANDOCERR_BLK_EMPTY, man->parse,
n->line, n->pos, man_macronames[n->tok]);
}
static void
check_par(CHKARGS)
{
switch (n->type) {
case ROFFT_BLOCK:
if (n->body->child == NULL)
roff_node_delete(man, n);
break;
case ROFFT_BODY:
if (n->child == NULL)
mandoc_vmsg(MANDOCERR_PAR_SKIP,
man->parse, n->line, n->pos,
"%s empty", man_macronames[n->tok]);
break;
case ROFFT_HEAD:
if (n->child != NULL)
mandoc_vmsg(MANDOCERR_ARG_SKIP,
man->parse, n->line, n->pos,
"%s %s%s", man_macronames[n->tok],
n->child->string,
n->child->next != NULL ? " ..." : "");
break;
default:
break;
}
}
static void
post_IP(CHKARGS)
{
switch (n->type) {
case ROFFT_BLOCK:
if (n->head->child == NULL && n->body->child == NULL)
roff_node_delete(man, n);
break;
case ROFFT_BODY:
if (n->parent->head->child == NULL && n->child == NULL)
mandoc_vmsg(MANDOCERR_PAR_SKIP,
man->parse, n->line, n->pos,
"%s empty", man_macronames[n->tok]);
break;
default:
break;
}
}
static void
post_TH(CHKARGS)
{
struct roff_node *nb;
const char *p;
free(man->meta.title);
free(man->meta.vol);
free(man->meta.os);
free(man->meta.msec);
free(man->meta.date);
man->meta.title = man->meta.vol = man->meta.date =
man->meta.msec = man->meta.os = NULL;
nb = n;
/* ->TITLE<- MSEC DATE OS VOL */
n = n->child;
if (n && n->string) {
for (p = n->string; '\0' != *p; p++) {
/* Only warn about this once... */
if (isalpha((unsigned char)*p) &&
! isupper((unsigned char)*p)) {
mandoc_vmsg(MANDOCERR_TITLE_CASE,
man->parse, n->line,
n->pos + (p - n->string),
"TH %s", n->string);
break;
}
}
man->meta.title = mandoc_strdup(n->string);
} else {
man->meta.title = mandoc_strdup("");
mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse,
nb->line, nb->pos, "TH");
}
/* TITLE ->MSEC<- DATE OS VOL */
if (n)
n = n->next;
if (n && n->string)
man->meta.msec = mandoc_strdup(n->string);
else {
man->meta.msec = mandoc_strdup("");
mandoc_vmsg(MANDOCERR_MSEC_MISSING, man->parse,
nb->line, nb->pos, "TH %s", man->meta.title);
}
/* TITLE MSEC ->DATE<- OS VOL */
if (n)
n = n->next;
if (n && n->string && '\0' != n->string[0]) {
man->meta.date = man->quick ?
mandoc_strdup(n->string) :
mandoc_normdate(man->parse, n->string,
n->line, n->pos);
} else {
man->meta.date = mandoc_strdup("");
mandoc_msg(MANDOCERR_DATE_MISSING, man->parse,
n ? n->line : nb->line,
n ? n->pos : nb->pos, "TH");
}
/* TITLE MSEC DATE ->OS<- VOL */
if (n && (n = n->next))
man->meta.os = mandoc_strdup(n->string);
else if (man->defos != NULL)
man->meta.os = mandoc_strdup(man->defos);
/* TITLE MSEC DATE OS ->VOL<- */
/* If missing, use the default VOL name for MSEC. */
if (n && (n = n->next))
man->meta.vol = mandoc_strdup(n->string);
else if ('\0' != man->meta.msec[0] &&
(NULL != (p = mandoc_a2msec(man->meta.msec))))
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
* meta-data.
*/
roff_node_delete(man, man->last);
}
static void
post_UC(CHKARGS)
{
static const char * const bsd_versions[] = {
"3rd Berkeley Distribution",
"4th Berkeley Distribution",
"4.2 Berkeley Distribution",
"4.3 Berkeley Distribution",
"4.4 Berkeley Distribution",
};
const char *p, *s;
n = n->child;
if (n == NULL || n->type != ROFFT_TEXT)
p = bsd_versions[0];
else {
s = n->string;
if (0 == strcmp(s, "3"))
p = bsd_versions[0];
else if (0 == strcmp(s, "4"))
p = bsd_versions[1];
else if (0 == strcmp(s, "5"))
p = bsd_versions[2];
else if (0 == strcmp(s, "6"))
p = bsd_versions[3];
else if (0 == strcmp(s, "7"))
p = bsd_versions[4];
else
p = bsd_versions[0];
}
free(man->meta.os);
man->meta.os = mandoc_strdup(p);
}
static void
post_AT(CHKARGS)
{
static const char * const unix_versions[] = {
"7th Edition",
"System III",
"System V",
"System V Release 2",
};
struct roff_node *nn;
const char *p, *s;
n = n->child;
if (n == NULL || n->type != ROFFT_TEXT)
p = unix_versions[0];
else {
s = n->string;
if (0 == strcmp(s, "3"))
p = unix_versions[0];
else if (0 == strcmp(s, "4"))
p = unix_versions[1];
else if (0 == strcmp(s, "5")) {
nn = n->next;
if (nn != NULL &&
nn->type == ROFFT_TEXT &&
nn->string[0] != '\0')
p = unix_versions[3];
else
p = unix_versions[2];
} else
p = unix_versions[0];
}
free(man->meta.os);
man->meta.os = mandoc_strdup(p);
}
static void
post_vs(CHKARGS)
{
if (NULL != n->prev)
return;
switch (n->parent->tok) {
case MAN_SH:
case MAN_SS:
mandoc_vmsg(MANDOCERR_PAR_SKIP, man->parse, n->line, n->pos,
"%s after %s", man_macronames[n->tok],
man_macronames[n->parent->tok]);
/* FALLTHROUGH */
case TOKEN_NONE:
/*
* Don't warn about this because it occurs in pod2man
* and would cause considerable (unfixable) warnage.
*/
roff_node_delete(man, n);
break;
default:
break;
}
}