From 3a265388f9599c00f6e4b5f83e8637462a5a2461 Mon Sep 17 00:00:00 2001 From: kibook Date: Fri, 27 Dec 2024 14:45:13 -0500 Subject: [PATCH] s1kd-validate: Add -8 (--deep-copy-nodes) option. Added a -8 (--deep-copy-nodes) option will causes the XML report (-x) to contain a deep copy of invalid nodes, including all descendant nodes, instead of a shallow copy with only the node and its attributes. --- tools/s1kd-validate/README.md | 7 ++++++- .../DMC-S1KDTOOLS-A-02-00-00-00A-040A-D_EN-CA.XML | 15 ++++++++++++--- tools/s1kd-validate/doc/s1kd-validate.1 | 11 +++++++++-- tools/s1kd-validate/s1kd-validate.c | 13 +++++++++---- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/tools/s1kd-validate/README.md b/tools/s1kd-validate/README.md index 90c4fe01..333e8cab 100644 --- a/tools/s1kd-validate/README.md +++ b/tools/s1kd-validate/README.md @@ -4,7 +4,7 @@ s1kd-validate - Validate S1000D CSDB objects against their schemas # SYNOPSIS - s1kd-validate [-s ] [-X ] [-F|-f] [-o|-x] [-elqTv^h?] + s1kd-validate [-s ] [-X ] [-F|-f] [-o|-x] [-elqTv8^h?] [...] # DESCRIPTION @@ -57,6 +57,11 @@ schemas. - \-x, --xml Output an XML report. + - \-8, --deep-copy-nodes + Include a deep copy of invalid nodes on the XML report (-x). By + default, only a shallow copy of the node is included (the node and + its attributes but no children). + - \-^, --remove-deleted Validate with elements that have a change type of "delete" removed. diff --git a/tools/s1kd-validate/doc/DMC-S1KDTOOLS-A-02-00-00-00A-040A-D_EN-CA.XML b/tools/s1kd-validate/doc/DMC-S1KDTOOLS-A-02-00-00-00A-040A-D_EN-CA.XML index bd57a4c8..d82ac2bb 100644 --- a/tools/s1kd-validate/doc/DMC-S1KDTOOLS-A-02-00-00-00A-040A-D_EN-CA.XML +++ b/tools/s1kd-validate/doc/DMC-S1KDTOOLS-A-02-00-00-00A-040A-D_EN-CA.XML @@ -6,10 +6,10 @@ - + - + s1kd-validate(1) | s1kd-tools @@ -47,6 +47,9 @@ Add -T (--summary) option. + + Add -8 (--deep-copy-nodes) option. + @@ -58,7 +61,7 @@ SYNOPSIS - ] [-X ] [-F|-f] [-o|-x] [-elqTv^h?] + ] [-X ] [-F|-f] [-o|-x] [-elqTv8^h?] [...]]]> @@ -142,6 +145,12 @@ Output an XML report. + + -8, --deep-copy-nodes + + Include a deep copy of invalid nodes on the XML report (-x). By default, only a shallow copy of the node is included (the node and its attributes but no children). + + -^, --remove-deleted diff --git a/tools/s1kd-validate/doc/s1kd-validate.1 b/tools/s1kd-validate/doc/s1kd-validate.1 index 47ac81d0..6eb92391 100644 --- a/tools/s1kd-validate/doc/s1kd-validate.1 +++ b/tools/s1kd-validate/doc/s1kd-validate.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 2.0.6 .\" -.TH "s1kd\-validate" "1" "2024\-12\-18" "" "s1kd\-tools" +.TH "s1kd\-validate" "1" "2024\-12\-27" "" "s1kd\-tools" .hy .SH NAME .PP @@ -9,7 +9,7 @@ s1kd\-validate \- Validate S1000D CSDB objects against their schemas .IP .nf \f[C] -s1kd\-validate\ [\-s\ ]\ [\-X\ ]\ [\-F|\-f]\ [\-o|\-x]\ [\-elqTv^h?] +s1kd\-validate\ [\-s\ ]\ [\-X\ ]\ [\-F|\-f]\ [\-o|\-x]\ [\-elqTv8^h?] \ \ \ \ \ \ \ \ \ \ \ \ \ \ [...] \f[] .fi @@ -87,6 +87,13 @@ Output an XML report. .RS .RE .TP +.B \-8, \-\-deep\-copy\-nodes +Include a deep copy of invalid nodes on the XML report (\-x). +By default, only a shallow copy of the node is included (the node and +its attributes but no children). +.RS +.RE +.TP .B \-^, \-\-remove\-deleted Validate with elements that have a change type of "delete" removed. .RS diff --git a/tools/s1kd-validate/s1kd-validate.c b/tools/s1kd-validate/s1kd-validate.c index 0d16bcbc..722c5664 100644 --- a/tools/s1kd-validate/s1kd-validate.c +++ b/tools/s1kd-validate/s1kd-validate.c @@ -9,7 +9,7 @@ #include "stats.h" #define PROG_NAME "s1kd-validate" -#define VERSION "4.2.0" +#define VERSION "4.3.0" #define ERR_PREFIX PROG_NAME ": ERROR: " #define SUCCESS_PREFIX PROG_NAME ": SUCCESS: " @@ -86,6 +86,8 @@ static int schema_parser_count = 0; /* Root element of the XML report. */ static xmlDocPtr xml_report_doc = NULL; +static int deep_copy_nodes = 0; + /* Add an error to the XML report. */ static void add_xml_report_error(const xmlNodePtr report_node, const xmlNodePtr node, const long lineno, const char *message) { @@ -106,7 +108,7 @@ static void add_xml_report_error(const xmlNodePtr report_node, const xmlNodePtr xpath = xpath_of(node); xmlSetProp(object, BAD_CAST "xpath", xpath); - xmlAddChild(object, xmlCopyNode(node, 2)); + xmlAddChild(object, xmlCopyNode(node, deep_copy_nodes ? 1 : 2)); xmlFree(xpath); } @@ -191,7 +193,7 @@ static struct s1kd_schema_parser *add_schema_parser(char *url) static void show_help(void) { - puts("Usage: " PROG_NAME " [-s ] [-X ] [-F|-f] [-o|-x] [-elqTv^h?] [...]"); + puts("Usage: " PROG_NAME " [-s ] [-X ] [-F|-f] [-o|-x] [-elqTv8^h?] [...]"); puts(""); puts("Options:"); puts(" -e, --ignore-empty Ignore empty/non-XML documents."); @@ -206,6 +208,7 @@ static void show_help(void) puts(" -v, --verbose Verbose output."); puts(" -X, --exclude Exclude namespace from validation by URI."); puts(" -x, --xml Output an XML report."); + puts(" -8, --deep-copy-nodes The XML report will include a deep copy of invalid nodes."); puts(" -^, --remove-deleted Validate with elements marked as \"delete\" removed."); puts(" --version Show version information."); puts(" Any number of CSDB objects to validate."); @@ -519,7 +522,7 @@ int main(int argc, char *argv[]) xmlNodePtr ignore_ns; - const char *sopts = "vqX:xFfloes:T^h?"; + const char *sopts = "vqX:xFfloes:T8^h?"; struct option lopts[] = { {"version" , no_argument , 0, 0}, {"help" , no_argument , 0, 'h'}, @@ -534,6 +537,7 @@ int main(int argc, char *argv[]) {"schema" , required_argument, 0, 's'}, {"summary" , no_argument , 0, 'T'}, {"xml" , no_argument , 0, 'x'}, + {"deep-copy-nodes", no_argument , 0, '8'}, {"remove-deleted" , no_argument , 0, '^'}, LIBXML2_PARSE_LONGOPT_DEFS {0, 0, 0, 0} @@ -564,6 +568,7 @@ int main(int argc, char *argv[]) case 's': schema = strdup(optarg); break; case '^': rem_del = 1; break; case 'T': show_stats = 1; break; + case '8': deep_copy_nodes = 1; case 'x': xml = 1; break; case 'h': case '?': show_help(); return EXIT_SUCCESS;