di-edid-decode: add optional arg to specify input filename

This makes it easier to e.g. run the tool inside gdb, and is
consistent with upstream edid-decode.

Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
Simon Ser 2022-06-10 15:02:16 +02:00 committed by Pekka Paalanen
parent 0b6970ed70
commit c14569af01

View file

@ -127,8 +127,9 @@ edid_checksum_index(size_t block_index)
}
int
main(void)
main(int argc, char *argv[])
{
FILE *in;
static uint8_t raw[32 * 1024];
size_t size = 0;
const struct di_edid *edid;
@ -144,9 +145,18 @@ main(void)
const struct di_edid_ext *const *exts;
size_t i;
while (!feof(stdin)) {
size += fread(&raw[size], 1, sizeof(raw) - size, stdin);
if (ferror(stdin)) {
in = stdin;
if (argc > 1) {
in = fopen(argv[1], "r");
if (!in) {
perror("failed to open input file");
return 1;
}
}
while (!feof(in)) {
size += fread(&raw[size], 1, sizeof(raw) - size, in);
if (ferror(in)) {
perror("fread failed");
return 1;
} else if (size >= sizeof(raw)) {
@ -155,6 +165,8 @@ main(void)
}
}
fclose(in);
info = di_info_parse_edid(raw, size);
if (!info) {
perror("di_edid_parse failed");