diff --git a/env_universal.cpp b/env_universal.cpp index 7ab5956c0..94e592a19 100644 --- a/env_universal.cpp +++ b/env_universal.cpp @@ -211,7 +211,7 @@ static void env_universal_remove_all() size_t i; wcstring_list_t lst; - env_universal_common_get_names2( lst, + env_universal_common_get_names( lst, 1, 1 ); for( i=0; ivalue; } - -#if 0 - /** - Second block type specific variable - */ - union - { - array_list_t for_vars; /**< List of values for a for block */ - int switch_taken; /**< Whether a switch match has already been found */ - process_t *function_call_process; /**< The process representing this function call */ - } param2; -#endif - - /** Name of file that created this block */ diff --git a/reader.cpp b/reader.cpp index 4093cc4dd..7c65c32d2 100644 --- a/reader.cpp +++ b/reader.cpp @@ -349,7 +349,7 @@ static int interrupted=0; */ static struct termios saved_modes; -static void reader_super_highlight_me_plenty( int pos, array_list_t *error ); +static void reader_super_highlight_me_plenty( int pos ); /** Variable to keep track of forced exits - see \c reader_exit_forced(); @@ -491,7 +491,7 @@ static void reader_kill( size_t begin_idx, int length, int mode, int newv ) data->command_line.erase(begin_idx, length); data->check_size(); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); } @@ -544,31 +544,9 @@ void reader_data_t::check_size() { } -/** - Compare two completion entrys - */ -/* -static int completion_cmp( const void *a, const void *b ) -{ - completion_t *c= *((completion_t **)a); - completion_t *d= *((completion_t **)b); - - return wcsfilecmp( c->completion, d->completion ); - -} -*/ /** Sort an array_list_t containing compltion_t structs. */ -/* -static void sort_completion_list( array_list_t *comp ) -{ - qsort( comp->arr, - al_get_count( comp ), - sizeof( void*), - &completion_cmp ); -} -*/ static void sort_completion_list( std::vector &comp ) { sort(comp.begin(), comp.end()); } @@ -577,33 +555,6 @@ static void sort_completion_list( std::vector &comp ) { Remove any duplicate completions in the list. This relies on the list first beeing sorted. */ -/* -static void remove_duplicates( array_list_t *l ) -{ - int in, out; - const wchar_t *prev; - completion_t *first; - - if( al_get_count( l ) == 0 ) - return; - - first = (completion_t *)al_get( l, 0 ); - prev = first->completion; - - for( in=1, out=1; in < al_get_count( l ); in++ ) - { - completion_t *curr = (completion_t *)al_get( l, in ); - - if( wcscmp( prev, curr->completion )!=0 ) - { - al_set( l, out++, curr ); - } - prev = curr->completion; - } - al_truncate( l, out ); -} -*/ - static void remove_duplicates(std::vector &l) { l.erase(std::unique( l.begin(), l.end()), l.end()); @@ -773,7 +724,7 @@ static void remove_backward() data->check_size(); data->suppress_autosuggestion = true; - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); @@ -793,7 +744,7 @@ static int insert_string(const wcstring &str) data->suppress_autosuggestion = false; /* Syntax highlight */ - reader_super_highlight_me_plenty( data->buff_pos-1, 0 ); + reader_super_highlight_me_plenty( data->buff_pos-1 ); reader_repaint(); return 1; @@ -1024,7 +975,7 @@ static void completion_insert( const wchar_t *val, int flags ) reader_set_buffer( (wchar_t *)sb.buff, (begin-buff)+move_cursor ); sb_destroy( &sb ); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); } @@ -1382,7 +1333,7 @@ static void reader_flash() pollint.tv_nsec = 100 * 1000000; nanosleep( &pollint, NULL ); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); } @@ -1839,7 +1790,7 @@ static void handle_history( const wcstring &new_str ) data->command_line = new_str; data->check_size(); data->buff_pos=data->command_line.size(); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); } @@ -1906,7 +1857,7 @@ static void handle_token_history( int forward, int reset ) } reader_replace_current_token( str ); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); } else @@ -1983,7 +1934,7 @@ static void handle_token_history( int forward, int reset ) if( str ) { reader_replace_current_token( str ); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); data->search_prev.push_back(str); data->search_pos = data->search_prev.size() - 1; @@ -2182,7 +2133,7 @@ void reader_set_buffer( const wchar_t *b, int p ) data->search_buff.clear(); data->history_search.go_to_end(); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint_needed(); } @@ -2483,7 +2434,7 @@ static int threaded_highlight(background_highlight_context_t *ctx) { \param match_highlight_pos the position to use for bracket matching. This need not be the same as the surrent cursor position \param error if non-null, any possible errors in the buffer are further descibed by the strings inserted into the specified arraylist */ -static void reader_super_highlight_me_plenty( int match_highlight_pos, array_list_t *error ) +static void reader_super_highlight_me_plenty( int match_highlight_pos ) { reader_sanity_check(); @@ -2701,7 +2652,7 @@ const wchar_t *reader_readline() exec_prompt(); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); s_reset( &data->screen, 1 ); reader_repaint(); @@ -3022,7 +2973,7 @@ const wchar_t *reader_readline() reader_replace_current_token( data->search_buff.c_str() ); } data->search_buff.clear(); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + reader_super_highlight_me_plenty( data->buff_pos ); reader_repaint(); } @@ -3223,7 +3174,7 @@ const wchar_t *reader_readline() data->command_line = data->autosuggestion; data->buff_pos = data->command_line.size(); data->check_size(); - reader_super_highlight_me_plenty(data->buff_pos, 0); + reader_super_highlight_me_plenty(data->buff_pos); reader_repaint(); } } diff --git a/util.cpp b/util.cpp index bee35495b..b446fa7ac 100644 --- a/util.cpp +++ b/util.cpp @@ -95,257 +95,6 @@ int maxi( int a, return a>b?a:b; } -/** - Real implementation of all al_push_* versions. Pushes arbitrary - element to end of list. - */ -static int al_push_generic( array_list_t *l, anything_t o ) -{ - if( l->pos >= l->size ) - { - int new_size = l->pos == 0 ? MIN_SIZE : 2 * l->pos; - void *tmp = realloc( l->arr, sizeof( anything_t )*new_size ); - if( tmp == 0 ) - { - oom_handler( l ); - return 0; - } - l->arr = (anything_t *)tmp; - l->size = new_size; - } - l->arr[l->pos++] = o; - return 1; -} - -int al_push( array_list_t *l, const void *o ) -{ - anything_t v; - v.ptr_val = (void *)o; - return al_push_generic( l, v ); -} - -int al_push_long( array_list_t *l, long val ) -{ - anything_t v; - v.long_val = val; - return al_push_generic( l, v ); -} - -int al_push_func( array_list_t *l, func_ptr_t f ) -{ - anything_t v; - v.func_val = f; - return al_push_generic( l, v ); -} - - -int al_push_all( array_list_t *a, array_list_t *b ) -{ - int k; - for( k=0; kpos ) - { - l->arr[pos]=v; - return 1; - } - old_pos=l->pos; - - l->pos = pos; - if( al_push_generic( l, v ) ) - { - memset( &l->arr[old_pos], - 0, - sizeof(anything_t) * (pos - old_pos) ); - return 1; - } - return 0; -} - -int al_set( array_list_t *l, int pos, const void *o ) -{ - anything_t v; - v.ptr_val = (void *)o; - return al_set_generic( l, pos, v ); -} - -int al_set_long( array_list_t *l, int pos, long o ) -{ - anything_t v; - v.long_val = o; - return al_set_generic( l, pos, v ); -} - -int al_set_func( array_list_t *l, int pos, func_ptr_t f ) -{ - anything_t v; - v.func_val = f; - return al_set_generic( l, pos, v ); -} - -/** - Real implementation of all al_get_* versions. Returns element from list. - */ -static anything_t al_get_generic( array_list_t *l, int pos ) -{ - anything_t res; - res.ptr_val=0; - - if( (pos >= 0) && ((size_t)pos < l->pos) ) - res = l->arr[pos]; - - return res; -} - -void *al_get( array_list_t *l, int pos ) -{ - return al_get_generic(l,pos).ptr_val; -} - -long al_get_long( array_list_t *l, int pos ) -{ - return al_get_generic(l,pos).long_val; -} - -func_ptr_t al_get_func( array_list_t *l, int pos ) -{ - return al_get_generic(l,pos).func_val; -} - - - -void al_truncate( array_list_t *l, int new_sz ) -{ - CHECK( l, ); - l->pos = new_sz; -} - -/** - Real implementation of all al_pop_* versions. Pops arbitrary - element from end of list. - */ -static anything_t al_pop_generic( array_list_t *l ) -{ - anything_t e; - - if( l->pos <= 0 ) - { - memset( &e, 0, sizeof(anything_t ) ); - return e; - } - - - e = l->arr[--l->pos]; - if( (l->pos*3 < l->size) && (l->size < MIN_SIZE) ) - { - anything_t *old_arr = l->arr; - int old_size = l->size; - l->size = l->size/2; - l->arr = (anything_t *)realloc( l->arr, sizeof(anything_t)*l->size ); - if( l->arr == 0 ) - { - l->arr = old_arr; - l->size = old_size; - /* - We are _shrinking_ the list here, so if the allocation - fails (it never should, but hey) then we can keep using - the old list - no need to flag any error... - */ - } - } - return e; -} - -void *al_pop( array_list_t *l ) -{ - return al_pop_generic(l).ptr_val; -} - -long al_pop_long( array_list_t *l ) -{ - return al_pop_generic(l).long_val; -} - -func_ptr_t al_pop_func( array_list_t *l ) -{ - return al_pop_generic(l).func_val; -} - -/** - Real implementation of all al_peek_* versions. Peeks last element - of list. - */ -static anything_t al_peek_generic( array_list_t *l ) -{ - anything_t res; - res.ptr_val=0; - if( l->pos>0) - res = l->arr[l->pos-1]; - return res; -} - -void *al_peek( array_list_t *l ) -{ - return al_peek_generic(l).ptr_val; -} - -long al_peek_long( array_list_t *l ) -{ - return al_peek_generic(l).long_val; -} - -func_ptr_t al_peek_func( array_list_t *l ) -{ - return al_peek_generic(l).func_val; -} - - -int al_get_count( array_list_t *l ) - -{ - CHECK( l, 0 ); - return l->pos; -} - -void al_foreach( array_list_t *l, void (*func)( void * )) -{ - size_t i; - - CHECK( l, ); - CHECK( func, ); - - for( i=0; ipos; i++ ) - func( l->arr[i].ptr_val ); -} - -void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux) -{ - size_t i; - - CHECK( l, ); - CHECK( func, ); - - for( i=0; ipos; i++ ) - func( l->arr[i].ptr_val, aux ); -} - int wcsfilecmp( const wchar_t *a, const wchar_t *b ) { CHECK( a, 0 ); diff --git a/util.h b/util.h index 625c950d0..d95615858 100644 --- a/util.h +++ b/util.h @@ -61,33 +61,6 @@ typedef struct priority_queue } priority_queue_t; -/** - Array list struct. - A dynamically growing list that supports stack operations. -*/ -typedef struct array_list -{ - /** - Array containing the data - */ - anything_t *arr; - - /** - Internal cursor position of the array_list_t. This is the - position to append elements at. This is also what the - array_list_t considers to be its true size, as reported by - al_get_count(), etc. Calls to e.g. al_insert will preserve the - values of all elements up to pos. - */ - size_t pos; - - /** - Amount of memory allocated in arr, expressed in number of elements. - */ - size_t size; -} -array_list_t; - /** Linked list node. */ @@ -143,146 +116,6 @@ int maxi( int a, int b ); */ int mini( int a, int b ); -/* - All the datastuctures below autoresize. The queue, stack and - priority queue are all impemented using an array and are guaranteed - to never be less than 50% full. -*/ - -/** - Append element to list - - \param l The list - \param o The element - \return - \return 1 if succesfull, 0 otherwise -*/ -int al_push( array_list_t *l, const void *o ); -/** - Append element to list - - \param l The list - \param o The element - \return - \return 1 if succesfull, 0 otherwise -*/ -int al_push_long( array_list_t *l, long o ); -/** - Append element to list - - \param l The list - \param f The element - \return 1 if succesfull, 0 otherwise -*/ -int al_push_func( array_list_t *l, func_ptr_t f ); - -/** - Append all elements of a list to another - - \param a The destination list - \param b The source list - \return 1 if succesfull, 0 otherwise -*/ -int al_push_all( array_list_t *a, array_list_t *b ); - - -/** - Sets the element at the specified index - - \param l The array_list_t - \param pos The index - \param o The element -*/ -int al_set( array_list_t *l, int pos, const void *o ); -/** - Sets the element at the specified index - - \param l The array_list_t - \param pos The index - \param v The element to set -*/ -int al_set_long( array_list_t *l, int pos, long v ); -/** - Sets the element at the specified index - - \param l The array_list_t - \param pos The index - \param f The element to insert -*/ -int al_set_func( array_list_t *l, int pos, func_ptr_t f ); - -/** - Returns the element at the specified index - - \param l The array_list_t - \param pos The index - \return The element -*/ -void *al_get( array_list_t *l, int pos ); -/** - Returns the element at the specified index - - \param l The array_list_t - \param pos The index - \return The element -*/ -long al_get_long( array_list_t *l, int pos ); -/** - Returns the element at the specified index - - \param l The array_list_t - \param pos The index - \return The element -*/ -func_ptr_t al_get_func( array_list_t *l, int pos ); - -/** - Truncates the list to new_sz items. -*/ -void al_truncate( array_list_t *l, int new_sz ); - -/** - Removes and returns the last entry in the list -*/ -void *al_pop( array_list_t *l ); -/** - Removes and returns the last entry in the list -*/ -long al_pop_long( array_list_t *l ); -/** - Removes and returns the last entry in the list -*/ -func_ptr_t al_pop_func( array_list_t *l ); - -/** - Returns the number of elements in the list -*/ -int al_get_count( array_list_t *l ); - -/** - Returns the last entry in the list witout removing it. -*/ -void *al_peek( array_list_t *l ); -/** - Returns the last entry in the list witout removing it. -*/ -long al_peek_long( array_list_t *l ); -/** - Returns the last entry in the list witout removing it. -*/ -func_ptr_t al_peek_func( array_list_t *l ); - -/** - Call the function func for each entry in the list -*/ -void al_foreach( array_list_t *l, void (*func)( void * )); - -/** - Same as al_foreach, but the function func takes an additional - argument, which is provided by the caller in the variable aux -*/ -void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux); - /** Compares two wide character strings with an (arguably) intuitive ordering. diff --git a/wildcard.cpp b/wildcard.cpp index 28b683f52..d7028cf7e 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -198,7 +198,7 @@ static int wildcard_match2( const wcstring &str_str, /** Matches the string against the wildcard, and if the wildcard is a possible completion of the string, the remainder of the string is - inserted into the array_list_t. + inserted into the out vector. */ static int wildcard_complete_internal( const wchar_t *orig, const wchar_t *str, diff --git a/wildcard.h b/wildcard.h index d5fba374b..e6db70995 100644 --- a/wildcard.h +++ b/wildcard.h @@ -66,11 +66,6 @@ enum \return 1 if matches where found, 0 otherwise. Return -1 on abort (I.e. ^C was pressed). */ -int wildcard_expand( const wchar_t *wc, - const wchar_t *base_dir, - int flags, - array_list_t *out ); - int wildcard_expand_string(const wcstring &wc, const wcstring &base_dir, int flags, std::vector &out ); /** Test whether the given wildcard matches the string