libsmartcols: (groups) remove hardcoded const numbers
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
74a4d22078
commit
4525b6cf16
|
@ -220,25 +220,28 @@ static int group_state_for_line(struct libscols_group *gr, struct libscols_line
|
||||||
return SCOLS_GSTATE_NONE;
|
return SCOLS_GSTATE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For now we assume that each active group is just 3 columns width. Later we can make it dynamic...
|
/*
|
||||||
|
* apply new @state to the chunk (addresesd by @xx) of grpset used for the group (@gr)
|
||||||
*/
|
*/
|
||||||
static void grpset_apply_group_state(struct libscols_group **xx, int state, struct libscols_group *gr)
|
static void grpset_apply_group_state(struct libscols_group **xx, int state, struct libscols_group *gr)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
DBG(GROUP, ul_debugobj(gr, " applying state to grpset"));
|
DBG(GROUP, ul_debugobj(gr, " applying state to grpset"));
|
||||||
|
|
||||||
/* gr->state holds the old state, @state is the new state
|
/* gr->state holds the old state, @state is the new state
|
||||||
*/
|
*/
|
||||||
if (state == SCOLS_GSTATE_NONE)
|
for (i = 0; i < SCOLS_GRPSET_CHUNKSIZ; i++)
|
||||||
xx[0] = xx[1] = xx[2] = NULL;
|
xx[i] = state == SCOLS_GSTATE_NONE ? NULL : gr;
|
||||||
else
|
|
||||||
xx[0] = xx[1] = xx[2] = gr;
|
|
||||||
gr->state = state;
|
gr->state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct libscols_group **grpset_locate_freespace(struct libscols_table *tb, size_t wanted, int prepend)
|
static struct libscols_group **grpset_locate_freespace(struct libscols_table *tb, int chunks, int prepend)
|
||||||
{
|
{
|
||||||
size_t i, avail = 0;
|
size_t i, avail = 0;
|
||||||
struct libscols_group **tmp, **first = NULL;
|
struct libscols_group **tmp, **first = NULL;
|
||||||
|
const size_t wanted = chunks * SCOLS_GRPSET_CHUNKSIZ;
|
||||||
|
|
||||||
if (!tb->grpset_size)
|
if (!tb->grpset_size)
|
||||||
prepend = 0;
|
prepend = 0;
|
||||||
|
@ -268,8 +271,8 @@ static struct libscols_group **grpset_locate_freespace(struct libscols_table *tb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG(TAB, ul_debugobj(tb, " realocate grpset [sz: old=%zu, new=%zu]",
|
DBG(TAB, ul_debugobj(tb, " realocate grpset [sz: old=%zu, new=%zu, new_chunks=%d]",
|
||||||
tb->grpset_size, tb->grpset_size + wanted));
|
tb->grpset_size, tb->grpset_size + wanted, chunks));
|
||||||
|
|
||||||
tmp = realloc(tb->grpset, (tb->grpset_size + wanted) * sizeof(struct libscols_group *));
|
tmp = realloc(tb->grpset, (tb->grpset_size + wanted) * sizeof(struct libscols_group *));
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
|
@ -310,9 +313,6 @@ static struct libscols_group **grpset_locate_group(struct libscols_table *tb, st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define SCOLS_GRPSET_MINSZ 3
|
|
||||||
|
|
||||||
static int grpset_update(struct libscols_table *tb, struct libscols_line *ln, struct libscols_group *gr)
|
static int grpset_update(struct libscols_table *tb, struct libscols_line *ln, struct libscols_group *gr)
|
||||||
{
|
{
|
||||||
struct libscols_group **xx;
|
struct libscols_group **xx;
|
||||||
|
@ -349,7 +349,7 @@ static int grpset_update(struct libscols_table *tb, struct libscols_line *ln, st
|
||||||
|
|
||||||
/* locate place in grpset where we draw the group */
|
/* locate place in grpset where we draw the group */
|
||||||
if (!tb->grpset || gr->state == SCOLS_GSTATE_NONE)
|
if (!tb->grpset || gr->state == SCOLS_GSTATE_NONE)
|
||||||
xx = grpset_locate_freespace(tb, SCOLS_GRPSET_MINSZ, 1);
|
xx = grpset_locate_freespace(tb, 1, 1);
|
||||||
else
|
else
|
||||||
xx = grpset_locate_group(tb, gr);
|
xx = grpset_locate_group(tb, gr);
|
||||||
if (!xx) {
|
if (!xx) {
|
||||||
|
|
|
@ -110,11 +110,11 @@ static int groups_ascii_art_to_buffer( struct libscols_table *tb,
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
for (i = 0; i < tb->grpset_size; i+=3) {
|
for (i = 0; i < tb->grpset_size; i += SCOLS_GRPSET_CHUNKSIZ) {
|
||||||
struct libscols_group *gr = tb->grpset[i];
|
struct libscols_group *gr = tb->grpset[i];
|
||||||
|
|
||||||
if (!gr) {
|
if (!gr) {
|
||||||
buffer_append_ntimes(buf, 3, cellpadding_symbol(tb));
|
buffer_append_ntimes(buf, SCOLS_GRPSET_CHUNKSIZ, cellpadding_symbol(tb));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ static int groups_ascii_art_to_buffer( struct libscols_table *tb,
|
||||||
case SCOLS_GSTATE_LAST_CHILD:
|
case SCOLS_GSTATE_LAST_CHILD:
|
||||||
buffer_append_data(buf, cellpadding_symbol(tb));
|
buffer_append_data(buf, cellpadding_symbol(tb));
|
||||||
buffer_append_data(buf, grp_c_last_symbol(tb));
|
buffer_append_data(buf, grp_c_last_symbol(tb));
|
||||||
if (grpset_is_empty(tb, i + 3, &rest)) {
|
if (grpset_is_empty(tb, i + SCOLS_GRPSET_CHUNKSIZ, &rest)) {
|
||||||
buffer_append_ntimes(buf, rest+1, grp_horizontal_symbol(tb));
|
buffer_append_ntimes(buf, rest+1, grp_horizontal_symbol(tb));
|
||||||
filled = 1;
|
filled = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,11 @@ enum {
|
||||||
SCOLS_GSTATE_CONT_CHILDREN
|
SCOLS_GSTATE_CONT_CHILDREN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Every group needs at least 3 columns
|
||||||
|
*/
|
||||||
|
#define SCOLS_GRPSET_CHUNKSIZ 3
|
||||||
|
|
||||||
struct libscols_group {
|
struct libscols_group {
|
||||||
int refcount;
|
int refcount;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue