Minor cleanups and improved error checking in reader code

darcs-hash:20061025203608-ac50b-213edeb462eaabce849d9cd13ffc30879e810bb8.gz
This commit is contained in:
axel 2006-10-26 06:36:08 +10:00
parent c627509e59
commit e0899addcb
2 changed files with 15 additions and 11 deletions

View file

@ -361,6 +361,9 @@ int reader_exit_forced()
return 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 ) static void reader_kill( wchar_t *begin, int length, int mode, int new )
{ {
if( new ) if( new )
@ -642,7 +645,7 @@ void reader_exit( int do_exit, int forced )
void repaint() void repaint()
{ {
parser_test( data->buff, data->indent, 0, 0 ); parser_test( data->buff, data->indent, 0, 0 );
s_write( &data->screen, s_write( &data->screen,
(wchar_t *)data->prompt_buff.buff, (wchar_t *)data->prompt_buff.buff,
data->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 ) static void handle_history( const wchar_t *new_str )
{ {
data->buff_len = wcslen( new_str ); if( new_str )
check_size(); {
wcscpy( data->buff, new_str ); data->buff_len = wcslen( new_str );
data->buff_pos=wcslen(data->buff); check_size();
reader_super_highlight_me_plenty( data->buff_pos, 0 ); 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 start = match-data->buff;
int count = wcslen(data->search_buff ); int count = wcslen(data->search_buff );
int i; int i;
// fwprintf( stderr, L"WEE color from %d to %d\n", start, start+count );
for( i=0; i<count; i++ ) for( i=0; i<count; i++ )
{ {
@ -1871,7 +1876,6 @@ static int read_i()
reader_set_highlight_function( &highlight_shell ); reader_set_highlight_function( &highlight_shell );
reader_set_test_function( &shell_test ); reader_set_test_function( &shell_test );
// data->prompt_width=60;
data->prev_end_loop=0; data->prev_end_loop=0;
while( (!data->end_loop) && (!sanity_check()) ) while( (!data->end_loop) && (!sanity_check()) )
@ -1980,7 +1984,8 @@ wchar_t *reader_readline()
reader_super_highlight_me_plenty( data->buff_pos, 0 ); reader_super_highlight_me_plenty( data->buff_pos, 0 );
repaint(); 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 */ if( tcsetattr(0,TCSANOW,&shell_modes)) /* set the new modes */
{ {
wperror(L"tcsetattr"); wperror(L"tcsetattr");

View file

@ -167,5 +167,4 @@ void reader_handle_int( int signal );
*/ */
int reader_exit_forced(); int reader_exit_forced();
#endif #endif