From f6d4aa13577c2f7d8c18458123f83ea6de9712d7 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 25 Apr 2018 19:17:37 +0100 Subject: Minor changes --- TODO.org | 7 ++++--- buff.c | 17 ++++++++--------- main.c | 2 +- obf.ed | 6 ++++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/TODO.org b/TODO.org index 1af5a23..f409a75 100644 --- a/TODO.org +++ b/TODO.org @@ -3,17 +3,18 @@ * IN-PROGRESS FIXME ** DONE check file name input in 'f' and 'w' -** TODO Change read_lines to use __get_lines (let fin point to the file to read from...) +** DONE Change read_lines to use __get_lines (let fin point to the file to read from...) -* IN-PROGRESS Commands [3/20] +* IN-PROGRESS Commands [3/21] ** DONE c ** DONE w -** TODO e +** IN-PROGRESS e ** TODO W ** TODO E ** TODO j ** TODO r +** TODO # ** TODO t ** TODO m ** TODO s 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); diff --git a/main.c b/main.c index 2d2a1eb..1718a5b 100644 --- a/main.c +++ b/main.c @@ -181,7 +181,7 @@ void main_loop(){ delete_lines(); break; case 'e': - cmd += 1; + cmd++; skip_blank((const char**)&cmd); if (cmd[0] == '!') //read_command(); diff --git a/obf.ed b/obf.ed index 1d964a6..937b3f2 100644 --- a/obf.ed +++ b/obf.ed @@ -7,7 +7,7 @@ H 1,$s/prev/p/g 1,$s/first/f/g 1,$s/last/ll/g -1,$s/move_to_line/mtl/g +1,$s/move_to_line/ml/g 1,$s/skip_blank/sb/g 1,$s/get_addr/ga/g 1,$s/main_loop/mp/g @@ -16,7 +16,7 @@ H 1,$s/read_lines/rl/g 1,$s/insert_lines/il/g 1,$s/print_lines/pl/g -1,$s/print_cur_line/pcl/g +1,$s/print_cur_line/pc/g 1,$s/print_lineno/pn/g 1,$s/search_pos/sp/g 1,$s/get_lines/gl/g @@ -24,6 +24,8 @@ H 1,$s/pos/p/g 1,$s/cur/c/g 1,$s/fprintf.*//g +1,$s/printf/P/g +1,$s/num_alloc/na/g 1,$s/ -> /->/g 1,$s/; */;/g 1,$s/ = /=/g -- cgit v1.2.3