Table

Table — table data API

Synopsis

struct              libscols_table;
struct libscols_table * scols_copy_table                (struct libscols_table *tb);
struct libscols_table * scols_new_table                 (void);
void                scols_ref_table                     (struct libscols_table *tb);
int                 scols_table_add_column              (struct libscols_table *tb,
                                                         struct libscols_column *cl);
int                 scols_table_add_line                (struct libscols_table *tb,
                                                         struct libscols_line *ln);
int                 scols_table_colors_wanted           (struct libscols_table *tb);
int                 scols_table_enable_ascii            (struct libscols_table *tb,
                                                         int enable);
int                 scols_table_enable_colors           (struct libscols_table *tb,
                                                         int enable);
int                 scols_table_enable_export           (struct libscols_table *tb,
                                                         int enable);
int                 scols_table_enable_maxout           (struct libscols_table *tb,
                                                         int enable);
int                 scols_table_enable_noheadings       (struct libscols_table *tb,
                                                         int enable);
int                 scols_table_enable_raw              (struct libscols_table *tb,
                                                         int enable);
struct libscols_column * scols_table_get_column         (struct libscols_table *tb,
                                                         size_t n);
char *              scols_table_get_column_separator    (struct libscols_table *tb);
struct libscols_line * scols_table_get_line             (struct libscols_table *tb,
                                                         size_t n);
char *              scols_table_get_line_separator      (struct libscols_table *tb);
int                 scols_table_get_ncols               (struct libscols_table *tb);
int                 scols_table_get_nlines              (struct libscols_table *tb);
FILE *              scols_table_get_stream              (struct libscols_table *tb);
int                 scols_table_is_ascii                (struct libscols_table *tb);
int                 scols_table_is_empty                (struct libscols_table *tb);
int                 scols_table_is_export               (struct libscols_table *tb);
int                 scols_table_is_maxout               (struct libscols_table *tb);
int                 scols_table_is_noheadings           (struct libscols_table *tb);
int                 scols_table_is_raw                  (struct libscols_table *tb);
int                 scols_table_is_tree                 (struct libscols_table *tb);
struct libscols_column * scols_table_new_column         (struct libscols_table *tb,
                                                         const char *name,
                                                         double whint,
                                                         int flags);
struct libscols_line * scols_table_new_line             (struct libscols_table *tb,
                                                         struct libscols_line *parent);
int                 scols_table_next_column             (struct libscols_table *tb,
                                                         struct libscols_iter *itr,
                                                         struct libscols_column **cl);
int                 scols_table_next_line               (struct libscols_table *tb,
                                                         struct libscols_iter *itr,
                                                         struct libscols_line **ln);
int                 scols_table_reduce_termwidth        (struct libscols_table *tb,
                                                         size_t reduce);
int                 scols_table_remove_column           (struct libscols_table *tb,
                                                         struct libscols_column *cl);
int                 scols_table_remove_columns          (struct libscols_table *tb);
int                 scols_table_remove_line             (struct libscols_table *tb,
                                                         struct libscols_line *ln);
void                scols_table_remove_lines            (struct libscols_table *tb);
int                 scols_table_set_column_separator    (struct libscols_table *tb,
                                                         const char *sep);
int                 scols_table_set_line_separator      (struct libscols_table *tb,
                                                         const char *sep);
int                 scols_table_set_stream              (struct libscols_table *tb,
                                                         FILE *stream);
int                 scols_table_set_symbols             (struct libscols_table *tb,
                                                         struct libscols_symbols *sy);
int                 scols_sort_table                    (struct libscols_table *tb,
                                                         struct libscols_column *cl);
void                scols_unref_table                   (struct libscols_table *tb);

Description

Table data manipulation API.

Details

struct libscols_table

struct libscols_table;

A table - The most abstract object, encapsulating lines, columns, symbols and cells


scols_copy_table ()

struct libscols_table * scols_copy_table                (struct libscols_table *tb);

Creates a new independent table copy, except struct libscols_symbols that are shared between the tables.

tb :

table

Returns :

a newly allocated copy of tb

scols_new_table ()

struct libscols_table * scols_new_table                 (void);

Returns :

A newly allocated table.

scols_ref_table ()

void                scols_ref_table                     (struct libscols_table *tb);

Increases the refcount of tb.

tb :

a pointer to a struct libscols_table instance

scols_table_add_column ()

int                 scols_table_add_column              (struct libscols_table *tb,
                                                         struct libscols_column *cl);

Adds cl to tb's column list.

tb :

a pointer to a struct libscols_table instance

cl :

a pointer to a struct libscols_column instance

Returns :

0, a negative number in case of an error.

scols_table_add_line ()

int                 scols_table_add_line                (struct libscols_table *tb,
                                                         struct libscols_line *ln);

Note that this function calls scols_line_alloc_cells() if number of the cells in the line is too small for tb.

tb :

table

ln :

line

Returns :

