From b3d8be14e12aca5993925c156da5eb76af88e665 Mon Sep 17 00:00:00 2001 From: Oskar Date: Sat, 20 Apr 2024 16:27:55 +0200 Subject: Fixed issue where files with no lines dont work properly with 'N' --- TODO | 2 +- editmode.c | 8 +++++++- test/nl.sh | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 1290cca..36ab87d 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ TODO list. This is mostly so i can plan more granularly and remember small stuff i was working on last time and what i should prioritise first. This is not my overall big planning board. (1 highest prio, 10 lowest) -1 - remove_line_contents more efficient. Maybe allow specifying amount of lines to add so we dont need to call the function too many times. +1 - Make remove_line_contents more efficient. Maybe allow specifying amount of lines to add so we dont need to call the function too many times. diff --git a/editmode.c b/editmode.c index b5aa770..14485d3 100644 --- a/editmode.c +++ b/editmode.c @@ -178,7 +178,13 @@ int new_line(char filename[], long long new_line_pos_temp, uint64_t amount_of_li fputc('\n', file); fputc('\n', file); fclose(file); - return 0; + + if(amount_of_lines == 1) { + return 0; + } + if(amount_of_lines > 1) { + amount_of_lines = amount_of_lines-1; + } } } diff --git a/test/nl.sh b/test/nl.sh index 9d3d0cb..d064504 100755 --- a/test/nl.sh +++ b/test/nl.sh @@ -1,5 +1,7 @@ #!/bin/bash +#Regen 'newlinetest' file so i dont have to manually repair it to its original state + filename="testgrounds/newlinetest" rm -f $filename -- cgit v1.2.3