Exemplo n.º 1
0
void write_high_scores( void )
{
    hash_table_t *cup_table;
    hash_search_t score_scan_ptr;
    hash_search_t cup_scan_ptr;
    char *event_name;
    char *cup_name;
    score_info_t *this_score;
    FILE *score_stream;
    char score_file[BUFF_LEN];

    if ( get_high_score_file_name( score_file, sizeof(score_file) ) == 0 ) {
	score_stream = fopen( score_file, "w" );
	begin_hash_scan( score_table, &score_scan_ptr );
	while ( next_hash_entry( score_scan_ptr, &event_name, (hash_entry_t*)&cup_table ) ) {
	    begin_hash_scan( *cup_table, &cup_scan_ptr );
	    while ( next_hash_entry( cup_scan_ptr, &cup_name, (hash_entry_t*)&this_score ) ) {
		fwrite( this_score, sizeof(this_score), 1, score_stream );
	    }
	    end_hash_scan( cup_scan_ptr );
	}
	end_hash_scan( score_scan_ptr );
	if ( fclose( score_stream ) != 0 ) {
	    perror( "fclose" );
	}
    }
}
Exemplo n.º 2
0
bool_t flush_fonts(void)
{
    font_node_t *fontnode;
    hash_search_t  sptr;
    list_t delete_list;
    list_elem_t elem;
    char *key;
    bool_t result;

    delete_list = create_list();
  
    begin_hash_scan(font_table, &sptr);
    while ( next_hash_entry(sptr, &key, (hash_entry_t*)(&fontnode)) ) {
	if (fontnode->ref_count == 0) {
	    elem = insert_list_elem(delete_list, NULL, (list_elem_data_t)key);
	}
    }
    end_hash_scan(sptr);

    elem = get_list_head(delete_list);
    while (elem != NULL) {
	key = (char*)get_list_elem_data(elem);

	result = del_font( key );
	check_assertion(result, "Attempt to flush non-existant font");

	elem = get_next_list_elem(delete_list, elem);
    }

    del_list(delete_list);

    return True;

}
Exemplo n.º 3
0
void print_statistics(void * ps_tree)
{
    /* Statistics data */
    unsigned int num_files = 0, max_file_len = 0, total_file_len = 0;
    unsigned int total_revisions = 0, max_revisions_for_file = 0;
    unsigned int total_branches = 0, max_branches_for_file = 0;
    unsigned int total_branches_sym = 0, max_branches_sym_for_file = 0;

    /* Other vars */
    struct hash_entry *he;
   
    printf("Statistics:\n");
    fflush(stdout);

    /* Gather file statistics */
    reset_hash_iterator(file_hash);
    while ((he=next_hash_entry(file_hash)))
    {
	int len = strlen(he->he_key);
	CvsFile *file = (CvsFile *)he->he_obj;
	
	num_files++;
	max_file_len = MAX(max_file_len, len);
	total_file_len += len;

	count_hash(file->revisions, &total_revisions, &max_revisions_for_file);
	count_hash(file->branches, &total_branches, &max_branches_for_file);
	count_hash(file->branches_sym, &total_branches_sym,
	    &max_branches_sym_for_file);
    }

    /* Print file statistics */
    printf("Num files: %d\nMax filename len: %d, Average filename len: %.2f\n",
	    num_files, max_file_len, (float)total_file_len/num_files);

    printf("Max revisions for file: %d, Average revisions for file: %.2f\n",
	  max_revisions_for_file, (float)total_revisions/num_files);
    printf("Max branches for file: %d, Average branches for file: %.2f\n",
	  max_branches_for_file, (float)total_branches/num_files);
    printf("Max branches_sym for file: %d, Average branches_sym for file: %.2f\n",
	  max_branches_sym_for_file, (float)total_branches_sym/num_files);

    /* Gather patchset statistics */
    twalk(ps_tree, stat_ps_tree_node);

    /* Print patchset statistics */
    printf("Num patchsets: %d\n", num_patch_sets);
    printf("Max PS members in PS: %d\nAverage PS members in PS: %.2f\n",
	    max_ps_member_in_ps, (float)num_ps_member/num_patch_sets);
    printf("Num authors: %d, Max author len: %d, Avg. author len: %.2f\n", 
	    num_authors, max_author_len, (float)total_author_len/num_authors);
    printf("Max desc len: %d, Avg. desc len: %.2f\n",
	    max_descr_len, (float)total_descr_len/num_patch_sets);
}
Exemplo n.º 4
0
static void count_hash(struct hash_table *hash, unsigned int *total, 
	unsigned int *max_val)
{
    int counter = 0;
    
    reset_hash_iterator(hash);
    while (next_hash_entry(hash))
	counter++;

    *total += counter;
    *max_val= MAX(*max_val, counter);
}
Exemplo n.º 5
0
/*! 
  Flushes cached copies of \c Mix_Music for all sound contexts

  \pre     

  \return  none
  \author  jfpatry
  \date    Created:  2000-08-13
  \date    Modified: 2000-08-13
*/
static void flush_cached_music()
{
    hash_search_t iter;
    music_context_data_t *data;

    check_assertion( initialized_, "audio module not initialized" );

    begin_hash_scan(music_contexts_, &iter);
    while ( next_hash_entry(iter, NULL, (hash_entry_t*)&data) ) {
	data->music = NULL;
    }
    end_hash_scan( iter );
} 
Exemplo n.º 6
0
/*! 
  Draws all UI widgets
  \return  None
  \author  jfpatry
  \date    Created:  2000-09-17
  \date    Modified: 2000-09-17
*/
void ui_draw( )
{
    hash_search_t iter;
    ui_callback_data_t *cb_data;

    ui_setup_display();

    begin_hash_scan( widget_draw_cbs, &iter );
    while ( next_hash_entry( iter, NULL, (hash_entry_t*)&cb_data ) ) {
	((widget_draw_cb_t)cb_data->cb)( cb_data->widget );
	check_assertion( !is_mode_change_pending(),
			 "widget draw callback changed the mode" );
    }
    end_hash_scan( iter );

    ui_draw_cursor();
}
Exemplo n.º 7
0
/*! 
  Calls all registered mouse motion callbacks 
  \arg \c  table the table storing callback data
  \arg \c  x x coordinate of mouse
  \arg \c  y y coordinate of mouse

  \return  None
  \author  jfpatry
  \date    Created:  2000-09-16
  \date    Modified: 2000-09-16
*/
static void trigger_mouse_motion_cbs( hash_table_t table, 
				      int x, int y )
{
    hash_search_t iter;
    ui_callback_data_t *cb_data;

    begin_hash_scan( table, &iter );
    while ( next_hash_entry( iter, NULL, (hash_entry_t*)&cb_data ) ) {
	((mouse_motion_event_cb_t)cb_data->cb)( 
	    cb_data->widget, x, y );

	if ( is_mode_change_pending() ) {
	    /* Callback just changed the mode; stop handling events
	       for this mode. */
	    break;
	}
    }
    end_hash_scan( iter );
}
Exemplo n.º 8
0
/*! 
  Flushes cached copies of \c Mix_Chunks for all sound contexts

  \pre     

  \return  none
  \author  jfpatry
  \date    Created:  2000-08-13
  \date    Modified: 2000-08-13
*/
static void flush_cached_sound_chunks()
{
    hash_search_t iter;
    sound_context_data_t *data;

    check_assertion( initialized_, "audio module not initialized" );

    begin_hash_scan(sound_contexts_, &iter);
    while ( next_hash_entry(iter, NULL, (hash_entry_t*)&data) ) {
	int i;
	for (i=0; i<data->num_sounds; i++) {
	    data->chunks[i] = NULL;
	}
	if (data->loop_count == -1) {
 
	    Mix_HaltChannel(data->channel);

	}
    }
    end_hash_scan( iter );
} 
Exemplo n.º 9
0
void write_saved_games( void )
{
    hash_search_t player_scan_ptr;
    hash_table_t event_table;
    hash_search_t event_scan_ptr;
    hash_table_t cup_table;
    hash_search_t cup_scan_ptr;
    hash_table_t race_table;
    hash_search_t race_scan_ptr;
    hash_search_t save_scan_ptr;
    char *player_name;
    char *event_name;
    FILE* save_stream;
    char save_file[BUFF_LEN];
    save_info_t *this_save;
    difficulty_level_t level;
    int i;
    hash_table_t player_table;

    /* Create list of players */
    player_table = create_hash_table();

    begin_hash_scan( progress_save_table, &player_scan_ptr );
    while ( next_hash_entry( player_scan_ptr, &player_name, NULL ) ) 
    {
	if ( !get_hash_entry( player_table, player_name, NULL ) ) {
	    add_hash_entry( player_table, player_name, "" );
	}
    }
    end_hash_scan( player_scan_ptr );

    for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
	begin_hash_scan( results_save_table[i], &player_scan_ptr );
	while ( next_hash_entry( player_scan_ptr, &player_name, NULL ) ) 
	{
	    if ( !get_hash_entry( player_table, player_name, NULL ) ) {
		add_hash_entry( player_table, player_name, "" );
	    }
	}
	end_hash_scan( player_scan_ptr );
    }


    /* truncate and initialize all save files */
    begin_hash_scan( player_table, &player_scan_ptr );
    while ( next_hash_entry( player_scan_ptr, &player_name, NULL )  )
    {
	truncate_and_init_save_file( player_name );
    }
    end_hash_scan( player_scan_ptr );


    /* Don't need player list anymore */
    del_hash_table( player_table );
    player_table = NULL;


    begin_hash_scan( progress_save_table, &player_scan_ptr );
    while ( next_hash_entry( player_scan_ptr, &player_name, 
			     (hash_entry_t*)&event_table ) ) 
    {
	if ( get_save_game_file_name( save_file, player_name, 
				      sizeof(save_file) ) == 0 ) 
	{
	    save_stream = fopen( save_file, "ab" );

	    if ( save_stream == NULL ) {
		print_warning( IMPORTANT_WARNING,
			       "Couldn't open `%s' for writing: %s",
			       save_file, 
			       strerror( errno ) );
	    } else {
		begin_hash_scan( event_table, &save_scan_ptr );

		while ( next_hash_entry( save_scan_ptr, &event_name, 
					 (hash_entry_t*)&this_save ) ) 
		{
		    for( i=0; i<DIFFICULTY_NUM_LEVELS; i++ ) {
			level = (difficulty_level_t)i;
			if ( this_save[level].data_type >= 0 ) {
			    fwrite( &(this_save[level]), 
				    sizeof(this_save[level]), 
				    1, 
				    save_stream );
			}
		    }
		}
		end_hash_scan( save_scan_ptr );

		if ( fclose( save_stream ) != 0 ) {
		    perror( "fclose" );
		}
		save_stream = NULL;
	    }
	}
    }
    end_hash_scan( player_scan_ptr );

    for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
	begin_hash_scan( results_save_table[i], &player_scan_ptr );
	while ( next_hash_entry( player_scan_ptr, &player_name, 
				 (hash_entry_t*)&event_table ) ) 
	{
	    if ( get_save_game_file_name( save_file, player_name, 
					  sizeof(save_file) ) == 0 ) 
	    {
		save_stream = fopen( save_file, "ab" );

		if ( save_stream == NULL ) {
		    print_warning( IMPORTANT_WARNING,
				   "Couldn't open `%s' for writing: %s",
				   save_file, 
				   strerror( errno ) );
		} else {
		    begin_hash_scan( event_table, &event_scan_ptr );
		    while ( next_hash_entry( event_scan_ptr, NULL, 
					     (hash_entry_t*)&cup_table ) ) 
		    {
			begin_hash_scan( cup_table, &cup_scan_ptr );
			while ( next_hash_entry( cup_scan_ptr, NULL,
						 (hash_entry_t*)&race_table ) )
			{
			    begin_hash_scan( race_table, &race_scan_ptr );
			    while ( next_hash_entry( race_scan_ptr, NULL,
						 (hash_entry_t*)&this_save ) )
			    {
				fwrite( this_save, 
					sizeof(save_info_t), 
					1, 
					save_stream );
				
			    }
			    end_hash_scan( race_scan_ptr );
			}
			end_hash_scan( cup_scan_ptr );
		    }
		    end_hash_scan( event_scan_ptr );

		    if ( fclose( save_stream ) != 0 ) {
			perror( "fclose" );
		    }
		    save_stream = NULL;
		}
	    }
	}
	end_hash_scan( player_scan_ptr );
    }
}
Exemplo n.º 10
0
void write_cache(time_t cache_date)
{
    struct hash_entry * file_iter;

    ps_counter = 0;

    if ((cache_fp = cache_open("w")) == NULL)
    {
	debug(DEBUG_SYSERROR, "can't open cvsps.cache for write");
	return;
    }

    fprintf(cache_fp, "cache version: %d\n", cache_version);
    fprintf(cache_fp, "cache date: %d\n", (int)cache_date);

    reset_hash_iterator(file_hash);

    while ((file_iter = next_hash_entry(file_hash)))
    {
	CvsFile * file = (CvsFile*)file_iter->he_obj;
	struct hash_entry * rev_iter;

	fprintf(cache_fp, "file: %s\n", file->filename);

	reset_hash_iterator(file->branches);
	while ((rev_iter = next_hash_entry(file->branches)))
	{
	    char * rev = (char *)rev_iter->he_key;
	    char * tag = (char *)rev_iter->he_obj;
	    fprintf(cache_fp, "%s: %s\n", rev, tag);
	}

	fprintf(cache_fp, "\n");

	reset_hash_iterator(file->symbols);
	while ((rev_iter = next_hash_entry(file->symbols)))
	{
	    char * tag = (char *)rev_iter->he_key;
	    CvsFileRevision * rev = (CvsFileRevision*)rev_iter->he_obj;
	    
	    if (rev->present)
		fprintf(cache_fp, "%s: %s\n", tag, rev->rev);
	}

	fprintf(cache_fp, "\n");

	reset_hash_iterator(file->revisions);
	while ((rev_iter = next_hash_entry(file->revisions)))
	{
	    CvsFileRevision * rev = (CvsFileRevision*)rev_iter->he_obj;
	    if (rev->present)
		fprintf(cache_fp, "%s %s\n", rev->rev, rev->branch);
	}

	fprintf(cache_fp, "\n");
    }

    fprintf(cache_fp, "\n");
    walk_all_patch_sets(write_patch_set_to_cache);
    fclose(cache_fp);
    cache_fp = NULL;
}