Annotation of mandoc/term.c, Revision 1.192
1.192 ! kristaps 1: /* $Id: term.c,v 1.191 2011/05/15 22:29:50 kristaps Exp $ */
1.1 kristaps 2: /*
1.159 schwarze 3: * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.177 schwarze 4: * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
1.1 kristaps 5: *
6: * Permission to use, copy, modify, and distribute this software for any
1.74 kristaps 7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 9: *
1.74 kristaps 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 17: */
1.128 kristaps 18: #ifdef HAVE_CONFIG_H
19: #include "config.h"
20: #endif
21:
1.126 kristaps 22: #include <sys/types.h>
23:
1.1 kristaps 24: #include <assert.h>
1.122 kristaps 25: #include <ctype.h>
1.141 kristaps 26: #include <stdint.h>
1.22 kristaps 27: #include <stdio.h>
1.1 kristaps 28: #include <stdlib.h>
29: #include <string.h>
30:
1.137 kristaps 31: #include "mandoc.h"
1.107 kristaps 32: #include "out.h"
1.71 kristaps 33: #include "term.h"
1.105 kristaps 34: #include "main.h"
1.1 kristaps 35:
1.191 kristaps 36: static void adjbuf(struct termp *p, int);
37: static void bufferc(struct termp *, char);
38: static void encode(struct termp *, const char *, size_t);
1.11 kristaps 39:
1.145 kristaps 40: void
1.71 kristaps 41: term_free(struct termp *p)
1.14 kristaps 42: {
43:
1.71 kristaps 44: if (p->buf)
45: free(p->buf);
1.102 kristaps 46: if (p->symtab)
1.185 kristaps 47: mchars_free(p->symtab);
1.145 kristaps 48:
1.142 kristaps 49: free(p);
50: }
51:
52:
53: void
54: term_begin(struct termp *p, term_margin head,
55: term_margin foot, const void *arg)
56: {
57:
58: p->headf = head;
59: p->footf = foot;
60: p->argf = arg;
1.146 kristaps 61: (*p->begin)(p);
1.142 kristaps 62: }
63:
64:
65: void
66: term_end(struct termp *p)
67: {
68:
1.146 kristaps 69: (*p->end)(p);
1.14 kristaps 70: }
71:
72:
1.145 kristaps 73: struct termp *
74: term_alloc(enum termenc enc)
1.14 kristaps 75: {
1.141 kristaps 76: struct termp *p;
1.14 kristaps 77:
1.179 kristaps 78: p = mandoc_calloc(1, sizeof(struct termp));
1.71 kristaps 79: p->enc = enc;
80: return(p);
1.14 kristaps 81: }
82:
83:
1.71 kristaps 84: /*
85: * Flush a line of text. A "line" is loosely defined as being something
86: * that should be followed by a newline, regardless of whether it's
87: * broken apart by newlines getting there. A line can also be a
1.130 kristaps 88: * fragment of a columnar list (`Bl -tag' or `Bl -column'), which does
89: * not have a trailing newline.
1.71 kristaps 90: *
1.130 kristaps 91: * The following flags may be specified:
1.71 kristaps 92: *
93: * - TERMP_NOLPAD: when beginning to write the line, don't left-pad the
94: * offset value. This is useful when doing columnar lists where the
95: * prior column has right-padded.
96: *
97: * - TERMP_NOBREAK: this is the most important and is used when making
98: * columns. In short: don't print a newline and instead pad to the
99: * right margin. Used in conjunction with TERMP_NOLPAD.
100: *
1.91 kristaps 101: * - TERMP_TWOSPACE: when padding, make sure there are at least two
102: * space characters of padding. Otherwise, rather break the line.
103: *
1.84 kristaps 104: * - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
105: * the line is overrun, and don't pad-right if it's underrun.
106: *
107: * - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
108: * overruning, instead save the position and continue at that point
109: * when the next invocation.
1.71 kristaps 110: *
111: * In-line line breaking:
112: *
113: * If TERMP_NOBREAK is specified and the line overruns the right
114: * margin, it will break and pad-right to the right margin after
115: * writing. If maxrmargin is violated, it will break and continue
1.114 kristaps 116: * writing from the right-margin, which will lead to the above scenario
117: * upon exit. Otherwise, the line will break at the right margin.
1.71 kristaps 118: */
119: void
120: term_flushln(struct termp *p)
1.53 kristaps 121: {
1.114 kristaps 122: int i; /* current input position in p->buf */
123: size_t vis; /* current visual position on output */
124: size_t vbl; /* number of blanks to prepend to output */
1.136 schwarze 125: size_t vend; /* end of word visual position on output */
1.114 kristaps 126: size_t bp; /* visual right border position */
1.172 schwarze 127: size_t dv; /* temporary for visual pos calculations */
1.152 kristaps 128: int j; /* temporary loop index for p->buf */
129: int jhy; /* last hyph before overflow w/r/t j */
130: size_t maxvis; /* output position of visible boundary */
131: size_t mmax; /* used in calculating bp */
1.53 kristaps 132:
1.71 kristaps 133: /*
134: * First, establish the maximum columns of "visible" content.
135: * This is usually the difference between the right-margin and
136: * an indentation, but can be, for tagged lists or columns, a
1.115 kristaps 137: * small set of values.
1.71 kristaps 138: */
1.175 kristaps 139: assert (p->rmargin >= p->offset);
1.174 schwarze 140: dv = p->rmargin - p->offset;
141: maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
142: dv = p->maxrmargin - p->offset;
143: mmax = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
1.92 kristaps 144:
1.71 kristaps 145: bp = TERMP_NOBREAK & p->flags ? mmax : maxvis;
1.115 kristaps 146:
1.136 schwarze 147: /*
148: * Indent the first line of a paragraph.
149: */
1.174 schwarze 150: vbl = p->flags & TERMP_NOLPAD ? (size_t)0 : p->offset;
1.136 schwarze 151:
1.174 schwarze 152: vis = vend = 0;
153: i = 0;
1.115 kristaps 154:
1.188 kristaps 155: while (i < p->col) {
1.71 kristaps 156: /*
1.154 kristaps 157: * Handle literal tab characters: collapse all
158: * subsequent tabs into a single huge set of spaces.
1.138 schwarze 159: */
1.188 kristaps 160: while (i < p->col && '\t' == p->buf[i]) {
1.154 kristaps 161: vend = (vis / p->tabwidth + 1) * p->tabwidth;
1.138 schwarze 162: vbl += vend - vis;
163: vis = vend;
1.169 schwarze 164: i++;
1.138 schwarze 165: }
166:
167: /*
1.71 kristaps 168: * Count up visible word characters. Control sequences
169: * (starting with the CSI) aren't counted. A space
170: * generates a non-printing word, which is valid (the
171: * space is printed according to regular spacing rules).
172: */
173:
1.188 kristaps 174: for (j = i, jhy = 0; j < p->col; j++) {
1.138 schwarze 175: if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
1.71 kristaps 176: break;
1.154 kristaps 177:
178: /* Back over the the last printed character. */
179: if (8 == p->buf[j]) {
1.153 kristaps 180: assert(j);
181: vend -= (*p->width)(p, p->buf[j - 1]);
1.154 kristaps 182: continue;
1.153 kristaps 183: }
1.154 kristaps 184:
185: /* Regular word. */
186: /* Break at the hyphen point if we overrun. */
187: if (vend > vis && vend < bp &&
188: ASCII_HYPH == p->buf[j])
189: jhy = j;
190:
191: vend += (*p->width)(p, p->buf[j]);
1.71 kristaps 192: }
1.53 kristaps 193:
1.71 kristaps 194: /*
1.81 kristaps 195: * Find out whether we would exceed the right margin.
1.136 schwarze 196: * If so, break to the next line.
1.81 kristaps 197: */
1.140 kristaps 198: if (vend > bp && 0 == jhy && vis > 0) {
1.136 schwarze 199: vend -= vis;
1.146 kristaps 200: (*p->endline)(p);
1.81 kristaps 201: if (TERMP_NOBREAK & p->flags) {
1.139 schwarze 202: p->viscol = p->rmargin;
1.146 kristaps 203: (*p->advance)(p, p->rmargin);
1.136 schwarze 204: vend += p->rmargin - p->offset;
1.81 kristaps 205: } else {
1.139 schwarze 206: p->viscol = 0;
1.136 schwarze 207: vbl = p->offset;
1.81 kristaps 208: }
1.130 kristaps 209:
1.129 kristaps 210: /* Remove the p->overstep width. */
1.130 kristaps 211:
1.174 schwarze 212: bp += (size_t)p->overstep;
1.129 kristaps 213: p->overstep = 0;
1.71 kristaps 214: }
1.138 schwarze 215:
1.130 kristaps 216: /* Write out the [remaining] word. */
1.188 kristaps 217: for ( ; i < p->col; i++) {
1.140 kristaps 218: if (vend > bp && jhy > 0 && i > jhy)
219: break;
1.138 schwarze 220: if ('\t' == p->buf[i])
221: break;
1.136 schwarze 222: if (' ' == p->buf[i]) {
1.164 kristaps 223: j = i;
224: while (' ' == p->buf[i])
1.136 schwarze 225: i++;
1.174 schwarze 226: dv = (size_t)(i - j) * (*p->width)(p, ' ');
1.172 schwarze 227: vbl += dv;
228: vend += dv;
1.71 kristaps 229: break;
1.136 schwarze 230: }
231: if (ASCII_NBRSP == p->buf[i]) {
1.153 kristaps 232: vbl += (*p->width)(p, ' ');
1.136 schwarze 233: continue;
234: }
1.130 kristaps 235:
1.136 schwarze 236: /*
237: * Now we definitely know there will be
238: * printable characters to output,
239: * so write preceding white space now.
240: */
241: if (vbl) {
1.146 kristaps 242: (*p->advance)(p, vbl);
1.139 schwarze 243: p->viscol += vbl;
1.136 schwarze 244: vbl = 0;
245: }
1.140 kristaps 246:
1.153 kristaps 247: if (ASCII_HYPH == p->buf[i]) {
1.146 kristaps 248: (*p->letter)(p, '-');
1.153 kristaps 249: p->viscol += (*p->width)(p, '-');
250: } else {
1.146 kristaps 251: (*p->letter)(p, p->buf[i]);
1.153 kristaps 252: p->viscol += (*p->width)(p, p->buf[i]);
253: }
1.136 schwarze 254: }
255: vis = vend;
1.71 kristaps 256: }
1.168 schwarze 257:
258: /*
259: * If there was trailing white space, it was not printed;
260: * so reset the cursor position accordingly.
261: */
262: vis -= vbl;
1.111 kristaps 263:
1.91 kristaps 264: p->col = 0;
1.129 kristaps 265: p->overstep = 0;
1.15 kristaps 266:
1.91 kristaps 267: if ( ! (TERMP_NOBREAK & p->flags)) {
1.139 schwarze 268: p->viscol = 0;
1.146 kristaps 269: (*p->endline)(p);
1.15 kristaps 270: return;
1.71 kristaps 271: }
1.15 kristaps 272:
1.91 kristaps 273: if (TERMP_HANG & p->flags) {
274: /* We need one blank after the tag. */
1.174 schwarze 275: p->overstep = (int)(vis - maxvis + (*p->width)(p, ' '));
1.91 kristaps 276:
277: /*
278: * Behave exactly the same way as groff:
1.92 kristaps 279: * If we have overstepped the margin, temporarily move
280: * it to the right and flag the rest of the line to be
281: * shorter.
1.91 kristaps 282: * If we landed right at the margin, be happy.
1.92 kristaps 283: * If we are one step before the margin, temporarily
284: * move it one step LEFT and flag the rest of the line
285: * to be longer.
1.91 kristaps 286: */
1.129 kristaps 287: if (p->overstep >= -1) {
288: assert((int)maxvis + p->overstep >= 0);
1.174 schwarze 289: maxvis += (size_t)p->overstep;
1.92 kristaps 290: } else
1.129 kristaps 291: p->overstep = 0;
1.91 kristaps 292:
293: } else if (TERMP_DANGLE & p->flags)
294: return;
1.15 kristaps 295:
1.92 kristaps 296: /* Right-pad. */
1.174 schwarze 297: if (maxvis > vis +
298: ((TERMP_TWOSPACE & p->flags) ? (*p->width)(p, ' ') : 0)) {
1.139 schwarze 299: p->viscol += maxvis - vis;
1.146 kristaps 300: (*p->advance)(p, maxvis - vis);
1.142 kristaps 301: vis += (maxvis - vis);
1.139 schwarze 302: } else { /* ...or newline break. */
1.146 kristaps 303: (*p->endline)(p);
1.139 schwarze 304: p->viscol = p->rmargin;
1.146 kristaps 305: (*p->advance)(p, p->rmargin);
1.91 kristaps 306: }
1.15 kristaps 307: }
308:
309:
1.71 kristaps 310: /*
311: * A newline only breaks an existing line; it won't assert vertical
312: * space. All data in the output buffer is flushed prior to the newline
313: * assertion.
314: */
315: void
316: term_newln(struct termp *p)
1.15 kristaps 317: {
318:
1.71 kristaps 319: p->flags |= TERMP_NOSPACE;
1.139 schwarze 320: if (0 == p->col && 0 == p->viscol) {
1.71 kristaps 321: p->flags &= ~TERMP_NOLPAD;
1.15 kristaps 322: return;
1.16 kristaps 323: }
1.71 kristaps 324: term_flushln(p);
325: p->flags &= ~TERMP_NOLPAD;
1.16 kristaps 326: }
327:
328:
1.71 kristaps 329: /*
330: * Asserts a vertical space (a full, empty line-break between lines).
331: * Note that if used twice, this will cause two blank spaces and so on.
332: * All data in the output buffer is flushed prior to the newline
333: * assertion.
334: */
335: void
336: term_vspace(struct termp *p)
1.16 kristaps 337: {
338:
1.62 kristaps 339: term_newln(p);
1.139 schwarze 340: p->viscol = 0;
1.146 kristaps 341: (*p->endline)(p);
1.16 kristaps 342: }
343:
1.125 kristaps 344: void
345: term_fontlast(struct termp *p)
346: {
347: enum termfont f;
348:
349: f = p->fontl;
350: p->fontl = p->fontq[p->fonti];
351: p->fontq[p->fonti] = f;
352: }
353:
354:
355: void
356: term_fontrepl(struct termp *p, enum termfont f)
357: {
358:
359: p->fontl = p->fontq[p->fonti];
360: p->fontq[p->fonti] = f;
361: }
362:
363:
364: void
365: term_fontpush(struct termp *p, enum termfont f)
366: {
367:
368: assert(p->fonti + 1 < 10);
369: p->fontl = p->fontq[p->fonti];
370: p->fontq[++p->fonti] = f;
371: }
372:
373:
374: const void *
375: term_fontq(struct termp *p)
376: {
377:
378: return(&p->fontq[p->fonti]);
379: }
380:
381:
382: enum termfont
383: term_fonttop(struct termp *p)
384: {
385:
386: return(p->fontq[p->fonti]);
387: }
388:
389:
390: void
391: term_fontpopq(struct termp *p, const void *key)
392: {
393:
394: while (p->fonti >= 0 && key != &p->fontq[p->fonti])
395: p->fonti--;
396: assert(p->fonti >= 0);
397: }
1.94 kristaps 398:
1.125 kristaps 399:
400: void
401: term_fontpop(struct termp *p)
402: {
403:
404: assert(p->fonti);
405: p->fonti--;
1.17 kristaps 406: }
407:
1.71 kristaps 408: /*
409: * Handle pwords, partial words, which may be either a single word or a
410: * phrase that cannot be broken down (such as a literal string). This
411: * handles word styling.
412: */
1.86 kristaps 413: void
414: term_word(struct termp *p, const char *word)
1.65 kristaps 415: {
1.191 kristaps 416: const char *seq, *cp;
417: char c;
1.184 kristaps 418: int sz;
1.124 kristaps 419: size_t ssz;
1.184 kristaps 420: enum mandoc_esc esc;
1.100 kristaps 421:
1.133 kristaps 422: if ( ! (TERMP_NOSPACE & p->flags)) {
1.151 schwarze 423: if ( ! (TERMP_KEEP & p->flags)) {
424: if (TERMP_PREKEEP & p->flags)
425: p->flags |= TERMP_KEEP;
1.133 kristaps 426: bufferc(p, ' ');
1.151 schwarze 427: if (TERMP_SENTENCE & p->flags)
428: bufferc(p, ' ');
429: } else
430: bufferc(p, ASCII_NBRSP);
1.133 kristaps 431: }
1.65 kristaps 432:
1.71 kristaps 433: if ( ! (p->flags & TERMP_NONOSPACE))
434: p->flags &= ~TERMP_NOSPACE;
1.166 kristaps 435: else
436: p->flags |= TERMP_NOSPACE;
1.133 kristaps 437:
1.173 schwarze 438: p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM);
1.65 kristaps 439:
1.184 kristaps 440: while ('\0' != *word) {
1.162 kristaps 441: if ((ssz = strcspn(word, "\\")) > 0)
442: encode(p, word, ssz);
1.124 kristaps 443:
1.178 kristaps 444: word += (int)ssz;
1.162 kristaps 445: if ('\\' != *word)
1.124 kristaps 446: continue;
447:
1.184 kristaps 448: word++;
449: esc = mandoc_escape(&word, &seq, &sz);
450: if (ESCAPE_ERROR == esc)
451: break;
1.124 kristaps 452:
1.184 kristaps 453: switch (esc) {
1.192 ! kristaps 454: case (ESCAPE_UNICODE):
! 455: encode(p, "?", 1);
! 456: break;
1.184 kristaps 457: case (ESCAPE_NUMBERED):
1.191 kristaps 458: if ('\0' != (c = mchars_num2char(seq, sz)))
459: encode(p, &c, 1);
1.184 kristaps 460: break;
461: case (ESCAPE_PREDEF):
1.191 kristaps 462: cp = mchars_res2str(p->symtab, seq, sz, &ssz);
463: if (NULL != cp)
464: encode(p, cp, ssz);
1.184 kristaps 465: break;
466: case (ESCAPE_SPECIAL):
1.191 kristaps 467: cp = mchars_spec2str(p->symtab, seq, sz, &ssz);
468: if (NULL != cp)
469: encode(p, cp, ssz);
470: else if (1 == ssz)
471: encode(p, seq, sz);
1.124 kristaps 472: break;
1.184 kristaps 473: case (ESCAPE_FONTBOLD):
1.125 kristaps 474: term_fontrepl(p, TERMFONT_BOLD);
1.124 kristaps 475: break;
1.184 kristaps 476: case (ESCAPE_FONTITALIC):
1.125 kristaps 477: term_fontrepl(p, TERMFONT_UNDER);
1.124 kristaps 478: break;
1.184 kristaps 479: case (ESCAPE_FONTROMAN):
1.125 kristaps 480: term_fontrepl(p, TERMFONT_NONE);
1.124 kristaps 481: break;
1.184 kristaps 482: case (ESCAPE_FONTPREV):
1.125 kristaps 483: term_fontlast(p);
1.124 kristaps 484: break;
1.184 kristaps 485: case (ESCAPE_NOSPACE):
486: if ('\0' == *word)
487: p->flags |= TERMP_NOSPACE;
488: break;
1.124 kristaps 489: default:
490: break;
491: }
492: }
1.65 kristaps 493: }
494:
1.71 kristaps 495: static void
1.188 kristaps 496: adjbuf(struct termp *p, int sz)
1.51 kristaps 497: {
498:
1.125 kristaps 499: if (0 == p->maxcols)
500: p->maxcols = 1024;
501: while (sz >= p->maxcols)
502: p->maxcols <<= 2;
503:
1.188 kristaps 504: p->buf = mandoc_realloc
505: (p->buf, sizeof(int) * (size_t)p->maxcols);
1.51 kristaps 506: }
507:
1.79 kristaps 508: static void
1.125 kristaps 509: bufferc(struct termp *p, char c)
510: {
511:
512: if (p->col + 1 >= p->maxcols)
513: adjbuf(p, p->col + 1);
514:
1.188 kristaps 515: p->buf[p->col++] = c;
1.125 kristaps 516: }
517:
518: static void
519: encode(struct termp *p, const char *word, size_t sz)
520: {
521: enum termfont f;
1.188 kristaps 522: int i, len;
523:
524: /* LINTED */
525: len = sz;
1.125 kristaps 526:
527: /*
528: * Encode and buffer a string of characters. If the current
529: * font mode is unset, buffer directly, else encode then buffer
530: * character by character.
531: */
532:
1.147 kristaps 533: if (TERMFONT_NONE == (f = term_fonttop(p))) {
1.188 kristaps 534: if (p->col + len >= p->maxcols)
535: adjbuf(p, p->col + len);
536: for (i = 0; i < len; i++)
537: p->buf[p->col++] = word[i];
1.125 kristaps 538: return;
539: }
540:
1.165 kristaps 541: /* Pre-buffer, assuming worst-case. */
542:
1.188 kristaps 543: if (p->col + 1 + (len * 3) >= p->maxcols)
544: adjbuf(p, p->col + 1 + (len * 3));
1.165 kristaps 545:
1.188 kristaps 546: for (i = 0; i < len; i++) {
547: if ( ! isgraph((unsigned char)word[i])) {
548: p->buf[p->col++] = word[i];
1.125 kristaps 549: continue;
1.79 kristaps 550: }
1.125 kristaps 551:
552: if (TERMFONT_UNDER == f)
1.188 kristaps 553: p->buf[p->col++] = '_';
1.125 kristaps 554: else
1.188 kristaps 555: p->buf[p->col++] = word[i];
1.125 kristaps 556:
1.188 kristaps 557: p->buf[p->col++] = 8;
558: p->buf[p->col++] = word[i];
1.79 kristaps 559: }
560: }
1.106 kristaps 561:
1.107 kristaps 562: size_t
1.149 kristaps 563: term_len(const struct termp *p, size_t sz)
564: {
565:
566: return((*p->width)(p, ' ') * sz);
567: }
568:
569:
570: size_t
571: term_strlen(const struct termp *p, const char *cp)
572: {
1.184 kristaps 573: size_t sz, rsz, i;
1.190 kristaps 574: int ssz, c;
1.171 kristaps 575: const char *seq, *rhs;
1.189 kristaps 576: static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' };
1.171 kristaps 577:
1.184 kristaps 578: /*
579: * Account for escaped sequences within string length
580: * calculations. This follows the logic in term_word() as we
581: * must calculate the width of produced strings.
582: */
583:
584: sz = 0;
1.189 kristaps 585: while ('\0' != *cp) {
586: rsz = strcspn(cp, rej);
587: for (i = 0; i < rsz; i++)
588: sz += (*p->width)(p, *cp++);
589:
1.192 ! kristaps 590: c = 0;
1.184 kristaps 591: switch (*cp) {
592: case ('\\'):
1.189 kristaps 593: cp++;
1.190 kristaps 594: rhs = NULL;
1.189 kristaps 595: switch (mandoc_escape(&cp, &seq, &ssz)) {
596: case (ESCAPE_ERROR):
1.184 kristaps 597: return(sz);
1.192 ! kristaps 598: case (ESCAPE_UNICODE):
! 599: c = '?';
! 600: /* FALLTHROUGH */
1.190 kristaps 601: case (ESCAPE_NUMBERED):
1.192 ! kristaps 602: if ('\0' != c)
! 603: c = mchars_num2char(seq, ssz);
1.190 kristaps 604: if ('\0' != c)
605: sz += (*p->width)(p, c);
606: break;
1.184 kristaps 607: case (ESCAPE_PREDEF):
1.185 kristaps 608: rhs = mchars_res2str
1.171 kristaps 609: (p->symtab, seq, ssz, &rsz);
610: break;
1.184 kristaps 611: case (ESCAPE_SPECIAL):
1.185 kristaps 612: rhs = mchars_spec2str
1.171 kristaps 613: (p->symtab, seq, ssz, &rsz);
614:
1.184 kristaps 615: if (ssz != 1 || rhs)
1.171 kristaps 616: break;
617:
618: rhs = seq;
619: rsz = ssz;
620: break;
621: default:
622: break;
623: }
1.149 kristaps 624:
1.184 kristaps 625: if (NULL == rhs)
626: break;
627:
628: for (i = 0; i < rsz; i++)
629: sz += (*p->width)(p, *rhs++);
630: break;
631: case (ASCII_NBRSP):
1.176 kristaps 632: sz += (*p->width)(p, ' ');
633: cp++;
1.184 kristaps 634: break;
635: case (ASCII_HYPH):
1.176 kristaps 636: sz += (*p->width)(p, '-');
637: cp++;
1.184 kristaps 638: break;
639: default:
640: break;
641: }
1.189 kristaps 642: }
1.149 kristaps 643:
644: return(sz);
645: }
646:
1.157 kristaps 647: /* ARGSUSED */
1.149 kristaps 648: size_t
649: term_vspan(const struct termp *p, const struct roffsu *su)
1.106 kristaps 650: {
651: double r;
652:
1.107 kristaps 653: switch (su->unit) {
1.106 kristaps 654: case (SCALE_CM):
1.107 kristaps 655: r = su->scale * 2;
1.106 kristaps 656: break;
657: case (SCALE_IN):
1.107 kristaps 658: r = su->scale * 6;
1.106 kristaps 659: break;
660: case (SCALE_PC):
1.107 kristaps 661: r = su->scale;
1.106 kristaps 662: break;
663: case (SCALE_PT):
1.107 kristaps 664: r = su->scale / 8;
1.106 kristaps 665: break;
666: case (SCALE_MM):
1.107 kristaps 667: r = su->scale / 1000;
1.106 kristaps 668: break;
669: case (SCALE_VS):
1.107 kristaps 670: r = su->scale;
1.106 kristaps 671: break;
672: default:
1.107 kristaps 673: r = su->scale - 1;
1.106 kristaps 674: break;
675: }
676:
677: if (r < 0.0)
678: r = 0.0;
1.107 kristaps 679: return(/* LINTED */(size_t)
1.106 kristaps 680: r);
681: }
682:
1.107 kristaps 683: size_t
1.149 kristaps 684: term_hspan(const struct termp *p, const struct roffsu *su)
1.106 kristaps 685: {
1.156 kristaps 686: double v;
1.108 kristaps 687:
1.156 kristaps 688: v = ((*p->hspan)(p, su));
689: if (v < 0.0)
690: v = 0.0;
691: return((size_t) /* LINTED */
692: v);
1.106 kristaps 693: }
CVSweb