Lines Matching refs:tp

225  * Internally, we maintain tp->lno and tp->cno, externally, everyone uses
228 #define UPDATE_POSITION(sp, tp) { \
229 (sp)->lno = (tp)->lno; \
230 (sp)->cno = (tp)->cno; \
255 TEXT *ntp, *tp; /* Input text structures. */
297 tp = TAILQ_FIRST(tiqh);
298 if (TAILQ_NEXT(tp, q) != NULL ||
299 tp->lb_len < (len + 32) * sizeof(CHAR_T)) {
303 tp->ai = tp->insert = tp->offset = tp->owrite = 0;
305 tp->len = len;
306 BINC_RETW(sp, tp->lb, tp->lb_len, len);
307 MEMMOVE(tp->lb, lp, len);
309 tp->len = 0;
311 newtp: if ((tp = text_init(sp, lp, len, len + 32)) == NULL)
313 TAILQ_INSERT_HEAD(tiqh, tp, q);
317 tp->term = TERM_OK;
320 tp->lno = sp->lno;
321 tp->cno = sp->cno;
331 tp->owrite = (tm->cno - tp->cno) + 1;
332 tp->insert = (len - tm->cno) - 1;
334 tp->insert = len - tp->cno;
336 if (LF_ISSET(TXT_EMARK) && txt_emark(sp, tp, tm->cno))
354 if (v_txt_auto(sp, ai_line, NULL, 0, tp))
356 tp->cno = tp->ai;
364 tp->offset = 0;
365 tp->ai = tp->cno;
367 tp->offset = tp->cno;
372 tp->lb[tp->cno++] = prompt;
373 ++tp->len;
374 ++tp->offset;
388 tp->lb[tp->cno] = CH_CURSOR;
389 ++tp->len;
390 ++tp->insert;
391 (void)vs_change(sp, tp->lno, LINE_RESET);
471 UPDATE_POSITION(sp, tp);
566 if (L__cedit == 1 && (L__filec == 0 || tp->cno == tp->offset)) {
567 tp->term = TERM_CEDIT;
571 if (txt_fc(sp, tp, &filec_redraw))
637 --tp->cno;
638 ++tp->owrite;
656 if (txt_hex(sp, tp))
673 if (vs_change(sp, tp->lno, LINE_RESET))
679 if (tp->cno <= tp->offset)
680 tp->term = TERM_CR;
687 tp->cno >= tp->offset + 1)
688 tp->term = TERM_SEARCH;
700 if (txt_abbrev(sp, tp, &evp->e_c, \
713 txt_unmap(sp, tp, &ec_flags); \
716 * situations where TXT_APPENDEOL is set but tp->insert \
718 * are tp->owrite characters. \
720 if (LF_ISSET(TXT_APPENDEOL) && tp->insert > 0) { \
721 --tp->len; \
722 --tp->insert; \
731 tp->sv_len = tp->len;
732 tp->sv_cno = tp->cno;
733 tp->len = tp->cno;
736 if (vs_change(sp, tp->lno, LINE_RESET))
748 tp->R_erase = 0;
749 owrite = tp->owrite;
750 insert = tp->insert;
752 for (p = tp->lb + tp->cno; owrite > 0 && isblank(*p);
753 ++p, --owrite, ++tp->R_erase);
756 ++p, ++tp->R_erase, --insert);
758 p = tp->lb + tp->cno + owrite;
779 ntp->lno = tp->lno + 1;
785 * tp structure, use the cursor as the length, the autoindent
795 if (v_txt_auto(sp, OOBLNO, tp, tp->cno, ntp))
833 tp = ntp;
834 if (vs_change(sp, tp->lno, LINE_INSERT))
864 tp->insert = tp->owrite;
865 tp->owrite = 0;
872 if (tp->cno <= tp->offset)
873 tp->term = TERM_ESC;
879 if (FL_ISSET(is_flags, IS_RUNNING) && tp->cno >= tp->offset + 1)
880 tp->term = TERM_SEARCH;
889 txt_Rresolve(sp, sp->tiq, tp, len);
895 if (tp->owrite) {
896 if (tp->insert)
897 MEMMOVE(tp->lb + tp->cno,
898 tp->lb + tp->cno + tp->owrite, tp->insert);
899 tp->len -= tp->owrite;
915 BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1);
916 tp->lb[tp->len] = '\0';
923 if (tp->cno != 0)
924 --tp->cno;
927 if (vs_change(sp, tp->lno, LINE_RESET))
931 if (tp->cno <= tp->ai && LF_ISSET(TXT_AUTOINDENT))
935 if (tp->cno <= tp->ai && LF_ISSET(TXT_AUTOINDENT))
948 if (tp->cno == 0)
953 if (tp->ai == 0 || tp->cno > tp->ai + tp->offset + 1)
959 BINC_GOTOW(sp, ait.lb, ait.lb_len, tp->ai);
960 MEMMOVE(ait.lb, tp->lb, tp->ai);
961 ait.ai = ait.len = tp->ai;
967 if (tp->ai == 0 || tp->cno > tp->ai + tp->offset + 1)
971 leftmargin: tp->lb[tp->cno - 1] = ' ';
972 tp->owrite += tp->cno - tp->offset;
973 tp->ai = 0;
974 tp->cno = tp->offset;
977 if (tp->ai == 0 || tp->cno > tp->ai + tp->offset)
980 (void)txt_dent(sp, tp, 0);
988 if (tp->cno <= tp->offset && LF_ISSET(TXT_BS)) {
989 tp->term = TERM_BS;
997 if (tp->cno == 0) {
999 txt_backup(sp, sp->tiq, tp, &flags)) == NULL)
1001 tp = ntp;
1006 if (tp->cno <= tp->offset) {
1013 --tp->cno;
1026 tp->lb[tp->cno] = ' ';
1036 ++tp->owrite;
1037 if (tp->cno < tp->ai)
1038 --tp->ai;
1049 if (tp->cno == 0) {
1051 txt_backup(sp, sp->tiq, tp, &flags)) == NULL)
1053 tp = ntp;
1059 if (tp->cno <= tp->offset) {
1073 if (tp->ai && tp->cno > tp->ai)
1074 max = tp->ai;
1076 tp->ai = 0;
1077 max = tp->offset;
1081 while (tp->cno > max && ISBLANK(tp->lb[tp->cno - 1])) {
1082 --tp->cno;
1083 ++tp->owrite;
1085 if (tp->cno == max)
1109 while (tp->cno > max) {
1110 if (ISBLANK(tp->lb[tp->cno - 1]))
1112 --tp->cno;
1113 ++tp->owrite;
1115 tp->lb[tp->cno] = ' ';
1119 --tp->cno;
1120 ++tp->owrite;
1122 tp->lb[tp->cno] = ' ';
1124 if (tp->cno > max)
1125 tmp = inword(tp->lb[tp->cno - 1]);
1126 while (tp->cno > max) {
1127 if (tmp != inword(tp->lb[tp->cno - 1])
1128 || ISBLANK(tp->lb[tp->cno - 1]))
1130 --tp->cno;
1131 ++tp->owrite;
1133 tp->lb[tp->cno] = ' ';
1148 if (tp->cno == 0) {
1150 txt_backup(sp, sp->tiq, tp, &flags)) == NULL)
1152 tp = ntp;
1156 if (tp->cno <= tp->offset) {
1170 if (tp->ai && tp->cno > tp->ai)
1171 max = tp->ai;
1173 tp->ai = 0;
1174 max = tp->offset;
1176 tp->owrite += tp->cno - max;
1184 tp->lb[--tp->cno] = ' ';
1185 } while (tp->cno > max);
1187 tp->cno = max;
1196 if (txt_dent(sp, tp, 1))
1285 if (txt_abbrev(sp, tp, &evp->e_c,
1295 txt_unmap(sp, tp, &ec_flags);
1300 insl_ch: if (txt_insch(sp, tp, &evp->e_c, flags))
1309 --tp->cno;
1310 ++tp->owrite;
1322 if (txt_hex(sp, tp))
1341 if (txt_margin(sp, tp, &wmt, &tmp, flags))
1358 ebuf_chk: if (tp->cno >= tp->len) {
1359 BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1);
1362 tp->lb[tp->cno] = CH_CURSOR;
1363 ++tp->insert;
1364 ++tp->len;
1378 if (tp->cno + tp->insert + tp->owrite != tp->len) {
1381 tp->len, tp->cno, tp->ai, tp->insert, tp->owrite);
1384 tp->len = tp->cno + tp->insert + tp->owrite;
1402 vs_change(sp, tp->lno, LINE_RESET))
1411 if (!KEYS_WAITING(sp) && txt_showmatch(sp, tp))
1430 UPDATE_POSITION(sp, tp);
1436 if (FL_ISSET(is_flags, IS_RUNNING) && txt_isrch(sp, vp, tp, &is_flags))
1456 vp->m_final.lno = tp->lno;
1457 vp->m_final.cno = tp->cno;
1473 txt_abbrev(SCR *sp, TEXT *tp, CHAR_T *pushcp, int isinfoline, int *didsubp, int *turnoffp)
1482 if (tp->cno == tp->offset)
1505 * offset character -- both can be tested for using tp->offset.
1507 off = tp->cno - 1; /* Previous character. */
1508 p = tp->lb + off;
1510 if (off == tp->offset || isblank(p[-1]))
1515 if (off == tp->offset || !inword(p[-1]))
1521 if (off == tp->offset ||
1565 if (off == tp->ai || off == tp->offset)
1612 tp->cno -= len;
1614 tp->owrite += len;
1616 if (tp->insert)
1617 MEMMOVE(tp->lb + tp->cno + qp->olen,
1618 tp->lb + tp->cno + tp->owrite + len, tp->insert);
1619 tp->owrite += qp->olen;
1620 tp->len -= len - qp->olen;
1639 txt_unmap(SCR *sp, TEXT *tp, u_int32_t *ec_flagsp)
1645 for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) {
1651 if (off == tp->ai || off == tp->offset)
1668 if ((off == tp->ai || off == tp->offset) && ex_is_unmap(p, len))
1679 txt_ai_resolve(SCR *sp, TEXT *tp, int *changedp)
1692 if (!tp->len || tp->offset || !tp->ai)
1699 if (tp->len <= tp->ai) {
1700 tp->ai = tp->cno = tp->len = 0;
1712 for (p = tp->lb, scno = 0, len = tp->len,
1739 old = p - tp->lb;
1746 MEMMOVE(p - del, p, tp->len - old);
1747 tp->len -= del;
1748 tp->cno -= del;
1751 for (p = tp->lb; tabs--;)
1766 v_txt_auto(SCR *sp, recno_t lno, TEXT *aitp, size_t len, TEXT *tp)
1778 tp->ai = 0;
1796 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + nlen);
1799 if (tp->len != 0)
1800 MEMMOVE(tp->lb + nlen, tp->lb, tp->len);
1801 tp->len += nlen;
1804 MEMMOVE(tp->lb, t, nlen);
1807 tp->ai = nlen;
1816 txt_backup(SCR *sp, TEXTH *tiqh, TEXT *tp, u_int32_t *flagsp)
1822 if ((ntp = TAILQ_PREV(tp, _texth, q)) == NULL) {
1826 return (tp);
1843 TAILQ_REMOVE(tiqh, tp, q);
1844 text_free(tp);
1891 txt_dent(SCR *sp, TEXT *tp, int isindent)
1917 for (current = cno = 0; cno < tp->cno; ++cno)
1918 current += tp->lb[cno] == '\t' ?
1919 COL_OFF(current, ts) : KEY_COL(sp, tp->lb[cno]);
1937 ai_reset = !isindent || tp->cno == tp->ai + tp->offset;
1944 for (; tp->cno > tp->offset &&
1945 (tp->lb[tp->cno - 1] == ' ' || tp->lb[tp->cno - 1] == '\t');
1946 --tp->cno, ++tp->owrite);
1947 for (current = cno = 0; cno < tp->cno; ++cno)
1948 current += tp->lb[cno] == '\t' ?
1949 COL_OFF(current, ts) : KEY_COL(sp, tp->lb[cno]);
1954 * of the line was a tp->offset character, and the user entered
1974 tp->ai = tabs + spaces;
1981 (void)txt_insch(sp, tp, &ch, 0);
1983 (void)txt_insch(sp, tp, &ch, 0);
1992 txt_fc(SCR *sp, TEXT *tp, int *redrawp)
2011 if (tp->cno == 1) {
2013 p = tp->lb;
2018 off = MAX(tp->ai, tp->offset), ap = tp->lb + off, p = ap;
2019 off < tp->cno; ++off, ++ap) {
2021 if (++off == tp->cno)
2093 tp->cno -= len;
2094 tp->owrite += len;
2098 for (; nlen > 0 && tp->owrite > 0; --nlen, --tp->owrite, ++tp->cno)
2103 off = p - tp->lb;
2104 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + nlen);
2105 p = tp->lb + off;
2107 tp->cno += nlen;
2108 tp->len += nlen;
2110 if (tp->insert != 0)
2111 (void)MEMMOVE(p + nlen, p, tp->insert);
2128 if (tp->owrite == 0) {
2129 off = p - tp->lb;
2130 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + 1);
2131 p = tp->lb + off;
2132 if (tp->insert != 0)
2133 (void)MEMMOVE(p + 1, p, tp->insert);
2134 ++tp->len;
2136 --tp->owrite;
2138 ++tp->cno;
2267 txt_emark(SCR *sp, TEXT *tp, size_t cno)
2281 if (tp->lb[cno] == '\t')
2282 (void)vs_columns(sp, tp->lb, tp->lno, &cno, &olen);
2284 olen = KEY_COL(sp, tp->lb[cno]);
2292 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + olen);
2294 if (tp->insert != 0)
2295 MEMMOVE(tp->lb + cno + 1 + chlen,
2296 tp->lb + cno + 1, tp->insert);
2298 tp->len += chlen;
2299 tp->owrite += chlen;
2300 p = tp->lb + cno;
2301 if (tp->lb[cno] == '\t' ||
2302 KEY_NEEDSWIDE(sp, tp->lb[cno]))
2307 KEY_NAME(sp, tp->lb[cno]),
2311 tp->lb[cno] = ch;
2312 return (vs_change(sp, tp->lno, LINE_RESET));
2353 txt_hex(SCR *sp, TEXT *tp)
2365 savec = tp->lb[tp->cno];
2366 tp->lb[tp->cno] = 0;
2369 for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --p, --off, ++len) {
2375 if (off == tp->ai || off == tp->offset)
2387 nothex: tp->lb[tp->cno] = savec;
2392 tp->lb[tp->cno] = savec;
2395 tp->cno -= len;
2396 tp->len -= len;
2397 tp->lb[tp->cno - 1] = value;
2400 if (tp->owrite)
2401 MEMMOVE(tp->lb + tp->cno, tp->lb + tp->cno + len,
2402 tp->owrite);
2405 if (tp->insert)
2406 MEMMOVE(tp->lb + tp->cno + tp->owrite,
2407 tp->lb + tp->cno + tp->owrite + len,
2408 tp->insert);
2433 txt_insch(SCR *sp, TEXT *tp, CHAR_T *chp, u_int flags)
2445 if (tp->owrite) {
2446 --tp->owrite;
2447 tp->lb[tp->cno++] = *chp;
2450 } else if (tp->owrite) { /* Overwrite a character. */
2451 cno = tp->cno;
2459 savech = tp->lb[cno];
2460 tp->lb[cno] = '\t';
2461 (void)vs_columns(sp, tp->lb, tp->lno, &cno, &nlen);
2462 tp->lb[cno] = savech;
2472 for (copydown = 0; nlen != 0 && tp->owrite != 0;) {
2473 --tp->owrite;
2475 if (tp->lb[cno] == '\t')
2477 tp->lb, tp->lno, &cno, &olen);
2479 olen = KEY_COL(sp, tp->lb[cno]);
2490 tp->lb, tp->lb_len, tp->len + olen);
2492 MEMMOVE(tp->lb + cno + 1 + chlen,
2493 tp->lb + cno + 1,
2494 tp->owrite + tp->insert);
2496 tp->len += chlen;
2497 tp->owrite += chlen;
2498 if (tp->lb[cno] == '\t' ||
2499 KEY_NEEDSWIDE(sp, tp->lb[cno]))
2500 for (p = tp->lb + cno + 1; chlen--;)
2504 KEY_NAME(sp, tp->lb[cno]) + nlen,
2505 p = tp->lb + cno + 1; chlen--;)
2517 if (copydown != 0 && (tp->len -= copydown) != 0)
2518 MEMMOVE(tp->lb + cno, tp->lb + cno + copydown,
2519 tp->owrite + tp->insert + copydown);
2523 tp->lb[tp->cno++] = *chp;
2529 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + 1);
2531 ++tp->len;
2532 if (tp->insert) { /* Insert a character. */
2533 if (tp->insert == 1)
2534 tp->lb[tp->cno + 1] = tp->lb[tp->cno];
2536 MEMMOVE(tp->lb + tp->cno + 1,
2537 tp->lb + tp->cno, tp->owrite + tp->insert);
2539 tp->lb[tp->cno++] = *chp;
2548 txt_isrch(SCR *sp, VICMD *vp, TEXT *tp, u_int8_t *is_flagsp)
2564 if (tp->cno <= 1) {
2573 if (tp->lb[tp->cno - 1] == '\\' &&
2574 (tp->cno == 2 || tp->lb[tp->cno - 2] != '\\'))
2581 if (IS_SHELLMETA(sp, tp->lb[tp->cno - 1]) &&
2582 (tp->cno == 2 || tp->lb[tp->cno - 2] != '\\'))
2592 if (tp->lb[0] == tp->lb[tp->cno - 1] &&
2593 (tp->cno == 2 || tp->lb[tp->cno - 2] != '\\')) {
2603 lno = tp->lno;
2624 if (tp->lb[0] == '/' ?
2626 &start, &vp->m_final, tp->lb + 1, tp->cno - 1, NULL, sf) :
2628 &start, &vp->m_final, tp->lb + 1, tp->cno - 1, NULL, sf)) {
2645 tp->lno = TMAP[0].lno;
2671 TEXT *tp;
2683 tp = TAILQ_FIRST(tiqh);
2686 txt_ai_resolve(sp, tp, &changed);
2689 if (db_set(sp, tp->lno, tp->lb, tp->len) ||
2690 (changed && vs_change(sp, tp->lno, LINE_RESET)))
2693 for (lno = tp->lno; (tp = TAILQ_NEXT(tp, q)) != NULL; ++lno) {
2695 txt_ai_resolve(sp, tp, &changed);
2698 if (db_append(sp, 0, lno, tp->lb, tp->len) ||
2699 (changed && vs_change(sp, tp->lno, LINE_RESET)))
2722 txt_showmatch(SCR *sp, TEXT *tp)
2735 UPDATE_POSITION(sp, tp);
2747 cs.cs_lno = tp->lno;
2748 cs.cs_cno = tp->cno - 1;
2789 txt_margin(SCR *sp, TEXT *tp, TEXT *wmtp, int *didbreak, u_int32_t flags)
2796 for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --off, --p, ++len) {
2811 if (off == tp->ai || off == tp->offset) {
2830 wmtp->insert = LF_ISSET(TXT_APPENDEOL) ? tp->insert - 1 : tp->insert;
2831 wmtp->owrite = tp->owrite;
2834 tp->cno -= len;
2836 tp->len -= len + tp->owrite + (tp->insert - 1);
2837 tp->insert = 1;
2839 tp->len -= len + tp->owrite + tp->insert;
2840 tp->insert = 0;
2842 tp->owrite = 0;
2851 --tp->cno;
2852 --tp->len;
2853 if (off == tp->ai || off == tp->offset)
2865 txt_Rresolve(SCR *sp, TEXTH *tiqh, TEXT *tp, const size_t orig_len)
2875 if (tp->owrite == 0)
2883 input_len += ttp == tp ? tp->cno : ttp->len + ttp->R_erase;
2903 retain = MIN(tp->owrite, orig_len - input_len);
2907 MEMCPY(tp->lb + tp->cno, p + input_len, retain);
2908 tp->len -= tp->owrite - retain;
2909 tp->owrite = 0;
2910 tp->insert += retain;