libsmartcols: fix hidden file usage
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
6db10580ca
commit
fdf7279849
|
@ -202,7 +202,7 @@ static int is_last_column(struct libscols_column *cl)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns);
|
next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns);
|
||||||
if (next && scols_column_is_hidden(next))
|
if (next && scols_column_is_hidden(next) && is_last_column(next))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -425,6 +425,7 @@ static int print_data(struct libscols_table *tb,
|
||||||
size_t len = 0, i, width, bytes;
|
size_t len = 0, i, width, bytes;
|
||||||
const char *color = NULL;
|
const char *color = NULL;
|
||||||
char *data, *wrapnl;
|
char *data, *wrapnl;
|
||||||
|
int is_last;
|
||||||
|
|
||||||
assert(tb);
|
assert(tb);
|
||||||
assert(cl);
|
assert(cl);
|
||||||
|
@ -437,17 +438,19 @@ static int print_data(struct libscols_table *tb,
|
||||||
if (!data)
|
if (!data)
|
||||||
data = "";
|
data = "";
|
||||||
|
|
||||||
|
is_last = is_last_column(cl);
|
||||||
|
|
||||||
switch (tb->format) {
|
switch (tb->format) {
|
||||||
case SCOLS_FMT_RAW:
|
case SCOLS_FMT_RAW:
|
||||||
fputs_nonblank(data, tb->out);
|
fputs_nonblank(data, tb->out);
|
||||||
if (!is_last_column(cl))
|
if (!is_last)
|
||||||
fputs(colsep(tb), tb->out);
|
fputs(colsep(tb), tb->out);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case SCOLS_FMT_EXPORT:
|
case SCOLS_FMT_EXPORT:
|
||||||
fprintf(tb->out, "%s=", scols_cell_get_data(&cl->header));
|
fprintf(tb->out, "%s=", scols_cell_get_data(&cl->header));
|
||||||
fputs_quoted(data, tb->out);
|
fputs_quoted(data, tb->out);
|
||||||
if (!is_last_column(cl))
|
if (!is_last)
|
||||||
fputs(colsep(tb), tb->out);
|
fputs(colsep(tb), tb->out);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -458,7 +461,7 @@ static int print_data(struct libscols_table *tb,
|
||||||
fputs("null", tb->out);
|
fputs("null", tb->out);
|
||||||
else
|
else
|
||||||
fputs_quoted_json(data, tb->out);
|
fputs_quoted_json(data, tb->out);
|
||||||
if (!is_last_column(cl))
|
if (!is_last)
|
||||||
fputs(", ", tb->out);
|
fputs(", ", tb->out);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -487,7 +490,7 @@ static int print_data(struct libscols_table *tb,
|
||||||
len = mbs_safe_nwidth(data, bytes, NULL);
|
len = mbs_safe_nwidth(data, bytes, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_last_column(cl)
|
if (is_last
|
||||||
&& len < width
|
&& len < width
|
||||||
&& !scols_table_is_maxout(tb)
|
&& !scols_table_is_maxout(tb)
|
||||||
&& !scols_column_is_right(cl))
|
&& !scols_column_is_right(cl))
|
||||||
|
@ -544,7 +547,7 @@ static int print_data(struct libscols_table *tb,
|
||||||
for (i = len; i < width; i++)
|
for (i = len; i < width; i++)
|
||||||
fputs(cellpadding_symbol(tb), tb->out); /* padding */
|
fputs(cellpadding_symbol(tb), tb->out); /* padding */
|
||||||
|
|
||||||
if (is_last_column(cl))
|
if (is_last)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (len > width && !scols_column_is_trunc(cl))
|
if (len > width && !scols_column_is_trunc(cl))
|
||||||
|
@ -727,7 +730,6 @@ static int print_line(struct libscols_table *tb,
|
||||||
while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
|
while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
if (scols_column_is_hidden(cl))
|
if (scols_column_is_hidden(cl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cl->pending_data) {
|
if (cl->pending_data) {
|
||||||
rc = print_pending_data(tb, cl, ln, scols_line_get_cell(ln, cl->seqnum));
|
rc = print_pending_data(tb, cl, ln, scols_line_get_cell(ln, cl->seqnum));
|
||||||
if (rc == 0 && cl->pending_data)
|
if (rc == 0 && cl->pending_data)
|
||||||
|
@ -955,7 +957,7 @@ static int print_tree(struct libscols_table *tb, struct libscols_buffer *buf)
|
||||||
static void dbg_column(struct libscols_table *tb, struct libscols_column *cl)
|
static void dbg_column(struct libscols_table *tb, struct libscols_column *cl)
|
||||||
{
|
{
|
||||||
if (scols_column_is_hidden(cl)) {
|
if (scols_column_is_hidden(cl)) {
|
||||||
DBG(COL, ul_debugobj(cl, "%s ignored", cl->header.data));
|
DBG(COL, ul_debugobj(cl, "%s (hidden) ignored", cl->header.data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,12 +1118,18 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
*/
|
*/
|
||||||
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
||||||
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
|
int is_last;
|
||||||
|
|
||||||
|
if (scols_column_is_hidden(cl))
|
||||||
|
continue;
|
||||||
rc = count_column_width(tb, cl, buf);
|
rc = count_column_width(tb, cl, buf);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
width += cl->width + (is_last_column(cl) ? 0 : 1); /* separator for non-last column */
|
is_last = is_last_column(cl);
|
||||||
width_min += cl->width_min + (is_last_column(cl) ? 0 : 1);
|
|
||||||
|
width += cl->width + (is_last ? 0 : 1); /* separator for non-last column */
|
||||||
|
width_min += cl->width_min + (is_last ? 0 : 1);
|
||||||
extremes += cl->is_extreme;
|
extremes += cl->is_extreme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1137,6 +1145,8 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
||||||
while (width_min > tb->termwidth
|
while (width_min > tb->termwidth
|
||||||
&& scols_table_next_column(tb, &itr, &cl) == 0) {
|
&& scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
|
if (scols_column_is_hidden(cl))
|
||||||
|
continue;
|
||||||
width_min--;
|
width_min--;
|
||||||
cl->width_min--;
|
cl->width_min--;
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1161,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
size_t org_width;
|
size_t org_width;
|
||||||
|
|
||||||
if (!cl->is_extreme)
|
if (!cl->is_extreme || scols_column_is_hidden(cl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
org_width = cl->width;
|
org_width = cl->width;
|
||||||
|
@ -1175,7 +1185,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
size_t add;
|
size_t add;
|
||||||
|
|
||||||
if (!cl->is_extreme)
|
if (!cl->is_extreme || scols_column_is_hidden(cl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* this column is too large, ignore?
|
/* this column is too large, ignore?
|
||||||
|
@ -1203,6 +1213,8 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
while (width < tb->termwidth) {
|
while (width < tb->termwidth) {
|
||||||
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
||||||
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
|
if (scols_column_is_hidden(cl))
|
||||||
|
continue;
|
||||||
cl->width++;
|
cl->width++;
|
||||||
width++;
|
width++;
|
||||||
if (width == tb->termwidth)
|
if (width == tb->termwidth)
|
||||||
|
@ -1241,7 +1253,8 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
|
|
||||||
DBG(TAB, ul_debugobj(cl, " checking %s (width=%zu, treeart=%zu)",
|
DBG(TAB, ul_debugobj(cl, " checking %s (width=%zu, treeart=%zu)",
|
||||||
cl->header.data, cl->width, cl->width_treeart));
|
cl->header.data, cl->width, cl->width_treeart));
|
||||||
|
if (scols_column_is_hidden(cl))
|
||||||
|
continue;
|
||||||
if (width <= tb->termwidth)
|
if (width <= tb->termwidth)
|
||||||
break;
|
break;
|
||||||
if (cl->width_hint > 1 && !scols_column_is_trunc(cl))
|
if (cl->width_hint > 1 && !scols_column_is_trunc(cl))
|
||||||
|
@ -1283,6 +1296,8 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
|
||||||
scols_reset_iter(&itr, SCOLS_ITER_BACKWARD);
|
scols_reset_iter(&itr, SCOLS_ITER_BACKWARD);
|
||||||
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
while (scols_table_next_column(tb, &itr, &cl) == 0) {
|
||||||
|
|
||||||
|
if (scols_column_is_hidden(cl))
|
||||||
|
continue;
|
||||||
if (width <= tb->termwidth)
|
if (width <= tb->termwidth)
|
||||||
break;
|
break;
|
||||||
if (width - cl->width < tb->termwidth) {
|
if (width - cl->width < tb->termwidth) {
|
||||||
|
@ -1387,7 +1402,9 @@ static int initialize_printing(struct libscols_table *tb, struct libscols_buffer
|
||||||
*/
|
*/
|
||||||
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
|
||||||
while (scols_table_next_line(tb, &itr, &ln) == 0) {
|
while (scols_table_next_line(tb, &itr, &ln) == 0) {
|
||||||
size_t sz = strlen_line(ln) + extra_bufsz;
|
size_t sz;
|
||||||
|
|
||||||
|
sz = strlen_line(ln) + extra_bufsz;
|
||||||
if (sz > bufsz)
|
if (sz > bufsz)
|
||||||
bufsz = sz;
|
bufsz = sz;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue