From 3ae22b7c965f93a061f013ba106b0f498f09fe3b Mon Sep 17 00:00:00 2001 From: hhb Date: Tue, 2 Feb 2021 22:27:52 +0000 Subject: [PATCH] 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 f6a8e463..010bf38a 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; @@ -1659,7 +1660,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; @@ -1942,7 +1945,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 @@ -2834,7 +2839,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; @@ -2862,7 +2869,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; @@ -2887,7 +2896,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; @@ -3004,6 +3015,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"); @@ -3238,6 +3250,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++; -- GitLab