summaryrefslogtreecommitdiff
path: root/buff.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-05-30 06:55:28 +0100
committerKatolaZ <katolaz@freaknet.org>2018-05-30 06:55:28 +0100
commite65fc4b791951f31d11510b3e214acb42b91730d (patch)
tree1680a03a7797c7d83b73b12772e3d7bab2e41d81 /buff.c
parent652ef404582555d9f7fca855424108a57cdea3ad (diff)
delete_lines refactoredrefactor
Diffstat (limited to 'buff.c')
-rw-r--r--buff.c42
1 files changed, 31 insertions, 11 deletions
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;
}