term.c revision 95c635efb7c3b86efc493e0447eaec7aecca3f0f
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/* $Id: term.c,v 1.201 2011/09/21 09:57:13 schwarze Exp $ */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Copyright (c) 2010, 2011 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 *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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#ifdef HAVE_CONFIG_H
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "config.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#endif
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <sys/types.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <assert.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <ctype.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <stdint.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <stdio.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <stdlib.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include <string.h>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "mandoc.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "out.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "term.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#include "main.h"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void adjbuf(struct termp *p, int);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void bufferc(struct termp *, char);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void encode(struct termp *, const char *, size_t);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void encode1(struct termp *, int);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_free(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->buf)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore free(p->buf);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->symtab)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore mchars_free(p->symtab);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore free(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_begin(struct termp *p, term_margin head,
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_margin foot, const void *arg)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->headf = head;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->footf = foot;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->argf = arg;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->begin)(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_end(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->end)(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Flush a line of text. A "line" is loosely defined as being something
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * that should be followed by a newline, regardless of whether it's
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * broken apart by newlines getting there. A line can also be a
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * fragment of a columnar list (`Bl -tag' or `Bl -column'), which does
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * not have a trailing newline.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * The following flags may be specified:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * - TERMP_NOBREAK: this is the most important and is used when making
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * columns. In short: don't print a newline and instead expect the
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * next call to do the padding up to the start of the next column.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * - TERMP_TWOSPACE: make sure there is room for at least two space
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * characters of padding. Otherwise, rather break the line.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * the line is overrun, and don't pad-right if it's underrun.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * overrunning, instead save the position and continue at that point
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * when the next invocation.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * In-line line breaking:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If TERMP_NOBREAK is specified and the line overruns the right
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * margin, it will break and pad-right to the right margin after
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * writing. If maxrmargin is violated, it will break and continue
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * writing from the right-margin, which will lead to the above scenario
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * upon exit. Otherwise, the line will break at the right margin.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_flushln(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int i; /* current input position in p->buf */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t vis; /* current visual position on output */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t vbl; /* number of blanks to prepend to output */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t vend; /* end of word visual position on output */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t bp; /* visual right border position */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t dv; /* temporary for visual pos calculations */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int j; /* temporary loop index for p->buf */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int jhy; /* last hyph before overflow w/r/t j */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t maxvis; /* output position of visible boundary */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t mmax; /* used in calculating bp */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * First, establish the maximum columns of "visible" content.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * This is usually the difference between the right-margin and
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * an indentation, but can be, for tagged lists or columns, a
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * small set of values.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert (p->rmargin >= p->offset);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore dv = p->rmargin - p->offset;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore dv = p->maxrmargin - p->offset;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore mmax = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore bp = TERMP_NOBREAK & p->flags ? mmax : maxvis;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Calculate the required amount of padding.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl = p->offset + p->overstep > p->viscol ?
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->offset + p->overstep - p->viscol : 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vis = vend = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore i = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while (i < p->col) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Handle literal tab characters: collapse all
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * subsequent tabs into a single huge set of spaces.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while (i < p->col && '\t' == p->buf[i]) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vend = (vis / p->tabwidth + 1) * p->tabwidth;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl += vend - vis;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vis = vend;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore i++;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Count up visible word characters. Control sequences
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * (starting with the CSI) aren't counted. A space
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * generates a non-printing word, which is valid (the
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * space is printed according to regular spacing rules).
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (j = i, jhy = 0; j < p->col; j++) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Back over the the last printed character. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (8 == p->buf[j]) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert(j);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vend -= (*p->width)(p, p->buf[j - 1]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Regular word. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Break at the hyphen point if we overrun. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (vend > vis && vend < bp &&
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore ASCII_HYPH == p->buf[j])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore jhy = j;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vend += (*p->width)(p, p->buf[j]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Find out whether we would exceed the right margin.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If so, break to the next line.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (vend > bp && 0 == jhy && vis > 0) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vend -= vis;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->endline)(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMP_NOBREAK & p->flags) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl = p->rmargin;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vend += p->rmargin - p->offset;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl = p->offset;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Remove the p->overstep width. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore bp += (size_t)p->overstep;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->overstep = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Write out the [remaining] word. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for ( ; i < p->col; i++) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (vend > bp && jhy > 0 && i > jhy)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\t' == p->buf[i])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (' ' == p->buf[i]) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore j = i;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while (' ' == p->buf[i])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore i++;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore dv = (size_t)(i - j) * (*p->width)(p, ' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl += dv;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vend += dv;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (ASCII_NBRSP == p->buf[i]) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl += (*p->width)(p, ' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Now we definitely know there will be
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * printable characters to output,
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * so write preceding white space now.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (vbl) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->advance)(p, vbl);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol += vbl;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vbl = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (ASCII_HYPH == p->buf[i]) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->letter)(p, '-');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol += (*p->width)(p, '-');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->letter)(p, p->buf[i]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (8 == p->buf[i])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol -= (*p->width)(p, p->buf[i-1]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore else
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol += (*p->width)(p, p->buf[i]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vis = vend;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If there was trailing white space, it was not printed;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * so reset the cursor position accordingly.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (vis)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore vis -= vbl;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->col = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->overstep = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ( ! (TERMP_NOBREAK & p->flags)) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->endline)(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMP_HANG & p->flags) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* We need one blank after the tag. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->overstep = (int)(vis - maxvis + (*p->width)(p, ' '));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Behave exactly the same way as groff:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If we have overstepped the margin, temporarily move
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * it to the right and flag the rest of the line to be
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * shorter.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If we landed right at the margin, be happy.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If we are one step before the margin, temporarily
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * move it one step LEFT and flag the rest of the line
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * to be longer.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->overstep < -1)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->overstep = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else if (TERMP_DANGLE & p->flags)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* If the column was overrun, break the line. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (maxvis <= vis +
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore ((TERMP_TWOSPACE & p->flags) ? (*p->width)(p, ' ') : 0)) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->endline)(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * A newline only breaks an existing line; it won't assert vertical
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * space. All data in the output buffer is flushed prior to the newline
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * assertion.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_newln(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->flags |= TERMP_NOSPACE;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->col || p->viscol)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_flushln(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Asserts a vertical space (a full, empty line-break between lines).
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Note that if used twice, this will cause two blank spaces and so on.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * All data in the output buffer is flushed prior to the newline
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * assertion.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_vspace(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_newln(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->viscol = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (*p->endline)(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fontlast(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum termfont f;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore f = p->fontl;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fontl = p->fontq[p->fonti];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fontq[p->fonti] = f;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fontrepl(struct termp *p, enum termfont f)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fontl = p->fontq[p->fonti];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fontq[p->fonti] = f;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fontpush(struct termp *p, enum termfont f)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert(p->fonti + 1 < 10);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fontl = p->fontq[p->fonti];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fontq[++p->fonti] = f;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreconst void *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fontq(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return(&p->fontq[p->fonti]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreenum termfont
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fonttop(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return(p->fontq[p->fonti]);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fontpopq(struct termp *p, const void *key)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while (p->fonti >= 0 && key != &p->fontq[p->fonti])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fonti--;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert(p->fonti >= 0);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_fontpop(struct termp *p)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore assert(p->fonti);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->fonti--;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Handle pwords, partial words, which may be either a single word or a
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * phrase that cannot be broken down (such as a literal string). This
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * handles word styling.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorevoid
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_word(struct termp *p, const char *word)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *seq, *cp;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore char c;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int sz, uc;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t ssz;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum mandoc_esc esc;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ( ! (TERMP_NOSPACE & p->flags)) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ( ! (TERMP_KEEP & p->flags)) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMP_PREKEEP & p->flags)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->flags |= TERMP_KEEP;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore bufferc(p, ' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMP_SENTENCE & p->flags)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore bufferc(p, ' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore bufferc(p, ASCII_NBRSP);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ( ! (p->flags & TERMP_NONOSPACE))
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->flags &= ~TERMP_NOSPACE;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore else
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->flags |= TERMP_NOSPACE;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while ('\0' != *word) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ((ssz = strcspn(word, "\\")) > 0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode(p, word, ssz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore word += (int)ssz;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\\' != *word)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore word++;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore esc = mandoc_escape(&word, &seq, &sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (ESCAPE_ERROR == esc)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMENC_ASCII != p->enc)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (esc) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_UNICODE):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore uc = mchars_num2uc(seq + 1, sz - 1);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\0' == uc)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode1(p, uc);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_SPECIAL):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore uc = mchars_spec2cp(p->symtab, seq, sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (uc <= 0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode1(p, uc);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (esc) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_UNICODE):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode1(p, '?');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_NUMBERED):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore c = mchars_num2char(seq, sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\0' != c)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode(p, &c, 1);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_SPECIAL):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore cp = mchars_spec2str(p->symtab, seq, sz, &ssz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (NULL != cp)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode(p, cp, ssz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore else if (1 == ssz)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore encode(p, seq, sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_FONTBOLD):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_fontrepl(p, TERMFONT_BOLD);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_FONTITALIC):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_fontrepl(p, TERMFONT_UNDER);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_FONT):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_FONTROMAN):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_fontrepl(p, TERMFONT_NONE);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_FONTPREV):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore term_fontlast(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_NOSPACE):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\0' == *word)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->flags |= TERMP_NOSPACE;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreadjbuf(struct termp *p, int sz)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (0 == p->maxcols)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->maxcols = 1024;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while (sz >= p->maxcols)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->maxcols <<= 2;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf = mandoc_realloc
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (p->buf, sizeof(int) * (size_t)p->maxcols);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorebufferc(struct termp *p, char c)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->col + 1 >= p->maxcols)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore adjbuf(p, p->col + 1);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = c;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * See encode().
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Do this for a single (probably unicode) value.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Does not check for non-decorated glyphs.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreencode1(struct termp *p, int c)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum termfont f;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->col + 4 >= p->maxcols)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore adjbuf(p, p->col + 4);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore f = term_fonttop(p);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMFONT_NONE == f) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = c;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else if (TERMFONT_UNDER == f) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = '_';
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore } else
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = c;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = 8;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = c;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreencode(struct termp *p, const char *word, size_t sz)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum termfont f;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int i, len;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* LINTED */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore len = sz;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Encode and buffer a string of characters. If the current
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * font mode is unset, buffer directly, else encode then buffer
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * character by character.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMFONT_NONE == (f = term_fonttop(p))) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->col + len >= p->maxcols)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore adjbuf(p, p->col + len);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < len; i++)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = word[i];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Pre-buffer, assuming worst-case. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (p->col + 1 + (len * 3) >= p->maxcols)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore adjbuf(p, p->col + 1 + (len * 3));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < len; i++) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (ASCII_HYPH != word[i] &&
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore ! isgraph((unsigned char)word[i])) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = word[i];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMFONT_UNDER == f)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = '_';
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore else if (ASCII_HYPH == word[i])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = '-';
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore else
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = word[i];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = 8;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore p->buf[p->col++] = word[i];
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoresize_t
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_len(const struct termp *p, size_t sz)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return((*p->width)(p, ' ') * sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoresize_t
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_strlen(const struct termp *p, const char *cp)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore size_t sz, rsz, i;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int ssz, c;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *seq, *rhs;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum mandoc_esc esc;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' };
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /*
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Account for escaped sequences within string length
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * calculations. This follows the logic in term_word() as we
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * must calculate the width of produced strings.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore while ('\0' != *cp) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore rsz = strcspn(cp, rej);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < rsz; i++)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, *cp++);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore c = 0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (*cp) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case ('\\'):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore cp++;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore esc = mandoc_escape(&cp, &seq, &ssz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (ESCAPE_ERROR == esc)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return(sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (TERMENC_ASCII != p->enc)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (esc) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_UNICODE):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore c = mchars_num2uc
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (seq + 1, ssz - 1);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\0' == c)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, c);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_SPECIAL):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore c = mchars_spec2cp
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (p->symtab, seq, ssz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (c <= 0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, c);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore continue;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore rhs = NULL;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (esc) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_UNICODE):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, '?');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_NUMBERED):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore c = mchars_num2char(seq, ssz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if ('\0' != c)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, c);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ESCAPE_SPECIAL):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore rhs = mchars_spec2str
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (p->symtab, seq, ssz, &rsz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (ssz != 1 || rhs)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore rhs = seq;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore rsz = ssz;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (NULL == rhs)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for (i = 0; i < rsz; i++)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, *rhs++);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ASCII_NBRSP):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, ' ');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore cp++;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (ASCII_HYPH):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore sz += (*p->width)(p, '-');
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore cp++;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return(sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore/* ARGSUSED */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoresize_t
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_vspan(const struct termp *p, const struct roffsu *su)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore double r;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (su->unit) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (SCALE_CM):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale * 2;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (SCALE_IN):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale * 6;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (SCALE_PC):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (SCALE_PT):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale / 8;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (SCALE_MM):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale / 1000;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore case (SCALE_VS):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore default:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = su->scale - 1;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore break;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore }
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (r < 0.0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r = 0.0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return(/* LINTED */(size_t)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore r);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoresize_t
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreterm_hspan(const struct termp *p, const struct roffsu *su)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore{
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore double v;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore v = ((*p->hspan)(p, su));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if (v < 0.0)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore v = 0.0;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return((size_t) /* LINTED */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore v);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore}