summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.org3
-rw-r--r--buff.c42
-rw-r--r--buff.h2
-rw-r--r--main.c3
-rwxr-xr-xtests/myed_test.sh2
-rw-r--r--tests/testlist.txt1
6 files changed, 40 insertions, 13 deletions
diff --git a/TODO.org b/TODO.org
index 6a72e1a..d5460cd 100644
--- a/TODO.org
+++ b/TODO.org
@@ -3,8 +3,9 @@
* IN-PROGRESS FIXME
** TODO Implement check on file modified
+** DONE Reimplement delete_lines
** DONE Re-check insert/append (test_insapp failing with a double-free)
-** TODO Re-check delete as well (maybe related to insert/append?!?!?)
+** DONE Re-check delete as well (maybe related to insert/append?!?!?)
** DONE check file name input in 'f' and 'w'
** DONE Change read_lines to use __get_lines (let fin point to the file to read from...)
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;
}
diff --git a/buff.h b/buff.h
index 020e3b2..14be917 100644
--- a/buff.h
+++ b/buff.h
@@ -5,7 +5,7 @@
#include <stdlib.h>
#include <string.h>
-#define E printf("?\n")
+#define E fprintf(stderr, "?\n")
#define CHECKADDR if (addr1 < addr2){ E; break;}
diff --git a/main.c b/main.c
index 5dce812..d22a028 100644
--- a/main.c
+++ b/main.c
@@ -211,6 +211,9 @@ void main_loop(){
if (ret ==-1 )
addr2 = 1, addr1=num;
CHECKADDR;
+ if (addr1 == 0){
+ E; break;
+ }
delete_lines();
break;
case 'e':
diff --git a/tests/myed_test.sh b/tests/myed_test.sh
index 4c551a4..c81679d 100755
--- a/tests/myed_test.sh
+++ b/tests/myed_test.sh
@@ -14,6 +14,8 @@ while read EDFILE EDSOURCE; do
FILE1=$(tempfile)
FILE2=$(tempfile)
+ #cat ${EDFILE} | /bin/ed ${EDSOURCE} > ${FILE1} 2>&1
+ #cat ${EDFILE} | ../myed ${EDSOURCE} > ${FILE2} 2>&1
cat ${EDFILE} | /bin/ed ${EDSOURCE} > ${FILE1} 2>/dev/null
cat ${EDFILE} | ../myed ${EDSOURCE} > ${FILE2} 2>/dev/null
diff --git a/tests/testlist.txt b/tests/testlist.txt
index df9ca98..d55ef3a 100644
--- a/tests/testlist.txt
+++ b/tests/testlist.txt
@@ -2,3 +2,4 @@ test_addr.ed pippo.c
#test_pippo.ed oejn
test_incr.ed pippo.c
test_insapp.ed pippo.c
+test_del.ed pippo.c