/* * Actions on history, only does one thing for now, but * we provide the function for future actions */ void xtp_handle_hl(struct tab *t, uint8_t cmd, int id) { struct history *h, *next; int i = 1; switch (cmd) { case XT_XTP_HL_REMOVE: /* walk backwards, as listed in reverse */ for (h = RB_MAX(history_list, &hl); h != NULL; h = next) { next = RB_PREV(history_list, &hl, h); if (id == i) { RB_REMOVE(history_list, &hl, h); g_free((gpointer) h->title); g_free((gpointer) h->uri); g_free(h); break; } i++; } break; case XT_XTP_HL_LIST: /* Nothing - just xtp_page_hl() below */ break; default: show_oops(t, "%s: unknown command", __func__); break; }; xtp_page_hl(t, NULL); }
int main(int argc, char **argv) { struct node *tmp, *ins; int i, max, min; RB_INIT(&root); for (i = 0; i < ITER; i++) { tmp = malloc(sizeof(struct node)); if (tmp == NULL) err(1, "malloc"); do { tmp->key = arc4random_uniform(MAX-MIN); tmp->key += MIN; } while (RB_FIND(tree, &root, tmp) != NULL); if (i == 0) max = min = tmp->key; else { if (tmp->key > max) max = tmp->key; if (tmp->key < min) min = tmp->key; } if (RB_INSERT(tree, &root, tmp) != NULL) errx(1, "RB_INSERT failed"); } ins = RB_MIN(tree, &root); if (ins->key != min) errx(1, "min does not match"); tmp = ins; ins = RB_MAX(tree, &root); if (ins->key != max) errx(1, "max does not match"); if (RB_REMOVE(tree, &root, tmp) != tmp) errx(1, "RB_REMOVE failed"); for (i = 0; i < ITER - 1; i++) { tmp = RB_ROOT(&root); if (tmp == NULL) errx(1, "RB_ROOT error"); if (RB_REMOVE(tree, &root, tmp) != tmp) errx(1, "RB_REMOVE error"); free(tmp); } exit(0); }
unsigned int tato_tree_int_max(TatoTreeInt *thiss) { TatoTreeIntNode *node = RB_MAX(TatoTreeInt_, thiss); return node ? node->key : 0; }
cur_t *cur_max(void) { return RB_MAX(curtree_s, &Head); }
tud_t *tud_max(void) { return RB_MAX(tudtree_s, &Head); }
/* * List has completed. * * Select the best filename for download, and download it if missing. */ int ctfile_find_for_extract_complete(struct ct_global_state *state, struct ct_op *op) { struct ct_ctfile_find_args *ccfa = op->op_args; struct ct_ctfile_find_fileop_args *ccffa; struct ct_op *list_fakeop = op->op_priv; struct ct_ctfile_list_args *ccla = list_fakeop->op_args; struct ctfile_list_tree result; struct ctfile_list_file *tmp; char *best = NULL; int ret = 0; RB_INIT(&result); ctfile_list_complete(&state->ctfile_list_files, ccla->ccla_matchmode, ccla->ccla_search, ccla->ccla_exclude, &result); e_free(ccla->ccla_search); e_free(&ccla->ccla_search); e_free(&ccla); e_free(&list_fakeop); /* * Prepare arguments for next operation. * either we'll download the next file, or skip straight to * the callback for after the download, either way we need the nextop */ ccffa = e_calloc(1, sizeof(*ccffa)); ccffa->ccffa_nextop = ccfa->ccfa_nextop; ccffa->ccffa_nextop_args = ccfa->ccfa_nextop_args; ccffa->ccffa_download_chain = ccfa->ccfa_download_chain; /* grab the newest one */ if ((tmp = RB_MAX(ctfile_list_tree, &result)) == NULL) { if (ccfa->ccfa_empty_ok) goto do_operation; else { CWARNX("%s: %s", ccfa->ccfa_tag, ct_strerror(CTE_NO_SUCH_BACKUP)); ret = CTE_NO_SUCH_BACKUP; e_free(&ccffa); goto out; } } /* pick the newest one */ best = e_strdup(tmp->mlf_name); CNDBG(CT_LOG_CTFILE, "backup file is %s", best); while ((tmp = RB_ROOT(&result)) != NULL) { RB_REMOVE(ctfile_list_tree, &result, tmp); e_free(&tmp); } /* * if the metadata file is not in the cache directory then we * need to download it first. if we need to recursively download * an incremental chain then that code will handle scheduling * those operations too. If we have it, we still need to check * that all others in the chain exist, however. */ if (!ctfile_in_cache(best, ccfa->ccfa_cachedir)) { ccffa->ccffa_base.cca_localname = best; ccffa->ccffa_base.cca_tdir = ccfa->ccfa_cachedir; ccffa->ccffa_base.cca_remotename = e_strdup(best); ccffa->ccffa_base.cca_ctfile = 1; ct_add_operation(state, ctfile_extract, ctfile_extract_nextop, ccffa); } else { do_operation: /* * No download needed, fake the next operation callback * to see if we need anymore. */ ccffa->ccffa_base.cca_localname = best; ccffa->ccffa_base.cca_tdir = ccfa->ccfa_cachedir; ccffa->ccffa_base.cca_ctfile = 1; op->op_args = ccffa; ctfile_extract_nextop(state, op); } out: e_free(&ccfa); return (ret); }
static udata_t *udata_max(void) { return RB_MAX(udatatree_s, &Head); }