Re: [PATCH v2 2/2] hexdump: Allow skipping identical lines

From: Miquel Raynal
Date: Mon Jan 20 2025 - 04:31:06 EST


Hello David & Petr,

On 17/01/2025 at 19:25:22 GMT, David Laight <david.laight.linux@xxxxxxxxx> wrote:

> On Fri, 17 Jan 2025 17:27:26 +0100
> Petr Mladek <pmladek@xxxxxxxx> wrote:
>
> ...
>> IMHO, it is perfectly fine to add support for skipping identical lines
>> only to print_hex_dump(). And I would go even further and replace
>>
>> void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
>> int rowsize, int groupsize,
>> const void *buf, size_t len, bool ascii)
>>
>> with
>>
>> void print_hex_dump(const char *level, const char *prefix_str,
>> enum hex_dump_type,
>> int rowsize, int groupsize,
>> const void *buf, size_t len)
>>
>> and combine all the flags into the one enum:
>>
>> enum hex_dump_type {
>> DUMP_HEX_ONLY = 0,
>> DUMP_HEX_AND_ASCII = BIT(1),
>> DUMP_PREFIX_ADDRESS = BIT(2),
>> DUMP_PREFIX_OFFSET = BIT(3),
>> DUMP_SKIP_IDENTICAL_LINES = BIT(4),
>> };

Would a single enum (in the prototype of the function) work? I like the
idea but we need some kind of OR combination to be supported, typically:

DUMP_HEX_AND_ASCII | DUMP_PREFIX_OFFSET | DUMP_SKIP_IDENTICAL_LINES

Maybe something like:

void print_hex(const char *level, const char *prefix_str,
int rowsize, int groupsize,
const void *buf, size_t len,
unsigned int dump_flags) // flags instead of enum?

enum hex_dump_flags {
// I'm not sure what to do with the default value?
DUMP_ASCII = BIT(0), // renamed?
DUMP_PREFIX_ADDRESS = BIT(1),
DUMP_PREFIX_OFFSET = BIT(2),
DUMP_SKIP_IDENTICAL_LINES = BIT(3),
};

>> How does that sound, please?
>
> Rename it as (say) print_hex() and add wrappers for the existing callers?

That would avoid the treewide changes, so yes I can try that, definitely.

Thanks,
Miquèl