1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 07:51:21 +03:00

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.
This commit is contained in:
Lennart Poettering 2021-03-04 22:07:46 +01:00
parent 21fbf095b8
commit 2c177b30e3
2 changed files with 22 additions and 6 deletions

View File

@ -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;
for (size_t i = 0; i < allocated; i++) {
if (t->display_map[i] == column)
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);
if (listed)
continue;
t->display_map[cur++] = t->display_map[i];

View File

@ -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);