summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src/table.c
diff options
context:
space:
mode:
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;
}