From: Karel Zak Date: Fri, 27 Oct 2023 09:58:00 +0000 (+0200) Subject: libsmartcols: cleanup datafunc() API X-Git-Tag: v2.40-rc1~151^2~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b0df377d4c996c69381115872c915e05db1f401b;p=thirdparty%2Futil-linux.git libsmartcols: cleanup datafunc() API Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index c0b364ec69..589a4ebcb1 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -223,7 +223,7 @@ int scols_column_get_json_type(const struct libscols_column *cl) * * If a simple string conversion is not possible then application (which want * to use filters and counters) needs to define data function to do the - * conversion. See scols_column_set_datafunc(). + * conversion. See scols_column_set_data_func(). * * Returns: 0, a negative value in case of an error. * @@ -628,22 +628,25 @@ int scols_column_get_wrap_data(const struct libscols_column *cl, return 0; } -/* scols_column_set_datafunc: +/* + * scols_column_set_data_func: * @cl: a pointer to a struct libscols_column instance * @datafunc: function to return data * @userdata: optional stuff for callbacks * - * The internal library operations (like filters) use standard cell data by default. - * This callback allows to use the data in another format for internal library purpose. - * - * The callback needs to return the data as pointer to void, and the datatype + * The table always keep data in strings in form that is printed on output, but + * for some internal operations (like filters or counters) it needs to convert + * the strings to usable data format. If this converion is not possible then + * application can define datafunc() callback to provide data for filters and counters. + + * The callback needs to return the data as pointer to void, and the data type * is defined by scols_column_set_data_type(). * * Returns: 0, a negative value in case of an error. * * Since: 2.40 */ -int scols_column_set_datafunc(struct libscols_column *cl, +int scols_column_set_data_func(struct libscols_column *cl, void *(*datafunc)(const struct libscols_column *, struct libscols_cell *, void *), @@ -660,11 +663,13 @@ int scols_column_set_datafunc(struct libscols_column *cl, /** * @cl: a pointer to a struct libscols_column instance * - * Returns: 1 if datafunc defined, or 0 + * See scols_column_set_data_func() for more details. + * + * Returns: 1 if data function defined, or 0 * * Since: 2.40 */ -int scols_column_has_datafunc(struct libscols_column *cl) +int scols_column_has_data_func(struct libscols_column *cl) { return cl && cl->datafunc != NULL ? 1 : 0; } diff --git a/libsmartcols/src/filter-param.c b/libsmartcols/src/filter-param.c index eacf18405a..446372e29f 100644 --- a/libsmartcols/src/filter-param.c +++ b/libsmartcols/src/filter-param.c @@ -277,7 +277,7 @@ static int fetch_holder_data(struct libscols_filter *fltr __attribute__((__unuse n->fetched = 1; - if (cl->datafunc) { + if (scols_column_has_data_func(cl)) { struct libscols_cell *ce = scols_line_get_column_cell(ln, cl); if (ce) diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 455c011d46..c97651f350 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -252,12 +252,12 @@ extern int scols_column_set_wrapfunc(struct libscols_column *cl, char *, void *), void *userdata); -extern int scols_column_set_datafunc(struct libscols_column *cl, +extern int scols_column_set_data_func(struct libscols_column *cl, void *(*datafunc)(const struct libscols_column *, struct libscols_cell *, void *), void *userdata); -extern int scols_column_has_datafunc(struct libscols_column *cl); +extern int scols_column_has_data_func(struct libscols_column *cl); extern char *scols_wrapnl_nextchunk(const struct libscols_column *cl, char *data, void *userdata); extern size_t scols_wrapnl_chunksize(const struct libscols_column *cl, const char *data, void *userdata); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index cf025e5ce7..41c74552e9 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -239,8 +239,8 @@ SMARTCOLS_2.40 { scols_counter_get_name; scols_filter_next_counter; scols_shellvar_name; - scols_column_set_datafunc; - scols_column_has_datafunc; + scols_column_set_data_func; + scols_column_has_data_func; scols_column_set_data_type; scols_column_get_data_type; } SMARTCOLS_2.39; diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 1810df7714..07fdc7a13c 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -674,7 +674,7 @@ static void unref_rawdata(struct libscols_table *tb) struct libscols_cell *ce; void *data; - if (cl != lsblk->sort_col && !scols_column_has_datafunc(cl)) + if (cl != lsblk->sort_col && !scols_column_has_data_func(cl)) continue; ce = scols_line_get_column_cell(ln, cl); @@ -1257,7 +1257,7 @@ static void device_fill_scols_cell(struct lsblk_device *dev, size_t datasiz = 0; int rc, id = get_column_id(colnum); - if (lsblk->sort_id == id || scols_column_has_datafunc(cl)) { + if (lsblk->sort_id == id || scols_column_has_data_func(cl)) { uint64_t rawdata = (uint64_t) -1; data = device_get_data(dev, parent, id, &rawdata, &datasiz); @@ -2270,10 +2270,10 @@ static void init_scols_filter(struct libscols_table *tb, struct libscols_filter /* For sizes use rawdata (u64) rather than strings from table */ if (ci->type == COLTYPE_SIZE && !lsblk->bytes - && !scols_column_has_datafunc(col)) { + && !scols_column_has_data_func(col)) { scols_column_set_data_type(col, SCOLS_DATA_U64); - scols_column_set_datafunc(col, get_u64_cell, NULL); + scols_column_set_data_func(col, get_u64_cell, NULL); lsblk->rawdata = 1; }