bool_t get_saved_race_results( char *player, char *event, char *cup, char *race, difficulty_level_t d, scalar_t *time, int *herring, int *score ) { hash_table_t player_table; hash_table_t event_table; hash_table_t cup_table; hash_table_t race_table; save_info_t *this_save; player_table = results_save_table[d]; if ( get_hash_entry( player_table, player, (hash_entry_t*)&event_table ) && get_hash_entry( event_table, event, (hash_entry_t*)&cup_table ) && get_hash_entry( cup_table, cup, (hash_entry_t*)&race_table ) && get_hash_entry( race_table, race, (hash_entry_t*)&this_save ) ) { *time = this_save->data.results.time; *herring = this_save->data.results.herring; *score = this_save->data.results.score; return True; } return False; }
bool_t set_saved_race_results( char *player, char *event, char *cup, char *race, difficulty_level_t d, scalar_t time, int herring, int score ) { hash_table_t player_table; hash_table_t event_table; hash_table_t cup_table; hash_table_t race_table; save_info_t *this_save; player_table = results_save_table[d]; if ( !get_hash_entry( player_table, player, (hash_entry_t*)&event_table ) ) { event_table = create_hash_table(); add_hash_entry( player_table, player, (hash_entry_t)event_table ); } if ( !get_hash_entry( event_table, event, (hash_entry_t*)&cup_table ) ) { cup_table = create_hash_table(); add_hash_entry( event_table, event, (hash_entry_t)cup_table ); } if ( !get_hash_entry( cup_table, cup, (hash_entry_t*)&race_table ) ) { race_table = create_hash_table(); add_hash_entry( cup_table, cup, (hash_entry_t)race_table ); } if ( !get_hash_entry( race_table, race, (hash_entry_t*)&this_save ) ) { this_save = (save_info_t*)malloc(sizeof(save_info_t)); memset( this_save, 0, sizeof(save_info_t) ); add_hash_entry( race_table, race, (hash_entry_t)this_save ); this_save->data_type = RACE_RESULTS; } check_assertion( this_save->data_type == RACE_RESULTS, "Invalid data type" ); strcpy( this_save->data.results.event, event ); strcpy( this_save->data.results.cup, cup ); strcpy( this_save->data.results.race, race ); this_save->data.results.difficulty = d; this_save->data.results.time = time; this_save->data.results.herring = herring; this_save->data.results.score = score; #ifdef __APPLE__ // Write as soon as possible write_saved_games(); #endif return True; }
int remove_from_hash(h_entry_t* hash, unsigned int hash_size, dc_t* cell, int type) { int hash_entry=0; entry_t *it, *tmp; if(!cell) return 0; if(!hash) return -1; /* find the list where the cell must be */ if(type==DHASH) hash_entry = get_hash_entry(cell->dhash, hash_size); else if(type==CHASH) hash_entry = get_hash_entry(cell->code, hash_size); else return -1; lock_get(&hash[hash_entry].lock); /* first element of the list */ it = hash[hash_entry].e; /* find the cell in the list */ /* a double linked list in the hash is kept alphabetically * or numerical ordered */ tmp = NULL; while(it!=NULL && it->dc != cell) { tmp = it; it = it->n; } if(it) { if(tmp) tmp->n = it->n; else hash[hash_entry].e = it->n; if(it->n) it->n->p = it->p; free_entry(it, (type==DHASH?ERASE_CELL:NOT_ERASE_CELL)); } lock_release(&hash[hash_entry].lock); return 0; }
bool_t get_high_score( char* event, char* cup, char** player, int *score ) { hash_table_t *cup_table; score_info_t *this_score; if ( get_hash_entry( score_table, event, (hash_entry_t*)&cup_table ) ) { if ( get_hash_entry( *cup_table, cup, (hash_entry_t*)&this_score ) ) { *player = this_score->player_name; *score = this_score->score; return True; } } return False; }
char* get_domain_from_hash(h_entry_t* hash, unsigned int hash_size, code_t code) { int hash_entry; entry_t* it; if(!hash || hash_size>MAX_HASH_SIZE) return NULL; /* find out the list in the hash where this code could be */ hash_entry = get_hash_entry(code, hash_size); lock_get(&hash[hash_entry].lock); /* parsing the list */ it = hash[hash_entry].e; while(it!=NULL && it->dc->code<code) it = it->n; lock_release(&hash[hash_entry].lock); /* the code does not exist */ if(it==NULL || it->dc->code > code ) return NULL; else /* returns the associated domain name */ return it->dc->domain; }
dc_t* get_code_from_hash(h_entry_t* hash, unsigned int hash_size, char* domain) { int hash_entry; unsigned int dhash; entry_t* it; if(!hash || hash_size>MAX_HASH_SIZE) return NULL; dhash = compute_hash(domain); hash_entry = get_hash_entry(dhash, hash_size); lock_get(&hash[hash_entry].lock); /* parsing the list */ it = hash[hash_entry].e; while(it!=NULL && it->dc->dhash<=dhash) { if(it->dc->dhash == dhash && strcasecmp(it->dc->domain, domain)==0) { lock_release(&hash[hash_entry].lock); return it->dc; } it = it->n; } lock_release(&hash[hash_entry].lock); return NULL; }
bool_t get_last_completed_cup( char* player, char* event, difficulty_level_t d, char** cup ) { hash_table_t event_table; save_info_t *this_save; if ( get_hash_entry( progress_save_table, player, (hash_entry_t*)&event_table ) ) { if ( get_hash_entry( event_table, event, (hash_entry_t*)&this_save ) ) { if (this_save[d].data_type == EVENT_INFO) { *cup = this_save[d].data.event.cup; return True; } } } return False; }
/*! Change volume for a sound associated with the specified sound context \pre sound_context != NULL \arg \c sound_context the sound context \i volume is a value 0-128 \return true if volume was set; false otherwise \author ehall \date Created: 2000-09-13 \date Modified: 2000-09-13 */ bool_t set_sound_volume( char *sound_context, int volume ) { int i; sound_context_data_t *data; if ( ! get_hash_entry( sound_contexts_, sound_context, (hash_entry_t*) &data ) ) { return False; } data->volume = volume; i = (int) (((double)data->num_sounds)*rand()/(RAND_MAX+1.0)); for ( i=0; i<data->num_sounds; i++ ) { if ( data->chunks[i] == NULL ) { bool_t found; found = get_sound_data( data->sound_names[i], &(data->chunks[i]) ); check_assertion( found, "sound name not found" ); check_assertion( data->chunks[i]!=NULL, "sound chunk not set" ); } Mix_VolumeChunk( data->chunks[i], data->volume ); } return True; }
str* pdt_get_prefix(pdt_hash_t *ph, str* sd) { int hash_entry; unsigned int dhash; pd_t* it; if(ph==NULL || ph->dhash==NULL || ph->hash_size>MAX_HASH_SIZE) { LOG(L_ERR, "PDT:pdt_get_prefix: bad parameters\n"); return NULL; } dhash = pdt_compute_hash(sd->s); hash_entry = get_hash_entry(dhash, ph->hash_size); lock_get(&ph->dhash[hash_entry].lock); it = ph->dhash[hash_entry].e; while(it!=NULL && it->dhash<=dhash) { if(it->dhash==dhash && it->domain.len==sd->len && strncasecmp(it->domain.s, sd->s, sd->len)==0) { lock_release(&ph->dhash[hash_entry].lock); return &it->prefix; } it = it->n; } lock_release(&ph->dhash[hash_entry].lock); return NULL; }
bool_t get_font_binding( char *binding, font_t **font ) { if (get_hash_entry(binding_table, binding, (hash_entry_t*)(font))) { return True; } return False; }
bool_t bind_font( char *binding, char *fontname, scalar_t size, colour_t colour ) { font_node_t *fontnode; font_t *font; print_debug(DEBUG_FONT, "Binding %s to font name: %s", binding, fontname); if (!get_font( fontname, &fontnode)) { check_assertion(0, "Attempt to bind to unloaded font"); return False; } if (get_hash_entry(binding_table, binding, (hash_entry_t*)(&font))) { font->node->ref_count--; } else { font = (font_t*)malloc(sizeof(font_t)); add_hash_entry(binding_table, binding, (hash_entry_t)font); } font->node = fontnode; font->size = size * mHeight / 320; font->colour = colour; font->node->ref_count += 1; return True; }
str* get_prefix(hash_t *ph, str* sd) { int hash_entry; unsigned int dhash; pd_t* it; if(ph==NULL || ph->dhash==NULL || ph->hash_size>MAX_HASH_SIZE) { LM_ERR("bad parameters\n"); return NULL; } dhash = pdt_compute_hash(sd); hash_entry = get_hash_entry(dhash, ph->hash_size); it = ph->dhash[hash_entry]; while(it!=NULL && it->dhash<=dhash) { if(it->dhash==dhash && it->domain.len==sd->len && strncasecmp(it->domain.s, sd->s, sd->len)==0) return &it->prefix; it = it->n; } return NULL; }
bool_t get_texture_binding( char *binding, GLuint *texid ) { texture_node_t *texnode; if (get_hash_entry(binding_table, binding, (hash_entry_t*)(&texnode))) { *texid = texnode->texture_id; return True; } return False; }
static int add_net (char *ptr, enum e_pin_type type, int bnum, int blk_pnum, int doall) { /* This routine is given a net name in *ptr, either DRIVER or RECEIVER * * specifying whether the block number given by bnum is driving this * * net or in the fan-out and doall, which is 0 for the counting pass * * and 1 for the loading pass. It updates the net data structure and * * returns the net number so the calling routine can update the block * * data structure. */ struct s_hash *h_ptr; int j, nindex; if (doall == 0) { /* Counting pass only */ h_ptr = insert_in_hash_table (hash_table, ptr, num_nets); nindex = h_ptr->index; if (nindex == num_nets) /* Net was not in the hash table */ num_nets++; return (nindex); } else { /* Load pass */ h_ptr = get_hash_entry (hash_table, ptr); nindex = h_ptr->index; if (h_ptr == NULL) { printf("Error in add_net: the second (load) pass found could not\n"); printf("find net %s in the symbol table.\n", ptr); exit(1); } net[nindex].num_pins++; if (type == DRIVER) { num_driver[nindex]++; j=0; /* Driver always in position 0 of pinlist */ } else { j = net[nindex].num_pins - num_driver[nindex]; /* num_driver is the number of signal drivers of this net. * * should always be zero or 1 unless the netlist is bad. */ if (j >= temp_num_pins[nindex]) { printf("Error: Net #%d (%s) has no driver and will cause\n", nindex, ptr); printf("memory corruption.\n"); exit(1); } } net[nindex].blocks[j] = bnum; net[nindex].blk_pin[j] = blk_pnum; return (nindex); } }
int pdt_remove_from_hash(pdt_hash_t *hash, str *sd) { int hash_entry=0; unsigned int dhash; pd_t *it, *tmp; if(sd==NULL) return 0; if(hash==NULL) { LOG(L_ERR, "PDT:pdt_remove_from_hash: bad parameters\n"); return -1; } /* find the list where the cell must be */ dhash = pdt_compute_hash(sd->s); hash_entry = get_hash_entry(dhash, hash->hash_size); lock_get(&hash->dhash[hash_entry].lock); /* first element of the list */ it = hash->dhash[hash_entry].e; /* find the cell in the list */ /* a double linked list in the hash is kept alphabetically * or numerical ordered */ tmp = NULL; while(it!=NULL) { if( it->dhash==dhash && it->domain.len==sd->len && strncasecmp(it->domain.s, sd->s, sd->len)==0) break; tmp = it; it = it->n; } if(it!=NULL) { if(tmp!=NULL) tmp->n = it->n; else hash->dhash[hash_entry].e = it->n; if(it->n) it->n->p = it->p; free_cell(it); } lock_release(&hash->dhash[hash_entry].lock); return 0; }
int pdt_add_to_hash(pdt_hash_t *hash, str *sp, str *sd) { int hash_entry=0; unsigned int dhash; pd_t *it, *tmp; pd_t *cell; if(hash==NULL || sp==NULL || sd==NULL) { LOG(L_ERR, "PDT:pdt_add_to_hash: bad parameters\n"); return -1; } dhash = pdt_compute_hash(sd->s); hash_entry = get_hash_entry(dhash, hash->hash_size); lock_get(&hash->dhash[hash_entry].lock); it = hash->dhash[hash_entry].e; tmp = NULL; while(it!=NULL && it->dhash < dhash) { tmp = it; it = it->n; } /* we need a new entry for this cell */ cell = new_cell(sp, sd); if(cell == NULL) { lock_release(&hash->dhash[hash_entry].lock); return -1; } if(tmp) tmp->n=cell; else hash->dhash[hash_entry].e = cell; cell->p=tmp; cell->n=it; if(it) it->p=cell; lock_release(&hash->dhash[hash_entry].lock); return 0; }
void collate_vnums(FILE * in_file) { int vnum; char * line; int line_size; int min_vnum=65000; int max_vnum=0; hash_entry * entry; line=malloc(BUF_SIZE); line_size=BUF_SIZE; for ( ; ; ) { getline(&line, &line_size, in_file); if (line[0] != '#') continue; vnum=atoi(line+1); if (vnum==0) break; if (vnum > max_vnum) max_vnum=vnum; if (vnum < min_vnum) min_vnum=vnum; add_vnum(vnum); } if (max_vnum != 0) { for (vnum=min_vnum; vnum <= max_vnum; vnum++) { if ( (entry=get_hash_entry(vnum)) != NULL && entry->offset>=0 ) { if ( entry->offset == 0 ) printf(" %i\n",entry->vnum); else printf(" %i-%i\n",entry->vnum,entry->vnum+entry->offset); } } } clear_hash_table(); free(line); }
void *remove_hash_object(struct hash_table *tbl, const char *key) { struct hash_entry *entry = get_hash_entry(tbl, key); void *retval = NULL; if (entry) { list_del(&entry->he_list); retval = entry->he_obj; free(entry); } return retval; }
/* returns -1 if any error * returns 1 if does not exist in hash * returns 0 if deleted succesfully * */ int remove_from_hash(hash_t *hash, str *sd) { int hash_entry=0; unsigned int dhash; pd_t *it, *prev; if(hash==NULL || sd==NULL || sd->s==NULL) { LM_ERR("bad parameters\n"); return -1; /* error */ } /* find the list where the cell must be */ dhash = pdt_compute_hash(sd); hash_entry = get_hash_entry(dhash, hash->hash_size); /* first element of the list */ it = hash->dhash[hash_entry]; /* find the cell in the list */ /* a double linked list in the hash is kept alphabetically * or numerical ordered */ prev = NULL; while(it!=NULL) { if( it->dhash==dhash && it->domain.len==sd->len && strncasecmp(it->domain.s, sd->s, sd->len)==0) break; prev = it; it = it->n; } if(it==NULL) return 1; /* does not exist in hash, nothing to delete */ /* the prefix/domain pair exists and must be deleted */ if(prev!=NULL) prev->n = it->n; else hash->dhash[hash_entry] = it->n; if(it->n) it->n->p = it->p; // check who should do it // free_cell(it); return 0; }
bool_t unbind_texture( char *binding ) { texture_node_t *tex; if (get_hash_entry( binding_table, binding, (hash_entry_t*)(&tex))) { tex->ref_count--; if (!del_hash_entry( binding_table, binding, NULL )) { check_assertion(0, "Cannot delete known texture binding"); return False; } return True; } return False; }
bool_t set_high_score( char* event, char* cup, char* player, int score ) { hash_table_t *cup_table; score_info_t *this_score; if ( !get_hash_entry( score_table, event, (hash_entry_t*)&cup_table ) ) { cup_table = (hash_table_t*)malloc(sizeof(hash_table_t)); *cup_table = create_hash_table(); add_hash_entry( score_table, event, cup_table ); } if ( !get_hash_entry( *cup_table, cup, (hash_entry_t*)&this_score ) ) { this_score = (score_info_t*)malloc(sizeof(score_info_t)); strcpy(this_score->event.event, event); strcpy(this_score->event.cup, cup); this_score->event.difficulty = (difficulty_level_t)0; this_score->data_type = (score_data_t)0; add_hash_entry( *cup_table, cup, this_score ); } this_score->score = score; strcpy( this_score->player_name, player ); return True; }
bool_t set_last_completed_cup( char* player, char* event, difficulty_level_t d, char* cup ) { hash_table_t event_table; save_info_t *this_save; difficulty_level_t level; int i; if ( !get_hash_entry( progress_save_table, player, (hash_entry_t*)&event_table ) ) { event_table = create_hash_table(); add_hash_entry( progress_save_table, player, event_table ); } if ( !get_hash_entry( event_table, event, (hash_entry_t*)&this_save ) ) { this_save = (save_info_t*)malloc(sizeof(save_info_t)* DIFFICULTY_NUM_LEVELS); memset( this_save, 0, sizeof(save_info_t) * DIFFICULTY_NUM_LEVELS ); for( i=0; i<DIFFICULTY_NUM_LEVELS; i++ ) { level = (difficulty_level_t)i; strcpy( this_save[level].data.event.event, event ); this_save[level].data.event.difficulty = d; if ( level != d ) { this_save[level].data_type = INVALID_DATA; } else { this_save[level].data_type = EVENT_INFO; } } add_hash_entry( event_table, event, this_save ); } this_save[d].data_type = EVENT_INFO; strcpy( this_save[d].data.event.cup, cup ); return True; }
bool_t unbind_font( char *binding ) { font_t *font; if (get_hash_entry( binding_table, binding, (hash_entry_t*)(&font))) { font->node->ref_count -= 1; if (!del_hash_entry( binding_table, binding, NULL )) { check_assertion(0, "Cannot delete known font binding"); return False; } free(font); return True; } return False; }
/*! Associate the sounds in the _name_ array with the sound context sound_context. If more than one sound is specified, then a sound will be chosen randomly from the list each time the sound is played. If num_sounds == 0, then the entry for the sound context is deleted. \pre \c sound_context != NULL \arg \c sound_context sound context to bind sounds to \arg \c names list of sound names to bind to context \arg \c num_sounds number of elements in \c names \return none \author jfpatry \date Created: 2000-08-13 \date Modified: 2000-08-14 */ void bind_sounds_to_context( char *sound_context, char **names, int num_sounds ) { int i; sound_context_data_t *data; check_assertion( initialized_, "audio module not initialized" ); if ( get_hash_entry( sound_contexts_, sound_context, (hash_entry_t*) &data ) ) { /* Entry for this context already exists; decrement ref_cts & delete arrays */ for (i=0; i<data->num_sounds; i++) { decr_sound_data_ref_ctr( data->sound_names[i] ); free( data->sound_names[i] ); } free( data->sound_names ); free( data->chunks ); del_hash_entry( sound_contexts_, sound_context, NULL ); } else { data = (sound_context_data_t*)malloc( sizeof(sound_context_data_t) ); } if ( num_sounds == 0 ) { /* delete the context */ free( data ); return; } check_assertion( num_sounds > 0, "num_sounds isn't > 0 " ); data->num_sounds = num_sounds; data->sound_names = (char**)malloc( sizeof(char*)*num_sounds ); data->chunks = (Mix_Chunk**)malloc( sizeof(Mix_Chunk*)*num_sounds ); data->loop_count = 0; data->channel = 0; data->volume = 128; for (i=0; i<num_sounds; i++) { data->sound_names[i] = string_copy( names[i] ); incr_sound_data_ref_ctr( names[i] ); data->chunks[i] = NULL; } add_hash_entry( sound_contexts_, sound_context, (hash_entry_t)data ); }
/*! Associate the music with name _name_ to the music context _music_context_. If _name_ is NULL or the null string, the data for the music context will be deleted. \pre \c music_context != \c NULL \arg \c music_context music context to bind sounds to \arg \c name name of music to bind to context \arg \c loop number of loops to play music for (-1 to loop forever) \return none \author jfpatry \date Created: 2000-08-13 \date Modified: 2000-08-14 */ void bind_music_to_context( char *music_context, char *name, int loop ) { music_context_data_t *data; check_assertion( initialized_, "audio module not initialized" ); if ( get_hash_entry( music_contexts_, music_context, (hash_entry_t*) &data ) ) { /* Entry for this context already exists; decrement ref count & delete string */ /* check if music is playing, stop if it is */ if ( current_music_name_ != NULL && strcmp( current_music_name_, data->music_name ) == 0 ) { Mix_HaltMusic(); current_music_name_ = NULL; current_music_data_ = NULL; check_assertion( get_music_playing_status( data->music_name ), "inconsistent music playing status info" ); set_music_playing_status( data->music_name, False ); } decr_music_data_ref_ctr( data->music_name ); free( data->music_name ); del_hash_entry( music_contexts_, music_context, NULL ); } else { data = (music_context_data_t*)malloc( sizeof(music_context_data_t) ); } if ( name == NULL || name[0]=='\0' ) { /* delete the context */ free( data ); return; } data->music_name = string_copy( name ); incr_music_data_ref_ctr( name ); data->music = NULL; data->loop = loop; add_hash_entry( music_contexts_, music_context, (hash_entry_t)data ); }
static void check_structure(t_subblock_data *subblock_data_ptr) { int iblk, ipin, istage, num_subs, num_ffblocks, inet, j; struct s_hash *h_ptr; printf("checking structure\n"); for (iblk = 0; iblk < num_blocks; iblk++) { printf("block name %s at stage %d\n", block[iblk].name, block[iblk].stage); num_ffblocks = subblock_data_ptr->num_ff_per_block[iblk]; num_subs = subblock_data_ptr->num_subblocks_per_block[iblk]; printf("num of sub %d, num of ff %d\n", num_subs, num_ffblocks); printf("check pin info \n"); for (ipin = 0; ipin < pins_per_clb; ipin++) { inet = block[iblk].nets[ipin]; if (inet != OPEN) printf("net %d(%s) at pin %d\n", inet, net[inet].name, ipin); } printf("check map table \n"); h_ptr = get_hash_entry(map_table, block[iblk].name); int begin = h_ptr->index; for (j = 0; j < h_ptr->count; j++) { int block_num = blockmap_inf[begin + j]; printf("block num %d(%s) at index %d\n", block_num, block[block_num].name, begin + j); } } for (istage = 0; istage < num_stage; istage++) { printf("net begin %d, num %d at stage %d\n", num_net_per_stage[istage].begin, num_net_per_stage[istage].num, istage); printf("block begin %d, num %d at stage %d\n", num_block_per_stage[istage].begin, num_block_per_stage[istage].num, istage); } for (inet = 0; inet < num_nets; inet++) { printf("net name %s at stage %d with num of pins %d\n", net[inet].name, net[inet].stage, net[inet].num_pins); int num_pin = net[inet].num_pins; for (ipin = 0; ipin < num_pin; ipin++) { iblk = net[inet].blocks[ipin]; printf("connect to block %d(%s) at pin %d\n", iblk, block[iblk].name, net[inet].blk_pin[ipin]); } } return; }
/*! Adds a mouse up callback for the specified widget. \pre widget != NULL \arg \c widget the widget to receive mouse up events \arg \c cb the callback function (NULL to remove callback) \return None \author jfpatry \date Created: 2000-09-16 \date Modified: 2000-09-16 */ void ui_add_mouse_up_callback( void* widget, mouse_button_event_cb_t cb ) { char *key; hash_table_t table; ui_callback_data_t *cb_data; key = generate_key_from_pointer( widget ); table = mouse_up_cbs; if ( get_hash_entry( table, key, NULL) ) { del_hash_entry( table, key, (hash_entry_t*)&cb_data ); free(cb_data); } if ( cb != NULL ) { add_hash_entry( table, key, generate_cb_data( widget, (void*) cb ) ); } }
bool_t load_font( char *fontname, char *filename, char *texname ) { font_node_t *fontnode; tex_font_metrics_t *tfm; texture_node_t *tex; print_debug(DEBUG_FONT, "Loading font %s from file: %s", fontname, filename); if ( initialized == False ) { check_assertion( 0, "font module not initialized" ); } if ( ! get_texture( texname, &tex ) ) { print_warning( IMPORTANT_WARNING, "Texture `%s' does not exist", texname ); return False; } tfm = load_tex_font_metrics( filename ); if ( tfm == NULL ) { print_warning( IMPORTANT_WARNING, "couldn't load font file %s", filename ); return False; } if (get_hash_entry( font_table, fontname, (hash_entry_t*)&fontnode )) { print_debug( DEBUG_FONT, "Font %s already exists, deleting...", fontname ); delete_tex_font_metrics( fontnode->tfm ); fontnode->tex->ref_count -= 1; } else { fontnode = (font_node_t*)malloc(sizeof(font_node_t)); fontnode->ref_count = 0; add_hash_entry( font_table, fontname, (hash_entry_t)fontnode ); } fontnode->tfm = tfm; fontnode->tex = tex; tex->ref_count += 1; return True; }
int add_to_hash(hash_t *hash, str *sp, str *sd) { int hash_entry=0; unsigned int dhash; pd_t *it, *prev, *cell; if(hash==NULL || sp==NULL || sp->s==NULL || sd==NULL || sd->s==NULL) { LM_ERR("bad parameters\n"); return -1; } dhash = pdt_compute_hash(sd); hash_entry = get_hash_entry(dhash, hash->hash_size); it = hash->dhash[hash_entry]; prev = NULL; while(it!=NULL && it->dhash < dhash) { prev = it; it = it->n; } /* we need a new entry for this cell */ cell = new_cell(sp, sd); if(cell == NULL) return -1; if(prev) prev->n=cell; else hash->dhash[hash_entry]= cell; cell->p=prev; cell->n=it; if(it) it->p=cell; return 0; }
/*! Play a sound associated with the specified sound context \pre sound_context != NULL \arg \c sound_context the sound context \i SDL number of loops, -1 for infinite \return true if sound was played; false otherwise \author jfpatry \date Created: 2000-08-13 \date Modified: 2000-09-13 ehall */ bool_t play_sound( char *sound_context, int loop ) { Mix_Chunk *chunk; sound_context_data_t *data; check_assertion( initialized_, "audio module not initialized" ); if ( getparam_sound_enabled() == False ) { return False; } if ( ! is_audio_open() ) { return False; } check_assertion( sound_context != NULL, "sound_context is null" ); if ( ! get_hash_entry( sound_contexts_, sound_context, (hash_entry_t*) &data ) ) { return False; } chunk = get_Mix_Chunk( data, NULL ); if ( chunk == NULL ) { return False; } if (data->loop_count == -1) { return False; } Mix_VolumeChunk( chunk, data->volume ); data->channel = Mix_PlayChannel( -1, chunk, loop ); data->loop_count = loop; return True; }