代码拉取完成,页面将自动刷新
From a53afb337985f8f1c7fe8f620fe30cec87f554d5 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 8 Nov 2018 21:17:47 +0100
Subject: [PATCH] format-table: add table_update() to update existing entries
(cherry picked from commit 27e730e6d0a7709c17ccef170f10846e92dca2a0)
Related: #1689832
---
src/basic/format-table.c | 40 ++++++++++++++++++++++++++++++++++++++++
src/basic/format-table.h | 2 ++
2 files changed, 42 insertions(+)
diff --git a/src/basic/format-table.c b/src/basic/format-table.c
index a3ff527e91..302642d748 100644
--- a/src/basic/format-table.c
+++ b/src/basic/format-table.c
@@ -590,6 +590,46 @@ int table_set_url(Table *t, TableCell *cell, const char *url) {
return free_and_replace(table_get_data(t, cell)->url, copy);
}
+int table_update(Table *t, TableCell *cell, TableDataType type, const void *data) {
+ _cleanup_free_ char *curl = NULL;
+ TableData *nd, *od;
+ size_t i;
+
+ assert(t);
+ assert(cell);
+
+ i = TABLE_CELL_TO_INDEX(cell);
+ if (i >= t->n_cells)
+ return -ENXIO;
+
+ assert_se(od = t->data[i]);
+
+ if (od->url) {
+ curl = strdup(od->url);
+ if (!curl)
+ return -ENOMEM;
+ }
+
+ nd = table_data_new(
+ type,
+ data,
+ od->minimum_width,
+ od->maximum_width,
+ od->weight,
+ od->align_percent,
+ od->ellipsize_percent);
+ if (!nd)
+ return -ENOMEM;
+
+ nd->color = od->color;
+ nd->url = TAKE_PTR(curl);
+
+ table_data_unref(od);
+ t->data[i] = nd;
+
+ return 0;
+}
+
int table_add_many_internal(Table *t, TableDataType first_type, ...) {
TableDataType type;
va_list ap;
diff --git a/src/basic/format-table.h b/src/basic/format-table.h
index 07cb2351cb..4273c8c49b 100644
--- a/src/basic/format-table.h
+++ b/src/basic/format-table.h
@@ -46,6 +46,8 @@ int table_set_ellipsize_percent(Table *t, TableCell *cell, unsigned percent);
int table_set_color(Table *t, TableCell *cell, const char *color);
int table_set_url(Table *t, TableCell *cell, const char *color);
+int table_update(Table *t, TableCell *cell, TableDataType type, const void *data);
+
int table_add_many_internal(Table *t, TableDataType first_type, ...);
#define table_add_many(t, ...) table_add_many_internal(t, __VA_ARGS__, _TABLE_DATA_TYPE_MAX)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。