]> git.xolatile.top Git - soikk-pearson_verify.git/commitdiff
Added quiet mode
authorSoikk <enriquedelacalhacar@gmail.com>
Sun, 20 Oct 2024 20:52:38 +0000 (22:52 +0200)
committerSoikk <enriquedelacalhacar@gmail.com>
Sun, 20 Oct 2024 20:52:38 +0000 (22:52 +0200)
Makefile
README.md
verify.c

index f66c3678ee91cd9e943b1fb4e52d5d88c443c4f8..da2b0f0edcc3f4bfb406675af613a7e4d6b35990 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,9 @@ all: verify.c
 debug: verify.c
        $(CC) verify.c -o verify -DDEBUG
 
+quiet: verify.c
+       $(CC) verify.c -o verify -DQUIET
+
 clean:
        rm -f verify
 
index d9ad8dbabc5af5327e6d6ba887931fb790c6b31c..5e6b07a7e0290c279d860770187b9351b94fdec6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
 # Pearson verify
 This program is meant to be used to verify the ouput of the pearson section of [dv1674_a2](https://github.com/sm13294/dv1674_a2).\
 \
-This program compares 64 bit floating point numbers stored in a separate line each from \<file1\> and \<file2\>. If all the pairs of numbers are the same up to the 15th decimal place, 0 will be returned. If not, this program will check if all numbers are the same up to the 11th decimal place, and if so 1 will be returned. If [stop] is 1, this program will stop as soon as this happens. If any numbers are not the same up to the 11th decimal place, 2 will be returned. If [stop] is 2, this program will stop as soon as this happens. If there is an error while executing this program, -1 will be returned, unless the error lies within the files' structures, in which case 2 will be returned, as it means there was a significant difference in the outputs. Compile with -DDEBUG (make debug) or define DEBUG in the program to print debug information.
+This program compares 64 bit floating point numbers stored in a separate line each from \<file1\> and \<file2\>. If all the pairs of numbers are the same up to the 15th decimal place, 0 will be returned. If not, this program will check if all numbers are the same up to the 11th decimal place, and if so 1 will be returned. If [stop] is 1, this program will stop as soon as this happens. If any numbers are not the same up to the 11th decimal place, 2 will be returned. If [stop] is 2, this program will stop as soon as this happens. If there is an error while executing this program, -1 will be returned, unless the error lies within the files' structures, in which case 2 will be returned, as it means there was a significant difference in the outputs. Define DEBUG in the source code or compile with -DDEBUG (or use make debug) to print debug information. Define QUIET in the source code or compile with -DQUIET (or use make quiet) to prevent the program from printing anything.
index dc4fdd54531a4616781757d6ac16af402537c8f6..744951ce3be5d8cdd85bc874e18d3273dfa23679 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -15,8 +15,9 @@ int main(int argc, char *argv[]){
        long unsigned int line = 1;
 
        if(argc < 3){
-               fprintf(stderr, "ERROR: Wrong usage.\n");
-               fprintf(stderr, "Usage: %s <file1> <file2> [stop]\n", argv[0]);
+#ifndef QUIET
+               fprintf(stderr, "ERROR:\tWrong usage.\n");
+               fprintf(stderr, "Usage:\t%s <file1> <file2> [stop]\n", argv[0]);
                fprintf(stderr,
                        "\tThis program compares 64 bit floating point numbers stored in a separate\n"
                        "\tline each from <file1> and <file2>. If all the pairs of numbers are the\n"
@@ -28,9 +29,12 @@ int main(int argc, char *argv[]){
                        "\tas this happens. If there is an error while executing this program, -1 will\n"
                        "\tbe returned, unless the error lies within the files' structures, in which\n"
                        "\tcase 2 will be returned, as it means there was a significant difference in\n"
-                       "\tthe outputs. Compile with -DDEBUG (make debug) or define DEBUG in the program\n"
-                       "\tto print debug information.\n"
+                       "\tthe outputs. Define DEBUG in the source code or compile with -DDEBUG (or use\n"
+                       "\tmake debug) to print debug information. Define QUIET in the source code or\n"
+                       "\tcompile with -DQUIET (or use make quiet) to prevent the program from printing\n"
+                       "\tanything.\n"
                );
+#endif
                ret = -1;
                goto end;
        }
@@ -41,13 +45,17 @@ int main(int argc, char *argv[]){
 
        f1 = fopen(argv[1], "rb");
        if(!f1){
-               fprintf(stderr, "ERROR: Cannot open file '%s'.\n", argv[1]);
+#ifndef QUIET
+               fprintf(stderr, "ERROR:\tCannot open file '%s'.\n", argv[1]);
+#endif
                ret = -1;
                goto end;
        }
        f2 = fopen(argv[2], "rb");
        if(!f2){
-               fprintf(stderr, "ERROR: Cannot open file '%s'.\n", argv[2]);
+#ifndef QUIET
+               fprintf(stderr, "ERROR:\tCannot open file '%s'.\n", argv[2]);
+#endif
                ret = -1;
                goto end;
        }
@@ -56,12 +64,16 @@ int main(int argc, char *argv[]){
                double d1, d2;
        
                if(fscanf(f1, "%lg\n", &d1) != 1){
-                       fprintf(stderr, "ERROR: Cannot read number from file '%s' at line %lu.\n", argv[1], line);
+#ifndef QUIET
+                       fprintf(stderr, "ERROR:\tCannot read number from file '%s' at line %lu.\n", argv[1], line);
+#endif
                        ret = 2;
                        goto close_end;
                }
                if(fscanf(f2, "%lg\n", &d2) != 1){
-                       fprintf(stderr, "ERROR: Cannot read number from file '%s' at line %lu.\n", argv[1], line);
+#ifndef QUIET
+                       fprintf(stderr, "ERROR:\tCannot read number from file '%s' at line %lu.\n", argv[1], line);
+#endif
                        ret = 2;
                        goto close_end;
                }
@@ -81,7 +93,9 @@ int main(int argc, char *argv[]){
        }
 
        if((feof(f1) && !feof(f2)) || (!feof(f1) && feof(f2))){
-               fprintf(stderr, "ERROR: Different number of lines in files '%s' and '%s'.\n", argv[1], argv[2]);
+#ifndef QUIET
+               fprintf(stderr, "ERROR:\tDifferent number of lines in files '%s' and '%s'.\n", argv[1], argv[2]);
+#endif
                ret = 2;
        }
 
@@ -90,9 +104,11 @@ close_end:
        fclose(f2);
 
 end:
+#ifndef QUIET
 #ifdef DEBUG
        printf("%lu lines read\n", line);
        printf("Return value: %d\n", ret);
+#endif
 #endif
 
        return ret;