From 10f241cce53c8a8da122728ec1577c1472149b85 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 1 Apr 2024 17:16:00 +0200 Subject: L+ and L- seems to work now. --- process_multiples.c | 29 +++++++++++++++++++++++------ startmode.c | 10 ++++++---- test/7ed-TESTING | Bin 70208 -> 0 bytes 3 files changed, 29 insertions(+), 10 deletions(-) delete mode 100755 test/7ed-TESTING diff --git a/process_multiples.c b/process_multiples.c index 78ed456..80f18c5 100644 --- a/process_multiples.c +++ b/process_multiples.c @@ -8,20 +8,37 @@ #include "i_validation.h" #include +int check_L_linecount(uint64_t Flines, uint64_t focus) { + + if (focus < 1 || focus > Flines) { + fprintf(stderr, "check_L_linecount()\n"); + return _INVALID; + } + return _VALID; +} + int call_L_plus_continue(char *multiple) { fprintf(stdout, "+ or - CONTINUE %s\n", multiple); return 0; } -uint64_t call_L_plus_minus_only(uint64_t focus, char p_or_m) { +uint64_t call_L_plus_minus_only(uint64_t focus, char p_or_m, uint64_t Flines) { switch (p_or_m) { - case '+': + case '+': { + int cll = check_L_linecount(Flines, focus+1); + if (cll == _INVALID) { + return focus; + } return focus+1; - break; - case '-': + break; } + case '-': { + int cll = check_L_linecount(Flines, focus-1); + if (cll == _INVALID) { + return focus; + } return focus-1; - break; + break; } } return _NA; @@ -39,7 +56,7 @@ uint64_t call_L(char *multiple, uint64_t focus, uint64_t Flines) { if (multiple[1] == '+' || multiple[1] == '-') { imm = _NA; if (multiple[2] == '\n') { // This is where - and + only inputs happen and get processed - focus = call_L_plus_minus_only(focus, multiple[1]); + focus = call_L_plus_minus_only(focus, multiple[1], Flines); return focus; } call_L_plus_continue(multiple); diff --git a/startmode.c b/startmode.c index 3d31aa5..f77611b 100644 --- a/startmode.c +++ b/startmode.c @@ -100,10 +100,12 @@ int startmode(char filename[]) { while (1) { char *multiple; char single; - int clif = count_lines_in_file(filename, Flines); - if (clif == ) + int clif = count_lines_in_file(filename, &Flines); + if (clif == 1) { + return EXIT_FAILURE; + } - int smode_input_ret = smode_input(&single, &multiple, focus, Flines); + int smode_input_ret = smode_input(&single, &multiple, focus); switch (smode_input_ret) { @@ -116,7 +118,7 @@ int startmode(char filename[]) { switch(multiple[0]) { case 'l': case 'L': - focus = call_L(multiple, focus); + focus = call_L(multiple, focus, Flines); break; case 'n': case 'N': diff --git a/test/7ed-TESTING b/test/7ed-TESTING deleted file mode 100755 index d89facd..0000000 Binary files a/test/7ed-TESTING and /dev/null differ -- cgit v1.2.3