Drop most 'const's from function prototypes

darcs-hash:20060612214742-ac50b-9b0801e8a7c07d6ab3f0acf569e1d6eb1eeb3f0e.gz
This commit is contained in:
axel 2006-06-13 07:47:42 +10:00
parent 2c95e087b2
commit 9aee2b7c9c
18 changed files with 138 additions and 138 deletions

View file

@ -517,7 +517,7 @@ int builtin_complete( wchar_t **argv )
sb_printf( sb_out, L"%ls\n", next ); sb_printf( sb_out, L"%ls\n", next );
} }
al_foreach( &comp, (void (*)(const void *))&free ); al_foreach( &comp, &free );
al_destroy( &comp ); al_destroy( &comp );
recursion_level--; recursion_level--;
} }
@ -569,8 +569,8 @@ int builtin_complete( wchar_t **argv )
} }
} }
al_foreach( &cmd, (void (*)(const void *))&free ); al_foreach( &cmd, &free );
al_foreach( &path, (void (*)(const void *))&free ); al_foreach( &path, &free );
al_destroy( &cmd ); al_destroy( &cmd );
al_destroy( &path ); al_destroy( &path );

View file

@ -745,10 +745,10 @@ int builtin_set( wchar_t **argv )
} }
} }
al_foreach( &result, (void (*)(const void *))&free ); al_foreach( &result, &free );
al_destroy( &result ); al_destroy( &result );
al_foreach( &indexes, (void (*)(const void *))&free ); al_foreach( &indexes, &free );
al_destroy(&indexes); al_destroy(&indexes);
al_destroy(&values); al_destroy(&values);

View file

@ -324,7 +324,7 @@ static void complete_free_entry( complete_entry *c )
/** /**
Free hash key and hash value Free hash key and hash value
*/ */
static void clear_hash_entry( const void *key, const void *data ) static void clear_hash_entry( void *key, void *data )
{ {
free( (void *)key ); free( (void *)key );
free( (void *)data ); free( (void *)data );
@ -918,7 +918,7 @@ static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
} }
} }
al_foreach( &l, (void (*)(const void *))&free ); al_foreach( &l, &free );
al_destroy( &l ); al_destroy( &l );
} }
@ -1223,7 +1223,7 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
hash_destroy( &lookup ); hash_destroy( &lookup );
al_foreach( &list, al_foreach( &list,
(void(*)(const void *))&free ); &free );
al_destroy( &list ); al_destroy( &list );
free( lookup_cmd ); free( lookup_cmd );
} }
@ -1454,7 +1454,7 @@ static void complete_from_args( const wchar_t *str,
copy_strings_with_prefix( comp_out, str, desc, 0, &possible_comp ); copy_strings_with_prefix( comp_out, str, desc, 0, &possible_comp );
al_foreach( &possible_comp, (void (*)(const void *))&free ); al_foreach( &possible_comp, &free );
al_destroy( &possible_comp ); al_destroy( &possible_comp );
} }

24
env.c
View file

