libsmartcols: use const qualifier where it's possible

Closes: https://github.com/karelzak/util-linux/issues/355
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
Igor Gnatenko 2016-09-21 08:30:48 +02:00
parent 0e0943c15b
commit f7a9ea28ef
7 changed files with 65 additions and 71 deletions

View File

@ -138,7 +138,7 @@ int scols_column_set_whint(struct libscols_column *cl, double whint)
*
* Returns: The width hint of column @cl, a negative value in case of an error.
*/
double scols_column_get_whint(struct libscols_column *cl)
double scols_column_get_whint(const struct libscols_column *cl)
{
return cl->width_hint;
}
@ -174,7 +174,7 @@ int scols_column_set_flags(struct libscols_column *cl, int flags)
*
* Returns: The flag mask of @cl, a negative value in case of an error.
*/
int scols_column_get_flags(struct libscols_column *cl)
int scols_column_get_flags(const struct libscols_column *cl)
{
return cl->flags;
}
@ -222,7 +222,7 @@ int scols_column_set_color(struct libscols_column *cl, const char *co)
*
* Returns: The current color setting of the column @cl.
*/
const char *scols_column_get_color(struct libscols_column *cl)
const char *scols_column_get_color(const struct libscols_column *cl)
{
return cl->color;
}
@ -260,7 +260,7 @@ int scols_column_set_cmpfunc(struct libscols_column *cl,
*
* Since: 2.27
*/
int scols_column_is_hidden(struct libscols_column *cl)
int scols_column_is_hidden(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_HIDDEN ? 1 : 0;
}
@ -273,7 +273,7 @@ int scols_column_is_hidden(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_trunc(struct libscols_column *cl)
int scols_column_is_trunc(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_TRUNC ? 1 : 0;
}
@ -285,7 +285,7 @@ int scols_column_is_trunc(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_tree(struct libscols_column *cl)
int scols_column_is_tree(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_TREE ? 1 : 0;
}
@ -297,7 +297,7 @@ int scols_column_is_tree(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_right(struct libscols_column *cl)
int scols_column_is_right(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_RIGHT ? 1 : 0;
}
@ -309,7 +309,7 @@ int scols_column_is_right(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_strict_width(struct libscols_column *cl)
int scols_column_is_strict_width(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_STRICTWIDTH ? 1 : 0;
}
@ -321,7 +321,7 @@ int scols_column_is_strict_width(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_noextremes(struct libscols_column *cl)
int scols_column_is_noextremes(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_NOEXTREMES ? 1 : 0;
}
@ -335,7 +335,7 @@ int scols_column_is_noextremes(struct libscols_column *cl)
*
* Since: 2.28
*/
int scols_column_is_wrap(struct libscols_column *cl)
int scols_column_is_wrap(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_WRAP ? 1 : 0;
}
@ -349,7 +349,7 @@ int scols_column_is_wrap(struct libscols_column *cl)
*
* Since: 2.29
*/
int scols_column_is_wrapnl(struct libscols_column *cl)
int scols_column_is_wrapnl(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_WRAPNL ? 1 : 0;
}

View File

@ -68,7 +68,7 @@ void scols_reset_iter(struct libscols_iter *itr, int direction)
*
* Returns: SCOLS_INTER_{FOR,BACK}WARD
*/
int scols_iter_get_direction(struct libscols_iter *itr)
int scols_iter_get_direction(const struct libscols_iter *itr)
{
return itr->direction;
}

View File

@ -100,7 +100,7 @@ enum {
extern struct libscols_iter *scols_new_iter(int direction);
extern void scols_free_iter(struct libscols_iter *itr);
extern void scols_reset_iter(struct libscols_iter *itr, int direction);
extern int scols_iter_get_direction(struct libscols_iter *itr);
extern int scols_iter_get_direction(const struct libscols_iter *itr);
/* init.c */
extern void scols_init_debug(int mask);
@ -139,26 +139,26 @@ extern int scols_cell_set_userdata(struct libscols_cell *ce, void *data);
extern int scols_cmpstr_cells(struct libscols_cell *a,
struct libscols_cell *b, void *data);
/* column.c */
extern int scols_column_is_tree(struct libscols_column *cl);
extern int scols_column_is_trunc(struct libscols_column *cl);
extern int scols_column_is_right(struct libscols_column *cl);
extern int scols_column_is_strict_width(struct libscols_column *cl);
extern int scols_column_is_hidden(struct libscols_column *cl);
extern int scols_column_is_noextremes(struct libscols_column *cl);
extern int scols_column_is_wrap(struct libscols_column *cl);
extern int scols_column_is_wrapnl(struct libscols_column *cl);
extern int scols_column_is_tree(const struct libscols_column *cl);
extern int scols_column_is_trunc(const struct libscols_column *cl);
extern int scols_column_is_right(const struct libscols_column *cl);
extern int scols_column_is_strict_width(const struct libscols_column *cl);
extern int scols_column_is_hidden(const struct libscols_column *cl);
extern int scols_column_is_noextremes(const struct libscols_column *cl);
extern int scols_column_is_wrap(const struct libscols_column *cl);
extern int scols_column_is_wrapnl(const struct libscols_column *cl);
extern int scols_column_set_flags(struct libscols_column *cl, int flags);
extern int scols_column_get_flags(struct libscols_column *cl);
extern int scols_column_get_flags(const struct libscols_column *cl);
extern struct libscols_column *scols_new_column(void);
extern void scols_ref_column(struct libscols_column *cl);
extern void scols_unref_column(struct libscols_column *cl);
extern struct libscols_column *scols_copy_column(const struct libscols_column *cl);
extern int scols_column_set_whint(struct libscols_column *cl, double whint);
extern double scols_column_get_whint(struct libscols_column *cl);
extern double scols_column_get_whint(const struct libscols_column *cl);
extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl);
extern int scols_column_set_color(struct libscols_column *cl, const char *color);
extern const char *scols_column_get_color(struct libscols_column *cl);
extern const char *scols_column_get_color(const struct libscols_column *cl);
extern int scols_column_set_cmpfunc(struct libscols_column *cl,
int (*cmp)(struct libscols_cell *a,
@ -178,10 +178,10 @@ extern int scols_line_add_child(struct libscols_line *ln, struct libscols_line *
extern int scols_line_has_children(struct libscols_line *ln);
extern int scols_line_next_child(struct libscols_line *ln,
struct libscols_iter *itr, struct libscols_line **chld);
extern struct libscols_line *scols_line_get_parent(struct libscols_line *ln);
extern struct libscols_line *scols_line_get_parent(const struct libscols_line *ln);
extern int scols_line_set_color(struct libscols_line *ln, const char *color);
extern const char *scols_line_get_color(struct libscols_line *ln);
extern size_t scols_line_get_ncells(struct libscols_line *ln);
extern const char *scols_line_get_color(const struct libscols_line *ln);
extern size_t scols_line_get_ncells(const struct libscols_line *ln);
extern struct libscols_cell *scols_line_get_cell(struct libscols_line *ln, size_t n);
extern struct libscols_cell *scols_line_get_column_cell(
struct libscols_line *ln,
@ -190,20 +190,20 @@ extern int scols_line_set_data(struct libscols_line *ln, size_t n, const char *d
extern int scols_line_refer_data(struct libscols_line *ln, size_t n, char *data);
extern int scols_line_set_column_data(struct libscols_line *ln, struct libscols_column *cl, const char *data);
extern int scols_line_refer_column_data(struct libscols_line *ln, struct libscols_column *cl, char *data);
extern struct libscols_line *scols_copy_line(struct libscols_line *ln);
extern struct libscols_line *scols_copy_line(const struct libscols_line *ln);
/* table */
extern int scols_table_colors_wanted(struct libscols_table *tb);
extern int scols_table_colors_wanted(const struct libscols_table *tb);
extern int scols_table_set_name(struct libscols_table *tb, const char *name);
extern struct libscols_cell *scols_table_get_title(struct libscols_table *tb);
extern int scols_table_is_raw(struct libscols_table *tb);
extern int scols_table_is_ascii(struct libscols_table *tb);
extern int scols_table_is_json(struct libscols_table *tb);
extern int scols_table_is_noheadings(struct libscols_table *tb);
extern int scols_table_is_empty(struct libscols_table *tb);
extern int scols_table_is_export(struct libscols_table *tb);
extern int scols_table_is_maxout(struct libscols_table *tb);
extern int scols_table_is_tree(struct libscols_table *tb);
extern int scols_table_is_raw(const struct libscols_table *tb);
extern int scols_table_is_ascii(const struct libscols_table *tb);
extern int scols_table_is_json(const struct libscols_table *tb);
extern int scols_table_is_noheadings(const struct libscols_table *tb);
extern int scols_table_is_empty(const struct libscols_table *tb);
extern int scols_table_is_export(const struct libscols_table *tb);
extern int scols_table_is_maxout(const struct libscols_table *tb);
extern int scols_table_is_tree(const struct libscols_table *tb);
extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
extern int scols_table_enable_raw(struct libscols_table *tb, int enable);
@ -226,10 +226,10 @@ extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_
extern int scols_table_remove_columns(struct libscols_table *tb);
extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl);
extern const char *scols_table_get_column_separator(struct libscols_table *tb);
extern const char *scols_table_get_line_separator(struct libscols_table *tb);
extern size_t scols_table_get_ncols(struct libscols_table *tb);
extern size_t scols_table_get_nlines(struct libscols_table *tb);
extern const char *scols_table_get_column_separator(const struct libscols_table *tb);
extern const char *scols_table_get_line_separator(const struct libscols_table *tb);
extern size_t scols_table_get_ncols(const struct libscols_table *tb);
extern size_t scols_table_get_nlines(const struct libscols_table *tb);
extern struct libscols_column *scols_table_get_column(struct libscols_table *tb, size_t n);
extern int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln);
extern int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln);
@ -241,7 +241,7 @@ extern struct libscols_table *scols_copy_table(struct libscols_table *tb);
extern int scols_table_set_symbols(struct libscols_table *tb, struct libscols_symbols *sy);
extern int scols_table_set_stream(struct libscols_table *tb, FILE *stream);
extern FILE *scols_table_get_stream(struct libscols_table *tb);
extern FILE *scols_table_get_stream(const struct libscols_table *tb);
extern int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce);
extern int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl);
@ -255,7 +255,7 @@ enum {
SCOLS_TERMFORCE_ALWAYS
};
extern int scols_table_set_termforce(struct libscols_table *tb, int force);
extern int scols_table_get_termforce(struct libscols_table *tb);
extern int scols_table_get_termforce(const struct libscols_table *tb);
extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
extern size_t scols_table_get_termwidth(struct libscols_table *tb);

View File

@ -71,7 +71,6 @@ void scols_ref_line(struct libscols_line *ln)
*/
void scols_unref_line(struct libscols_line *ln)
{
if (ln && --ln->refcount <= 0) {
DBG(CELL, ul_debugobj(ln, "dealloc"));
list_del(&ln->ln_lines);
@ -235,7 +234,7 @@ int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child)
*
* Returns: a pointer to @ln's parent, NULL in case it has no parent or if there was an error.
*/
struct libscols_line *scols_line_get_parent(struct libscols_line *ln)
struct libscols_line *scols_line_get_parent(const struct libscols_line *ln)
{
return ln ? ln->parent : NULL;
}
@ -304,7 +303,7 @@ int scols_line_set_color(struct libscols_line *ln, const char *co)
*
* Returns: @ln's color string, NULL in case of an error.
*/
const char *scols_line_get_color(struct libscols_line *ln)
const char *scols_line_get_color(const struct libscols_line *ln)
{
return ln->color;
}
@ -315,7 +314,7 @@ const char *scols_line_get_color(struct libscols_line *ln)
*
* Returns: number of cells
*/
size_t scols_line_get_ncells(struct libscols_line *ln)
size_t scols_line_get_ncells(const struct libscols_line *ln)
{
return ln->ncells;
}
@ -432,7 +431,7 @@ int scols_line_refer_column_data(struct libscols_line *ln,
*
* Returns: A newly allocated copy of @ln, NULL in case of an error.
*/
struct libscols_line *scols_copy_line(struct libscols_line *ln)
struct libscols_line *scols_copy_line(const struct libscols_line *ln)
{
struct libscols_line *ret;
size_t i;

View File

@ -184,7 +184,7 @@ struct libscols_table {
} while(0)
static inline int scols_iter_is_last(struct libscols_iter *itr)
static inline int scols_iter_is_last(const struct libscols_iter *itr)
{
if (!itr || !itr->head || !itr->p)
return 0;

View File

@ -170,5 +170,4 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sy)
scols_unref_symbols(ret);
return NULL;
}

View File

@ -112,7 +112,6 @@ void scols_unref_table(struct libscols_table *tb)
}
}
/**
* scols_table_set_name:
* @tb: a pointer to a struct libscols_table instance
@ -227,7 +226,6 @@ int scols_table_remove_columns(struct libscols_table *tb)
return 0;
}
/**
* scols_table_new_column:
* @tb: table
@ -331,14 +329,13 @@ int scols_table_next_column(struct libscols_table *tb,
return rc;
}
/**
* scols_table_get_ncols:
* @tb: table
*
* Returns: the ncols table member
* Returns: the ncols table member.
*/
size_t scols_table_get_ncols(struct libscols_table *tb)
size_t scols_table_get_ncols(const struct libscols_table *tb)
{
return tb->ncols;
}
@ -347,9 +344,9 @@ size_t scols_table_get_ncols(struct libscols_table *tb)
* scols_table_get_nlines:
* @tb: table
*
* Returns: the nlines table member, a negative number in case of an error.
* Returns: the nlines table member.
*/
size_t scols_table_get_nlines(struct libscols_table *tb)
size_t scols_table_get_nlines(const struct libscols_table *tb)
{
return tb->nlines;
}
@ -382,7 +379,7 @@ int scols_table_set_stream(struct libscols_table *tb, FILE *stream)
*
* Returns: stream pointer, NULL in case of an error or an unset stream.
*/
FILE *scols_table_get_stream(struct libscols_table *tb)
FILE *scols_table_get_stream(const struct libscols_table *tb)
{
return tb->out;
}
@ -916,7 +913,7 @@ int scols_table_enable_nowrap(struct libscols_table *tb, int enable)
*
* Returns: 1 if colors are enabled.
*/
int scols_table_colors_wanted(struct libscols_table *tb)
int scols_table_colors_wanted(const struct libscols_table *tb)
{
return tb->colors_wanted;
}
@ -927,7 +924,7 @@ int scols_table_colors_wanted(struct libscols_table *tb)
*
* Returns: 1 if the table is empty.
*/
int scols_table_is_empty(struct libscols_table *tb)
int scols_table_is_empty(const struct libscols_table *tb)
{
return !tb->nlines;
}
@ -938,7 +935,7 @@ int scols_table_is_empty(struct libscols_table *tb)
*
* Returns: 1 if ASCII tree is enabled.
*/
int scols_table_is_ascii(struct libscols_table *tb)
int scols_table_is_ascii(const struct libscols_table *tb)
{
return tb->ascii;
}
@ -949,7 +946,7 @@ int scols_table_is_ascii(struct libscols_table *tb)
*
* Returns: 1 if header output is disabled.
*/
int scols_table_is_noheadings(struct libscols_table *tb)
int scols_table_is_noheadings(const struct libscols_table *tb)
{
return tb->no_headings;
}
@ -960,7 +957,7 @@ int scols_table_is_noheadings(struct libscols_table *tb)
*
* Returns: 1 if export output format is enabled.
*/
int scols_table_is_export(struct libscols_table *tb)
int scols_table_is_export(const struct libscols_table *tb)
{
return tb->format == SCOLS_FMT_EXPORT;
}
@ -971,7 +968,7 @@ int scols_table_is_export(struct libscols_table *tb)
*
* Returns: 1 if raw output format is enabled.
*/
int scols_table_is_raw(struct libscols_table *tb)
int scols_table_is_raw(const struct libscols_table *tb)
{
return tb->format == SCOLS_FMT_RAW;
}
@ -984,19 +981,18 @@ int scols_table_is_raw(struct libscols_table *tb)
*
* Since: 2.27
*/
int scols_table_is_json(struct libscols_table *tb)
int scols_table_is_json(const struct libscols_table *tb)
{
return tb->format == SCOLS_FMT_JSON;
}
/**
* scols_table_is_maxout
* @tb: table
*
* Returns: 1 if output maximization is enabled or 0
*/
int scols_table_is_maxout(struct libscols_table *tb)
int scols_table_is_maxout(const struct libscols_table *tb)
{
return tb->maxout;
}
@ -1007,7 +1003,7 @@ int scols_table_is_maxout(struct libscols_table *tb)
*
* Returns: returns 1 tree-like output is expected.
*/
int scols_table_is_tree(struct libscols_table *tb)
int scols_table_is_tree(const struct libscols_table *tb)
{
return tb->ntreecols > 0;
}
@ -1047,7 +1043,7 @@ int scols_table_set_line_separator(struct libscols_table *tb, const char *sep)
*
* Returns: @tb column separator, NULL in case of an error
*/
const char *scols_table_get_column_separator(struct libscols_table *tb)
const char *scols_table_get_column_separator(const struct libscols_table *tb)
{
return tb->colsep;
}
@ -1058,7 +1054,7 @@ const char *scols_table_get_column_separator(struct libscols_table *tb)
*
* Returns: @tb line separator, NULL in case of an error
*/
const char *scols_table_get_line_separator(struct libscols_table *tb)
const char *scols_table_get_line_separator(const struct libscols_table *tb)
{
return tb->linesep;
}
@ -1124,7 +1120,7 @@ int scols_table_set_termforce(struct libscols_table *tb, int force)
*
* Returns: SCOLS_TERMFORCE_{NEVER,ALWAYS,AUTO} or a negative value in case of an error.
*/
int scols_table_get_termforce(struct libscols_table *tb)
int scols_table_get_termforce(const struct libscols_table *tb)
{
return tb->termforce;
}