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