From 70e0f980dba015b29aa65edd2bd377e7eb705b20 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 5 Sep 2023 11:52:39 +0200 Subject: [PATCH] libsmartcols: (filter) make holders API more generic The internal implementation is generic (can hold something else than only column name). Let's make the API also generic. Maybe later we can support something else than only column names in expressions (e.g. env.variables ?). Signed-off-by: Karel Zak --- libsmartcols/samples/filter.c | 2 +- libsmartcols/src/filter.c | 11 ++++++++--- libsmartcols/src/libsmartcols.h.in | 4 ++-- libsmartcols/src/libsmartcols.sym | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libsmartcols/samples/filter.c b/libsmartcols/samples/filter.c index fe8121c8e1..ec61b7f00e 100644 --- a/libsmartcols/samples/filter.c +++ b/libsmartcols/samples/filter.c @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) if (!itr) err(EXIT_FAILURE, "failed to allocate iterator"); - while (scols_filter_next_name(fltr, itr, &name) == 0) { + while (scols_filter_next_holder(fltr, itr, &name, 0) == 0) { struct libscols_column *col = scols_table_get_column_by_name(tb, name); if (!col) { diff --git a/libsmartcols/src/filter.c b/libsmartcols/src/filter.c index 2cef954ed4..e99e79fc69 100644 --- a/libsmartcols/src/filter.c +++ b/libsmartcols/src/filter.c @@ -153,18 +153,23 @@ const char *scols_filter_get_errmsg(struct libscols_filter *fltr) return fltr ? fltr->errmsg : NULL; } -int scols_filter_next_name(struct libscols_filter *fltr, - struct libscols_iter *itr, const char **name) +int scols_filter_next_holder(struct libscols_filter *fltr, + struct libscols_iter *itr, + const char **name, + int type) { struct filter_param *prm = NULL; int rc = 0; *name = NULL; + if (!type) + type = F_HOLDER_COLUMN; /* default */ do { rc = filter_next_param(fltr, itr, &prm); - if (rc == 0 && prm->holder == F_HOLDER_COLUMN) + if (rc == 0 && (int) prm->holder == type) { *name = prm->val.str; + } } while (rc == 0 && !*name); return rc; diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index ae1f581450..200d7f5d3d 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -377,8 +377,8 @@ extern const char *scols_filter_get_errmsg(struct libscols_filter *fltr); extern int scols_line_apply_filter(struct libscols_line *ln, struct libscols_filter *fltr, int *status); -extern int scols_filter_next_name(struct libscols_filter *fltr, - struct libscols_iter *itr, const char **name); +extern int scols_filter_next_holder(struct libscols_filter *fltr, + struct libscols_iter *itr, const char **name, int type); extern int scols_filter_assign_column(struct libscols_filter *fltr, const char *name, struct libscols_column *col); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index 5e0c560696..2b17090693 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -226,7 +226,7 @@ SMARTCOLS_2.40 { scols_new_filter; scols_unref_filter; scols_filter_get_errmsg; - scols_filter_next_name; + scols_filter_next_holder; scols_filter_assign_column; scols_line_apply_filter; } SMARTCOLS_2.39; -- 2.47.3