From f6d4aa13577c2f7d8c18458123f83ea6de9712d7 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 25 Apr 2018 19:17:37 +0100 Subject: Minor changes --- buff.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'buff.c') diff --git a/buff.c b/buff.c index 93c779b..89ca82f 100644 --- a/buff.c +++ b/buff.c @@ -21,13 +21,13 @@ int __get_lines(FILE *fin, line_t **first, line_t **last, int *tot){ *first = *last = NULL; while(feof(fin) == 0){ if (!fgets(buff, 4095, fin)) break; - if (buff[0] == '.') + if (*buff == '.') break; s = strlen(buff) + 1; *tot += s -1; l = malloc(sizeof(line_t)); l->c = malloc(s * sizeof(char)); - num_alloc +=1; + num_alloc++; memcpy(l->c, buff, s); l->s = s; if (*first == NULL){ @@ -42,7 +42,7 @@ int __get_lines(FILE *fin, line_t **first, line_t **last, int *tot){ l->next = NULL; *last = l; } - n += 1; + n++; } fprintf(stderr, " >>>> get_lines: num_alloc: %d\n", num_alloc); return n; @@ -95,12 +95,11 @@ void print_lines(char lineno){ for (i=1; inext; pos = i; cur = p; - while(pos < addr1){ + while(pos++ < addr1){ if (lineno) printf("%d\t", pos); printf("%s", cur->c); cur = cur->next; - pos += 1; } if (lineno) printf("%d\t", pos); @@ -205,7 +204,7 @@ void insert_lines(){ first -> prev = cur -> prev; last -> next = cur; num += n; - pos -=1 ; + pos-- ; cur = last; } } @@ -226,14 +225,16 @@ void delete_lines(){ if (addr1 < addr2){ return; } + move_to_line(addr2,0); fprintf(stderr, " >>> delete: addr1: %d addr2: %d pos: %d\n", addr1, addr2, pos); if (addr2 <= 1){ /* we are deleting the first line */ while(pos <= addr1){ + pos ++; free(cur->c); - num_free += 1; + num_free++; if (cur -> next){ cur = cur -> next; free(cur -> prev); @@ -241,10 +242,8 @@ void delete_lines(){ else { free(cur); cur = NULL; - pos ++; break; } - pos ++; } fprintf(stderr, " >>>> delete_lines: num_free: %d\n", num_free); -- cgit v1.2.3