From e0899addcb171577516ad168f06aa2545c299d78 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 26 Oct 2006 06:36:08 +1000 Subject: [PATCH] Minor cleanups and improved error checking in reader code darcs-hash:20061025203608-ac50b-213edeb462eaabce849d9cd13ffc30879e810bb8.gz --- reader.c | 25 +++++++++++++++---------- reader.h | 1 - 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/reader.c b/reader.c index cf4e5affe..0ee77b68b 100644 --- a/reader.c +++ b/reader.c @@ -361,6 +361,9 @@ int reader_exit_forced() return exit_forced; } +/** + Internal helper function for handling killing parts of text. +*/ static void reader_kill( wchar_t *begin, int length, int mode, int new ) { if( new ) @@ -642,7 +645,7 @@ void reader_exit( int do_exit, int forced ) void repaint() { parser_test( data->buff, data->indent, 0, 0 ); - + s_write( &data->screen, (wchar_t *)data->prompt_buff.buff, data->buff, @@ -1286,13 +1289,16 @@ void reader_replace_current_token( wchar_t *new_token ) */ static void handle_history( const wchar_t *new_str ) { - data->buff_len = wcslen( new_str ); - check_size(); - wcscpy( data->buff, new_str ); - data->buff_pos=wcslen(data->buff); - reader_super_highlight_me_plenty( data->buff_pos, 0 ); + if( new_str ) + { + data->buff_len = wcslen( new_str ); + check_size(); + wcscpy( data->buff, new_str ); + data->buff_pos=wcslen(data->buff); + reader_super_highlight_me_plenty( data->buff_pos, 0 ); - repaint(); + repaint(); + } } /** @@ -1840,7 +1846,6 @@ static void reader_super_highlight_me_plenty( int match_highlight_pos, array_lis int start = match-data->buff; int count = wcslen(data->search_buff ); int i; -// fwprintf( stderr, L"WEE color from %d to %d\n", start, start+count ); for( i=0; iprompt_width=60; data->prev_end_loop=0; while( (!data->end_loop) && (!sanity_check()) ) @@ -1980,7 +1984,8 @@ wchar_t *reader_readline() reader_super_highlight_me_plenty( data->buff_pos, 0 ); repaint(); - tcgetattr(0,&old_modes); /* get the current terminal modes */ + /* get the current terminal modes. These will be restored when the function returns. */ + tcgetattr(0,&old_modes); if( tcsetattr(0,TCSANOW,&shell_modes)) /* set the new modes */ { wperror(L"tcsetattr"); diff --git a/reader.h b/reader.h index 9bd0223c4..f20c2aeb2 100644 --- a/reader.h +++ b/reader.h @@ -167,5 +167,4 @@ void reader_handle_int( int signal ); */ int reader_exit_forced(); - #endif