From 8bb05ac73a5b448b339ce0bc8d396c82c459b47f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:33:32 +0200 Subject: Merging upstream version 2.40. Signed-off-by: Daniel Baumann --- libsmartcols/src/table.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'libsmartcols/src/table.c') diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 8449c4f..3d23da8 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -521,6 +521,50 @@ size_t scols_table_get_nlines(const struct libscols_table *tb) return tb->nlines; } + +int scols_table_set_cursor(struct libscols_table *tb, + struct libscols_line *ln, + struct libscols_column *cl, + struct libscols_cell *ce) +{ + if (!tb) + return -EINVAL; + + tb->cur_line = ln; + tb->cur_column = cl; + tb->cur_cell = ce; + + return 0; +} + +/** + * scols_table_get_cursor: + * @tb: table + * @ln: returns current line (optional) + * @cl: returns current column (optional) + * @ce: returns current cell (optional) + * + * Returns: 0 on success, negative number in case of error. + * + * Since: 2.40 + */ +int scols_table_get_cursor(struct libscols_table *tb, + struct libscols_line **ln, + struct libscols_column **cl, + struct libscols_cell **ce) +{ + if (!tb) + return -EINVAL; + + if (ln) + *ln = tb->cur_line; + if (cl) + *cl = tb->cur_column; + if (ce) + *ce = tb->cur_cell; + return 0; +} + /** * scols_table_set_stream: * @tb: table @@ -632,6 +676,15 @@ struct libscols_column *scols_table_get_column_by_name( if (cn && strcmp(cn, name) == 0) return cl; } + + scols_reset_iter(&itr, SCOLS_ITER_FORWARD); + while (scols_table_next_column(tb, &itr, &cl) == 0) { + const char *cn = scols_column_get_name_as_shellvar(cl); + + if (cn && strcmp(cn, name) == 0) + return cl; + } + return NULL; } -- cgit v1.2.3