libsmartcols: add scols_line_is_ancestor()

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-05-05 12:12:43 +02:00
parent 60102db546
commit eebf2dd89b
4 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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