diff options
author | KatolaZ <katolaz@freaknet.org> | 2018-05-30 06:29:18 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2018-05-30 06:29:18 +0100 |
commit | 652ef404582555d9f7fca855424108a57cdea3ad (patch) | |
tree | b9106730be79381027b50fd48bd3b99c5400a6ac /main.c | |
parent | 8a4e57da301445ae4ad7bf06a7ce18c3091ac9df (diff) |
Reimplemented (and fixed) insert/append
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 42 |
1 files changed, 34 insertions, 8 deletions
@@ -58,10 +58,18 @@ int get_addr(const char **cmd){ case ',': /* range 1 */ /* refactor to set addr2 = addr1 */ fprintf(stderr, " >>>> comma: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos); comma = 1; + if (addr1 == -1){ + (*cmd)++; + return -1; + } addr2 = addr1; + addr1 = -1; break; case ';': /* range 2*/ semic = 1; + if (addr1 == -1){ + return -1; + } addr2 = addr1; break; case '?': DIR = BW; @@ -133,8 +141,9 @@ int get_addr(const char **cmd){ if (semic){ addr1 = num; addr2 = pos; - } return 2; + } + return 1; } if (addr1 == -1){ addr1 = addr2 = pos; @@ -167,13 +176,13 @@ void main_loop(){ char *cmd, *c; int ret; - char p; + char p, move; cmd = malloc(256 * sizeof(char)); c = cmd; while(1){ - p = 0; + p = 0; move = 0; fgets(cmd, 255, stdin); ret = get_addr((const char **) &cmd); @@ -187,19 +196,20 @@ void main_loop(){ case 'a': if (addr1 > -1) move_to_line(addr1, 0); + else + addr1 = pos; append_lines(); break; case 'c': if (addr1 > -1) move_to_line(addr1,0); + CHECKADDR; delete_lines(); addr1 = addr2 = pos; append_lines(); case 'd': - if (ret < 0){ - E; - break; - } + if (ret ==-1 ) + addr2 = 1, addr1=num; CHECKADDR; delete_lines(); break; @@ -233,6 +243,9 @@ void main_loop(){ case 'i': if (addr1 > -1) move_to_line(addr1, 0); + else + addr1 = pos; + CHECKADDR; insert_lines(); break; case 'k': @@ -252,6 +265,10 @@ void main_loop(){ move_to_line(addr1, 0); print_cur_line(p); } + else if (ret == -1){ + addr2=1, addr1=num; + print_lines(p); + } else E; break; @@ -272,6 +289,15 @@ void main_loop(){ case 'q': goto cleanup; break; + case 'm': move = 1; + case 't': + cmd +=1; + CHECKADDR; + if (get_addr((const char**)&cmd) == 1) + transfer_lines(addr1, move); + else + E; + break; case 'w': cmd +=1; get_fname(&cmd); @@ -314,7 +340,7 @@ int main(int argc, char *argv[]){ perror(fname); } main_loop(); - addr1 = pos, addr2 = 1; + addr1 = num, addr2 = 1; delete_lines(); free(fname); } |