diff --git a/parser.c b/parser.c index a8c3d6124..599a01f73 100644 --- a/parser.c +++ b/parser.c @@ -223,6 +223,7 @@ typedef struct int block_count( block_t *b ) { + if( b==0) return 0; return( block_count(b->outer)+1); diff --git a/reader.c b/reader.c index f755f50b1..2cd274a1b 100644 --- a/reader.c +++ b/reader.c @@ -76,8 +76,8 @@ commence. #include "signal.h" /** - Maximum length of prefix string when printing completion - list. Longer prefixes will be ellipsized. + Maximum length of prefix string when printing completion + list. Longer prefixes will be ellipsized. */ #define PREFIX_MAX_LEN 8 @@ -128,7 +128,7 @@ typedef struct reader_data */ wchar_t *search_buff; /** - Saved position used by token history search + Saved position used by token history search */ int token_history_pos; @@ -160,12 +160,12 @@ typedef struct reader_data size_t buff_len; /** - The current position of the cursor in buff. + The current position of the cursor in buff. */ size_t buff_pos; /** - The current position of the cursor in output buffer. + The current position of the cursor in output buffer. */ size_t output_pos; @@ -219,7 +219,7 @@ typedef struct reader_data int (*test_func)( wchar_t * ); /** - When this is true, the reader will exit + When this is true, the reader will exit */ int end_loop; @@ -237,7 +237,7 @@ static reader_data_t *data=0; /** - Flag for ending non-interactive shell + Flag for ending non-interactive shell */ static int end_loop = 0; @@ -327,11 +327,11 @@ static void term_steal() common_handle_winch(0 ); - if( tcsetattr(0,TCSANOW,&old_modes)) /* return to previous mode */ - { - wperror(L"tcsetattr"); - exit(1); - } + if( tcsetattr(0,TCSANOW,&old_modes))/* return to previous mode */ + { + wperror(L"tcsetattr"); + exit(1); + } } @@ -672,27 +672,27 @@ static int calc_prompt_width( array_list_t *arr ) Test these color escapes with parameter value 0..7 */ char * esc[] = - { - set_a_foreground, - set_a_background, - set_foreground, - set_background, - } + { + set_a_foreground, + set_a_background, + set_foreground, + set_background, + } ; /* Test these regular escapes without any parameter values */ char *esc2[] = - { - enter_bold_mode, - exit_attribute_mode, - enter_underline_mode, - exit_underline_mode, - enter_standout_mode, - exit_standout_mode, - flash_screen - } + { + enter_bold_mode, + exit_attribute_mode, + enter_underline_mode, + exit_underline_mode, + enter_standout_mode, + exit_standout_mode, + flash_screen + } ; for( l=0; l < (sizeof(esc)/sizeof(char *)) && !found; l++ ) @@ -1080,8 +1080,8 @@ static int insert_char( int c ) enter_insert_mode) ) { /* - Colors look ok, so we set the right color and insert a - character + Colors look ok, so we set the right color and insert a + character */ set_color_translated( data->color[data->buff_pos-1] ); if( data->buff_pos < data->buff_len ) @@ -1488,8 +1488,8 @@ static int handle_completions( array_list_t *comp ) else { /* - There is no common prefix in the completions, and show_list - is true, so we print the list + There is no common prefix in the completions, and show_list + is true, so we print the list */ int len; wchar_t * prefix; @@ -1512,10 +1512,10 @@ static int handle_completions( array_list_t *comp ) else { wchar_t tmp[2]= - { - ellipsis_char, - 0 - } + { + ellipsis_char, + 0 + } ; prefix = wcsdupcat( tmp, @@ -1542,11 +1542,10 @@ static int handle_completions( array_list_t *comp ) succeeds with one column. */ /* -*/ + */ } free( prefix ); - repaint(); } @@ -2182,14 +2181,14 @@ static void move_word( int dir, int erase ) } break; /* - case 2: - if( !iswspace(data->buff[end_buff_pos] ) ) - { - mode++; - if( !dir ) - end_buff_pos-=step; - } - break; + case 2: + if( !iswspace(data->buff[end_buff_pos] ) ) + { + mode++; + if( !dir ) + end_buff_pos-=step; + } + break; */ } } @@ -2449,7 +2448,7 @@ static void reader_super_highlight_me_plenty( wchar_t * buff, int *color, int po for( i=0; i>8 == 0 ) { @@ -2574,8 +2573,8 @@ wchar_t *reader_readline() repaint(); tcgetattr(0,&old_modes); /* get the current terminal modes */ - if( tcsetattr(0,TCSANOW,&shell_modes)) /* set the new modes */ - { + if( tcsetattr(0,TCSANOW,&shell_modes)) /* set the new modes */ + { wperror(L"tcsetattr"); exit(1); } @@ -2765,14 +2764,16 @@ wchar_t *reader_readline() /* yank*/ case R_YANK: - yank_str = kill_yank(); + { yank_str = kill_yank(); insert_str( yank_str ); yank = wcslen( yank_str ); // wcscpy(data->search_buff,data->buff); break; - - /* rotate killring*/ + } + + /* rotate killring*/ case R_YANK_POP: + { if( yank ) { for( i=0; isearch_buff ) { if( data->token_history_pos==-1 ) @@ -2804,28 +2807,34 @@ wchar_t *reader_readline() } break; - - /* delete backward*/ + } + + /* delete backward*/ case R_BACKWARD_DELETE_CHAR: + { remove_backward(); break; - - /* delete forward*/ + } + + /* delete forward*/ case R_DELETE_CHAR: + { remove_forward(); break; - - /* exit, but only if line is empty */ + } + + /* exit, but only if line is empty or the previous keypress was also an exit call */ case R_EXIT: - + { if( data->buff_len == 0 ) { writestr( L"\n" ); data->end_loop=1; } break; - - /* Newline, evaluate*/ + } + + /* Newline, evaluate*/ case L'\n': { data->buff[data->buff_len]=L'\0'; @@ -2854,9 +2863,9 @@ wchar_t *reader_readline() break; } - /* History up*/ + /* History up */ case R_HISTORY_SEARCH_BACKWARD: -// fwprintf( stderr, L"Search history for \'%ls\' %d long\n", data->search_buff, wcslen(data->search_buff) ); + { if( (last_char != R_HISTORY_SEARCH_BACKWARD) && (last_char != R_HISTORY_SEARCH_FORWARD) ) { @@ -2866,9 +2875,11 @@ wchar_t *reader_readline() handle_history(history_prev_match(data->search_buff)); break; - - /* History down*/ + } + + /* History down */ case R_HISTORY_SEARCH_FORWARD: + { if( (last_char != R_HISTORY_SEARCH_BACKWARD) && (last_char != R_HISTORY_SEARCH_FORWARD) ) { @@ -2878,7 +2889,9 @@ wchar_t *reader_readline() handle_history(history_next_match(data->search_buff)); break; - + } + + /* Token search for a earlier match */ case R_HISTORY_TOKEN_SEARCH_BACKWARD: { int reset=0; @@ -2894,6 +2907,7 @@ wchar_t *reader_readline() break; } + /* Token search for a later match */ case R_HISTORY_TOKEN_SEARCH_FORWARD: { int reset=0; @@ -2910,7 +2924,6 @@ wchar_t *reader_readline() } - /* Move left*/ case R_BACKWARD_CHAR: if( data->buff_pos > 0 ) @@ -2930,6 +2943,7 @@ wchar_t *reader_readline() /* Move right*/ case R_FORWARD_CHAR: + { if( data->buff_pos < data->buff_len ) { if( !force_repaint() ) @@ -2946,33 +2960,45 @@ wchar_t *reader_readline() } } break; - + } + case R_DELETE_LINE: + { data->buff[0]=0; data->buff_len=0; data->buff_pos=0; repaint(); - - /* kill one word left */ + break; + } + + /* kill one word left */ case R_BACKWARD_KILL_WORD: + { move_word(0,1); break; - - /* kill one word right */ + } + + /* kill one word right */ case R_KILL_WORD: + { move_word(1,1); break; - - /* move one word left*/ + } + + /* move one word left*/ case R_BACKWARD_WORD: + { move_word(0,0); break; - - /* move one word right*/ + } + + /* move one word right*/ case R_FORWARD_WORD: + { move_word( 1,0); break; - + } + case R_CLEAR_SCREEN: { writembs( clear_screen ); @@ -2990,7 +3016,6 @@ wchar_t *reader_readline() case R_END_OF_HISTORY: { history_reset(); - break; } @@ -3145,9 +3170,9 @@ int reader_read( int fd ) { int res; /* - If reader_read is called recursively through the '.' builtin, - we need to preserve is_interactive, so we save the - original state. We also update the signal handlers. + If reader_read is called recursively through the '.' builtin, + we need to preserve is_interactive, so we save the + original state. We also update the signal handlers. */ int shell_was_interactive = is_interactive;