From 973479aa7fc254b887aed5fe6a57935648ee883c Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Thu, 31 May 2018 14:36:27 +0100 Subject: Check on modified files 'q'.Implemented 'W'.more tests.minor fixes --- buff.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'buff.c') diff --git a/buff.c b/buff.c index c9d6800..fde4448 100644 --- a/buff.c +++ b/buff.c @@ -138,6 +138,7 @@ int read_file(){ cur = b_end; fclose(fin); fprintf(stderr, "%d\n", tot); + mod = 0; return 0; } @@ -207,7 +208,7 @@ void append_lines(){ first = last = NULL; n = __get_lines(stdin, &first, &last, &tot); __append_lines(addr1, n, first, last); - + mod = 1; } void insert_lines(){ @@ -221,7 +222,7 @@ void insert_lines(){ __append_lines(addr1, n, first, last); else __append_lines(addr1-1, n, first, last); - + mod = 1; } @@ -264,7 +265,8 @@ void delete_lines(){ pos = addr2 - 1; cur = prev; } - num -= addr1 - addr2 + 1; + num -= addr1 - addr2 + 1; + mod = 1; } @@ -276,15 +278,19 @@ void change_lines(){ -int write_lines(){ +int write_lines(char app){ FILE *fout; line_t *l; int tot=0; - - if (! (fout = fopen(fname, "w+"))){ - return -1; - } + if (!app) + fout = fopen(fname, "w+"); + else + fout = fopen(fname, "a"); + + if (!fout) + return -1; + l = b_start; while(l){ tot += fprintf(fout, "%s", l->c); @@ -381,4 +387,5 @@ void transfer_lines(int addr, char move){ } __append_lines(addr, n, first, last); move_to_line(addr+n,0); + mod = 1; } -- cgit v1.2.3