Skip to content

Commit

Permalink
s1kd-brexcheck: Add -8 (--deep-copy-nodes) option.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kibook committed Dec 27, 2024
1 parent 3a26538 commit 26aeb38
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
7 changes: 6 additions & 1 deletion tools/s1kd-brexcheck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ s1kd-brexcheck - Validate S1000D CSDB objects against BREX data modules
# SYNOPSIS

s1kd-brexcheck [-b <brex>] [-d <dir>] [-I <path>] [-w <severities>]
[-X <version>] [-F|-f] [-BceLlNnopqrS[tu]sTvx^h?]
[-X <version>] [-F|-f] [-BceLlNnopqrS[tu]sTvx8^h?]
[<object>...]

# DESCRIPTION
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<dmIdent>
<dmCode modelIdentCode="S1KDTOOLS" systemDiffCode="A" systemCode="04" subSystemCode="0" subSubSystemCode="0" assyCode="00" disassyCode="00" disassyCodeVariant="A" infoCode="040" infoCodeVariant="A" itemLocationCode="D"/>
<language languageIsoCode="en" countryIsoCode="CA"/>
<issueInfo issueNumber="040" inWork="01"/>
<issueInfo issueNumber="040" inWork="02"/>
</dmIdent>
<dmAddressItems>
<issueDate year="2024" month="03" day="21"/>
<issueDate year="2024" month="12" day="27"/>
<dmTitle>
<techName>s1kd-brexcheck(1) | s1kd-tools</techName>
</dmTitle>
Expand Down Expand Up @@ -41,6 +41,9 @@
<reasonForUpdate id="rfu-0001" updateHighlight="1">
<simplePara>Add --zenity-progress option.</simplePara>
</reasonForUpdate>
<reasonForUpdate id="rfu-0002" updateHighlight="1">
<simplePara>Add -8 (--deep-copy-nodes) option.</simplePara>
</reasonForUpdate>
</dmStatus>
</identAndStatusSection>
<content>
Expand All @@ -52,8 +55,8 @@
<levelledPara>
<title>SYNOPSIS</title>
<para>
<verbatimText verbatimStyle="vs24"><![CDATA[s1kd-brexcheck [-b <brex>] [-d <dir>] [-I <path>] [-w <severities>]
[-X <version>] [-F|-f] [-BceLlNnopqrS[tu]sTvx^h?]
<verbatimText verbatimStyle="vs24" changeMark="1" changeType="modify" reasonForUpdateRefIds="rfu-0002"><![CDATA[s1kd-brexcheck [-b <brex>] [-d <dir>] [-I <path>] [-w <severities>]
[-X <version>] [-F|-f] [-BceLlNnopqrS[tu]sTvx8^h?]
[<object>...]]]></verbatimText>
</para>
</levelledPara>
Expand Down Expand Up @@ -216,6 +219,12 @@
<para>Output an XML report.</para>
</listItemDefinition>
</definitionListItem>
<definitionListItem changeMark="1" changeType="add" reasonForUpdateRefIds="rfu-0002">
<listItemTerm>-8, --deep-copy-nodes</listItemTerm>
<listItemDefinition>
<para>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).</para>
</listItemDefinition>
</definitionListItem>
<definitionListItem>
<listItemTerm>-^, --remove-deleted</listItemTerm>
<listItemDefinition>
Expand Down
11 changes: 9 additions & 2 deletions tools/s1kd-brexcheck/doc/s1kd-brexcheck.1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,7 +11,7 @@ modules
.nf
\f[C]
s1kd\-brexcheck\ [\-b\ <brex>]\ [\-d\ <dir>]\ [\-I\ <path>]\ [\-w\ <severities>]
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [\-X\ <version>]\ [\-F|\-f]\ [\-BceLlNnopqrS[tu]sTvx^h?]
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [\-X\ <version>]\ [\-F|\-f]\ [\-BceLlNnopqrS[tu]sTvx8^h?]
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [<object>...]
\f[]
.fi
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions tools/s1kd-brexcheck/s1kd-brexcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -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|" \
Expand Down Expand Up @@ -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 };

Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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 <brex>] [-d <dir>] [-I <path>] [-w <file>] [-X <version>] [-F|-f] [-BceLlNnopqrS[tu]sTvx^h?] [<object>...]");
puts("Usage: " PROG_NAME " [-b <brex>] [-d <dir>] [-I <path>] [-w <file>] [-X <version>] [-F|-f] [-BceLlNnopqrS[tu]sTvx8^h?] [<object>...]");
puts("");
puts("Options:");
puts(" -B, --default-brex Use the default BREX.");
Expand All @@ -1894,6 +1897,7 @@ static void show_help(void)
puts(" -w, --severity-levels <file> List of severity levels.");
puts(" -X, --xpath-version <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.");
Expand Down Expand Up @@ -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'},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 26aeb38

Please sign in to comment.