man.c revision 698f87a48e2e945bfe5493ce168e0d0ae1cedd5c
/* $Id: man.c,v 1.121 2013/11/10 22:54:40 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "man.h"
#include "mandoc.h"
#include "libman.h"
#include "libmandoc.h"
const char *const __man_macronames[MAN_MAX] = {
"br", "TH", "SH", "SS",
"TP", "LP", "PP", "P",
"IP", "HP", "SM", "SB",
"BI", "IB", "BR", "RB",
"R", "B", "I", "IR",
"RI", "na", "sp", "nf",
"fi", "RE", "RS", "DT",
"UC", "PD", "AT", "in",
"ft", "OP", "EX", "EE",
"UR", "UE"
};
const char * const *man_macronames = __man_macronames;
static int man_node_append(struct man *,
struct man_node *);
static void man_node_free(struct man_node *);
static void man_node_unlink(struct man *,
struct man_node *);
static int man_pmacro(struct man *, int, char *, int);
static void man_alloc1(struct man *);
static int man_descope(struct man *, int, int);
const struct man_node *
{
}
const struct man_meta *
{
}
void
{
}
void
{
}
struct man *
{
struct man *p;
man_alloc1(p);
return(p);
}
int
{
if (man_macroend(man))
return(1);
return(0);
}
int
{
}
static void
{
}
static void
{
}
static int
{
case (MAN_NEXT_SIBLING):
break;
case (MAN_NEXT_CHILD):
break;
default:
abort();
/* NOTREACHED */
}
if ( ! man_valid_pre(man, p))
return(0);
switch (p->type) {
case (MAN_HEAD):
break;
case (MAN_TAIL):
break;
case (MAN_BODY):
break;
default:
break;
}
switch (p->type) {
case (MAN_TBL):
/* FALLTHROUGH */
case (MAN_TEXT):
if ( ! man_valid_post(man))
return(0);
break;
default:
break;
}
return(1);
}
static struct man_node *
{
struct man_node *p;
return(p);
}
int
{
struct man_node *p;
if ( ! man_node_append(man, p))
return(0);
return(1);
}
int
{
struct man_node *p;
if ( ! man_node_append(man, p))
return(0);
return(1);
}
int
{
struct man_node *p;
if ( ! man_node_append(man, p))
return(0);
return(1);
}
int
{
struct man_node *p;
if ( ! man_node_append(man, p))
return(0);
return(1);
}
int
{
struct man_node *p;
if ( ! man_node_append(man, p))
return(0);
return(1);
}
int
{
struct man_node *n;
if ( ! man_node_append(man, n))
return(0);
return(1);
}
/*
* Free all of the resources held by a node. This does NOT unlink a
* node from its context; for that, see man_node_unlink().
*/
static void
man_node_free(struct man_node *p)
{
if (p->string)
free(p);
}
void
{
while (p->child)
man_node_unlink(man, p);
man_node_free(p);
}
int
{
struct man_node *n;
if ( ! man_node_append(man, n))
return(0);
}
int
{
struct man_node *n;
if ( ! man_node_append(man, n))
return(0);
}
static int
{
/*
* Co-ordinate what happens with having a next-line scope open:
* first close out the element scope (if applicable), then close
* out the block scope (also if applicable).
*/
return(0);
}
return(1);
return(0);
}
static int
{
int i;
/* Literal free-form text whitespace is preserved. */
return(0);
}
/* Skip leading whitespace. */ ;
/*
* Blank lines are ignored right after headings
* but add a single vertical space elsewhere.
*/
if ('\0' == buf[i]) {
/* Allocate a blank entry. */
return(0);
}
return(1);
}
/*
* Warn if the last un-escaped character is whitespace. Then
* strip away the remaining spaces (tabs stay!).
*/
assert(i);
for (--i; i && ' ' == buf[i]; i--)
/* Spin back to non-space. */ ;
/* Jump ahead of escaped whitespace. */
buf[i] = '\0';
}
return(0);
/*
* End-of-sentence check. If the last character is an unescaped
* EOS character, then flag the node as being the end of a
* sentence. The front-end will know how to interpret this.
*/
assert(i);
}
static int
{
int i, ppos;
char mac[5];
struct man_node *n;
return(1);
return(1);
/*
* Copy the first word into a nil-terminated buffer.
* Stop copying when a tab, space, or eoln is encountered.
*/
i = 0;
mac[i] = '\0';
return(1);
}
/* The macro is sane. Jump to the next word. */
offs++;
/*
* Trailing whitespace. Note that tabs are allowed to be passed
* into the parser as "text", so we only warn about spaces here.
*/
/*
* Remove prior ELINE macro, as it's being clobbered by a new
* macro. Note that NSCOPED macros do not close out ELINE
* macros---they don't print text---so we let those slip by.
*/
/* Remove repeated NSCOPED macros causing ELINE. */
n = n->parent;
man_macronames[n->tok]);
man_node_delete(man, n);
}
/*
* Remove prior BLINE macro that is being clobbered.
*/
/* Might be a text node like 8 in
* .TP 8
* .SH foo
*/
n = n->parent;
/* Remove element that didn't end BLINE, if any. */
n = n->parent;
n = n->parent;
man_macronames[n->tok]);
man_node_delete(man, n);
}
/*
* Save the fact that we're in the next-line for a block. In
* this way, embedded roff instructions can "remember" state
* when they exit.
*/
/* Call to handler... */
goto err;
/*
* We weren't in a block-line scope when entering the
* above-parsed macro, so return.
*/
return(1);
}
/*
* If we're in a block scope, then allow this macro to slip by
* without closing scope around it.
*/
return(1);
}
/*
* If we've opened a new next-line element scope, then return
* now, as the next line will close out the block scope.
*/
return(1);
/* Close out the block scope opened in the prior line. */
return(0);
err: /* Error out. */
return(0);
}
/*
* Unlink a node from its context. If "man" is provided, the last parse
* point will also be adjusted accordingly.
*/
static void
{
/* Adjust siblings. */
if (n->prev)
if (n->next)
/* Adjust parent. */
if (n->parent) {
}
/* Adjust parse point, if applicable. */
/*XXX: this can occur when bailing from validation. */
/*assert(NULL == n->next);*/
if (n->prev) {
} else {
}
}
}
const struct mparse *
{
}