From 9af921a9645fcee2502f65cb596c922cbe7e53d9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Apr 07 2021 22:35:34 +0000 Subject: format-table: add an API for getting the cell at a specific row/column (cherry picked from commit 9314ead7853a1479fc60eb2ae7e3d0a77b7eba7c) Related: #1689832 patch_name: 0131-format-table-add-an-API-for-getting-the-cell-at-a-sp.patch present_in_specfile: true location_in_specfile: 131 squash_commits: true --- diff --git a/src/basic/format-table.c b/src/basic/format-table.c index 302642d..809a4be 100644 --- a/src/basic/format-table.c +++ b/src/basic/format-table.c @@ -1416,3 +1416,18 @@ int table_set_reverse(Table *t, size_t column, bool b) { t->reverse_map[column] = b; return 0; } + +TableCell *table_get_cell(Table *t, size_t row, size_t column) { + size_t i; + + assert(t); + + if (column >= t->n_columns) + return NULL; + + i = row * t->n_columns + column; + if (i >= t->n_cells) + return NULL; + + return TABLE_INDEX_TO_CELL(i); +} diff --git a/src/basic/format-table.h b/src/basic/format-table.h index 4273c8c..40fea79 100644 --- a/src/basic/format-table.h +++ b/src/basic/format-table.h @@ -66,3 +66,5 @@ static inline TableCell* TABLE_HEADER_CELL(size_t i) { size_t table_get_rows(Table *t); size_t table_get_columns(Table *t); + +TableCell *table_get_cell(Table *t, size_t row, size_t column);