]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/table-format: generalize table_sync_column_width to more columns
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 25 Mar 2026 13:49:55 +0000 (14:49 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 26 Mar 2026 09:31:23 +0000 (10:31 +0100)
The column index is moved to the first position. I think we're unlikely
to want to synchronize widths of *different* columns, and having just
one column argument makes the callers simpler. Also, the type is changed
to size_t to match other functions, and this avoids the need to cast
to size_t in the callers.

src/bless-boot/bless-boot.c
src/dissect/dissect.c
src/id128/id128.c
src/shared/format-table.c
src/shared/format-table.h

index bf1c6e7a0cbc3514a4447f18cbb3692ec7679600..b82be92dbdf0526720ee26d97190fff84fb8f3db 100644 (file)
@@ -50,7 +50,7 @@ static int help(void) {
         if (r < 0)
                 return r;
 
-        (void) table_sync_column_width(options, 0, verbs, 0);
+        (void) table_sync_column_widths(0, options, verbs);
 
         printf("%s [OPTIONS...] COMMAND\n"
                "\n%sMark the boot process as good or bad.%s\n"
index 3597971af9b03631eedf88bfe986e057ac11f35c..bcfd7f5a816e12ccb4bcaf992e83c19d5d40eb4b 100644 (file)
@@ -141,7 +141,7 @@ static int help(void) {
                 return r;
 
         /* Make the 1st column same width in both tables */
-        (void) table_sync_column_width(options, 0, commands, 0);
+        (void) table_sync_column_widths(0, options, commands);
 
         printf("%1$s [OPTIONS...] IMAGE\n"
                "%1$s [OPTIONS...] --mount IMAGE PATH\n"
index 688504c71480e7d272eb4f056958ebf333a26ead..fe4d2f2283644c4126664ce397344846500c4655 100644 (file)
@@ -208,7 +208,7 @@ static int help(void) {
                 return r;
 
         /* Make the 1st column same width in both tables */
-        (void) table_sync_column_width(options, 0, verbs, 0);
+        (void) table_sync_column_widths(0, options, verbs);
 
         printf("%s [OPTIONS...] COMMAND\n\n"
                "%sGenerate and print 128-bit identifiers.%s\n"
index 279e7fda68e7f8da1e9304ebe7c0bd7f71f432f9..04552b5b567761e1992514a04be79ce6b2b45b9f 100644 (file)
@@ -2185,26 +2185,35 @@ int table_set_column_width(Table *t, size_t column, size_t width) {
         return r;
 }
 
-int table_sync_column_width(Table *a, size_t column_a, Table *b, size_t column_b) {
-        size_t w1, w2;
-        int r;
+int _table_sync_column_widths(size_t column, Table *a, ...) {
+        size_t max = 0;
+        va_list ap;
+        int r = 0;
 
         assert(a);
-        assert(b);
 
-        /* Make both tables have specified columns of same width */
+        /* Make the specified column have the same width in the tables. */
 
-        r = table_data_requested_width(a, column_a, &w1);
-        if (r < 0)
-                return log_error_errno(r, "Failed to query table column width: %m");
+        va_start(ap, a);
+        for (Table *t = a; t; t = va_arg(ap, Table*)) {
+                size_t w;
 
-        r = table_data_requested_width(b, column_b, &w2);
+                r = table_data_requested_width(t, column, &w);
+                if (r < 0)
+                        break;
+
+                max = MAX(max, w);
+        }
+        va_end(ap);
         if (r < 0)
                 return log_error_errno(r, "Failed to query table column width: %m");
 
         r = 0;
-        RET_GATHER(r, table_set_column_width(a, column_a, MAX(w1, w2)));
-        RET_GATHER(r, table_set_column_width(b, column_b, MAX(w1, w2)));
+        va_start(ap, a);
+        for (Table *t = a; t; t = va_arg(ap, Table*))
+                RET_GATHER(r, table_set_column_width(t, column, max));
+        va_end(ap);
+
         return r;
 }
 
index 9a11fb7c30cefd1416daaa2ade1bb0f72a3236ad..bb5a68b7e9fa35c90c60249c0a2c11b614b7369a 100644 (file)
@@ -144,7 +144,8 @@ int table_hide_column_from_display_internal(Table *t, ...);
 int table_data_requested_width(Table *table, size_t column, size_t *ret);
 
 int table_set_column_width(Table *t, size_t column, size_t width);
-int table_sync_column_width(Table *a, size_t column_a, Table *b, size_t column_b);
+int _table_sync_column_widths(size_t column, Table *a, ...);
+#define table_sync_column_widths(column, a, ...) _table_sync_column_widths(column, a, __VA_ARGS__, NULL)
 
 int table_print(Table *t, FILE *f);
 int table_format(Table *t, char **ret);