0, a negative value in case of an error.

scols_table_colors_wanted ()

int                 scols_table_colors_wanted           (struct libscols_table *tb);

tb :

table

Returns :

1 if colors are enabled.

scols_table_enable_ascii ()

int                 scols_table_enable_ascii            (struct libscols_table *tb,
                                                         int enable);

The ASCII-only output is relevant for tree-like outputs. The library checks if the current environment is UTF8 compatible by default. This function overrides this check and force the library to use ASCII chars for the tree.

If a custom libcols_symbols are specified (see scols_table_set_symbols() then ASCII flag setting is ignored.

tb :

table

enable :

1 or 0

Returns :

0 on success, negative number in case of an error.

scols_table_enable_colors ()

int                 scols_table_enable_colors           (struct libscols_table *tb,
                                                         int enable);

Enable/disable colors.

tb :

table

enable :

1 or 0

Returns :

0 on success, negative number in case of an error.

scols_table_enable_export ()

int                 scols_table_enable_export           (struct libscols_table *tb,
                                                         int enable);

Enable/disable export output format (COLUMNAME="value" ...). The parsable output formats (export and raw) are mutually exclusive.

tb :

table

enable :

1 or 0

Returns :

0 on success, negative number in case of an error.

scols_table_enable_maxout ()

int                 scols_table_enable_maxout           (struct libscols_table *tb,
                                                         int enable);

The extra space after last column is ignored by default. The output maximization use the extra space for all columns.

tb :

table

enable :

1 or 0

Returns :

0 on success, negative number in case of an error.

scols_table_enable_noheadings ()

int                 scols_table_enable_noheadings       (struct libscols_table *tb,
                                                         int enable);

Enable/disable header line.

tb :

table

enable :

1 or 0

Returns :

0 on success, negative number in case of an error.

scols_table_enable_raw ()

int                 scols_table_enable_raw              (struct libscols_table *tb,
                                                         int enable);

Enable/disable raw output format. The parsable output formats (export and raw) are mutually exclusive.

tb :

table

enable :

1 or 0

Returns :

0 on success, negative number in case of an error.

scols_table_get_column ()

struct libscols_column * scols_table_get_column         (struct libscols_table *tb,
                                                         size_t n);

tb :

table

n :

number of column (0..N)

Returns :

pointer to column or NULL

scols_table_get_column_separator ()

char *              scols_table_get_column_separator    (struct libscols_table *tb);

tb :

table

Returns :

tb column separator, NULL in case of an error

scols_table_get_line ()

struct libscols_line * scols_table_get_line             (struct libscols_table *tb,
                                                         size_t n);

This is a shortcut for

ln = scols_new_line(); scols_line_set_....(cl, ...); scols_table_add_line(tb, ln);

tb :

table

n :

column number (0..N)

Returns :

a newly allocate line

scols_table_get_line_separator ()

char *              scols_table_get_line_separator      (struct libscols_table *tb);

tb :

table

Returns :

tb line separator, NULL in case of an error

scols_table_get_ncols ()

int                 scols_table_get_ncols               (struct libscols_table *tb);

tb :

table

Returns :

the ncols table member, a negative number in case of an error.

scols_table_get_nlines ()

int                 scols_table_get_nlines              (struct libscols_table *tb);

tb :

table

Returns :

the nlines table member, a negative number in case of an error.

scols_table_get_stream ()

FILE *              scols_table_get_stream              (struct libscols_table *tb);

Gets the output stream for table tb.

tb :

table

Returns :

stream pointer, NULL in case of an error or an unset stream.

scols_table_is_ascii ()

int                 scols_table_is_ascii                (struct libscols_table *tb);

tb :

table

Returns :

1 if ASCII tree is enabled.

scols_table_is_empty ()

int                 scols_table_is_empty                (struct libscols_table *tb);

tb :

table

Returns :

1 if the table is empty.

scols_table_is_export ()

int                 scols_table_is_export               (struct libscols_table *tb);

tb :

table

Returns :

1 if export output format is enabled.

scols_table_is_maxout ()

int                 scols_table_is_maxout               (struct libscols_table *tb);

tb :

table

Returns :

1 if output maximization is enabled, negative value in case of an error.

scols_table_is_noheadings ()

int                 scols_table_is_noheadings           (struct libscols_table *tb);

tb :

table

Returns :

1 if header output is disabled.

scols_table_is_raw ()

int                 scols_table_is_raw                  (struct libscols_table *tb);

tb :

table

Returns :

1 if raw output format is enabled.

scols_table_is_tree ()

int                 scols_table_is_tree                 (struct libscols_table *tb);

tb :

table

Returns :

returns 1 tree-like output is expected.

scols_table_new_column ()

struct libscols_column * scols_table_new_column         (struct libscols_table *tb,
                                                         const char *name,
                                                         double whint,
                                                         int flags);

This is shortcut for

cl = scols_new_column(); scols_column_set_....(cl, ...); scols_table_add_column(tb, cl);

The column width is possible to define by three ways:

whint = 0..1 : relative width, percent of terminal width

whint = 1..N : absolute width, empty colum will be truncated to the column header width

whint = 1..N

The column is necessary to address by sequential number. The first defined column has the colnum = 0. For example:

scols_table_new_column(tab, "FOO", 0.5, 0); // colnum = 0 scols_table_new_column(tab, "BAR", 0.5, 0); // colnum = 1 . . scols_line_get_cell(line, 0); // FOO column scols_line_get_cell(line, 1); // BAR column

tb :

table

name :

column header

whint :

column width hint (absolute width: N > 1; relative width: N < 1)

flags :

flags integer

Returns :

newly allocated column

scols_table_new_line ()

struct libscols_line * scols_table_new_line             (struct libscols_table *tb,
                                                         struct libscols_line *parent);

This is shortcut for

ln = scols_new_line(); scols_table_add_line(tb, ln); scols_line_add_child(parent, ln);

tb :

table

parent :

parental line or NULL

Returns :

newly allocate line

scols_table_next_column ()

int                 scols_table_next_column             (struct libscols_table *tb,
                                                         struct libscols_iter *itr,
                                                         struct libscols_column **cl);

Returns the next column of tb via cl.

tb :

a pointer to a struct libscols_table instance

itr :

a pointer to a struct libscols_iter instance

cl :

a pointer to a pointer to a struct libscols_column instance

Returns :

0, a negative value in case of an error.

scols_table_next_line ()

int                 scols_table_next_line               (struct libscols_table *tb,
                                                         struct libscols_iter *itr,
                                                         struct libscols_line **ln);

Finds the next line and returns a pointer to it via ln.

tb :

a pointer to a struct libscols_table instance

itr :

a pointer to a struct libscols_iter instance

ln :

a pointer to a pointer to a struct libscols_line instance

Returns :

0, a negative value in case of an error.

scols_table_reduce_termwidth ()

int                 scols_table_reduce_termwidth        (struct libscols_table *tb,
                                                         size_t reduce);

Reduce the output width to reduce.

tb :

table

reduce :

width

Returns :

0, a negative value in case of an error.

scols_table_remove_column ()

int                 scols_table_remove_column           (struct libscols_table *tb,
                                                         struct libscols_column *cl);

Removes cl from tb.

tb :

a pointer to a struct libscols_table instance

cl :

a pointer to a struct libscols_column instance

Returns :

0, a negative number in case of an error.

scols_table_remove_columns ()

int                 scols_table_remove_columns          (struct libscols_table *tb);

Removes all of tb's columns.

tb :

a pointer to a struct libscols_table instance

Returns :

0, a negative number in case of an error.

scols_table_remove_line ()

int                 scols_table_remove_line             (struct libscols_table *tb,
                                                         struct libscols_line *ln);

Note that this function does not destroy the parent<->child relationship between lines. You have to call scols_line_remove_child()

tb :

table

ln :

line

Returns :

0, a negative value in case of an error.

scols_table_remove_lines ()

void                scols_table_remove_lines            (struct libscols_table *tb);

This empties the table and also destroys all the parent<->child relationships.

tb :

table

scols_table_set_column_separator ()

int                 scols_table_set_column_separator    (struct libscols_table *tb,
                                                         const char *sep);

Sets the column separator of tb to sep. Please note that sep should always take up a single cell in the output.

tb :

table

sep :

separator

Returns :

0, a negative value in case of an error.

scols_table_set_line_separator ()

int                 scols_table_set_line_separator      (struct libscols_table *tb,
                                                         const char *sep);

Sets the line separator of tb to sep.

tb :

table

sep :

separator

Returns :

0, a negative value in case of an error.

scols_table_set_stream ()

int                 scols_table_set_stream              (struct libscols_table *tb,
                                                         FILE *stream);

Sets the output stream for table tb.

tb :

table

stream :

output stream

Returns :

0, a negative number in case of an error.

scols_table_set_symbols ()

int                 scols_table_set_symbols             (struct libscols_table *tb,
                                                         struct libscols_symbols *sy);

Add a reference to sy from the table. The symbols are used by library to draw tree output. If no symbols are specified then library checks the current environment to select ASCII or UTF8 symbols. This default behavior could be controlled by scols_table_enable_ascii().

tb :

table

sy :

symbols or NULL

Returns :

0, a negative value in case of an error.

scols_sort_table ()

int                 scols_sort_table                    (struct libscols_table *tb,
                                                         struct libscols_column *cl);

Orders the table by the column. See also scols_column_set_cmpfunc().

tb :

table

cl :

order by this column

Returns :

0, a negative value in case of an error.

scols_unref_table ()

void                scols_unref_table                   (struct libscols_table *tb);

Decreases the refcount of tb. When the count falls to zero, the instance is automatically deallocated.

tb :

a pointer to a struct libscols_table instance