]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: cleanup datafunc() API
authorKarel Zak <kzak@redhat.com>
Fri, 27 Oct 2023 09:58:00 +0000 (11:58 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Nov 2023 21:25:47 +0000 (22:25 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/column.c
libsmartcols/src/filter-param.c
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
misc-utils/lsblk.c

index c0b364ec69ada8f87babae27ee7710474034a90c..589a4ebcb1a2d111204cd2074b4669fb45e4823b 100644 (file)
@@ -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;
 }
index eacf18405ae633bbccac97c0e5c649fe56fbfce9..446372e29f7ab1e2d2b7c41e9c77df0dbdbd3c38 100644 (file)
@@ -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)
index 455c011d46abc3bca0b5785c554d123f830353cc..c97651f35023641f5d264edfbd5ad300f46dacde 100644 (file)
@@ -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);
index cf025e5ce71db3846b2ef0cfe726e400454c7918..41c74552e967d82674a7d4bf9d25ccc4ed453514 100644 (file)
@@ -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;
index 1810df7714d77478d8ee81dc0b9f1ca8b5071219..07fdc7a13c7e4629010f7d33771c883cca8474fb 100644 (file)
@@ -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;
                }