diff options
author | 2011-12-28 12:36:47 -0800 | |
---|---|---|
committer | 2011-12-28 12:36:47 -0800 | |
commit | 78322a63218e8c66a4788dc79e252db4050bca23 (patch) | |
tree | 289c0cb82cc30e0c4f5d86e6be24b4e1990bb572 | |
parent | 46fa2dd2f0d104471bbb00b8e119decd91cda71d (diff) |
Migrate some more away from array_list_t
-rw-r--r-- | env.cpp | 12 | ||||
-rw-r--r-- | reader.cpp | 49 | ||||
-rw-r--r-- | screen.cpp | 16 | ||||
-rw-r--r-- | screen.h | 8 | ||||
-rw-r--r-- | wildcard.cpp | 27 |
5 files changed, 48 insertions, 64 deletions
@@ -1678,7 +1678,6 @@ char **env_export_arr( int recalc ) if( has_changed ) { - array_list_t uni; hash_table_t vals; int prev_was_null=1; int pos=0; @@ -1690,16 +1689,15 @@ char **env_export_arr( int recalc ) get_exported( top, &vals ); - al_init( &uni ); - env_universal_get_names( &uni, 1, 0 ); - for( i=0; i<al_get_count( &uni ); i++ ) + wcstring_list_t uni; + env_universal_get_names2( uni, 1, 0 ); + for( i=0; i<uni.size(); i++ ) { - wchar_t *key = (wchar_t *)al_get( &uni, i ); - wchar_t *val = env_universal_get( key ); + const wchar_t *key = uni.at(i).c_str(); + const wchar_t *val = env_universal_get( key ); if( wcscmp( val, ENV_NULL) && !hash_get( &vals, key ) ) hash_put( &vals, key, val ); } - al_destroy( &uni ); export_buffer.used=0; @@ -236,13 +236,13 @@ class reader_data_t /** Name of the current application */ - wchar_t *name; + wcstring app_name; /** The prompt command */ - wchar_t *prompt; + wcstring prompt; /** The output of the last evaluation of the prompt command */ - string_buffer_t prompt_buff; + wcstring prompt_buff; /** Color is the syntax highlighting for buff. The format is that @@ -424,7 +424,7 @@ static void reader_repaint() parser_test( data->buff, data->indent, 0, 0 ); s_write( &data->screen, - (wchar_t *)data->prompt_buff.buff, + data->prompt_buff.c_str(), data->buff, data->color, data->indent, @@ -606,7 +606,6 @@ int reader_interrupted() void reader_write_title() { const wchar_t *title; - array_list_t l; wchar_t *term = env_get( L"TERM" ); /* @@ -649,26 +648,23 @@ void reader_write_title() if( wcslen( title ) ==0 ) return; - al_init( &l ); + wcstring_list_t lst; proc_push_interactive(0); - if( exec_subshell( title, &l ) != -1 ) + if( exec_subshell2( title, lst ) != -1 ) { int i; - if( al_get_count( &l ) > 0 ) + if( lst.size() > 0 ) { writestr( L"\x1b]2;" ); - for( i=0; i<al_get_count( &l ); i++ ) + for( i=0; i<lst.size(); i++ ) { - writestr( (wchar_t *)al_get( &l, i ) ); + writestr( lst.at(i).c_str() ); } writestr( L"\7" ); } } - proc_pop_interactive(); - - al_foreach( &l, &free ); - al_destroy( &l ); + proc_pop_interactive(); set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); } @@ -682,11 +678,11 @@ static void exec_prompt() array_list_t prompt_list; al_init( &prompt_list ); - if( data->prompt ) + if( data->prompt.size() ) { proc_push_interactive( 0 ); - if( exec_subshell( data->prompt, &prompt_list ) == -1 ) + if( exec_subshell( data->prompt.c_str(), &prompt_list ) == -1 ) { /* If executing the prompt fails, make sure we at least don't print any junk */ al_foreach( &prompt_list, &free ); @@ -698,13 +694,13 @@ static void exec_prompt() reader_write_title(); - sb_clear( &data->prompt_buff ); + data->prompt_buff.resize(0); - for( i = 0; i < al_get_count( &prompt_list )-1; i++ ) + for( i = 0; i < al_get_count( &prompt_list ); i++ ) { - sb_append( &data->prompt_buff, (wchar_t *)al_get( &prompt_list, i ), L"\n" ); + if (i > 0) data->prompt_buff += L"\n"; + data->prompt_buff += (wchar_t *)al_get( &prompt_list, i ); } - sb_append( &data->prompt_buff, (wchar_t *)al_get( &prompt_list, i )); al_foreach( &prompt_list, &free ); al_destroy( &prompt_list ); @@ -2276,14 +2272,12 @@ void reader_push( const wchar_t *name ) } reader_data_t *n = new(buff) reader_data_t; - n->name = wcsdup( name ); + n->app_name = name; n->next = data; sb_init( &n->kill_item ); data=n; - sb_init( &data->prompt_buff ); - check_size(); data->buff[0]=0; sb_init( &data->search_buff ); @@ -2317,16 +2311,12 @@ void reader_pop() data=data->next; - free(n->name ); - free( n->prompt ); free( n->buff ); free( n->color ); free( n->indent ); sb_destroy( &n->search_buff ); sb_destroy( &n->kill_item ); - sb_destroy( &n->prompt_buff ); - /* Clean up after history search */ @@ -2345,15 +2335,14 @@ void reader_pop() else { end_loop = 0; - history_set_mode( data->name ); + history_set_mode( data->app_name.c_str() ); s_reset( &data->screen, 1 ); } } void reader_set_prompt( const wchar_t *new_prompt ) { - free( data->prompt ); - data->prompt=wcsdup(new_prompt); + data->prompt = new_prompt; } void reader_set_complete_function( void (*f)( const wchar_t *, @@ -70,7 +70,7 @@ static buffer_t *s_writeb_buffer=0; specified position of the specified wide character string. All of \c seq must match, but str may be longer than seq. */ -static int try_sequence( char *seq, wchar_t *str ) +static int try_sequence( const char *seq, const wchar_t *str ) { int i; @@ -106,7 +106,7 @@ static int next_tab_stop( int in ) to detect common escape sequences that may be embeded in a prompt, such as color codes. */ -static int calc_prompt_width( wchar_t *prompt ) +static int calc_prompt_width( const wchar_t *prompt ) { int res = 0; int j, k; @@ -573,7 +573,7 @@ static void s_write_mbs( buffer_t *b, char *s ) Convert a wide string to a multibyte string and append it to the buffer. */ -static void s_write_str( buffer_t *b, wchar_t *s ) +static void s_write_str( buffer_t *b, const wchar_t *s ) { int (*writer_old)(char) = output_get_writer(); @@ -588,7 +588,7 @@ static void s_write_str( buffer_t *b, wchar_t *s ) /** Update the screen to match the desired output. */ -static void s_update( screen_t *scr, wchar_t *prompt ) +static void s_update( screen_t *scr, const wchar_t *prompt ) { int i, j, k; int prompt_width = calc_prompt_width( prompt ); @@ -710,10 +710,10 @@ static int is_dumb() void s_write( screen_t *s, - wchar_t *prompt, - wchar_t *b, - int *c, - int *indent, + const wchar_t *prompt, + const wchar_t *b, + const int *c, + const int *indent, int cursor ) { int i; @@ -135,10 +135,10 @@ typedef struct as possible. */ void s_write( screen_t *s, - wchar_t *prompt, - wchar_t *commandline, - int *colors, - int *indent, + const wchar_t *prompt, + const wchar_t *commandline, + const int *colors, + const int *indent, int cursor_pos ); /** diff --git a/wildcard.cpp b/wildcard.cpp index 7e51be03..02c651c7 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -388,23 +388,21 @@ static wchar_t *complete_get_desc_suffix_internal( const wchar_t *suff_orig ) wchar_t *suff = wcsdup( suff_orig ); wchar_t *cmd = wcsdupcat( SUFFIX_CMD_STR, suff ); - wchar_t *desc = 0; - array_list_t l; if( !suff || !cmd ) DIE_MEM(); - al_init( &l ); + wcstring_list_t lst; + wcstring desc; - if( exec_subshell( cmd, &l ) != -1 ) + if( exec_subshell2( cmd, lst ) != -1 ) { - - if( al_get_count( &l )>0 ) + if( lst.size()>0 ) { - wchar_t *ln = (wchar_t *)al_get(&l, 0 ); - if( wcscmp( ln, L"unknown" ) != 0 ) + const wcstring & ln = lst.at(0); + if( ln.size() > 0 && ln != L"unknown" ) { - desc = wcsdup( ln); + desc = ln; /* I have decided I prefer to have the description begin in uppercase and the whole universe will just @@ -416,17 +414,16 @@ static wchar_t *complete_get_desc_suffix_internal( const wchar_t *suff_orig ) } free(cmd); - al_foreach( &l, &free ); - al_destroy( &l ); - if( !desc ) + if( ! desc.size() ) { - desc = wcsdup(COMPLETE_FILE_DESC); + desc = COMPLETE_FILE_DESC; } - hash_put( suffix_hash, suff, desc ); + wchar_t *tmp = wcsdup(desc.c_str()); + hash_put( suffix_hash, suff, tmp ); - return desc; + return tmp; } /** |