Lines Matching refs:TT
90 if (*s == '\t') *width = TT.tabstop;
170 struct slice_list *s = TT.slices;
179 TT.text = (struct block_list *)dlist_add((struct double_list **)&TT.text,
183 TT.slices = (struct slice_list *)dlist_add(
184 (struct double_list **)&TT.slices,
193 if (s == TT.slices) return -1; //error out of bounds
203 (struct double_list **)&TT.slices,
208 (struct double_list **)&TT.slices,
214 (struct double_list **)&TT.slices,
219 s = (struct slice_list *)dlist_add_after((struct double_list **)&TT.slices,
231 struct slice_list *e, *s = TT.slices;
242 if (s == TT.slices) return -1; //error out of bounds
250 if (e == TT.slices) return -1; //error out of bounds
259 if (s == TT.slices) TT.slices = s->next;
281 (struct double_list **)&TT.slices,
297 struct slice_list *s = TT.slices;
307 if (s == TT.slices) s = 0; //error out of bounds
315 struct slice_list *s = TT.slices;
329 } while (s != TT.slices);
336 struct slice_list *s = TT.slices;
350 } while (s != TT.slices->prev); //tail
357 struct slice_list *s = TT.slices;
364 } while (s != TT.slices);
371 struct slice_list *s = TT.slices;
384 } while (s != TT.slices);
391 struct slice_list *s = TT.slices;
417 if (!TT.filesize || !offset) return 0;
418 else if (TT.filesize <= offset) return TT.filesize-1;
426 if (!TT.filesize) offset = 1;
427 else if (TT.filesize <= offset) return TT.filesize-1;
429 return TT.filesize-1;
437 if (offset >= TT.filesize) offset--;
451 struct slice_list *s = TT.slices;
459 if ((end = TT.filesize) > offset+max_len) return 0;
471 } while (s != TT.slices && j);
492 } while (pos < TT.filesize);
510 llist_traverse((void *)TT.slices, llist_free_double);
511 llist_traverse((void *)TT.text, block_list_free);
512 TT.slices = 0, TT.text = 0;
525 TT.filesize = 0;
531 TT.filesize = text_filesize();
539 struct slice_list *s = TT.slices;
553 } while (s != TT.slices);
570 if (!TT.filesize) TT.cursor = 0;
573 if (TT.cursor < 1) {
574 TT.cursor = 0;
576 } else if (TT.cursor >= TT.filesize-1) {
577 TT.cursor = TT.filesize-1;
580 if ((len = text_codepoint(buf, TT.cursor)) < 1) {
581 TT.cursor--; //we are not in valid data try jump over
585 else TT.cursor--; //combine char jump over
589 // TT.vi_mov_flag is used for special cases when certain move
606 TT.cur_row = 0, TT.scr_row = 0;
607 if (!TT.cursor) {
608 TT.screen = 0;
609 TT.vi_mov_flag = 0x20000000;
611 } else if (TT.screen > (1<<18) || TT.cursor > (1<<18)) {
614 TT.screen = text_strrchr(TT.cursor-1, '\n')+1;
615 TT.vi_mov_flag = 0x20000000;
619 s = text_count(0, TT.screen, '\n');
620 c = text_count(0, TT.cursor, '\n');
622 TT.screen = text_strrchr(TT.cursor-1, '\n')+1;
624 TT.vi_mov_flag = 0x20000000; //TODO I disabled scroll
627 if (distance > (int)TT.screen_height) {
628 int n, adj = distance-TT.screen_height;
629 TT.vi_mov_flag = 0x20000000; //TODO I disabled scroll
631 if ((n = text_strchr(TT.screen, '\n'))+1 > TT.screen)
632 TT.screen = n+1;
636 TT.scr_row = s;
637 TT.cur_row = c;
646 size_t start = from, end = TT.cursor;
649 memset(TT.yank.data, 0, TT.yank.alloc);
650 if (TT.vi_mov_flag&0x80000000) start = TT.cursor, end = from;
651 else TT.cursor = start; //yank moves cursor to left pos always?
653 if (TT.yank.alloc < end-from) {
657 TT.yank.data = xrealloc(TT.yank.data, new_bounds);
658 TT.yank.alloc = new_bounds;
662 for (str = TT.yank.data ; start<end; start++, str++) *str = text_byte(start);
671 size_t start = from, end = TT.cursor;
675 if (TT.vi_mov_flag&0x80000000)
676 start = TT.cursor, end = from;
679 if (TT.vi_mov_flag&2) {
686 TT.cursor = start;
687 TT.filesize = text_filesize();
690 TT.vi_mov_flag |= 0x30000000;
698 TT.vi_mode = 2;
705 TT.vi_mov_flag |= 0x80000000;
706 for (;count && TT.cursor; count--) {
707 TT.cursor--;
708 if (text_byte(TT.cursor) == '\n') TT.cursor++;
720 len = text_codepoint(buf, TT.cursor);
723 else if (len > 0) TT.cursor += len;
724 else TT.cursor++;
726 for (;TT.cursor < TT.filesize;) {
727 if ((len = text_codepoint(buf, TT.cursor)) < 1) {
728 TT.cursor++; //we are not in valid data try jump over
733 else TT.cursor += len;
744 for (;count--;) TT.cursor = text_psol(TT.cursor);
746 TT.vi_mov_flag |= 0x80000000;
755 for (;count--;) TT.cursor = text_nsol(TT.cursor);
762 TT.cursor = text_sol(TT.screen);
768 TT.cursor = text_sol(TT.screen);
769 cur_down(TT.screen_height-1, 1, 0);
775 TT.cursor = text_sol(TT.screen);
776 cur_down(TT.screen_height/2, 1, 0);
782 size_t pos = text_strstr(TT.cursor+1, s);
784 if (TT.last_search != s) {
785 free(TT.last_search);
786 TT.last_search = xstrdup(s);
789 if (pos != SIZE_MAX) TT.cursor = pos;
796 size_t history = TT.cursor;
797 size_t pos = text_sol(TT.cursor); //go left to first char on line
798 TT.vi_mov_flag |= 0x4;
800 for (;count0; count0--) TT.cursor = text_nsol(TT.cursor);
804 TT.cursor = history;
810 size_t pos = text_sol(TT.cursor); //go left to first char on line
811 TT.vi_mov_flag |= 0x30000000;
813 for (;count0; count0--) TT.cursor = text_nsol(TT.cursor);
815 if (pos == TT.cursor && TT.filesize) pos--;
823 size_t from = TT.cursor;
825 if (text_byte(TT.cursor) == '\n') {
830 if (text_byte(TT.cursor) == '\n') TT.vi_mov_flag |= 2;
843 char c = text_byte(TT.cursor);
845 if (TT.cursor > TT.filesize-1) break;
848 if (++TT.cursor > TT.filesize-1) break;
849 if ((c = text_byte(TT.cursor)) == '\n') break;
852 if (++TT.cursor > TT.filesize-1) break;
853 c = text_byte(TT.cursor);
857 if (++TT.cursor > TT.filesize-1) break;
858 c = text_byte(TT.cursor);
862 if (++TT.cursor > TT.filesize-1) break;
863 c = text_byte(TT.cursor);
878 c = text_byte(TT.cursor);
880 if (!TT.cursor) break;
883 if (!--TT.cursor) break;
884 c = text_byte(TT.cursor);
888 if (!--TT.cursor) break;
890 c = text_byte(TT.cursor);
894 if (!--TT.cursor) break;
896 c = text_byte(TT.cursor);
902 for (;TT.cursor; TT.cursor--) {
903 c = text_byte(TT.cursor-1);
908 TT.vi_mov_flag |= 0x80000000;
921 c = text_byte(TT.cursor);
923 TT.cursor++;
924 for (;TT.cursor < TT.filesize-1; TT.cursor++) {
925 c = text_byte(TT.cursor+1);
930 TT.vi_mov_flag |= 2;
940 insert_str(xstrdup(str), TT.cursor, len, len, HEAP);
941 TT.cursor += len;
942 TT.filesize = text_filesize();
943 TT.vi_mov_flag |= 0x30000000;
948 TT.cursor = text_sol(TT.cursor);
949 TT.cur_col = 0;
950 TT.vi_mov_flag |= 0x80000000;
956 size_t new = text_strchr(TT.cursor, '\n');
958 if (new != TT.cursor) {
959 TT.cursor = new - 1;
960 TT.vi_mov_flag |= 2;
968 TT.cursor = text_strchr(TT.cursor, '\n');
976 for (i=0; i<TT.screen_height-2; ++i) {
977 TT.screen = text_psol(TT.screen);
979 TT.cursor = text_psol(TT.screen);
987 for (i=0; i<TT.screen_height-2; ++i) TT.screen = text_nsol(TT.screen);
989 if (TT.screen > TT.cursor) TT.cursor = TT.screen;
994 TT.screen = text_nsol(TT.screen);
996 if (TT.screen > TT.cursor) TT.cursor = TT.screen;
1001 TT.screen = text_psol(TT.screen);
1003 TT.cursor = text_psol(TT.cursor);
1013 size_t history = TT.cursor;
1014 char *start = TT.yank.data;
1018 if ((TT.cursor = text_strchr(TT.cursor, '\n')) == SIZE_MAX)
1019 TT.cursor = TT.filesize;
1020 else TT.cursor = text_nsol(TT.cursor);
1025 TT.vi_mov_flag |= 0x10000000;
1026 TT.cursor = history;
1035 size_t pos = text_strchr(TT.cursor, *symbol);
1036 if (pos != SIZE_MAX) TT.cursor = pos;
1043 size_t pos = text_strrchr(TT.cursor, *symbol);
1044 if (pos != SIZE_MAX) TT.cursor = pos;
1051 size_t prev_cursor = TT.cursor;
1053 TT.cursor = 0;
1055 if (TT.vi_mov_flag&0x40000000 && (TT.cursor = TT.filesize) > 0)
1056 TT.cursor = text_sol(TT.cursor-1);
1060 TT.cursor = next;
1061 TT.cursor++;
1065 if (prev_cursor > TT.cursor) TT.vi_mov_flag |= 0x80000000;
1072 TT.cursor = text_eol(TT.cursor);
1073 insert_str(xstrdup("\n"), TT.cursor++, 1, 1, HEAP);
1074 TT.vi_mov_flag |= 0x30000000;
1075 TT.vi_mode = 2;
1081 TT.cursor = text_psol(TT.cursor);
1087 size_t pos = TT.cursor;
1099 TT.cursor = text_sol(TT.cursor);
1100 TT.vi_mode = 2;
1109 if ((next = text_strchr(TT.cursor, '\n')) == SIZE_MAX) break;
1110 TT.cursor = next+1;
1111 vi_delete(reg, TT.cursor-1, 0);
1118 if (TT.last_search) search_str(TT.last_search);
1205 TT.count0 = 0, TT.count1 = 0, TT.vi_mov_flag = 0;
1206 TT.vi_reg = '"';
1210 TT.vi_reg = *cmd; //TODO check validity
1215 if (errno || val == 0) val = 1, TT.vi_mov_flag |= 0x40000000;
1217 TT.count0 = val;
1221 return vi_special[i].vi_special(TT.vi_reg, TT.count0, TT.count1);
1236 TT.count1 = val;
1241 TT.vi_mov_flag |= vi_movs[i].flags;
1243 if (TT.vi_mov_flag&1 && !(*cmd)) return 0;
1248 int prev_cursor = TT.cursor;
1249 if (vi_mov(TT.count0, TT.count1, cmd)) {
1250 if (vi_cmd) return (vi_cmd(TT.vi_reg, prev_cursor, TT.vi_mov_flag));
1279 TT.list = 1;
1280 TT.vi_mov_flag |= 0x30000000;
1284 TT.list = 0;
1285 TT.vi_mov_flag |= 0x30000000;
1296 if (wc < 32 && TT.list) {
1302 int i = TT.tabstop;
1305 ret = TT.tabstop;
1365 redraw = (TT.vi_mov_flag & 0x30000000)>>28;
1367 scroll = TT.drawn_row-TT.scr_row;
1368 if (TT.drawn_row<0 || TT.cur_row<0 || TT.scr_row<0) redraw = 3;
1369 else if (abs(scroll)>TT.screen_height/2) redraw = 3;
1376 SOL = text_sol(TT.cursor);
1380 for (SSOL = TT.screen, y = 0; SSOL < SOL; y++) SSOL = text_nsol(SSOL);
1387 bytes = TT.cursor-SOL; // TT.cur_col;
1397 if (TT.vi_mode == 2 && TT.il->len) {
1398 char* iend = TT.il->data; //input end
1402 clip = (aw+iw) - TT.screen_width+margin;
1407 iend = TT.il->data;
1412 iend = TT.il->data;
1423 else if ( aw+margin > TT.screen_width) {
1424 clip = aw-TT.screen_width+margin;
1435 x += crunch_str(&end, TT.screen_width-x, stdout, "\t\n", vi_crunch);
1439 y = 0, SSOL = TT.screen, line = toybuf;
1443 if (clip != TT.drawn_col) redraw = 3;
1445 for (; y < TT.screen_height; y++ ) {
1453 else if (scroll<0 && TT.screen_height-y-1<-scroll)
1462 crunch_str(&line, TT.screen_width-1, stdout, "\t\n", vi_crunch);
1466 if (SSOL+bytes < TT.filesize) {
1473 TT.drawn_row = TT.scr_row, TT.drawn_col = clip;
1476 tty_jump(0, TT.screen_height);
1478 if (TT.vi_mode == 2) printf("\033[1m-- INSERT --\033[m");
1479 if (!TT.vi_mode) {
1480 cx_scr = printf("%s", TT.il->data);
1481 cy_scr = TT.screen_height;
1486 sprintf(toybuf, "%zu/%zuC %zu%% %d,%d", TT.cursor, TT.filesize,
1487 (100*TT.cursor)/(TT.filesize ? : 1), TT.cur_row+1, TT.cur_col+1);
1488 if (TT.cur_col != cx_scr) sprintf(toybuf+strlen(toybuf),"-%d", cx_scr+1);
1490 tty_jump(TT.screen_width-strlen(toybuf), TT.screen_height);
1504 FILE *script = FLAG(s) ? xfopen(TT.s, "r") : 0;
1506 TT.il = xzalloc(sizeof(struct str_line));
1507 TT.il->data = xzalloc(80);
1508 TT.yank.data = xzalloc(128);
1510 TT.il->alloc = 80, TT.yank.alloc = 128;
1514 TT.vi_mov_flag = 0x20000000;
1515 TT.vi_mode = 1, TT.tabstop = 8;
1517 TT.screen_width = 80, TT.screen_height = 24;
1518 terminal_size(&TT.screen_width, &TT.screen_height);
1519 TT.screen_height -= 1;
1546 terminal_size(&TT.screen_width, &TT.screen_height);
1547 TT.screen_height -= 1; //TODO this is hack fix visual alignment
1552 if (TT.vi_mode && key>=256) {
1565 if (TT.vi_mode == 1) { //NORMAL
1570 TT.vi_mode = 0;
1571 TT.il->data[0]=key;
1572 TT.il->len++;
1576 TT.vi_mode = 2;
1582 TT.vi_mode = 2;
1617 } else if (TT.vi_mode == 0) { //EX MODE
1621 if (TT.il->len > 1) {
1622 TT.il->data[--TT.il->len] = 0;
1627 TT.vi_mode = 1;
1628 TT.il->len = 0;
1629 memset(TT.il->data, 0, TT.il->alloc);
1633 if (run_ex_cmd(TT.il->data) == -1)
1635 TT.vi_mode = 1;
1636 TT.il->len = 0;
1637 memset(TT.il->data, 0, TT.il->alloc);
1641 if (TT.il->len == TT.il->alloc) {
1642 TT.il->data = realloc(TT.il->data, TT.il->alloc*2);
1643 TT.il->alloc *= 2;
1645 TT.il->data[TT.il->len] = key;
1646 TT.il->len++;
1650 } else if (TT.vi_mode == 2) {//INSERT MODE
1653 i_insert(TT.il->data, TT.il->len);
1655 TT.vi_mode = 1;
1656 TT.il->len = 0;
1657 memset(TT.il->data, 0, TT.il->alloc);
1661 if (TT.il->len) {
1662 char *last = utf8_last(TT.il->data, TT.il->len);
1665 TT.il->len -= shrink;
1672 TT.il->data[TT.il->len++] = '\n';
1673 i_insert(TT.il->data, TT.il->len);
1674 TT.il->len = 0;
1675 memset(TT.il->data, 0, TT.il->alloc);
1681 if (TT.il->len+utf8_dec_p+1 >= TT.il->alloc) {
1682 TT.il->data = realloc(TT.il->data, TT.il->alloc*2);
1683 TT.il->alloc *= 2;
1685 strcpy(TT.il->data+TT.il->len, utf8_code);
1686 TT.il->len += utf8_dec_p;
1697 free(TT.il->data), free(TT.il), free(TT.yank.data);