]>
Commit | Line | Data |
---|---|---|
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 | |
14 | extern "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 | 33 | struct libscols_iter; |
1d90bcb1 OO |
34 | |
35 | /** | |
36 | * libscols_symbols: | |
37 | * | |
38 | * Symbol groups for printing tree hierarchies | |
39 | */ | |
b36992fb | 40 | struct libscols_symbols; |
1d90bcb1 OO |
41 | |
42 | /** | |
43 | * libscols_cell: | |
44 | * | |
45 | * A cell - the smallest library object | |
46 | */ | |
6d107269 | 47 | struct libscols_cell; |
1d90bcb1 OO |
48 | |
49 | /** | |
50 | * libscols_line: | |
51 | * | |
52 | * A line - an array of cells | |
53 | */ | |
3e542c76 | 54 | struct 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 | 61 | struct libscols_table; |
1d90bcb1 OO |
62 | |
63 | /** | |
64 | * libscols_column: | |
65 | * | |
66 | * A column - defines the number of columns and column names | |
67 | */ | |
8a38a8d3 | 68 | struct libscols_column; |
0b0ab9ff OO |
69 | |
70 | /* iter.c */ | |
71 | enum { | |
72 | ||
73 | SCOLS_ITER_FORWARD = 0, | |
74 | SCOLS_ITER_BACKWARD | |
75 | }; | |
76 | ||
1d90bcb1 OO |
77 | /* |
78 | * Column flags | |
79 | */ | |
8b992cb5 | 80 | enum { |
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 | */ | |
93 | enum { | |
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 | */ |
102 | enum { | |
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 |
109 | extern struct libscols_iter *scols_new_iter(int direction); |
110 | extern void scols_free_iter(struct libscols_iter *itr); | |
111 | extern void scols_reset_iter(struct libscols_iter *itr, int direction); | |
f7a9ea28 | 112 | extern int scols_iter_get_direction(const struct libscols_iter *itr); |
1a4d989e | 113 | |
4418714f KZ |
114 | /* init.c */ |
115 | extern void scols_init_debug(int mask); | |
116 | ||
117 | /* version.c */ | |
118 | extern int scols_parse_version_string(const char *ver_string); | |
119 | extern int scols_get_library_version(const char **ver_string); | |
120 | ||
b36992fb OO |
121 | /* symbols.c */ |
122 | extern struct libscols_symbols *scols_new_symbols(void); | |
3e542c76 KZ |
123 | extern void scols_ref_symbols(struct libscols_symbols *sy); |
124 | extern void scols_unref_symbols(struct libscols_symbols *sy); | |
4fb899ed IG |
125 | extern struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sy); |
126 | extern int scols_symbols_set_branch(struct libscols_symbols *sy, const char *str); | |
127 | extern int scols_symbols_set_vertical(struct libscols_symbols *sy, const char *str); | |
128 | extern int scols_symbols_set_right(struct libscols_symbols *sy, const char *str); | |
129 | extern int scols_symbols_set_title_padding(struct libscols_symbols *sy, const char *str); | |
130 | extern int scols_symbols_set_cell_padding(struct libscols_symbols *sy, const char *str); | |
b36992fb | 131 | |
d52f5542 KZ |
132 | extern int scols_symbols_set_group_vertical(struct libscols_symbols *sy, const char *str); |
133 | extern int scols_symbols_set_group_horizontal(struct libscols_symbols *sy, const char *str); | |
134 | extern int scols_symbols_set_group_first_member(struct libscols_symbols *sy, const char *str); | |
135 | extern int scols_symbols_set_group_last_member(struct libscols_symbols *sy, const char *str); | |
136 | extern int scols_symbols_set_group_middle_member(struct libscols_symbols *sy, const char *str); | |
137 | extern int scols_symbols_set_group_last_child(struct libscols_symbols *sy, const char *str); | |
138 | extern int scols_symbols_set_group_middle_child(struct libscols_symbols *sy, const char *str); | |
139 | ||
6d107269 | 140 | /* cell.c */ |
1577b259 | 141 | extern int scols_reset_cell(struct libscols_cell *ce); |
74bd28ad KZ |
142 | extern int scols_cell_copy_content(struct libscols_cell *dest, |
143 | const struct libscols_cell *src); | |
618a1d6d IG |
144 | extern int scols_cell_set_data(struct libscols_cell *ce, const char *data); |
145 | extern int scols_cell_refer_data(struct libscols_cell *ce, char *data); | |
6d107269 OO |
146 | extern const char *scols_cell_get_data(const struct libscols_cell *ce); |
147 | extern int scols_cell_set_color(struct libscols_cell *ce, const char *color); | |
148 | extern const char *scols_cell_get_color(const struct libscols_cell *ce); | |
149 | ||
e865838d KZ |
150 | extern int scols_cell_set_flags(struct libscols_cell *ce, int flags); |
151 | extern int scols_cell_get_flags(const struct libscols_cell *ce); | |
6ffbd283 | 152 | extern int scols_cell_get_alignment(const struct libscols_cell *ce); |
e865838d | 153 | |
57a86f9b KZ |
154 | extern void *scols_cell_get_userdata(struct libscols_cell *ce); |
155 | extern int scols_cell_set_userdata(struct libscols_cell *ce, void *data); | |
156 | ||
157 | extern int scols_cmpstr_cells(struct libscols_cell *a, | |
158 | struct libscols_cell *b, void *data); | |
1577b259 | 159 | /* column.c */ |
f7a9ea28 IG |
160 | extern int scols_column_is_tree(const struct libscols_column *cl); |
161 | extern int scols_column_is_trunc(const struct libscols_column *cl); | |
162 | extern int scols_column_is_right(const struct libscols_column *cl); | |
163 | extern int scols_column_is_strict_width(const struct libscols_column *cl); | |
164 | extern int scols_column_is_hidden(const struct libscols_column *cl); | |
165 | extern int scols_column_is_noextremes(const struct libscols_column *cl); | |
166 | extern int scols_column_is_wrap(const struct libscols_column *cl); | |
949ea05f KZ |
167 | extern int scols_column_is_customwrap(const struct libscols_column *cl); |
168 | ||
82053f5e KZ |
169 | extern size_t scols_column_get_width(const struct libscols_column *cl); |
170 | ||
949ea05f KZ |
171 | extern int scols_column_set_safechars(struct libscols_column *cl, const char *safe); |
172 | extern const char *scols_column_get_safechars(const struct libscols_column *cl); | |
8a38a8d3 | 173 | |
b2c871f9 KZ |
174 | extern int scols_column_set_json_type(struct libscols_column *cl, int type); |
175 | extern int scols_column_get_json_type(const struct libscols_column *cl); | |
176 | ||
8b992cb5 | 177 | extern int scols_column_set_flags(struct libscols_column *cl, int flags); |
f7a9ea28 | 178 | extern int scols_column_get_flags(const struct libscols_column *cl); |
1577b259 KZ |
179 | extern struct libscols_column *scols_new_column(void); |
180 | extern void scols_ref_column(struct libscols_column *cl); | |
181 | extern void scols_unref_column(struct libscols_column *cl); | |
182 | extern struct libscols_column *scols_copy_column(const struct libscols_column *cl); | |
183 | extern int scols_column_set_whint(struct libscols_column *cl, double whint); | |
f7a9ea28 | 184 | extern double scols_column_get_whint(const struct libscols_column *cl); |
74bd28ad | 185 | extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl); |
1577b259 | 186 | extern int scols_column_set_color(struct libscols_column *cl, const char *color); |
f7a9ea28 | 187 | extern const char *scols_column_get_color(const struct libscols_column *cl); |
68a7f92b | 188 | extern struct libscols_table *scols_column_get_table(const struct libscols_column *cl); |
1577b259 | 189 | |
57a86f9b KZ |
190 | extern 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 |
195 | extern 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 | |
202 | extern char *scols_wrapnl_nextchunk(const struct libscols_column *cl, char *data, void *userdata); | |
203 | extern size_t scols_wrapnl_chunksize(const struct libscols_column *cl, const char *data, void *userdata); | |
204 | ||
3e542c76 KZ |
205 | /* line.c */ |
206 | extern struct libscols_line *scols_new_line(void); | |
207 | extern void scols_ref_line(struct libscols_line *ln); | |
208 | extern void scols_unref_line(struct libscols_line *ln); | |
209 | extern int scols_line_alloc_cells(struct libscols_line *ln, size_t n); | |
210 | extern void scols_line_free_cells(struct libscols_line *ln); | |
211 | extern int scols_line_set_userdata(struct libscols_line *ln, void *data); | |
212 | extern void *scols_line_get_userdata(struct libscols_line *ln); | |
213 | extern int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *child); | |
214 | extern int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child); | |
7e8fe029 | 215 | extern int scols_line_has_children(struct libscols_line *ln); |
eebf2dd8 | 216 | extern int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *parent); |
7e8fe029 KZ |
217 | extern int scols_line_next_child(struct libscols_line *ln, |
218 | struct libscols_iter *itr, struct libscols_line **chld); | |
f7a9ea28 | 219 | extern struct libscols_line *scols_line_get_parent(const struct libscols_line *ln); |
3e542c76 | 220 | extern int scols_line_set_color(struct libscols_line *ln, const char *color); |
f7a9ea28 IG |
221 | extern const char *scols_line_get_color(const struct libscols_line *ln); |
222 | extern size_t scols_line_get_ncells(const struct libscols_line *ln); | |
3e542c76 | 223 | extern struct libscols_cell *scols_line_get_cell(struct libscols_line *ln, size_t n); |
57a86f9b KZ |
224 | extern struct libscols_cell *scols_line_get_column_cell( |
225 | struct libscols_line *ln, | |
226 | struct libscols_column *cl); | |
3e542c76 KZ |
227 | extern int scols_line_set_data(struct libscols_line *ln, size_t n, const char *data); |
228 | extern int scols_line_refer_data(struct libscols_line *ln, size_t n, char *data); | |
78371865 KZ |
229 | extern int scols_line_set_column_data(struct libscols_line *ln, struct libscols_column *cl, const char *data); |
230 | extern int scols_line_refer_column_data(struct libscols_line *ln, struct libscols_column *cl, char *data); | |
f7a9ea28 | 231 | extern struct libscols_line *scols_copy_line(const struct libscols_line *ln); |
3e542c76 KZ |
232 | |
233 | /* table */ | |
f7a9ea28 | 234 | extern int scols_table_colors_wanted(const struct libscols_table *tb); |
2a6cfc13 | 235 | extern int scols_table_set_name(struct libscols_table *tb, const char *name); |
96960717 | 236 | extern const char *scols_table_get_name(const struct libscols_table *tb); |
e865838d | 237 | extern struct libscols_cell *scols_table_get_title(struct libscols_table *tb); |
f7a9ea28 IG |
238 | extern int scols_table_is_raw(const struct libscols_table *tb); |
239 | extern int scols_table_is_ascii(const struct libscols_table *tb); | |
240 | extern int scols_table_is_json(const struct libscols_table *tb); | |
241 | extern int scols_table_is_noheadings(const struct libscols_table *tb); | |
36e07ceb | 242 | extern int scols_table_is_header_repeat(const struct libscols_table *tb); |
f7a9ea28 IG |
243 | extern int scols_table_is_empty(const struct libscols_table *tb); |
244 | extern int scols_table_is_export(const struct libscols_table *tb); | |
245 | extern int scols_table_is_maxout(const struct libscols_table *tb); | |
94dbb322 | 246 | extern int scols_table_is_minout(const struct libscols_table *tb); |
8427c2ec | 247 | extern int scols_table_is_nowrap(const struct libscols_table *tb); |
43e06c67 | 248 | extern int scols_table_is_nolinesep(const struct libscols_table *tb); |
f7a9ea28 | 249 | extern int scols_table_is_tree(const struct libscols_table *tb); |
28a3cc83 | 250 | extern int scols_table_is_noencoding(const struct libscols_table *tb); |
8a38a8d3 OO |
251 | |
252 | extern int scols_table_enable_colors(struct libscols_table *tb, int enable); | |
0925a9dd KZ |
253 | extern int scols_table_enable_raw(struct libscols_table *tb, int enable); |
254 | extern int scols_table_enable_ascii(struct libscols_table *tb, int enable); | |
2a6cfc13 | 255 | extern int scols_table_enable_json(struct libscols_table *tb, int enable); |
0925a9dd | 256 | extern int scols_table_enable_noheadings(struct libscols_table *tb, int enable); |
36e07ceb | 257 | extern int scols_table_enable_header_repeat(struct libscols_table *tb, int enable); |
0925a9dd KZ |
258 | extern int scols_table_enable_export(struct libscols_table *tb, int enable); |
259 | extern int scols_table_enable_maxout(struct libscols_table *tb, int enable); | |
94dbb322 | 260 | extern int scols_table_enable_minout(struct libscols_table *tb, int enable); |
df73852b | 261 | extern int scols_table_enable_nowrap(struct libscols_table *tb, int enable); |
2981e0fd | 262 | extern int scols_table_enable_nolinesep(struct libscols_table *tb, int enable); |
28a3cc83 | 263 | extern int scols_table_enable_noencoding(struct libscols_table *tb, int enable); |
0925a9dd | 264 | |
4baab7df KZ |
265 | extern int scols_table_set_column_separator(struct libscols_table *tb, const char *sep); |
266 | extern int scols_table_set_line_separator(struct libscols_table *tb, const char *sep); | |
d1b4d14f | 267 | |
0925a9dd | 268 | extern struct libscols_table *scols_new_table(void); |
3e542c76 KZ |
269 | extern void scols_ref_table(struct libscols_table *tb); |
270 | extern void scols_unref_table(struct libscols_table *tb); | |
0925a9dd | 271 | extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl); |
3e542c76 KZ |
272 | extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl); |
273 | extern int scols_table_remove_columns(struct libscols_table *tb); | |
7bdefc7f | 274 | extern int scols_table_move_column(struct libscols_table *tb, struct libscols_column *pre, struct libscols_column *cl); |
8b992cb5 | 275 | extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags); |
3e542c76 | 276 | extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl); |
94dbb322 | 277 | extern int scols_table_set_columns_iter(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column *cl); |
f7a9ea28 IG |
278 | extern const char *scols_table_get_column_separator(const struct libscols_table *tb); |
279 | extern const char *scols_table_get_line_separator(const struct libscols_table *tb); | |
280 | extern size_t scols_table_get_ncols(const struct libscols_table *tb); | |
281 | extern size_t scols_table_get_nlines(const struct libscols_table *tb); | |
3e542c76 KZ |
282 | extern struct libscols_column *scols_table_get_column(struct libscols_table *tb, size_t n); |
283 | extern int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln); | |
284 | extern int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln); | |
285 | extern void scols_table_remove_lines(struct libscols_table *tb); | |
286 | extern int scols_table_next_line(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_line **ln); | |
287 | extern struct libscols_line *scols_table_new_line(struct libscols_table *tb, struct libscols_line *parent); | |
288 | extern struct libscols_line *scols_table_get_line(struct libscols_table *tb, size_t n); | |
289 | extern struct libscols_table *scols_copy_table(struct libscols_table *tb); | |
290 | extern int scols_table_set_symbols(struct libscols_table *tb, struct libscols_symbols *sy); | |
63168cf9 KZ |
291 | extern int scols_table_set_default_symbols(struct libscols_table *tb); |
292 | extern struct libscols_symbols *scols_table_get_symbols(const struct libscols_table *tb); | |
3e542c76 | 293 | |
571441e2 | 294 | extern int scols_table_set_stream(struct libscols_table *tb, FILE *stream); |
f7a9ea28 | 295 | extern FILE *scols_table_get_stream(const struct libscols_table *tb); |
e906be06 | 296 | extern int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce); |
571441e2 | 297 | |
57a86f9b | 298 | extern int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl); |
066f46e0 | 299 | extern int scols_sort_table_by_tree(struct libscols_table *tb); |
19055a25 KZ |
300 | /* |
301 | * | |
302 | */ | |
303 | enum { | |
304 | SCOLS_TERMFORCE_AUTO = 0, | |
305 | SCOLS_TERMFORCE_NEVER, | |
306 | SCOLS_TERMFORCE_ALWAYS | |
307 | }; | |
308 | extern int scols_table_set_termforce(struct libscols_table *tb, int force); | |
f7a9ea28 | 309 | extern int scols_table_get_termforce(const struct libscols_table *tb); |
19055a25 | 310 | extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width); |
e0140aa1 | 311 | extern size_t scols_table_get_termwidth(const struct libscols_table *tb); |
e33b3874 KZ |
312 | extern int scols_table_set_termheight(struct libscols_table *tb, size_t height); |
313 | extern size_t scols_table_get_termheight(const struct libscols_table *tb); | |
19055a25 KZ |
314 | |
315 | ||
3e542c76 KZ |
316 | /* table_print.c */ |
317 | extern int scols_print_table(struct libscols_table *tb); | |
2a965b80 | 318 | extern int scols_print_table_to_string(struct libscols_table *tb, char **data); |
3e542c76 | 319 | |
2a750b4c KZ |
320 | extern int scols_table_print_range( struct libscols_table *tb, |
321 | struct libscols_line *start, | |
322 | struct libscols_line *end); | |
cfa18572 IG |
323 | extern 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 */ |
329 | int scols_line_link_group(struct libscols_line *ln, struct libscols_line *member, int id); | |
330 | int 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 */ |