diff options
-rw-r--r-- | i_validation.c | 39 | ||||
-rw-r--r-- | startmode.c | 9 | ||||
-rw-r--r-- | test/testcases/i_validation_cases.txt | 21 | ||||
-rwxr-xr-x | test/vimmn | bin | 0 -> 26904 bytes |
4 files changed, 40 insertions, 29 deletions
diff --git a/i_validation.c b/i_validation.c index 9ae541e..4ba7ff8 100644 --- a/i_validation.c +++ b/i_validation.c @@ -109,39 +109,30 @@ int validate_plus_continue(char *smode_buf) { // if vcpm returns _PLUS_CONTINUE int validate_imm_numbers(char *smode_buf) { - int Kflag; + // Validate after L when its clear that there are only numbers char nums_with_zero[] = "0123456789"; - // Check the rest with a loop. Start at 2 + int kflag = _INVALID; + //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] == nums_with_zero[j]) {//check if there is a number, if there is then next check - if (smode_buf[i+1] == '\n' || smode_buf[i+1] == '\0') { // if there was a number then check if theres a newline - // it will break out here and then an if statement check will also check it again so that it can break out of the outer loop - - 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; - } - + + if (smode_buf[i] == '\n') { + return _VALID; + } + kflag = _INVALID; + if (smode_buf[i] == nums_with_zero[j]) { + kflag = _VALID; break; } - } //inner nested loop - - - + } //inner nested loop + if (kflag == _INVALID) { + return _INVALID; + } }//outer nested loop - return 0; // remove, its just here to make the compiler not output a bunch of warnings + return _NA; } int validate_L(char *smode_buf) { diff --git a/startmode.c b/startmode.c index e9064f4..821610a 100644 --- a/startmode.c +++ b/startmode.c @@ -25,13 +25,14 @@ int ncat(char filename[]) { return 0; } -int display_name_linecount(char *filename, uint64_t Flines) { +int display_name_linecount(char *filename) { + uint64_t Flines; int returnval = count_lines_in_file(filename, &Flines); if (returnval == 1) { return 1; } - fprintf(stdout,"%s %lu lines\n", filename, Flines); + fprintf(stdout,"%s %ld lines\n", filename, Flines); return 0; } @@ -39,7 +40,7 @@ int display_name_linecount(char *filename, uint64_t Flines) { int startmode(char filename[]) { // The entry to the program. Count lines and display the count. Also show which file is being edited. uint64_t Flines; - int dnl = display_name_linecount(filename, Flines); + int dnl = display_name_linecount(filename); if (dnl == 1) { return EXIT_FAILURE; } @@ -139,7 +140,7 @@ int startmode(char filename[]) { case 'C': case 'c': - int dnl = display_name_linecount(filename, Flines); + int dnl = display_name_linecount(filename); if (dnl == 1) { return EXIT_FAILURE; } diff --git a/test/testcases/i_validation_cases.txt b/test/testcases/i_validation_cases.txt index 3e1754b..474feb2 100644 --- a/test/testcases/i_validation_cases.txt +++ b/test/testcases/i_validation_cases.txt @@ -93,6 +93,25 @@ Overall results: Tested OK. Seems fine. validate_imm_numbers Positive input (Valid): +L1 +L2 +L9 +L10 +L10000 +L999 +L1112 +L3987453 + Negative (Invalid): +L1- +L9+ +L1L +L9a +L1F +L9e +L100000000L +L942sA +L223+213123 +L2+1 -Overall results:
\ No newline at end of file +Overall results: Tested OK. Seems fine.
\ No newline at end of file diff --git a/test/vimmn b/test/vimmn Binary files differnew file mode 100755 index 0000000..5a1ee36 --- /dev/null +++ b/test/vimmn |