summaryrefslogtreecommitdiff
path: root/lineset.c
diff options
context:
space:
mode:
Diffstat (limited to 'lineset.c')
-rw-r--r--lineset.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lineset.c b/lineset.c
index f672798..40fe3f0 100644
--- a/lineset.c
+++ b/lineset.c
@@ -58,6 +58,7 @@ void ensure_num_lines(lineset_t *ls, int n){
}
}
+
void dump_lines(lineset_t ls, FILE *f){
int i;
for (i=0; i<ls.num ;i++){
@@ -124,3 +125,45 @@ void paste_region(int x1, int y1){
}
redraw();
}
+
+void copy_lines_to_ring(int y1, int y2, int which){
+ lineset_t *tmp;
+ int i, len, *idx;
+
+ if (y1 > y2){
+ y1 ^= y2;
+ y2 ^= y1;
+ y1 ^= y2;
+ }
+ if (which == CUR)
+ idx = &undo_cur;
+ else
+ idx = &undo_lst;
+ if (*idx == undo_sz - 1){
+ undo_sz += 10;
+ tmp = realloc(undo, undo_sz * sizeof(lineset_t));
+ if (tmp == NULL){
+ fprintf(stderr, "Error allocating undo buffer");
+ exit(1);
+ }
+ undo = tmp;
+ }
+ (*idx) ++;
+ ensure_num_lines(&(undo[*idx]), y2 - y1 + 1);
+ for(i=y1; i<=y2; i++){
+ len = strlen(screen.l[i].s);
+ ensure_line_length(&(undo[*idx].l[i-y1]), len);
+ strcpy(undo[*idx].l[i-y1].s, screen.l[i].s);
+ undo[*idx].l[i-y1].n = i;
+ undo[*idx].l[i-y1].lst = screen.l[i].lst;
+ }
+ undo[*idx].num = y2 - y1 + 1;
+ if (which == CUR)
+ undo_lst = undo_cur;
+#ifdef DEBUG
+ fprintf(stderr, "undo_ring: y1: %d y2: %d idx: %d\n", y1, y2, *idx);
+ for(i=0; i<undo[undo_cur].num; i++){
+ fprintf(stderr, "UU: %d| %s\n", undo[*idx].l[i].n, undo[*idx].l[i].s);
+ }
+#endif
+}