Filters and counters

Filters and counters — defines lines filter and counter

Functions

Types and Values

Description

An API to define and use filter and counters.

Functions

scols_counter_get_name ()

const char *
scols_counter_get_name (struct libscols_counter *ct);

Parameters

ct

counter instance

 

Returns

name of the counter.

Since: 2.40


scols_counter_get_result ()

unsigned long long
scols_counter_get_result (struct libscols_counter *ct);

Parameters

ct

counter instance

 

Returns

result from the counter

Since: 2.40


scols_counter_set_func ()

int
scols_counter_set_func (struct libscols_counter *ct,
                        int func);

Defines function to calculate data.

Parameters

ct

counter instance

 

func

SCOLS_COUNTER_{COUNT,MAX,MIN,SUM}

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_counter_set_name ()

int
scols_counter_set_name (struct libscols_counter *ct,
                        const char *name);

The name is not use by library, it's just description usable for application when prints results from countes.

Parameters

ct

counter instance

 

name

something for humans

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_counter_set_param ()

int
scols_counter_set_param (struct libscols_counter *ct,
                         const char *name);

Assigns a counter to the column. The name is used in the same way as names in the filter expression. This is usable for counter that calcuate with data from table cells (e.g. max, sum, etc.)

Parameters

ct

counter instance

 

name

holder (column) name

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_dump_filter ()

int
scols_dump_filter (struct libscols_filter *fltr,
                   FILE *out);

Dumps internal filter nodes in JSON format. This function is mostly designed for debugging purpose. The fileds in the output are subject to change.

Parameters

fltr

filter instance

 

out

output stream

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_filter_assign_column ()

int
scols_filter_assign_column (struct libscols_filter *fltr,
                            struct libscols_iter *itr,
                            const char *name,
                            struct libscols_column *col);

Assign col to filter parametr. The parametr is addressed by itr or by name . See scols_filter_next_holder().

Parameters

fltr

pointer to filter

 

itr

iterator

 

name

holder name

 

col

column

 

Returns

0, a negative value in case of an error.

Since: 2.40


scols_filter_get_errmsg ()

const char *
scols_filter_get_errmsg (struct libscols_filter *fltr);

Parameters

fltr

filter instance

 

Returns

string with parse-error message of NULL (if no error)

Since: 2.40


scols_filter_new_counter ()

struct libscols_counter *
scols_filter_new_counter (struct libscols_filter *fltr);

Alocates a new counter instance into the filter.

Parameters

fltr

filter instance

 

Returns

new counter or NULL in case of an error.

Since: 2.40


scols_filter_next_counter ()

int
scols_filter_next_counter (struct libscols_filter *fltr,
                           struct libscols_iter *itr,
                           struct libscols_counter **ct);

Finds the next counter and returns a pointer to it via ct .

Parameters

fltr

filter instance

 

itr

a pointer to a struct libscols_iter instance

 

ct

returns the next counter

 

Returns

0, a negative value in case of an error, and 1 at the end.

Since: 2.40


scols_filter_next_holder ()

int
scols_filter_next_holder (struct libscols_filter *fltr,
                          struct libscols_iter *itr,
                          const char **name,
                          int type);

Finds the next holder used in the expression and and returns a name via name . The currently supported holder type is only column name.

Parameters

fltr

filter instance

 

itr

a pointer to a struct libscols_iter instance

 

name

returns the next column name

 

type

0 (not implemented yet)

 

Returns

0, a negative value in case of an error, and 1 at the end.

Since: 2.40


scols_filter_parse_string ()

int
scols_filter_parse_string (struct libscols_filter *fltr,
                           const char *str);

Parses filter, see scols_filter_get_errmsg() for errors.

Parameters

fltr

filter instance

 

str

string with filter expression

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_filter_set_filler_cb ()

int
scols_filter_set_filler_cb (struct libscols_filter *fltr,
                            int (*cb) (struct libscols_filter *, struct libscols_line *, size_t, void *),
                            void *userdata);

The application can apply filter for empty lines to avoid filling the table with unnecessary data (for example if the line will be later removed from the table due to filter).

This callback is used by filter to ask application to fill to the line data which are necessary to evaluate the filter expression. The callback arguments are filter, column number and userdata.

1
2
3
4
5
6
7
8
9
10
11
12
ln = scols_table_new_line(tab, NULL);

scols_filter_set_filler_cb(filter, my_filler, NULL);

scols_line_apply_filter(line, filter, &status);
if (status == 0)
	scols_table_remove_line(tab, line);
else for (i = 0; i < ncolumns; i++) {
	if (scols_line_is_filled(line, i))
		continue;
	my_filler(NULL, ln, i, NULL);
}

Parameters

fltr

filter instance

 

cb

application defined callback

 

userdata

pointer to private callback data

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_line_apply_filter ()

int
scols_line_apply_filter (struct libscols_line *ln,
                         struct libscols_filter *fltr,
                         int *status);

Applies filter (and also counters assisiated with the filter).

Parameters

ln

apply filter to the line

 

fltr

filter instance

 

status

return 1 or 0 as result of the expression

 

Returns

0, a negative number in case of an error.

Since: 2.40


scols_line_is_filled ()

int
scols_line_is_filled (struct libscols_line *ln,
                      size_t n);

Parameters

ln

a pointer to a struct libscols_line instance

 

n

number of the cell

 

Returns

0 or 1 if cell was already filled (note that NULL is also valid filler)


scols_new_filter ()

struct libscols_filter *
scols_new_filter (const char *str);

Allocated and optionally parses a new filter.

Parameters

str

filter expression or NULL

 

Returns

new filter instance or NULL in case of error.

Since: 2.40


scols_ref_filter ()

void
scols_ref_filter (struct libscols_filter *fltr);

Increment filter reference counter.

Parameters

fltr

filter instance

 

Since: 2.40


scols_unref_filter ()

void
scols_unref_filter (struct libscols_filter *fltr);

Deincrements reference counter, unallocates the filter for the last reference.

Parameters

fltr

filter instance

 

Since: 2.40

Types and Values

struct libscols_filter

struct libscols_filter;

A filter - defines the filtering


struct libscols_counter

struct libscols_counter;

A filter counter