@ -188,7 +188,7 @@ static const wchar_t *locale_variable[] =
/** /**
Free hash key and hash value Free hash key and hash value
*/ */
static void clear_hash_entry( const void *key, const void *data ) static void clear_hash_entry( void *key, void *data )
{ {
var_entry_t *entry = (var_entry_t *)data; var_entry_t *entry = (var_entry_t *)data;
if( entry->export ) if( entry->export )
@ -435,14 +435,14 @@ static void setup_path()
sb_destroy( &b ); sb_destroy( &b );
al_foreach( &l, (void (*)(const void *))&free ); al_foreach( &l, &free );
path = env_get( L"PATH" ); path = env_get( L"PATH" );
al_truncate( &l, 0 ); al_truncate( &l, 0 );
tokenize_variable_array( path, &l ); tokenize_variable_array( path, &l );
} }
} }
al_foreach( &l, (void (*)(const void *))&free ); al_foreach( &l, &free );
al_destroy( &l ); al_destroy( &l );
} }
@ -763,7 +763,7 @@ int env_set( const wchar_t *key,
if( !done ) if( !done )
{ {
void *k, *v; void *k, *v;
hash_remove( &node->env, key, (const void **)&k, (const void **)&v ); hash_remove( &node->env, key, &k, &v );
free( k ); free( k );
free( v ); free( v );
@ -831,7 +831,7 @@ static int try_remove( env_node_t *n,
const wchar_t *key, const wchar_t *key,
int var_mode ) int var_mode )
{ {
const void *old_key_void, *old_val_void; void *old_key_void, *old_val_void;
wchar_t *old_key, *old_val; wchar_t *old_key, *old_val;
if( n == 0 ) if( n == 0 )
@ -1176,8 +1176,8 @@ void env_pop()
Function used with hash_foreach to insert keys of one table into Function used with hash_foreach to insert keys of one table into
another another
*/ */
static void add_key_to_hash( const void *key, static void add_key_to_hash( void *key,
const void *data, void *data,
void *aux ) void *aux )
{ {
var_entry_t *e = (var_entry_t *)data; var_entry_t *e = (var_entry_t *)data;
@ -1191,7 +1191,7 @@ static void add_key_to_hash( const void *key,
/** /**
Add key to hashtable Add key to hashtable
*/ */
static void add_to_hash( const void *k, void *aux ) static void add_to_hash( void *k, void *aux )
{ {
hash_put( (hash_table_t *)aux, hash_put( (hash_table_t *)aux,
k, k,
@ -1201,8 +1201,8 @@ static void add_to_hash( const void *k, void *aux )
/** /**
Add key to list Add key to list
*/ */
static void add_key_to_list( const void * key, static void add_key_to_list( void * key,
const void * val, void * val,
void *aux ) void *aux )
{ {
al_push( (array_list_t *)aux, key ); al_push( (array_list_t *)aux, key );
@ -1286,7 +1286,7 @@ void env_get_names( array_list_t *l, int flags )
/** /**
Function used by env_export_arr to iterate over hashtable of variables Function used by env_export_arr to iterate over hashtable of variables
*/ */
static void export_func1( const void *k, const void *v, void *aux ) static void export_func1( void *k, void *v, void *aux )
{ {
var_entry_t *val_entry = (var_entry_t *)v; var_entry_t *val_entry = (var_entry_t *)v;
if( val_entry->export ) if( val_entry->export )
@ -1302,7 +1302,7 @@ static void export_func1( const void *k, const void *v, void *aux )
/** /**
Function used by env_export_arr to iterate over hashtable of variables Function used by env_export_arr to iterate over hashtable of variables
*/ */
static void export_func2( const void *k, const void *v, void *aux ) static void export_func2( void *k, void *v, void *aux )
{ {
wchar_t *key = (wchar_t *)k; wchar_t *key = (wchar_t *)k;
wchar_t *val = (wchar_t *)v; wchar_t *val = (wchar_t *)v;

View file

@ -116,8 +116,8 @@ void env_universal_common_init( void (*cb)(int type, const wchar_t *key, const w
/** /**
Free both key and data Free both key and data
*/ */
static void erase( const void *key, static void erase( void *key,
const void *data ) void *data )
{ {
free( (void *)key ); free( (void *)key );
free( (void *)data ); free( (void *)data );
@ -205,8 +205,8 @@ static void remove_entry( wchar_t *name )
void *k, *v; void *k, *v;
hash_remove( &env_universal_var, hash_remove( &env_universal_var,
name, name,
(const void **)&k, &k,
(const void **)&v ); &v );
free( k ); free( k );
free( v ); free( v );
} }
@ -498,8 +498,8 @@ message_t *create_message( int type,
Function used with hash_foreach to insert keys of one table into Function used with hash_foreach to insert keys of one table into
another another
*/ */
static void add_key_to_hash( const void *key, static void add_key_to_hash( void *key,
const void *data, void *data,
void *aux ) void *aux )
{ {
var_uni_entry_t *e = (var_uni_entry_t *)data; var_uni_entry_t *e = (var_uni_entry_t *)data;
@ -546,8 +546,8 @@ int env_universal_common_get_export( const wchar_t *name )
\param v the variable value \param v the variable value
\param q the queue to add the message to \param q the queue to add the message to
*/ */
static void enqueue( const void *k, static void enqueue( void *k,
const void *v, void *v,
void *q) void *q)
{ {
const wchar_t *key = (const wchar_t *)k; const wchar_t *key = (const wchar_t *)k;

View file

@ -627,7 +627,7 @@ void event_destroy()
if( events ) if( events )
{ {
al_foreach( events, (void (*)(const void *))&event_free ); al_foreach( events, (void (*)(void *))&event_free );
al_destroy( events ); al_destroy( events );
free( events ); free( events );
events=0; events=0;
@ -635,7 +635,7 @@ void event_destroy()
if( killme ) if( killme )
{ {
al_foreach( killme, (void (*)(const void *))&event_free ); al_foreach( killme, (void (*)(void *))&event_free );
al_destroy( killme ); al_destroy( killme );
free( killme ); free( killme );
killme=0; killme=0;
@ -647,7 +647,7 @@ void event_free( event_t *e )
/* /*
When apropriate, we clear the argument vector When apropriate, we clear the argument vector
*/ */
al_foreach( &e->arguments, (void (*)(const void *))&free ); al_foreach( &e->arguments, &free );
al_destroy( &e->arguments ); al_destroy( &e->arguments );
free( (void *)e->function_name ); free( (void *)e->function_name );

View file

@ -837,7 +837,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
} }
} }
/* Free remaining strings in list l and truncate it */ /* Free remaining strings in list l and truncate it */
al_foreach( &var_item_list, (void (*)(const void *))&free ); al_foreach( &var_item_list, &free );
al_truncate( &var_item_list, 0 ); al_truncate( &var_item_list, 0 );
/* Add items from list idx back to list l */ /* Add items from list idx back to list l */
al_push_all( &var_item_list, var_idx_list ); al_push_all( &var_item_list, var_idx_list );
@ -1163,7 +1163,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
if( exec_subshell( subcmd, &sub_res)==-1 ) if( exec_subshell( subcmd, &sub_res)==-1 )
{ {
al_foreach( &sub_res, (void (*)(const void *))&free ); al_foreach( &sub_res, &free );
al_destroy( &sub_res ); al_destroy( &sub_res );
free( subcmd ); free( subcmd );
return 0; return 0;
@ -1202,7 +1202,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
al_destroy( &sub_res ); al_destroy( &sub_res );
al_foreach( &tail_expand, (void (*)(const void *))&free ); al_foreach( &tail_expand, &free );
al_destroy( &tail_expand ); al_destroy( &tail_expand );
free( subcmd ); free( subcmd );
@ -1630,7 +1630,7 @@ wchar_t *expand_one( void *context, wchar_t *string, int flags )
} }
} }
al_foreach( &l, (void(*)(const void *))&free ); al_foreach( &l, &free );
al_destroy( &l ); al_destroy( &l );
halloc_register( context, one ); halloc_register( context, one );

View file

@ -116,7 +116,7 @@ static void autoload_names( array_list_t *out, int get_hidden )
} }
closedir(dir); closedir(dir);
} }
al_foreach( &path_list, (void (*)(const void *))&free ); al_foreach( &path_list, &free );
al_destroy( &path_list ); al_destroy( &path_list );
} }
@ -124,8 +124,8 @@ static void autoload_names( array_list_t *out, int get_hidden )
/** /**
Free all contents of an entry to the function hash table Free all contents of an entry to the function hash table
*/ */
static void clear_function_entry( const void *key, static void clear_function_entry( void *key,
const void *data ) void *data )
{ {
function_data_t *d = (function_data_t *)data; function_data_t *d = (function_data_t *)data;
free( (void *)d->cmd ); free( (void *)d->cmd );
@ -209,7 +209,7 @@ int function_exists( const wchar_t *cmd )
void function_remove( const wchar_t *name ) void function_remove( const wchar_t *name )
{ {
void *key; void *key;
const void *dv; void *dv;
function_data_t *d; function_data_t *d;
event_t ev; event_t ev;
@ -221,7 +221,7 @@ void function_remove( const wchar_t *name )
hash_remove( &function, hash_remove( &function,
name, name,
(const void **) &key, &key,
&dv ); &dv );
d=(function_data_t *)dv; d=(function_data_t *)dv;
@ -303,8 +303,8 @@ static int al_contains_str( array_list_t *list, const wchar_t * str )
/** /**
Helper function for removing hidden functions Helper function for removing hidden functions
*/ */
static void get_names_internal( const void *key, static void get_names_internal( void *key,
const void *val, void *val,
void *aux ) void *aux )
{ {
wchar_t *name = (wchar_t *)key; wchar_t *name = (wchar_t *)key;
@ -319,9 +319,9 @@ static void get_names_internal( const void *key,
/** /**
Helper function for removing hidden functions Helper function for removing hidden functions
*/ */
static void get_names_internal_all( const void *key, static void get_names_internal_all( void *key,
const void *val, void *val,
void *aux ) void *aux )
{ {
wchar_t *name = (wchar_t *)key; wchar_t *name = (wchar_t *)key;

View file

@ -360,7 +360,7 @@ static void history_save()
Save the specified mode to file Save the specified mode to file
*/ */
static void history_destroy_mode( const void *name, const void *link ) static void history_destroy_mode( void *name, void *link )
{ {
mode_name = (wchar_t *)name; mode_name = (wchar_t *)name;
history_data *d = (history_data *)link; history_data *d = (history_data *)link;

View file

@ -1,5 +1,5 @@
/** \file input.c /** \file input.c
a
Functions for reading a character of input from stdin, using the Functions for reading a character of input from stdin, using the
inputrc information for key bindings. inputrc information for key bindings.
@ -1411,7 +1411,7 @@ int input_init()
/** /**
Free memory used by the specified mapping Free memory used by the specified mapping
*/ */
static void destroy_mapping( const void *key, const void *val ) static void destroy_mapping( void *key, void *val )
{ {
int i; int i;
array_list_t *mappings = (array_list_t *)val; array_list_t *mappings = (array_list_t *)val;

View file

@ -100,7 +100,7 @@ const wchar_t *intern_static( const wchar_t *in )
/** /**
Free the specified key/value pair. Should only be called by intern_free_all at shutdown Free the specified key/value pair. Should only be called by intern_free_all at shutdown
*/ */
static void clear_value( const void *key, const void *data ) static void clear_value( void *key, void *data )
{ {
debug( 3, L"interned string: '%ls'", data ); debug( 3, L"interned string: '%ls'", data );
free( (void *)data ); free( (void *)data );

2
kill.c
View file

@ -179,7 +179,7 @@ static void kill_check_x_buffer()
} }
} }
al_foreach( &list, (void (*)(const void *))&free ); al_foreach( &list, &free );
al_destroy( &list ); al_destroy( &list );
} }
} }

View file

@ -1120,7 +1120,7 @@ static void launch( char *filter, array_list_t *files, int fileno )
/** /**
Clean up one entry from the hash table of launch files Clean up one entry from the hash table of launch files
*/ */
static void clear_entry( const void *key, const void *val ) static void clear_entry( void *key, void *val )
{ {
/* /*
The key is a mime value, either from the libraries internal hash The key is a mime value, either from the libraries internal hash

View file

@ -544,7 +544,7 @@ int output_color_code( const wchar_t *val )
} }
al_foreach( &el, (void (*)(const void *))&free ); al_foreach( &el, &free );
al_destroy( &el ); al_destroy( &el );
return color | (is_bold?FISH_COLOR_BOLD:0); return color | (is_bold?FISH_COLOR_BOLD:0);

View file

@ -433,7 +433,7 @@ void parse_util_token_extent( const wchar_t *buff,
/** /**
Free hash value, but not hash key Free hash value, but not hash key
*/ */
static void clear_hash_value( const void *key, const void *data ) static void clear_hash_value( void *key, void *data )
{ {
free( (void *)data ); free( (void *)data );
} }
@ -441,7 +441,7 @@ static void clear_hash_value( const void *key, const void *data )
/** /**
Part of the autoloader cleanup Part of the autoloader cleanup
*/ */
static void clear_loaded_entry( const void *key, const void *data ) static void clear_loaded_entry( void *key, void *data )
{ {
hash_table_t *loaded = (hash_table_t *)data; hash_table_t *loaded = (hash_table_t *)data;
hash_foreach( loaded, hash_foreach( loaded,
@ -474,7 +474,7 @@ void parse_util_load_reset( const wchar_t *path_var )
if( all_loaded ) if( all_loaded )
{ {
void *key, *data; void *key, *data;
hash_remove( all_loaded, path_var, (const void **)&key, (const void **)&data ); hash_remove( all_loaded, path_var, &key, &data );
if( key ) if( key )
clear_loaded_entry( key, data ); clear_loaded_entry( key, data );
} }
@ -622,7 +622,7 @@ int parse_util_load( const wchar_t *cmd,
hash_put( loaded, intern( cmd ), tm ); hash_put( loaded, intern( cmd ), tm );
} }
al_foreach( path_list, (void (*)(const void *))&free ); al_foreach( path_list, &free );
al_truncate( path_list, 0 ); al_truncate( path_list, 0 );
return reloaded; return reloaded;

View file

@ -660,7 +660,7 @@ void reader_write_title()
} }
proc_pop_interactive(); proc_pop_interactive();
al_foreach( &l, (void (*)(const void *))&free ); al_foreach( &l, &free );
al_destroy( &l ); al_destroy( &l );
set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); set_color( FISH_COLOR_RESET, FISH_COLOR_RESET );
} }
@ -804,7 +804,7 @@ static void write_prompt()
if( data->exec_prompt ) if( data->exec_prompt )
{ {
al_foreach( &prompt_list, (void (*)(const void *))&free ); al_foreach( &prompt_list, &free );
al_truncate( &prompt_list, 0 ); al_truncate( &prompt_list, 0 );
if( data->prompt ) if( data->prompt )
@ -814,7 +814,7 @@ static void write_prompt()
if( exec_subshell( data->prompt, &prompt_list ) == -1 ) if( exec_subshell( data->prompt, &prompt_list ) == -1 )
{ {
/* If executing the prompt fails, make sure we at least don't print any junk */ /* If executing the prompt fails, make sure we at least don't print any junk */
al_foreach( &prompt_list, (void (*)(const void *))&free ); al_foreach( &prompt_list, &free );
al_destroy( &prompt_list ); al_destroy( &prompt_list );
al_init( &prompt_list ); al_init( &prompt_list );
} }
@ -1674,7 +1674,7 @@ static void reader_interactive_init()
static void reader_interactive_destroy() static void reader_interactive_destroy()
{ {
kill_destroy(); kill_destroy();
al_foreach( &prompt_list, (void (*)(const void *))&free ); al_foreach( &prompt_list, &free );
al_destroy( &prompt_list ); al_destroy( &prompt_list );
writestr( L"\n" ); writestr( L"\n" );
@ -1776,7 +1776,7 @@ static void reset_token_history()
data->token_history_pos = -1; data->token_history_pos = -1;
data->search_pos=0; data->search_pos=0;
al_foreach( &data->search_prev, (void (*)(const void *))&free ); al_foreach( &data->search_prev, &free );
al_truncate( &data->search_prev, 0 ); al_truncate( &data->search_prev, 0 );
al_push( &data->search_prev, wcsdup( data->search_buff ) ); al_push( &data->search_prev, wcsdup( data->search_buff ) );
} }
@ -2172,7 +2172,7 @@ void reader_pop()
/* /*
Clean up after history search Clean up after history search
*/ */
al_foreach( &n->search_prev, (void (*)(const void *))&free ); al_foreach( &n->search_prev, &free );
al_destroy( &n->search_prev ); al_destroy( &n->search_prev );
free( (void *)n->token_history_buff); free( (void *)n->token_history_buff);
@ -2438,7 +2438,7 @@ wchar_t *reader_readline()
if( (last_char == R_COMPLETE) && (c != R_COMPLETE) && (!comp_empty) ) if( (last_char == R_COMPLETE) && (c != R_COMPLETE) && (!comp_empty) )
{ {
al_foreach( &comp, (void (*)(const void *))&free ); al_foreach( &comp, &free );
al_truncate( &comp, 0 ); al_truncate( &comp, 0 );
comp_empty = 1; comp_empty = 1;
} }
@ -2523,7 +2523,7 @@ wchar_t *reader_readline()
if( (comp_empty = if( (comp_empty =
handle_completions( &comp ) ) ) handle_completions( &comp ) ) )
{ {
al_foreach( &comp, (void (*)(const void *))&free ); al_foreach( &comp, &free );
al_truncate( &comp, 0 ); al_truncate( &comp, 0 );
} }

78
util.c
View file

@ -175,8 +175,8 @@ int q_empty( dyn_queue_t *q )
/* Hash table functions */ /* Hash table functions */
void hash_init2( hash_table_t *h, void hash_init2( hash_table_t *h,
int (*hash_func)(const void *key), int (*hash_func)(void *key),
int (*compare_func)(const void *key1, const void *key2), int (*compare_func)(void *key1, void *key2),
size_t capacity) size_t capacity)
{ {
int i; int i;
@ -192,8 +192,8 @@ void hash_init2( hash_table_t *h,
} }
void hash_init( hash_table_t *h, void hash_init( hash_table_t *h,
int (*hash_func)(const void *key), int (*hash_func)(void *key),
int (*compare_func)(const void *key1, const void *key2) ) int (*compare_func)(void *key1, void *key2) )
{ {
h->arr = 0; h->arr = 0;
h->size = 0; h->size = 0;
@ -213,7 +213,7 @@ void hash_destroy( hash_table_t *h )
\return index in the table, or to the first free index if the key is not in the table \return index in the table, or to the first free index if the key is not in the table
*/ */
static int hash_search( hash_table_t *h, static int hash_search( hash_table_t *h,
const void *key ) void *key )
{ {
int hv; int hv;
int pos; int pos;
@ -290,38 +290,38 @@ int hash_put( hash_table_t *h,
} }
} }
pos = hash_search( h, key ); pos = hash_search( h, (void *)key );
if( h->arr[pos].key == 0 ) if( h->arr[pos].key == 0 )
{ {
h->count++; h->count++;
} }
h->arr[pos].key = key; h->arr[pos].key = (void *)key;
h->arr[pos].data = data; h->arr[pos].data = (void *)data;
return 1; return 1;
} }
const void *hash_get( hash_table_t *h, void *hash_get( hash_table_t *h,
const void *key ) const void *key )
{ {
if( !h->count ) if( !h->count )
return 0; return 0;
int pos = hash_search( h, key ); int pos = hash_search( h, (void *)key );
if( h->arr[pos].key == 0 ) if( h->arr[pos].key == 0 )
return 0; return 0;
else else
return h->arr[pos].data; return h->arr[pos].data;
} }
const void *hash_get_key( hash_table_t *h, void *hash_get_key( hash_table_t *h,
const void *key ) const void *key )
{ {
if( !h->count ) if( !h->count )
return 0; return 0;
int pos = hash_search( h, key ); int pos = hash_search( h, (void *)key );
if( h->arr[pos].key == 0 ) if( h->arr[pos].key == 0 )
return 0; return 0;
else else
@ -335,8 +335,8 @@ int hash_get_count( hash_table_t *h)
void hash_remove( hash_table_t *h, void hash_remove( hash_table_t *h,
const void *key, const void *key,
const void **old_key, void **old_key,
const void **old_val ) void **old_val )
{ {
if( !h->count ) if( !h->count )
{ {
@ -348,7 +348,7 @@ void hash_remove( hash_table_t *h,
return; return;
} }
int pos = hash_search( h, key ); int pos = hash_search( h, (void *)key );
int next_pos; int next_pos;
if( h->arr[pos].key == 0 ) if( h->arr[pos].key == 0 )
@ -407,15 +407,15 @@ int hash_contains( hash_table_t *h,
if( !h->count ) if( !h->count )
return 0; return 0;
int pos = hash_search( h, key ); int pos = hash_search( h, (void *)key );
return h->arr[pos].key != 0; return h->arr[pos].key != 0;
} }
/** /**
Push hash value into array_list_t Push hash value into array_list_t
*/ */
static void hash_put_data( const void *key, static void hash_put_data( void *key,
const void *data, void *data,
void *al ) void *al )
{ {
al_push( (array_list_t *)al, al_push( (array_list_t *)al,
@ -432,7 +432,7 @@ void hash_get_data( hash_table_t *h,
/** /**
Push hash key into array_list_t Push hash key into array_list_t
*/ */
static void hash_put_key( const void *key, const void *data, void *al ) static void hash_put_key( void *key, void *data, void *al )
{ {
al_push( (array_list_t *)al, key ); al_push( (array_list_t *)al, key );
} }
@ -445,7 +445,7 @@ void hash_get_keys( hash_table_t *h,
} }
void hash_foreach( hash_table_t *h, void hash_foreach( hash_table_t *h,
void (*func)(const void *, const void *) ) void (*func)( void *, void *) )
{ {
int i; int i;
for( i=0; i<h->size; i++ ) for( i=0; i<h->size; i++ )
@ -458,7 +458,7 @@ void hash_foreach( hash_table_t *h,
} }
void hash_foreach2( hash_table_t *h, void hash_foreach2( hash_table_t *h,
void (*func)( const void *, const void *, void * ), void (*func)( void *, void *, void * ),
void *aux ) void *aux )
{ {
int i; int i;
@ -472,7 +472,7 @@ void hash_foreach2( hash_table_t *h,
} }
int hash_str_cmp( const void *a, const void *b ) int hash_str_cmp( void *a, void *b )
{ {
return strcmp((char *)a,(char *)b) == 0; return strcmp((char *)a,(char *)b) == 0;
} }
@ -486,7 +486,7 @@ static uint rotl5( uint in )
} }
int hash_str_func( const void *data ) int hash_str_func( void *data )
{ {
int res = 0x67452301u; int res = 0x67452301u;
const char *str = data; const char *str = data;
@ -497,7 +497,7 @@ int hash_str_func( const void *data )
return res; return res;
} }
int hash_wcs_func( const void *data ) int hash_wcs_func( void *data )
{ {
int res = 0x67452301u; int res = 0x67452301u;
const wchar_t *str = data; const wchar_t *str = data;
@ -509,12 +509,12 @@ int hash_wcs_func( const void *data )
} }
int hash_wcs_cmp( const void *a, const void *b ) int hash_wcs_cmp( void *a, void *b )
{ {
return wcscmp((wchar_t *)a,(wchar_t *)b) == 0; return wcscmp((wchar_t *)a,(wchar_t *)b) == 0;
} }
int hash_ptr_func( const void *data ) int hash_ptr_func( void *data )
{ {
return (int)(long) data; return (int)(long) data;
} }
@ -522,8 +522,8 @@ int hash_ptr_func( const void *data )
/** /**
Hash comparison function suitable for direct pointer comparison Hash comparison function suitable for direct pointer comparison
*/ */
int hash_ptr_cmp( const void *a, int hash_ptr_cmp( void *a,
const void *b ) void *b )
{ {
return a == b; return a == b;
} }
@ -691,7 +691,7 @@ int al_push( array_list_t *l, const void *o )
l->arr = tmp; l->arr = tmp;
l->size = new_size; l->size = new_size;
} }
l->arr[l->pos++] = o; l->arr[l->pos++] = (void *)o;
return 1; return 1;
} }
@ -715,7 +715,7 @@ int al_set( array_list_t *l, int pos, const void *o )
return 0; return 0;
if( pos < l->pos ) if( pos < l->pos )
{ {
l->arr[pos] = o; l->arr[pos] = (void *)o;
return 1; return 1;
} }
old_pos=l->pos; old_pos=l->pos;
@ -734,7 +734,7 @@ int al_set( array_list_t *l, int pos, const void *o )
return 0; return 0;
} }
const void *al_get( array_list_t *l, int pos ) void *al_get( array_list_t *l, int pos )
{ {
if( pos < 0 ) if( pos < 0 )
return 0; return 0;
@ -748,12 +748,12 @@ void al_truncate( array_list_t *l, int new_sz )
l->pos = new_sz; l->pos = new_sz;
} }
const void *al_pop( array_list_t *l ) void *al_pop( array_list_t *l )
{ {
const void *e = l->arr[--l->pos]; void *e = l->arr[--l->pos];
if( (l->pos*3 < l->size) && (l->size < MIN_SIZE) ) if( (l->pos*3 < l->size) && (l->size < MIN_SIZE) )
{ {
const void ** old_arr = l->arr; void ** old_arr = l->arr;
int old_size = l->size; int old_size = l->size;
l->size = l->size/2; l->size = l->size/2;
l->arr = realloc( l->arr, sizeof(void*)*l->size ); l->arr = realloc( l->arr, sizeof(void*)*l->size );
@ -766,7 +766,7 @@ const void *al_pop( array_list_t *l )
return e; return e;
} }
const void *al_peek( array_list_t *l ) void *al_peek( array_list_t *l )
{ {
return l->pos>0?l->arr[l->pos-1]:0; return l->pos>0?l->arr[l->pos-1]:0;
@ -783,14 +783,14 @@ int al_get_count( array_list_t *l )
return l->pos; return l->pos;
} }
void al_foreach( array_list_t *l, void (*func)( const void * )) void al_foreach( array_list_t *l, void (*func)( void * ))
{ {
int i; int i;
for( i=0; i<l->pos; i++ ) for( i=0; i<l->pos; i++ )
func( l->arr[i] ); func( l->arr[i] );
} }
void al_foreach2( array_list_t *l, void (*func)( const void *, void *), void *aux) void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux)
{ {
int i; int i;
for( i=0; i<l->pos; i++ ) for( i=0; i<l->pos; i++ )

66
util.h
View file

@ -31,9 +31,9 @@ dyn_queue_t;
typedef struct typedef struct
{ {
/** Hash key*/ /** Hash key*/
const void *key; void *key;
/** Value */ /** Value */
const void *data; void *data;
} }
hash_struct_t; hash_struct_t;
@ -61,9 +61,9 @@ typedef struct hash_table
/** Length of array */ /** Length of array */
int size; int size;
/** Hash function */ /** Hash function */
int (*hash_func)( const void *key ); int (*hash_func)( void *key );
/** Comparison function */ /** Comparison function */
int (*compare_func)( const void *key1, const void *key2 ); int (*compare_func)( void *key1, void *key2 );
} }
hash_table_t; hash_table_t;
@ -93,7 +93,7 @@ priority_queue_t;
typedef struct array_list typedef struct array_list
{ {
/** Array containing the data */ /** Array containing the data */
const void **arr; void **arr;
/** Position to append elements at*/ /** Position to append elements at*/
int pos; int pos;
/** Length of array */ /** Length of array */
@ -195,15 +195,15 @@ int q_empty( dyn_queue_t *q );
Initialize a hash table. The hash function must never return the value 0. Initialize a hash table. The hash function must never return the value 0.
*/ */
void hash_init( hash_table_t *h, void hash_init( hash_table_t *h,
int (*hash_func)(const void *key), int (*hash_func)( void *key),
int (*compare_func)(const void *key1, const void *key2) ); int (*compare_func)( void *key1, void *key2 ) );
/** /**
Initialize a hash table. The hash function must never return the value 0. Initialize a hash table. The hash function must never return the value 0.
*/ */
void hash_init2( hash_table_t *h, void hash_init2( hash_table_t *h,
int (*hash_func)(const void *key), int (*hash_func)( void *key ),
int (*compare_func)(const void *key1, const void *key2), int (*compare_func)( void *key1, void *key2 ),
size_t capacity); size_t capacity);
/** /**
@ -219,13 +219,13 @@ int hash_put( hash_table_t *h,
/** /**
Returns the data with the associated key, or 0 if no such key is in the hashtable Returns the data with the associated key, or 0 if no such key is in the hashtable
*/ */
const void *hash_get( hash_table_t *h, void *hash_get( hash_table_t *h,
const void *key ); const void *key );
/** /**
Returns the hash tables version of the specified key Returns the hash tables version of the specified key
*/ */
const void *hash_get_key( hash_table_t *h, void *hash_get_key( hash_table_t *h,
const void *key ); const void *key );
/** /**
Returns the number of key/data pairs in the table. Returns the number of key/data pairs in the table.
@ -241,8 +241,8 @@ int hash_get_count( hash_table_t *h);
*/ */
void hash_remove( hash_table_t *h, void hash_remove( hash_table_t *h,
const void *key, const void *key,
const void **old_key, void **old_key,
const void **old_data ); void **old_data );
/** /**
Checks whether the specified key is in the hash table Checks whether the specified key is in the hash table
@ -266,49 +266,49 @@ void hash_get_data( hash_table_t *h,
Call the function func for each key/data pair in the table Call the function func for each key/data pair in the table
*/ */
void hash_foreach( hash_table_t *h, void hash_foreach( hash_table_t *h,
void (*func)( const void *, const void * ) ); void (*func)( void *, void * ) );
/** /**
Same as hash_foreach, but the function func takes an additional Same as hash_foreach, but the function func takes an additional
argument, which is provided by the caller in the variable aux argument, which is provided by the caller in the variable aux
*/ */
void hash_foreach2( hash_table_t *h, void (*func)( const void *, void hash_foreach2( hash_table_t *h, void (*func)( void *,
const void *, void *,
void *), void *),
void *aux ); void *aux );
/** /**
Hash function suitable for character strings. Hash function suitable for character strings.
*/ */
int hash_str_func( const void *data ); int hash_str_func( void *data );
/** /**
Hash comparison function suitable for character strings Hash comparison function suitable for character strings
*/ */
int hash_str_cmp( const void *a, int hash_str_cmp( void *a,
const void *b ); void *b );
/** /**
Hash function suitable for wide character strings. Hash function suitable for wide character strings.
*/ */
int hash_wcs_func( const void *data ); int hash_wcs_func( void *data );
/** /**
Hash comparison function suitable for wide character strings Hash comparison function suitable for wide character strings
*/ */
int hash_wcs_cmp( const void *a, int hash_wcs_cmp( void *a,
const void *b ); void *b );
/** /**
Hash function suitable for direct pointer comparison Hash function suitable for direct pointer comparison
*/ */
int hash_ptr_func( const void *data ); int hash_ptr_func( void *data );
/** /**
Hash comparison function suitable for direct pointer comparison Hash comparison function suitable for direct pointer comparison
*/ */
int hash_ptr_cmp( const void *a, int hash_ptr_cmp( void *a,
const void *b ); void *b );
@ -404,7 +404,7 @@ int al_set( array_list_t *l, int pos, const void *o );
\param pos The index \param pos The index
\return The element \return The element
*/ */
const void *al_get( array_list_t *l, int pos ); void *al_get( array_list_t *l, int pos );
/** /**
Truncates the list to new_sz items. Truncates the list to new_sz items.
@ -414,7 +414,7 @@ void al_truncate( array_list_t *l, int new_sz );
/** /**
Removes and returns the last entry in the list Removes and returns the last entry in the list
*/ */
const void *al_pop( array_list_t *l ); void *al_pop( array_list_t *l );
/** /**
Returns the number of elements in the list Returns the number of elements in the list
@ -424,7 +424,7 @@ int al_get_count( array_list_t *l );
/** /**
Returns the last entry in the list witout removing it. Returns the last entry in the list witout removing it.
*/ */
const void *al_peek( array_list_t *l ); void *al_peek( array_list_t *l );
/** /**
Returns 1 if the list is empty, 0 otherwise Returns 1 if the list is empty, 0 otherwise
@ -434,13 +434,13 @@ int al_empty( array_list_t *l);
/** /**
Call the function func for each entry in the list Call the function func for each entry in the list
*/ */
void al_foreach( array_list_t *l, void (*func)(const void * )); void al_foreach( array_list_t *l, void (*func)( void * ));
/** /**
Same as al_foreach, but the function func takes an additional Same as al_foreach, but the function func takes an additional
argument, which is provided by the caller in the variable aux argument, which is provided by the caller in the variable aux
*/ */
void al_foreach2( array_list_t *l, void (*func)(const void *, void *), void *aux); void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux);
/** /**
Compares two wide character strings without case but with Compares two wide character strings without case but with