From c6372a1b3f56d7022f135b8f1baeaff44816ec7c Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sat, 18 Sep 2010 09:51:16 +0800 Subject: remove trailing spaces This is done by `sed -i -e 's/[ \t]*$//' *.[c,h]`, which should not introduce any functionality change. --- reader.c | 472 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 236 insertions(+), 236 deletions(-) (limited to 'reader.c') diff --git a/reader.c b/reader.c index 426f06c9..69b2e80d 100644 --- a/reader.c +++ b/reader.c @@ -240,7 +240,7 @@ typedef struct reader_data /** The output of the last evaluation of the prompt command */ string_buffer_t prompt_buff; - + /** Color is the syntax highlighting for buff. The format is that color[i] is the classification (according to the enum in @@ -284,7 +284,7 @@ typedef struct reader_data int prev_end_loop; /** - The current contents of the top item in the kill ring. + The current contents of the top item in the kill ring. */ string_buffer_t kill_item; @@ -423,12 +423,12 @@ int reader_exit_forced() static void reader_repaint() { parser_test( data->buff, data->indent, 0, 0 ); - + s_write( &data->screen, (wchar_t *)data->prompt_buff.buff, data->buff, - data->color, - data->indent, + data->color, + data->indent, data->buff_pos ); data->repaint_needed = 0; } @@ -460,7 +460,7 @@ static void reader_kill( wchar_t *begin, int length, int mode, int new ) sb_append( &data->kill_item, old ); } - + kill_replace( old, (wchar_t *)data->kill_item.buff ); free( old ); } @@ -469,19 +469,19 @@ static void reader_kill( wchar_t *begin, int length, int mode, int new ) { data->buff_pos = maxi( begin-data->buff, data->buff_pos-length ); } - + data->buff_len -= length; memmove( begin, begin+length, sizeof( wchar_t )*(wcslen( begin+length )+1) ); - + reader_super_highlight_me_plenty( data->buff_pos, 0 ); reader_repaint(); - + } void reader_handle_int( int sig ) { block_t *c = current_block; - + if( !is_interactive_read ) { while( c ) @@ -491,9 +491,9 @@ void reader_handle_int( int sig ) c=c->outer; } } - + interrupted = 1; - + } wchar_t *reader_current_filename() @@ -560,7 +560,7 @@ static int completion_cmp( const void *a, const void *b ) */ static void sort_completion_list( array_list_t *comp ) { - qsort( comp->arr, + qsort( comp->arr, al_get_count( comp ), sizeof( void*), &completion_cmp ); @@ -575,17 +575,17 @@ 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 ); @@ -635,8 +635,8 @@ void reader_write_title() if( strstr( n, "tty" ) || strstr( n, "/vc/") ) return; - - + + } title = function_exists( L"fish_title" )?L"fish_title":DEFAULT_TITLE; @@ -661,7 +661,7 @@ void reader_write_title() } } proc_pop_interactive(); - + al_foreach( &l, &free ); al_destroy( &l ); set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); @@ -676,11 +676,11 @@ static void exec_prompt() array_list_t prompt_list; al_init( &prompt_list ); - + if( data->prompt ) { proc_push_interactive( 0 ); - + if( exec_subshell( data->prompt, &prompt_list ) == -1 ) { /* If executing the prompt fails, make sure we at least don't print any junk */ @@ -690,11 +690,11 @@ static void exec_prompt() } proc_pop_interactive(); } - + reader_write_title(); - + sb_clear( &data->prompt_buff ); - + for( i=0; iprompt_buff, (wchar_t *)al_get( &prompt_list, i ) ); @@ -703,10 +703,10 @@ static void exec_prompt() sb_append( &data->prompt_buff, L"\n" ); } } - + al_foreach( &prompt_list, &free ); al_destroy( &prompt_list ); - + } void reader_init() @@ -716,7 +716,7 @@ void reader_init() memcpy( &saved_modes, &shell_modes, sizeof(saved_modes)); /* save a copy so we can reset the terminal later */ - + shell_modes.c_lflag &= ~ICANON; /* turn off canonical mode */ shell_modes.c_lflag &= ~ECHO; /* turn off echo mode */ shell_modes.c_cc[VMIN]=1; @@ -740,7 +740,7 @@ void reader_exit( int do_exit, int forced ) end_loop=do_exit; if( forced ) exit_forced = 1; - + } void reader_repaint_needed() @@ -789,14 +789,14 @@ static int insert_str(wchar_t *str) { int len = wcslen( str ); int old_len = data->buff_len; - + assert( data->buff_pos >= 0 ); assert( data->buff_pos <= data->buff_len ); assert( len >= 0 ); - + data->buff_len += len; check_size(); - + /* Insert space for extra characters at the right position */ if( data->buff_pos < old_len ) { @@ -807,13 +807,13 @@ static int insert_str(wchar_t *str) memmove( &data->buff[data->buff_pos], str, sizeof(wchar_t)*len ); data->buff_pos += len; data->buff[data->buff_len]='\0'; - + /* - Syntax highlight + Syntax highlight */ reader_super_highlight_me_plenty( data->buff_pos-1, 0 ); - + reader_repaint(); return 1; } @@ -827,7 +827,7 @@ static int insert_char( int c ) { wchar_t str[]= { - 0, 0 + 0, 0 } ; str[0] = c; @@ -881,7 +881,7 @@ static wchar_t get_quote( wchar_t *cmd, int len ) i++; if( !cmd[i] ) break; - i++; + i++; } else { @@ -1004,29 +1004,29 @@ static void completion_insert( const wchar_t *val, int flags ) int add_space = !(flags & COMPLETE_NO_SPACE); int do_replace = (flags & COMPLETE_NO_CASE); int do_escape = !(flags & COMPLETE_DONT_ESCAPE); - + // debug( 0, L"Insert completion %ls with flags %d", val, flags); if( do_replace ) { - + int tok_start, tok_len; wchar_t *begin, *end; string_buffer_t sb; wchar_t *escaped; - + parse_util_token_extent( data->buff, data->buff_pos, &begin, 0, 0, 0 ); end = data->buff+data->buff_pos; tok_start = begin - data->buff; tok_len = end-begin; - + sb_init( &sb ); sb_append_substring( &sb, data->buff, begin - data->buff ); - + if( do_escape ) { - escaped = escape( val, ESCAPE_ALL | ESCAPE_NO_QUOTED ); + escaped = escape( val, ESCAPE_ALL | ESCAPE_NO_QUOTED ); sb_append( &sb, escaped ); free( escaped ); } @@ -1034,28 +1034,28 @@ static void completion_insert( const wchar_t *val, int flags ) { sb_append( &sb, val ); } - - if( add_space ) + + if( add_space ) { sb_append( &sb, L" " ); } - + sb_append( &sb, end ); - + reader_set_buffer( (wchar_t *)sb.buff, (begin-data->buff)+wcslen(val)+!!add_space ); sb_destroy( &sb ); - + reader_super_highlight_me_plenty( data->buff_pos, 0 ); reader_repaint(); - + } else { - + if( do_escape ) { - + get_param( data->buff, data->buff_pos, "e, @@ -1071,7 +1071,7 @@ static void completion_insert( const wchar_t *val, int flags ) const wchar_t *pin; wchar_t *pout; - + replaced = pout = malloc( sizeof(wchar_t)*(wcslen(val) + 1) ); @@ -1106,20 +1106,20 @@ static void completion_insert( const wchar_t *val, int flags ) { replaced = wcsdup(val); } - + if( insert_str( replaced ) ) { /* - Print trailing space since this is the only completion + Print trailing space since this is the only completion */ - if( add_space ) + if( add_space ) { if( quote && - (data->buff[data->buff_pos] != quote ) ) + (data->buff[data->buff_pos] != quote ) ) { - /* - This is a quoted parameter, first print a quote + /* + This is a quoted parameter, first print a quote */ insert_char( quote ); } @@ -1128,9 +1128,9 @@ static void completion_insert( const wchar_t *val, int flags ) } free(replaced); - + } - + } /** @@ -1138,7 +1138,7 @@ static void completion_insert( const wchar_t *val, int flags ) fish_pager outputs any text, it is inserted into the input backbuffer. - \param prefix the string to display before every completion. + \param prefix the string to display before every completion. \param is_quoted should be set if the argument is quoted. This will change the display style. \param comp the list of completions to display */ @@ -1162,7 +1162,7 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp ) { prefix_esc = escape( prefix,1); } - + sb_init( &cmd ); sb_init( &msg ); sb_printf( &cmd, @@ -1177,13 +1177,13 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp ) in->fd = 3; escaped_separator = escape( COMPLETE_SEP_STR, 1); - + for( i=0; iflags & COMPLETE_NO_CASE ); } - + for( i=0; ibuff, data->buff_pos, &begin, 0, 0, 0 ); base_len = data->buff_pos - (begin-data->buff); } - + foo = escape( el->completion + base_len, ESCAPE_ALL | ESCAPE_NO_QUOTED ); } else @@ -1217,12 +1217,12 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp ) foo = escape( el->completion, ESCAPE_ALL | ESCAPE_NO_QUOTED ); } } - + if( el && el->description ) { baz = escape( el->description, 1 ); } - + if( !foo ) { debug( 0, L"Run pager called with bad argument." ); @@ -1231,33 +1231,33 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp ) } else if( baz ) { - sb_printf( &msg, L"%ls%ls%ls\n", + sb_printf( &msg, L"%ls%ls%ls\n", foo, escaped_separator, baz ); } else { - sb_printf( &msg, L"%ls\n", + sb_printf( &msg, L"%ls\n", foo ); } - free( foo ); - free( baz ); + free( foo ); + free( baz ); } - free( escaped_separator ); - + free( escaped_separator ); + foo = wcs2str( (wchar_t *)msg.buff ); b_append( in->param2.out_buffer, foo, strlen(foo) ); free( foo ); - + term_donate(); - + io_data_t *out = io_buffer_create( 0 ); out->next = in; out->fd = 4; - + eval( (wchar_t *)cmd.buff, out, TOP); term_steal(); @@ -1296,22 +1296,22 @@ static void reader_flash() struct timespec pollint; int i; - + for( i=0; ibuff_pos; i++ ) { data->color[i] = HIGHLIGHT_SEARCH_MATCH<<16; } - + reader_repaint(); - + pollint.tv_sec = 0; pollint.tv_nsec = 100 * 1000000; nanosleep( &pollint, NULL ); reader_super_highlight_me_plenty( data->buff_pos, 0 ); reader_repaint(); - - + + } /** @@ -1338,7 +1338,7 @@ int reader_can_replace( const wchar_t *in, int flags ) { return 1; } - + CHECK( in, 1 ); @@ -1357,7 +1357,7 @@ int reader_can_replace( const wchar_t *in, int flags ) /** Handle the list of completions. This means the following: - + - If the list is empty, flash the terminal. - If the list contains one element, write the whole element, and if the element does not end on a '/', '@', ':', or a '=', also write a trailing @@ -1366,7 +1366,7 @@ int reader_can_replace( const wchar_t *in, int flags ) the prefix. - If the list contains multiple elements without. a common prefix, call run_pager to display a list of completions. Depending on terminal size and the length of the list, run_pager may either show less than a screenfull and exit or use an interactive pager to allow the user to scroll through the completions. - + \param comp the list of completion strings */ @@ -1382,13 +1382,13 @@ static int handle_completions( array_list_t *comp ) int flags=0; wchar_t *begin, *end; wchar_t *tok; - + parse_util_token_extent( data->buff, data->buff_pos, &begin, 0, 0, 0 ); end = data->buff+data->buff_pos; - + context = halloc( 0, 0 ); tok = halloc_wcsndup( context, begin, end-begin ); - + /* Check trivial cases */ @@ -1409,9 +1409,9 @@ static int handle_completions( array_list_t *comp ) */ case 1: { - + completion_t *c = (completion_t *)al_get( comp, 0 ); - + /* If this is a replacement completion, check that we know how to replace it, e.g. that @@ -1421,15 +1421,15 @@ static int handle_completions( array_list_t *comp ) if( !(c->flags & COMPLETE_NO_CASE) || reader_can_replace( tok, c->flags ) ) { completion_insert( c->completion, - c->flags ); + c->flags ); } done = 1; len = 1; break; } } - - + + if( !done ) { /* @@ -1445,9 +1445,9 @@ static int handle_completions( array_list_t *comp ) */ if( c->flags & COMPLETE_NO_CASE ) continue; - + count++; - + if( base ) { new_len = comp_len( base, c->completion ); @@ -1474,8 +1474,8 @@ static int handle_completions( array_list_t *comp ) done = 1; } } - - + + if( !done && base == 0 ) { @@ -1487,9 +1487,9 @@ static int handle_completions( array_list_t *comp ) { int offset = wcslen( tok ); - + count = 0; - + for( i=0; iflags & COMPLETE_NO_CASE) ) continue; - + if( !reader_can_replace( tok, c->flags ) ) { len=0; @@ -1517,7 +1517,7 @@ static int handle_completions( array_list_t *comp ) base = wcsdup( c->completion ); len = wcslen( base ); flags = c->flags; - + } } @@ -1525,15 +1525,15 @@ static int handle_completions( array_list_t *comp ) { if( count > 1 ) flags = flags | COMPLETE_NO_SPACE; - + base[len]=L'\0'; completion_insert( base, flags ); done = 1; } - + } } - + free( base ); if( !done ) @@ -1581,9 +1581,9 @@ static int handle_completions( array_list_t *comp ) wchar_t quote; get_param( data->buff, data->buff_pos, "e, 0, 0, 0 ); is_quoted = (quote != L'\0'); - + write_loop(1, "\n", 1 ); - + run_pager( prefix, is_quoted, comp ); } @@ -1593,11 +1593,11 @@ static int handle_completions( array_list_t *comp ) } - + halloc_free( context ); return len; - + } @@ -1619,7 +1619,7 @@ static void reader_interactive_init() not enable it for us. */ - /* + /* Check if we are in control of the terminal, so that we don't do semi-expensive things like reset signal handlers unless we really have to, which we often don't. @@ -1628,7 +1628,7 @@ static void reader_interactive_init() { int block_count = 0; int i; - + /* Bummer, we are not in control of the terminal. Stop until parent has given us control of it. Stopping in fish is a bit @@ -1640,13 +1640,13 @@ static void reader_interactive_init() signal deliveries. In practice, this code should only be run suring startup, when we're not waiting for any signals. */ - while (signal_is_blocked()) + while (signal_is_blocked()) { signal_unblock(); block_count++; } signal_reset_handlers(); - + /* Ok, signal handlers are taken out of the picture. Stop ourself in a loop until we are in control of the terminal. @@ -1655,16 +1655,16 @@ static void reader_interactive_init() { killpg( shell_pgid, SIGTTIN); } - + signal_set_handlers(); - for( i=0; ibuff, data->buff_pos, &begin, &end, 0, 0 ); - + sb_clear( &data->search_buff ); if( begin ) { @@ -1870,11 +1870,11 @@ static void handle_token_history( int forward, int reset ) if( current_pos == -1 ) { const wchar_t *item; - + /* Move to previous line */ - free( (void *)data->token_history_buff ); + free( (void *)data->token_history_buff ); /* Search for previous item that contains this substring @@ -1989,12 +1989,12 @@ static void move_word( int dir, int erase, int new ) { return; } - + if( dir && data->buff_pos == data->buff_len ) { return; } - + /* If we are beyond the last character and moving left, start by moving one step, since otehrwise we'll start on the \0, which @@ -2004,10 +2004,10 @@ static void move_word( int dir, int erase, int new ) { if( !end_buff_pos ) return; - + end_buff_pos--; } - + /* When moving left, ignore the character under the cursor */ @@ -2015,7 +2015,7 @@ static void move_word( int dir, int erase, int new ) { end_buff_pos+=2*step; } - + /* Remove all whitespace characters before finding a word */ @@ -2039,26 +2039,26 @@ static void move_word( int dir, int erase, int new ) */ if( end_buff_pos != data->buff_pos ) { - + c = data->buff[end_buff_pos]; - + if( !iswspace( c ) ) { break; } } - + end_buff_pos+=step; } - + /* Remove until we find a character that is not alphanumeric */ while( 1 ) { wchar_t c; - + if( !dir ) { if( end_buff_pos <= 0 ) @@ -2069,9 +2069,9 @@ static void move_word( int dir, int erase, int new ) if( end_buff_pos >= data->buff_len ) break; } - + c = data->buff[end_buff_pos]; - + if( !iswalnum( c ) ) { /* @@ -2097,7 +2097,7 @@ static void move_word( int dir, int erase, int new ) Make sure we don't move beyond begining or end of buffer */ end_buff_pos = maxi( 0, mini( end_buff_pos, data->buff_len ) ); - + if( erase ) @@ -2105,9 +2105,9 @@ static void move_word( int dir, int erase, int new ) int remove_count = abs(data->buff_pos - end_buff_pos); int first_char = mini( data->buff_pos, end_buff_pos ); // fwprintf( stderr, L"Remove from %d to %d\n", first_char, first_char+remove_count ); - + reader_kill( data->buff + first_char, remove_count, dir?KILL_APPEND:KILL_PREPEND, new ); - + } else { @@ -2232,7 +2232,7 @@ void reader_run_command( const wchar_t *cmd ) int reader_shell_test( wchar_t *b ) { int res = parser_test( b, 0, 0, 0 ); - + if( res & PARSER_TEST_ERROR ) { string_buffer_t sb; @@ -2240,9 +2240,9 @@ int reader_shell_test( wchar_t *b ) int tmp[1]; int tmp2[1]; - + s_write( &data->screen, L"", L"", tmp, tmp2, 0 ); - + parser_test( b, 0, &sb, L"fish" ); fwprintf( stderr, L"%ls", sb.buff ); sb_destroy( &sb ); @@ -2268,7 +2268,7 @@ void reader_push( wchar_t *name ) { DIE_MEM(); } - + n->name = wcsdup( name ); n->next = data; sb_init( &n->kill_item ); @@ -2318,7 +2318,7 @@ void reader_pop() free( n->indent ); sb_destroy( &n->search_buff ); sb_destroy( &n->kill_item ); - + s_destroy( &n->screen ); sb_destroy( &n->prompt_buff ); @@ -2419,9 +2419,9 @@ static void handle_end_loop() int job_count=0; int is_breakpoint=0; block_t *b; - - for( b = current_block; - b; + + for( b = current_block; + b; b = b->outer ) { if( b->type == BREAKPOINT ) @@ -2430,7 +2430,7 @@ static void handle_end_loop() break; } } - + for( j=first_job; j; j=j->next ) { if( !job_is_completed(j) ) @@ -2439,11 +2439,11 @@ static void handle_end_loop() break; } } - + if( !reader_exit_forced() && !data->prev_end_loop && job_count && !is_breakpoint ) { writestr(_( L"There are stopped jobs. A second attempt to exit will enforce their termination.\n" )); - + reader_exit( 0, 0 ); data->prev_end_loop=1; } @@ -2454,13 +2454,13 @@ static void handle_end_loop() /* We already know that stdin is a tty since we're in interactive mode. If isatty returns false, it - means stdin must have been closed. + means stdin must have been closed. */ for( j = first_job; j; j=j->next ) { if( ! job_is_completed( j ) ) { - job_signal( j, SIGHUP ); + job_signal( j, SIGHUP ); } } } @@ -2476,12 +2476,12 @@ static void handle_end_loop() static int read_i() { event_fire_generic(L"fish_prompt"); - + reader_push(L"fish"); reader_set_complete_function( &complete ); reader_set_highlight_function( &highlight_shell ); reader_set_test_function( &reader_shell_test ); - + data->prev_end_loop=0; while( (!data->end_loop) && (!sanity_check()) ) @@ -2499,9 +2499,9 @@ static int read_i() during evaluation. */ - + tmp = reader_readline(); - + if( data->end_loop) { @@ -2510,7 +2510,7 @@ static int read_i() else if( tmp ) { tmp = wcsdup( tmp ); - + data->buff_pos=data->buff_len=0; data->buff[data->buff_len]=L'\0'; reader_run_command( tmp ); @@ -2524,7 +2524,7 @@ static int read_i() data->prev_end_loop=0; } } - + } reader_pop(); @@ -2562,12 +2562,12 @@ static int is_backslashed( const wchar_t *str, int pos ) { int count = 0; int i; - + for( i=pos-1; i>=0; i-- ) { if( str[i] != L'\\' ) break; - + count++; } @@ -2591,19 +2591,19 @@ wchar_t *reader_readline() sb_clear( &data->search_buff ); data->buff[data->buff_len]='\0'; data->search_mode = NO_SEARCH; - - + + exec_prompt(); reader_super_highlight_me_plenty( data->buff_pos, 0 ); s_reset( &data->screen, 1 ); reader_repaint(); - /* + /* get the current terminal modes. These will be restored when the function returns. */ - tcgetattr(0,&old_modes); + tcgetattr(0,&old_modes); /* set the new modes */ if( tcsetattr(0,TCSANOW,&shell_modes)) { @@ -2613,7 +2613,7 @@ wchar_t *reader_readline() while( !finished && !data->end_loop) { int regular_char = 0; - + /* Sometimes strange input sequences seem to generate a zero byte. I believe these simply mean a character was pressed @@ -2626,7 +2626,7 @@ wchar_t *reader_readline() is_interactive_read = 1; c=input_readch(); is_interactive_read = was_interactive_read; - + if( ( (!wchar_private(c))) && (c>31) && (c != 127) ) { if( can_read(0) ) @@ -2673,36 +2673,36 @@ wchar_t *reader_readline() */ if( last_char != R_YANK && last_char != R_YANK_POP ) yank=0; - + switch( c ) { /* go to beginning of line*/ case R_BEGINNING_OF_LINE: { - while( ( data->buff_pos>0 ) && + while( ( data->buff_pos>0 ) && ( data->buff[data->buff_pos-1] != L'\n' ) ) { data->buff_pos--; } - + reader_repaint(); break; } case R_END_OF_LINE: { - while( data->buff[data->buff_pos] && + while( data->buff[data->buff_pos] && data->buff[data->buff_pos] != L'\n' ) { data->buff_pos++; } - + reader_repaint(); break; } - + case R_BEGINNING_OF_BUFFER: { data->buff_pos = 0; @@ -2724,7 +2724,7 @@ wchar_t *reader_readline() { if( data->repaint_needed ) reader_repaint(); - + break; } @@ -2762,26 +2762,26 @@ wchar_t *reader_readline() parse_util_cmdsubst_extent( data->buff, data->buff_pos, &begin, &end ); parse_util_token_extent( begin, data->buff_pos - (begin-data->buff), &token_begin, &token_end, 0, 0 ); - + cursor_steps = token_end - data->buff- data->buff_pos; data->buff_pos += cursor_steps; if( is_backslashed( data->buff, data->buff_pos ) ) { remove_backward(); } - + reader_repaint(); - + len = data->buff_pos - (begin-data->buff); buffcpy = wcsndup( begin, len ); comp = al_halloc( 0 ); data->complete_func( buffcpy, comp ); - + sort_completion_list( comp ); remove_duplicates( comp ); - + free( buffcpy ); comp_empty = handle_completions( comp ); @@ -2799,20 +2799,20 @@ wchar_t *reader_readline() wchar_t *begin = &data->buff[data->buff_pos]; wchar_t *end = begin; int len; - + while( *end && *end != L'\n' ) end++; - + if( end==begin && *end ) end++; - + len = end-begin; - + if( len ) { reader_kill( begin, len, KILL_APPEND, last_char!=R_KILL_LINE ); } - + break; } @@ -2823,18 +2823,18 @@ wchar_t *reader_readline() wchar_t *end = &data->buff[data->buff_pos]; wchar_t *begin = end; int len; - + while( begin > data->buff && *begin != L'\n' ) begin--; - + if( *begin == L'\n' ) begin++; - + len = maxi( end-begin, 1 ); begin = end - len; - - reader_kill( begin, len, KILL_PREPEND, last_char!=R_BACKWARD_KILL_LINE ); - + + reader_kill( begin, len, KILL_PREPEND, last_char!=R_BACKWARD_KILL_LINE ); + } break; @@ -2845,29 +2845,29 @@ wchar_t *reader_readline() wchar_t *end = &data->buff[data->buff_pos]; wchar_t *begin = end; int len; - + while( begin > data->buff && *begin != L'\n' ) begin--; - + if( *begin == L'\n' ) begin++; - + len = maxi( end-begin, 0 ); begin = end - len; while( *end && *end != L'\n' ) end++; - + if( begin == end && *end ) end++; - + len = end-begin; - + if( len ) { - reader_kill( begin, len, KILL_APPEND, last_char!=R_KILL_WHOLE_LINE ); + reader_kill( begin, len, KILL_APPEND, last_char!=R_KILL_WHOLE_LINE ); } - + break; } @@ -2901,7 +2901,7 @@ wchar_t *reader_readline() if( data->search_mode ) { data->search_mode= NO_SEARCH; - + if( data->token_history_pos==-1 ) { history_reset(); @@ -2915,7 +2915,7 @@ wchar_t *reader_readline() sb_clear( &data->search_buff ); reader_super_highlight_me_plenty( data->buff_pos, 0 ); reader_repaint(); - + } break; @@ -2958,7 +2958,7 @@ wchar_t *reader_readline() insert_char( '\n' ); break; } - + switch( data->test_func( data->buff ) ) { @@ -2977,12 +2977,12 @@ wchar_t *reader_readline() reader_repaint(); break; } - + /* We are incomplete, continue editing */ case PARSER_TEST_INCOMPLETE: - { + { insert_char( '\n' ); break; } @@ -3000,7 +3000,7 @@ wchar_t *reader_readline() } } - + break; } @@ -3011,7 +3011,7 @@ wchar_t *reader_readline() case R_HISTORY_TOKEN_SEARCH_FORWARD: { int reset = 0; - + if( data->search_mode == NO_SEARCH ) { reset = 1; @@ -3024,7 +3024,7 @@ wchar_t *reader_readline() { data->search_mode = TOKEN_SEARCH; } - + sb_append( &data->search_buff, data->buff ); } @@ -3034,7 +3034,7 @@ wchar_t *reader_readline() case LINE_SEARCH: { const wchar_t *it = 0; - + if( ( c == R_HISTORY_SEARCH_BACKWARD ) || ( c == R_HISTORY_TOKEN_SEARCH_BACKWARD ) ) { @@ -3044,12 +3044,12 @@ wchar_t *reader_readline() { it = history_next_match((wchar_t *)data->search_buff.buff); } - + handle_history( it ); - + break; } - + case TOKEN_SEARCH: { if( ( c == R_HISTORY_SEARCH_BACKWARD ) || @@ -3061,10 +3061,10 @@ wchar_t *reader_readline() { handle_token_history( SEARCH_FORWARD, reset ); } - + break; } - + } break; } @@ -3080,13 +3080,13 @@ wchar_t *reader_readline() } break; } - + /* Move right*/ case R_FORWARD_CHAR: { if( data->buff_pos < data->buff_len ) { - data->buff_pos++; + data->buff_pos++; reader_repaint(); } break; @@ -3138,49 +3138,49 @@ wchar_t *reader_readline() int line_old = parse_util_get_line_from_offset( data->buff, data->buff_pos ); int line_new; - + if( c == R_UP_LINE ) line_new = line_old-1; else line_new = line_old+1; - + int line_count = parse_util_lineno( data->buff, data->buff_len )-1; - + if( line_new >= 0 && line_new <= line_count) { int base_pos_new; int base_pos_old; - + int indent_old; int indent_new; int line_offset_old; int total_offset_new; - base_pos_new = parse_util_get_offset_from_line( data->buff, + base_pos_new = parse_util_get_offset_from_line( data->buff, line_new ); - base_pos_old = parse_util_get_offset_from_line( data->buff, + base_pos_old = parse_util_get_offset_from_line( data->buff, line_old ); - - + + indent_old = data->indent[base_pos_old]; indent_new = data->indent[base_pos_new]; - + line_offset_old = data->buff_pos - parse_util_get_offset_from_line( data->buff, line_old ); total_offset_new = parse_util_get_offset( data->buff, line_new, line_offset_old - 4*(indent_new-indent_old)); data->buff_pos = total_offset_new; reader_repaint(); } - + break; } - + /* Other, if a normal character, we add it to the command */ default: { - + if( (!wchar_private(c)) && (( (c>31) || (c==L'\n'))&& (c != 127)) ) { regular_char = 1; @@ -3199,7 +3199,7 @@ wchar_t *reader_readline() } } - + if( (c != R_HISTORY_SEARCH_BACKWARD) && (c != R_HISTORY_SEARCH_FORWARD) && (c != R_HISTORY_TOKEN_SEARCH_BACKWARD) && @@ -3211,7 +3211,7 @@ wchar_t *reader_readline() history_reset(); data->token_history_pos=-1; } - + last_char = c; } @@ -3226,10 +3226,10 @@ wchar_t *reader_readline() { wperror(L"tcsetattr"); } - + set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); } - + return finished ? data->buff : 0; } @@ -3239,8 +3239,8 @@ int reader_search_mode() { return -1; } - - return !!data->search_mode; + + return !!data->search_mode; } @@ -3278,18 +3278,18 @@ static int read_ni( int fd, io_data_t *io ) int c; c = fread(buff, 1, 4096, in_stream); - + if( ferror( in_stream ) && ( errno != EINTR ) ) { debug( 1, _( L"Error while reading from file descriptor" ) ); - + /* Reset buffer on error. We won't evaluate incomplete files. */ acc.used=0; break; - + } b_append( &acc, buff, c ); @@ -3311,7 +3311,7 @@ static int read_ni( int fd, io_data_t *io ) { string_buffer_t sb; sb_init( &sb ); - + if( !parser_test( str, 0, &sb, L"fish" ) ) { eval( str, io, TOP ); @@ -3322,7 +3322,7 @@ static int read_ni( int fd, io_data_t *io ) res = 1; } sb_destroy( &sb ); - + free( str ); } else @@ -3365,7 +3365,7 @@ int reader_read( int fd, io_data_t *io ) int inter = ((fd == STDIN_FILENO) && isatty(STDIN_FILENO)); proc_push_interactive( inter ); - + res= is_interactive?read_i():read_ni( fd, io ); /* @@ -3375,7 +3375,7 @@ int reader_read( int fd, io_data_t *io ) if( data ) data->end_loop = 0; end_loop = 0; - + proc_pop_interactive(); return res; } -- cgit v1.2.3