colors_init(colormode, "cfdisk");
fdisk_init_debug(0);
+ scols_init_debug(0);
+
cf->cxt = fdisk_new_context();
if (!cf->cxt)
err(EXIT_FAILURE, _("failed to allocate libfdisk context"));
if (!nparts)
return 0;
+ scols_init_debug(0);
table = scols_new_table();
if (!table) {
warn(_("failed to initialize output table"));
if (!ce)
return -EINVAL;
+ /*DBG(CELL, ul_debugobj(ce, "reset"));*/
free(ce->data);
free(ce->color);
memset(ce, 0, sizeof(*ce));
rc = scols_cell_set_color(dest, scols_cell_get_color(src));
if (!rc)
dest->userdata = src->userdata;
+
+ DBG(CELL, ul_debugobj((void *) src, "copy into %p", dest));
return rc;
}
cl = calloc(1, sizeof(*cl));
if (!cl)
return NULL;
-
+ DBG(COL, ul_debugobj(cl, "alloc"));
cl->refcount = 1;
INIT_LIST_HEAD(&cl->cl_columns);
return cl;
void scols_unref_column(struct libscols_column *cl)
{
if (cl && --cl->refcount <= 0) {
+ DBG(COL, ul_debugobj(cl, "dealloc"));
list_del(&cl->cl_columns);
scols_reset_cell(&cl->header);
free(cl->color);
* scols_copy_column:
* @cl: a pointer to a struct libscols_column instance
*
- * Creates a new column and copies @cl's data over to it.
+ * Creates a new column and copies @cl's data over to it.
*
* Returns: a pointer to a new struct libscols_column instance.
*/
if (!ret)
return NULL;
+ DBG(COL, ul_debugobj((void *) cl, "copy to %p", ret));
+
if (scols_column_set_color(ret, cl->color))
goto err;
if (scols_cell_copy_content(&ret->header, &cl->header))
ln = calloc(1, sizeof(*ln));
if (!ln)
return NULL;
+
+ DBG(LINE, ul_debugobj(ln, "alloc"));
ln->refcount = 1;
INIT_LIST_HEAD(&ln->ln_lines);
INIT_LIST_HEAD(&ln->ln_children);
{
if (ln && --ln->refcount <= 0) {
+ DBG(CELL, ul_debugobj(ln, "dealloc"));
list_del(&ln->ln_lines);
list_del(&ln->ln_children);
-
scols_line_free_cells(ln);
free(ln->color);
free(ln);
if (!ln || !ln->cells)
return;
+ DBG(LINE, ul_debugobj(ln, "free cells"));
+
for (i = 0; i < ln->ncells; i++)
scols_reset_cell(&ln->cells[i]);
return 0;
}
+ DBG(LINE, ul_debugobj(ln, "alloc %zu cells", n));
+
ce = realloc(ln->cells, n * sizeof(struct libscols_cell));
if (!ce)
return -errno;
if (!ln || !child)
return -EINVAL;
+
+ DBG(LINE, ul_debugobj(ln, "remove child %p", child));
+
list_del_init(&child->ln_children);
scols_unref_line(child);
if (child->parent)
scols_line_remove_child(child->parent, child);
+ DBG(LINE, ul_debugobj(ln, "add child %p", child));
+
/* new reference from parent to child */
list_add_tail(&child->ln_children, &ln->ln_branch);
scols_ref_line(child);
ret->ncells = ln->ncells;
ret->seqnum = ln->seqnum;
+ DBG(LINE, ul_debugobj(ln, "copy to %p", ret));
+
for (i = 0; i < ret->ncells; ++i) {
if (scols_cell_copy_content(&ret->cells[i], &ln->cells[i]))
goto err;
* Debug
*/
#define SCOLS_DEBUG_INIT (1 << 1)
+#define SCOLS_DEBUG_CELL (1 << 2)
+#define SCOLS_DEBUG_LINE (1 << 3)
+#define SCOLS_DEBUG_TAB (1 << 4)
+#define SCOLS_DEBUG_COL (1 << 5)
+#define SCOLS_DEBUG_BUFF (1 << 6)
#define SCOLS_DEBUG_ALL 0xFFFF
UL_DEBUG_DECLARE_MASK(libsmartcols);
INIT_LIST_HEAD(&tb->tb_lines);
INIT_LIST_HEAD(&tb->tb_columns);
+ DBG(TAB, ul_debugobj(tb, "alloc"));
return tb;
}
void scols_unref_table(struct libscols_table *tb)
{
if (tb && (--tb->refcount <= 0)) {
+ DBG(TAB, ul_debugobj(tb, "dealloc"));
scols_table_remove_lines(tb);
scols_table_remove_columns(tb);
scols_unref_symbols(tb->symbols);
if (cl->flags & SCOLS_FL_TREE)
tb->ntreecols++;
+ DBG(TAB, ul_debugobj(tb, "add column %p", cl));
list_add_tail(&cl->cl_columns, &tb->tb_columns);
cl->seqnum = tb->ncols++;
scols_ref_column(cl);
if (cl->flags & SCOLS_FL_TREE)
tb->ntreecols--;
+ DBG(TAB, ul_debugobj(tb, "remove column %p", cl));
list_del_init(&cl->cl_columns);
tb->ncols--;
scols_unref_column(cl);
if (!tb || !list_empty(&tb->tb_lines))
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "remove all columns"));
while (!list_empty(&tb->tb_columns)) {
struct libscols_column *cl = list_entry(tb->tb_columns.next,
struct libscols_column, cl_columns);
assert (tb);
if (!tb)
return NULL;
+
+ DBG(TAB, ul_debugobj(tb, "new column name=%s, whint=%g, flags=%d",
+ name, whint, flags));
cl = scols_new_column();
if (!cl)
return NULL;
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "setting alternative stream"));
tb->out = stream;
return 0;
}
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "reduce terminal width: %zu", reduce));
tb->termreduce = reduce;
return 0;
}
return rc;
}
+ DBG(TAB, ul_debugobj(tb, "add line %p", ln));
list_add_tail(&ln->ln_lines, &tb->tb_lines);
ln->seqnum = tb->nlines++;
scols_ref_line(ln);
if (!tb || !ln)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "remove line %p", ln));
list_del_init(&ln->ln_lines);
tb->nlines--;
scols_unref_line(ln);
if (!tb)
return;
+ DBG(TAB, ul_debugobj(tb, "remove all lines"));
while (!list_empty(&tb->tb_lines)) {
struct libscols_line *ln = list_entry(tb->tb_lines.next,
struct libscols_line, ln_lines);
if (!tb || !tb->ncols)
return NULL;
+
ln = scols_new_line();
if (!ln)
return NULL;
if (!ret)
return NULL;
+ DBG(TAB, ul_debugobj(tb, "copy into %p", ret));
+
if (tb->symbols)
scols_table_set_symbols(ret, tb->symbols);
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "setting alternative symbols %p", sy));
+
if (tb->symbols) /* unref old */
scols_unref_symbols(tb->symbols);
if (sy) { /* ref user defined */
assert(tb);
if (!tb)
return -EINVAL;
+
+ DBG(TAB, ul_debugobj(tb, "colors: %s", enable ? "ENABLE" : "DISABLE"));
tb->colors_wanted = enable;
return 0;
}
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "raw: %s", enable ? "ENABLE" : "DISABLE"));
if (enable)
tb->format = SCOLS_FMT_RAW;
else if (tb->format == SCOLS_FMT_RAW)
assert(tb);
if (!tb)
return -EINVAL;
+
+ DBG(TAB, ul_debugobj(tb, "export: %s", enable ? "ENABLE" : "DISABLE"));
if (enable)
tb->format = SCOLS_FMT_EXPORT;
else if (tb->format == SCOLS_FMT_EXPORT)
assert(tb);
if (!tb)
return -EINVAL;
+
+ DBG(TAB, ul_debugobj(tb, "ascii: %s", enable ? "ENABLE" : "DISABLE"));
tb->ascii = enable ? 1 : 0;
return 0;
}
assert(tb);
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "noheading: %s", enable ? "ENABLE" : "DISABLE"));
tb->no_headings = enable ? 1 : 0;
return 0;
}
assert(tb);
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "maxout: %s", enable ? "ENABLE" : "DISABLE"));
tb->maxout = enable ? 1 : 0;
return 0;
}
return -ENOMEM;
}
+ DBG(TAB, ul_debugobj(tb, "new columns separator: %s", sep));
free(tb->colsep);
tb->colsep = p;
return 0;
return -ENOMEM;
}
+ DBG(TAB, ul_debugobj(tb, "new lines separator: %s", sep));
free(tb->linesep);
tb->linesep = p;
return 0;
if (!tb || !cl)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "sorting table"));
list_sort(&tb->tb_lines, cells_cmp_wrapper, cl);
return 0;
}
buf->cur = buf->begin = ((char *) buf) + sizeof(struct libscols_buffer);
buf->encdata = NULL;
buf->bufsz = sz;
+
+ DBG(BUFF, ul_debugobj(buf, "alloc (size=%zu)", sz));
return buf;
}
static void free_buffer(struct libscols_buffer *buf)
{
+ if (!buf)
+ return;
+ DBG(BUFF, ul_debugobj(buf, "dealloc"));
free(buf->encdata);
free(buf);
}
if (!buf)
return -EINVAL;
+ /*DBG(BUFF, ul_debugobj(buf, "reset data"));*/
buf->begin[0] = '\0';
buf->cur = buf->begin;
buf->art_idx = 0;
/* save the current buffer possition to art_idx */
static void buffer_set_art_index(struct libscols_buffer *buf)
{
- if (buf)
+ if (buf) {
buf->art_idx = buf->cur - buf->begin;
+ /*DBG(BUFF, ul_debugobj(buf, "art index: %zu", buf->art_idx));*/
+ }
}
static char *buffer_get_data(struct libscols_buffer *buf)
assert(tb);
assert(cl);
+ DBG(TAB, ul_debugobj(tb,
+ " -> data, column=%p, line=%p, cell=%p, buff=%p",
+ cl, ln, ce, buf));
+
data = buffer_get_data(buf);
if (!data)
data = "";
assert(ln);
+ DBG(TAB, ul_debugobj(tb, "printing line, line=%p, buff=%p", ln, buf));
+
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
rc = cell_to_buffer(tb, ln, cl, buf);
list_empty(&tb->tb_lines))
return 0;
+ DBG(TAB, ul_debugobj(tb, "printing header"));
+
/* set width according to the size of data
*/
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
assert(tb);
+ DBG(TAB, ul_debugobj(tb, "printing tree"));
+
rc = print_header(tb, buf);
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
return rc;
}
+static void dbg_column(struct libscols_table *tb, struct libscols_column *cl)
+{
+ DBG(COL, ul_debugobj(cl, "%15s seq=%zu, width=%zd, "
+ "hint=%d, avg=%zu, max=%zu, min=%zu, "
+ "extreme=%s",
+
+ cl->header.data, cl->seqnum, cl->width,
+ cl->width_hint > 1 ? (int) cl->width_hint :
+ (int) (cl->width_hint * tb->termwidth),
+ cl->width_avg,
+ cl->width_max,
+ cl->width_min,
+ cl->is_extreme ? "yes" : "not"));
+}
+
+static void dbg_columns(struct libscols_table *tb)
+{
+ struct libscols_iter itr;
+ struct libscols_column *cl;
+
+ scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
+ while (scols_table_next_column(tb, &itr, &cl) == 0)
+ dbg_column(tb, cl);
+}
+
/*
* This function counts column width.
*
cl->width = (size_t) cl->width_hint;
+ ON_DBG(COL, dbg_column(tb, cl));
return rc;
}
+
/*
* This is core of the scols_* voodo...
*/
int trunc_only, rc = 0;
int extremes = 0;
+
+ DBG(TAB, ul_debugobj(tb, "recounting widths (termwidth=%zu)", tb->termwidth));
+
/* set basic columns width
*/
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
/* reduce columns with extreme fields
*/
if (width > tb->termwidth && extremes) {
+ DBG(TAB, ul_debugobj(tb, " reduce width (extreme columns)"));
+
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (scols_table_next_column(tb, &itr, &cl) == 0) {
size_t org_width;
}
if (width < tb->termwidth) {
- /* try to found extreme column which fits into available space
- */
if (extremes) {
+ DBG(TAB, ul_debugobj(tb, " enlarge width (extreme columns)"));
+
/* enlarge the first extreme column */
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (scols_table_next_column(tb, &itr, &cl) == 0) {
}
if (width < tb->termwidth && scols_table_is_maxout(tb)) {
+ DBG(TAB, ul_debugobj(tb, " enlarge width (max-out)"));
+
/* try enlarge all columns */
while (width < tb->termwidth) {
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
struct libscols_column *cl = list_entry(
tb->tb_columns.prev, struct libscols_column, cl_columns);
+ DBG(TAB, ul_debugobj(tb, " enlarge width (last column)"));
+
if (!scols_column_is_right(cl) && tb->termwidth - width > 0) {
cl->width += tb->termwidth - width;
width = tb->termwidth;
while (width > tb->termwidth) {
size_t org = width;
+ DBG(TAB, ul_debugobj(tb, " reduce width (current=%zu, "
+ "wanted=%zu, mode=%s)",
+ width, tb->termwidth,
+ trunc_only ? "trunc-only" : "all-relative"));
+
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (scols_table_next_column(tb, &itr, &cl) == 0) {
if (width <= tb->termwidth)
}
}
-/*
- fprintf(stderr, "terminal: %d, output: %d\n", tb->termwidth, width);
+ DBG(TAB, ul_debugobj(tb, " result: %zu", width));
+ ON_DBG(TAB, dbg_columns(tb));
- scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
- while (scols_table_next_column(tb, &itr, &cl) == 0) {
- fprintf(stderr, "width: %s=%zd [hint=%d, avg=%zd, max=%zd, extreme=%s]\n",
- cl->name, cl->width,
- cl->width_hint > 1 ? (int) cl->width_hint :
- (int) (cl->width_hint * tb->termwidth),
- cl->width_avg,
- cl->width_max,
- cl->is_extreme ? "yes" : "not");
- }
-*/
return rc;
}
if (!tb)
return -1;
+ DBG(TAB, ul_debugobj(tb, "printing"));
if (!tb->symbols)
scols_table_set_symbols(tb, NULL); /* use default */
if (!tb)
return -EINVAL;
+ DBG(TAB, ul_debugobj(tb, "printing to string"));
+
/* create a stream for output */
stream = open_memstream(data, &sz);
if (!stream)
} else if (argc != optind)
usage(stderr);
+ scols_init_debug(0);
+
/* lslogins -u -s == lslogins */
if (lslogins_flag & F_USRAC && lslogins_flag & F_SYSAC)
lslogins_flag &= ~(F_USRAC | F_SYSAC);
* initialize libmount
*/
mnt_init_debug(0);
+ scols_init_debug(0);
tb = parse_tabfiles(tabfiles, ntabfiles, tabtype);
if (!tb)
errx(EXIT_FAILURE, _("the sort column has to be between output columns."));
mnt_init_debug(0);
+ scols_init_debug(0);
/*
* initialize output columns
&ncolumns, column_name_to_id) < 0)
return EXIT_FAILURE;
+ scols_init_debug(0);
+
rc = get_local_locks(&locks);
if (!rc && !list_empty(&locks))
struct libscols_line *ln;
int i, rc = 0;
+ scols_init_debug(0);
+
if (!(tb = scols_new_table()))
err(EXIT_FAILURE, _("failed to initialize output table"));
scols_table_enable_raw(tb, raw);
int i;
char buf[BUFSIZ];
const char *data;
- struct libscols_table *table = scols_new_table();
+ struct libscols_table *table;
+ scols_init_debug(0);
+
+ table = scols_new_table();
if (!table)
err(EXIT_FAILURE, _("failed to initialize output table"));
columns[ncolumns++] = COL_UNITS;
}
+ scols_init_debug(0);
+
if (list_empty(&lims)) {
/* default is to print all resources */
size_t n;
if (!itr)
err(EXIT_FAILURE, _("failed to initialize libmount iterator"));
+ scols_init_debug(0);
+
table = scols_new_table();
if (!table)
err(EXIT_FAILURE, _("failed to initialize output table"));
struct libscols_table *table;
uint32_t flags;
+ scols_init_debug(0);
+
/* create output table */
table = scols_new_table();
if (!table) {