Skip to content

Commit

Permalink
s1kd-validate: 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 f1781c3 commit 3a26538
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
7 changes: 6 additions & 1 deletion tools/s1kd-validate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ s1kd-validate - Validate S1000D CSDB objects against their schemas

# SYNOPSIS

s1kd-validate [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv^h?]
s1kd-validate [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv8^h?]
[<object>...]

# DESCRIPTION
Expand Down Expand Up @@ -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.

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="02" subSystemCode="0" subSubSystemCode="0" assyCode="00" disassyCode="00" disassyCodeVariant="A" infoCode="040" infoCodeVariant="A" itemLocationCode="D"/>
<language languageIsoCode="en" countryIsoCode="CA"/>
<issueInfo issueNumber="027" inWork="01"/>
<issueInfo issueNumber="027" inWork="02"/>
</dmIdent>
<dmAddressItems>
<issueDate year="2024" month="12" day="18"/>
<issueDate year="2024" month="12" day="27"/>
<dmTitle>
<techName>s1kd-validate(1) | s1kd-tools</techName>
</dmTitle>
Expand Down Expand Up @@ -47,6 +47,9 @@
<reasonForUpdate id="rfu-summary" updateHighlight="1" updateReasonType="urt02">
<simplePara>Add -T (--summary) option.</simplePara>
</reasonForUpdate>
<reasonForUpdate id="rfu-deep-copy" updateHighlight="1" updateReasonType="urt02">
<simplePara>Add -8 (--deep-copy-nodes) option.</simplePara>
</reasonForUpdate>
</dmStatus>
</identAndStatusSection>
<content>
Expand All @@ -58,7 +61,7 @@
<levelledPara>
<title>SYNOPSIS</title>
<para>
<verbatimText verbatimStyle="vs24" changeMark="1" changeType="modify" reasonForUpdateRefIds="rfu-xml-report rfu-change-exclude rfu-summary"><![CDATA[s1kd-validate [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv^h?]
<verbatimText verbatimStyle="vs24" changeMark="1" changeType="modify" reasonForUpdateRefIds="rfu-xml-report rfu-change-exclude rfu-summary rfu-deep-copy"><![CDATA[s1kd-validate [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv8^h?]
[<object>...]]]></verbatimText>
</para>
</levelledPara>
Expand Down Expand Up @@ -142,6 +145,12 @@
<para>Output an XML report.</para>
</listItemDefinition>
</definitionListItem>
<definitionListItem changeMark="1" changeType="add" reasonForUpdateRefIds="rfu-deep-copy">
<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-validate/doc/s1kd-validate.1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +9,7 @@ s1kd\-validate \- Validate S1000D CSDB objects against their schemas
.IP
.nf
\f[C]
s1kd\-validate\ [\-s\ <path>]\ [\-X\ <URI>]\ [\-F|\-f]\ [\-o|\-x]\ [\-elqTv^h?]
s1kd\-validate\ [\-s\ <path>]\ [\-X\ <URI>]\ [\-F|\-f]\ [\-o|\-x]\ [\-elqTv8^h?]
\ \ \ \ \ \ \ \ \ \ \ \ \ \ [<object>...]
\f[]
.fi
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions tools/s1kd-validate/s1kd-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand Down Expand Up @@ -191,7 +193,7 @@ static struct s1kd_schema_parser *add_schema_parser(char *url)

static void show_help(void)
{
puts("Usage: " PROG_NAME " [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv^h?] [<object>...]");
puts("Usage: " PROG_NAME " [-s <path>] [-X <URI>] [-F|-f] [-o|-x] [-elqTv8^h?] [<object>...]");
puts("");
puts("Options:");
puts(" -e, --ignore-empty Ignore empty/non-XML documents.");
Expand All @@ -206,6 +208,7 @@ static void show_help(void)
puts(" -v, --verbose Verbose output.");
puts(" -X, --exclude <URI> 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(" <object> Any number of CSDB objects to validate.");
Expand Down Expand Up @@ -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'},
Expand All @@ -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}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a26538

Please sign in to comment.