From f5af9591856569c39d718059b3dbbc69c6e5f8d5 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 1 Apr 2024 18:33:53 +0200 Subject: Implemented call_L_only. This makes the program behave like 7ed v1 and asks for a line number after pressing enter. I still want old functionality to work because there really isnt any reason not to have it. --- process_multiples.c | 36 ++++++++++++++++++++++++++++++++++-- test/testgrounds/newlinetest | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/process_multiples.c b/process_multiples.c index 80f18c5..61adcb3 100644 --- a/process_multiples.c +++ b/process_multiples.c @@ -17,12 +17,43 @@ int check_L_linecount(uint64_t Flines, uint64_t focus) { return _VALID; } -int call_L_plus_continue(char *multiple) { +uint64_t call_L_plus_continue(char *multiple) { fprintf(stdout, "+ or - CONTINUE %s\n", multiple); return 0; } +uint64_t call_L_only(uint64_t focus, uint64_t Flines) { + + char buf[32] = { '\0' }; + fprintf(stdout, "(L): "); + fgets(buf, 30, stdin); + + if (buf[0] == '\n') { + return focus; + } + + char *endptr; + uint64_t new_focus = strtol(buf, &endptr, 10); + errno = 0; + if (errno == ERANGE) { + return focus; + } + if (endptr == buf) { + return focus; + } + if (*endptr != '\n') { + return focus; + } + + int cll = check_L_linecount(Flines, new_focus); + if (cll == _INVALID) { + return focus; + } + + return new_focus; +} + uint64_t call_L_plus_minus_only(uint64_t focus, char p_or_m, uint64_t Flines) { switch (p_or_m) { case '+': { @@ -50,7 +81,8 @@ uint64_t call_L(char *multiple, uint64_t focus, uint64_t Flines) { if (multiple[1] == '\n') { imm = _NA; - fprintf(stdout, "L only\n"); + focus = call_L_only(focus, Flines); + return focus; } if (multiple[1] == '+' || multiple[1] == '-') { diff --git a/test/testgrounds/newlinetest b/test/testgrounds/newlinetest index f00c965..766a493 100644 --- a/test/testgrounds/newlinetest +++ b/test/testgrounds/newlinetest @@ -8,3 +8,4 @@ 8 9 10 +WOW! -- cgit v1.2.3