From e65fc4b791951f31d11510b3e214acb42b91730d Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 30 May 2018 06:55:28 +0100 Subject: delete_lines refactored --- buff.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'buff.c') diff --git a/buff.c b/buff.c index 48c5a80..6da5656 100644 --- a/buff.c +++ b/buff.c @@ -235,29 +235,49 @@ void insert_lines(){ void delete_lines(){ - line_t *handle; + line_t *handle = NULL, *next, *prev; int num_free = 0; - if (addr1 == -1){ - addr1 = pos; - } if (addr2 == -1){ addr2 = addr1; } - - if (addr1 < addr2){ - return; - } - move_to_line(addr2,0); fprintf(stderr, " >>> delete: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos); - /* FIXME: REIMPLEMENT delete_lines() */ + if (addr2 > 1){ + handle = cur -> prev; + } + while(pos <= addr1){ + pos ++; + next = cur -> next; + prev = cur -> prev; + free(cur -> c); + free(cur); + if (next) + cur = next; + else + break; + } + + if (!handle){ + /* first line deleted */ + b_start = cur; + } + else{ + handle -> next = cur; + } + + if (addr1 < num) + pos = addr1 +1; + else{ + pos = addr2 - 1; + cur = prev; + } - num -= addr1 - addr2 + 1; + num -= addr1 - addr2 + 1; } -- cgit v1.2.3