]> git.cameronkatri.com Git - mandoc.git/blob - term.c
Drop leading, internal, and trailing blank characters in \o (overstrike)
[mandoc.git] / term.c
1 /* $Id: term.c,v 1.249 2015/08/30 21:10:56 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "mandoc.h"
29 #include "mandoc_aux.h"
30 #include "out.h"
31 #include "term.h"
32 #include "main.h"
33
34 static size_t cond_width(const struct termp *, int, int *);
35 static void adjbuf(struct termp *p, size_t);
36 static void bufferc(struct termp *, char);
37 static void encode(struct termp *, const char *, size_t);
38 static void encode1(struct termp *, int);
39
40
41 void
42 term_free(struct termp *p)
43 {
44
45 free(p->buf);
46 free(p->fontq);
47 free(p);
48 }
49
50 void
51 term_begin(struct termp *p, term_margin head,
52 term_margin foot, const struct roff_meta *arg)
53 {
54
55 p->headf = head;
56 p->footf = foot;
57 p->argf = arg;
58 (*p->begin)(p);
59 }
60
61 void
62 term_end(struct termp *p)
63 {
64
65 (*p->end)(p);
66 }
67
68 /*
69 * Flush a chunk of text. By default, break the output line each time
70 * the right margin is reached, and continue output on the next line
71 * at the same offset as the chunk itself. By default, also break the
72 * output line at the end of the chunk.
73 * The following flags may be specified:
74 *
75 * - TERMP_NOBREAK: Do not break the output line at the right margin,
76 * but only at the max right margin. Also, do not break the output
77 * line at the end of the chunk, such that the next call can pad to
78 * the next column. However, if less than p->trailspace blanks,
79 * which can be 0, 1, or 2, remain to the right margin, the line
80 * will be broken.
81 * - TERMP_BRIND: If the chunk does not fit and the output line has
82 * to be broken, start the next line at the right margin instead
83 * of at the offset. Used together with TERMP_NOBREAK for the tags
84 * in various kinds of tagged lists.
85 * - TERMP_DANGLE: Do not break the output line at the right margin,
86 * append the next chunk after it even if this one is too long.
87 * To be used together with TERMP_NOBREAK.
88 * - TERMP_HANG: Like TERMP_DANGLE, and also suppress padding before
89 * the next chunk if this column is not full.
90 */
91 void
92 term_flushln(struct termp *p)
93 {
94 size_t i; /* current input position in p->buf */
95 int ntab; /* number of tabs to prepend */
96 size_t vis; /* current visual position on output */
97 size_t vbl; /* number of blanks to prepend to output */
98 size_t vend; /* end of word visual position on output */
99 size_t bp; /* visual right border position */
100 size_t dv; /* temporary for visual pos calculations */
101 size_t j; /* temporary loop index for p->buf */
102 size_t jhy; /* last hyph before overflow w/r/t j */
103 size_t maxvis; /* output position of visible boundary */
104
105 /*
106 * First, establish the maximum columns of "visible" content.
107 * This is usually the difference between the right-margin and
108 * an indentation, but can be, for tagged lists or columns, a
109 * small set of values.
110 *
111 * The following unsigned-signed subtractions look strange,
112 * but they are actually correct. If the int p->overstep
113 * is negative, it gets sign extended. Subtracting that
114 * very large size_t effectively adds a small number to dv.
115 */
116 dv = p->rmargin > p->offset ? p->rmargin - p->offset : 0;
117 maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
118
119 if (p->flags & TERMP_NOBREAK) {
120 dv = p->maxrmargin > p->offset ?
121 p->maxrmargin - p->offset : 0;
122 bp = (int)dv > p->overstep ?
123 dv - (size_t)p->overstep : 0;
124 } else
125 bp = maxvis;
126
127 /*
128 * Calculate the required amount of padding.
129 */
130 vbl = p->offset + p->overstep > p->viscol ?
131 p->offset + p->overstep - p->viscol : 0;
132
133 vis = vend = 0;
134 i = 0;
135
136 while (i < p->col) {
137 /*
138 * Handle literal tab characters: collapse all
139 * subsequent tabs into a single huge set of spaces.
140 */
141 ntab = 0;
142 while (i < p->col && '\t' == p->buf[i]) {
143 vend = (vis / p->tabwidth + 1) * p->tabwidth;
144 vbl += vend - vis;
145 vis = vend;
146 ntab++;
147 i++;
148 }
149
150 /*
151 * Count up visible word characters. Control sequences
152 * (starting with the CSI) aren't counted. A space
153 * generates a non-printing word, which is valid (the
154 * space is printed according to regular spacing rules).
155 */
156
157 for (j = i, jhy = 0; j < p->col; j++) {
158 if (' ' == p->buf[j] || '\t' == p->buf[j])
159 break;
160
161 /* Back over the the last printed character. */
162 if (8 == p->buf[j]) {
163 assert(j);
164 vend -= (*p->width)(p, p->buf[j - 1]);
165 continue;
166 }
167
168 /* Regular word. */
169 /* Break at the hyphen point if we overrun. */
170 if (vend > vis && vend < bp &&
171 (ASCII_HYPH == p->buf[j] ||
172 ASCII_BREAK == p->buf[j]))
173 jhy = j;
174
175 /*
176 * Hyphenation now decided, put back a real
177 * hyphen such that we get the correct width.
178 */
179 if (ASCII_HYPH == p->buf[j])
180 p->buf[j] = '-';
181
182 vend += (*p->width)(p, p->buf[j]);
183 }
184
185 /*
186 * Find out whether we would exceed the right margin.
187 * If so, break to the next line.
188 */
189 if (vend > bp && 0 == jhy && vis > 0) {
190 vend -= vis;
191 (*p->endline)(p);
192 p->viscol = 0;
193 if (TERMP_BRIND & p->flags) {
194 vbl = p->rmargin;
195 vend += p->rmargin;
196 vend -= p->offset;
197 } else
198 vbl = p->offset;
199
200 /* use pending tabs on the new line */
201
202 if (0 < ntab)
203 vbl += ntab * p->tabwidth;
204
205 /*
206 * Remove the p->overstep width.
207 * Again, if p->overstep is negative,
208 * sign extension does the right thing.
209 */
210
211 bp += (size_t)p->overstep;
212 p->overstep = 0;
213 }
214
215 /* Write out the [remaining] word. */
216 for ( ; i < p->col; i++) {
217 if (vend > bp && jhy > 0 && i > jhy)
218 break;
219 if ('\t' == p->buf[i])
220 break;
221 if (' ' == p->buf[i]) {
222 j = i;
223 while (i < p->col && ' ' == p->buf[i])
224 i++;
225 dv = (i - j) * (*p->width)(p, ' ');
226 vbl += dv;
227 vend += dv;
228 break;
229 }
230 if (ASCII_NBRSP == p->buf[i]) {
231 vbl += (*p->width)(p, ' ');
232 continue;
233 }
234 if (ASCII_BREAK == p->buf[i])
235 continue;
236
237 /*
238 * Now we definitely know there will be
239 * printable characters to output,
240 * so write preceding white space now.
241 */
242 if (vbl) {
243 (*p->advance)(p, vbl);
244 p->viscol += vbl;
245 vbl = 0;
246 }
247
248 (*p->letter)(p, p->buf[i]);
249 if (8 == p->buf[i])
250 p->viscol -= (*p->width)(p, p->buf[i-1]);
251 else
252 p->viscol += (*p->width)(p, p->buf[i]);
253 }
254 vis = vend;
255 }
256
257 /*
258 * If there was trailing white space, it was not printed;
259 * so reset the cursor position accordingly.
260 */
261 if (vis > vbl)
262 vis -= vbl;
263 else
264 vis = 0;
265
266 p->col = 0;
267 p->overstep = 0;
268 p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE);
269
270 if ( ! (TERMP_NOBREAK & p->flags)) {
271 p->viscol = 0;
272 (*p->endline)(p);
273 return;
274 }
275
276 if (TERMP_HANG & p->flags) {
277 p->overstep += (int)(p->offset + vis - p->rmargin +
278 p->trailspace * (*p->width)(p, ' '));
279
280 /*
281 * If we have overstepped the margin, temporarily move
282 * it to the right and flag the rest of the line to be
283 * shorter.
284 * If there is a request to keep the columns together,
285 * allow negative overstep when the column is not full.
286 */
287 if (p->trailspace && p->overstep < 0)
288 p->overstep = 0;
289 return;
290
291 } else if (TERMP_DANGLE & p->flags)
292 return;
293
294 /* If the column was overrun, break the line. */
295 if (maxvis < vis + p->trailspace * (*p->width)(p, ' ')) {
296 (*p->endline)(p);
297 p->viscol = 0;
298 }
299 }
300
301 /*
302 * A newline only breaks an existing line; it won't assert vertical
303 * space. All data in the output buffer is flushed prior to the newline
304 * assertion.
305 */
306 void
307 term_newln(struct termp *p)
308 {
309
310 p->flags |= TERMP_NOSPACE;
311 if (p->col || p->viscol)
312 term_flushln(p);
313 }
314
315 /*
316 * Asserts a vertical space (a full, empty line-break between lines).
317 * Note that if used twice, this will cause two blank spaces and so on.
318 * All data in the output buffer is flushed prior to the newline
319 * assertion.
320 */
321 void
322 term_vspace(struct termp *p)
323 {
324
325 term_newln(p);
326 p->viscol = 0;
327 if (0 < p->skipvsp)
328 p->skipvsp--;
329 else
330 (*p->endline)(p);
331 }
332
333 /* Swap current and previous font; for \fP and .ft P */
334 void
335 term_fontlast(struct termp *p)
336 {
337 enum termfont f;
338
339 f = p->fontl;
340 p->fontl = p->fontq[p->fonti];
341 p->fontq[p->fonti] = f;
342 }
343
344 /* Set font, save current, discard previous; for \f, .ft, .B etc. */
345 void
346 term_fontrepl(struct termp *p, enum termfont f)
347 {
348
349 p->fontl = p->fontq[p->fonti];
350 p->fontq[p->fonti] = f;
351 }
352
353 /* Set font, save previous. */
354 void
355 term_fontpush(struct termp *p, enum termfont f)
356 {
357
358 p->fontl = p->fontq[p->fonti];
359 if (++p->fonti == p->fontsz) {
360 p->fontsz += 8;
361 p->fontq = mandoc_reallocarray(p->fontq,
362 p->fontsz, sizeof(enum termfont *));
363 }
364 p->fontq[p->fonti] = f;
365 }
366
367 /* Flush to make the saved pointer current again. */
368 void
369 term_fontpopq(struct termp *p, int i)
370 {
371
372 assert(i >= 0);
373 if (p->fonti > i)
374 p->fonti = i;
375 }
376
377 /* Pop one font off the stack. */
378 void
379 term_fontpop(struct termp *p)
380 {
381
382 assert(p->fonti);
383 p->fonti--;
384 }
385
386 /*
387 * Handle pwords, partial words, which may be either a single word or a
388 * phrase that cannot be broken down (such as a literal string). This
389 * handles word styling.
390 */
391 void
392 term_word(struct termp *p, const char *word)
393 {
394 const char nbrsp[2] = { ASCII_NBRSP, 0 };
395 const char *seq, *cp;
396 int sz, uc;
397 size_t ssz;
398 enum mandoc_esc esc;
399
400 if ( ! (TERMP_NOSPACE & p->flags)) {
401 if ( ! (TERMP_KEEP & p->flags)) {
402 bufferc(p, ' ');
403 if (TERMP_SENTENCE & p->flags)
404 bufferc(p, ' ');
405 } else
406 bufferc(p, ASCII_NBRSP);
407 }
408 if (TERMP_PREKEEP & p->flags)
409 p->flags |= TERMP_KEEP;
410
411 if ( ! (p->flags & TERMP_NONOSPACE))
412 p->flags &= ~TERMP_NOSPACE;
413 else
414 p->flags |= TERMP_NOSPACE;
415
416 p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
417 p->skipvsp = 0;
418
419 while ('\0' != *word) {
420 if ('\\' != *word) {
421 if (TERMP_NBRWORD & p->flags) {
422 if (' ' == *word) {
423 encode(p, nbrsp, 1);
424 word++;
425 continue;
426 }
427 ssz = strcspn(word, "\\ ");
428 } else
429 ssz = strcspn(word, "\\");
430 encode(p, word, ssz);
431 word += (int)ssz;
432 continue;
433 }
434
435 word++;
436 esc = mandoc_escape(&word, &seq, &sz);
437 if (ESCAPE_ERROR == esc)
438 continue;
439
440 switch (esc) {
441 case ESCAPE_UNICODE:
442 uc = mchars_num2uc(seq + 1, sz - 1);
443 break;
444 case ESCAPE_NUMBERED:
445 uc = mchars_num2char(seq, sz);
446 if (uc < 0)
447 continue;
448 break;
449 case ESCAPE_SPECIAL:
450 if (p->enc == TERMENC_ASCII) {
451 cp = mchars_spec2str(p->symtab,
452 seq, sz, &ssz);
453 if (cp != NULL)
454 encode(p, cp, ssz);
455 } else {
456 uc = mchars_spec2cp(p->symtab, seq, sz);
457 if (uc > 0)
458 encode1(p, uc);
459 }
460 continue;
461 case ESCAPE_FONTBOLD:
462 term_fontrepl(p, TERMFONT_BOLD);
463 continue;
464 case ESCAPE_FONTITALIC:
465 term_fontrepl(p, TERMFONT_UNDER);
466 continue;
467 case ESCAPE_FONTBI:
468 term_fontrepl(p, TERMFONT_BI);
469 continue;
470 case ESCAPE_FONT:
471 /* FALLTHROUGH */
472 case ESCAPE_FONTROMAN:
473 term_fontrepl(p, TERMFONT_NONE);
474 continue;
475 case ESCAPE_FONTPREV:
476 term_fontlast(p);
477 continue;
478 case ESCAPE_NOSPACE:
479 if (p->flags & TERMP_BACKAFTER)
480 p->flags &= ~TERMP_BACKAFTER;
481 else if (*word == '\0')
482 p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
483 continue;
484 case ESCAPE_SKIPCHAR:
485 p->flags |= TERMP_BACKAFTER;
486 continue;
487 case ESCAPE_OVERSTRIKE:
488 cp = seq + sz;
489 while (seq < cp) {
490 if (*seq == '\\') {
491 mandoc_escape(&seq, NULL, NULL);
492 continue;
493 }
494 encode1(p, *seq++);
495 if (seq < cp) {
496 if (p->flags & TERMP_BACKBEFORE)
497 p->flags |= TERMP_BACKAFTER;
498 else
499 p->flags |= TERMP_BACKBEFORE;
500 }
501 }
502 /* Trim trailing backspace/blank pair. */
503 if (p->col > 2 && p->buf[p->col - 1] == ' ')
504 p->col -= 2;
505 continue;
506 default:
507 continue;
508 }
509
510 /*
511 * Common handling for Unicode and numbered
512 * character escape sequences.
513 */
514
515 if (p->enc == TERMENC_ASCII) {
516 cp = ascii_uc2str(uc);
517 encode(p, cp, strlen(cp));
518 } else {
519 if ((uc < 0x20 && uc != 0x09) ||
520 (uc > 0x7E && uc < 0xA0))
521 uc = 0xFFFD;
522 encode1(p, uc);
523 }
524 }
525 p->flags &= ~TERMP_NBRWORD;
526 }
527
528 static void
529 adjbuf(struct termp *p, size_t sz)
530 {
531
532 if (0 == p->maxcols)
533 p->maxcols = 1024;
534 while (sz >= p->maxcols)
535 p->maxcols <<= 2;
536
537 p->buf = mandoc_reallocarray(p->buf, p->maxcols, sizeof(int));
538 }
539
540 static void
541 bufferc(struct termp *p, char c)
542 {
543
544 if (p->col + 1 >= p->maxcols)
545 adjbuf(p, p->col + 1);
546
547 p->buf[p->col++] = c;
548 }
549
550 /*
551 * See encode().
552 * Do this for a single (probably unicode) value.
553 * Does not check for non-decorated glyphs.
554 */
555 static void
556 encode1(struct termp *p, int c)
557 {
558 enum termfont f;
559
560 if (p->col + 7 >= p->maxcols)
561 adjbuf(p, p->col + 7);
562
563 f = (c == ASCII_HYPH || isgraph(c)) ?
564 p->fontq[p->fonti] : TERMFONT_NONE;
565
566 if (p->flags & TERMP_BACKBEFORE) {
567 if (p->buf[p->col - 1] == ' ')
568 p->col--;
569 else
570 p->buf[p->col++] = 8;
571 p->flags &= ~TERMP_BACKBEFORE;
572 }
573 if (TERMFONT_UNDER == f || TERMFONT_BI == f) {
574 p->buf[p->col++] = '_';
575 p->buf[p->col++] = 8;
576 }
577 if (TERMFONT_BOLD == f || TERMFONT_BI == f) {
578 if (ASCII_HYPH == c)
579 p->buf[p->col++] = '-';
580 else
581 p->buf[p->col++] = c;
582 p->buf[p->col++] = 8;
583 }
584 p->buf[p->col++] = c;
585 if (p->flags & TERMP_BACKAFTER) {
586 p->flags |= TERMP_BACKBEFORE;
587 p->flags &= ~TERMP_BACKAFTER;
588 }
589 }
590
591 static void
592 encode(struct termp *p, const char *word, size_t sz)
593 {
594 size_t i;
595
596 if (p->col + 2 + (sz * 5) >= p->maxcols)
597 adjbuf(p, p->col + 2 + (sz * 5));
598
599 for (i = 0; i < sz; i++) {
600 if (ASCII_HYPH == word[i] ||
601 isgraph((unsigned char)word[i]))
602 encode1(p, word[i]);
603 else
604 p->buf[p->col++] = word[i];
605 }
606 }
607
608 void
609 term_setwidth(struct termp *p, const char *wstr)
610 {
611 struct roffsu su;
612 int iop, width;
613
614 iop = 0;
615 width = 0;
616 if (NULL != wstr) {
617 switch (*wstr) {
618 case '+':
619 iop = 1;
620 wstr++;
621 break;
622 case '-':
623 iop = -1;
624 wstr++;
625 break;
626 default:
627 break;
628 }
629 if (a2roffsu(wstr, &su, SCALE_MAX))
630 width = term_hspan(p, &su);
631 else
632 iop = 0;
633 }
634 (*p->setwidth)(p, iop, width);
635 }
636
637 size_t
638 term_len(const struct termp *p, size_t sz)
639 {
640
641 return((*p->width)(p, ' ') * sz);
642 }
643
644 static size_t
645 cond_width(const struct termp *p, int c, int *skip)
646 {
647
648 if (*skip) {
649 (*skip) = 0;
650 return(0);
651 } else
652 return((*p->width)(p, c));
653 }
654
655 size_t
656 term_strlen(const struct termp *p, const char *cp)
657 {
658 size_t sz, rsz, i;
659 int ssz, skip, uc;
660 const char *seq, *rhs;
661 enum mandoc_esc esc;
662 static const char rej[] = { '\\', ASCII_NBRSP, ASCII_HYPH,
663 ASCII_BREAK, '\0' };
664
665 /*
666 * Account for escaped sequences within string length
667 * calculations. This follows the logic in term_word() as we
668 * must calculate the width of produced strings.
669 */
670
671 sz = 0;
672 skip = 0;
673 while ('\0' != *cp) {
674 rsz = strcspn(cp, rej);
675 for (i = 0; i < rsz; i++)
676 sz += cond_width(p, *cp++, &skip);
677
678 switch (*cp) {
679 case '\\':
680 cp++;
681 esc = mandoc_escape(&cp, &seq, &ssz);
682 if (ESCAPE_ERROR == esc)
683 continue;
684
685 rhs = NULL;
686
687 switch (esc) {
688 case ESCAPE_UNICODE:
689 uc = mchars_num2uc(seq + 1, ssz - 1);
690 break;
691 case ESCAPE_NUMBERED:
692 uc = mchars_num2char(seq, ssz);
693 if (uc < 0)
694 continue;
695 break;
696 case ESCAPE_SPECIAL:
697 if (p->enc == TERMENC_ASCII) {
698 rhs = mchars_spec2str(p->symtab,
699 seq, ssz, &rsz);
700 if (rhs != NULL)
701 break;
702 } else {
703 uc = mchars_spec2cp(p->symtab,
704 seq, ssz);
705 if (uc > 0)
706 sz += cond_width(p, uc, &skip);
707 }
708 continue;
709 case ESCAPE_SKIPCHAR:
710 skip = 1;
711 continue;
712 case ESCAPE_OVERSTRIKE:
713 rsz = 0;
714 rhs = seq + ssz;
715 while (seq < rhs) {
716 if (*seq == '\\') {
717 mandoc_escape(&seq, NULL, NULL);
718 continue;
719 }
720 i = (*p->width)(p, *seq++);
721 if (rsz < i)
722 rsz = i;
723 }
724 sz += rsz;
725 continue;
726 default:
727 continue;
728 }
729
730 /*
731 * Common handling for Unicode and numbered
732 * character escape sequences.
733 */
734
735 if (rhs == NULL) {
736 if (p->enc == TERMENC_ASCII) {
737 rhs = ascii_uc2str(uc);
738 rsz = strlen(rhs);
739 } else {
740 if ((uc < 0x20 && uc != 0x09) ||
741 (uc > 0x7E && uc < 0xA0))
742 uc = 0xFFFD;
743 sz += cond_width(p, uc, &skip);
744 continue;
745 }
746 }
747
748 if (skip) {
749 skip = 0;
750 break;
751 }
752
753 /*
754 * Common handling for all escape sequences
755 * printing more than one character.
756 */
757
758 for (i = 0; i < rsz; i++)
759 sz += (*p->width)(p, *rhs++);
760 break;
761 case ASCII_NBRSP:
762 sz += cond_width(p, ' ', &skip);
763 cp++;
764 break;
765 case ASCII_HYPH:
766 sz += cond_width(p, '-', &skip);
767 cp++;
768 /* FALLTHROUGH */
769 case ASCII_BREAK:
770 break;
771 default:
772 break;
773 }
774 }
775
776 return(sz);
777 }
778
779 int
780 term_vspan(const struct termp *p, const struct roffsu *su)
781 {
782 double r;
783 int ri;
784
785 switch (su->unit) {
786 case SCALE_BU:
787 r = su->scale / 40.0;
788 break;
789 case SCALE_CM:
790 r = su->scale * 6.0 / 2.54;
791 break;
792 case SCALE_FS:
793 r = su->scale * 65536.0 / 40.0;
794 break;
795 case SCALE_IN:
796 r = su->scale * 6.0;
797 break;
798 case SCALE_MM:
799 r = su->scale * 0.006;
800 break;
801 case SCALE_PC:
802 r = su->scale;
803 break;
804 case SCALE_PT:
805 r = su->scale / 12.0;
806 break;
807 case SCALE_EN:
808 /* FALLTHROUGH */
809 case SCALE_EM:
810 r = su->scale * 0.6;
811 break;
812 case SCALE_VS:
813 r = su->scale;
814 break;
815 default:
816 abort();
817 /* NOTREACHED */
818 }
819 ri = r > 0.0 ? r + 0.4995 : r - 0.4995;
820 return(ri < 66 ? ri : 1);
821 }
822
823 /*
824 * Convert a scaling width to basic units, rounding down.
825 */
826 int
827 term_hspan(const struct termp *p, const struct roffsu *su)
828 {
829
830 return((*p->hspan)(p, su));
831 }