format-table: add new uint32_t hex field type

This commit is contained in:
Lennart Poettering
2023-07-07 17:26:33 +02:00
committed by Luca Boccassi
parent 055ca3cd0a
commit f4ae435bec
2 changed files with 17 additions and 0 deletions

View File

@@ -318,6 +318,7 @@ static size_t table_data_size(TableDataType type, const void *data) {
case TABLE_INT32:
case TABLE_UINT32:
case TABLE_UINT32_HEX:
return sizeof(uint32_t);
case TABLE_INT16:
@@ -981,6 +982,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
}
case TABLE_UINT32:
case TABLE_UINT32_HEX:
buffer.uint32 = va_arg(ap, uint32_t);
data = &buffer.uint32;
break;
@@ -1365,6 +1367,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
return CMP(a->uint16, b->uint16);
case TABLE_UINT32:
case TABLE_UINT32_HEX:
return CMP(a->uint32, b->uint32);
case TABLE_UINT64:
@@ -1756,6 +1759,18 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
break;
}
case TABLE_UINT32_HEX: {
_cleanup_free_ char *p = NULL;
p = new(char, 8 + 1);
if (!p)
return NULL;
sprintf(p, "%" PRIx32, d->uint32);
d->formatted = TAKE_PTR(p);
break;
}
case TABLE_UINT64: {
_cleanup_free_ char *p = NULL;
@@ -2689,6 +2704,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
return json_variant_new_unsigned(ret, d->uint16);
case TABLE_UINT32:
case TABLE_UINT32_HEX:
return json_variant_new_unsigned(ret, d->uint32);
case TABLE_UINT64:

View File

@@ -40,6 +40,7 @@ typedef enum TableDataType {
TABLE_UINT8,
TABLE_UINT16,
TABLE_UINT32,
TABLE_UINT32_HEX,
TABLE_UINT64,
TABLE_UINT64_HEX,
TABLE_PERCENT,