Debian Codegraph @

libsmartcols/src/libsmartcols.h.in

raw
1 /*
2 * Prints table or tree.
3 *
4 * Copyright (C) 2014 Ondrej Oprala <[email protected]>
5 * Copyright (C) 2014 Karel Zak <[email protected]>
6 *
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
9 */
10 #ifndef _LIBSMARTCOLS_H
11 #define _LIBSMARTCOLS_H
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #include <stdarg.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <sys/types.h>
21
22 /**
23 * LIBSMARTCOLS_VERSION:
24 *
25 * Library version string
26 */
27 #define LIBSMARTCOLS_VERSION "@LIBSMARTCOLS_VERSION@"
28
29 /**
30 * libscols_iter:
31 *
32 * Generic iterator
33 */
34 struct libscols_iter;
35
36 /**
37 * libscols_symbols:
38 *
39 * Symbol groups for printing tree hierarchies
40 */
41 struct libscols_symbols;
42
43 /**
44 * libscols_cell:
45 *
46 * A cell - the smallest library object
47 */
48 struct libscols_cell;
49
50 /**
51 * libscols_line:
52 *
53 * A line - an array of cells
54 */
55 struct libscols_line;
56
57 /**
58 * libscols_table:
59 *
60 * A table - The most abstract object, encapsulating lines, columns, symbols and cells
61 */
62 struct libscols_table;
63
64 /**
65 * libscols_column:
66 *
67 * A column - defines the number of columns and column names
68 */
69 struct libscols_column;
70
71 /**
72 * libscols_filter:
73 *
74 * A filter - defines the filtering
75 */
76 struct libscols_filter;
77
78 /**
79 * libscols_counter:
80 *
81 * A filter counter
82 */
83 struct libscols_counter;
84
85 enum {
86 SCOLS_COUNTER_COUNT = 0,
87 SCOLS_COUNTER_MAX,
88 SCOLS_COUNTER_MIN,
89 SCOLS_COUNTER_SUM,
90
91 __SCOLS_NCOUNTES
92 };
93
94 /* iter.c */
95 enum {
96
97 SCOLS_ITER_FORWARD = 0,
98 SCOLS_ITER_BACKWARD
99 };
100
101 /*
102 * Column flags
103 */
104 enum {
105 SCOLS_FL_TRUNC = (1 << 0), /* truncate fields data if necessary */
106 SCOLS_FL_TREE = (1 << 1), /* use tree "ascii art" */
107 SCOLS_FL_RIGHT = (1 << 2), /* align to the right */
108 SCOLS_FL_STRICTWIDTH = (1 << 3), /* don't reduce width if column is empty */
109 SCOLS_FL_NOEXTREMES = (1 << 4), /* ignore extreme fields when count column width*/
110 SCOLS_FL_HIDDEN = (1 << 5), /* maintain data, but don't print */
111 SCOLS_FL_WRAP = (1 << 6) /* wrap long lines to multi-line cells */
112 };
113
114 /*
115 * Column JSON types
116 */
117 enum {
118 SCOLS_JSON_STRING = 0, /* default */
119 SCOLS_JSON_NUMBER = 1,
120 SCOLS_JSON_BOOLEAN = 2,
121 SCOLS_JSON_ARRAY_STRING = 3, /* e.g. for multi-line (SCOLS_FL_WRAP) cells */
122 SCOLS_JSON_ARRAY_NUMBER = 4,
123 SCOLS_JSON_BOOLEAN_OPTIONAL = 5,
124 SCOLS_JSON_FLOAT = 6
125 };
126
127 /*
128 * Types used by filters and counters
129 */
130 enum {
131 SCOLS_DATA_NONE = 0, /* default */
132 SCOLS_DATA_U64, /* uint64_t */
133 SCOLS_DATA_BOOLEAN, /* 0 or 1 */
134 SCOLS_DATA_FLOAT, /* long double */
135 SCOLS_DATA_STRING
136 };
137
138 /*
139 * Cell flags, see scols_cell_set_flags() before use
140 */
141 enum {
142 /* alignment evaluated in order: right,center,left */
143 SCOLS_CELL_FL_LEFT = 0,
144 SCOLS_CELL_FL_CENTER = (1 << 0),
145 SCOLS_CELL_FL_RIGHT = (1 << 1)
146 };
147
148
149 #ifndef __GNUC_PREREQ
150 # if defined __GNUC__ && defined __GNUC_MINOR__
151 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
152 # else
153 # define __GNUC_PREREQ(maj, min) 0
154 # endif
155 #endif
156
157 #ifndef __ul_attribute__
158 # if __GNUC_PREREQ (3, 4)
159 # define __ul_attribute__(_a_) __attribute__(_a_)
160 # else
161 # define __ul_attribute__(_a_)
162 # endif
163 #endif
164
165 extern struct libscols_iter *scols_new_iter(int direction);
166 extern void scols_free_iter(struct libscols_iter *itr);
167 extern void scols_reset_iter(struct libscols_iter *itr, int direction);
168 extern int scols_iter_get_direction(const struct libscols_iter *itr);
169
170 /* init.c */
171 extern void scols_init_debug(int mask);
172
173 /* version.c */
174 extern int scols_parse_version_string(const char *ver_string);
175 extern int scols_get_library_version(const char **ver_string);
176
177 /* symbols.c */
178 extern struct libscols_symbols *scols_new_symbols(void);
179 extern void scols_ref_symbols(struct libscols_symbols *sy);
180 extern void scols_unref_symbols(struct libscols_symbols *sy);
181 extern struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sy);
182 extern int scols_symbols_set_branch(struct libscols_symbols *sy, const char *str);
183 extern int scols_symbols_set_vertical(struct libscols_symbols *sy, const char *str);
184 extern int scols_symbols_set_right(struct libscols_symbols *sy, const char *str);
185 extern int scols_symbols_set_title_padding(struct libscols_symbols *sy, const char *str);
186 extern int scols_symbols_set_cell_padding(struct libscols_symbols *sy, const char *str);
187
188 extern int scols_symbols_set_group_vertical(struct libscols_symbols *sy, const char *str);
189 extern int scols_symbols_set_group_horizontal(struct libscols_symbols *sy, const char *str);
190 extern int scols_symbols_set_group_first_member(struct libscols_symbols *sy, const char *str);
191 extern int scols_symbols_set_group_last_member(struct libscols_symbols *sy, const char *str);
192 extern int scols_symbols_set_group_middle_member(struct libscols_symbols *sy, const char *str);
193 extern int scols_symbols_set_group_last_child(struct libscols_symbols *sy, const char *str);
194 extern int scols_symbols_set_group_middle_child(struct libscols_symbols *sy, const char *str);
195
196 /* cell.c */
197 extern int scols_reset_cell(struct libscols_cell *ce);
198 extern int scols_cell_copy_content(struct libscols_cell *dest,
199 const struct libscols_cell *src);
200 extern int scols_cell_set_data(struct libscols_cell *ce, const char *data);
201 extern int scols_cell_refer_data(struct libscols_cell *ce, char *data);
202 extern int scols_cell_refer_memory(struct libscols_cell *ce, char *data, size_t datasiz);
203
204 extern const char *scols_cell_get_data(const struct libscols_cell *ce);
205 extern size_t scols_cell_get_datasiz(struct libscols_cell *ce);
206
207 extern int scols_cell_set_color(struct libscols_cell *ce, const char *color);
208 extern const char *scols_cell_get_color(const struct libscols_cell *ce);
209
210 extern int scols_cell_set_uri(struct libscols_cell *ce, const char *uri);
211 extern const char *scols_cell_get_uri(const struct libscols_cell *ce);
212 extern int scols_cell_disable_uri(struct libscols_cell *ce, int disable);
213
214 extern int scols_cell_set_flags(struct libscols_cell *ce, int flags);
215 extern int scols_cell_get_flags(const struct libscols_cell *ce);
216 extern int scols_cell_get_alignment(const struct libscols_cell *ce);
217
218 extern void *scols_cell_get_userdata(struct libscols_cell *ce);
219 extern int scols_cell_set_userdata(struct libscols_cell *ce, void *data);
220
221 extern int scols_cmpstr_cells(struct libscols_cell *a,
222 struct libscols_cell *b, void *data);
223
224 /* column.c */
225 extern int scols_column_is_tree(const struct libscols_column *cl);
226 extern int scols_column_is_trunc(const struct libscols_column *cl);
227 extern int scols_column_is_right(const struct libscols_column *cl);
228 extern int scols_column_is_strict_width(const struct libscols_column *cl);
229 extern int scols_column_is_hidden(const struct libscols_column *cl);
230 extern int scols_column_is_noextremes(const struct libscols_column *cl);
231 extern int scols_column_is_wrap(const struct libscols_column *cl);
232 extern int scols_column_is_customwrap(const struct libscols_column *cl);
233
234 extern size_t scols_column_get_width(const struct libscols_column *cl);
235
236 extern int scols_column_set_safechars(struct libscols_column *cl, const char *safe);
237 extern const char *scols_column_get_safechars(const struct libscols_column *cl);
238
239 extern int scols_column_set_json_type(struct libscols_column *cl, int type);
240 extern int scols_column_get_json_type(const struct libscols_column *cl);
241
242 extern int scols_column_set_data_type(struct libscols_column *cl, int type);
243 extern int scols_column_get_data_type(const struct libscols_column *cl);
244
245 extern int scols_column_set_flags(struct libscols_column *cl, int flags);
246 extern int scols_column_get_flags(const struct libscols_column *cl);
247 extern struct libscols_column *scols_new_column(void);
248 extern void scols_ref_column(struct libscols_column *cl);
249 extern void scols_unref_column(struct libscols_column *cl);
250 extern struct libscols_column *scols_copy_column(const struct libscols_column *cl);
251 extern int scols_column_set_whint(struct libscols_column *cl, double whint);
252 extern double scols_column_get_whint(const struct libscols_column *cl);
253
254 extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl);
255 extern int scols_column_set_headercolor(struct libscols_column *cl, const char *color);
256 extern const char *scols_column_get_headercolor(struct libscols_column *cl);
257
258 extern int scols_column_set_color(struct libscols_column *cl, const char *color);
259 extern const char *scols_column_get_color(const struct libscols_column *cl);
260 extern struct libscols_table *scols_column_get_table(const struct libscols_column *cl);
261
262 extern int scols_column_set_uri(struct libscols_column *cl, const char *uri);
263 extern const char *scols_column_get_uri(const struct libscols_column *cl);
264
265 extern int scols_column_set_name(struct libscols_column *cl, const char *name);
266 extern const char *scols_column_get_name(struct libscols_column *cl);
267 extern const char *scols_column_get_name_as_shellvar(struct libscols_column *cl);
268 extern int scols_shellvar_name(const char *name, char **buf, size_t *bufsz);
269
270 extern int scols_column_refer_annotation(struct libscols_column *cl, const char *annotation);
271 extern const char *scols_column_get_annotation(struct libscols_column *cl);
272
273 extern int scols_column_set_properties(struct libscols_column *cl, const char *opts);
274
275 extern int scols_column_set_cmpfunc(struct libscols_column *cl,
276 int (*cmp)(struct libscols_cell *a,
277 struct libscols_cell *b, void *),
278 void *data);
279
280 extern int scols_column_set_wrapfunc(struct libscols_column *cl,
281 size_t (*wrap_chunksize)(const struct libscols_column *,
282 const char *, void *),
283 char * (*wrap_nextchunk)(const struct libscols_column *,
284 char *, void *),
285 void *userdata);
286
287 extern int scols_column_set_data_func(struct libscols_column *cl,
288 void *(*datafunc)(const struct libscols_column *,
289 struct libscols_cell *,
290 void *),
291 void *userdata);
292 extern int scols_column_has_data_func(struct libscols_column *cl);
293
294 extern char *scols_wrapnl_nextchunk(const struct libscols_column *cl, char *data, void *userdata);
295 extern size_t scols_wrapnl_chunksize(const struct libscols_column *cl, const char *data, void *userdata);
296
297 extern char *scols_wrapzero_nextchunk(const struct libscols_column *cl, char *data, void *userdata);
298
299 extern int scols_column_get_wrap_data(const struct libscols_column *cl,
300 char **data, size_t *datasiz, char **cur, char **next);
301
302 /* line.c */
303 extern struct libscols_line *scols_new_line(void);
304 extern void scols_ref_line(struct libscols_line *ln);
305 extern void scols_unref_line(struct libscols_line *ln);
306 extern int scols_line_alloc_cells(struct libscols_line *ln, size_t n);
307 extern void scols_line_free_cells(struct libscols_line *ln);
308 extern int scols_line_set_userdata(struct libscols_line *ln, void *data);
309 extern void *scols_line_get_userdata(struct libscols_line *ln);
310 extern int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *child);
311 extern int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child);
312 extern int scols_line_has_children(struct libscols_line *ln);
313 extern int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *parent);
314 extern int scols_line_next_child(struct libscols_line *ln,
315 struct libscols_iter *itr, struct libscols_line **chld);
316 extern struct libscols_line *scols_line_get_parent(const struct libscols_line *ln);
317 extern int scols_line_set_color(struct libscols_line *ln, const char *color);
318 extern const char *scols_line_get_color(const struct libscols_line *ln);
319 extern size_t scols_line_get_ncells(const struct libscols_line *ln);
320 extern struct libscols_cell *scols_line_get_cell(struct libscols_line *ln, size_t n);
321 extern struct libscols_cell *scols_line_get_column_cell(
322 struct libscols_line *ln,
323 struct libscols_column *cl);
324 extern int scols_line_set_data(struct libscols_line *ln, size_t n, const char *data);
325 extern int scols_line_refer_data(struct libscols_line *ln, size_t n, char *data);
326 extern int scols_line_vprintf(struct libscols_line *ln, size_t n, const char *fmt, va_list ap)
327 __ul_attribute__((format(printf, 3, 0)));
328 extern int scols_line_sprintf(struct libscols_line *ln, size_t n, const char *fmt, ...)
329 __ul_attribute__((format(printf, 3, 4)));
330 extern int scols_line_is_filled(struct libscols_line *ln, size_t n);
331 extern int scols_line_set_column_data(struct libscols_line *ln, struct libscols_column *cl, const char *data);
332 extern const char *scols_line_get_column_data(struct libscols_line *ln, struct libscols_column *cl);
333 extern int scols_line_refer_column_data(struct libscols_line *ln, struct libscols_column *cl, char *data);
334 extern int scols_line_vprintf_column(struct libscols_line *ln, struct libscols_column *cl, const char *fmt, va_list ap)
335 __ul_attribute__((format(printf, 3, 0)));
336 extern int scols_line_sprintf_column(struct libscols_line *ln, struct libscols_column *cl, const char *fmt, ...)
337 __ul_attribute__((format(printf, 3, 4)));
338 extern struct libscols_line *scols_copy_line(const struct libscols_line *ln);
339
340 /* table */
341 extern int scols_table_colors_wanted(const struct libscols_table *tb);
342 extern int scols_table_set_name(struct libscols_table *tb, const char *name);
343 extern const char *scols_table_get_name(const struct libscols_table *tb);
344 extern struct libscols_cell *scols_table_get_title(struct libscols_table *tb);
345 extern int scols_table_is_raw(const struct libscols_table *tb);
346 extern int scols_table_is_ascii(const struct libscols_table *tb);
347 extern int scols_table_is_json(const struct libscols_table *tb);
348 extern int scols_table_is_noheadings(const struct libscols_table *tb);
349 extern int scols_table_is_header_repeat(const struct libscols_table *tb);
350 extern int scols_table_is_empty(const struct libscols_table *tb);
351 extern int scols_table_is_export(const struct libscols_table *tb);
352 extern int scols_table_is_shellvar(const struct libscols_table *tb);
353 extern int scols_table_is_maxout(const struct libscols_table *tb);
354 extern int scols_table_is_minout(const struct libscols_table *tb);
355 extern int scols_table_is_nowrap(const struct libscols_table *tb);
356 extern int scols_table_is_nolinesep(const struct libscols_table *tb);
357 extern int scols_table_is_tree(const struct libscols_table *tb);
358 extern int scols_table_is_noencoding(const struct libscols_table *tb);
359
360 extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
361 extern int scols_table_enable_raw(struct libscols_table *tb, int enable);
362 extern int scols_table_enable_ascii(struct libscols_table *tb, int enable);
363 extern int scols_table_enable_json(struct libscols_table *tb, int enable);
364 extern int scols_table_enable_noheadings(struct libscols_table *tb, int enable);
365 extern int scols_table_enable_header_repeat(struct libscols_table *tb, int enable);
366 extern int scols_table_enable_export(struct libscols_table *tb, int enable);
367 extern int scols_table_enable_shellvar(struct libscols_table *tb, int enable);
368 extern int scols_table_enable_maxout(struct libscols_table *tb, int enable);
369 extern int scols_table_enable_minout(struct libscols_table *tb, int enable);
370 extern int scols_table_enable_nowrap(struct libscols_table *tb, int enable);
371 extern int scols_table_enable_nolinesep(struct libscols_table *tb, int enable);
372 extern int scols_table_enable_noencoding(struct libscols_table *tb, int enable);
373
374 extern int scols_table_set_column_separator(struct libscols_table *tb, const char *sep);
375 extern int scols_table_set_line_separator(struct libscols_table *tb, const char *sep);
376
377 extern struct libscols_table *scols_new_table(void);
378 extern void scols_ref_table(struct libscols_table *tb);
379 extern void scols_unref_table(struct libscols_table *tb);
380 extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl);
381 extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl);
382 extern int scols_table_remove_columns(struct libscols_table *tb);
383 extern int scols_table_move_column(struct libscols_table *tb, struct libscols_column *pre, struct libscols_column *cl);
384 extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
385 extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl);
386 extern int scols_table_set_columns_iter(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column *cl);
387 extern const char *scols_table_get_column_separator(const struct libscols_table *tb);
388 extern const char *scols_table_get_line_separator(const struct libscols_table *tb);
389 extern size_t scols_table_get_ncols(const struct libscols_table *tb);
390 extern size_t scols_table_get_nlines(const struct libscols_table *tb);
391 extern struct libscols_column *scols_table_get_column(struct libscols_table *tb, size_t n);
392 struct libscols_column *scols_table_get_column_by_name(struct libscols_table *tb, const char *name);
393 extern int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln);
394 extern int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln);
395 extern void scols_table_remove_lines(struct libscols_table *tb);
396 extern int scols_table_next_line(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_line **ln);
397 extern struct libscols_line *scols_table_new_line(struct libscols_table *tb, struct libscols_line *parent);
398 extern struct libscols_line *scols_table_get_line(struct libscols_table *tb, size_t n);
399 extern struct libscols_table *scols_copy_table(struct libscols_table *tb);
400 extern int scols_table_set_symbols(struct libscols_table *tb, struct libscols_symbols *sy);
401 extern int scols_table_set_default_symbols(struct libscols_table *tb);
402 extern struct libscols_symbols *scols_table_get_symbols(const struct libscols_table *tb);
403
404 extern int scols_table_set_stream(struct libscols_table *tb, FILE *stream);
405 extern FILE *scols_table_get_stream(const struct libscols_table *tb);
406 extern int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce);
407
408 extern int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl);
409 extern int scols_sort_table_by_tree(struct libscols_table *tb);
410
411 extern int scols_table_get_cursor(struct libscols_table *tb,
412 struct libscols_line **ln,
413 struct libscols_column **cl,
414 struct libscols_cell **ce);
415
416 /*
417 *
418 */
419 enum {
420 SCOLS_TERMFORCE_AUTO = 0,
421 SCOLS_TERMFORCE_NEVER,
422 SCOLS_TERMFORCE_ALWAYS
423 };
424 extern int scols_table_set_termforce(struct libscols_table *tb, int force);
425 extern int scols_table_get_termforce(const struct libscols_table *tb);
426 extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
427 extern size_t scols_table_get_termwidth(const struct libscols_table *tb);
428 extern int scols_table_set_termheight(struct libscols_table *tb, size_t height);
429 extern size_t scols_table_get_termheight(const struct libscols_table *tb);
430
431
432 /* table_print.c */
433 extern int scols_print_table(struct libscols_table *tb);
434 extern int scols_print_table_to_string(struct libscols_table *tb, char **data);
435
436 extern int scols_table_print_range( struct libscols_table *tb,
437 struct libscols_line *start,
438 struct libscols_line *end);
439 extern int scols_table_print_range_to_string( struct libscols_table *tb,
440 struct libscols_line *start,
441 struct libscols_line *end,
442 char **data);
443
444 /* grouping.c */
445 int scols_line_link_group(struct libscols_line *ln, struct libscols_line *member, int id);
446 int scols_table_group_lines(struct libscols_table *tb, struct libscols_line *ln,
447 struct libscols_line *member, int id);
448
449 /* filter.c */
450 extern int scols_filter_parse_string(struct libscols_filter *fltr, const char *str);
451 extern struct libscols_filter *scols_new_filter(const char *str);
452 extern void scols_ref_filter(struct libscols_filter *fltr);
453 extern void scols_unref_filter(struct libscols_filter *fltr);
454 extern int scols_dump_filter(struct libscols_filter *fltr, FILE *out);
455 extern const char *scols_filter_get_errmsg(struct libscols_filter *fltr);
456
457 extern int scols_line_apply_filter(struct libscols_line *ln,
458 struct libscols_filter *fltr, int *status);
459
460 extern int scols_filter_next_holder(struct libscols_filter *fltr,
461 struct libscols_iter *itr, const char **name, int type);
462 extern int scols_filter_has_holder(struct libscols_filter *fltr, const char *name);
463
464 extern int scols_filter_assign_column(struct libscols_filter *fltr,
465 struct libscols_iter *itr,
466 const char *name, struct libscols_column *col);
467 extern int scols_filter_set_filler_cb(struct libscols_filter *fltr,
468 int (*cb)(struct libscols_filter *,
469 struct libscols_line *, size_t, void *),
470 void *userdata);
471
472 extern struct libscols_counter *scols_filter_new_counter(struct libscols_filter *fltr);
473 extern int scols_counter_set_name(struct libscols_counter *ct, const char *name);
474 extern int scols_counter_set_param(struct libscols_counter *ct, const char *name);
475 extern int scols_counter_set_func(struct libscols_counter *ct, int func);
476
477 extern unsigned long long scols_counter_get_result(struct libscols_counter *ct);
478 extern const char *scols_counter_get_name(struct libscols_counter *ct);
479 extern int scols_filter_next_counter(struct libscols_filter *fltr,
480 struct libscols_iter *itr, struct libscols_counter **ct);
481
482 #ifdef __cplusplus
483 }
484 #endif
485
486 #endif /* _LIBSMARTCOLS_H */