void unsafemap_rbtree_sub ( RBNODE node, void (*mapfun)(RBNODE) ){ if (NULL!=node){ mapfun(node); unsafemap_rbtree_sub(node->left,mapfun); unsafemap_rbtree_sub(node->right,mapfun); } }
void map_rbtree_sub ( RBNODE node, void * (*mapfun)(const void *, void *) ){ if (NULL!=node){ node->value = mapfun(node->key,node->value); map_rbtree_sub(node->left,mapfun); map_rbtree_sub(node->right,mapfun); } }
js_MapKeywords(void (*mapfun)(const char *)) { struct keyword *kw; for (kw = keywords; kw->name; kw++) mapfun(kw->name); }
void hash_table_map (struct hash_table *ht, int (*mapfun) (void *, void *, void *), void *closure) { struct mapping *mp = ht->mappings; struct mapping *end = ht->mappings + ht->size; for (; mp < end; mp++) if (!EMPTY_MAPPING_P (mp)) { void *key; repeat: key = mp->key; if (mapfun (key, mp->value, closure)) return; /* hash_table_remove might have moved the adjacent mappings. */ if (mp->key != key && !EMPTY_MAPPING_P (mp)) goto repeat; } }
extern void map_files(lua_State *L, const char *dirpath, void (*mapfun)(lua_State *, const char *)) { DIR *handle; struct dirent *d; int firsterror; if (!(handle = opendir(dirpath))) goto done; for (;;) { errno = 0; if (!(d = readdir(handle))) break; if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; mapfun(L, d->d_name); } done: firsterror = errno; if (handle && (closedir(handle) == -1) && !firsterror) firsterror = errno; if (firsterror) luaL_error(L, "cannot list directory %s: %s", dirpath, strerror(firsterror)); }