Implement xml export / import #3

Merged
mhu merged 20 commits from xml-export into master 2023-01-06 18:50:08 +01:00
5 changed files with 30 additions and 2 deletions
Showing only changes of commit b3827b25c6 - Show all commits

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); 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_ */ #endif /* _ELFPATCHCRC_XML_H_ */

View File

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

View File

@ -64,3 +64,4 @@
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:schema> </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_LIST (4)
#define ARG_KEY_EXPORT (5) #define ARG_KEY_EXPORT (5)
#define ARG_KEY_IMPORT (6) #define ARG_KEY_IMPORT (6)
#define ARG_KEY_XSD (7)
struct command_line_options { struct command_line_options {
bool little_endian; bool little_endian;
bool dry_run; bool dry_run;
bool verbose; bool verbose;
bool print_xsd;
enum granularity granularity; enum granularity granularity;
enum crc_format format; enum crc_format format;
struct crc_settings crc; 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: case ARG_KEY_LIST:
args->list = true; args->list = true;
break; break;
case ARG_KEY_XSD:
args->print_xsd = true;
break;
case 'p': case 'p':
/* Polyniomial */ /* Polyniomial */
args->crc.polynomial = strtoull(arg, &endptr, 0); 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}, {"list-crcs", ARG_KEY_LIST, 0, 0, "List predefined CRCs", 0},
{"export", ARG_KEY_EXPORT, "XML", 0, "Export CRCs to XML file", 3}, {"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}, {"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 */ /* Sentinel */
{NULL, 0, 0, 0, NULL, 0} {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->little_endian = false;
opts->verbose = false; opts->verbose = false;
opts->print_xsd = false;
opts->granularity = GRANULARITY_BYTE; opts->granularity = GRANULARITY_BYTE;
opts->dry_run = false; opts->dry_run = false;
opts->crc.xor = 0UL; opts->crc.xor = 0UL;
@ -393,6 +400,10 @@ int main(int argc, char **argv)
prepare_default_opts(&cmd_opts); prepare_default_opts(&cmd_opts);
parse_cmdline_options(&argc, &argv, &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) if (cmd_opts.verbose || cmd_opts.dry_run)
reporting_enable_verbose(); reporting_enable_verbose();

View File

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