diff options
author | KatolaZ <[email protected]> | 2018-05-31 14:36:27 +0100 |
---|---|---|
committer | KatolaZ <[email protected]> | 2018-05-31 14:36:27 +0100 |
commit | 973479aa7fc254b887aed5fe6a57935648ee883c (patch) | |
tree | 791036edaccb2be9ed73514cf534bb41765ea344 /main.c | |
parent | 00d893c8f8e742acc15e6675dec20c946dfb6fd7 (diff) |
Check on modified files 'q'.Implemented 'W'.more tests.minor fixes
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 58 |
1 files changed, 46 insertions, 12 deletions
@@ -14,7 +14,7 @@ int num = 0; int pos = 0; /* addr1 is the last address, while addr2 is the previous one */ int addr1, addr2; -char *fname; +char *fname, mod=0, lc; line_t* marks[26] = {NULL}; @@ -141,12 +141,12 @@ int get_addr(const char **cmd){ if (semic){ addr1 = num; addr2 = pos; - return 2; + return 2; + } + if (addr1 == -1){ + addr1 = addr2 = pos; + return -1; } - return 1; - } - if (addr1 == -1){ - addr1 = addr2 = pos; return 1; } return 2; @@ -176,13 +176,13 @@ void main_loop(){ char *cmd, *c; int ret, addr, tmp1, tmp2; - char p, move; + char p, move, app; cmd = malloc(256 * sizeof(char)); c = cmd; while(1){ - p = 0; move = 0; + p = 0; move = 0, app = 0; fgets(cmd, 255, stdin); ret = get_addr((const char **) &cmd); @@ -192,6 +192,7 @@ void main_loop(){ fprintf(stderr, ">>> *** addr1: %d, addr2= %d***\n", addr1, addr2); } + switch(cmd[0]){ case 'a': if (addr1 > -1) @@ -208,7 +209,7 @@ void main_loop(){ addr1 = addr2 = pos; append_lines(); case 'd': - if (ret ==-1 ) + if (ret == -1 ) addr2 = 1, addr1=num; CHECKADDR; if (addr1 == 0){ @@ -216,7 +217,14 @@ void main_loop(){ } delete_lines(); break; + case 'E': mod = 0; case 'e': + if (mod){ + if (lc != 'e'){ + E; + break; + } + } cmd++; skip_blank((const char**)&cmd); if (cmd[0] == '!') @@ -278,8 +286,14 @@ void main_loop(){ case '\0': case '\n': fprintf(stderr, ">>>> void command\n"); - if (ret < -1 ) - E; + if (ret == -1 ){ + if (cur -> next){ + cur = cur -> next, pos += 1; + print_cur_line(0); + } + else + E; + } else { if (addr1 <=num) move_to_line(addr1, 1); @@ -289,7 +303,17 @@ void main_loop(){ E; } break; + case 'Q': mod = 0; case 'q': + fprintf(stderr, " >>>> q: mod: %d lc: %c\n", mod, lc); + if (mod){ + if (lc == 'q') + goto cleanup; + else { + E; + break; + } + } goto cleanup; break; case 'm': move = 1; @@ -308,28 +332,38 @@ void main_loop(){ E; move = 0; break; + case 'W': app = 1; case 'w': cmd += 1; get_fname(&cmd); if (!fname) E; else{ - if (write_lines()){ + if (write_lines(app)){ perror(fname); E; } } break; + case '!': + cmd += 1; + //exec_command(); case '=': if (addr1 == -1) addr1 = num; print_lineno(); break; + case 'h': /* not impl. */ + case 'H': /* not impl. */ + case '#': + break; default: if (cmd[0]) fprintf(stderr, ">>> **** unknown command: '%c'****\n", cmd[0]); E; } + lc = cmd[0]; + cmd = c; } cleanup: free(c); |