anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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