From b10f9522863c937c08d41e2d6da48174cdb3906a Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Fri, 20 Apr 2018 18:23:24 +0100 Subject: Implemented 'c' command --- main.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index aeeb680..e0b60ff 100644 --- a/main.c +++ b/main.c @@ -4,12 +4,14 @@ #include "buff.h" #include + + line_t *b_start = NULL; line_t *b_end = NULL; line_t *cur = NULL; unsigned int num = 0; unsigned int pos = 0; -/* addr1 is the lasr address, while addr2 is the previous one */ +/* addr1 is the last address, while addr2 is the previous one */ int addr1, addr2; @@ -117,28 +119,40 @@ void main_loop(){ } switch(cmd[0]){ - case 'i': - if (addr1 > -1) - move_to_line(addr1, 0); - insert_lines(); - break; case 'a': if (addr1 > -1) move_to_line(addr1, 0); append_lines(); break; + case 'c': + if (addr1 > -1) + move_to_line(addr1,0); + delete_lines(); + addr1 = addr2 = pos; + append_lines(); case 'd': + if (ret == -1){ + E; + break; + } + if (ret == 2){ + CHECKADDR; + } + if (ret == 1) + addr2 = addr1; delete_lines(); break; + case 'i': + if (addr1 > -1) + move_to_line(addr1, 0); + insert_lines(); + break; case 'n': p = 1; case 'p': - if (ret == 2) - if (addr1 < addr2){ - printf("?\n"); - break; - } - else - print_lines(p); + if (ret == 2){ + CHECKADDR; + print_lines(p); + } else if (ret == 1) move_to_line(addr2, 1); else if (ret == 0) @@ -166,7 +180,7 @@ void main_loop(){ break; default: fprintf(stderr, ">>> **** unknown command: '%c'****\n", cmd[0]); - printf("?\n"); + E; } } } -- cgit v1.2.3