]> git.ipfire.org Git - thirdparty/util-linux.git/blob - libsmartcols/src/smartcolsP.h
misc: Fix various typos
[thirdparty/util-linux.git] / libsmartcols / src / smartcolsP.h
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 "debug.h"
19
20 #include "libsmartcols.h"
21
22 /*
23 * Debug
24 */
25 #define SCOLS_DEBUG_HELP (1 << 0)
26 #define SCOLS_DEBUG_INIT (1 << 1)
27 #define SCOLS_DEBUG_CELL (1 << 2)
28 #define SCOLS_DEBUG_LINE (1 << 3)
29 #define SCOLS_DEBUG_TAB (1 << 4)
30 #define SCOLS_DEBUG_COL (1 << 5)
31 #define SCOLS_DEBUG_BUFF (1 << 6)
32 #define SCOLS_DEBUG_ALL 0xFFFF
33
34 UL_DEBUG_DECLARE_MASK(libsmartcols);
35 #define DBG(m, x) __UL_DBG(libsmartcols, SCOLS_DEBUG_, m, x)
36 #define ON_DBG(m, x) __UL_DBG_CALL(libsmartcols, SCOLS_DEBUG_, m, x)
37 #define DBG_FLUSH __UL_DBG_FLUSH(libsmartcols, SCOLS_DEBUG_)
38
39 /*
40 * Generic iterator
41 */
42 struct libscols_iter {
43 struct list_head *p; /* current position */
44 struct list_head *head; /* start position */
45 int direction; /* SCOLS_ITER_{FOR,BACK}WARD */
46 };
47
48 /*
49 * Tree symbols
50 */
51 struct libscols_symbols {
52 int refcount;
53 char *branch;
54 char *vert;
55 char *right;
56 char *title_padding;
57 };
58
59 /*
60 * Table cells
61 */
62 struct libscols_cell {
63 char *data;
64 char *color;
65 void *userdata;
66 int flags;
67 };
68
69
70 /*
71 * Table column
72 */
73 struct libscols_column {
74 int refcount; /* reference counter */
75 size_t seqnum; /* column index */
76
77 size_t width; /* real column width */
78 size_t width_min; /* minimal width (usually header width) */
79 size_t width_max; /* maximal width */
80 size_t width_avg; /* average width, used to detect extreme fields */
81 size_t width_treeart; /* size of the tree ascii art */
82 double width_hint; /* hint (N < 1 is in percent of termwidth) */
83
84 int flags;
85 int is_extreme;
86 char *color; /* default column color */
87
88 char *pending_data;
89 size_t pending_data_sz;
90 char *pending_data_buf;
91
92 int (*cmpfunc)(struct libscols_cell *,
93 struct libscols_cell *,
94 void *); /* cells comparison function */
95 void *cmpfunc_data;
96
97 struct libscols_cell header;
98 struct list_head cl_columns;
99
100 struct libscols_table *table;
101 };
102
103 /*
104 * Table line
105 */
106 struct libscols_line {
107 int refcount;
108 size_t seqnum;
109
110 void *userdata;
111 char *color; /* default line color */
112
113 struct libscols_cell *cells; /* array with data */
114 size_t ncells; /* number of cells */
115
116 struct list_head ln_lines; /* table lines */
117 struct list_head ln_branch; /* begin of branch (head of ln_children) */
118 struct list_head ln_children;
119
120 struct libscols_line *parent;
121 };
122
123 enum {
124 SCOLS_FMT_HUMAN = 0, /* default, human readable */
125 SCOLS_FMT_RAW, /* space separated */
126 SCOLS_FMT_EXPORT, /* COLNAME="data" ... */
127 SCOLS_FMT_JSON /* http://en.wikipedia.org/wiki/JSON */
128 };
129
130 /*
131 * The table
132 */
133 struct libscols_table {
134 int refcount;
135 char *name; /* optional table name (for JSON) */
136 size_t ncols; /* number of columns */
137 size_t ntreecols; /* number of columns with SCOLS_FL_TREE */
138 size_t nlines; /* number of lines */
139 size_t termwidth; /* terminal width */
140 size_t termreduce; /* extra blank space */
141 FILE *out; /* output stream */
142
143 char *colsep; /* column separator */
144 char *linesep; /* line separator */
145
146 struct list_head tb_columns;
147 struct list_head tb_lines;
148 struct libscols_symbols *symbols;
149 struct libscols_cell title; /* optional table title (for humans) */
150
151 int indent; /* indention counter */
152 int indent_last_sep;/* last printed has been line separator */
153 int format; /* SCOLS_FMT_* */
154
155 /* flags */
156 unsigned int ascii :1, /* don't use unicode */
157 colors_wanted :1, /* enable colors */
158 is_term :1, /* isatty() */
159 maxout :1, /* maximize output */
160 header_printed :1, /* header already printed */
161 no_headings :1, /* don't print header */
162 no_linesep :1, /* don't print line separator */
163 no_wrap :1; /* never wrap lines */
164 };
165
166 #define IS_ITER_FORWARD(_i) ((_i)->direction == SCOLS_ITER_FORWARD)
167 #define IS_ITER_BACKWARD(_i) ((_i)->direction == SCOLS_ITER_BACKWARD)
168
169 #define SCOLS_ITER_INIT(itr, list) \
170 do { \
171 (itr)->p = IS_ITER_FORWARD(itr) ? \
172 (list)->next : (list)->prev; \
173 (itr)->head = (list); \
174 } while(0)
175
176 #define SCOLS_ITER_ITERATE(itr, res, restype, member) \
177 do { \
178 res = list_entry((itr)->p, restype, member); \
179 (itr)->p = IS_ITER_FORWARD(itr) ? \
180 (itr)->p->next : (itr)->p->prev; \
181 } while(0)
182
183
184 static inline int scols_iter_is_last(struct libscols_iter *itr)
185 {
186 if (!itr || !itr->head || !itr->p)
187 return 0;
188
189 return itr->p == itr->head;
190 }
191
192 #endif /* _LIBSMARTCOLS_PRIVATE_H */