int exec_pipe( int fd[2]) { int res; while( ( res=pipe( fd ) ) ) { if( errno != EINTR ) { wperror(L"pipe"); return res; } } debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]); if( open_fds == 0 ) { open_fds = al_halloc( global_context ); } al_push_long( open_fds, (long)fd[0] ); al_push_long( open_fds, (long)fd[1] ); return res; }
/** Test stack functionality */ static int stack_test( int elements ) { long i; int res=1; array_list_t s; al_init( &s ); for( i=0; i<elements; i++ ) { long foo; al_push_long( &s, i); al_push_long( &s, i); if( (foo=al_pop_long( &s )) != i ) { err( L"Unexpected data" ); res = 0; break; } } for( i=0; i<elements; i++ ) { long foo; if( (foo=al_pop_long( &s )) != (elements-i-1) ) { err( L"Unexpected data" ); res = 0; break; } } al_destroy( &s ); return res; }
const wchar_t *history_prev_match( const wchar_t *needle ) { if( current_mode ) { if( current_mode->pos > 0 ) { for( current_mode->pos--; current_mode->pos>=0; current_mode->pos-- ) { item_t *i = item_get( current_mode, al_get( ¤t_mode->item, current_mode->pos ) ); wchar_t *haystack = (wchar_t *)i->data; if( history_test( needle, haystack ) ) { int is_used; /* This is ugly. Whenever we call item_get(), there is a chance that the return value of any previous call to item_get will become invalid. The history_is_used function uses the item_get() function. Therefore, we must create a copy of the haystack string, and if the string is unused, we must call item_get anew. */ haystack = wcsdup(haystack ); is_used = history_is_used( haystack ); free( haystack ); if( !is_used ) { i = item_get( current_mode, al_get( ¤t_mode->item, current_mode->pos ) ); al_push_long( ¤t_mode->used, current_mode->pos ); return i->data; } } } } if( !current_mode->has_loaded ) { /* We found no match in the list, try loading the history file and continue the search */ history_load( current_mode ); return history_prev_match( needle ); } else { /* We found no match in the list, and the file is already loaded. Set poition before first element and return original search string. */ current_mode->pos=-1; if( al_peek_long( ¤t_mode->used ) != -1 ) al_push_long( ¤t_mode->used, -1 ); } } return needle; }