Add --xsd option to print out the used XSD

This commit is contained in:
Mario Hüttel 2023-01-04 14:47:19 +01:00
parent 3bd46d888d
commit b3827b25c6
5 changed files with 30 additions and 2 deletions

View File

@ -37,4 +37,9 @@ struct xml_crc_import *xml_import_from_file(const char *path);
*/
void xml_crc_import_free(struct xml_crc_import *data);
/**
* @brief Print XML XSD file to stdout
*/
void xml_print_xsd(void);
#endif /* _ELFPATCHCRC_XML_H_ */

View File

@ -8,7 +8,7 @@
# SYNOPSYS
**patchelfcrc** [**-lrv?V**] [**-g** *GRANULARITY*] [**-p** *POLYNOMIAL*] [**-s** *STARTVALUE*]
[**-x** *XORVAL*] [**-F** *FORMAT*] [**-O** *OUTPUTSECTION*] [**-S** *SEC*]
[**\--granularity**=*GRANULARITY*] [**\--little-endian**] [**\--dry-run**]
[**\--granularity**=*GRANULARITY*] [**\--little-endian**] [**\--dry-run**] [**\--xsd**]
[**\--poly**=*POLYNOMIAL*] [**\--reversed**] [**\--start-value**=*STARTVALUE*]
[**--verbose**] [**\--xor-out**=*XORVAL*] [**\--end-magic**=*MAGIC*]
[**\--crc-format**=*FORMAT*] [**\--list-crcs**] [**\--output-section**=*OUTPUTSECTION*]
@ -65,6 +65,12 @@
**-V**, **\--version**
: Print version number
**\--list-crcs**
: List the possible predefined CRCs
**\--xsd**
: Print the XSD file used to validate the XML import to stdout
**--usage**
: Print usage hints on command line options.

View File

@ -64,3 +64,4 @@
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -38,11 +38,13 @@ const char *argp_program_bug_address = "<mario [dot] huettel [at] linux [dot] co
#define ARG_KEY_LIST (4)
#define ARG_KEY_EXPORT (5)
#define ARG_KEY_IMPORT (6)
#define ARG_KEY_XSD (7)
struct command_line_options {
bool little_endian;
bool dry_run;
bool verbose;
bool print_xsd;
enum granularity granularity;
enum crc_format format;
struct crc_settings crc;
@ -94,6 +96,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case ARG_KEY_LIST:
args->list = true;
break;
case ARG_KEY_XSD:
args->print_xsd = true;
break;
case 'p':
/* Polyniomial */
args->crc.polynomial = strtoull(arg, &endptr, 0);
@ -183,6 +188,7 @@ static int parse_cmdline_options(int *argc, char ***argv, struct command_line_op
{"list-crcs", ARG_KEY_LIST, 0, 0, "List predefined CRCs", 0},
{"export", ARG_KEY_EXPORT, "XML", 0, "Export CRCs to XML file", 3},
{"import", ARG_KEY_IMPORT, "XML", 0, "Do not caclulate CRCs but import them from file", 3},
{"xsd", ARG_KEY_XSD, 0, 0, "Print XSD to stdout", 0},
/* Sentinel */
{NULL, 0, 0, 0, NULL, 0}
};
@ -204,6 +210,7 @@ static void prepare_default_opts(struct command_line_options *opts)
{
opts->little_endian = false;
opts->verbose = false;
opts->print_xsd = false;
opts->granularity = GRANULARITY_BYTE;
opts->dry_run = false;
opts->crc.xor = 0UL;
@ -393,6 +400,10 @@ int main(int argc, char **argv)
prepare_default_opts(&cmd_opts);
parse_cmdline_options(&argc, &argv, &cmd_opts);
if (cmd_opts.print_xsd) {
xml_print_xsd();
goto free_cmds;
}
if (cmd_opts.verbose || cmd_opts.dry_run)
reporting_enable_verbose();

View File

@ -230,3 +230,8 @@ void xml_crc_import_free(struct xml_crc_import *data)
data->xml_crc_entries = NULL;
free(data);
}
void xml_print_xsd(void)
{
printf("%.*s", schema_xsd_len, schema_xsd);
}