diff options
Diffstat (limited to 'src/utils/libsmartcols/src')
-rw-r--r-- | src/utils/libsmartcols/src/buffer.c | 2 | ||||
-rw-r--r-- | src/utils/libsmartcols/src/calculate.c | 2 | ||||
-rw-r--r-- | src/utils/libsmartcols/src/libsmartcols.h | 4 | ||||
-rw-r--r-- | src/utils/libsmartcols/src/print-api.c | 8 | ||||
-rw-r--r-- | src/utils/libsmartcols/src/print.c | 261 | ||||
-rw-r--r-- | src/utils/libsmartcols/src/smartcolsP.h | 10 | ||||
-rw-r--r-- | src/utils/libsmartcols/src/table.c | 66 |
7 files changed, 244 insertions, 109 deletions
diff --git a/src/utils/libsmartcols/src/buffer.c b/src/utils/libsmartcols/src/buffer.c index d376e8f..8a31379 100644 --- a/src/utils/libsmartcols/src/buffer.c +++ b/src/utils/libsmartcols/src/buffer.c @@ -56,6 +56,8 @@ int buffer_append_data(struct libscols_buffer *buf, const char *str) return -EINVAL; if (!str || !*str) return 0; + if (!buf->cur || !buf->begin) + return -EINVAL; sz = strlen(str); maxsz = buf->bufsz - (buf->cur - buf->begin); diff --git a/src/utils/libsmartcols/src/calculate.c b/src/utils/libsmartcols/src/calculate.c index b6137fd..974fc34 100644 --- a/src/utils/libsmartcols/src/calculate.c +++ b/src/utils/libsmartcols/src/calculate.c @@ -325,7 +325,7 @@ int __scols_calculate(struct libscols_table *tb, struct libscols_buffer *buf) DBG(TAB, ul_debugobj(tb, " enlarge width (last column)")); - if (!scols_column_is_right(col) && tb->termwidth - width > 0) { + if (!scols_column_is_right(col)) { col->width += tb->termwidth - width; width = tb->termwidth; } diff --git a/src/utils/libsmartcols/src/libsmartcols.h b/src/utils/libsmartcols/src/libsmartcols.h index 35c24c9..26c00bc 100644 --- a/src/utils/libsmartcols/src/libsmartcols.h +++ b/src/utils/libsmartcols/src/libsmartcols.h @@ -95,7 +95,9 @@ enum { enum { SCOLS_JSON_STRING = 0, /* default */ SCOLS_JSON_NUMBER = 1, - SCOLS_JSON_BOOLEAN = 2 + SCOLS_JSON_BOOLEAN = 2, + SCOLS_JSON_ARRAY_STRING = 3, /* e.g. for multi-line (SCOLS_FL_WRAP) cells */ + SCOLS_JSON_ARRAY_NUMBER = 4 }; /* diff --git a/src/utils/libsmartcols/src/print-api.c b/src/utils/libsmartcols/src/print-api.c index 89dd3bf..237d9ae 100644 --- a/src/utils/libsmartcols/src/print-api.c +++ b/src/utils/libsmartcols/src/print-api.c @@ -119,8 +119,8 @@ static int do_print_table(struct libscols_table *tb, int *is_empty) if (scols_table_is_json(tb)) { ul_jsonwrt_init(&tb->json, tb->out, 0); ul_jsonwrt_root_open(&tb->json); - ul_jsonwrt_array_open(&tb->json, tb->name); - ul_jsonwrt_array_close(&tb->json, 1); + ul_jsonwrt_array_open(&tb->json, tb->name ? tb->name : ""); + ul_jsonwrt_array_close(&tb->json); ul_jsonwrt_root_close(&tb->json); } else if (is_empty) *is_empty = 1; @@ -134,7 +134,7 @@ static int do_print_table(struct libscols_table *tb, int *is_empty) if (scols_table_is_json(tb)) { ul_jsonwrt_root_open(&tb->json); - ul_jsonwrt_array_open(&tb->json, tb->name); + ul_jsonwrt_array_open(&tb->json, tb->name ? tb->name : ""); } if (tb->format == SCOLS_FMT_HUMAN) @@ -150,7 +150,7 @@ static int do_print_table(struct libscols_table *tb, int *is_empty) rc = __scols_print_table(tb, buf); if (scols_table_is_json(tb)) { - ul_jsonwrt_array_close(&tb->json, 1); + ul_jsonwrt_array_close(&tb->json); ul_jsonwrt_root_close(&tb->json); } done: diff --git a/src/utils/libsmartcols/src/print.c b/src/utils/libsmartcols/src/print.c index 9d78c90..9f60148 100644 --- a/src/utils/libsmartcols/src/print.c +++ b/src/utils/libsmartcols/src/print.c @@ -1,5 +1,4 @@ -/* - * table.c - functions handling the data at the table level + /* print.c - functions to print table * * Copyright (C) 2010-2014 Karel Zak <kzak@redhat.com> * Copyright (C) 2016 Igor Gnatenko <i.gnatenko.brain@gmail.com> @@ -217,16 +216,94 @@ static int has_pending_data(struct libscols_table *tb) return 0; } +static void fputs_color_reset(struct libscols_table *tb) +{ + if (tb->cur_color) { + fputs(UL_COLOR_RESET, tb->out); + tb->cur_color = NULL; + } +} + +static void fputs_color(struct libscols_table *tb, const char *color) +{ + if (tb->cur_color) + fputs_color_reset(tb); + + tb->cur_color = color; + if (color) + fputs(color, tb->out); +} + +static const char *get_cell_color(struct libscols_table *tb, + struct libscols_column *cl, + struct libscols_line *ln, + struct libscols_cell *ce) +{ + const char *color = NULL; + + if (!tb || !tb->colors_wanted || tb->format != SCOLS_FMT_HUMAN) + return NULL; + if (ce) + color = ce->color; + if (!color && (!ln || !ln->color) && cl) + color = cl->color; + return color; +} + +/* switch from line color to cell/column color */ +static void fputs_color_cell_open(struct libscols_table *tb, + struct libscols_column *cl, + struct libscols_line *ln, + struct libscols_cell *ce) +{ + const char *color = get_cell_color(tb, cl, ln, ce); + + if (color) + fputs_color(tb, color); +} + +/* switch from cell/column color to line color or reset */ +static void fputs_color_cell_close(struct libscols_table *tb, + struct libscols_column *cl, + struct libscols_line *ln, + struct libscols_cell *ce) +{ + const char *color = get_cell_color(tb, cl, ln, ce); + + if (color) + fputs_color(tb, ln ? ln->color : NULL); +} + +/* switch to line color */ +static void fputs_color_line_open(struct libscols_table *tb, + struct libscols_line *ln) +{ + if (!tb || !tb->colors_wanted || tb->format != SCOLS_FMT_HUMAN) + return; + fputs_color(tb, ln ? ln->color : NULL); +} + +/* switch off all colors */ +static void fputs_color_line_close(struct libscols_table *tb) +{ + if (!tb || !tb->colors_wanted || tb->format != SCOLS_FMT_HUMAN) + return; + fputs_color_reset(tb); +} + /* print padding or ASCII-art instead of data of @cl */ static void print_empty_cell(struct libscols_table *tb, struct libscols_column *cl, struct libscols_line *ln, /* optional */ + struct libscols_cell *ce, size_t bufsz) { size_t len_pad = 0; /* in screen cells as opposed to bytes */ DBG(COL, ul_debugobj(cl, " printing empty cell")); + fputs_color_cell_open(tb, cl, ln, ce); + /* generate tree ASCII-art rather than padding */ if (ln && scols_column_is_tree(cl)) { if (!ln->parent) { @@ -256,39 +333,28 @@ static void print_empty_cell(struct libscols_table *tb, } /* minout -- don't fill */ - if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) + if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) { + fputs_color_cell_close(tb, cl, ln, ce); return; + } /* default -- fill except last column */ - if (!scols_table_is_maxout(tb) && is_last_column(cl)) + if (!scols_table_is_maxout(tb) && is_last_column(cl)) { + fputs_color_cell_close(tb, cl, ln, ce); return; + } /* fill rest of cell with space */ for(; len_pad < cl->width; ++len_pad) fputs(cellpadding_symbol(tb), tb->out); + fputs_color_cell_close(tb, cl, ln, ce); + if (!is_last_column(cl)) fputs(colsep(tb), tb->out); } -static const char *get_cell_color(struct libscols_table *tb, - struct libscols_column *cl, - struct libscols_line *ln, /* optional */ - struct libscols_cell *ce) /* optional */ -{ - const char *color = NULL; - - if (tb && tb->colors_wanted) { - if (ce) - color = ce->color; - if (ln && !color) - color = ln->color; - if (!color) - color = cl->color; - } - return color; -} /* Fill the start of a line with padding (or with tree ascii-art). * @@ -304,6 +370,7 @@ static const char *get_cell_color(struct libscols_table *tb, static void print_newline_padding(struct libscols_table *tb, struct libscols_column *cl, struct libscols_line *ln, /* optional */ + struct libscols_cell *ce, size_t bufsz) { size_t i; @@ -316,9 +383,13 @@ static void print_newline_padding(struct libscols_table *tb, fputs(linesep(tb), tb->out); /* line break */ tb->termlines_used++; + fputs_color_line_open(tb, ln); + /* fill cells after line break */ for (i = 0; i <= (size_t) cl->seqnum; i++) - print_empty_cell(tb, scols_table_get_column(tb, i), ln, bufsz); + print_empty_cell(tb, scols_table_get_column(tb, i), ln, ce, bufsz); + + fputs_color_line_close(tb); } /* @@ -374,7 +445,6 @@ static int print_pending_data( struct libscols_line *ln, /* optional */ struct libscols_cell *ce) { - const char *color = get_cell_color(tb, cl, ln, ce); size_t width = cl->width, bytes; size_t len = width, i; char *data; @@ -407,25 +477,29 @@ static int print_pending_data( if (bytes) step_pending_data(cl, bytes); - if (color) - fputs(color, tb->out); + fputs_color_cell_open(tb, cl, ln, ce); + fputs(data, tb->out); - if (color) - fputs(UL_COLOR_RESET, tb->out); free(data); /* minout -- don't fill */ - if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) + if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) { + fputs_color_cell_close(tb, cl, ln, ce); return 0; + } /* default -- fill except last column */ - if (!scols_table_is_maxout(tb) && is_last_column(cl)) + if (!scols_table_is_maxout(tb) && is_last_column(cl)) { + fputs_color_cell_close(tb, cl, ln, ce); return 0; + } /* fill rest of cell with space */ for(i = len; i < width; i++) fputs(cellpadding_symbol(tb), tb->out); + fputs_color_cell_close(tb, cl, ln, ce); + if (!is_last_column(cl)) fputs(colsep(tb), tb->out); @@ -435,6 +509,49 @@ err: return -errno; } +static void print_json_data(struct libscols_table *tb, + struct libscols_column *cl, + const char *name, + char *data) +{ + switch (cl->json_type) { + case SCOLS_JSON_STRING: + /* name: "aaa" */ + ul_jsonwrt_value_s(&tb->json, name, data); + break; + case SCOLS_JSON_NUMBER: + /* name: 123 */ + ul_jsonwrt_value_raw(&tb->json, name, data); + break; + case SCOLS_JSON_BOOLEAN: + /* name: true|false */ + ul_jsonwrt_value_boolean(&tb->json, name, + !*data ? 0 : + *data == '0' ? 0 : + *data == 'N' || *data == 'n' ? 0 : 1); + break; + case SCOLS_JSON_ARRAY_STRING: + case SCOLS_JSON_ARRAY_NUMBER: + /* name: [ "aaa", "bbb", "ccc" ] */ + ul_jsonwrt_array_open(&tb->json, name); + + if (!scols_column_is_customwrap(cl)) + ul_jsonwrt_value_s(&tb->json, NULL, data); + else do { + char *next = cl->wrap_nextchunk(cl, data, cl->wrapfunc_data); + + if (cl->json_type == SCOLS_JSON_ARRAY_STRING) + ul_jsonwrt_value_s(&tb->json, NULL, data); + else + ul_jsonwrt_value_raw(&tb->json, NULL, data); + data = next; + } while (data); + + ul_jsonwrt_array_close(&tb->json); + break; + } +} + static int print_data(struct libscols_table *tb, struct libscols_column *cl, struct libscols_line *ln, /* optional */ @@ -442,7 +559,6 @@ static int print_data(struct libscols_table *tb, struct libscols_buffer *buf) { size_t len = 0, i, width, bytes; - const char *color = NULL; char *data, *nextchunk; const char *name = NULL; int is_last; @@ -472,36 +588,23 @@ static int print_data(struct libscols_table *tb, return 0; case SCOLS_FMT_EXPORT: - fprintf(tb->out, "%s=", name); + fputs_shell_ident(name, tb->out); + if (endswith(name, "%")) + fputs("PCT", tb->out); + fputc('=', tb->out); fputs_quoted(data, tb->out); if (!is_last) fputs(colsep(tb), tb->out); return 0; case SCOLS_FMT_JSON: - switch (cl->json_type) { - case SCOLS_JSON_STRING: - ul_jsonwrt_value_s(&tb->json, name, data, is_last); - break; - case SCOLS_JSON_NUMBER: - ul_jsonwrt_value_raw(&tb->json, name, data, is_last); - break; - case SCOLS_JSON_BOOLEAN: - ul_jsonwrt_value_boolean(&tb->json, name, - !*data ? 0 : - *data == '0' ? 0 : - *data == 'N' || *data == 'n' ? 0 : 1, - is_last); - break; - } + print_json_data(tb, cl, name, data); return 0; case SCOLS_FMT_HUMAN: break; /* continue below */ } - color = get_cell_color(tb, cl, ln, ce); - /* Encode. Note that 'len' and 'width' are number of cells, not bytes. */ data = buffer_get_safe_data(tb, buf, &len, scols_column_get_safechars(cl)); @@ -549,49 +652,39 @@ static int print_data(struct libscols_table *tb, data = NULL; } + fputs_color_cell_open(tb, cl, ln, ce); + if (data && *data) { if (scols_column_is_right(cl)) { - if (color) - fputs(color, tb->out); for (i = len; i < width; i++) fputs(cellpadding_symbol(tb), tb->out); - fputs(data, tb->out); - if (color) - fputs(UL_COLOR_RESET, tb->out); len = width; + } + fputs(data, tb->out); - } else if (color) { - char *p = data; - size_t art = buffer_get_safe_art_size(buf); - - /* we don't want to colorize tree ascii art */ - if (scols_column_is_tree(cl) && art && art < bytes) { - fwrite(p, 1, art, tb->out); - p += art; - } - - fputs(color, tb->out); - fputs(p, tb->out); - fputs(UL_COLOR_RESET, tb->out); - } else - fputs(data, tb->out); } /* minout -- don't fill */ - if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) + if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) { + fputs_color_cell_close(tb, cl, ln, ce); return 0; + } /* default -- fill except last column */ - if (!scols_table_is_maxout(tb) && is_last) + if (!scols_table_is_maxout(tb) && is_last) { + fputs_color_cell_close(tb, cl, ln, ce); return 0; + } /* fill rest of cell with space */ for(i = len; i < width; i++) fputs(cellpadding_symbol(tb), tb->out); + fputs_color_cell_close(tb, cl, ln, ce); + if (len > width && !scols_column_is_trunc(cl)) { DBG(COL, ul_debugobj(cl, "*** data len=%zu > column width=%zu", len, width)); - print_newline_padding(tb, cl, ln, buffer_get_size(buf)); /* next column starts on next line */ + print_newline_padding(tb, cl, ln, ce, buffer_get_size(buf)); /* next column starts on next line */ } else if (!is_last) fputs(colsep(tb), tb->out); /* columns separator */ @@ -664,6 +757,8 @@ static int print_line(struct libscols_table *tb, DBG(LINE, ul_debugobj(ln, "printing line")); + fputs_color_line_open(tb, ln); + /* regular line */ scols_reset_iter(&itr, SCOLS_ITER_FORWARD); while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) { @@ -677,12 +772,14 @@ static int print_line(struct libscols_table *tb, if (rc == 0 && cl->pending_data) pending = 1; } + fputs_color_line_close(tb); /* extra lines of the multi-line cells */ while (rc == 0 && pending) { DBG(LINE, ul_debugobj(ln, "printing pending data")); pending = 0; fputs(linesep(tb), tb->out); + fputs_color_line_open(tb, ln); tb->termlines_used++; scols_reset_iter(&itr, SCOLS_ITER_FORWARD); while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) { @@ -693,8 +790,9 @@ static int print_line(struct libscols_table *tb, if (rc == 0 && cl->pending_data) pending = 1; } else - print_empty_cell(tb, cl, ln, buffer_get_size(buf)); + print_empty_cell(tb, cl, ln, NULL, buffer_get_size(buf)); } + fputs_color_line_close(tb); } return 0; @@ -702,7 +800,7 @@ static int print_line(struct libscols_table *tb, int __scols_print_title(struct libscols_table *tb) { - int rc, color = 0; + int rc; mbs_align_t align; size_t width, len = 0, bufsz, titlesz; char *title = NULL, *buf = NULL; @@ -783,15 +881,14 @@ int __scols_print_title(struct libscols_table *tb) goto done; } - if (tb->colors_wanted && tb->title.color) - color = 1; - if (color) - fputs(tb->title.color, tb->out); + + if (tb->colors_wanted) + fputs_color(tb, tb->title.color); fputs(title, tb->out); - if (color) - fputs(UL_COLOR_RESET, tb->out); + if (tb->colors_wanted) + fputs_color_reset(tb); fputc('\n', tb->out); rc = 0; @@ -877,7 +974,7 @@ int __scols_print_range(struct libscols_table *tb, rc = print_line(tb, ln, buf); if (scols_table_is_json(tb)) - ul_jsonwrt_object_close(&tb->json, last); + ul_jsonwrt_object_close(&tb->json); else if (last == 0 && tb->no_linesep == 0) { fputs(linesep(tb), tb->out); tb->termlines_used++; @@ -937,9 +1034,9 @@ static int print_tree_line(struct libscols_table *tb, last = (is_child(ln) && is_last_child(ln)) || (is_tree_root(ln) && is_last_tree_root(tb, ln)); - ul_jsonwrt_object_close(&tb->json, last); + ul_jsonwrt_object_close(&tb->json); if (last && is_child(ln)) - ul_jsonwrt_array_close(&tb->json, last); + ul_jsonwrt_array_close(&tb->json); ln = ln->parent; } while(ln && last); diff --git a/src/utils/libsmartcols/src/smartcolsP.h b/src/utils/libsmartcols/src/smartcolsP.h index 5e9b9ec..810cc0f 100644 --- a/src/utils/libsmartcols/src/smartcolsP.h +++ b/src/utils/libsmartcols/src/smartcolsP.h @@ -124,7 +124,7 @@ struct libscols_column { struct libscols_cell header; - struct list_head cl_columns; + struct list_head cl_columns; /* member of table->tb_columns */ struct libscols_table *table; @@ -212,8 +212,8 @@ struct libscols_table { char *colsep; /* column separator */ char *linesep; /* line separator */ - struct list_head tb_columns; - struct list_head tb_lines; + struct list_head tb_columns; /* list of columns, items: column->cl_columns */ + struct list_head tb_lines; /* list of lines; items: line->ln_lines */ struct list_head tb_groups; /* all defined groups */ struct libscols_group **grpset; @@ -222,6 +222,8 @@ struct libscols_table { size_t ngrpchlds_pending; /* groups with not yet printed children */ struct libscols_line *walk_last_tree_root; /* last root, used by scols_walk_() */ + struct libscols_column *dflt_sort_column; /* default sort column, set by scols_sort_table() */ + struct libscols_symbols *symbols; struct libscols_cell title; /* optional table title (for humans) */ @@ -232,6 +234,8 @@ struct libscols_table { size_t termlines_used; /* printed line counter */ size_t header_next; /* where repeat header */ + const char *cur_color; /* current active color when printing */ + /* flags */ unsigned int ascii :1, /* don't use unicode */ colors_wanted :1, /* enable colors */ diff --git a/src/utils/libsmartcols/src/table.c b/src/utils/libsmartcols/src/table.c index a3ba21d..cbc5fd4 100644 --- a/src/utils/libsmartcols/src/table.c +++ b/src/utils/libsmartcols/src/table.c @@ -50,7 +50,7 @@ static void check_padding_debug(struct libscols_table *tb) { const char *str; - assert(libsmartcols_debug_mask); /* debug has to be enabled! */ + assert(libsmartcols_debug_mask); /* debug has to be already initialized! */ str = getenv("LIBSMARTCOLS_DEBUG_PADDING"); if (!str || (strcmp(str, "on") != 0 && strcmp(str, "1") != 0)) @@ -270,6 +270,8 @@ int scols_table_remove_column(struct libscols_table *tb, if (cl->flags & SCOLS_FL_TREE) tb->ntreecols--; + if (tb->dflt_sort_column == cl) + tb->dflt_sort_column = NULL; DBG(TAB, ul_debugobj(tb, "remove column")); list_del_init(&cl->cl_columns); @@ -1076,6 +1078,10 @@ int scols_table_enable_json(struct libscols_table *tb, int enable) * Enable/disable export output format (COLUMNAME="value" ...). * The parsable output formats (export and raw) are mutually exclusive. * + * Note that COLUMNAME maybe be modified on output to contains only chars + * allowed as shell variable identifiers, for example MIN-IO and FSUSE% will be + * MIN_IO and FSUSE_PCT. + * * Returns: 0 on success, negative number in case of an error. */ int scols_table_enable_export(struct libscols_table *tb, int enable) @@ -1511,41 +1517,63 @@ static int sort_line_children(struct libscols_line *ln, struct libscols_column * return 0; } +static int __scols_sort_tree(struct libscols_table *tb, struct libscols_column *cl) +{ + struct libscols_line *ln; + struct libscols_iter itr; + + if (!tb || !cl || !cl->cmpfunc) + return -EINVAL; + + scols_reset_iter(&itr, SCOLS_ITER_FORWARD); + while (scols_table_next_line(tb, &itr, &ln) == 0) + sort_line_children(ln, cl); + return 0; +} + /** * scols_sort_table: * @tb: table - * @cl: order by this column + * @cl: order by this column or NULL * * Orders the table by the column. See also scols_column_set_cmpfunc(). If the * tree output is enabled then children in the tree are recursively sorted too. * + * The column @cl is saved as the default sort column to the @tb and the next time + * is possible to call scols_sort_table(tb, NULL). The saved column is also used by + * scols_sort_table_by_tree(). + * * Returns: 0, a negative value in case of an error. */ int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl) { - if (!tb || !cl || !cl->cmpfunc) + if (!tb) + return -EINVAL; + if (!cl) + cl = tb->dflt_sort_column; + if (!cl || !cl->cmpfunc) return -EINVAL; - DBG(TAB, ul_debugobj(tb, "sorting table")); + DBG(TAB, ul_debugobj(tb, "sorting table by %zu column", cl->seqnum)); list_sort(&tb->tb_lines, cells_cmp_wrapper_lines, cl); - if (scols_table_is_tree(tb)) { - struct libscols_line *ln; - struct libscols_iter itr; + if (scols_table_is_tree(tb)) + __scols_sort_tree(tb, cl); - scols_reset_iter(&itr, SCOLS_ITER_FORWARD); - while (scols_table_next_line(tb, &itr, &ln) == 0) - sort_line_children(ln, cl); - } + if (cl && cl != tb->dflt_sort_column) + tb->dflt_sort_column = cl; return 0; } +/* + * Move all @ln's children after @ln in the table. + */ static struct libscols_line *move_line_and_children(struct libscols_line *ln, struct libscols_line *pre) { if (pre) { list_del_init(&ln->ln_lines); /* remove from old position */ - list_add(&ln->ln_lines, &pre->ln_lines); /* add to the new place (behind @pre) */ + list_add(&ln->ln_lines, &pre->ln_lines); /* add to the new place (after @pre) */ } pre = ln; @@ -1567,7 +1595,10 @@ static struct libscols_line *move_line_and_children(struct libscols_line *ln, st * @tb: table * * Reorders lines in the table by parent->child relation. Note that order of - * the lines in the table is independent on the tree hierarchy. + * the lines in the table is independent on the tree hierarchy by default. + * + * The children of the lines are sorted according to the default sort column + * if scols_sort_table() has been previously called. * * Since: 2.30 * @@ -1583,13 +1614,12 @@ int scols_sort_table_by_tree(struct libscols_table *tb) DBG(TAB, ul_debugobj(tb, "sorting table by tree")); - scols_reset_iter(&itr, SCOLS_ITER_FORWARD); - while (scols_table_next_line(tb, &itr, &ln) == 0) { - if (ln->parent) - continue; + if (tb->dflt_sort_column) + __scols_sort_tree(tb, tb->dflt_sort_column); + scols_reset_iter(&itr, SCOLS_ITER_FORWARD); + while (scols_table_next_line(tb, &itr, &ln) == 0) move_line_and_children(ln, NULL); - } return 0; } |