From 4a99dc41d3a9836753a33c00d31e4cbce4e0e3b4 Mon Sep 17 00:00:00 2001 From: Oskar Date: Wed, 3 Apr 2024 23:09:13 +0200 Subject: L+ and L- with numbers work now. Now only immediate numbers are left and then we are done with the L functionality. --- TODO | 2 +- process_multiples.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index ef26101..4612590 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 - improve the length check. If i make the length of an input too big then it seems like the input after the fgets limit gets stuck in stdin and that is kind of a problem. +1 - Finish L implementation diff --git a/process_multiples.c b/process_multiples.c index 5abbdfa..8af048c 100644 --- a/process_multiples.c +++ b/process_multiples.c @@ -17,7 +17,7 @@ int check_L_linecount(uint64_t Flines, uint64_t focus) { return _VALID; } -uint64_t call_L_plus_minus_continue(char *multiple) { +uint64_t call_L_plus_minus_continue(char *multiple, uint64_t focus, uint64_t Flines) { char new_multiple[32] = { '\0' }; @@ -26,9 +26,32 @@ uint64_t call_L_plus_minus_continue(char *multiple) { for( ; multiple[j] != '\n' ; i++, j++) { new_multiple[i] = multiple[j]; } + + char *endptr; + uint64_t new_focus = strtol(new_multiple, &endptr, 10); + errno = 0; + if (errno == ERANGE) { + return focus; + } + if (endptr == new_multiple) { + return focus; + } + + if(multiple[1] == '+') { new_focus = focus+new_focus; } + if(multiple[1] == '-') { + int64_t s_new_focus = (int64_t)new_focus; + int64_t s_focus = (int64_t)focus; + if((s_focus-s_new_focus) <= 0) { + new_focus = 0; + } else { + new_focus = focus-new_focus; + } + } + if(check_L_linecount(Flines, new_focus) == _INVALID) { + return focus; + } - fprintf(stdout, "%s\n", new_multiple); - return 0; + return new_focus; } uint64_t call_L_only(uint64_t focus, uint64_t Flines) { @@ -100,7 +123,8 @@ uint64_t call_L(char *multiple, uint64_t focus, uint64_t Flines) { focus = call_L_plus_minus_only(focus, multiple[1], Flines); return focus; } - call_L_plus_minus_continue(multiple); + focus = call_L_plus_minus_continue(multiple, focus, Flines); + return focus; } -- cgit v1.2.3