/src/util-linux/libsmartcols/src/smartcolsP.h
Line | Count | Source |
1 | | /* |
2 | | * smartcolsP.h - private library header file |
3 | | * |
4 | | * Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com> |
5 | | * Copyright (C) 2014 Karel Zak <kzak@redhat.com> |
6 | | * |
7 | | * This file may be redistributed under the terms of the |
8 | | * GNU Lesser General Public License. |
9 | | */ |
10 | | |
11 | | #ifndef _LIBSMARTCOLS_PRIVATE_H |
12 | | #define _LIBSMARTCOLS_PRIVATE_H |
13 | | |
14 | | #include "c.h" |
15 | | #include "list.h" |
16 | | #include "strutils.h" |
17 | | #include "color-names.h" |
18 | | #include "jsonwrt.h" |
19 | | #include "debug.h" |
20 | | #include "buffer.h" |
21 | | |
22 | | #include <stdbool.h> |
23 | | |
24 | | #include "libsmartcols.h" |
25 | | |
26 | | /* |
27 | | * Debug |
28 | | */ |
29 | 0 | #define SCOLS_DEBUG_HELP (1 << 0) |
30 | 0 | #define SCOLS_DEBUG_INIT (1 << 1) |
31 | 0 | #define SCOLS_DEBUG_CELL (1 << 2) |
32 | 0 | #define SCOLS_DEBUG_LINE (1 << 3) |
33 | 0 | #define SCOLS_DEBUG_TAB (1 << 4) |
34 | 0 | #define SCOLS_DEBUG_COL (1 << 5) |
35 | | #define SCOLS_DEBUG_BUFF (1 << 6) |
36 | 0 | #define SCOLS_DEBUG_GROUP (1 << 7) |
37 | 5.74k | #define SCOLS_DEBUG_FLTR (1 << 8) |
38 | 0 | #define SCOLS_DEBUG_FPARAM (1 << 9) |
39 | | |
40 | | UL_DEBUG_DECLARE_MASK(libsmartcols); |
41 | 0 | #define DBG(m, x) __UL_DBG(libsmartcols, SCOLS_DEBUG_, m, x) |
42 | 4.96k | #define DBG_OBJ(m, h, x) __UL_DBG_OBJ(libsmartcols, SCOLS_DEBUG_, m, h, x) |
43 | 774 | #define ON_DBG(m, x) __UL_DBG_CALL(libsmartcols, SCOLS_DEBUG_, m, x) |
44 | | #define DBG_FLUSH __UL_DBG_FLUSH(libsmartcols, SCOLS_DEBUG_) |
45 | | |
46 | | #define SCOLS_BUFPTR_TREEEND 0 |
47 | | |
48 | | /* |
49 | | * Generic iterator |
50 | | */ |
51 | | struct libscols_iter { |
52 | | struct list_head *p; /* current position */ |
53 | | struct list_head *head; /* start position */ |
54 | | int direction; /* SCOLS_ITER_{FOR,BACK}WARD */ |
55 | | }; |
56 | | |
57 | | /* |
58 | | * Tree symbols |
59 | | */ |
60 | | struct libscols_symbols { |
61 | | int refcount; |
62 | | |
63 | | char *tree_branch; |
64 | | char *tree_vert; |
65 | | char *tree_right; |
66 | | |
67 | | char *group_vert; |
68 | | char *group_horz; |
69 | | char *group_first_member; |
70 | | char *group_last_member; |
71 | | char *group_middle_member; |
72 | | char *group_last_child; |
73 | | char *group_middle_child; |
74 | | |
75 | | char *title_padding; |
76 | | char *cell_padding; |
77 | | }; |
78 | | |
79 | | /* |
80 | | * Table cells |
81 | | */ |
82 | | struct libscols_cell { |
83 | | char *data; |
84 | | size_t datasiz; |
85 | | char *color; |
86 | | char *uri; |
87 | | void *userdata; |
88 | | int flags; |
89 | | size_t width; |
90 | | |
91 | | unsigned int is_filled : 1, |
92 | | no_uri : 1; |
93 | | }; |
94 | | |
95 | | extern int scols_line_move_cells(struct libscols_line *ln, size_t newn, size_t oldn); |
96 | | |
97 | | struct libscols_wstat { |
98 | | size_t width_min; |
99 | | size_t width_max; |
100 | | double width_avg; |
101 | | double width_sqr_sum; |
102 | | double width_deviation; |
103 | | |
104 | | size_t width_treeart; |
105 | | }; |
106 | | |
107 | | /* |
108 | | * Table column |
109 | | */ |
110 | | struct libscols_column { |
111 | | int refcount; /* reference counter */ |
112 | | size_t seqnum; /* column index */ |
113 | | |
114 | | size_t width; /* expected column width */ |
115 | | size_t width_treeart; |
116 | | double width_hint; /* hint (N < 1 is in percent of termwidth) */ |
117 | | |
118 | | struct libscols_wstat wstat; /* private __scols_calculate() data */ |
119 | | |
120 | | int json_type; /* SCOLS_JSON_* */ |
121 | | int data_type; /* SCOLS_DATA_* */ |
122 | | |
123 | | int flags; |
124 | | char *color; /* default column color */ |
125 | | char *annotation; /* column annotation */ |
126 | | char *uri; /* default column URI prefix */ |
127 | | struct ul_buffer uri_buf; /* temporary buffer to compose URIs */ |
128 | | char *safechars; /* do not encode this bytes */ |
129 | | |
130 | | int (*cmpfunc)(struct libscols_cell *, |
131 | | struct libscols_cell *, |
132 | | void *); /* cells comparison function */ |
133 | | void *cmpfunc_data; |
134 | | |
135 | | /* multi-line cell data wrapping */ |
136 | | char *(*wrap_nextchunk)(const struct libscols_column *, char *, void *); |
137 | | void *wrapfunc_data; |
138 | | |
139 | | size_t wrap_datasz; |
140 | | size_t wrap_datamax; |
141 | | char *wrap_data; |
142 | | char *wrap_cur; |
143 | | char *wrap_next; |
144 | | struct libscols_cell *wrap_cell; |
145 | | |
146 | | void *(*datafunc)(const struct libscols_column *, |
147 | | struct libscols_cell *, |
148 | | void *); |
149 | | void *datafunc_data; |
150 | | |
151 | | struct libscols_cell header; /* column name with color etc. */ |
152 | | char *shellvar; /* raw column name in shell compatible format */ |
153 | | |
154 | | struct list_head cl_columns; /* member of table->tb_columns */ |
155 | | |
156 | | struct libscols_table *table; |
157 | | |
158 | | unsigned int is_groups : 1; /* print group chart */ |
159 | | |
160 | | }; |
161 | | |
162 | | #define colsep(tb) ((tb)->colsep ? (tb)->colsep : " ") |
163 | | #define linesep(tb) ((tb)->linesep ? (tb)->linesep : "\n") |
164 | | |
165 | | enum { |
166 | | SCOLS_GSTATE_NONE = 0, /* not activate yet */ |
167 | | SCOLS_GSTATE_FIRST_MEMBER, |
168 | | SCOLS_GSTATE_MIDDLE_MEMBER, |
169 | | SCOLS_GSTATE_LAST_MEMBER, |
170 | | SCOLS_GSTATE_MIDDLE_CHILD, |
171 | | SCOLS_GSTATE_LAST_CHILD, |
172 | | SCOLS_GSTATE_CONT_MEMBERS, |
173 | | SCOLS_GSTATE_CONT_CHILDREN |
174 | | }; |
175 | | |
176 | | /* |
177 | | * Every group needs at least 3 columns |
178 | | */ |
179 | 0 | #define SCOLS_GRPSET_CHUNKSIZ 3 |
180 | | |
181 | | struct libscols_group { |
182 | | int refcount; |
183 | | |
184 | | size_t nmembers; |
185 | | |
186 | | struct list_head gr_members; /* head of line->ln_group */ |
187 | | struct list_head gr_children; /* head of line->ln_children */ |
188 | | struct list_head gr_groups; /* member of table->tb_groups */ |
189 | | |
190 | | int state; /* SCOLS_GSTATE_* */ |
191 | | }; |
192 | | |
193 | | /* |
194 | | * Table line |
195 | | */ |
196 | | struct libscols_line { |
197 | | int refcount; |
198 | | size_t seqnum; |
199 | | |
200 | | void *userdata; |
201 | | char *color; /* default line color */ |
202 | | |
203 | | struct libscols_cell *cells; /* array with data */ |
204 | | size_t ncells; /* number of cells */ |
205 | | |
206 | | struct list_head ln_lines; /* member of table->tb_lines */ |
207 | | struct list_head ln_branch; /* head of line->ln_children */ |
208 | | struct list_head ln_children; /* member of line->ln_children or group->gr_children */ |
209 | | struct list_head ln_groups; /* member of group->gr_groups */ |
210 | | |
211 | | struct libscols_line *parent; |
212 | | struct libscols_group *parent_group; /* for group childs */ |
213 | | struct libscols_group *group; /* for group members */ |
214 | | }; |
215 | | |
216 | | enum { |
217 | | SCOLS_FMT_HUMAN = 0, /* default, human readable */ |
218 | | SCOLS_FMT_RAW, /* space separated */ |
219 | | SCOLS_FMT_EXPORT, /* COLNAME="data" ... */ |
220 | | SCOLS_FMT_JSON /* http://en.wikipedia.org/wiki/JSON */ |
221 | | }; |
222 | | |
223 | | /* |
224 | | * The table |
225 | | */ |
226 | | struct libscols_table { |
227 | | int refcount; |
228 | | char *name; /* optional table name (for JSON) */ |
229 | | size_t ncols; /* number of columns */ |
230 | | size_t ntreecols; /* number of columns with SCOLS_FL_TREE */ |
231 | | size_t nlines; /* number of lines */ |
232 | | size_t termwidth; /* terminal width (number of columns) */ |
233 | | size_t termheight; /* terminal height (number of lines) */ |
234 | | size_t termreduce; /* extra blank space */ |
235 | | size_t outwidth; /* effective output width (calculated internally) */ |
236 | | int termforce; /* SCOLS_TERMFORCE_* */ |
237 | | FILE *out; /* output stream */ |
238 | | |
239 | | char *colsep; /* column separator */ |
240 | | char *linesep; /* line separator */ |
241 | | |
242 | | struct list_head tb_columns; /* list of columns, items: column->cl_columns */ |
243 | | struct list_head tb_lines; /* list of lines; items: line->ln_lines */ |
244 | | |
245 | | struct list_head tb_groups; /* all defined groups */ |
246 | | struct libscols_group **grpset; |
247 | | size_t grpset_size; |
248 | | |
249 | | size_t ngrpchlds_pending; /* groups with not yet printed children */ |
250 | | struct libscols_line *walk_last_tree_root; /* last root, used by scols_walk_() */ |
251 | | |
252 | | struct libscols_column *dflt_sort_column; /* default sort column, set by scols_sort_table() */ |
253 | | |
254 | | struct libscols_symbols *symbols; |
255 | | struct libscols_cell title; /* optional table title (for humans) */ |
256 | | |
257 | | struct ul_jsonwrt json; /* JSON formatting */ |
258 | | |
259 | | int format; /* SCOLS_FMT_* */ |
260 | | |
261 | | size_t termlines_used; /* printed line counter */ |
262 | | size_t header_next; /* where repeat header */ |
263 | | |
264 | | const char *cur_color; /* current active color when printing */ |
265 | | |
266 | | struct libscols_cell *cur_cell; /* currently used cell */ |
267 | | struct libscols_line *cur_line; /* currently used line */ |
268 | | struct libscols_column *cur_column; /* currently used column */ |
269 | | |
270 | | enum ul_json_format json_format; /* JSON output format */ |
271 | | |
272 | | /* flags */ |
273 | | bool ascii , /* don't use unicode */ |
274 | | colors_wanted , /* enable colors */ |
275 | | is_term , /* isatty() */ |
276 | | padding_debug , /* output visible padding chars */ |
277 | | is_dummy_print, /* printing used for width calculation only */ |
278 | | is_shellvar , /* shell compatible column names */ |
279 | | maxout , /* maximize output */ |
280 | | minout , /* minimize output (mutually exclusive to maxout) */ |
281 | | header_repeat , /* print header after libscols_table->termheight */ |
282 | | header_printed, /* header already printed */ |
283 | | priv_symbols , /* default private symbols */ |
284 | | walk_last_done, /* last tree root walked */ |
285 | | no_headings , /* don't print header */ |
286 | | no_encode , /* don't care about control and non-printable chars */ |
287 | | no_linesep , /* don't print line separator */ |
288 | | no_wrap , /* never wrap lines */ |
289 | | is_calculated ; /* column widths already calculated */ |
290 | | }; |
291 | | |
292 | 0 | #define IS_ITER_FORWARD(_i) ((_i)->direction == SCOLS_ITER_FORWARD) |
293 | | #define IS_ITER_BACKWARD(_i) ((_i)->direction == SCOLS_ITER_BACKWARD) |
294 | | |
295 | | #define SCOLS_ITER_INIT(itr, list) \ |
296 | 0 | do { \ |
297 | 0 | (itr)->p = IS_ITER_FORWARD(itr) ? \ |
298 | 0 | (list)->next : (list)->prev; \ |
299 | 0 | (itr)->head = (list); \ |
300 | 0 | } while(0) |
301 | | |
302 | | #define SCOLS_ITER_ITERATE(itr, res, restype, member) \ |
303 | 0 | do { \ |
304 | 0 | res = list_entry((itr)->p, restype, member); \ |
305 | 0 | (itr)->p = IS_ITER_FORWARD(itr) ? \ |
306 | 0 | (itr)->p->next : (itr)->p->prev; \ |
307 | 0 | } while(0) |
308 | | |
309 | | |
310 | | static inline int scols_iter_is_last(const struct libscols_iter *itr) |
311 | 0 | { |
312 | 0 | if (!itr || !itr->head || !itr->p) |
313 | 0 | return 0; |
314 | 0 |
|
315 | 0 | return itr->p == itr->head; |
316 | 0 | } Unexecuted instantiation: filter.c:scols_iter_is_last Unexecuted instantiation: filter-param.c:scols_iter_is_last Unexecuted instantiation: filter-expr.c:scols_iter_is_last Unexecuted instantiation: iter.c:scols_iter_is_last Unexecuted instantiation: column.c:scols_iter_is_last Unexecuted instantiation: line.c:scols_iter_is_last Unexecuted instantiation: table.c:scols_iter_is_last Unexecuted instantiation: grouping.c:scols_iter_is_last Unexecuted instantiation: init.c:scols_iter_is_last Unexecuted instantiation: filter-parser.c:scols_iter_is_last Unexecuted instantiation: filter-scanner.c:scols_iter_is_last Unexecuted instantiation: symbols.c:scols_iter_is_last Unexecuted instantiation: cell.c:scols_iter_is_last Unexecuted instantiation: version.c:scols_iter_is_last |
317 | | |
318 | | /* |
319 | | * line.c |
320 | | */ |
321 | | int scols_line_next_group_child(struct libscols_line *ln, |
322 | | struct libscols_iter *itr, |
323 | | struct libscols_line **chld); |
324 | | |
325 | | /* |
326 | | * column.c |
327 | | */ |
328 | | void scols_column_reset_wrap(struct libscols_column *cl); |
329 | | int scols_column_next_wrap( struct libscols_column *cl, |
330 | | struct libscols_cell *ce, |
331 | | char **data); |
332 | | int scols_column_greatest_wrap( struct libscols_column *cl, |
333 | | struct libscols_cell *ce, |
334 | | char **data); |
335 | | int scols_column_has_pending_wrap(struct libscols_column *cl); |
336 | | int scols_column_move_wrap(struct libscols_column *cl, size_t bytes); |
337 | | |
338 | | /* |
339 | | * table.c |
340 | | */ |
341 | | int scols_table_next_group(struct libscols_table *tb, |
342 | | struct libscols_iter *itr, |
343 | | struct libscols_group **gr); |
344 | | int scols_table_set_cursor(struct libscols_table *tb, |
345 | | struct libscols_line *ln, |
346 | | struct libscols_column *cl, |
347 | | struct libscols_cell *ce); |
348 | | |
349 | | #define scols_table_reset_cursor(_t) scols_table_set_cursor((_t), NULL, NULL, NULL) |
350 | | |
351 | | |
352 | | /* |
353 | | * grouping.c |
354 | | */ |
355 | | void scols_ref_group(struct libscols_group *gr); |
356 | | void scols_group_remove_children(struct libscols_group *gr); |
357 | | void scols_group_remove_members(struct libscols_group *gr); |
358 | | void scols_unref_group(struct libscols_group *gr); |
359 | | void scols_groups_fix_members_order(struct libscols_table *tb); |
360 | | int scols_groups_update_grpset(struct libscols_table *tb, struct libscols_line *ln); |
361 | | void scols_groups_reset_state(struct libscols_table *tb); |
362 | | struct libscols_group *scols_grpset_get_printable_children(struct libscols_table *tb); |
363 | | |
364 | | /* |
365 | | * walk.c |
366 | | */ |
367 | | extern int scols_walk_tree(struct libscols_table *tb, |
368 | | struct libscols_column *cl, |
369 | | int (*callback)(struct libscols_table *, |
370 | | struct libscols_line *, |
371 | | struct libscols_column *, |
372 | | void *), |
373 | | void *data); |
374 | | extern int scols_walk_is_last(struct libscols_table *tb, struct libscols_line *ln); |
375 | | |
376 | | /* |
377 | | * calculate.c |
378 | | */ |
379 | | extern int __scols_calculate(struct libscols_table *tb, struct ul_buffer *buf); |
380 | | |
381 | | /* |
382 | | * print.c |
383 | | */ |
384 | | int __cursor_to_buffer(struct libscols_table *tb, |
385 | | struct ul_buffer *buf, |
386 | | int cal); |
387 | | |
388 | | void __scols_cleanup_printing(struct libscols_table *tb, struct ul_buffer *buf); |
389 | | int __scols_initialize_printing(struct libscols_table *tb, struct ul_buffer *buf); |
390 | | int __scols_print_tree(struct libscols_table *tb, struct ul_buffer *buf); |
391 | | int __scols_print_table(struct libscols_table *tb, struct ul_buffer *buf); |
392 | | int __scols_print_header(struct libscols_table *tb, struct ul_buffer *buf); |
393 | | int __scols_print_title(struct libscols_table *tb); |
394 | | int __scols_print_range(struct libscols_table *tb, |
395 | | struct ul_buffer *buf, |
396 | | struct libscols_iter *itr, |
397 | | struct libscols_line *end); |
398 | | |
399 | | static inline int is_tree_root(struct libscols_line *ln) |
400 | 0 | { |
401 | 0 | return ln && !ln->parent && !ln->parent_group; |
402 | 0 | } Unexecuted instantiation: filter.c:is_tree_root Unexecuted instantiation: filter-param.c:is_tree_root Unexecuted instantiation: filter-expr.c:is_tree_root Unexecuted instantiation: iter.c:is_tree_root Unexecuted instantiation: column.c:is_tree_root Unexecuted instantiation: line.c:is_tree_root Unexecuted instantiation: table.c:is_tree_root Unexecuted instantiation: grouping.c:is_tree_root Unexecuted instantiation: init.c:is_tree_root Unexecuted instantiation: filter-parser.c:is_tree_root Unexecuted instantiation: filter-scanner.c:is_tree_root Unexecuted instantiation: symbols.c:is_tree_root Unexecuted instantiation: cell.c:is_tree_root Unexecuted instantiation: version.c:is_tree_root |
403 | | |
404 | | static inline int is_last_tree_root(struct libscols_table *tb, struct libscols_line *ln) |
405 | 0 | { |
406 | 0 | if (!ln || !tb || tb->walk_last_tree_root != ln) |
407 | 0 | return 0; |
408 | 0 |
|
409 | 0 | return 1; |
410 | 0 | } Unexecuted instantiation: filter.c:is_last_tree_root Unexecuted instantiation: filter-param.c:is_last_tree_root Unexecuted instantiation: filter-expr.c:is_last_tree_root Unexecuted instantiation: iter.c:is_last_tree_root Unexecuted instantiation: column.c:is_last_tree_root Unexecuted instantiation: line.c:is_last_tree_root Unexecuted instantiation: table.c:is_last_tree_root Unexecuted instantiation: grouping.c:is_last_tree_root Unexecuted instantiation: init.c:is_last_tree_root Unexecuted instantiation: filter-parser.c:is_last_tree_root Unexecuted instantiation: filter-scanner.c:is_last_tree_root Unexecuted instantiation: symbols.c:is_last_tree_root Unexecuted instantiation: cell.c:is_last_tree_root Unexecuted instantiation: version.c:is_last_tree_root |
411 | | |
412 | | static inline int is_child(struct libscols_line *ln) |
413 | 0 | { |
414 | 0 | return ln && ln->parent; |
415 | 0 | } Unexecuted instantiation: filter.c:is_child Unexecuted instantiation: filter-param.c:is_child Unexecuted instantiation: filter-expr.c:is_child Unexecuted instantiation: iter.c:is_child Unexecuted instantiation: column.c:is_child Unexecuted instantiation: line.c:is_child Unexecuted instantiation: table.c:is_child Unexecuted instantiation: grouping.c:is_child Unexecuted instantiation: init.c:is_child Unexecuted instantiation: filter-parser.c:is_child Unexecuted instantiation: filter-scanner.c:is_child Unexecuted instantiation: symbols.c:is_child Unexecuted instantiation: cell.c:is_child Unexecuted instantiation: version.c:is_child |
416 | | |
417 | | static inline int is_last_child(struct libscols_line *ln) |
418 | 0 | { |
419 | 0 | if (!ln || !ln->parent) |
420 | 0 | return 0; |
421 | 0 |
|
422 | 0 | return list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch); |
423 | 0 | } Unexecuted instantiation: filter.c:is_last_child Unexecuted instantiation: filter-param.c:is_last_child Unexecuted instantiation: filter-expr.c:is_last_child Unexecuted instantiation: iter.c:is_last_child Unexecuted instantiation: column.c:is_last_child Unexecuted instantiation: line.c:is_last_child Unexecuted instantiation: table.c:is_last_child Unexecuted instantiation: grouping.c:is_last_child Unexecuted instantiation: init.c:is_last_child Unexecuted instantiation: filter-parser.c:is_last_child Unexecuted instantiation: filter-scanner.c:is_last_child Unexecuted instantiation: symbols.c:is_last_child Unexecuted instantiation: cell.c:is_last_child Unexecuted instantiation: version.c:is_last_child |
424 | | |
425 | | static inline int is_first_child(struct libscols_line *ln) |
426 | 0 | { |
427 | 0 | if (!ln || !ln->parent) |
428 | 0 | return 0; |
429 | 0 |
|
430 | 0 | return list_entry_is_first(&ln->ln_children, &ln->parent->ln_branch); |
431 | 0 | } Unexecuted instantiation: filter.c:is_first_child Unexecuted instantiation: filter-param.c:is_first_child Unexecuted instantiation: filter-expr.c:is_first_child Unexecuted instantiation: iter.c:is_first_child Unexecuted instantiation: column.c:is_first_child Unexecuted instantiation: line.c:is_first_child Unexecuted instantiation: table.c:is_first_child Unexecuted instantiation: grouping.c:is_first_child Unexecuted instantiation: init.c:is_first_child Unexecuted instantiation: filter-parser.c:is_first_child Unexecuted instantiation: filter-scanner.c:is_first_child Unexecuted instantiation: symbols.c:is_first_child Unexecuted instantiation: cell.c:is_first_child Unexecuted instantiation: version.c:is_first_child |
432 | | |
433 | | |
434 | | static inline int is_last_column(struct libscols_column *cl) |
435 | 0 | { |
436 | 0 | struct libscols_column *next; |
437 | 0 |
|
438 | 0 | if (list_entry_is_last(&cl->cl_columns, &cl->table->tb_columns)) |
439 | 0 | return 1; |
440 | 0 |
|
441 | 0 | next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns); |
442 | 0 | if (next && scols_column_is_hidden(next) && is_last_column(next)) |
443 | 0 | return 1; |
444 | 0 | return 0; |
445 | 0 | } Unexecuted instantiation: filter.c:is_last_column Unexecuted instantiation: filter-param.c:is_last_column Unexecuted instantiation: filter-expr.c:is_last_column Unexecuted instantiation: iter.c:is_last_column Unexecuted instantiation: column.c:is_last_column Unexecuted instantiation: line.c:is_last_column Unexecuted instantiation: table.c:is_last_column Unexecuted instantiation: grouping.c:is_last_column Unexecuted instantiation: init.c:is_last_column Unexecuted instantiation: filter-parser.c:is_last_column Unexecuted instantiation: filter-scanner.c:is_last_column Unexecuted instantiation: symbols.c:is_last_column Unexecuted instantiation: cell.c:is_last_column Unexecuted instantiation: version.c:is_last_column |
446 | | |
447 | | static inline int is_last_group_member(struct libscols_line *ln) |
448 | 0 | { |
449 | 0 | if (!ln || !ln->group) |
450 | 0 | return 0; |
451 | | |
452 | 0 | return list_entry_is_last(&ln->ln_groups, &ln->group->gr_members); |
453 | 0 | } Unexecuted instantiation: filter.c:is_last_group_member Unexecuted instantiation: filter-param.c:is_last_group_member Unexecuted instantiation: filter-expr.c:is_last_group_member Unexecuted instantiation: iter.c:is_last_group_member Unexecuted instantiation: column.c:is_last_group_member Unexecuted instantiation: line.c:is_last_group_member Unexecuted instantiation: table.c:is_last_group_member Unexecuted instantiation: grouping.c:is_last_group_member Unexecuted instantiation: init.c:is_last_group_member Unexecuted instantiation: filter-parser.c:is_last_group_member Unexecuted instantiation: filter-scanner.c:is_last_group_member Unexecuted instantiation: symbols.c:is_last_group_member Unexecuted instantiation: cell.c:is_last_group_member Unexecuted instantiation: version.c:is_last_group_member |
454 | | |
455 | | static inline int is_first_group_member(struct libscols_line *ln) |
456 | 0 | { |
457 | 0 | if (!ln || !ln->group) |
458 | 0 | return 0; |
459 | | |
460 | 0 | return list_entry_is_first(&ln->ln_groups, &ln->group->gr_members); |
461 | 0 | } Unexecuted instantiation: filter.c:is_first_group_member Unexecuted instantiation: filter-param.c:is_first_group_member Unexecuted instantiation: filter-expr.c:is_first_group_member Unexecuted instantiation: iter.c:is_first_group_member Unexecuted instantiation: column.c:is_first_group_member Unexecuted instantiation: line.c:is_first_group_member Unexecuted instantiation: table.c:is_first_group_member Unexecuted instantiation: grouping.c:is_first_group_member Unexecuted instantiation: init.c:is_first_group_member Unexecuted instantiation: filter-parser.c:is_first_group_member Unexecuted instantiation: filter-scanner.c:is_first_group_member Unexecuted instantiation: symbols.c:is_first_group_member Unexecuted instantiation: cell.c:is_first_group_member Unexecuted instantiation: version.c:is_first_group_member |
462 | | |
463 | | static inline int is_group_member(struct libscols_line *ln) |
464 | 0 | { |
465 | 0 | return ln && ln->group; |
466 | 0 | } Unexecuted instantiation: filter.c:is_group_member Unexecuted instantiation: filter-param.c:is_group_member Unexecuted instantiation: filter-expr.c:is_group_member Unexecuted instantiation: iter.c:is_group_member Unexecuted instantiation: column.c:is_group_member Unexecuted instantiation: line.c:is_group_member Unexecuted instantiation: table.c:is_group_member Unexecuted instantiation: grouping.c:is_group_member Unexecuted instantiation: init.c:is_group_member Unexecuted instantiation: filter-parser.c:is_group_member Unexecuted instantiation: filter-scanner.c:is_group_member Unexecuted instantiation: symbols.c:is_group_member Unexecuted instantiation: cell.c:is_group_member Unexecuted instantiation: version.c:is_group_member |
467 | | |
468 | | static inline int is_last_group_child(struct libscols_line *ln) |
469 | 0 | { |
470 | 0 | if (!ln || !ln->parent_group) |
471 | 0 | return 0; |
472 | | |
473 | 0 | return list_entry_is_last(&ln->ln_children, &ln->parent_group->gr_children); |
474 | 0 | } Unexecuted instantiation: filter.c:is_last_group_child Unexecuted instantiation: filter-param.c:is_last_group_child Unexecuted instantiation: filter-expr.c:is_last_group_child Unexecuted instantiation: iter.c:is_last_group_child Unexecuted instantiation: column.c:is_last_group_child Unexecuted instantiation: line.c:is_last_group_child Unexecuted instantiation: table.c:is_last_group_child Unexecuted instantiation: grouping.c:is_last_group_child Unexecuted instantiation: init.c:is_last_group_child Unexecuted instantiation: filter-parser.c:is_last_group_child Unexecuted instantiation: filter-scanner.c:is_last_group_child Unexecuted instantiation: symbols.c:is_last_group_child Unexecuted instantiation: cell.c:is_last_group_child Unexecuted instantiation: version.c:is_last_group_child |
475 | | |
476 | | static inline int is_group_child(struct libscols_line *ln) |
477 | 0 | { |
478 | 0 | return ln && ln->parent_group; |
479 | 0 | } Unexecuted instantiation: filter.c:is_group_child Unexecuted instantiation: filter-param.c:is_group_child Unexecuted instantiation: filter-expr.c:is_group_child Unexecuted instantiation: iter.c:is_group_child Unexecuted instantiation: column.c:is_group_child Unexecuted instantiation: line.c:is_group_child Unexecuted instantiation: table.c:is_group_child Unexecuted instantiation: grouping.c:is_group_child Unexecuted instantiation: init.c:is_group_child Unexecuted instantiation: filter-parser.c:is_group_child Unexecuted instantiation: filter-scanner.c:is_group_child Unexecuted instantiation: symbols.c:is_group_child Unexecuted instantiation: cell.c:is_group_child Unexecuted instantiation: version.c:is_group_child |
480 | | |
481 | | static inline int has_groups(struct libscols_table *tb) |
482 | 0 | { |
483 | 0 | return tb && !list_empty(&tb->tb_groups); |
484 | 0 | } Unexecuted instantiation: filter.c:has_groups Unexecuted instantiation: filter-param.c:has_groups Unexecuted instantiation: filter-expr.c:has_groups Unexecuted instantiation: iter.c:has_groups Unexecuted instantiation: column.c:has_groups Unexecuted instantiation: line.c:has_groups Unexecuted instantiation: table.c:has_groups Unexecuted instantiation: grouping.c:has_groups Unexecuted instantiation: init.c:has_groups Unexecuted instantiation: filter-parser.c:has_groups Unexecuted instantiation: filter-scanner.c:has_groups Unexecuted instantiation: symbols.c:has_groups Unexecuted instantiation: cell.c:has_groups Unexecuted instantiation: version.c:has_groups |
485 | | |
486 | | static inline int has_children(struct libscols_line *ln) |
487 | 0 | { |
488 | 0 | return ln && !list_empty(&ln->ln_branch); |
489 | 0 | } Unexecuted instantiation: filter.c:has_children Unexecuted instantiation: filter-param.c:has_children Unexecuted instantiation: filter-expr.c:has_children Unexecuted instantiation: iter.c:has_children Unexecuted instantiation: column.c:has_children Unexecuted instantiation: line.c:has_children Unexecuted instantiation: table.c:has_children Unexecuted instantiation: grouping.c:has_children Unexecuted instantiation: init.c:has_children Unexecuted instantiation: filter-parser.c:has_children Unexecuted instantiation: filter-scanner.c:has_children Unexecuted instantiation: symbols.c:has_children Unexecuted instantiation: cell.c:has_children Unexecuted instantiation: version.c:has_children |
490 | | |
491 | | static inline int has_group_children(struct libscols_line *ln) |
492 | 0 | { |
493 | 0 | return ln && ln->group && !list_empty(&ln->group->gr_children); |
494 | 0 | } Unexecuted instantiation: filter.c:has_group_children Unexecuted instantiation: filter-param.c:has_group_children Unexecuted instantiation: filter-expr.c:has_group_children Unexecuted instantiation: iter.c:has_group_children Unexecuted instantiation: column.c:has_group_children Unexecuted instantiation: line.c:has_group_children Unexecuted instantiation: table.c:has_group_children Unexecuted instantiation: grouping.c:has_group_children Unexecuted instantiation: init.c:has_group_children Unexecuted instantiation: filter-parser.c:has_group_children Unexecuted instantiation: filter-scanner.c:has_group_children Unexecuted instantiation: symbols.c:has_group_children Unexecuted instantiation: cell.c:has_group_children Unexecuted instantiation: version.c:has_group_children |
495 | | |
496 | | /* |
497 | | * Filter stuff |
498 | | */ |
499 | | enum filter_holder { |
500 | | F_HOLDER_NONE, |
501 | | F_HOLDER_COLUMN /* column name */ |
502 | | }; |
503 | | |
504 | | /* node types */ |
505 | | enum filter_ntype { |
506 | | F_NODE_PARAM, |
507 | | F_NODE_EXPR |
508 | | }; |
509 | | |
510 | | /* expression types */ |
511 | | enum filter_etype { |
512 | | F_EXPR_AND, |
513 | | F_EXPR_OR, |
514 | | F_EXPR_NEG, |
515 | | |
516 | | F_EXPR_EQ, |
517 | | F_EXPR_NE, |
518 | | |
519 | | F_EXPR_LT, |
520 | | F_EXPR_LE, |
521 | | F_EXPR_GT, |
522 | | F_EXPR_GE, |
523 | | |
524 | | F_EXPR_REG, |
525 | | F_EXPR_NREG, |
526 | | }; |
527 | | |
528 | | struct filter_node { |
529 | | enum filter_ntype type; |
530 | | int refcount; |
531 | | }; |
532 | | |
533 | 913 | #define filter_node_get_type(n) (((struct filter_node *)(n))->type) |
534 | | |
535 | | struct filter_param; |
536 | | struct filter_expr; |
537 | | |
538 | | struct libscols_counter { |
539 | | char *name; |
540 | | struct list_head counters; |
541 | | struct filter_param *param; |
542 | | struct libscols_filter *filter; |
543 | | |
544 | | int func; |
545 | | unsigned long long result; |
546 | | |
547 | | unsigned int neg : 1, |
548 | | has_result : 1; |
549 | | }; |
550 | | |
551 | | struct libscols_filter { |
552 | | int refcount; |
553 | | char *errmsg; |
554 | | struct filter_node *root; |
555 | | FILE *src; |
556 | | |
557 | | int (*filler_cb)(struct libscols_filter *, struct libscols_line *, size_t, void *); |
558 | | void *filler_data; |
559 | | |
560 | | struct list_head params; |
561 | | struct list_head counters; |
562 | | |
563 | | size_t parse_nodes; |
564 | | unsigned int parsing : 1; |
565 | | }; |
566 | | |
567 | 779 | #define SCOLS_FILTER_MAX_EXPRSZ 1024 |
568 | 23.5k | #define SCOLS_FILTER_MAX_NODES 256 |
569 | 904 | #define SCOLS_FILTER_MAX_REGSZ 256 |
570 | | |
571 | | struct filter_node *__filter_new_node(enum filter_ntype type, size_t sz); |
572 | | void filter_ref_node(struct filter_node *n); |
573 | | void filter_unref_node(struct filter_node *n); |
574 | | |
575 | | void filter_dump_node(struct ul_jsonwrt *json, struct filter_node *n); |
576 | | int filter_eval_node(struct libscols_filter *fltr, struct libscols_line *ln, |
577 | | struct filter_node *n, int *status); |
578 | | /* param */ |
579 | | int filter_compile_param(struct libscols_filter *fltr, struct filter_param *n); |
580 | | void filter_dump_param(struct ul_jsonwrt *json, struct filter_param *n); |
581 | | int filter_eval_param(struct libscols_filter *fltr, struct libscols_line *ln, |
582 | | struct filter_param *n, int *status); |
583 | | void filter_free_param(struct filter_param *n); |
584 | | void filter_free_params(struct libscols_filter *fltr); |
585 | | int filter_param_reset_holder(struct filter_param *n); |
586 | | int filter_param_get_datatype(struct filter_param *n); |
587 | | |
588 | | int filter_next_param(struct libscols_filter *fltr, |
589 | | struct libscols_iter *itr, struct filter_param **prm); |
590 | | |
591 | | int filter_compare_params(struct libscols_filter *fltr, |
592 | | enum filter_etype oper, |
593 | | struct filter_param *l, |
594 | | struct filter_param *r, |
595 | | int *status); |
596 | | int filter_cast_param(struct libscols_filter *fltr, |
597 | | struct libscols_line *ln, |
598 | | int type, |
599 | | struct filter_param *n, |
600 | | struct filter_param **result); |
601 | | |
602 | | int is_filter_holder_node(struct filter_node *n); |
603 | | |
604 | | int filter_count_param(struct libscols_filter *fltr, |
605 | | struct libscols_line *ln, |
606 | | struct libscols_counter *ct); |
607 | | |
608 | | /* expr */ |
609 | | void filter_free_expr(struct filter_expr *n); |
610 | | void filter_dump_expr(struct ul_jsonwrt *json, struct filter_expr *n); |
611 | | int filter_eval_expr(struct libscols_filter *fltr, struct libscols_line *ln, |
612 | | struct filter_expr *n, int *status); |
613 | | |
614 | | /* required by parser */ |
615 | | struct filter_node *filter_new_param(struct libscols_filter *filter, |
616 | | int type, |
617 | | enum filter_holder holder, |
618 | | void *data); |
619 | | struct filter_node *filter_new_expr(struct libscols_filter *filter, |
620 | | enum filter_etype type, |
621 | | struct filter_node *left, |
622 | | struct filter_node *right); |
623 | | |
624 | | #endif /* _LIBSMARTCOLS_PRIVATE_H */ |