tree.c revision 371584c2eae4cf827fd406ba26c14f021adaaa70
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov/* $Id: tree.c,v 1.69 2015/10/12 00:08:16 schwarze Exp $ */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * copyright notice and this permission notice appear in all copies.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "config.h"
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov#include <sys/types.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <assert.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <limits.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <stdio.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <stdlib.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <time.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "mandoc.h"
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov#include "roff.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "mdoc.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "man.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "main.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void print_box(const struct eqn_box *, int);
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankovstatic void print_man(const struct roff_node *, int);
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankovstatic void print_mdoc(const struct roff_node *, int);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void print_span(const struct tbl_span *, int);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankovtree_mdoc(void *arg, const struct roff_man *mdoc)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov print_mdoc(mdoc->first->child, 0);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankovtree_man(void *arg, const struct roff_man *man)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov print_man(man->first->child, 0);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankovprint_mdoc(const struct roff_node *n, int indent)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *p, *t;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int i, j;
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore size_t argc;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore struct mdoc_argv *argv;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (n == NULL)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov return;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore argv = NULL;
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore argc = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = p = NULL;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (n->type) {
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ROOT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "root";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BLOCK:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "block";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_HEAD:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov t = "head";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BODY:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->end)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "body-end";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore else
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov t = "body";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TAIL:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov t = "tail";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ELEM:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "elem";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TEXT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "text";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TBL:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_EQN:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov t = "eqn";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore abort();
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (n->type) {
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TEXT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = n->string;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BODY:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = mdoc_macronames[n->tok];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_HEAD:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = mdoc_macronames[n->tok];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TAIL:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = mdoc_macronames[n->tok];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ELEM:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = mdoc_macronames[n->tok];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->args) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore argv = n->args->argv;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore argc = n->args->argc;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BLOCK:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = mdoc_macronames[n->tok];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->args) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore argv = n->args->argv;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore argc = n->args->argc;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TBL:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_EQN:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov p = "EQ";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ROOT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = "root";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore abort();
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->span) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert(NULL == p && NULL == t);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore print_span(n->span, indent);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < indent; i++)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov putchar(' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf("%s (%s)", p, t);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < (int)argc; i++) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf(" -%s", mdoc_argnames[argv[i].arg]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (argv[i].sz > 0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf(" [");
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (j = 0; j < (int)argv[i].sz; j++)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf(" [%s]", argv[i].value[j]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (argv[i].sz > 0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf(" ]");
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore putchar(' ');
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov if (MDOC_DELIMO & n->flags)
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov putchar('(');
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore if (MDOC_LINE & n->flags)
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore putchar('*');
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov printf("%d:%d", n->line, n->pos + 1);
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov if (MDOC_DELIMC & n->flags)
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov putchar(')');
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov if (MDOC_EOS & n->flags)
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov putchar('.');
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov putchar('\n');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (n->eqn)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov print_box(n->eqn->root->first, indent + 4);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->child)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov print_mdoc(n->child, indent +
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov (n->type == ROFFT_BLOCK ? 2 : 4));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->next)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore print_mdoc(n->next, indent);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankovprint_man(const struct roff_node *n, int indent)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *p, *t;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int i;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (n == NULL)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov return;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = p = NULL;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (n->type) {
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ROOT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "root";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ELEM:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "elem";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TEXT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "text";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BLOCK:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "block";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_HEAD:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov t = "head";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BODY:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov t = "body";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TBL:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_EQN:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov t = "eqn";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore abort();
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (n->type) {
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TEXT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = n->string;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ELEM:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BLOCK:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_HEAD:
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_BODY:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = man_macronames[n->tok];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_ROOT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p = "root";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_TBL:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov break;
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov case ROFFT_EQN:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov p = "EQ";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore abort();
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->span) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert(NULL == p && NULL == t);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore print_span(n->span, indent);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < indent; i++)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov putchar(' ');
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf("%s (%s) ", p, t);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (MAN_LINE & n->flags)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov putchar('*');
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov printf("%d:%d", n->line, n->pos + 1);
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov if (MAN_EOS & n->flags)
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov putchar('.');
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov putchar('\n');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (n->eqn)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov print_box(n->eqn->root->first, indent + 4);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->child)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov print_man(n->child, indent +
371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov (n->type == ROFFT_BLOCK ? 2 : 4));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (n->next)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore print_man(n->next, indent);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreprint_box(const struct eqn_box *ep, int indent)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int i;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *t;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov static const char *posnames[] = {
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov NULL, "sup", "subsup", "sub",
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov "to", "from", "fromto",
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov "over", "sqrt", NULL };
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (NULL == ep)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < indent; i++)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov putchar(' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = NULL;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (ep->type) {
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_ROOT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "eqn-root";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_LISTONE:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_LIST:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "eqn-list";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_SUBEXPR:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "eqn-expr";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_TEXT:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "eqn-text";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_PILE:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov t = "eqn-pile";
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov break;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case EQN_MATRIX:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore t = "eqn-matrix";
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov fputs(t, stdout);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->pos)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" pos=%s", posnames[ep->pos]);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->left)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" left=\"%s\"", ep->left);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->right)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" right=\"%s\"", ep->right);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->top)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" top=\"%s\"", ep->top);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->bottom)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" bottom=\"%s\"", ep->bottom);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->text)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" text=\"%s\"", ep->text);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->font)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" font=%d", ep->font);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->size != EQN_DEFSIZE)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" size=%d", ep->size);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (ep->expectargs != UINT_MAX && ep->expectargs != ep->args)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" badargs=%zu(%zu)", ep->args, ep->expectargs);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov else if (ep->args)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov printf(" args=%zu", ep->args);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov putchar('\n');
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov print_box(ep->first, indent + 4);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore print_box(ep->next, indent);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreprint_span(const struct tbl_span *sp, int indent)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const struct tbl_dat *dp;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int i;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < indent; i++)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov putchar(' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (sp->pos) {
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case TBL_SPAN_HORIZ:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar('-');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case TBL_SPAN_DHORIZ:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar('=');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (dp = sp->first; dp; dp = dp->next) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (dp->pos) {
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case TBL_DATA_HORIZ:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case TBL_DATA_NHORIZ:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar('-');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case TBL_DATA_DHORIZ:
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov case TBL_DATA_NDHORIZ:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar('=');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf("[\"%s\"", dp->string ? dp->string : "");
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (dp->spans)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf("(%d)", dp->spans);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (NULL == dp->layout)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar('*');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar(']');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore putchar(' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore printf("(tbl) %d:1\n", sp->line);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}