libsmartcols: add scols_line_is_ancestor()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
60102db546
commit
eebf2dd89b
|
@ -71,6 +71,7 @@ scols_line_get_ncells
|
|||
scols_line_get_parent
|
||||
scols_line_get_userdata
|
||||
scols_line_has_children
|
||||
scols_line_is_ancestor
|
||||
scols_line_next_child
|
||||
scols_line_refer_column_data
|
||||
scols_line_refer_data
|
||||
|
|
|
@ -193,6 +193,7 @@ extern void *scols_line_get_userdata(struct libscols_line *ln);
|
|||
extern int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *child);
|
||||
extern int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child);
|
||||
extern int scols_line_has_children(struct libscols_line *ln);
|
||||
extern int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *parent);
|
||||
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(const struct libscols_line *ln);
|
||||
|
|
|
@ -164,4 +164,5 @@ global:
|
|||
scols_cell_get_alignment;
|
||||
scols_table_move_column;
|
||||
scols_sort_table_by_tree;
|
||||
scols_line_is_ancestor;
|
||||
} SMARTCOLS_2.29;
|
||||
|
|
|
@ -307,6 +307,25 @@ int scols_line_next_child(struct libscols_line *ln,
|
|||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* scols_line_is_ancestor:
|
||||
* @ln: line
|
||||
* @parent: potential parent
|
||||
*
|
||||
* The function is designed to detect circular dependencies between @ln and
|
||||
* @parent. It checks if @ln is not any (grand) parent in the @parent's tree.
|
||||
*/
|
||||
int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *parent)
|
||||
{
|
||||
while (parent) {
|
||||
if (parent == ln)
|
||||
return 1;
|
||||
parent = scols_line_get_parent(parent);
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* scols_line_set_color:
|
||||
* @ln: a pointer to a struct libscols_line instance
|
||||
|
|
Loading…
Reference in New Issue