static void rectangle_insert(EditState *s, const char *str) { int line, col, start_line, i, loff; eb_get_pos(s->b, &start_line, &col, s->b->mark); eb_get_pos(s->b, &line, &col, s->offset); for (i = start_line; i <= line; i++) { loff = eb_goto_pos(s->b, i, 0); eb_insert(s->b, loff, str, strlen(str)); } s->region_style = 0; }
/* XXX: optimize !!!!! */ static void tty_gotoxy(ShellState *s, int x, int y, int relative) { int total_lines, cur_line, line_num, col_num, offset, offset1, c; unsigned char buf1[10]; /* compute offset */ eb_get_pos(s->b, &total_lines, &col_num, s->b->total_size); line_num = total_lines - TTY_YSIZE; if (line_num < 0) line_num = 0; if (relative) { eb_get_pos(s->b, &cur_line, &col_num, s->cur_offset); cur_line -= line_num; if (cur_line < 0) cur_line = 0; x += col_num; y += line_num; } if (y < 0) y = 0; else if (y >= TTY_YSIZE) y = TTY_YSIZE - 1; if (x < 0) x = 0; line_num += y; /* add lines if necessary */ while (line_num >= total_lines) { buf1[0] = '\n'; eb_insert(s->b, s->b->total_size, buf1, 1); total_lines++; } offset = eb_goto_pos(s->b, line_num, 0); for (; x > 0; x--) { c = eb_nextc(s->b, offset, &offset1); if (c == '\n') { buf1[0] = ' '; for (; x > 0; x--) { eb_insert(s->b, offset, buf1, 1); } break; } else { offset = offset1; } } s->cur_offset = offset; }
static void rectangle_cut(EditState *s) { int line, col, start_line, i, loff; eb_get_pos(s->b, &start_line, &col, s->b->mark); eb_get_pos(s->b, &line, &col, s->offset); for (i = start_line; i <= line; i++) { loff = eb_goto_pos(s->b, i, 0); if (eb_is_empty_line(s->b, loff)) continue; eb_delete(s->b, loff, col); } s->region_style = 0; put_status(s, "Rectangle cut done on line %d to line %d\n", start_line, line); }
/* get current offset of the line in list */ int list_get_offset(EditState *s) { int line, col; eb_get_pos(s->b, &line, &col, s->offset); return eb_goto_pos(s->b, line, 0); }
/* get current position (index) in list */ int list_get_pos(EditState *s) { int line, col; eb_get_pos(s->b, &line, &col, s->offset); return line; }