Blame SOURCES/0130-format-table-add-table_update-to-update-existing-ent.patch

a3e2b5
From a53afb337985f8f1c7fe8f620fe30cec87f554d5 Mon Sep 17 00:00:00 2001
a3e2b5
From: Lennart Poettering <lennart@poettering.net>
a3e2b5
Date: Thu, 8 Nov 2018 21:17:47 +0100
a3e2b5
Subject: [PATCH] format-table: add table_update() to update existing entries
a3e2b5
a3e2b5
(cherry picked from commit 27e730e6d0a7709c17ccef170f10846e92dca2a0)
a3e2b5
a3e2b5
Related: #1689832
a3e2b5
---
a3e2b5
 src/basic/format-table.c | 40 ++++++++++++++++++++++++++++++++++++++++
a3e2b5
 src/basic/format-table.h |  2 ++
a3e2b5
 2 files changed, 42 insertions(+)
a3e2b5
a3e2b5
diff --git a/src/basic/format-table.c b/src/basic/format-table.c
a3e2b5
index a3ff527e91..302642d748 100644
a3e2b5
--- a/src/basic/format-table.c
a3e2b5
+++ b/src/basic/format-table.c
a3e2b5
@@ -590,6 +590,46 @@ int table_set_url(Table *t, TableCell *cell, const char *url) {
a3e2b5
         return free_and_replace(table_get_data(t, cell)->url, copy);
a3e2b5
 }
a3e2b5
 
a3e2b5
+int table_update(Table *t, TableCell *cell, TableDataType type, const void *data) {
a3e2b5
+        _cleanup_free_ char *curl = NULL;
a3e2b5
+        TableData *nd, *od;
a3e2b5
+        size_t i;
a3e2b5
+
a3e2b5
+        assert(t);
a3e2b5
+        assert(cell);
a3e2b5
+
a3e2b5
+        i = TABLE_CELL_TO_INDEX(cell);
a3e2b5
+        if (i >= t->n_cells)
a3e2b5
+                return -ENXIO;
a3e2b5
+
a3e2b5
+        assert_se(od = t->data[i]);
a3e2b5
+
a3e2b5
+        if (od->url) {
a3e2b5
+                curl = strdup(od->url);
a3e2b5
+                if (!curl)
a3e2b5
+                        return -ENOMEM;
a3e2b5
+        }
a3e2b5
+
a3e2b5
+        nd = table_data_new(
a3e2b5
+                        type,
a3e2b5
+                        data,
a3e2b5
+                        od->minimum_width,
a3e2b5
+                        od->maximum_width,
a3e2b5
+                        od->weight,
a3e2b5
+                        od->align_percent,
a3e2b5
+                        od->ellipsize_percent);
a3e2b5
+        if (!nd)
a3e2b5
+                return -ENOMEM;
a3e2b5
+
a3e2b5
+        nd->color = od->color;
a3e2b5
+        nd->url = TAKE_PTR(curl);
a3e2b5
+
a3e2b5
+        table_data_unref(od);
a3e2b5
+        t->data[i] = nd;
a3e2b5
+
a3e2b5
+        return 0;
a3e2b5
+}
a3e2b5
+
a3e2b5
 int table_add_many_internal(Table *t, TableDataType first_type, ...) {
a3e2b5
         TableDataType type;
a3e2b5
         va_list ap;
a3e2b5
diff --git a/src/basic/format-table.h b/src/basic/format-table.h
a3e2b5
index 07cb2351cb..4273c8c49b 100644
a3e2b5
--- a/src/basic/format-table.h
a3e2b5
+++ b/src/basic/format-table.h
a3e2b5
@@ -46,6 +46,8 @@ int table_set_ellipsize_percent(Table *t, TableCell *cell, unsigned percent);
a3e2b5
 int table_set_color(Table *t, TableCell *cell, const char *color);
a3e2b5
 int table_set_url(Table *t, TableCell *cell, const char *color);
a3e2b5
 
a3e2b5
+int table_update(Table *t, TableCell *cell, TableDataType type, const void *data);
a3e2b5
+
a3e2b5
 int table_add_many_internal(Table *t, TableDataType first_type, ...);
a3e2b5
 #define table_add_many(t, ...) table_add_many_internal(t, __VA_ARGS__, _TABLE_DATA_TYPE_MAX)
a3e2b5