void tree_foreach(struct tree_link *tree, tree_link_arg_predicate_t predicate, void *arg) { struct list_link *iter, *enditer; struct tree_link *item; if(!list_is_empty(&tree->children)) { iter = list_first_link(&tree->children); enditer = list_last_link(&tree->children); for(; iter != enditer; iter = list_next(iter)) { item = MEMBERCAST(struct tree_link, iter, listLink); /* goto child */ tree_foreach(item, predicate, arg); /* then all child are look in, call user */ predicate(item, arg); } }
void tree_init_save(tree_t *tree) { char *filename; FILE *f; /* Build init file name from tree file name */ filename = tree_init_filename(tree); if ( (f = fopen(filename, "w")) != NULL ) { long size; tree_foreach(tree, (tree_func_t *) tree_init_save_object, f); size = ftell(f); fclose(f); if ( size <= 0 ) remove(filename); } free(filename); }
void userlist_rehash (session *sess) { tree_foreach (sess->usertree_alpha, (tree_traverse_func *)rehash_cb, sess); }
void url_clear() { tree_foreach((tree*)url_tree, (tree_traverse_func*)url_free, nullptr); tree_destroy((tree*)url_tree); url_tree = nullptr; }
static void tree_init_load_line(tree_t *tree, char *str, tree_err_loc_t *loc) { char *s1, *s2; int qual = -1; /* Remove comments */ if ( (s1 = strchr(str, '#')) != NULL ) *s1 = NUL; /* Parse init qualifier */ s1 = strskip_spaces(str); s2 = strskip_chars(s1); if ( *s2 != NUL ) *(s2++) = NUL; s2 = strskip_spaces(s2); if ( *s1 == NUL ) return; strupper(s1); if ( strcmp(s1, "BREAKPOINT") == 0 ) { qual = TREE_INIT_BREAKPOINT | TREE_INIT_ENABLE; } else if ( strcmp(s1, "/BREAKPOINT") == 0 ) { qual = TREE_INIT_BREAKPOINT; } else if ( strcmp(s1, "FORCE_SKIP") == 0 ) { qual = TREE_INIT_FORCE_SKIP | TREE_INIT_ENABLE; } else if ( strcmp(s1, "/FORCE_SKIP") == 0 ) { qual = TREE_INIT_FORCE_SKIP; } else if ( strcmp(s1, "CLEAR") == 0 ) { qual = TREE_INIT_CLEAR; } else { tree_warning(tree, loc, "Illegal init qualifier"); } if ( qual >= 0 ) { /* Parse node names */ while ( *s2 != NUL ) { /* Extract node name */ s1 = s2; s2 = strskip_chars(s1); if ( *s2 != NUL ) *(s2++) = NUL; s2 = strskip_spaces(s2); /* Wildcard for all nodes */ if ( strcmp(s1, "*") == 0 ) { tree_foreach(tree, (tree_func_t *) tree_init_load_object, (void *) qual); } else { tree_item_t *item = tree_retrieve(tree, s1); if ( item != NULL ) { if ( item->object->type == TYPE_SEQ ) qual |= TREE_INIT_RECURSIVE; tree_init_load_item(item, qual); } else { tree_warning(tree, loc, "Unknown node name '%s'", s1); } } } } }
void tex_tr_release(struct tex_tr *tr) { tree_foreach(&tr->tnd, &tree_post_order_DFS, &release, 0, NULL); }
void tex_tr_print(struct tex_tr *tr, FILE *fh) { tree_foreach(&tr->tnd, &tree_pre_order_DFS, &print, 0, fh); }