From 5d9aa978796cd7290c4c7ece59a75da532fd839c Mon Sep 17 00:00:00 2001 From: Oskar Date: Sun, 7 Apr 2024 19:45:50 +0200 Subject: N is completely done, will start on X maybe? --- TODO | 6 ++---- process_multiples.c | 35 +++++++++++++++++++++++++++++++++++ startmode.c | 4 ++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 5443165..c7716d0 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ 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 - Think about how i want N to actually work -1 - Implement N functionality. -1 - Do tests on N -2 - All L functionality is done. Did some testing and made some fixes. I will keep this here for now in case i find anything more. +1 - +2 - All L and N functionality is done. Did some testing and made some fixes. I will keep this here for now in case i find anything more. 2 - Not really a TODO point but more of an observation and a realisation i have made. I could have just used regex to do the validation of my commands. How about that... Well im too far in (sunk cost fallacy or whatever its called). diff --git a/process_multiples.c b/process_multiples.c index fc648a0..e690280 100644 --- a/process_multiples.c +++ b/process_multiples.c @@ -201,6 +201,40 @@ int call_N_immediate(char *multiple, uint64_t Flines, char *filename) { } +int call_N_plus_continue(char *multiple, uint64_t focus, char *filename) { + + char new_multiple[32] = { '\0' }; + + int choice_yesno = 0; + int i = 0; + int j = 2; + for( ; multiple[j] != '\n' ; i++, j++) { + new_multiple[i] = multiple[j]; + } + + char *endptr; + uint64_t newlines_to_add = strtol(new_multiple, &endptr, 10); + errno = 0; + if (errno == ERANGE) { + return -1; + } + if (endptr == new_multiple) { + return -1; + } + + if (newlines_to_add > 1) { + choice_yesno = choice(); + } + if (choice_yesno == 1) { return -1; } + + for(uint64_t count = 0 ; count < newlines_to_add ; count++) { // This is very inefficient if you are adding thousands of lines but why would you wanna do that anyway? + new_line(filename, focus); + } + + return 0; + +} + uint64_t call_N(char *multiple, uint64_t focus, uint64_t Flines, char *filename) { int imm = _IMM_NUMBER; @@ -219,6 +253,7 @@ uint64_t call_N(char *multiple, uint64_t focus, uint64_t Flines, char *filename) } // N plus continue. Still figuring out how this is gonna work. + call_N_plus_continue(multiple, focus, filename); return 0; } diff --git a/startmode.c b/startmode.c index 80b5427..8dd918d 100644 --- a/startmode.c +++ b/startmode.c @@ -119,11 +119,11 @@ int startmode(char filename[]) { switch(multiple[0]) { case 'l': case 'L': - focus = call_L(multiple, focus, Flines); + focus = call_L(multiple, focus, Flines); // implemented break; case 'n': case 'N': - call_N(multiple, focus, Flines, filename); + call_N(multiple, focus, Flines, filename); // Implemented break; case 'x': case 'X': -- cgit v1.2.3