From 78322a63218e8c66a4788dc79e252db4050bca23 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 28 Dec 2011 12:36:47 -0800 Subject: [PATCH] Migrate some more away from array_list_t --- env.cpp | 12 +++++------- reader.cpp | 49 +++++++++++++++++++------------------------------ screen.cpp | 16 ++++++++-------- screen.h | 8 ++++---- wildcard.cpp | 27 ++++++++++++--------------- 5 files changed, 48 insertions(+), 64 deletions(-) diff --git a/env.cpp b/env.cpp index 4392aa6e1..3305d861d 100644 --- a/env.cpp +++ b/env.cpp @@ -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; ibuff, 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; iprompt ) + 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 *, diff --git a/screen.cpp b/screen.cpp index 24caf8ef8..e8fe83968 100644 --- a/screen.cpp +++ b/screen.cpp @@ -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; diff --git a/screen.h b/screen.h index 291f35c64..4623f64e1 100644 --- a/screen.h +++ b/screen.h @@ -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 7e51be030..02c651c7e 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; } /**