]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - libsmartcols/src/smartcolsP.h
2 * smartcolsP.h - private library header file
4 * Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
5 * Copyright (C) 2014 Karel Zak <kzak@redhat.com>
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
11 #ifndef _LIBSMARTCOLS_PRIVATE_H
12 #define _LIBSMARTCOLS_PRIVATE_H
17 #include "color-names.h"
20 #include "libsmartcols.h"
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
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_)
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 */
51 struct libscols_symbols
{
62 struct libscols_cell
{
73 struct libscols_column
{
74 int refcount
; /* reference counter */
75 size_t seqnum
; /* column index */
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) */
86 char *color
; /* default column color */
89 size_t pending_data_sz
;
90 char *pending_data_buf
;
92 int (*cmpfunc
)(struct libscols_cell
*,
93 struct libscols_cell
*,
94 void *); /* cells comparison function */
97 struct libscols_cell header
;
98 struct list_head cl_columns
;
100 struct libscols_table
*table
;
106 struct libscols_line
{
111 char *color
; /* default line color */
113 struct libscols_cell
*cells
; /* array with data */
114 size_t ncells
; /* number of cells */
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
;
120 struct libscols_line
*parent
;
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 */
133 struct libscols_table
{
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 */
143 char *colsep
; /* column separator */
144 char *linesep
; /* line separator */
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) */
151 int indent
; /* indention counter */
152 int indent_last_sep
;/* last printed has been line separator */
153 int format
; /* SCOLS_FMT_* */
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 */
166 #define IS_ITER_FORWARD(_i) ((_i)->direction == SCOLS_ITER_FORWARD)
167 #define IS_ITER_BACKWARD(_i) ((_i)->direction == SCOLS_ITER_BACKWARD)
169 #define SCOLS_ITER_INIT(itr, list) \
171 (itr)->p = IS_ITER_FORWARD(itr) ? \
172 (list)->next : (list)->prev; \
173 (itr)->head = (list); \
176 #define SCOLS_ITER_ITERATE(itr, res, restype, member) \
178 res = list_entry((itr)->p, restype, member); \
179 (itr)->p = IS_ITER_FORWARD(itr) ? \
180 (itr)->p->next : (itr)->p->prev; \
184 static inline int scols_iter_is_last(struct libscols_iter
*itr
)
186 if (!itr
|| !itr
->head
|| !itr
->p
)
189 return itr
->p
== itr
->head
;
192 #endif /* _LIBSMARTCOLS_PRIVATE_H */