]> git.ipfire.org Git - thirdparty/util-linux.git/blame - libsmartcols/src/libsmartcols.h.in
libsmartcols: cleanup and extend padding functionality
[thirdparty/util-linux.git] / libsmartcols / src / libsmartcols.h.in
CommitLineData
1a4d989e
OO
1/*
2 * Prints table or tree.
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#ifndef _LIBSMARTCOLS_H
11#define _LIBSMARTCOLS_H
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#include <stdlib.h>
ce44112b 18#include <stdio.h>
1a4d989e
OO
19#include <sys/types.h>
20
e2310281
KZ
21/**
22 * LIBSMARTCOLS_VERSION:
23 *
24 * Library version string
25 */
1a4d989e
OO
26#define LIBSMARTCOLS_VERSION "@LIBSMARTCOLS_VERSION@"
27
1d90bcb1
OO
28/**
29 * libscols_iter:
30 *
31 * Generic iterator
32 */
0b0ab9ff 33struct libscols_iter;
1d90bcb1
OO
34
35/**
36 * libscols_symbols:
37 *
38 * Symbol groups for printing tree hierarchies
39 */
b36992fb 40struct libscols_symbols;
1d90bcb1
OO
41
42/**
43 * libscols_cell:
44 *
45 * A cell - the smallest library object
46 */
6d107269 47struct libscols_cell;
1d90bcb1
OO
48
49/**
50 * libscols_line:
51 *
52 * A line - an array of cells
53 */
3e542c76 54struct libscols_line;
1d90bcb1
OO
55
56/**
57 * libscols_table:
58 *
59 * A table - The most abstract object, encapsulating lines, columns, symbols and cells
60 */
3e542c76 61struct libscols_table;
1d90bcb1
OO
62
63/**
64 * libscols_column:
65 *
66 * A column - defines the number of columns and column names
67 */
8a38a8d3 68struct libscols_column;
0b0ab9ff
OO
69
70/* iter.c */
71enum {
72
73 SCOLS_ITER_FORWARD = 0,
74 SCOLS_ITER_BACKWARD
75};
76
1d90bcb1
OO
77/*
78 * Column flags
79 */
8b992cb5 80enum {
dc365860
KZ
81 SCOLS_FL_TRUNC = (1 << 0), /* truncate fields data if necessary */
82 SCOLS_FL_TREE = (1 << 1), /* use tree "ascii art" */
83 SCOLS_FL_RIGHT = (1 << 2), /* align to the right */
84 SCOLS_FL_STRICTWIDTH = (1 << 3), /* don't reduce width if column is empty */
85 SCOLS_FL_NOEXTREMES = (1 << 4), /* ignore extreme fields when count column width*/
6d6b6d18 86 SCOLS_FL_HIDDEN = (1 << 5), /* maintain data, but don't print */
949ea05f 87 SCOLS_FL_WRAP = (1 << 6) /* wrap long lines to multi-line cells */
8b992cb5
OO
88};
89
b2c871f9
KZ
90/*
91 * Column JSON types
92 */
93enum {
94 SCOLS_JSON_STRING = 0, /* default */
95 SCOLS_JSON_NUMBER = 1,
96 SCOLS_JSON_BOOLEAN = 2
97};
98
b3256eff 99/*
e865838d 100 * Cell flags, see scols_cell_set_flags() before use
b3256eff
IG
101 */
102enum {
6ffbd283
KZ
103 /* alignment evaluated in order: right,center,left */
104 SCOLS_CELL_FL_LEFT = 0,
105 SCOLS_CELL_FL_CENTER = (1 << 0),
106 SCOLS_CELL_FL_RIGHT = (1 << 1)
b3256eff
IG
107};
108
0b0ab9ff
OO
109extern struct libscols_iter *scols_new_iter(int direction);
110extern void scols_free_iter(struct libscols_iter *itr);
111extern void scols_reset_iter(struct libscols_iter *itr, int direction);
f7a9ea28 112extern int scols_iter_get_direction(const struct libscols_iter *itr);
1a4d989e 113
4418714f
KZ
114/* init.c */
115extern void scols_init_debug(int mask);
116
117/* version.c */
118extern int scols_parse_version_string(const char *ver_string);
119extern int scols_get_library_version(const char **ver_string);
120
b36992fb
OO
121/* symbols.c */
122extern struct libscols_symbols *scols_new_symbols(void);
3e542c76
KZ
123extern void scols_ref_symbols(struct libscols_symbols *sy);
124extern void scols_unref_symbols(struct libscols_symbols *sy);
4fb899ed
IG
125extern struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sy);
126extern int scols_symbols_set_branch(struct libscols_symbols *sy, const char *str);
127extern int scols_symbols_set_vertical(struct libscols_symbols *sy, const char *str);
128extern int scols_symbols_set_right(struct libscols_symbols *sy, const char *str);
129extern int scols_symbols_set_title_padding(struct libscols_symbols *sy, const char *str);
130extern int scols_symbols_set_cell_padding(struct libscols_symbols *sy, const char *str);
b36992fb 131
d52f5542
KZ
132extern int scols_symbols_set_group_vertical(struct libscols_symbols *sy, const char *str);
133extern int scols_symbols_set_group_horizontal(struct libscols_symbols *sy, const char *str);
134extern int scols_symbols_set_group_first_member(struct libscols_symbols *sy, const char *str);
135extern int scols_symbols_set_group_last_member(struct libscols_symbols *sy, const char *str);
136extern int scols_symbols_set_group_middle_member(struct libscols_symbols *sy, const char *str);
137extern int scols_symbols_set_group_last_child(struct libscols_symbols *sy, const char *str);
138extern int scols_symbols_set_group_middle_child(struct libscols_symbols *sy, const char *str);
139
6d107269 140/* cell.c */
1577b259 141extern int scols_reset_cell(struct libscols_cell *ce);
74bd28ad
KZ
142extern int scols_cell_copy_content(struct libscols_cell *dest,
143 const struct libscols_cell *src);
618a1d6d
IG
144extern int scols_cell_set_data(struct libscols_cell *ce, const char *data);
145extern int scols_cell_refer_data(struct libscols_cell *ce, char *data);
6d107269
OO
146extern const char *scols_cell_get_data(const struct libscols_cell *ce);
147extern int scols_cell_set_color(struct libscols_cell *ce, const char *color);
148extern const char *scols_cell_get_color(const struct libscols_cell *ce);
149
e865838d
KZ
150extern int scols_cell_set_flags(struct libscols_cell *ce, int flags);
151extern int scols_cell_get_flags(const struct libscols_cell *ce);
6ffbd283 152extern int scols_cell_get_alignment(const struct libscols_cell *ce);
e865838d 153
57a86f9b
KZ
154extern void *scols_cell_get_userdata(struct libscols_cell *ce);
155extern int scols_cell_set_userdata(struct libscols_cell *ce, void *data);
156
157extern int scols_cmpstr_cells(struct libscols_cell *a,
158 struct libscols_cell *b, void *data);
1577b259 159/* column.c */
f7a9ea28
IG
160extern int scols_column_is_tree(const struct libscols_column *cl);
161extern int scols_column_is_trunc(const struct libscols_column *cl);
162extern int scols_column_is_right(const struct libscols_column *cl);
163extern int scols_column_is_strict_width(const struct libscols_column *cl);
164extern int scols_column_is_hidden(const struct libscols_column *cl);
165extern int scols_column_is_noextremes(const struct libscols_column *cl);
166extern int scols_column_is_wrap(const struct libscols_column *cl);
949ea05f
KZ
167extern int scols_column_is_customwrap(const struct libscols_column *cl);
168
82053f5e
KZ
169extern size_t scols_column_get_width(const struct libscols_column *cl);
170
949ea05f
KZ
171extern int scols_column_set_safechars(struct libscols_column *cl, const char *safe);
172extern const char *scols_column_get_safechars(const struct libscols_column *cl);
8a38a8d3 173
b2c871f9
KZ
174extern int scols_column_set_json_type(struct libscols_column *cl, int type);
175extern int scols_column_get_json_type(const struct libscols_column *cl);
176
8b992cb5 177extern int scols_column_set_flags(struct libscols_column *cl, int flags);
f7a9ea28 178extern int scols_column_get_flags(const struct libscols_column *cl);
1577b259
KZ
179extern struct libscols_column *scols_new_column(void);
180extern void scols_ref_column(struct libscols_column *cl);
181extern void scols_unref_column(struct libscols_column *cl);
182extern struct libscols_column *scols_copy_column(const struct libscols_column *cl);
183extern int scols_column_set_whint(struct libscols_column *cl, double whint);
f7a9ea28 184extern double scols_column_get_whint(const struct libscols_column *cl);
74bd28ad 185extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl);
1577b259 186extern int scols_column_set_color(struct libscols_column *cl, const char *color);
f7a9ea28 187extern const char *scols_column_get_color(const struct libscols_column *cl);
68a7f92b 188extern struct libscols_table *scols_column_get_table(const struct libscols_column *cl);
1577b259 189
57a86f9b
KZ
190extern int scols_column_set_cmpfunc(struct libscols_column *cl,
191 int (*cmp)(struct libscols_cell *a,
192 struct libscols_cell *b, void *),
193 void *data);
194
949ea05f
KZ
195extern int scols_column_set_wrapfunc(struct libscols_column *cl,
196 size_t (*wrap_chunksize)(const struct libscols_column *,
197 const char *, void *),
198 char * (*wrap_nextchunk)(const struct libscols_column *,
199 char *, void *),
81b176c4 200 void *userdata);
949ea05f
KZ
201
202extern char *scols_wrapnl_nextchunk(const struct libscols_column *cl, char *data, void *userdata);
203extern size_t scols_wrapnl_chunksize(const struct libscols_column *cl, const char *data, void *userdata);
204
3e542c76
KZ
205/* line.c */
206extern struct libscols_line *scols_new_line(void);
207extern void scols_ref_line(struct libscols_line *ln);
208extern void scols_unref_line(struct libscols_line *ln);
209extern int scols_line_alloc_cells(struct libscols_line *ln, size_t n);
210extern void scols_line_free_cells(struct libscols_line *ln);
211extern int scols_line_set_userdata(struct libscols_line *ln, void *data);
212extern void *scols_line_get_userdata(struct libscols_line *ln);
213extern int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *child);
214extern int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child);
7e8fe029 215extern int scols_line_has_children(struct libscols_line *ln);
eebf2dd8 216extern int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *parent);
7e8fe029
KZ
217extern int scols_line_next_child(struct libscols_line *ln,
218 struct libscols_iter *itr, struct libscols_line **chld);
f7a9ea28 219extern struct libscols_line *scols_line_get_parent(const struct libscols_line *ln);
3e542c76 220extern int scols_line_set_color(struct libscols_line *ln, const char *color);
f7a9ea28
IG
221extern const char *scols_line_get_color(const struct libscols_line *ln);
222extern size_t scols_line_get_ncells(const struct libscols_line *ln);
3e542c76 223extern struct libscols_cell *scols_line_get_cell(struct libscols_line *ln, size_t n);
57a86f9b
KZ
224extern struct libscols_cell *scols_line_get_column_cell(
225 struct libscols_line *ln,
226 struct libscols_column *cl);
3e542c76
KZ
227extern int scols_line_set_data(struct libscols_line *ln, size_t n, const char *data);
228extern int scols_line_refer_data(struct libscols_line *ln, size_t n, char *data);
78371865
KZ
229extern int scols_line_set_column_data(struct libscols_line *ln, struct libscols_column *cl, const char *data);
230extern int scols_line_refer_column_data(struct libscols_line *ln, struct libscols_column *cl, char *data);
f7a9ea28 231extern struct libscols_line *scols_copy_line(const struct libscols_line *ln);
3e542c76
KZ
232
233/* table */
f7a9ea28 234extern int scols_table_colors_wanted(const struct libscols_table *tb);
2a6cfc13 235extern int scols_table_set_name(struct libscols_table *tb, const char *name);
96960717 236extern const char *scols_table_get_name(const struct libscols_table *tb);
e865838d 237extern struct libscols_cell *scols_table_get_title(struct libscols_table *tb);
f7a9ea28
IG
238extern int scols_table_is_raw(const struct libscols_table *tb);
239extern int scols_table_is_ascii(const struct libscols_table *tb);
240extern int scols_table_is_json(const struct libscols_table *tb);
241extern int scols_table_is_noheadings(const struct libscols_table *tb);
36e07ceb 242extern int scols_table_is_header_repeat(const struct libscols_table *tb);
f7a9ea28
IG
243extern int scols_table_is_empty(const struct libscols_table *tb);
244extern int scols_table_is_export(const struct libscols_table *tb);
245extern int scols_table_is_maxout(const struct libscols_table *tb);
94dbb322 246extern int scols_table_is_minout(const struct libscols_table *tb);
8427c2ec 247extern int scols_table_is_nowrap(const struct libscols_table *tb);
43e06c67 248extern int scols_table_is_nolinesep(const struct libscols_table *tb);
f7a9ea28 249extern int scols_table_is_tree(const struct libscols_table *tb);
28a3cc83 250extern int scols_table_is_noencoding(const struct libscols_table *tb);
8a38a8d3
OO
251
252extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
0925a9dd
KZ
253extern int scols_table_enable_raw(struct libscols_table *tb, int enable);
254extern int scols_table_enable_ascii(struct libscols_table *tb, int enable);
2a6cfc13 255extern int scols_table_enable_json(struct libscols_table *tb, int enable);
0925a9dd 256extern int scols_table_enable_noheadings(struct libscols_table *tb, int enable);
36e07ceb 257extern int scols_table_enable_header_repeat(struct libscols_table *tb, int enable);
0925a9dd
KZ
258extern int scols_table_enable_export(struct libscols_table *tb, int enable);
259extern int scols_table_enable_maxout(struct libscols_table *tb, int enable);
94dbb322 260extern int scols_table_enable_minout(struct libscols_table *tb, int enable);
df73852b 261extern int scols_table_enable_nowrap(struct libscols_table *tb, int enable);
2981e0fd 262extern int scols_table_enable_nolinesep(struct libscols_table *tb, int enable);
28a3cc83 263extern int scols_table_enable_noencoding(struct libscols_table *tb, int enable);
0925a9dd 264
4baab7df
KZ
265extern int scols_table_set_column_separator(struct libscols_table *tb, const char *sep);
266extern int scols_table_set_line_separator(struct libscols_table *tb, const char *sep);
d1b4d14f 267
0925a9dd 268extern struct libscols_table *scols_new_table(void);
3e542c76
KZ
269extern void scols_ref_table(struct libscols_table *tb);
270extern void scols_unref_table(struct libscols_table *tb);
0925a9dd 271extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl);
3e542c76
KZ
272extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl);
273extern int scols_table_remove_columns(struct libscols_table *tb);
7bdefc7f 274extern int scols_table_move_column(struct libscols_table *tb, struct libscols_column *pre, struct libscols_column *cl);
8b992cb5 275extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
3e542c76 276extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl);
94dbb322 277extern int scols_table_set_columns_iter(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column *cl);
f7a9ea28
IG
278extern const char *scols_table_get_column_separator(const struct libscols_table *tb);
279extern const char *scols_table_get_line_separator(const struct libscols_table *tb);
280extern size_t scols_table_get_ncols(const struct libscols_table *tb);
281extern size_t scols_table_get_nlines(const struct libscols_table *tb);
3e542c76
KZ
282extern struct libscols_column *scols_table_get_column(struct libscols_table *tb, size_t n);
283extern int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln);
284extern int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln);
285extern void scols_table_remove_lines(struct libscols_table *tb);
286extern int scols_table_next_line(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_line **ln);
287extern struct libscols_line *scols_table_new_line(struct libscols_table *tb, struct libscols_line *parent);
288extern struct libscols_line *scols_table_get_line(struct libscols_table *tb, size_t n);
289extern struct libscols_table *scols_copy_table(struct libscols_table *tb);
290extern int scols_table_set_symbols(struct libscols_table *tb, struct libscols_symbols *sy);
63168cf9
KZ
291extern int scols_table_set_default_symbols(struct libscols_table *tb);
292extern struct libscols_symbols *scols_table_get_symbols(const struct libscols_table *tb);
3e542c76 293
571441e2 294extern int scols_table_set_stream(struct libscols_table *tb, FILE *stream);
f7a9ea28 295extern FILE *scols_table_get_stream(const struct libscols_table *tb);
e906be06 296extern int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce);
571441e2 297
57a86f9b 298extern int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl);
066f46e0 299extern int scols_sort_table_by_tree(struct libscols_table *tb);
19055a25
KZ
300/*
301 *
302 */
303enum {
304 SCOLS_TERMFORCE_AUTO = 0,
305 SCOLS_TERMFORCE_NEVER,
306 SCOLS_TERMFORCE_ALWAYS
307};
308extern int scols_table_set_termforce(struct libscols_table *tb, int force);
f7a9ea28 309extern int scols_table_get_termforce(const struct libscols_table *tb);
19055a25 310extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
e0140aa1 311extern size_t scols_table_get_termwidth(const struct libscols_table *tb);
e33b3874
KZ
312extern int scols_table_set_termheight(struct libscols_table *tb, size_t height);
313extern size_t scols_table_get_termheight(const struct libscols_table *tb);
19055a25
KZ
314
315
3e542c76
KZ
316/* table_print.c */
317extern int scols_print_table(struct libscols_table *tb);
2a965b80 318extern int scols_print_table_to_string(struct libscols_table *tb, char **data);
3e542c76 319
2a750b4c
KZ
320extern int scols_table_print_range( struct libscols_table *tb,
321 struct libscols_line *start,
322 struct libscols_line *end);
cfa18572
IG
323extern int scols_table_print_range_to_string( struct libscols_table *tb,
324 struct libscols_line *start,
325 struct libscols_line *end,
326 char **data);
2a750b4c 327
d52f5542
KZ
328/* grouping.c */
329int scols_line_link_group(struct libscols_line *ln, struct libscols_line *member, int id);
330int scols_table_group_lines(struct libscols_table *tb, struct libscols_line *ln,
331 struct libscols_line *member, int id);
1a4d989e
OO
332#ifdef __cplusplus
333}
334#endif
335
336#endif /* _LIBSMARTCOLS_H */