teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0131-format-table-add-an-API-for-getting-the-cell-at-a-sp.patch

ff6046
From ecc27a3bf5935cebc63aa4e3b650861d1f0ef97f Mon Sep 17 00:00:00 2001
ff6046
From: Lennart Poettering <lennart@poettering.net>
ff6046
Date: Thu, 8 Nov 2018 21:21:09 +0100
ff6046
Subject: [PATCH] format-table: add an API for getting the cell at a specific
ff6046
 row/column
ff6046
ff6046
(cherry picked from commit 9314ead7853a1479fc60eb2ae7e3d0a77b7eba7c)
ff6046
ff6046
Related: #1689832
ff6046
---
ff6046
 src/basic/format-table.c | 15 +++++++++++++++
ff6046
 src/basic/format-table.h |  2 ++
ff6046
 2 files changed, 17 insertions(+)
ff6046
ff6046
diff --git a/src/basic/format-table.c b/src/basic/format-table.c
ff6046
index 302642d748..809a4be284 100644
ff6046
--- a/src/basic/format-table.c
ff6046
+++ b/src/basic/format-table.c
ff6046
@@ -1416,3 +1416,18 @@ int table_set_reverse(Table *t, size_t column, bool b) {
ff6046
         t->reverse_map[column] = b;
ff6046
         return 0;
ff6046
 }
ff6046
+
ff6046
+TableCell *table_get_cell(Table *t, size_t row, size_t column) {
ff6046
+        size_t i;
ff6046
+
ff6046
+        assert(t);
ff6046
+
ff6046
+        if (column >= t->n_columns)
ff6046
+                return NULL;
ff6046
+
ff6046
+        i = row * t->n_columns + column;
ff6046
+        if (i >= t->n_cells)
ff6046
+                return NULL;
ff6046
+
ff6046
+        return TABLE_INDEX_TO_CELL(i);
ff6046
+}
ff6046
diff --git a/src/basic/format-table.h b/src/basic/format-table.h
ff6046
index 4273c8c49b..40fea79f78 100644
ff6046
--- a/src/basic/format-table.h
ff6046
+++ b/src/basic/format-table.h
ff6046
@@ -66,3 +66,5 @@ static inline TableCell* TABLE_HEADER_CELL(size_t i) {
ff6046
 
ff6046
 size_t table_get_rows(Table *t);
ff6046
 size_t table_get_columns(Table *t);
ff6046
+
ff6046
+TableCell *table_get_cell(Table *t, size_t row, size_t column);