Lines Matching full:p
47 term_setcol(struct termp *p, size_t maxtcol) in term_setcol() argument
49 if (maxtcol > p->maxtcol) { in term_setcol()
50 p->tcols = mandoc_recallocarray(p->tcols, in term_setcol()
51 p->maxtcol, maxtcol, sizeof(*p->tcols)); in term_setcol()
52 p->maxtcol = maxtcol; in term_setcol()
54 p->lasttcol = maxtcol - 1; in term_setcol()
55 p->tcol = p->tcols; in term_setcol()
59 term_free(struct termp *p) in term_free() argument
62 for (p->tcol = p->tcols; p->tcol < p->tcols + p->maxtcol; p->tcol++) in term_free()
63 free(p->tcol->buf); in term_free()
64 free(p->tcols); in term_free()
65 free(p->fontq); in term_free()
66 free(p); in term_free()
70 term_begin(struct termp *p, term_margin head, in term_begin() argument
74 p->headf = head; in term_begin()
75 p->footf = foot; in term_begin()
76 p->argf = arg; in term_begin()
77 (*p->begin)(p); in term_begin()
81 term_end(struct termp *p) in term_end() argument
84 (*p->end)(p); in term_end()
95 term_flushln(struct termp *p) in term_flushln() argument
109 vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ? in term_flushln()
110 0 : p->tcol->offset - p->viscol; in term_flushln()
111 if (p->minbl && vbl < p->minbl) in term_flushln()
112 vbl = p->minbl; in term_flushln()
114 if ((p->flags & TERMP_MULTICOL) == 0) in term_flushln()
115 p->tcol->col = 0; in term_flushln()
120 vfield = p->tcol->rmargin > p->viscol + vbl ? in term_flushln()
121 p->tcol->rmargin - p->viscol - vbl : 0; in term_flushln()
130 vtarget = (p->flags & TERMP_NOBREAK) == 0 ? vfield : in term_flushln()
131 p->maxrmargin > p->viscol + vbl ? in term_flushln()
132 p->maxrmargin - p->viscol - vbl : 0; in term_flushln()
139 term_fill(p, &nbr, &vbr, in term_flushln()
140 p->flags & TERMP_BRNEVER ? SIZE_MAX : vtarget); in term_flushln()
151 if (p->flags & TERMP_CENTER) in term_flushln()
153 else if (p->flags & TERMP_RIGHT) in term_flushln()
159 term_field(p, vbl, nbr); in term_flushln()
161 p->tcol->taboff += vbr; in term_flushln()
163 p->tcol->taboff += vtarget; in term_flushln()
164 p->tcol->taboff += (*p->width)(p, ' '); in term_flushln()
173 for (ic = p->tcol->col; ic < p->tcol->lastcol; ic++) { in term_flushln()
174 switch (p->tcol->buf[ic]) { in term_flushln()
176 if (p->flags & TERMP_BRTRSP) in term_flushln()
180 if (p->flags & TERMP_BRTRSP) in term_flushln()
181 vbr += (*p->width)(p, ' '); in term_flushln()
193 if (ic == p->tcol->lastcol) in term_flushln()
201 while (p->tcol->col < p->tcol->lastcol && in term_flushln()
202 p->tcol->buf[p->tcol->col] == ' ') in term_flushln()
203 p->tcol->col++; in term_flushln()
213 if (p->flags & TERMP_MULTICOL) in term_flushln()
216 endline(p); in term_flushln()
225 vbl = p->flags & TERMP_BRIND ? in term_flushln()
226 p->tcol->rmargin : p->tcol->offset; in term_flushln()
231 p->col = p->tcol->col = p->tcol->lastcol = 0; in term_flushln()
232 p->minbl = p->trailspace; in term_flushln()
233 p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE | TERMP_NOPAD); in term_flushln()
235 if (p->flags & TERMP_MULTICOL) in term_flushln()
246 if ((p->flags & TERMP_HANG) == 0 && in term_flushln()
247 ((p->flags & TERMP_NOBREAK) == 0 || in term_flushln()
248 vbr + term_len(p, p->trailspace) > vfield)) in term_flushln()
249 endline(p); in term_flushln()
260 term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget) in term_fill() argument
271 taboff = p->tcol->taboff; in term_fill()
272 for (ic = p->tcol->col; ic < p->tcol->lastcol; ic++) { in term_fill()
273 switch (p->tcol->buf[ic]) { in term_fill()
276 vis -= (*p->width)(p, p->tcol->buf[ic - 1]); in term_fill()
282 if (p->tcol->buf[ic] == ' ') in term_fill()
283 vn += (*p->width)(p, ' '); in term_fill()
295 case '\n': /* Escape \p (break at the end of the word). */ in term_fill()
307 p->tcol->buf[ic] = '-'; in term_fill()
308 vis += (*p->width)(p, '-'); in term_fill()
318 taboff = -vis - (*p->width)(p, ' '); in term_fill()
322 switch (p->tcol->buf[ic]) { in term_fill()
334 p->tcol->buf[ic] = ' '; in term_fill()
337 vis += (*p->width)(p, p->tcol->buf[ic]); in term_fill()
366 term_field(struct termp *p, size_t vbl, size_t nbr) in term_field() argument
375 taboff = p->tcol->taboff; in term_field()
376 for (ic = p->tcol->col; ic < nbr; ic++) { in term_field()
383 switch (p->tcol->buf[ic]) { in term_field()
389 taboff = -vis - (*p->width)(p, ' '); in term_field()
394 if (p->tcol->buf[ic] == '\t') { in term_field()
401 dv = (*p->width)(p, ' '); in term_field()
415 (*p->advance)(p, vbl); in term_field()
416 p->viscol += vbl; in term_field()
422 (*p->letter)(p, p->tcol->buf[ic]); in term_field()
423 if (p->tcol->buf[ic] == '\b') { in term_field()
424 dv = (*p->width)(p, p->tcol->buf[ic - 1]); in term_field()
425 p->viscol -= dv; in term_field()
428 dv = (*p->width)(p, p->tcol->buf[ic]); in term_field()
429 p->viscol += dv; in term_field()
433 p->tcol->col = nbr; in term_field()
437 endline(struct termp *p) in endline() argument
439 if ((p->flags & (TERMP_NEWMC | TERMP_ENDMC)) == TERMP_ENDMC) { in endline()
440 p->mc = NULL; in endline()
441 p->flags &= ~TERMP_ENDMC; in endline()
443 if (p->mc != NULL) { in endline()
444 if (p->viscol && p->maxrmargin >= p->viscol) in endline()
445 (*p->advance)(p, p->maxrmargin - p->viscol + 1); in endline()
446 p->flags |= TERMP_NOBUF | TERMP_NOSPACE; in endline()
447 term_word(p, p->mc); in endline()
448 p->flags &= ~(TERMP_NOBUF | TERMP_NEWMC); in endline()
450 p->viscol = 0; in endline()
451 p->minbl = 0; in endline()
452 (*p->endline)(p); in endline()
461 term_newln(struct termp *p) in term_newln() argument
463 p->flags |= TERMP_NOSPACE; in term_newln()
464 if (p->tcol->lastcol || p->viscol) in term_newln()
465 term_flushln(p); in term_newln()
466 p->tcol->taboff = 0; in term_newln()
476 term_vspace(struct termp *p) in term_vspace() argument
479 term_newln(p); in term_vspace()
480 p->viscol = 0; in term_vspace()
481 p->minbl = 0; in term_vspace()
482 if (0 < p->skipvsp) in term_vspace()
483 p->skipvsp--; in term_vspace()
485 (*p->endline)(p); in term_vspace()
488 /* Swap current and previous font; for \fP and .ft P */
490 term_fontlast(struct termp *p) in term_fontlast() argument
494 f = p->fontl; in term_fontlast()
495 p->fontl = p->fontq[p->fonti]; in term_fontlast()
496 p->fontq[p->fonti] = f; in term_fontlast()
501 term_fontrepl(struct termp *p, enum termfont f) in term_fontrepl() argument
504 p->fontl = p->fontq[p->fonti]; in term_fontrepl()
505 p->fontq[p->fonti] = f; in term_fontrepl()
510 term_fontpush(struct termp *p, enum termfont f) in term_fontpush() argument
513 p->fontl = p->fontq[p->fonti]; in term_fontpush()
514 if (++p->fonti == p->fontsz) { in term_fontpush()
515 p->fontsz += 8; in term_fontpush()
516 p->fontq = mandoc_reallocarray(p->fontq, in term_fontpush()
517 p->fontsz, sizeof(*p->fontq)); in term_fontpush()
519 p->fontq[p->fonti] = f; in term_fontpush()
524 term_fontpopq(struct termp *p, int i) in term_fontpopq() argument
528 if (p->fonti > i) in term_fontpopq()
529 p->fonti = i; in term_fontpopq()
534 term_fontpop(struct termp *p) in term_fontpop() argument
537 assert(p->fonti); in term_fontpop()
538 p->fonti--; in term_fontpop()
547 term_word(struct termp *p, const char *word) in term_word() argument
556 if ((p->flags & TERMP_NOBUF) == 0) { in term_word()
557 if ((p->flags & TERMP_NOSPACE) == 0) { in term_word()
558 if ((p->flags & TERMP_KEEP) == 0) { in term_word()
559 bufferc(p, ' '); in term_word()
560 if (p->flags & TERMP_SENTENCE) in term_word()
561 bufferc(p, ' '); in term_word()
563 bufferc(p, ASCII_NBRSP); in term_word()
565 if (p->flags & TERMP_PREKEEP) in term_word()
566 p->flags |= TERMP_KEEP; in term_word()
567 if (p->flags & TERMP_NONOSPACE) in term_word()
568 p->flags |= TERMP_NOSPACE; in term_word()
570 p->flags &= ~TERMP_NOSPACE; in term_word()
571 p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE); in term_word()
572 p->skipvsp = 0; in term_word()
577 if (TERMP_NBRWORD & p->flags) { in term_word()
579 encode(p, nbrsp, 1); in term_word()
586 encode(p, word, ssz); in term_word()
601 bufferc(p, ASCII_NBRZW); in term_word()
604 if (p->enc == TERMENC_ASCII) { in term_word()
607 encode(p, cp, ssz); in term_word()
609 bufferc(p, ASCII_NBRZW); in term_word()
613 encode1(p, uc); in term_word()
615 bufferc(p, ASCII_NBRZW); in term_word()
623 term_fontrepl(p, TERMFONT_BOLD); in term_word()
627 term_fontrepl(p, TERMFONT_UNDER); in term_word()
630 term_fontrepl(p, TERMFONT_BI); in term_word()
635 term_fontrepl(p, TERMFONT_NONE); in term_word()
638 term_fontlast(p); in term_word()
641 bufferc(p, '\n'); in term_word()
644 if (p->flags & TERMP_BACKAFTER) in term_word()
645 p->flags &= ~TERMP_BACKAFTER; in term_word()
647 p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE); in term_word()
650 if (p->type == TERMTYPE_PDF) in term_word()
651 encode(p, "pdf", 3); in term_word()
652 else if (p->type == TERMTYPE_PS) in term_word()
653 encode(p, "ps", 2); in term_word()
654 else if (p->enc == TERMENC_ASCII) in term_word()
655 encode(p, "ascii", 5); in term_word()
657 encode(p, "utf8", 4); in term_word()
660 if (p->flags & TERMP_BACKAFTER) { in term_word()
661 p->flags &= ~TERMP_BACKAFTER; in term_word()
666 uc = -p->col; in term_word()
671 uc += term_hen(p, &su); in term_word()
674 uc -= term_len(p, 1); in term_word()
675 if (p->flags & TERMP_BACKBEFORE) in term_word()
676 p->flags &= ~TERMP_BACKBEFORE; in term_word()
678 bufferc(p, ASCII_NBRSP); in term_word()
682 if (p->flags & TERMP_BACKBEFORE) { in term_word()
683 p->flags &= ~TERMP_BACKBEFORE; in term_word()
684 assert(p->col > 0); in term_word()
685 p->col--; in term_word()
687 if (p->col >= (size_t)(-uc)) { in term_word()
688 p->col += uc; in term_word()
690 uc += p->col; in term_word()
691 p->col = 0; in term_word()
692 if (p->tcol->offset > (size_t)(-uc)) { in term_word()
693 p->ti += uc; in term_word()
694 p->tcol->offset += uc; in term_word()
696 p->ti -= p->tcol->offset; in term_word()
697 p->tcol->offset = 0; in term_word()
704 uc = term_hen(p, &su); in term_word()
706 if (p->tcol->rmargin <= p->tcol->offset) in term_word()
708 lsz = p->tcol->rmargin - p->tcol->offset; in term_word()
737 if (p->enc == TERMENC_ASCII) { in term_word()
739 csz = term_strlen(p, cp); in term_word()
742 csz = (*p->width)(p, uc); in term_word()
744 if (p->enc == TERMENC_ASCII) in term_word()
745 encode(p, cp, ssz); in term_word()
747 encode1(p, uc); in term_word()
752 p->flags |= TERMP_BACKAFTER; in term_word()
761 encode1(p, *seq++); in term_word()
763 if (p->flags & TERMP_BACKBEFORE) in term_word()
764 p->flags |= TERMP_BACKAFTER; in term_word()
766 p->flags |= TERMP_BACKBEFORE; in term_word()
770 if (p->tcol->lastcol > 2 && in term_word()
771 (p->tcol->buf[p->tcol->lastcol - 1] == ' ' || in term_word()
772 p->tcol->buf[p->tcol->lastcol - 1] == '\t')) in term_word()
773 p->tcol->lastcol -= 2; in term_word()
774 if (p->col > p->tcol->lastcol) in term_word()
775 p->col = p->tcol->lastcol; in term_word()
778 bufferc(p, ASCII_NBRZW); in term_word()
789 if (p->enc == TERMENC_ASCII) { in term_word()
791 encode(p, cp, strlen(cp)); in term_word()
796 encode1(p, uc); in term_word()
799 p->flags &= ~TERMP_NBRWORD; in term_word()
813 bufferc(struct termp *p, char c) in bufferc() argument
815 if (p->flags & TERMP_NOBUF) { in bufferc()
816 (*p->letter)(p, c); in bufferc()
819 if (p->col + 1 >= p->tcol->maxcols) in bufferc()
820 adjbuf(p->tcol, p->col + 1); in bufferc()
821 if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP)) in bufferc()
822 p->tcol->buf[p->col] = c; in bufferc()
823 if (p->tcol->lastcol < ++p->col) in bufferc()
824 p->tcol->lastcol = p->col; in bufferc()
828 term_tab_ref(struct termp *p) in term_tab_ref() argument
830 if (p->tcol->lastcol && p->tcol->lastcol <= p->col && in term_tab_ref()
831 (p->flags & TERMP_NOBUF) == 0) in term_tab_ref()
832 bufferc(p, ASCII_TABREF); in term_tab_ref()
841 encode1(struct termp *p, int c) in encode1() argument
845 if (p->flags & TERMP_NOBUF) { in encode1()
846 (*p->letter)(p, c); in encode1()
850 if (p->col + 7 >= p->tcol->maxcols) in encode1()
851 adjbuf(p->tcol, p->col + 7); in encode1()
854 p->fontq[p->fonti] : TERMFONT_NONE; in encode1()
856 if (p->flags & TERMP_BACKBEFORE) { in encode1()
857 if (p->tcol->buf[p->col - 1] == ' ' || in encode1()
858 p->tcol->buf[p->col - 1] == '\t') in encode1()
859 p->col--; in encode1()
861 p->tcol->buf[p->col++] = '\b'; in encode1()
862 p->flags &= ~TERMP_BACKBEFORE; in encode1()
865 p->tcol->buf[p->col++] = '_'; in encode1()
866 p->tcol->buf[p->col++] = '\b'; in encode1()
870 p->tcol->buf[p->col++] = '-'; in encode1()
872 p->tcol->buf[p->col++] = c; in encode1()
873 p->tcol->buf[p->col++] = '\b'; in encode1()
875 if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP)) in encode1()
876 p->tcol->buf[p->col] = c; in encode1()
877 if (p->tcol->lastcol < ++p->col) in encode1()
878 p->tcol->lastcol = p->col; in encode1()
879 if (p->flags & TERMP_BACKAFTER) { in encode1()
880 p->flags |= TERMP_BACKBEFORE; in encode1()
881 p->flags &= ~TERMP_BACKAFTER; in encode1()
886 encode(struct termp *p, const char *word, size_t sz) in encode() argument
890 if (p->flags & TERMP_NOBUF) { in encode()
892 (*p->letter)(p, word[i]); in encode()
896 if (p->col + 2 + (sz * 5) >= p->tcol->maxcols) in encode()
897 adjbuf(p->tcol, p->col + 2 + (sz * 5)); in encode()
902 encode1(p, word[i]); in encode()
904 if (p->tcol->lastcol <= p->col || in encode()
906 p->tcol->buf[p->col] = word[i]; in encode()
907 p->col++; in encode()
915 (p->flags & TERMP_BACKBEFORE)) { in encode()
916 p->flags &= ~TERMP_BACKBEFORE; in encode()
917 p->flags |= TERMP_BACKAFTER; in encode()
921 if (p->tcol->lastcol < p->col) in encode()
922 p->tcol->lastcol = p->col; in encode()
926 term_setwidth(struct termp *p, const char *wstr) in term_setwidth() argument
947 width = term_hspan(p, &su); in term_setwidth()
951 (*p->setwidth)(p, iop, width); in term_setwidth()
955 term_len(const struct termp *p, size_t sz) in term_len() argument
958 return (*p->width)(p, ' ') * sz; in term_len()
962 cond_width(const struct termp *p, int c, int *skip) in cond_width() argument
969 return (*p->width)(p, c); in cond_width()
973 term_strlen(const struct termp *p, const char *cp) in term_strlen() argument
993 sz += cond_width(p, *cp++, &skip); in term_strlen()
1010 if (p->enc == TERMENC_ASCII) { in term_strlen()
1017 sz += cond_width(p, uc, &skip); in term_strlen()
1024 if (p->type == TERMTYPE_PDF) { in term_strlen()
1027 } else if (p->type == TERMTYPE_PS) { in term_strlen()
1030 } else if (p->enc == TERMENC_ASCII) { in term_strlen()
1049 i = (*p->width)(p, *seq++); in term_strlen()
1065 if (p->enc == TERMENC_ASCII) { in term_strlen()
1072 sz += cond_width(p, uc, &skip); in term_strlen()
1088 sz += (*p->width)(p, *rhs++); in term_strlen()
1091 sz += cond_width(p, ' ', &skip); in term_strlen()
1095 sz += cond_width(p, '-', &skip); in term_strlen()
1107 term_vspan(const struct termp *p, const struct roffsu *su) in term_vspan() argument
1152 term_hspan(const struct termp *p, const struct roffsu *su) in term_hspan() argument
1155 return (*p->hspan)(p, su); in term_hspan()
1162 term_hen(const struct termp *p, const struct roffsu *su) in term_hen() argument
1166 if ((bu = (*p->hspan)(p, su)) >= 0) in term_hen()