diff options
author | Oskar <[email protected]> | 2024-04-01 17:16:00 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-04-01 17:16:00 +0200 |
commit | 10f241cce53c8a8da122728ec1577c1472149b85 (patch) | |
tree | 9efc29fbe28d15b7bde9cefd38cc1df945ec524a | |
parent | 3fbbbfbfceff0344d6f78c68cfcf11193557be76 (diff) |
L+ and L- seems to work now.
-rw-r--r-- | process_multiples.c | 29 | ||||
-rw-r--r-- | startmode.c | 10 | ||||
-rwxr-xr-x | test/7ed-TESTING | bin | 70208 -> 0 bytes |
3 files changed, 29 insertions, 10 deletions
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 <stdint.h> +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 Binary files differdeleted file mode 100755 index d89facd..0000000 --- a/test/7ed-TESTING +++ /dev/null |