Lines Matching +full:tx +full:- +full:termination +full:- +full:fix
1 /*-
55 * v_tcmd --
64 vp->m_final.lno = sp->lno; in v_tcmd()
65 vp->m_final.cno = sp->cno; in v_tcmd()
72 sp->lno = TMAP[0].lno; in v_tcmd()
73 sp->cno = 0; in v_tcmd()
101 sp->lno = vp->m_final.lno; in v_tcmd()
102 sp->cno = vp->m_final.cno; in v_tcmd()
109 * Initialize the screen map for colon command-line input.
127 vip->sv_tm_lno = TMAP->lno; in txt_map_init()
128 vip->sv_tm_soff = TMAP->soff; in txt_map_init()
129 vip->sv_tm_coff = TMAP->coff; in txt_map_init()
130 vip->sv_t_maxrows = sp->t_maxrows; in txt_map_init()
131 vip->sv_t_minrows = sp->t_minrows; in txt_map_init()
132 vip->sv_t_rows = sp->t_rows; in txt_map_init()
136 * Fix it, filling in fake lines as we go. in txt_map_init()
140 HMAP + (sp->t_maxrows - 1); TMAP < esmp; ++TMAP) { in txt_map_init()
142 TMAP[1].coff = HMAP->coff; in txt_map_init()
154 sp->t_rows = sp->t_minrows = ++sp->t_maxrows; in txt_map_init()
161 * Reset the screen map for colon command-line input.
172 sp->t_rows = vip->sv_t_rows; in txt_map_end()
173 sp->t_minrows = vip->sv_t_minrows; in txt_map_end()
174 sp->t_maxrows = vip->sv_t_maxrows; in txt_map_end()
181 for (cnt = sp->t_rows; cnt <= sp->t_maxrows; ++cnt) { in txt_map_end()
182 (void)sp->gp->scr_move(sp, cnt, 0); in txt_map_end()
183 (void)sp->gp->scr_clrtoeol(sp); in txt_map_end()
185 TMAP = HMAP + (sp->t_rows - 1); in txt_map_end()
187 --TMAP; in txt_map_end()
191 * (logical) line. Fix it. If the user entered a whole in txt_map_end()
195 while (vip->sv_tm_lno != TMAP->lno || in txt_map_end()
196 vip->sv_tm_soff != TMAP->soff) in txt_map_end()
221 * Internally, we maintain tp->lno and tp->cno, externally, everyone uses
222 * sp->lno and sp->cno. Make them consistent as necessary.
225 (sp)->lno = (tp)->lno; \
226 (sp)->cno = (tp)->cno; \
230 * v_txt --
261 size_t rcol; /* 0-N: insert offset in the replay buffer. */ in v_txt()
276 gp = sp->gp; in v_txt()
288 * default to 0 -- text_init() handles this.) If changing a line, in v_txt()
291 tiqh = sp->tiq; in v_txt()
295 tp->lb_len < (len + 32) * sizeof(CHAR_T)) { in v_txt()
299 tp->ai = tp->insert = tp->offset = tp->owrite = 0; in v_txt()
301 tp->len = len; in v_txt()
302 BINC_RETW(sp, tp->lb, tp->lb_len, len); in v_txt()
303 MEMMOVE(tp->lb, lp, len); in v_txt()
305 tp->len = 0; in v_txt()
312 /* Set default termination condition. */ in v_txt()
313 tp->term = TERM_OK; in v_txt()
316 tp->lno = sp->lno; in v_txt()
317 tp->cno = sp->cno; in v_txt()
327 tp->owrite = (tm->cno - tp->cno) + 1; in v_txt()
328 tp->insert = (len - tm->cno) - 1; in v_txt()
330 tp->insert = len - tp->cno; in v_txt()
332 if (LF_ISSET(TXT_EMARK) && txt_emark(sp, tp, tm->cno)) in v_txt()
352 tp->cno = tp->ai; in v_txt()
355 * The cc and S commands have a special feature -- leading in v_txt()
360 tp->offset = 0; in v_txt()
361 tp->ai = tp->cno; in v_txt()
363 tp->offset = tp->cno; in v_txt()
368 tp->lb[tp->cno++] = prompt; in v_txt()
369 ++tp->len; in v_txt()
370 ++tp->offset; in v_txt()
374 * If appending after the end-of-line, add a space into the buffer in v_txt()
384 tp->lb[tp->cno] = CH_CURSOR; in v_txt()
385 ++tp->len; in v_txt()
386 ++tp->insert; in v_txt()
387 (void)vs_change(sp, tp->lno, LINE_RESET); in v_txt()
392 * from the RIGHT-HAND margin, not the left. It's more useful to in v_txt()
393 * us as a distance from the left-hand margin, i.e. the same as in v_txt()
418 margin = sp->cols - margin; in v_txt()
490 fc.e_flno = vip->totalcount >= in v_txt()
491 sp->rows ? 1 : sp->rows - vip->totalcount; in v_txt()
492 fc.e_tlno = sp->rows; in v_txt()
493 vip->linecount = vip->lcontinue = vip->totalcount = 0; in v_txt()
498 /* Deal with all non-character events. */ in v_txt()
499 switch (evp->e_event) { in v_txt()
531 * input. (Historically, it's okay to replay non-existent input.) in v_txt()
535 if (LF_ISSET(TXT_RECORD) && rcol == 0 && evp->e_c == '\0') { in v_txt()
536 if (vip->rep == NULL) in v_txt()
546 * File name completion and colon command-line editing. We don't in v_txt()
550 * command-line editing if it's not. in v_txt()
557 O_STR(sp, O_CEDIT)[0] == evp->e_c) in v_txt()
560 O_STR(sp, O_FILEC)[0] == evp->e_c) in v_txt()
562 if (L__cedit == 1 && (L__filec == 0 || tp->cno == tp->offset)) { in v_txt()
563 tp->term = TERM_CEDIT; in v_txt()
575 if (F_ISSET(&evp->e_ch, CH_ABBREVIATED)) { in v_txt()
590 BINC_GOTO(sp, EVENT, vip->rep, in v_txt()
591 vip->rep_len, (rcol + 1) * sizeof(EVENT)); in v_txt()
592 vip->rep[rcol++] = *evp; in v_txt()
596 if (rcol == vip->rep_cnt) in v_txt()
598 evp = vip->rep + rcol++; in v_txt()
604 if (evp->e_c == ' ') in v_txt()
609 if (F_ISSET(&evp->e_ch, CH_QUOTED)) in v_txt()
628 if (evp->e_value != K_NL) { in v_txt()
638 * this test delimits the value by any non-hex character. Offset by in v_txt()
641 if (hexcnt > 1 && !ISXDIGIT(evp->e_c)) { in v_txt()
647 switch (evp->e_value) { in v_txt()
660 if (vs_change(sp, tp->lno, LINE_RESET)) in v_txt()
666 if (tp->cno <= tp->offset) in v_txt()
667 tp->term = TERM_CR; in v_txt()
674 tp->cno >= tp->offset + 1) in v_txt()
675 tp->term = TERM_SEARCH; in v_txt()
687 if (txt_abbrev(sp, tp, &evp->e_c, \ in v_txt()
693 rcol -= tmp + 1; \ in v_txt()
703 * situations where TXT_APPENDEOL is set but tp->insert \ in v_txt()
705 * are tp->owrite characters. \ in v_txt()
707 if (LF_ISSET(TXT_APPENDEOL) && tp->insert > 0) { \ in v_txt()
708 --tp->len; \ in v_txt()
709 --tp->insert; \ in v_txt()
718 tp->sv_len = tp->len; in v_txt()
719 tp->sv_cno = tp->cno; in v_txt()
720 tp->len = tp->cno; in v_txt()
723 if (vs_change(sp, tp->lno, LINE_RESET)) in v_txt()
735 tp->R_erase = 0; in v_txt()
736 owrite = tp->owrite; in v_txt()
737 insert = tp->insert; in v_txt()
739 for (p = tp->lb + tp->cno; owrite > 0 && isblank(*p); in v_txt()
740 ++p, --owrite, ++tp->R_erase); in v_txt()
743 ++p, ++tp->R_erase, --insert); in v_txt()
745 p = tp->lb + tp->cno + owrite; in v_txt()
748 isblank(*p); ++p, --insert); in v_txt()
761 TAILQ_INSERT_TAIL(sp->tiq, ntp, q); in v_txt()
764 ntp->insert = insert; in v_txt()
765 ntp->owrite = owrite; in v_txt()
766 ntp->lno = tp->lno + 1; in v_txt()
782 if (v_txt_auto(sp, OOBLNO, tp, tp->cno, ntp)) in v_txt()
788 ntp->cno = ntp->ai; in v_txt()
799 BINC_GOTOW(sp, ntp->lb, in v_txt()
800 ntp->lb_len, ntp->len + WMTSPACE + 32); in v_txt()
801 MEMMOVE(ntp->lb + ntp->cno, wmt.lb, WMTSPACE); in v_txt()
802 ntp->len += WMTSPACE; in v_txt()
803 ntp->cno += wmt.offset; in v_txt()
804 ntp->owrite = wmt.owrite; in v_txt()
805 ntp->insert = wmt.insert; in v_txt()
811 if (ntp->owrite == 0 && ntp->insert == 0) { in v_txt()
812 BINC_GOTOW(sp, ntp->lb, ntp->lb_len, ntp->len + 1); in v_txt()
814 ntp->lb[ntp->cno] = CH_CURSOR; in v_txt()
815 ++ntp->insert; in v_txt()
816 ++ntp->len; in v_txt()
821 if (vs_change(sp, tp->lno, LINE_INSERT)) in v_txt()
831 --rcount; in v_txt()
833 vip->rep_cnt = rcol; in v_txt()
851 tp->insert = tp->owrite; in v_txt()
852 tp->owrite = 0; in v_txt()
859 if (tp->cno <= tp->offset) in v_txt()
860 tp->term = TERM_ESC; in v_txt()
866 if (FL_ISSET(is_flags, IS_RUNNING) && tp->cno >= tp->offset + 1) in v_txt()
867 tp->term = TERM_SEARCH; in v_txt()
876 txt_Rresolve(sp, sp->tiq, tp, len); in v_txt()
882 if (tp->owrite) { in v_txt()
883 if (tp->insert) in v_txt()
884 MEMMOVE(tp->lb + tp->cno, in v_txt()
885 tp->lb + tp->cno + tp->owrite, tp->insert); in v_txt()
886 tp->len -= tp->owrite; in v_txt()
893 * 0, the termination condition has already been set. in v_txt()
899 if (txt_resolve(sp, sp->tiq, flags)) in v_txt()
902 BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1); in v_txt()
903 tp->lb[tp->len] = '\0'; in v_txt()
910 if (tp->cno != 0) in v_txt()
911 --tp->cno; in v_txt()
914 if (vs_change(sp, tp->lno, LINE_RESET)) in v_txt()
918 if (tp->cno <= tp->ai && LF_ISSET(TXT_AUTOINDENT)) in v_txt()
922 if (tp->cno <= tp->ai && LF_ISSET(TXT_AUTOINDENT)) in v_txt()
929 * autoindent or already inserted non-ai characters, it's a in v_txt()
935 if (tp->cno == 0) in v_txt()
940 if (tp->ai == 0 || tp->cno > tp->ai + tp->offset + 1) in v_txt()
946 BINC_GOTOW(sp, ait.lb, ait.lb_len, tp->ai); in v_txt()
947 MEMMOVE(ait.lb, tp->lb, tp->ai); in v_txt()
948 ait.ai = ait.len = tp->ai; in v_txt()
954 if (tp->ai == 0 || tp->cno > tp->ai + tp->offset + 1) in v_txt()
958 leftmargin: tp->lb[tp->cno - 1] = ' '; in v_txt()
959 tp->owrite += tp->cno - tp->offset; in v_txt()
960 tp->ai = 0; in v_txt()
961 tp->cno = tp->offset; in v_txt()
964 if (tp->ai == 0 || tp->cno > tp->ai + tp->offset) in v_txt()
975 if (tp->cno <= tp->offset && LF_ISSET(TXT_BS)) { in v_txt()
976 tp->term = TERM_BS; in v_txt()
984 if (tp->cno == 0) { in v_txt()
986 txt_backup(sp, sp->tiq, tp, &flags)) == NULL) in v_txt()
993 if (tp->cno <= tp->offset) { in v_txt()
1000 --tp->cno; in v_txt()
1004 * <blank>s, presumably because it's easier to fix a minor in v_txt()
1013 tp->lb[tp->cno] = ' '; in v_txt()
1023 ++tp->owrite; in v_txt()
1024 if (tp->cno < tp->ai) in v_txt()
1025 --tp->ai; in v_txt()
1036 if (tp->cno == 0) { in v_txt()
1038 txt_backup(sp, sp->tiq, tp, &flags)) == NULL) in v_txt()
1046 if (tp->cno <= tp->offset) { in v_txt()
1060 if (tp->ai && tp->cno > tp->ai) in v_txt()
1061 max = tp->ai; in v_txt()
1063 tp->ai = 0; in v_txt()
1064 max = tp->offset; in v_txt()
1068 while (tp->cno > max && ISBLANK(tp->lb[tp->cno - 1])) { in v_txt()
1069 --tp->cno; in v_txt()
1070 ++tp->owrite; in v_txt()
1072 if (tp->cno == max) in v_txt()
1077 * -- as 1, 3, or 6 words. Historic vi had two classes of in v_txt()
1082 * treats it as 3 words -- there are two classes of in v_txt()
1096 while (tp->cno > max) { in v_txt()
1097 if (ISBLANK(tp->lb[tp->cno - 1])) in v_txt()
1099 --tp->cno; in v_txt()
1100 ++tp->owrite; in v_txt()
1102 tp->lb[tp->cno] = ' '; in v_txt()
1106 --tp->cno; in v_txt()
1107 ++tp->owrite; in v_txt()
1109 tp->lb[tp->cno] = ' '; in v_txt()
1111 if (tp->cno > max) in v_txt()
1112 tmp = inword(tp->lb[tp->cno - 1]); in v_txt()
1113 while (tp->cno > max) { in v_txt()
1114 if (tmp != inword(tp->lb[tp->cno - 1]) in v_txt()
1115 || ISBLANK(tp->lb[tp->cno - 1])) in v_txt()
1117 --tp->cno; in v_txt()
1118 ++tp->owrite; in v_txt()
1120 tp->lb[tp->cno] = ' '; in v_txt()
1135 if (tp->cno == 0) { in v_txt()
1137 txt_backup(sp, sp->tiq, tp, &flags)) == NULL) in v_txt()
1143 if (tp->cno <= tp->offset) { in v_txt()
1157 if (tp->ai && tp->cno > tp->ai) in v_txt()
1158 max = tp->ai; in v_txt()
1160 tp->ai = 0; in v_txt()
1161 max = tp->offset; in v_txt()
1163 tp->owrite += tp->cno - max; in v_txt()
1171 tp->lb[--tp->cno] = ' '; in v_txt()
1172 } while (tp->cno > max); in v_txt()
1174 tp->cno = max; in v_txt()
1187 evp->e_c = '^'; in v_txt()
1208 if (sp->showmode != SM_COMMAND && quote != Q_VTHIS && in v_txt()
1219 match_chars = VIP(sp)->mcs; in v_txt()
1220 cp = STRCHR(match_chars, evp->e_c); in v_txt()
1221 if (cp != NULL && (cp - match_chars) & 1) in v_txt()
1237 if (LF_ISSET(TXT_BEAUTIFY) && ISCNTRL(evp->e_c) && in v_txt()
1238 evp->e_value != K_FORMFEED && evp->e_value != K_TAB) { in v_txt()
1247 * If entering a non-word character after a word, check for in v_txt()
1252 if (!inword(evp->e_c)) { in v_txt()
1255 if (txt_abbrev(sp, tp, &evp->e_c, in v_txt()
1260 rcol -= tmp + 1; in v_txt()
1264 if (isblank(evp->e_c) && UNMAP_TST) in v_txt()
1268 abb = inword(evp->e_c) ? AB_INWORD : AB_NOTWORD; in v_txt()
1270 insl_ch: if (txt_insch(sp, tp, &evp->e_c, flags)) in v_txt()
1279 --tp->cno; in v_txt()
1280 ++tp->owrite; in v_txt()
1314 if (isblank(evp->e_c)) in v_txt()
1328 ebuf_chk: if (tp->cno >= tp->len) { in v_txt()
1329 BINC_GOTOW(sp, tp->lb, tp->lb_len, tp->len + 1); in v_txt()
1332 tp->lb[tp->cno] = CH_CURSOR; in v_txt()
1333 ++tp->insert; in v_txt()
1334 ++tp->len; in v_txt()
1344 if (tp->cno + tp->insert + tp->owrite != tp->len) { in v_txt()
1347 tp->len, tp->cno, tp->ai, tp->insert, tp->owrite); in v_txt()
1350 tp->len = tp->cno + tp->insert + tp->owrite; in v_txt()
1368 vs_change(sp, tp->lno, LINE_RESET)) in v_txt()
1386 if ((vip->totalcount != 0 || F_ISSET(gp, G_BELLSCHED)) && in v_txt()
1415 vip->rep_cnt = rcol; in v_txt()
1422 vp->m_final.lno = tp->lno; in v_txt()
1423 vp->m_final.cno = tp->cno; in v_txt()
1430 txt_err(sp, sp->tiq); in v_txt()
1435 * txt_abbrev --
1448 if (tp->cno == tp->offset) in txt_abbrev()
1458 * off-by-one error. The way this worked was that when the inserted in txt_abbrev()
1459 * text switched from a "word" character to a non-word character, in txt_abbrev()
1461 * type (i.e. word/non-word) of the character entered TWO characters in txt_abbrev()
1471 * offset character -- both can be tested for using tp->offset. in txt_abbrev()
1473 off = tp->cno - 1; /* Previous character. */ in txt_abbrev()
1474 p = tp->lb + off; in txt_abbrev()
1476 if (off == tp->offset || isblank(p[-1])) in txt_abbrev()
1478 if (inword(p[-1])) /* Move backward to change. */ in txt_abbrev()
1480 --off; --p; ++len; in txt_abbrev()
1481 if (off == tp->offset || !inword(p[-1])) in txt_abbrev()
1486 --off; --p; ++len; in txt_abbrev()
1487 if (off == tp->offset || in txt_abbrev()
1488 inword(p[-1]) || isblank(p[-1])) in txt_abbrev()
1531 if (off == tp->ai || off == tp->offset) in txt_abbrev()
1550 * characters will be re-tested for abbreviations. It's difficult to in txt_abbrev()
1567 if (v_event_push(sp, NULL, qp->output, qp->olen, CH_ABBREVIATED)) in txt_abbrev()
1579 tp->cno -= len; in txt_abbrev()
1580 if (qp->olen >= len) in txt_abbrev()
1581 tp->owrite += len; in txt_abbrev()
1583 if (tp->insert) in txt_abbrev()
1584 MEMMOVE(tp->lb + tp->cno + qp->olen, in txt_abbrev()
1585 tp->lb + tp->cno + tp->owrite + len, tp->insert); in txt_abbrev()
1586 tp->owrite += qp->olen; in txt_abbrev()
1587 tp->len -= len - qp->olen; in txt_abbrev()
1602 * txt_unmap --
1612 for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --p, --off) { in txt_unmap()
1618 if (off == tp->ai || off == tp->offset) in txt_unmap()
1635 if ((off == tp->ai || off == tp->offset) && ex_is_unmap(p, len)) in txt_unmap()
1642 * txt_ai_resolve --
1659 if (!tp->len || tp->offset || !tp->ai) in txt_ai_resolve()
1666 if (tp->len <= tp->ai) { in txt_ai_resolve()
1667 tp->ai = tp->cno = tp->len = 0; in txt_ai_resolve()
1679 for (p = tp->lb, scno = 0, len = tp->len, in txt_ai_resolve()
1680 spaces = tab_after_sp = 0; len-- && isblank(*p); ++p) in txt_ai_resolve()
1706 spaces = scno - cno; in txt_ai_resolve()
1709 * Figure out how many characters we're dropping -- if we're not in txt_ai_resolve()
1712 old = p - tp->lb; in txt_ai_resolve()
1718 del = old - new; in txt_ai_resolve()
1719 MEMMOVE(p - del, p, tp->len - old); in txt_ai_resolve()
1720 tp->len -= del; in txt_ai_resolve()
1721 tp->cno -= del; in txt_ai_resolve()
1724 for (p = tp->lb; tabs--;) in txt_ai_resolve()
1726 while (spaces--) in txt_ai_resolve()
1732 * v_txt_auto --
1751 tp->ai = 0; in v_txt_auto()
1757 t = aitp->lb; in v_txt_auto()
1760 for (p = t; len > 0; ++p, --len) in v_txt_auto()
1765 if ((nlen = (p - t)) == 0) in v_txt_auto()
1769 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + nlen); in v_txt_auto()
1772 if (tp->len != 0) in v_txt_auto()
1773 MEMMOVE(tp->lb + nlen, tp->lb, tp->len); in v_txt_auto()
1774 tp->len += nlen; in v_txt_auto()
1777 MEMMOVE(tp->lb, t, nlen); in v_txt_auto()
1780 tp->ai = nlen; in v_txt_auto()
1785 * txt_backup --
1803 ntp->len = ntp->sv_len; in txt_backup()
1807 if (ntp->owrite == 0 && ntp->insert == 0) { in txt_backup()
1808 ntp->lb[ntp->len] = CH_CURSOR; in txt_backup()
1809 ++ntp->insert; in txt_backup()
1810 ++ntp->len; in txt_backup()
1820 if (vs_change(sp, ntp->lno + 1, LINE_DELETE)) in txt_backup()
1829 * previous shiftwidth value, i.e. for a 1-based numbering, with shiftwidth=3,
1837 * meant that inserting text into previously existing text was strange -- ^T
1846 * i<CR>^Tx<CR>^Tx<CR>^Tx<CR>^Dx<CR>^Dx<CR>^Dx<esc>
1857 * txt_dent --
1890 for (current = cno = 0; cno < tp->cno; ++cno) in txt_dent()
1891 current += tp->lb[cno] == '\t' ? in txt_dent()
1892 COL_OFF(current, ts) : KEY_COL(sp, tp->lb[cno]); in txt_dent()
1898 --target; in txt_dent()
1899 target -= target % sw; in txt_dent()
1910 ai_reset = !isindent || tp->cno == tp->ai + tp->offset; in txt_dent()
1917 for (; tp->cno > tp->offset && in txt_dent()
1918 (tp->lb[tp->cno - 1] == ' ' || tp->lb[tp->cno - 1] == '\t'); in txt_dent()
1919 --tp->cno, ++tp->owrite); in txt_dent()
1920 for (current = cno = 0; cno < tp->cno; ++cno) in txt_dent()
1921 current += tp->lb[cno] == '\t' ? in txt_dent()
1922 COL_OFF(current, ts) : KEY_COL(sp, tp->lb[cno]); in txt_dent()
1927 * of the line was a tp->offset character, and the user entered in txt_dent()
1933 * beginning of the line (or the last non-<blank> character) to the in txt_dent()
1945 spaces = target - cno; in txt_dent()
1950 tp->ai = tabs + spaces; in txt_dent()
1956 for (ch = '\t'; tabs > 0; --tabs) in txt_dent()
1958 for (ch = ' '; spaces > 0; --spaces) in txt_dent()
1964 * txt_fc --
1984 * Find the beginning of this "word" -- if we're at the beginning in txt_fc()
1987 if (tp->cno == 1) { in txt_fc()
1989 p = tp->lb; in txt_fc()
1994 off = MAX(tp->ai, tp->offset), ap = tp->lb + off, p = ap; in txt_fc()
1995 off < tp->cno; ++off, ++ap) { in txt_fc()
1997 if (++off == tp->cno) in txt_fc()
2031 (void)sp->gp->scr_bell(sp); in txt_fc()
2035 nlen = STRLEN(cmd.argv[0]->bp); in txt_fc()
2043 for (nlen = cmd.argv[0]->len; --argc > 0;) { in txt_fc()
2044 if (cmd.argv[argc]->len < nlen) in txt_fc()
2045 nlen = cmd.argv[argc]->len; in txt_fc()
2047 cmd.argv[argc]->bp[indx] == cmd.argv[0]->bp[indx]; in txt_fc()
2056 bp = cmd.argv[0]->bp; in txt_fc()
2058 if ((bp = argv_esc(sp, &cmd, cmd.argv[0]->bp, nlen)) == NULL) in txt_fc()
2064 for (t = bp; len > 0 && nlen > 0; --len, --nlen) in txt_fc()
2069 tp->cno -= len; in txt_fc()
2070 tp->owrite += len; in txt_fc()
2074 for (; nlen > 0 && tp->owrite > 0; --nlen, --tp->owrite, ++tp->cno) in txt_fc()
2079 off = p - tp->lb; in txt_fc()
2080 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + nlen); in txt_fc()
2081 p = tp->lb + off; in txt_fc()
2083 tp->cno += nlen; in txt_fc()
2084 tp->len += nlen; in txt_fc()
2086 if (tp->insert != 0) in txt_fc()
2087 (void)MEMMOVE(p + nlen, p, tp->insert); in txt_fc()
2088 while (nlen--) in txt_fc()
2100 INT2CHAR(sp, cmd.argv[0]->bp, cmd.argv[0]->len + 1, np, nplen); in txt_fc()
2104 if (tp->owrite == 0) { in txt_fc()
2105 off = p - tp->lb; in txt_fc()
2106 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + 1); in txt_fc()
2107 p = tp->lb + off; in txt_fc()
2108 if (tp->insert != 0) in txt_fc()
2109 (void)MEMMOVE(p + 1, p, tp->insert); in txt_fc()
2110 ++tp->len; in txt_fc()
2112 --tp->owrite; in txt_fc()
2114 ++tp->cno; in txt_fc()
2122 * txt_fc_col --
2136 gp = sp->gp; in txt_fc_col()
2139 INT2CHAR(sp, argv[0]->bp, argv[0]->len + 1, np, nlen); in txt_fc_col()
2143 prefix = (pp - np) + 1; in txt_fc_col()
2144 for (ac = argc - 1, av = argv + 1; ac > 0; --ac, ++av) in txt_fc_col()
2145 if (av[0]->len < prefix || in txt_fc_col()
2146 MEMCMP(av[0]->bp, argv[0]->bp, in txt_fc_col()
2160 for (ac = argc, av = argv, colwidth = 0; ac > 0; --ac, ++av) { in txt_fc_col()
2161 for (col = 0, p = av[0]->bp + prefix; *p != '\0'; ++p) in txt_fc_col()
2183 if (colwidth >= sp->cols) { in txt_fc_col()
2184 for (ac = argc, av = argv; ac > 0; --ac, ++av) { in txt_fc_col()
2185 INT2CHAR(sp, av[0]->bp+prefix, av[0]->len+1-prefix, in txt_fc_col()
2197 numcols = (sp->cols - 1) / colwidth; in txt_fc_col()
2208 INT2CHAR(sp, argv[base]->bp+prefix, in txt_fc_col()
2209 argv[base]->len+1-prefix, np, nlen); in txt_fc_col()
2218 "%*s", (int)(colwidth - cnt), ""); in txt_fc_col()
2239 * txt_emark --
2257 if (tp->lb[cno] == '\t') in txt_emark()
2258 (void)vs_columns(sp, tp->lb, tp->lno, &cno, &olen); in txt_emark()
2260 olen = KEY_COL(sp, tp->lb[cno]); in txt_emark()
2265 * to fix it up. in txt_emark()
2268 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + olen); in txt_emark()
2269 chlen = olen - nlen; in txt_emark()
2270 if (tp->insert != 0) in txt_emark()
2271 MEMMOVE(tp->lb + cno + 1 + chlen, in txt_emark()
2272 tp->lb + cno + 1, tp->insert); in txt_emark()
2274 tp->len += chlen; in txt_emark()
2275 tp->owrite += chlen; in txt_emark()
2276 p = tp->lb + cno; in txt_emark()
2277 if (tp->lb[cno] == '\t' || in txt_emark()
2278 KEY_NEEDSWIDE(sp, tp->lb[cno])) in txt_emark()
2279 for (cno += chlen; chlen--;) in txt_emark()
2283 KEY_NAME(sp, tp->lb[cno]), in txt_emark()
2284 cno += chlen; chlen--;) in txt_emark()
2287 tp->lb[cno] = ch; in txt_emark()
2288 return (vs_change(sp, tp->lno, LINE_RESET)); in txt_emark()
2292 * txt_err --
2309 for (lno = TAILQ_FIRST(tiqh)->lno; in txt_err()
2310 !db_exist(sp, lno) && lno > 0; --lno); in txt_err()
2312 sp->lno = lno == 0 ? 1 : lno; in txt_err()
2313 sp->cno = 0; in txt_err()
2320 * txt_hex --
2324 * This is an extension. The pattern "^X[0-9a-fA-F]*" is a way
2337 * Null-terminate the string. Since nul isn't a legal hex value, in txt_hex()
2341 savec = tp->lb[tp->cno]; in txt_hex()
2342 tp->lb[tp->cno] = 0; in txt_hex()
2345 for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --p, --off, ++len) { in txt_hex()
2351 if (off == tp->ai || off == tp->offset) in txt_hex()
2363 nothex: tp->lb[tp->cno] = savec; in txt_hex()
2368 tp->lb[tp->cno] = savec; in txt_hex()
2371 tp->cno -= len; in txt_hex()
2372 tp->len -= len; in txt_hex()
2373 tp->lb[tp->cno - 1] = value; in txt_hex()
2376 if (tp->owrite) in txt_hex()
2377 MEMMOVE(tp->lb + tp->cno, tp->lb + tp->cno + len, in txt_hex()
2378 tp->owrite); in txt_hex()
2381 if (tp->insert) in txt_hex()
2382 MEMMOVE(tp->lb + tp->cno + tp->owrite, in txt_hex()
2383 tp->lb + tp->cno + tp->owrite + len, in txt_hex()
2384 tp->insert); in txt_hex()
2390 * txt_insch --
2417 * The 'R' command does one-for-one replacement, because there's in txt_insch()
2421 if (tp->owrite) { in txt_insch()
2422 --tp->owrite; in txt_insch()
2423 tp->lb[tp->cno++] = *chp; in txt_insch()
2426 } else if (tp->owrite) { /* Overwrite a character. */ in txt_insch()
2427 cno = tp->cno; in txt_insch()
2435 savech = tp->lb[cno]; in txt_insch()
2436 tp->lb[cno] = '\t'; in txt_insch()
2437 (void)vs_columns(sp, tp->lb, tp->lno, &cno, &nlen); in txt_insch()
2438 tp->lb[cno] = savech; in txt_insch()
2448 for (copydown = 0; nlen != 0 && tp->owrite != 0;) { in txt_insch()
2449 --tp->owrite; in txt_insch()
2451 if (tp->lb[cno] == '\t') in txt_insch()
2453 tp->lb, tp->lno, &cno, &olen); in txt_insch()
2455 olen = KEY_COL(sp, tp->lb[cno]); in txt_insch()
2463 nlen -= olen; in txt_insch()
2466 tp->lb, tp->lb_len, tp->len + olen); in txt_insch()
2467 chlen = olen - nlen; in txt_insch()
2468 MEMMOVE(tp->lb + cno + 1 + chlen, in txt_insch()
2469 tp->lb + cno + 1, in txt_insch()
2470 tp->owrite + tp->insert); in txt_insch()
2472 tp->len += chlen; in txt_insch()
2473 tp->owrite += chlen; in txt_insch()
2474 if (tp->lb[cno] == '\t' || in txt_insch()
2475 KEY_NEEDSWIDE(sp, tp->lb[cno])) in txt_insch()
2476 for (p = tp->lb + cno + 1; chlen--;) in txt_insch()
2480 KEY_NAME(sp, tp->lb[cno]) + nlen, in txt_insch()
2481 p = tp->lb + cno + 1; chlen--;) in txt_insch()
2493 if (copydown != 0 && (tp->len -= copydown) != 0) in txt_insch()
2494 MEMMOVE(tp->lb + cno, tp->lb + cno + copydown, in txt_insch()
2495 tp->owrite + tp->insert + copydown); in txt_insch()
2499 tp->lb[tp->cno++] = *chp; in txt_insch()
2505 BINC_RETW(sp, tp->lb, tp->lb_len, tp->len + 1); in txt_insch()
2507 ++tp->len; in txt_insch()
2508 if (tp->insert) { /* Insert a character. */ in txt_insch()
2509 if (tp->insert == 1) in txt_insch()
2510 tp->lb[tp->cno + 1] = tp->lb[tp->cno]; in txt_insch()
2512 MEMMOVE(tp->lb + tp->cno + 1, in txt_insch()
2513 tp->lb + tp->cno, tp->owrite + tp->insert); in txt_insch()
2515 tp->lb[tp->cno++] = *chp; in txt_insch()
2520 * txt_isrch --
2530 /* If it's a one-line screen, we don't do incrementals. */ in txt_isrch()
2540 if (tp->cno <= 1) { in txt_isrch()
2541 vp->m_final = vp->m_start; in txt_isrch()
2549 if (tp->lb[tp->cno - 1] == '\\' && in txt_isrch()
2550 (tp->cno == 2 || tp->lb[tp->cno - 2] != '\\')) in txt_isrch()
2557 if (IS_SHELLMETA(sp, tp->lb[tp->cno - 1]) && in txt_isrch()
2558 (tp->cno == 2 || tp->lb[tp->cno - 2] != '\\')) in txt_isrch()
2559 vp->m_final = vp->m_start; in txt_isrch()
2562 * If we see the search pattern termination character, then quit doing in txt_isrch()
2568 if (tp->lb[0] == tp->lb[tp->cno - 1] && in txt_isrch()
2569 (tp->cno == 2 || tp->lb[tp->cno - 2] != '\\')) { in txt_isrch()
2570 vp->m_final = vp->m_start; in txt_isrch()
2579 lno = tp->lno; in txt_isrch()
2593 start = vp->m_start; in txt_isrch()
2596 start = vp->m_final; in txt_isrch()
2600 if (tp->lb[0] == '/' ? in txt_isrch()
2602 &start, &vp->m_final, tp->lb + 1, tp->cno - 1, NULL, sf) : in txt_isrch()
2604 &start, &vp->m_final, tp->lb + 1, tp->cno - 1, NULL, sf)) { in txt_isrch()
2605 sp->lno = vp->m_final.lno; in txt_isrch()
2606 sp->cno = vp->m_final.cno; in txt_isrch()
2621 tp->lno = TMAP[0].lno; in txt_isrch()
2624 * If the colon command-line moved, i.e. the screen scrolled, in txt_isrch()
2628 * We shouldn't be calling vs_line, here -- we need dirty bits in txt_isrch()
2634 (void)sp->gp->scr_refresh(sp, 0); in txt_isrch()
2640 * txt_resolve --
2665 if (db_set(sp, tp->lno, tp->lb, tp->len) || in txt_resolve()
2666 (changed && vs_change(sp, tp->lno, LINE_RESET))) in txt_resolve()
2669 for (lno = tp->lno; (tp = TAILQ_NEXT(tp, q)) != NULL; ++lno) { in txt_resolve()
2674 if (db_append(sp, 0, lno, tp->lb, tp->len) || in txt_resolve()
2675 (changed && vs_change(sp, tp->lno, LINE_RESET))) in txt_resolve()
2680 * Clear the input flag, the look-aside buffer is no longer valid. in txt_resolve()
2690 * txt_showmatch --
2705 gp = sp->gp; in txt_showmatch()
2723 cs.cs_lno = tp->lno; in txt_showmatch()
2724 cs.cs_cno = tp->cno - 1; in txt_showmatch()
2727 startc = STRCHR(VIP(sp)->mcs, endc = cs.cs_ch)[-1]; in txt_showmatch()
2743 else if (cs.cs_ch == startc && --cnt == 0) in txt_showmatch()
2750 sp->lno = cs.cs_lno; in txt_showmatch()
2751 sp->cno = cs.cs_cno; in txt_showmatch()
2761 * txt_margin --
2772 for (off = tp->cno - 1, p = tp->lb + off, len = 0;; --off, --p, ++len) { in txt_margin()
2787 if (off == tp->ai || off == tp->offset) { in txt_margin()
2800 * line -- it's going to be used to set the cursor value when we in txt_margin()
2804 wmtp->lb = p + 1; in txt_margin()
2805 wmtp->offset = len; in txt_margin()
2806 wmtp->insert = LF_ISSET(TXT_APPENDEOL) ? tp->insert - 1 : tp->insert; in txt_margin()
2807 wmtp->owrite = tp->owrite; in txt_margin()
2810 tp->cno -= len; in txt_margin()
2812 tp->len -= len + tp->owrite + (tp->insert - 1); in txt_margin()
2813 tp->insert = 1; in txt_margin()
2815 tp->len -= len + tp->owrite + tp->insert; in txt_margin()
2816 tp->insert = 0; in txt_margin()
2818 tp->owrite = 0; in txt_margin()
2824 for (;; --p, --off) { in txt_margin()
2827 --tp->cno; in txt_margin()
2828 --tp->len; in txt_margin()
2829 if (off == tp->ai || off == tp->offset) in txt_margin()
2837 * txt_Rresolve --
2851 if (tp->owrite == 0) in txt_Rresolve()
2856 * plus the blanks erased by <carriage-return>/<newline>s. in txt_Rresolve()
2859 input_len += ttp == tp ? tp->cno : ttp->len + ttp->R_erase; in txt_Rresolve()
2879 retain = MIN(tp->owrite, orig_len - input_len); in txt_Rresolve()
2881 TAILQ_FIRST(tiqh)->lno, DBG_FATAL | DBG_NOCACHE, &p, NULL)) in txt_Rresolve()
2883 MEMCPY(tp->lb + tp->cno, p + input_len, retain); in txt_Rresolve()
2884 tp->len -= tp->owrite - retain; in txt_Rresolve()
2885 tp->owrite = 0; in txt_Rresolve()
2886 tp->insert += retain; in txt_Rresolve()
2891 * txt_nomorech --