Lines Matching full:p
47 term_setcol(struct termp *p, size_t maxtcol)
49 if (maxtcol > p->maxtcol) {
50 p->tcols = mandoc_recallocarray(p->tcols,
51 p->maxtcol, maxtcol, sizeof(*p->tcols));
52 p->maxtcol = maxtcol;
54 p->lasttcol = maxtcol - 1;
55 p->tcol = p->tcols;
59 term_free(struct termp *p)
62 for (p->tcol = p->tcols; p->tcol < p->tcols + p->maxtcol; p->tcol++)
63 free(p->tcol->buf);
64 free(p->tcols);
65 free(p->fontq);
66 free(p);
70 term_begin(struct termp *p, term_margin head,
74 p->headf = head;
75 p->footf = foot;
76 p->argf = arg;
77 (*p->begin)(p);
81 term_end(struct termp *p)
84 (*p->end)(p);
95 term_flushln(struct termp *p)
112 vbl = (p->flags & TERMP_NOPAD) || p->tcol->offset < p->viscol ?
113 0 : p->tcol->offset - p->viscol;
114 if (p->minbl > 0 && vbl < term_len(p, p->minbl))
115 vbl = term_len(p, p->minbl);
117 if ((p->flags & TERMP_MULTICOL) == 0)
118 p->tcol->col = 0;
123 vfield = p->tcol->rmargin > p->viscol + vbl ?
124 p->tcol->rmargin - p->viscol - vbl : 0;
133 vtarget = (p->flags & TERMP_NOBREAK) == 0 ? vfield :
134 p->maxrmargin > p->viscol + vbl ?
135 p->maxrmargin - p->viscol - vbl : 0;
142 term_fill(p, &nbr, &vbr,
143 p->flags & TERMP_BRNEVER ? SIZE_MAX / 2 : vtarget);
154 if (p->flags & TERMP_CENTER)
156 else if (p->flags & TERMP_RIGHT)
162 term_field(p, vbl, nbr);
164 p->tcol->taboff += vbr;
166 p->tcol->taboff += vtarget;
167 p->tcol->taboff += term_len(p, 1);
176 for (ic = p->tcol->col; ic < p->tcol->lastcol; ic++) {
177 switch (p->tcol->buf[ic]) {
179 if (p->flags & TERMP_BRTRSP)
183 if (p->flags & TERMP_BRTRSP)
184 vbr += term_len(p, 1);
196 if (ic == p->tcol->lastcol)
204 while (p->tcol->col < p->tcol->lastcol &&
205 p->tcol->buf[p->tcol->col] == ' ')
206 p->tcol->col++;
216 if (p->flags & TERMP_MULTICOL)
219 endline(p);
228 vbl = p->flags & TERMP_BRIND ?
229 p->tcol->rmargin : p->tcol->offset;
234 p->col = p->tcol->col = p->tcol->lastcol = 0;
235 p->minbl = p->trailspace;
236 p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE | TERMP_NOPAD);
238 if (p->flags & TERMP_MULTICOL)
249 if ((p->flags & TERMP_HANG) == 0 &&
250 ((p->flags & TERMP_NOBREAK) == 0 ||
251 vbr + term_len(p, p->trailspace) > vfield + term_len(p, 1) / 2))
252 endline(p);
263 term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget)
277 taboff = p->tcol->taboff;
278 enw = (*p->getwidth)(p, ' ');
280 for (ic = p->tcol->col; ic < p->tcol->lastcol; ic++) {
281 switch (p->tcol->buf[ic]) {
284 vis -= (*p->getwidth)(p, p->tcol->buf[ic - 1]);
290 if (p->tcol->buf[ic] == ' ')
303 case '\n': /* Escape \p (break at the end of the word). */
315 p->tcol->buf[ic] = '-';
316 vis += (*p->getwidth)(p, '-');
330 switch (p->tcol->buf[ic]) {
342 p->tcol->buf[ic] = ' ';
345 vis += (*p->getwidth)(p, p->tcol->buf[ic]);
374 term_field(struct termp *p, size_t vbl, size_t nbr)
385 taboff = p->tcol->taboff;
386 for (ic = p->tcol->col; ic < nbr; ic++) {
393 switch (p->tcol->buf[ic]) {
399 taboff = -vis - (*p->getwidth)(p, ' ');
404 if (p->tcol->buf[ic] == '\t') {
411 dv = (*p->getwidth)(p, ' ');
425 (*p->advance)(p, vbl);
431 (*p->letter)(p, p->tcol->buf[ic]);
432 if (p->tcol->buf[ic] == '\b') {
433 dv = (*p->getwidth)(p, p->tcol->buf[ic - 1]);
434 p->viscol -= dv;
437 dv = (*p->getwidth)(p, p->tcol->buf[ic]);
438 p->viscol += dv;
442 p->tcol->col = nbr;
450 endline(struct termp *p)
452 if ((p->flags & (TERMP_NEWMC | TERMP_ENDMC)) == TERMP_ENDMC) {
453 p->mc = NULL;
454 p->flags &= ~TERMP_ENDMC;
456 if (p->mc != NULL) {
457 if (p->viscol > 0 && p->viscol <= p->maxrmargin)
458 (*p->advance)(p,
459 p->maxrmargin - p->viscol + term_len(p, 1));
460 p->flags |= TERMP_NOBUF | TERMP_NOSPACE;
461 term_word(p, p->mc);
462 p->flags &= ~(TERMP_NOBUF | TERMP_NEWMC);
464 (*p->endline)(p);
473 term_newln(struct termp *p)
475 p->flags |= TERMP_NOSPACE;
476 if (p->tcol->lastcol || p->viscol)
477 term_flushln(p);
478 p->tcol->taboff = 0;
488 term_vspace(struct termp *p)
491 term_newln(p);
492 if (0 < p->skipvsp)
493 p->skipvsp--;
495 (*p->endline)(p);
498 /* Swap current and previous font; for \fP and .ft P */
500 term_fontlast(struct termp *p)
504 f = p->fontl;
505 p->fontl = p->fontq[p->fonti];
506 p->fontq[p->fonti] = f;
511 term_fontrepl(struct termp *p, enum termfont f)
513 p->fontl = p->fontq[p->fonti];
514 if (p->fontibi && f == TERMFONT_UNDER)
516 p->fontq[p->fonti] = f;
521 term_fontpush(struct termp *p, enum termfont f)
525 fl = p->fontq[p->fonti];
526 if (++p->fonti == p->fontsz) {
527 p->fontsz += 8;
528 p->fontq = mandoc_reallocarray(p->fontq,
529 p->fontsz, sizeof(*p->fontq));
531 p->fontq[p->fonti] = fl;
532 term_fontrepl(p, f);
537 term_fontpopq(struct termp *p, int i)
540 if (p->fonti > i)
541 p->fonti = i;
546 term_fontpop(struct termp *p)
548 assert(p->fonti > 0);
549 p->fonti--;
558 term_word(struct termp *p, const char *word)
572 if ((p->flags & TERMP_NOBUF) == 0) {
573 if ((p->flags & TERMP_NOSPACE) == 0) {
574 if ((p->flags & TERMP_KEEP) == 0) {
575 bufferc(p, ' ');
576 if (p->flags & TERMP_SENTENCE)
577 bufferc(p, ' ');
579 bufferc(p, ASCII_NBRSP);
581 if (p->flags & TERMP_PREKEEP)
582 p->flags |= TERMP_KEEP;
583 if (p->flags & TERMP_NONOSPACE)
584 p->flags |= TERMP_NOSPACE;
586 p->flags &= ~TERMP_NOSPACE;
587 p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
588 p->skipvsp = 0;
593 if (TERMP_NBRWORD & p->flags) {
595 encode(p, nbrsp, 1);
602 encode(p, word, ssz);
617 bufferc(p, ASCII_NBRZW);
620 if (p->enc == TERMENC_ASCII) {
623 encode(p, cp, ssz);
625 bufferc(p, ASCII_NBRZW);
629 encode1(p, uc);
631 bufferc(p, ASCII_NBRZW);
639 term_fontrepl(p, TERMFONT_BOLD);
643 term_fontrepl(p, TERMFONT_UNDER);
646 term_fontrepl(p, TERMFONT_BI);
651 term_fontrepl(p, TERMFONT_NONE);
654 term_fontlast(p);
657 bufferc(p, '\n');
660 if (p->flags & TERMP_BACKAFTER)
661 p->flags &= ~TERMP_BACKAFTER;
663 p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
666 if (p->type == TERMTYPE_PDF)
667 encode(p, "pdf", 3);
668 else if (p->type == TERMTYPE_PS)
669 encode(p, "ps", 2);
670 else if (p->enc == TERMENC_ASCII)
671 encode(p, "ascii", 5);
673 encode(p, "utf8", 4);
676 if (p->flags & TERMP_BACKAFTER) {
677 p->flags &= ~TERMP_BACKAFTER;
682 bu = -term_len(p, p->col);
687 bu += term_hspan(p, &su);
690 bu -= term_len(p, 1);
691 if (p->flags & TERMP_BACKBEFORE)
692 p->flags &= ~TERMP_BACKBEFORE;
694 bufferc(p, ASCII_NBRSP);
698 if (p->flags & TERMP_BACKBEFORE) {
699 p->flags &= ~TERMP_BACKBEFORE;
700 assert(p->col > 1);
701 p->col--;
703 if (term_len(p, p->col) >= (size_t)(-bu)) {
704 p->col -= -bu / term_len(p, 1);
706 bu += term_len(p, p->col);
707 p->col = 0;
708 if (p->tcol->offset > (size_t)(-bu)) {
709 p->ti += bu;
710 p->tcol->offset += bu;
712 p->ti -= p->tcol->offset;
713 p->tcol->offset = 0;
720 bu = term_hspan(p, &su);
722 if (p->tcol->rmargin <= p->tcol->offset)
724 lsz = p->tcol->rmargin - p->tcol->offset;
753 if (p->enc == TERMENC_ASCII) {
755 csz = term_strlen(p, cp);
758 csz = (*p->getwidth)(p, uc);
760 if (p->enc == TERMENC_ASCII)
761 encode(p, cp, ssz);
763 encode1(p, uc);
771 p->flags |= TERMP_BACKAFTER;
780 encode1(p, *seq++);
782 if (p->flags & TERMP_BACKBEFORE)
783 p->flags |= TERMP_BACKAFTER;
785 p->flags |= TERMP_BACKBEFORE;
789 if (p->tcol->lastcol > 2 &&
790 (p->tcol->buf[p->tcol->lastcol - 1] == ' ' ||
791 p->tcol->buf[p->tcol->lastcol - 1] == '\t'))
792 p->tcol->lastcol -= 2;
793 if (p->col > p->tcol->lastcol)
794 p->col = p->tcol->lastcol;
797 bufferc(p, ASCII_NBRZW);
808 if (p->enc == TERMENC_ASCII) {
810 encode(p, cp, strlen(cp));
815 encode1(p, uc);
818 p->flags &= ~TERMP_NBRWORD;
832 bufferc(struct termp *p, char c)
834 if (p->flags & TERMP_NOBUF) {
835 (*p->letter)(p, c);
838 if (p->col + 1 >= p->tcol->maxcols)
839 adjbuf(p->tcol, p->col + 1);
840 if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))
841 p->tcol->buf[p->col] = c;
842 if (p->tcol->lastcol < ++p->col)
843 p->tcol->lastcol = p->col;
847 term_tab_ref(struct termp *p)
849 if (p->tcol->lastcol && p->tcol->lastcol <= p->col &&
850 (p->flags & TERMP_NOBUF) == 0)
851 bufferc(p, ASCII_TABREF);
860 encode1(struct termp *p, int c)
864 if (p->flags & TERMP_NOBUF) {
865 (*p->letter)(p, c);
869 if (p->col + 7 >= p->tcol->maxcols)
870 adjbuf(p->tcol, p->col + 7);
873 p->fontq[p->fonti] : TERMFONT_NONE;
875 if (p->flags & TERMP_BACKBEFORE) {
876 if (p->tcol->buf[p->col - 1] == ' ' ||
877 p->tcol->buf[p->col - 1] == '\t')
878 p->col--;
880 p->tcol->buf[p->col++] = '\b';
881 p->flags &= ~TERMP_BACKBEFORE;
884 p->tcol->buf[p->col++] = '_';
885 p->tcol->buf[p->col++] = '\b';
889 p->tcol->buf[p->col++] = '-';
891 p->tcol->buf[p->col++] = c;
892 p->tcol->buf[p->col++] = '\b';
894 if (p->tcol->lastcol <= p->col || (c != ' ' && c != ASCII_NBRSP))
895 p->tcol->buf[p->col] = c;
896 if (p->tcol->lastcol < ++p->col)
897 p->tcol->lastcol = p->col;
898 if (p->flags & TERMP_BACKAFTER) {
899 p->flags |= TERMP_BACKBEFORE;
900 p->flags &= ~TERMP_BACKAFTER;
905 encode(struct termp *p, const char *word, size_t sz)
909 if (p->flags & TERMP_NOBUF) {
911 (*p->letter)(p, word[i]);
915 if (p->col + 2 + (sz * 5) >= p->tcol->maxcols)
916 adjbuf(p->tcol, p->col + 2 + (sz * 5));
921 encode1(p, word[i]);
923 if (p->tcol->lastcol <= p->col ||
925 p->tcol->buf[p->col] = word[i];
926 p->col++;
934 (p->flags & TERMP_BACKBEFORE)) {
935 p->flags &= ~TERMP_BACKBEFORE;
936 p->flags |= TERMP_BACKAFTER;
940 if (p->tcol->lastcol < p->col)
941 p->tcol->lastcol = p->col;
945 term_setwidth(struct termp *p, const char *wstr)
966 width = term_hspan(p, &su);
970 (*p->setwidth)(p, iop, width);
974 term_len(const struct termp *p, size_t sz)
976 return (*p->getwidth)(p, ' ') * sz;
980 cond_width(const struct termp *p, int c, int *skip)
986 return (*p->getwidth)(p, c);
990 term_strlen(const struct termp *p, const char *cp)
1023 sz += cond_width(p, *cp++, &skip);
1040 if (p->enc == TERMENC_ASCII) {
1047 sz += cond_width(p, uc, &skip);
1054 if (p->type == TERMTYPE_PDF) {
1057 } else if (p->type == TERMTYPE_PS) {
1060 } else if (p->enc == TERMENC_ASCII) {
1079 this_sz = (*p->getwidth)(p, *seq++);
1095 if (p->enc == TERMENC_ASCII) {
1102 sz += cond_width(p, uc, &skip);
1118 sz += (*p->getwidth)(p, *rhs++);
1121 sz += cond_width(p, ' ', &skip);
1125 sz += cond_width(p, '-', &skip);
1137 term_vspan(const struct termp *p, const struct roffsu *su)
1182 term_hspan(const struct termp *p, const struct roffsu *su)
1184 return (*p->hspan)(p, su);