From 2c177b30e3756711cacecc2f4f759919920b841b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 4 Mar 2021 22:07:46 +0100 Subject: [PATCH] format-table: teach table_hide_column_from_display() to accept multiple arguments In case we want to hide multiple columns in one go, make that easy. --- src/shared/format-table.c | 25 ++++++++++++++++++++----- src/shared/format-table.h | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/shared/format-table.c b/src/shared/format-table.c index f324962b9cd..1c28fa73fa7 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1162,11 +1162,11 @@ int table_set_sort_internal(Table *t, size_t first_column, ...) { return 0; } -int table_hide_column_from_display(Table *t, size_t column) { +int table_hide_column_from_display_internal(Table *t, ...) { + size_t cur = 0; int r; assert(t); - assert(column < t->n_columns); /* If the display map is empty, initialize it with all available columns */ if (!t->display_map) { @@ -1175,10 +1175,25 @@ int table_hide_column_from_display(Table *t, size_t column) { return r; } - size_t allocated = t->n_display_map, cur = 0; + for (size_t i = 0; i < t->n_display_map; i++) { + bool listed = false; + va_list ap; + + va_start(ap, t); + for (;;) { + size_t column; + + column = va_arg(ap, size_t); + if (column == SIZE_MAX) + break; + if (column == t->display_map[i]) { + listed = true; + break; + } + } + va_end(ap); - for (size_t i = 0; i < allocated; i++) { - if (t->display_map[i] == column) + if (listed) continue; t->display_map[cur++] = t->display_map[i]; diff --git a/src/shared/format-table.h b/src/shared/format-table.h index e31c71f7927..087daf34859 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -107,7 +107,8 @@ int table_set_display_internal(Table *t, size_t first_column, ...); int table_set_sort_internal(Table *t, size_t first_column, ...); #define table_set_sort(...) table_set_sort_internal(__VA_ARGS__, SIZE_MAX) int table_set_reverse(Table *t, size_t column, bool b); -int table_hide_column_from_display(Table *t, size_t column); +int table_hide_column_from_display_internal(Table *t, ...); +#define table_hide_column_from_display(t, ...) table_hide_column_from_display_internal(t, __VA_ARGS__, (size_t) -1) int table_print(Table *t, FILE *f); int table_format(Table *t, char **ret); -- 2.47.3