diff options
-rw-r--r-- | 7ed.c | 18 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | i_validation.c | 39 | ||||
-rw-r--r-- | process_multiples.c | 23 | ||||
-rw-r--r-- | startmode.c | 4 | ||||
-rw-r--r-- | test/testgrounds/newlinetest | 5 |
6 files changed, 37 insertions, 56 deletions
@@ -30,6 +30,24 @@ " N Create a newline on the line after focus\n"\ " X Remove all contents of a line except the newline itself\n"\ " D Remove all contents of a line including the newline itself\n"\ + " \n"\ + "It is possible to use some of these commands along wih numbers and '+' or '-'.\n"\ + "Commands that support this functionality: L, N, X, D\n"\ + "VALID EXAMPLES:\n"\ + " \n"\ + " 'L+' Would increment the line focus by 1. If you were to put a '-' then it would decrement.\n"\ + " 'L10' Would change the focus to line number 10.\n"\ + " 'L+10 Would increment the line focus by 10. If you were to put a '-' then it would decrement by 10.\n"\ + " 'N', 'N+', 'N+1' Are all valid but do the same thing.\n"\ + " 'N+10' Would add 10 more lines.\n"\ + " 'N10 Would add a line after line 10.'\n"\ + " 'X', 'X+', 'X+1' Are all valid but do the same thing. \n"\ + " 'X10' Would remove the contents of line 10.\n"\ + " 'X+10' Would remove the contents of the current line including the next 9 lines.\n"\ + " 'D', 'D+', 'D+1' Are all valid but do the same thing. \n"\ + " 'D10' Would remove line 10 entirely.\n"\ + " 'D+10' Would remove the current line entirely as well as entirely remove the next 9 lines.\n"\ + " \n"\ #define PROGRAM_NAME "7ed" @@ -1,9 +1,7 @@ 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 - Remove testing code, add comments for future me. -1 - Perform full test of the whole program -1 - Re-write USAGE +1 - Perform full test of the whole program. (I already found a major bug) 2 - Re-write Makefile to make it easier 2 - Add some quality of life features 3 - Re-write new_line and remove_line_contents for better performance. (They are very inefficient) diff --git a/i_validation.c b/i_validation.c index 70762cf..e34ddca 100644 --- a/i_validation.c +++ b/i_validation.c @@ -8,16 +8,8 @@ #include "input.h" #include <stdint.h> -// This will be the new input system for combining commands with line numbers -// Work in progress and far from finished. This is not included when compiling normally. - int validate_check_p_m(char *smode_buf, int mode) { // Check for +, -, +0, -0, +\n, or -\n -/* -_INVALID (immediately stop validating and return invalid to everything) -_PLUS_ONLY (L+ only. Immediately valid. Return) -_PLUS_CONTINUE (L+ And more numbers after it. Will make validate_plus_continue run) -_NA (None of these cases) -*/ + char nums[] = "123456789"; int iflag = _INVALID; @@ -76,12 +68,7 @@ _NA (None of these cases) } int validate_check_imm(char *smode_buf, int mode) { // check immediately for \n, 0 or numbers -/* -_INVALID (immediately stop validating and return invalid to everything) -_IMM_NOTHING == _VALID(valid) -_NA (None of these cases) -_IMM_NUMBER (number immediately after L or N or whatever) -*/ + char nums[] = "123456789"; int iflag = _INVALID; @@ -157,7 +144,7 @@ int validate_imm_numbers(char *smode_buf, int mode) { //Start at 1 for (int i = 1 ; i < SMODE_MAX_INPUT_SIZE ; i++) { - // Nested loop to check every element in nums_with_zero on the current smode element (i)(outer loop) + for (int j = 0 ; j < 10 ; j++) { if (smode_buf[i] == '\n') { @@ -181,7 +168,7 @@ int validate_imm_numbers(char *smode_buf, int mode) { int validate_LN(char *smode_buf, int mode) { // this is still a huge function, validating strings is complicated.... - // although i will admit that the code is overall just so much easier to work with. Still happy that i fixed that. + // though i will admit that the code is overall just so much easier to work with. Still happy that i fixed that. int vcpm_result = validate_check_p_m(smode_buf, mode); @@ -189,59 +176,47 @@ int validate_LN(char *smode_buf, int mode) { int plus_continue = TRUE_7ED; switch(vcpm_result) { case _PLUS_ONLY: - //printf("PLUS ONLY\n"); return _VALID; break; case _PLUS_CONTINUE: - //printf("PLUS CONTINUE\n"); + break; case _INVALID: - //printf("INVALID\n"); return _INVALID; break; case _NA: - //printf("NA\n"); vcimm = TRUE_7ED; plus_continue = FALSE_7ED; break; } if (vcimm == TRUE_7ED) { // This is where L0 is caught - //printf("vcimm start\n"); int vcimm_result = validate_check_imm(smode_buf, mode); int imm_number = FALSE_7ED; switch(vcimm_result) { case _IMM_NUMBER: - //printf("imm number\n"); imm_number = TRUE_7ED; break; case _VALID: - //printf("valid\n"); return _VALID; break; case _INVALID: - //printf("invalid\n"); return _INVALID; break; case _NA: - //printf("NA\n"); return _INVALID; break; } if (imm_number == TRUE_7ED) { - //printf("vimmn start\n"); int vimmn_result = validate_imm_numbers(smode_buf, mode); switch(vimmn_result) { case _VALID: - //printf("valid\n"); return _VALID; break; case _INVALID: - //printf("invalid\n"); return _INVALID; break; case _NA: - //printf("NA\n"); return _INVALID; break; } @@ -251,19 +226,15 @@ int validate_LN(char *smode_buf, int mode) { if (plus_continue == TRUE_7ED) { - //printf("validate plus continue \n"); int vpct_result = validate_plus_continue(smode_buf); switch(vpct_result) { case _VALID: - //printf("valid\n"); return _VALID; break; case _INVALID: - //printf("invalid\n"); return _INVALID; break; case _NA: - //printf("NA\n"); return _INVALID; break; diff --git a/process_multiples.c b/process_multiples.c index c60bdb6..2918aa1 100644 --- a/process_multiples.c +++ b/process_multiples.c @@ -8,9 +8,9 @@ #include "i_validation.h" #include <stdint.h> -int check_L_linecount(uint64_t Flines, uint64_t focus, int mode) { - - if (mode == MODE_N) { // Last check that allows for N0 to work. +int check_L_linecount(uint64_t Flines, uint64_t focus, int mode) { // Check if you are trying to modify or move to lines under 1 or lines that are over the total amount of lines in the file. + // Mode N allows us to go to line 0 because N needs it. + if (mode == MODE_N) { if (focus == 0) { return _VALID; } @@ -23,7 +23,7 @@ int check_L_linecount(uint64_t Flines, uint64_t focus, int mode) { return _VALID; } -uint64_t call_L_immediate(char *multiple, uint64_t focus, uint64_t Flines) { +uint64_t call_L_immediate(char *multiple, uint64_t focus, uint64_t Flines) { // Go to a specific newline char new_multiple[32] = { '\0' }; @@ -51,7 +51,7 @@ uint64_t call_L_immediate(char *multiple, uint64_t focus, uint64_t Flines) { } -uint64_t call_L_plus_minus_continue(char *multiple, uint64_t focus, uint64_t Flines) { +uint64_t call_L_plus_minus_continue(char *multiple, uint64_t focus, uint64_t Flines) { // Go up or down a number of lines char new_multiple[32] = { '\0' }; @@ -88,7 +88,7 @@ uint64_t call_L_plus_minus_continue(char *multiple, uint64_t focus, uint64_t Fli return new_focus; } -uint64_t call_L_only(uint64_t focus, uint64_t Flines) { +uint64_t call_L_only(uint64_t focus, uint64_t Flines) { // Old L functionality. char buf[SMODE_MAX_SIZE] = { '\0' }; fprintf(stdout, "(L): "); @@ -120,7 +120,7 @@ uint64_t call_L_only(uint64_t focus, uint64_t Flines) { return new_focus; } -uint64_t call_L_plus_minus_only(uint64_t focus, char p_or_m, uint64_t Flines) { +uint64_t call_L_plus_minus_only(uint64_t focus, char p_or_m, uint64_t Flines) { // Go up or down by only 1 switch (p_or_m) { case '+': { int cll = check_L_linecount(Flines, focus+1, MODE_L); @@ -141,7 +141,7 @@ uint64_t call_L_plus_minus_only(uint64_t focus, char p_or_m, uint64_t Flines) { return _NA; } -uint64_t call_L(char *multiple, uint64_t focus, uint64_t Flines) { +uint64_t call_L(char *multiple, uint64_t focus, uint64_t Flines) { // Main L function to decide what to do. int imm = _IMM_NUMBER; @@ -171,7 +171,7 @@ uint64_t call_L(char *multiple, uint64_t focus, uint64_t Flines) { return focus; } -int call_N_immediate(char *multiple, uint64_t Flines, char *filename) { +int call_N_immediate(char *multiple, uint64_t Flines, char *filename) { char new_multiple[32] = { '\0' }; @@ -252,7 +252,6 @@ uint64_t call_N(char *multiple, uint64_t focus, uint64_t Flines, char *filename) return 0; } - // N plus continue. Still figuring out how this is gonna work. call_N_plus_continue(multiple, focus, filename); return 0; } @@ -266,7 +265,7 @@ uint64_t call_N(char *multiple, uint64_t focus, uint64_t Flines, char *filename) return 0; } -int call_X_plus_continue(char *multiple, uint64_t focus, char *filename, uint64_t Flines) { // NOT DONE!! IT IS A COPY OF call_N_plus_continue !!! +int call_X_plus_continue(char *multiple, uint64_t focus, char *filename, uint64_t Flines) { char new_multiple[32] = { '\0' }; @@ -292,7 +291,7 @@ int call_X_plus_continue(char *multiple, uint64_t focus, char *filename, uint64_ if (choice() == 1) { return -1; } - for(uint64_t count = 0 ; count < amount_of_lines_to_remove ; count++) { // This is very inefficient if you are adding thousands of lines but why would you wanna do that anyway? + for(uint64_t count = 0 ; count < amount_of_lines_to_remove ; count++) { // This is very inefficient remove_line_contents(filename, focus+count); } diff --git a/startmode.c b/startmode.c index 372cc94..cc19376 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); // implemented + focus = call_L(multiple, focus, Flines); break; case 'n': case 'N': - call_N(multiple, focus, Flines, filename); // Implemented + call_N(multiple, focus, Flines, filename); break; case 'x': case 'X': diff --git a/test/testgrounds/newlinetest b/test/testgrounds/newlinetest index f00c965..91fa8e8 100644 --- a/test/testgrounds/newlinetest +++ b/test/testgrounds/newlinetest @@ -2,9 +2,4 @@ 2 3 4 -5 -6 -7 -8 -9 10 |