summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src/table.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:30 +0000
commitc61e14d3a8412cd50d98aab604e607692c844c8a (patch)
tree4925aca0e6b64c8664ea2f3fdfa99a52dc93d5da /libsmartcols/src/table.c
parentAdding upstream version 2.39.3. (diff)
downloadutil-linux-c61e14d3a8412cd50d98aab604e607692c844c8a.tar.xz
util-linux-c61e14d3a8412cd50d98aab604e607692c844c8a.zip
Adding upstream version 2.40.upstream/2.40
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libsmartcols/src/table.c')
-rw-r--r--libsmartcols/src/table.c53
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;
}