Lines Matching +full:ps +full:- +full:seq +full:- +full:loop
3 * Copyright (c) 2010-2022, 2025 Ingo Schwarze <schwarze@openbsd.org>
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;
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);
74 p->headf = head;
75 p->footf = foot;
76 p->argf = arg;
77 (*p->begin)(p);
84 (*p->end)(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;
120 /* Loop over output lines. */
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;
143 p->flags & TERMP_BRNEVER ? SIZE_MAX / 2 : vtarget);
154 if (p->flags & TERMP_CENTER)
155 vbl += (vtarget - vbr) / 2;
156 else if (p->flags & TERMP_RIGHT)
157 vbl += vtarget - vbr;
164 p->tcol->taboff += vbr;
166 p->tcol->taboff += vtarget;
167 p->tcol->taboff += term_len(p, 1);
170 * If there is no text left in the field, exit the loop.
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)
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++;
209 * In multi-column mode, leave the rest of the text
213 * In single-column mode, simply break the line.
216 if (p->flags & TERMP_MULTICOL)
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))
273 int graph; /* Last character was non-blank. */
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] == ' ')
315 p->tcol->buf[ic] = '-';
316 vis += (*p->getwidth)(p, '-');
326 taboff = -vis - enw;
330 switch (p->tcol->buf[ic]) {
332 if (taboff < 0 && (size_t)-taboff > vis)
337 vis -= taboff;
339 case ASCII_NBRZW: /* Non-breakable zero-width. */
341 case ASCII_NBRSP: /* Non-breakable space. */
342 p->tcol->buf[ic] = ' ';
345 vis += (*p->getwidth)(p, p->tcol->buf[ic]);
358 * trailing whitespace, the loop could not check yet whether it
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') {
405 if (taboff < 0 && (size_t)-taboff > vis)
409 dv = term_tab_next(vt) - vt;
411 dv = (*p->getwidth)(p, ' ');
420 * We found a non-blank character to print,
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;
435 vis -= dv;
437 dv = (*p->getwidth)(p, p->tcol->buf[ic]);
438 p->viscol += dv;
442 p->tcol->col = nbr;
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);
475 p->flags |= TERMP_NOSPACE;
476 if (p->tcol->lastcol || p->viscol)
478 p->tcol->taboff = 0;
482 * Asserts a vertical space (a full, empty line-break between lines).
492 if (0 < p->skipvsp)
493 p->skipvsp--;
495 (*p->endline)(p);
504 f = p->fontl;
505 p->fontl = p->fontq[p->fonti];
506 p->fontq[p->fonti] = f;
513 p->fontl = p->fontq[p->fonti];
514 if (p->fontibi && f == TERMFONT_UNDER)
516 p->fontq[p->fonti] = 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;
540 if (p->fonti > i)
541 p->fonti = i;
548 assert(p->fonti > 0);
549 p->fonti--;
562 const char *seq; /* Escape sequence argument. */
572 if ((p->flags & TERMP_NOBUF) == 0) {
573 if ((p->flags & TERMP_NOSPACE) == 0) {
574 if ((p->flags & TERMP_KEEP) == 0) {
576 if (p->flags & TERMP_SENTENCE)
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) {
608 esc = mandoc_escape(&word, &seq, &sz);
611 uc = mchars_num2uc(seq + 1, sz - 1);
614 uc = mchars_num2char(seq, sz);
620 if (p->enc == TERMENC_ASCII) {
621 cp = mchars_spec2str(seq, sz, &ssz);
627 uc = mchars_spec2cp(seq, sz);
635 uc = *seq;
660 if (p->flags & TERMP_BACKAFTER)
661 p->flags &= ~TERMP_BACKAFTER;
663 p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
666 if (p->type == TERMTYPE_PDF)
668 else if (p->type == TERMTYPE_PS)
669 encode(p, "ps", 2);
670 else if (p->enc == TERMENC_ASCII)
676 if (p->flags & TERMP_BACKAFTER) {
677 p->flags &= ~TERMP_BACKAFTER;
680 if (*seq == '|') {
681 seq++;
682 bu = -term_len(p, p->col);
685 if (a2roffsu(seq, &su, SCALE_EM) == NULL)
690 bu -= term_len(p, 1);
691 if (p->flags & TERMP_BACKBEFORE)
692 p->flags &= ~TERMP_BACKBEFORE;
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;
718 if ((cp = a2roffsu(seq, &su, SCALE_EM)) == NULL)
722 if (p->tcol->rmargin <= p->tcol->offset)
724 lsz = p->tcol->rmargin - p->tcol->offset;
727 if (*cp == seq[-1])
728 uc = -1;
730 seq = cp + 1;
731 esc = mandoc_escape(&seq, &cp, &sz);
734 uc = mchars_num2uc(cp + 1, sz - 1);
743 uc = *seq;
746 uc = -1;
753 if (p->enc == TERMENC_ASCII) {
758 csz = (*p->getwidth)(p, uc);
760 if (p->enc == TERMENC_ASCII)
765 lsz -= csz;
771 p->flags |= TERMP_BACKAFTER;
774 cp = seq + sz;
775 while (seq < cp) {
776 if (*seq == '\\') {
777 mandoc_escape(&seq, NULL, NULL);
780 encode1(p, *seq++);
781 if (seq < cp) {
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;
808 if (p->enc == TERMENC_ASCII) {
818 p->flags &= ~TERMP_NBRWORD;
824 if (c->maxcols == 0)
825 c->maxcols = 1024;
826 while (c->maxcols <= sz)
827 c->maxcols <<= 2;
828 c->buf = mandoc_reallocarray(c->buf, c->maxcols, sizeof(*c->buf));
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;
849 if (p->tcol->lastcol && p->tcol->lastcol <= p->col &&
850 (p->flags & TERMP_NOBUF) == 0)
857 * Does not check for non-decorated glyphs.
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;
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));
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;
958 case '-':
959 iop = -1;
970 (*p->setwidth)(p, iop, width);
976 return (*p->getwidth)(p, ' ') * sz;
986 return (*p->getwidth)(p, c);
992 const char *seq; /* Escape sequence argument. */
1029 esc = mandoc_escape(&cp, &seq, &ssz);
1032 uc = mchars_num2uc(seq + 1, ssz - 1);
1035 uc = mchars_num2char(seq, ssz);
1040 if (p->enc == TERMENC_ASCII) {
1041 rhs = mchars_spec2str(seq, ssz, &rsz);
1045 uc = mchars_spec2cp(seq, ssz);
1051 uc = *seq;
1054 if (p->type == TERMTYPE_PDF) {
1057 } else if (p->type == TERMTYPE_PS) {
1058 rhs = "ps";
1060 } else if (p->enc == TERMENC_ASCII) {
1073 rhs = seq + ssz;
1074 while (seq < rhs) {
1075 if (*seq == '\\') {
1076 mandoc_escape(&seq, NULL, NULL);
1079 this_sz = (*p->getwidth)(p, *seq++);
1095 if (p->enc == TERMENC_ASCII) {
1118 sz += (*p->getwidth)(p, *rhs++);
1125 sz += cond_width(p, '-', &skip);
1142 switch (su->unit) {
1144 r = su->scale / 40.0;
1147 r = su->scale * 6.0 / 2.54;
1150 r = su->scale * 65536.0 / 40.0;
1153 r = su->scale * 6.0;
1156 r = su->scale * 0.006;
1159 r = su->scale;
1162 r = su->scale / 12.0;
1166 r = su->scale * 0.6;
1169 r = su->scale;
1174 ri = r > 0.0 ? r + 0.4995 : r - 0.4995;
1184 return (*p->hspan)(p, su);