/** * Append child to parent. * * If this is a frequent operation, consider using an extended tree. */ void etree_append_child(etree_t *tree, void *parent, void *child) { node_t *cn, *pn; etree_check(tree); g_assert(parent != NULL); g_assert(child != NULL); g_assert(etree_is_orphan(tree, child)); cn = ptr_add_offset(child, tree->offset); pn = ptr_add_offset(parent, tree->offset); if (etree_is_extended(tree)) { nodex_t *px = ptr_add_offset(parent, tree->offset); if (px->last_child != NULL) { node_t *lcn = px->last_child; g_assert(0 == ptr_cmp(lcn->parent, px)); g_assert(NULL == lcn->sibling); lcn->sibling = cn; } else { g_assert(NULL == px->child); px->child = cn; } px->last_child = cn; } else { if (NULL == pn->child) { pn->child = cn; } else { node_t *lcn = etree_node_last_sibling(pn->child); lcn->sibling = cn; } } cn->parent = pn; tree->count = 0; /* Tree count is now unknown */ }
/** * Retrieve known GWC URLs. * They are normally saved in ~/.gtk-gnutella/gwcache. */ static void gwc_retrieve(void) { file_path_t fp[4], *fpv; uint len, added; int line, idx; FILE *in; char tmp[1024]; len = settings_file_path_load(fp, gwc_file, SFP_ALL); g_assert(len <= N_ITEMS(fp)); fpv = &fp[0]; retry: g_assert(ptr_cmp(fpv, &fp[N_ITEMS(fp)]) < 0); if (&fp[0] == fpv) in = file_config_open_read_chosen(gwc_what, fpv, len, &idx); else in = file_config_open_read_norename_chosen(gwc_what, fpv, len, &idx); if (NULL == in) return; /* * Retrieve each line, counting the amount of entries added. */ line = 0; added = 0; while (fgets(tmp, sizeof(tmp), in)) { line++; if (tmp[0] == '#') /* Skip comments */ continue; if (tmp[0] == '\n') /* Allow empty lines */ continue; (void) strchomp(tmp, 0); if (gwc_add(tmp)) added++; } fclose(in); /* * Now check whether we added anything from that file, and if we have not * and there are more backup files to open, retry with these fallbacks * instead. */ if (0 == added && UNSIGNED(idx) < len - 1) { g_warning("%s(): nothing loaded from \"%s/%s\", trying fallbacks", G_STRFUNC, fpv[idx].dir, fpv[idx].name); fpv += idx + 1; len -= idx + 1; g_assert(size_is_positive(len)); goto retry; } else { if (GNET_PROPERTY(bootstrap_debug)) { g_debug("%s(): loaded %u URL%s from \"%s/%s\"", G_STRFUNC, added, plural(added), fpv[idx].dir, fpv[idx].name); } } }