diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:32 +0000 |
commit | 8bb05ac73a5b448b339ce0bc8d396c82c459b47f (patch) | |
tree | 1fdda006866bca20d41cb206767ea5241e36852f /libsmartcols/src/table.c | |
parent | Adding debian version 2.39.3-11. (diff) | |
download | util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.tar.xz util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.zip |
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | libsmartcols/src/table.c | 53 |
1 files changed, 53 insertions, 0 deletions
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; } |