diff options
author | KatolaZ <[email protected]> | 2018-05-30 06:55:28 +0100 |
---|---|---|
committer | KatolaZ <[email protected]> | 2018-05-30 06:55:28 +0100 |
commit | e65fc4b791951f31d11510b3e214acb42b91730d (patch) | |
tree | 1680a03a7797c7d83b73b12772e3d7bab2e41d81 | |
parent | 652ef404582555d9f7fca855424108a57cdea3ad (diff) |
delete_lines refactoredrefactor
-rw-r--r-- | TODO.org | 3 | ||||
-rw-r--r-- | buff.c | 42 | ||||
-rw-r--r-- | buff.h | 2 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rwxr-xr-x | tests/myed_test.sh | 2 | ||||
-rw-r--r-- | tests/testlist.txt | 1 |
6 files changed, 40 insertions, 13 deletions
@@ -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...) @@ -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; } @@ -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;} @@ -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 |