From 26aeb38bd9e62f012ed47fd2611548eae2599109 Mon Sep 17 00:00:00 2001 From: kibook Date: Fri, 27 Dec 2024 14:55:01 -0500 Subject: [PATCH] s1kd-brexcheck: 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-brexcheck/README.md | 7 ++++++- ...MC-S1KDTOOLS-A-04-00-00-00A-040A-D_EN-CA.XML | 17 +++++++++++++---- tools/s1kd-brexcheck/doc/s1kd-brexcheck.1 | 11 +++++++++-- tools/s1kd-brexcheck/s1kd-brexcheck.c | 14 ++++++++++---- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/tools/s1kd-brexcheck/README.md b/tools/s1kd-brexcheck/README.md index 489e69a2..ef824e72 100644 --- a/tools/s1kd-brexcheck/README.md +++ b/tools/s1kd-brexcheck/README.md @@ -5,7 +5,7 @@ s1kd-brexcheck - Validate S1000D CSDB objects against BREX data modules # SYNOPSIS s1kd-brexcheck [-b ] [-d ] [-I ] [-w ] - [-X ] [-F|-f] [-BceLlNnopqrS[tu]sTvx^h?] + [-X ] [-F|-f] [-BceLlNnopqrS[tu]sTvx8^h?] [...] # DESCRIPTION @@ -119,6 +119,11 @@ invalid XML tree. - \-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 Check the CSDB objects with elements that have a change type of "delete" removed. diff --git a/tools/s1kd-brexcheck/doc/DMC-S1KDTOOLS-A-04-00-00-00A-040A-D_EN-CA.XML b/tools/s1kd-brexcheck/doc/DMC-S1KDTOOLS-A-04-00-00-00A-040A-D_EN-CA.XML index 7e50ae0d..76c110f6 100644 --- a/tools/s1kd-brexcheck/doc/DMC-S1KDTOOLS-A-04-00-00-00A-040A-D_EN-CA.XML +++ b/tools/s1kd-brexcheck/doc/DMC-S1KDTOOLS-A-04-00-00-00A-040A-D_EN-CA.XML @@ -6,10 +6,10 @@ - + - + s1kd-brexcheck(1) | s1kd-tools @@ -41,6 +41,9 @@ Add --zenity-progress option. + + Add -8 (--deep-copy-nodes) option. + @@ -52,8 +55,8 @@ SYNOPSIS - ] [-d ] [-I ] [-w ] - [-X ] [-F|-f] [-BceLlNnopqrS[tu]sTvx^h?] + ] [-d ] [-I ] [-w ] + [-X ] [-F|-f] [-BceLlNnopqrS[tu]sTvx8^h?] [...]]]> @@ -216,6 +219,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-brexcheck/doc/s1kd-brexcheck.1 b/tools/s1kd-brexcheck/doc/s1kd-brexcheck.1 index e4934a70..b4469a39 100644 --- a/tools/s1kd-brexcheck/doc/s1kd-brexcheck.1 +++ b/tools/s1kd-brexcheck/doc/s1kd-brexcheck.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 2.0.6 .\" -.TH "s1kd\-brexcheck" "1" "2024\-03\-21" "" "s1kd\-tools" +.TH "s1kd\-brexcheck" "1" "2024\-12\-27" "" "s1kd\-tools" .hy .SH NAME .PP @@ -11,7 +11,7 @@ modules .nf \f[C] s1kd\-brexcheck\ [\-b\ ]\ [\-d\ ]\ [\-I\ ]\ [\-w\ ] -\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [\-X\ ]\ [\-F|\-f]\ [\-BceLlNnopqrS[tu]sTvx^h?] +\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [\-X\ ]\ [\-F|\-f]\ [\-BceLlNnopqrS[tu]sTvx8^h?] \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [...] \f[] .fi @@ -176,6 +176,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 Check the CSDB objects with elements that have a change type of "delete" removed. diff --git a/tools/s1kd-brexcheck/s1kd-brexcheck.c b/tools/s1kd-brexcheck/s1kd-brexcheck.c index 3f74dc64..b447411c 100644 --- a/tools/s1kd-brexcheck/s1kd-brexcheck.c +++ b/tools/s1kd-brexcheck/s1kd-brexcheck.c @@ -37,7 +37,7 @@ #define PROGRESS_ZENITY 2 #define PROG_NAME "s1kd-brexcheck" -#define VERSION "5.0.1" +#define VERSION "5.1.0" #define STRUCT_OBJ_RULE_PATH BAD_CAST \ "//contextRules[not(@rulesContext) or @rulesContext=$schema]//structureObjectRule|" \ @@ -114,6 +114,9 @@ static bool ignore_empty = false; /* Remove elements marked as "delete" before check. */ static bool rem_delete = false; +/* Whether to do a deep copy of invalid nodes for the XML report. */ +static bool deep_copy_nodes = false; + /* Version of XPath to use. */ enum xpath_version { DYNAMIC, XPATH_1, XPATH_2 }; @@ -326,7 +329,7 @@ static void dump_nodes_xml(xmlNodeSetPtr nodes, const char *fname, xmlNodePtr br if (node->type == XML_ATTRIBUTE_NODE) node = node->parent; - xmlAddChild(object, xmlCopyNode(node, 2)); + xmlAddChild(object, xmlCopyNode(node, deep_copy_nodes ? 1 : 2)); } } @@ -1867,7 +1870,7 @@ int s1kdCheckBREX(const char *object_xml, int object_size, const char *brex_xml, /* Show usage message. */ static void show_help(void) { - puts("Usage: " PROG_NAME " [-b ] [-d ] [-I ] [-w ] [-X ] [-F|-f] [-BceLlNnopqrS[tu]sTvx^h?] [...]"); + puts("Usage: " PROG_NAME " [-b ] [-d ] [-I ] [-w ] [-X ] [-F|-f] [-BceLlNnopqrS[tu]sTvx8^h?] [...]"); puts(""); puts("Options:"); puts(" -B, --default-brex Use the default BREX."); @@ -1894,6 +1897,7 @@ static void show_help(void) puts(" -w, --severity-levels List of severity levels."); puts(" -X, --xpath-version Force the version of XPath that will be used."); puts(" -x, --xml XML output."); + puts(" -8, --deep-copy-nodes The XML report will contain a deep copy of invalid nodes."); puts(" -^, --remove-deleted Check with elements marked as \"delete\" removed."); puts(" --version Show version information."); puts(" --zenity-progress Prints progress information in the zenity --progress format."); @@ -1959,7 +1963,7 @@ int main(int argc, char *argv[]) /* xpath_version */ DYNAMIC }; - const char *sopts = "Bb:eI:xvqslw:StupFfNncLTrd:oX:^h?"; + const char *sopts = "Bb:eI:xvqslw:StupFfNncLTrd:oX:8^h?"; struct option lopts[] = { {"version" , no_argument , 0, 0}, {"help" , no_argument , 0, 'h'}, @@ -1988,6 +1992,7 @@ int main(int argc, char *argv[]) {"recursive" , no_argument , 0, 'r'}, {"output-valid" , no_argument , 0, 'o'}, {"xpath-version" , required_argument, 0, 'X'}, + {"deep-copy-nodes", no_argument , 0, '8'}, {"remove-deleted" , no_argument , 0, '^'}, {"zenity-progress", no_argument , 0, 0}, LIBXML2_PARSE_LONGOPT_DEFS @@ -2036,6 +2041,7 @@ int main(int argc, char *argv[]) case 'I': add_path(&brex_search_paths, &num_brex_search_paths, &BREX_PATH_MAX, optarg, &opts); break; + case '8': deep_copy_nodes = true; case 'x': xmlout = true; break; case 'q': opts.verbosity = SILENT; break; case 'v': opts.verbosity = VERBOSE; break;