summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i_validation.c207
-rw-r--r--i_validation.h6
-rw-r--r--input.c4
3 files changed, 55 insertions, 162 deletions
diff --git a/i_validation.c b/i_validation.c
index e443697..1239b85 100644
--- a/i_validation.c
+++ b/i_validation.c
@@ -11,7 +11,7 @@
// 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) { // Check for +, -, +0, -0, +\n, or -\n
+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)
@@ -20,25 +20,55 @@ _NA (None of these cases)
*/
char nums[] = "123456789";
int iflag = _INVALID;
- if (smode_buf[1] == '+' || smode_buf[1] == '-') {
- if (smode_buf[2] == '0') {
- return _INVALID; // Only L0 (invalid)
- }
- if (smode_buf[2] == '\n') { // Only L+
- return _PLUS_ONLY;
- }
- for (int i = 0 ; i < 9 ; i++) { // Check if theres a number after +
- iflag = _VALID;
- if (smode_buf[2] == nums[i]) {
- return _PLUS_CONTINUE; // if true then continue
- } else {
- iflag = _INVALID;
+ switch(mode) {
+ case MODE_L:
+ if (smode_buf[1] == '+' || smode_buf[1] == '-') {
+ if (smode_buf[2] == '0') {
+ return _INVALID; // Only L0 (invalid)
+ }
+ if (smode_buf[2] == '\n') { // Only L+
+ return _PLUS_ONLY;
+ }
+
+ for (int i = 0 ; i < 9 ; i++) { // Check if theres a number after +
+ iflag = _VALID;
+ if (smode_buf[2] == nums[i]) {
+ return _PLUS_CONTINUE; // if true then continue
+ } else {
+ iflag = _INVALID;
+ }
+ }
+ if (iflag == _INVALID) {
+ return _INVALID;
+ }
}
- }
- if (iflag == _INVALID) {
+ break;
+ case MODE_N:
+ if (smode_buf[1] == '+') {
+ if (smode_buf[2] == '0') {
+ return _INVALID; // Only L0 (invalid)
+ }
+ if (smode_buf[2] == '\n') { // Only L+
+ return _PLUS_ONLY;
+ }
+
+ for (int i = 0 ; i < 9 ; i++) { // Check if theres a number after +
+ iflag = _VALID;
+ if (smode_buf[2] == nums[i]) {
+ return _PLUS_CONTINUE; // if true then continue
+ } else {
+ iflag = _INVALID;
+ }
+ }
+ if (iflag == _INVALID) {
+ return _INVALID;
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "WRONG MODE\n");
return _INVALID;
- }
}
return _NA;
@@ -135,12 +165,12 @@ int validate_imm_numbers(char *smode_buf) {
return _NA;
}
-int validate_L(char *smode_buf) {
+int validate_L(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.
- int vcpm_result = validate_check_p_m(smode_buf);
+ int vcpm_result = validate_check_p_m(smode_buf, mode);
int vcimm = FALSE_7ED;
int plus_continue = TRUE_7ED;
@@ -226,146 +256,7 @@ int validate_L(char *smode_buf) {
}
}
-
- // this below will become validate_imm_numbers or something
return _INVALID; // temporary invalid
}
-
-int validate_N(char *smode_buf) {
- /* N will work very similarly to L.
- When i mark as (DONE) i don't actually mean the full feature, i mean the input validation for that specific feature to be done.
-
- Just N will create a new line after the focus line (DONE)
- N+ will do the same (DONE)
- N+1 will do the same (DONE)
- In short: N = N+ = N+1 (They will all create 1 line after the focus line)
-
- N+2 Will create 2 lines after focus line.
- N+10 Will create 10 lines after the focus line
- N10 Will create a line after line 10
-
- */
- char nums_with_zero[] = "0123456789";
- char nums[] = "123456789";
- int N_num_flag = _INVALID;
- int plus_num_flag = _INVALID; //If true the if statement will validate if input is valid after the +
- int num_flag = _INVALID; // If true the if statement will validate if input is valid after L
- if (smode_buf[1] == '+') {
- plus_num_flag = _ONE;
- if (smode_buf[2] == '0') {
- return _INVALID;
- }
-
- if (!((smode_buf[2] >= '0' && smode_buf[2] <= '9') || smode_buf[2] == '\n')) {
- return _INVALID;
- }
-
- for (int i = 0 ; i < 9 ; i++) { // Check if theres a number after +
- if (smode_buf[2] == nums[i]) {
- plus_num_flag = _VALID;
- break;
- }
- }
- }
-
- if (plus_num_flag == _VALID) { // Because there is a number after + or - then the flag is 0 and this code runs
- int plus_valid_flag = _INVALID;
- N_num_flag = _INVALID; // False
- // Check the rest with a loop. Start at 2
- for (int i = 2 ; 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] == nums_with_zero[j]) {//check if its not a number. It could be the null terminator so we check if it is
- if (smode_buf[i+1] == '\n' || smode_buf[i+1] == '\0') {
- N_num_flag = _VALID; // valid
- plus_valid_flag = _VALID; //valid
-
- break;
- }
- break;
- }
- if(smode_buf[i+1] != nums_with_zero[j]) {
- return _INVALID;
- }
-
- } //inner nested loop
- if (plus_valid_flag == _VALID) {
- break;
- }
-
-
- }//outer nested loop
- }
-
- // We aren't checking for N_num_flag yet because i haven't gotten that far in the code
- if (smode_buf[1] == '0') { // [1] because there is no + at 1. Number starts immediately after L
- N_num_flag = _INVALID; // if 0 then its just invalid immediately
- }
-
- for (int i = 0 ; i < 9 ; i++) { // Check if it starts with a number
- if (smode_buf[1] == nums[i]) {
- //printf("Its a number!\n");
- num_flag = _VALID;
- break;
- }
- }
-
- if (num_flag == 0) { // Start validating if there are numbers after N
- int valid_flag = _INVALID;
- N_num_flag = _INVALID; // False
- int Kflag = _INVALID;
- // Check the rest with a loop. Start at 2
- 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] == nums_with_zero[j]) {//check if its not a number. It could be the null terminator so we check if it is
- if (smode_buf[i+1] == '\n' || smode_buf[i+1] == '\0') {
-
- N_num_flag = _VALID;
- valid_flag = _VALID;
- break;
- }
- Kflag = _INVALID;
- for (int k = 0 ; k < 10 ; k++) {
- if (smode_buf[i+1] == nums_with_zero[k]) { // We checked for newline earlier but since we didnt fine one
- Kflag = _VALID; // We check if theres a number. If theres a number then keep going
- break; // If there is anything but a number then Return _INVALID
- }
- }
- if (Kflag == _INVALID) {
- return _INVALID;
- }
- break;
- }
-
- } //inner nested loop
- if (valid_flag == _VALID) {
- //printf("Validflag!\n");
- break;
- }
-
- }//outer nested loop
- }
-
- if (smode_buf[1] == '\n') {
- return _VALID; // just return N
- }
-
- if (plus_num_flag == _ONE) {
- return _VALID;
- }
-
- if (N_num_flag == _VALID) {
- return _VALID; // actually return the valid string here
- }
- if (N_num_flag == _INVALID) {
- return _INVALID; // invalid! return '?'
- }
-
- return _INVALID;
-
-} \ No newline at end of file
diff --git a/i_validation.h b/i_validation.h
index 50cf6fb..28aea47 100644
--- a/i_validation.h
+++ b/i_validation.h
@@ -13,15 +13,17 @@
#define _IMM_NOTHING _VALID
#define _CONTINUE 6
#define _NA 7
+#define MODE_L 76
+#define MODE_N 78
int validate_imm_numbers(char *smode_buf);
-int validate_check_p_m(char *smode_buf);
+int validate_check_p_m(char *smode_buf, int mode);
int validate_check_imm(char *smode_buf);
int validate_plus_continue(char *smode_buf);
-int validate_L(char *smode_buf);
+int validate_L(char *smode_buf, int mode);
int validate_N(char *smode_buf); \ No newline at end of file
diff --git a/input.c b/input.c
index 2cc2089..a2c97f0 100644
--- a/input.c
+++ b/input.c
@@ -34,7 +34,7 @@ int smode_input(char *single, char **multiple, uint64_t focus) { // This functio
case 'l':
case 'L': {
- int chk = validate_L(smode_buf);
+ int chk = validate_L(smode_buf, MODE_L);
if (chk == _INVALID) {
return _FAIL;
}
@@ -46,7 +46,7 @@ int smode_input(char *single, char **multiple, uint64_t focus) { // This functio
case 'n':
case 'N': {
- int chk = validate_N(smode_buf);
+ int chk = validate_L(smode_buf, MODE_N);
if (chk == _INVALID) {
return _FAIL;
}