[libxml2] Add a flag to not output anything when xmllint succeeded



commit 02bee4c41444fa5c50e3b9ad5f851656b6d0b086
Author: hhb <haibohuang2010 gmail com>
Date:   Tue Feb 2 22:27:52 2021 +0000

    Add a flag to not output anything when xmllint succeeded

 xmllint.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/xmllint.c b/xmllint.c
index 4469bf0a..6ca1bf54 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -165,6 +165,7 @@ static int xinclude = 0;
 static int dtdattrs = 0;
 static int loaddtd = 0;
 static xmllintReturnCode progresult = XMLLINT_RETURN_OK;
+static int quiet = 0;
 static int timing = 0;
 static int generate = 0;
 static int dropdtd = 0;
@@ -1665,7 +1666,9 @@ testSAX(const char *filename) {
                                      (void *)user_data);
        if (repeat == 0) {
            if (ret == 0) {
-               fprintf(stderr, "%s validates\n", filename);
+               if (!quiet) {
+                   fprintf(stderr, "%s validates\n", filename);
+               }
            } else if (ret > 0) {
                fprintf(stderr, "%s fails to validate\n", filename);
                progresult = XMLLINT_ERR_VALID;
@@ -1948,7 +1951,9 @@ static void streamFile(char *filename) {
                fprintf(stderr, "%s fails to validate\n", filename);
                progresult = XMLLINT_ERR_VALID;
            } else {
-               fprintf(stderr, "%s validates\n", filename);
+               if (!quiet) {
+                   fprintf(stderr, "%s validates\n", filename);
+               }
            }
        }
 #endif
@@ -2840,7 +2845,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
 #endif
        ret = xmlSchematronValidateDoc(ctxt, doc);
        if (ret == 0) {
-           fprintf(stderr, "%s validates\n", filename);
+           if (!quiet) {
+               fprintf(stderr, "%s validates\n", filename);
+           }
        } else if (ret > 0) {
            fprintf(stderr, "%s fails to validate\n", filename);
            progresult = XMLLINT_ERR_VALID;
@@ -2868,7 +2875,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
        xmlRelaxNGSetValidErrors(ctxt, xmlGenericError, xmlGenericError, NULL);
        ret = xmlRelaxNGValidateDoc(ctxt, doc);
        if (ret == 0) {
-           fprintf(stderr, "%s validates\n", filename);
+           if (!quiet) {
+               fprintf(stderr, "%s validates\n", filename);
+           }
        } else if (ret > 0) {
            fprintf(stderr, "%s fails to validate\n", filename);
            progresult = XMLLINT_ERR_VALID;
@@ -2893,7 +2902,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) {
        xmlSchemaSetValidErrors(ctxt, xmlGenericError, xmlGenericError, NULL);
        ret = xmlSchemaValidateDoc(ctxt, doc);
        if (ret == 0) {
-           fprintf(stderr, "%s validates\n", filename);
+           if (!quiet) {
+               fprintf(stderr, "%s validates\n", filename);
+           }
        } else if (ret > 0) {
            fprintf(stderr, "%s fails to validate\n", filename);
            progresult = XMLLINT_ERR_VALID;
@@ -3010,6 +3021,7 @@ static void usage(FILE *f, const char *name) {
     fprintf(f, "\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
     fprintf(f, "\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
 #endif /* LIBXML_VALID_ENABLED */
+    fprintf(f, "\t--quiet : be quiet when succeeded\n");
     fprintf(f, "\t--timing : print some timings\n");
     fprintf(f, "\t--output file or -o file: save to a given file\n");
     fprintf(f, "\t--repeat : repeat 100 times, for timing or profiling\n");
@@ -3244,6 +3256,9 @@ main(int argc, char **argv) {
        else if ((!strcmp(argv[i], "-insert")) ||
                 (!strcmp(argv[i], "--insert")))
            insert++;
+       else if ((!strcmp(argv[i], "-quiet")) ||
+                (!strcmp(argv[i], "--quiet")))
+           quiet++;
        else if ((!strcmp(argv[i], "-timing")) ||
                 (!strcmp(argv[i], "--timing")))
            timing++;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]