AVL_NODE_TYPE* AVL_PREFIXED(avl_find_prev_mod)(AVL_CONST_TREE_TYPE* root, const AVL_REFERENCE_TYPE obj_hash) { AVL_NODE_TYPE* node = *root; AVL_NODE_TYPE* lower_bound = NULL; AVL_REFERENCE_TYPE h; yassert(node != NULL); /* This is one of the parts I could try to optimize * I've checked the assembly, and it sucks ... */ /* Both the double-test while/ternary and the current one * are producing the same assembly code. */ /** * Get a key that */ while(node != NULL) { h = AVL_REFERENCE(node); /* * [0] is the length of the obj_hash * * The obj_hashs starts at [1] * */ #ifdef DEBUG if(h[0] != obj_hash[0]) { DIE_MSG("NSEC3 corrupted NSEC3 node"); } #endif int cmp = memcmp(&obj_hash[1], &h[1], h[0]); /* equals */ if(cmp == 0) { // want the prev mod return nsec3_avl_node_mod_prev(node); } /* bigger */ if(cmp > 0) { lower_bound = node; node = AVL_CHILD(node, DIR_RIGHT); } else { node = AVL_CHILD(node, DIR_LEFT); } } if(lower_bound == NULL) { lower_bound = *root; yassert(lower_bound != NULL); while((node = AVL_CHILD(lower_bound, DIR_RIGHT)) != NULL) { lower_bound = node; } } return lower_bound; }
void xy_startup() { globals = malloc(sizeof(GLOBALS)); if (!logging_init()) { fprintf(stderr, INIT_LOGGING_FAILURE); exit(1); } globals->log = get_logger("xy"); log_info(globals->log, STARTUP_MSG); xy_dir_init(); globals->cfg = xy_rc_init(); xy_inotify_init(); if (globals->in_fd == -1) { DIE_MSG("xy_inotify_init failed"); } if (!ipc_init()) { fprintf(stderr, INIT_IPC_FAILURE); DIE; } log_info(globals->log, IPC_STARTUP_MSG); if (!broadcast_init()) { fprintf(stderr, INIT_BROADCAST_FAILURE); DIE; } log_info(globals->log, BROADCAST_STARTUP_MSG); broadcast_send(STARTUP_MSG); /* if (!is_xinerama_active(globals->dpy)) { fprintf(stderr, "Xinerama is not active\n"); DIE; } */ /* char buffer[MSG_LEN]; memset(buffer, 0, MSG_LEN); sprintf(buffer, DISPLAYS_FOUND, *global_num_screens); broadcast_send(buffer); memset(buffer, 0, MSG_LEN); for (int i = 0; i < *global_num_screens; i++) { int sn = global_screens[i].screen_number; int xorg = global_screens[i].x_org; int yorg = global_screens[i].y_org; int width = global_screens[i].width; int height = global_screens[i].height; sprintf(buffer, DISPLAY_MESSAGE, sn, xorg, yorg, width, height); broadcast_send(buffer); memset(buffer, 0, MSG_LEN); } */ // TODO grab keys xy_init(); set_process_name("xy: main"); }