Lines Matching refs: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
61 for (p->tcol = p->tcols; p->tcol < p->tcols + p->maxtcol; p->tcol++) in term_free()
62 free(p->tcol->buf); in term_free()
63 free(p->tcols); in term_free()
64 free(p->fontq); in term_free()
65 free(p); in term_free()
69 term_begin(struct termp *p, term_margin head, in term_begin() argument
73 p->headf = head; in term_begin()
74 p->footf = foot; in term_begin()
75 p->argf = arg; in term_begin()
76 (*p->begin)(p); in term_begin()
80 term_end(struct termp *p) in term_end() argument
83 (*p->end)(p); in term_end()
94 term_flushln(struct termp *p) in term_flushln() argument
108 vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ? in term_flushln()
109 0 : p->tcol->offset - p->viscol; in term_flushln()
110 if (p->minbl && vbl < p->minbl) in term_flushln()
111 vbl = p->minbl; in term_flushln()
113 if ((p->flags & TERMP_MULTICOL) == 0) in term_flushln()
114 p->tcol->col = 0; in term_flushln()
119 vfield = p->tcol->rmargin > p->viscol + vbl ? in term_flushln()
120 p->tcol->rmargin - p->viscol - vbl : 0; in term_flushln()
129 vtarget = (p->flags & TERMP_NOBREAK) == 0 ? vfield : in term_flushln()
130 p->maxrmargin > p->viscol + vbl ? in term_flushln()
131 p->maxrmargin - p->viscol - vbl : 0; in term_flushln()
138 term_fill(p, &nbr, &vbr, in term_flushln()
139 p->flags & TERMP_BRNEVER ? SIZE_MAX : vtarget); in term_flushln()
150 if (p->flags & TERMP_CENTER) in term_flushln()
152 else if (p->flags & TERMP_RIGHT) in term_flushln()
158 term_field(p, vbl, nbr); in term_flushln()
167 for (ic = p->tcol->col; ic < p->tcol->lastcol; ic++) { in term_flushln()
168 switch (p->tcol->buf[ic]) { in term_flushln()
170 if (p->flags & TERMP_BRTRSP) in term_flushln()
174 if (p->flags & TERMP_BRTRSP) in term_flushln()
175 vbr += (*p->width)(p, ' '); in term_flushln()
185 if (ic == p->tcol->lastcol) in term_flushln()
193 while (p->tcol->col < p->tcol->lastcol && in term_flushln()
194 p->tcol->buf[p->tcol->col] == ' ') in term_flushln()
195 p->tcol->col++; in term_flushln()
205 if (p->flags & TERMP_MULTICOL) in term_flushln()
208 endline(p); in term_flushln()
209 p->viscol = 0; in term_flushln()
218 vbl = p->flags & TERMP_BRIND ? in term_flushln()
219 p->tcol->rmargin : p->tcol->offset; in term_flushln()
224 p->col = p->tcol->col = p->tcol->lastcol = 0; in term_flushln()
225 p->minbl = p->trailspace; in term_flushln()
226 p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE | TERMP_NOPAD); in term_flushln()
228 if (p->flags & TERMP_MULTICOL) in term_flushln()
239 if ((p->flags & TERMP_HANG) == 0 && in term_flushln()
240 ((p->flags & TERMP_NOBREAK) == 0 || in term_flushln()
241 vbr + term_len(p, p->trailspace) > vfield)) in term_flushln()
242 endline(p); in term_flushln()
253 term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget) in term_fill() argument
263 for (ic = p->tcol->col; ic < p->tcol->lastcol; ic++) { in term_fill()
264 switch (p->tcol->buf[ic]) { in term_fill()
267 vis -= (*p->width)(p, p->tcol->buf[ic - 1]); in term_fill()
273 switch (p->tcol->buf[ic]) { in term_fill()
278 vn = vis + (*p->width)(p, ' '); in term_fill()
309 p->tcol->buf[ic] = '-'; in term_fill()
310 vis += (*p->width)(p, '-'); in term_fill()
320 p->tcol->buf[ic] = ' '; in term_fill()
324 vis += (*p->width)(p, p->tcol->buf[ic]); in term_fill()
350 term_field(struct termp *p, size_t vbl, size_t nbr) in term_field() argument
358 for (ic = p->tcol->col; ic < nbr; ic++) { in term_field()
365 switch (p->tcol->buf[ic]) { in term_field()
376 dv = (*p->width)(p, ' '); in term_field()
390 (*p->advance)(p, vbl); in term_field()
391 p->viscol += vbl; in term_field()
397 (*p->letter)(p, p->tcol->buf[ic]); in term_field()
398 if (p->tcol->buf[ic] == '\b') { in term_field()
399 dv = (*p->width)(p, p->tcol->buf[ic - 1]); in term_field()
400 p->viscol -= dv; in term_field()
403 dv = (*p->width)(p, p->tcol->buf[ic]); in term_field()
404 p->viscol += dv; in term_field()
408 p->tcol->col = nbr; in term_field()
412 endline(struct termp *p) in endline() argument
414 if ((p->flags & (TERMP_NEWMC | TERMP_ENDMC)) == TERMP_ENDMC) { in endline()
415 p->mc = NULL; in endline()
416 p->flags &= ~TERMP_ENDMC; in endline()
418 if (p->mc != NULL) { in endline()
419 if (p->viscol && p->maxrmargin >= p->viscol) in endline()
420 (*p->advance)(p, p->maxrmargin - p->viscol + 1); in endline()
421 p->flags |= TERMP_NOBUF | TERMP_NOSPACE; in endline()
422 term_word(p, p->mc); in endline()
423 p->flags &= ~(TERMP_NOBUF | TERMP_NEWMC); in endline()
425 p->viscol = 0; in endline()
426 p->minbl = 0; in endline()
427 (*p->endline)(p); in endline()
436 term_newln(struct termp *p) in term_newln() argument
439 p->flags |= TERMP_NOSPACE; in term_newln()
440 if (p->tcol->lastcol || p->viscol) in term_newln()
441 term_flushln(p); in term_newln()
451 term_vspace(struct termp *p) in term_vspace() argument
454 term_newln(p); in term_vspace()
455 p->viscol = 0; in term_vspace()
456 p->minbl = 0; in term_vspace()
457 if (0 < p->skipvsp) in term_vspace()
458 p->skipvsp--; in term_vspace()
460 (*p->endline)(p); in term_vspace()
465 term_fontlast(struct termp *p) in term_fontlast() argument
469 f = p->fontl; in term_fontlast()
470 p->fontl = p->fontq[p->fonti]; in term_fontlast()
471 p->fontq[p->fonti] = f; in term_fontlast()
476 term_fontrepl(struct termp *p, enum termfont f) in term_fontrepl() argument
479 p->fontl = p->fontq[p->fonti]; in term_fontrepl()
480 p->fontq[p->fonti] = f; in term_fontrepl()
485 term_fontpush(struct termp *p, enum termfont f) in term_fontpush() argument
488 p->fontl = p->fontq[p->fonti]; in term_fontpush()
489 if (++p->fonti == p->fontsz) { in term_fontpush()
490 p->fontsz += 8; in term_fontpush()
491 p->fontq = mandoc_reallocarray(p->fontq, in term_fontpush()
492 p->fontsz, sizeof(*p->fontq)); in term_fontpush()
494 p->fontq[p->fonti] = f; in term_fontpush()
499 term_fontpopq(struct termp *p, int i) in term_fontpopq() argument
503 if (p->fonti > i) in term_fontpopq()
504 p->fonti = i; in term_fontpopq()
509 term_fontpop(struct termp *p) in term_fontpop() argument
512 assert(p->fonti); in term_fontpop()
513 p->fonti--; in term_fontpop()
522 term_word(struct termp *p, const char *word) in term_word() argument
531 if ((p->flags & TERMP_NOBUF) == 0) { in term_word()
532 if ((p->flags & TERMP_NOSPACE) == 0) { in term_word()
533 if ((p->flags & TERMP_KEEP) == 0) { in term_word()
534 bufferc(p, ' '); in term_word()
535 if (p->flags & TERMP_SENTENCE) in term_word()
536 bufferc(p, ' '); in term_word()
538 bufferc(p, ASCII_NBRSP); in term_word()
540 if (p->flags & TERMP_PREKEEP) in term_word()
541 p->flags |= TERMP_KEEP; in term_word()
542 if (p->flags & TERMP_NONOSPACE) in term_word()
543 p->flags |= TERMP_NOSPACE; in term_word()
545 p->flags &= ~TERMP_NOSPACE; in term_word()
546 p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE); in term_word()
547 p->skipvsp = 0; in term_word()
552 if (TERMP_NBRWORD & p->flags) { in term_word()
554 encode(p, nbrsp, 1); in term_word()
561 encode(p, word, ssz); in term_word()
578 if (p->enc == TERMENC_ASCII) { in term_word()
581 encode(p, cp, ssz); in term_word()
585 encode1(p, uc); in term_word()
593 term_fontrepl(p, TERMFONT_BOLD); in term_word()
597 term_fontrepl(p, TERMFONT_UNDER); in term_word()
600 term_fontrepl(p, TERMFONT_BI); in term_word()
605 term_fontrepl(p, TERMFONT_NONE); in term_word()
608 term_fontlast(p); in term_word()
611 bufferc(p, '\n'); in term_word()
614 if (p->flags & TERMP_BACKAFTER) in term_word()
615 p->flags &= ~TERMP_BACKAFTER; in term_word()
617 p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE); in term_word()
620 if (p->type == TERMTYPE_PDF) in term_word()
621 encode(p, "pdf", 3); in term_word()
622 else if (p->type == TERMTYPE_PS) in term_word()
623 encode(p, "ps", 2); in term_word()
624 else if (p->enc == TERMENC_ASCII) in term_word()
625 encode(p, "ascii", 5); in term_word()
627 encode(p, "utf8", 4); in term_word()
632 uc = -p->col; in term_word()
637 uc += term_hen(p, &su); in term_word()
640 bufferc(p, ASCII_NBRSP); in term_word()
641 else if (p->col > (size_t)(-uc)) in term_word()
642 p->col += uc; in term_word()
644 uc += p->col; in term_word()
645 p->col = 0; in term_word()
646 if (p->tcol->offset > (size_t)(-uc)) { in term_word()
647 p->ti += uc; in term_word()
648 p->tcol->offset += uc; in term_word()
650 p->ti -= p->tcol->offset; in term_word()
651 p->tcol->offset = 0; in term_word()
658 uc = term_hen(p, &su); in term_word()
660 if (p->tcol->rmargin <= p->tcol->offset) in term_word()
662 lsz = p->tcol->rmargin - p->tcol->offset; in term_word()
691 if (p->enc == TERMENC_ASCII) { in term_word()
693 csz = term_strlen(p, cp); in term_word()
696 csz = (*p->width)(p, uc); in term_word()
698 if (p->enc == TERMENC_ASCII) in term_word()
699 encode(p, cp, ssz); in term_word()
701 encode1(p, uc); in term_word()
706 p->flags |= TERMP_BACKAFTER; in term_word()
715 encode1(p, *seq++); in term_word()
717 if (p->flags & TERMP_BACKBEFORE) in term_word()
718 p->flags |= TERMP_BACKAFTER; in term_word()
720 p->flags |= TERMP_BACKBEFORE; in term_word()
724 if (p->tcol->lastcol > 2 && in term_word()
725 (p->tcol->buf[p->tcol->lastcol - 1] == ' ' || in term_word()
726 p->tcol->buf[p->tcol->lastcol - 1] == '\t')) in term_word()
727 p->tcol->lastcol -= 2; in term_word()
728 if (p->col > p->tcol->lastcol) in term_word()
729 p->col = p->tcol->lastcol; in term_word()
740 if (p->enc == TERMENC_ASCII) { in term_word()
742 encode(p, cp, strlen(cp)); in term_word()
747 encode1(p, uc); in term_word()
750 p->flags &= ~TERMP_NBRWORD; in term_word()
764 bufferc(struct termp *p, char c) in bufferc() argument
766 if (p->flags & TERMP_NOBUF) { in bufferc()
767 (*p->letter)(p, c); in bufferc()
770 if (p->col + 1 >= p->tcol->maxcols) in bufferc()
771 adjbuf(p->tcol, p->col + 1); in bufferc()
772 if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP)) in bufferc()
773 p->tcol->buf[p->col] = c; in bufferc()
774 if (p->tcol->lastcol < ++p->col) in bufferc()
775 p->tcol->lastcol = p->col; in bufferc()
784 encode1(struct termp *p, int c) in encode1() argument
788 if (p->flags & TERMP_NOBUF) { in encode1()
789 (*p->letter)(p, c); in encode1()
793 if (p->col + 7 >= p->tcol->maxcols) in encode1()
794 adjbuf(p->tcol, p->col + 7); in encode1()
797 p->fontq[p->fonti] : TERMFONT_NONE; in encode1()
799 if (p->flags & TERMP_BACKBEFORE) { in encode1()
800 if (p->tcol->buf[p->col - 1] == ' ' || in encode1()
801 p->tcol->buf[p->col - 1] == '\t') in encode1()
802 p->col--; in encode1()
804 p->tcol->buf[p->col++] = '\b'; in encode1()
805 p->flags &= ~TERMP_BACKBEFORE; in encode1()
808 p->tcol->buf[p->col++] = '_'; in encode1()
809 p->tcol->buf[p->col++] = '\b'; in encode1()
813 p->tcol->buf[p->col++] = '-'; in encode1()
815 p->tcol->buf[p->col++] = c; in encode1()
816 p->tcol->buf[p->col++] = '\b'; in encode1()
818 if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP)) in encode1()
819 p->tcol->buf[p->col] = c; in encode1()
820 if (p->tcol->lastcol < ++p->col) in encode1()
821 p->tcol->lastcol = p->col; in encode1()
822 if (p->flags & TERMP_BACKAFTER) { in encode1()
823 p->flags |= TERMP_BACKBEFORE; in encode1()
824 p->flags &= ~TERMP_BACKAFTER; in encode1()
829 encode(struct termp *p, const char *word, size_t sz) in encode() argument
833 if (p->flags & TERMP_NOBUF) { in encode()
835 (*p->letter)(p, word[i]); in encode()
839 if (p->col + 2 + (sz * 5) >= p->tcol->maxcols) in encode()
840 adjbuf(p->tcol, p->col + 2 + (sz * 5)); in encode()
845 encode1(p, word[i]); in encode()
847 if (p->tcol->lastcol <= p->col || in encode()
849 p->tcol->buf[p->col] = word[i]; in encode()
850 p->col++; in encode()
858 (p->flags & TERMP_BACKBEFORE)) { in encode()
859 p->flags &= ~TERMP_BACKBEFORE; in encode()
860 p->flags |= TERMP_BACKAFTER; in encode()
864 if (p->tcol->lastcol < p->col) in encode()
865 p->tcol->lastcol = p->col; in encode()
869 term_setwidth(struct termp *p, const char *wstr) in term_setwidth() argument
890 width = term_hspan(p, &su); in term_setwidth()
894 (*p->setwidth)(p, iop, width); in term_setwidth()
898 term_len(const struct termp *p, size_t sz) in term_len() argument
901 return (*p->width)(p, ' ') * sz; in term_len()
905 cond_width(const struct termp *p, int c, int *skip) in cond_width() argument
912 return (*p->width)(p, c); in cond_width()
916 term_strlen(const struct termp *p, const char *cp) in term_strlen() argument
936 sz += cond_width(p, *cp++, &skip); in term_strlen()
953 if (p->enc == TERMENC_ASCII) { in term_strlen()
960 sz += cond_width(p, uc, &skip); in term_strlen()
967 if (p->type == TERMTYPE_PDF) { in term_strlen()
970 } else if (p->type == TERMTYPE_PS) { in term_strlen()
973 } else if (p->enc == TERMENC_ASCII) { in term_strlen()
992 i = (*p->width)(p, *seq++); in term_strlen()
1008 if (p->enc == TERMENC_ASCII) { in term_strlen()
1015 sz += cond_width(p, uc, &skip); in term_strlen()
1031 sz += (*p->width)(p, *rhs++); in term_strlen()
1034 sz += cond_width(p, ' ', &skip); in term_strlen()
1038 sz += cond_width(p, '-', &skip); in term_strlen()
1050 term_vspan(const struct termp *p, const struct roffsu *su) in term_vspan() argument
1095 term_hspan(const struct termp *p, const struct roffsu *su) in term_hspan() argument
1098 return (*p->hspan)(p, su); in term_hspan()
1105 term_hen(const struct termp *p, const struct roffsu *su) in term_hen() argument
1109 if ((bu = (*p->hspan)(p, su)) >= 0) in term_hen()