]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/format-table.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / shared / format-table.h
CommitLineData
1960e736
LP
1/* SPDX-License-Identifier: LGPL-2.1+ */
2#pragma once
3
4#include <stdbool.h>
5#include <stdio.h>
6#include <sys/types.h>
7
31ac2357 8#include "json.h"
1960e736
LP
9#include "macro.h"
10
11typedef enum TableDataType {
12 TABLE_EMPTY,
13 TABLE_STRING,
14 TABLE_BOOLEAN,
15 TABLE_TIMESTAMP,
16 TABLE_TIMESPAN,
17 TABLE_SIZE,
18 TABLE_UINT32,
a4661181
LP
19 TABLE_UINT64,
20 TABLE_PERCENT,
1960e736
LP
21 _TABLE_DATA_TYPE_MAX,
22 _TABLE_DATA_TYPE_INVALID = -1,
23} TableDataType;
24
25typedef struct Table Table;
26typedef struct TableCell TableCell;
27
28Table *table_new_internal(const char *first_header, ...) _sentinel_;
29#define table_new(...) table_new_internal(__VA_ARGS__, NULL)
30Table *table_new_raw(size_t n_columns);
31Table *table_unref(Table *t);
32
33DEFINE_TRIVIAL_CLEANUP_FUNC(Table*, table_unref);
34
35int table_add_cell_full(Table *t, TableCell **ret_cell, TableDataType type, const void *data, size_t minimum_width, size_t maximum_width, unsigned weight, unsigned align_percent, unsigned ellipsize_percent);
36static inline int table_add_cell(Table *t, TableCell **ret_cell, TableDataType type, const void *data) {
37 return table_add_cell_full(t, ret_cell, type, data, (size_t) -1, (size_t) -1, (unsigned) -1, (unsigned) -1, (unsigned) -1);
38}
39
40int table_dup_cell(Table *t, TableCell *cell);
41
42int table_set_minimum_width(Table *t, TableCell *cell, size_t minimum_width);
43int table_set_maximum_width(Table *t, TableCell *cell, size_t maximum_width);
44int table_set_weight(Table *t, TableCell *cell, unsigned weight);
45int table_set_align_percent(Table *t, TableCell *cell, unsigned percent);
46int table_set_ellipsize_percent(Table *t, TableCell *cell, unsigned percent);
47int table_set_color(Table *t, TableCell *cell, const char *color);
165ca566 48int table_set_url(Table *t, TableCell *cell, const char *color);
359abf6d 49int table_set_uppercase(Table *t, TableCell *cell, bool b);
1960e736 50
27e730e6
LP
51int table_update(Table *t, TableCell *cell, TableDataType type, const void *data);
52
1960e736
LP
53int table_add_many_internal(Table *t, TableDataType first_type, ...);
54#define table_add_many(t, ...) table_add_many_internal(t, __VA_ARGS__, _TABLE_DATA_TYPE_MAX)
55
56void table_set_header(Table *table, bool b);
57void table_set_width(Table *t, size_t width);
58int table_set_display(Table *t, size_t first_column, ...);
59int table_set_sort(Table *t, size_t first_column, ...);
a2c73e2d 60int table_set_reverse(Table *t, size_t column, bool b);
1960e736
LP
61
62int table_print(Table *t, FILE *f);
63int table_format(Table *t, char **ret);
64
65static inline TableCell* TABLE_HEADER_CELL(size_t i) {
66 return SIZE_TO_PTR(i + 1);
67}
68
69size_t table_get_rows(Table *t);
70size_t table_get_columns(Table *t);
9314ead7
LP
71
72TableCell *table_get_cell(Table *t, size_t row, size_t column);
62d99b39
LP
73
74const void *table_get(Table *t, TableCell *cell);
75const void *table_get_at(Table *t, size_t row, size_t column);
31ac2357
LP
76
77int table_to_json(Table *t, JsonVariant **ret);
78int table_print_json(Table *t, FILE *f, unsigned json_flags);