summaryrefslogtreecommitdiff
path: root/buff.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-04-25 19:17:37 +0100
committerKatolaZ <katolaz@freaknet.org>2018-04-25 19:17:37 +0100
commitf6d4aa13577c2f7d8c18458123f83ea6de9712d7 (patch)
treedaff87b1340b3aeb1eb82bb062e686b62f922a8e /buff.c
parentd46fc59c8713fdc2805ed613132f5cfabbcca1c2 (diff)
Minor changes
Diffstat (limited to 'buff.c')
-rw-r--r--buff.c17
1 files changed, 8 insertions, 9 deletions
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; i<addr2; i++) p = p->next;
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);