Additional warning fixes and migration from int to size_t or long where appropriate

This commit is contained in:
ridiculousfish 2012-08-04 13:47:56 -07:00
parent 7a46227141
commit 54ceb4211e
7 changed files with 228 additions and 287 deletions

View file

@ -61,7 +61,8 @@ static const wchar_t *current_buffer=0;
What the commandline builtin considers to be the current cursor What the commandline builtin considers to be the current cursor
position. position.
*/ */
static int current_cursor_pos = -1; static const size_t kInvalidCursorPosition = (size_t)(-1);
static size_t current_cursor_pos = kInvalidCursorPosition;
/** /**
Returns the current commandline buffer. Returns the current commandline buffer.
@ -74,7 +75,7 @@ static const wchar_t *get_buffer()
/** /**
Returns the position of the cursor Returns the position of the cursor
*/ */
static int get_cursor_pos() static size_t get_cursor_pos()
{ {
return current_cursor_pos; return current_cursor_pos;
} }
@ -94,7 +95,7 @@ static void replace_part( const wchar_t *begin,
int append_mode ) int append_mode )
{ {
const wchar_t *buff = get_buffer(); const wchar_t *buff = get_buffer();
long out_pos=get_cursor_pos(); size_t out_pos = get_cursor_pos();
wcstring out; wcstring out;
@ -127,7 +128,7 @@ static void replace_part( const wchar_t *begin,
} }
} }
out.append( end ); out.append( end );
reader_set_buffer( out, (size_t)out_pos ); reader_set_buffer( out, out_pos );
} }
/** /**
@ -222,12 +223,12 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer(); current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
if( current_buffer ) if( current_buffer )
{ {
current_cursor_pos = (int)wcslen( current_buffer ); current_cursor_pos = wcslen( current_buffer );
} }
else else
{ {
current_buffer = reader_get_buffer(); current_buffer = reader_get_buffer();
current_cursor_pos = (int)reader_get_cursor_pos(); current_cursor_pos = reader_get_cursor_pos();
} }
if( !get_buffer() ) if( !get_buffer() )
@ -387,7 +388,7 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
case 'I': case 'I':
current_buffer = woptarg; current_buffer = woptarg;
current_cursor_pos = (int)wcslen( woptarg ); current_cursor_pos = wcslen( woptarg );
break; break;
case 'C': case 'C':
@ -551,7 +552,7 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
} }
else else
{ {
append_format(stdout_buffer, L"%d\n", reader_get_cursor_pos() ); append_format(stdout_buffer, L"%lu\n", (unsigned long)reader_get_cursor_pos() );
return 0; return 0;
} }
@ -559,9 +560,9 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
if( line_mode ) if( line_mode )
{ {
int pos = reader_get_cursor_pos(); size_t pos = reader_get_cursor_pos();
const wchar_t *buff = reader_get_buffer(); const wchar_t *buff = reader_get_buffer();
append_format(stdout_buffer, L"%d\n", parse_util_lineno( buff, pos ) ); append_format(stdout_buffer, L"%lu\n", (unsigned long)parse_util_lineno( buff, pos ) );
return 0; return 0;
} }

View file

@ -51,53 +51,10 @@
*/ */
#define AUTOLOAD_MIN_AGE 60 #define AUTOLOAD_MIN_AGE 60
int parse_util_lineno( const wchar_t *str, size_t offset )
int parse_util_lineno( const wchar_t *str, int len )
{ {
/** int res = 0;
First cached state for( size_t i=0; str[i] && i<offset; i++ )
*/
static wchar_t *prev_str = 0;
static int i=0;
static int res = 1;
/**
Second cached state
*/
static wchar_t *prev_str2 = 0;
static int i2 = 0;
static int res2 = 1;
CHECK( str, 0 );
if( str != prev_str || i>len )
{
if( prev_str2 == str && i2 <= len )
{
wchar_t *tmp_str = prev_str;
int tmp_i = i;
int tmp_res = res;
prev_str = prev_str2;
i=i2;
res=res2;
prev_str2 = tmp_str;
i2 = tmp_i;
res2 = tmp_res;
}
else
{
prev_str2 = prev_str;
i2 = i;
res2=res;
prev_str = (wchar_t *)str;
i=0;
res=1;
}
}
for( ; str[i] && i<len; i++ )
{ {
if( str[i] == L'\n' ) if( str[i] == L'\n' )
{ {
@ -108,18 +65,11 @@ int parse_util_lineno( const wchar_t *str, int len )
} }
int parse_util_get_line_from_offset( const wcstring &str, int pos ) int parse_util_get_line_from_offset( const wcstring &str, size_t pos )
{ {
// return parse_util_lineno( buff, pos );
const wchar_t *buff = str.c_str(); const wchar_t *buff = str.c_str();
int i;
int count = 0; int count = 0;
if( pos < 0 ) for( size_t i=0; i<pos; i++ )
{
return -1;
}
for( i=0; i<pos; i++ )
{ {
if( !buff[i] ) if( !buff[i] )
{ {
@ -363,7 +313,7 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
Get the beginning and end of the job or process definition under the cursor Get the beginning and end of the job or process definition under the cursor
*/ */
static void job_or_process_extent( const wchar_t *buff, static void job_or_process_extent( const wchar_t *buff,
int cursor_pos, size_t cursor_pos,
const wchar_t **a, const wchar_t **a,
const wchar_t **b, const wchar_t **b,
int process ) int process )
@ -460,7 +410,7 @@ static void job_or_process_extent( const wchar_t *buff,
} }
void parse_util_process_extent( const wchar_t *buff, void parse_util_process_extent( const wchar_t *buff,
int pos, size_t pos,
const wchar_t **a, const wchar_t **a,
const wchar_t **b ) const wchar_t **b )
{ {
@ -468,7 +418,7 @@ void parse_util_process_extent( const wchar_t *buff,
} }
void parse_util_job_extent( const wchar_t *buff, void parse_util_job_extent( const wchar_t *buff,
int pos, size_t pos,
const wchar_t **a, const wchar_t **a,
const wchar_t **b ) const wchar_t **b )
{ {

View file

@ -53,7 +53,7 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
\param b the end of the searched string \param b the end of the searched string
*/ */
void parse_util_process_extent( const wchar_t *buff, void parse_util_process_extent( const wchar_t *buff,
int cursor_pos, size_t cursor_pos,
const wchar_t **a, const wchar_t **a,
const wchar_t **b ); const wchar_t **b );
@ -67,7 +67,7 @@ void parse_util_process_extent( const wchar_t *buff,
\param b the end of the searched string \param b the end of the searched string
*/ */
void parse_util_job_extent( const wchar_t *buff, void parse_util_job_extent( const wchar_t *buff,
int cursor_pos, size_t cursor_pos,
const wchar_t **a, const wchar_t **a,
const wchar_t **b ); const wchar_t **b );
@ -94,12 +94,12 @@ void parse_util_token_extent( const wchar_t *buff,
/** /**
Get the linenumber at the specified character offset Get the linenumber at the specified character offset
*/ */
int parse_util_lineno( const wchar_t *str, int len ); int parse_util_lineno( const wchar_t *str, size_t len );
/** /**
Calculate the line number of the specified cursor position Calculate the line number of the specified cursor position
*/ */
int parse_util_get_line_from_offset( const wcstring &str, int pos ); int parse_util_get_line_from_offset( const wcstring &str, size_t pos );
/** /**
Get the offset of the first character on the specified line Get the offset of the first character on the specified line

View file

@ -228,7 +228,7 @@ class reader_data_t
wcstring_list_t search_prev; wcstring_list_t search_prev;
/** The current position in search_prev */ /** The current position in search_prev */
int search_pos; size_t search_pos;
/** Length of the command */ /** Length of the command */
size_t command_length() const { return command_line.size(); } size_t command_length() const { return command_line.size(); }
@ -795,12 +795,10 @@ static int insert_char( wchar_t c )
/** /**
Calculate the length of the common prefix substring of two strings. Calculate the length of the common prefix substring of two strings.
*/ */
static int comp_len( const wchar_t *a, const wchar_t *b ) static size_t comp_len( const wchar_t *a, const wchar_t *b )
{ {
int i; size_t i;
for( i=0; for( i=0; a[i] != L'\0' && b[i] != L'\0' && a[i]==b[i]; i++ )
a[i] != '\0' && b[i] != '\0' && a[i]==b[i];
i++ )
; ;
return i; return i;
} }
@ -808,12 +806,10 @@ static int comp_len( const wchar_t *a, const wchar_t *b )
/** /**
Calculate the case insensitive length of the common prefix substring of two strings. Calculate the case insensitive length of the common prefix substring of two strings.
*/ */
static int comp_ilen( const wchar_t *a, const wchar_t *b ) static size_t comp_ilen( const wchar_t *a, const wchar_t *b )
{ {
int i; size_t i;
for( i=0; for( i=0; a[i] != L'\0' && b[i] != L'\0' && towlower(a[i])==towlower(b[i]); i++ )
a[i] != '\0' && b[i] != '\0' && towlower(a[i])==towlower(b[i]);
i++ )
; ;
return i; return i;
} }
@ -842,7 +838,7 @@ static wcstring completion_apply_to_command_line(const wcstring &val_str, int fl
if( do_replace ) if( do_replace )
{ {
int move_cursor; size_t move_cursor;
const wchar_t *begin, *end; const wchar_t *begin, *end;
wchar_t *escaped; wchar_t *escaped;
@ -974,7 +970,7 @@ static void run_pager( const wcstring &prefix, int is_quoted, const std::vector<
for( size_t i=0; i< comp.size(); i++ ) for( size_t i=0; i< comp.size(); i++ )
{ {
int base_len=-1; long base_len=-1;
const completion_t &el = comp.at( i ); const completion_t &el = comp.at( i );
wchar_t *foo=0; wchar_t *foo=0;
@ -1314,10 +1310,10 @@ static int reader_can_replace( const wcstring &in, int flags )
*/ */
static int handle_completions( const std::vector<completion_t> &comp ) static bool handle_completions( const std::vector<completion_t> &comp )
{ {
wchar_t *base = NULL; wchar_t *base = NULL;
int len = 0; size_t len = 0;
bool done = false; bool done = false;
int count = 0; int count = 0;
int flags=0; int flags=0;
@ -1379,7 +1375,7 @@ static int handle_completions( const std::vector<completion_t> &comp )
if( base ) if( base )
{ {
int new_len = comp_len( base, c.completion.c_str() ); size_t new_len = comp_len( base, c.completion.c_str() );
len = mini(new_len, len); len = mini(new_len, len);
} }
else else
@ -1410,15 +1406,13 @@ static int handle_completions( const std::vector<completion_t> &comp )
if( begin ) if( begin )
{ {
int offset = tok.size(); size_t offset = tok.size();
count = 0; count = 0;
for( size_t i=0; i< comp.size(); i++ ) for( size_t i=0; i< comp.size(); i++ )
{ {
const completion_t &c = comp.at( i ); const completion_t &c = comp.at( i );
int new_len;
if( !(c.flags & COMPLETE_NO_CASE) ) if( !(c.flags & COMPLETE_NO_CASE) )
continue; continue;
@ -1433,7 +1427,7 @@ static int handle_completions( const std::vector<completion_t> &comp )
if( base ) if( base )
{ {
new_len = offset + comp_ilen( base+offset, c.completion.c_str()+offset ); size_t new_len = offset + comp_ilen( base+offset, c.completion.c_str()+offset );
len = new_len < len ? new_len: len; len = new_len < len ? new_len: len;
} }
else else
@ -1499,9 +1493,7 @@ static int handle_completions( const std::vector<completion_t> &comp )
reader_repaint(); reader_repaint();
} }
return len; return len > 0;
} }
@ -1711,7 +1703,7 @@ static void handle_token_history( int forward, int reset )
return; return;
const wchar_t *str=0; const wchar_t *str=0;
int current_pos; long current_pos;
tokenizer tok; tokenizer tok;
if( reset ) if( reset )
@ -1726,7 +1718,7 @@ static void handle_token_history( int forward, int reset )
current_pos = data->token_history_pos; current_pos = data->token_history_pos;
if( forward || data->search_pos + 1 < (long)data->search_prev.size() ) if( forward || data->search_pos + 1 < data->search_prev.size() )
{ {
if( forward ) if( forward )
{ {
@ -1822,8 +1814,8 @@ static void handle_token_history( int forward, int reset )
reader_replace_current_token( str ); reader_replace_current_token( str );
reader_super_highlight_me_plenty( data->buff_pos ); reader_super_highlight_me_plenty( data->buff_pos );
reader_repaint(); reader_repaint();
data->search_pos = data->search_prev.size();
data->search_prev.push_back(str); data->search_prev.push_back(str);
data->search_pos = data->search_prev.size() - 1;
} }
else if( ! reader_interrupted() ) else if( ! reader_interrupted() )
{ {
@ -2011,10 +2003,10 @@ void reader_set_buffer( const wcstring &b, size_t pos )
} }
int reader_get_cursor_pos() size_t reader_get_cursor_pos()
{ {
if( !data ) if( !data )
return -1; return (size_t)(-1);
return data->buff_pos; return data->buff_pos;
} }
@ -2493,20 +2485,19 @@ static int wchar_private( wchar_t c )
Test if the specified character in the specified string is Test if the specified character in the specified string is
backslashed. backslashed.
*/ */
static int is_backslashed( const wchar_t *str, int pos ) static bool is_backslashed( const wchar_t *str, size_t pos )
{ {
int count = 0; size_t count = 0;
int i; size_t idx = pos;
while (idx--)
for( i=pos-1; i>=0; i-- )
{ {
if( str[i] != L'\\' ) if( str[idx] != L'\\' )
break; break;
count++; count++;
} }
return count %2; return (count % 2) == 1;
} }
@ -2514,11 +2505,11 @@ const wchar_t *reader_readline()
{ {
wint_t c; wint_t c;
int i; int last_char=0;
int last_char=0, yank=0; size_t yank_len=0;
const wchar_t *yank_str; const wchar_t *yank_str;
std::vector<completion_t> comp; std::vector<completion_t> comp;
int comp_empty=1; bool comp_empty = true;
int finished=0; int finished=0;
struct termios old_modes; struct termios old_modes;
@ -2533,9 +2524,9 @@ const wchar_t *reader_readline()
reader_repaint(); reader_repaint();
/* /*
get the current terminal modes. These will be restored when the get the current terminal modes. These will be restored when the
function returns. function returns.
*/ */
tcgetattr(0,&old_modes); tcgetattr(0,&old_modes);
/* set the new modes */ /* set the new modes */
if( tcsetattr(0,TCSANOW,&shell_modes)) if( tcsetattr(0,TCSANOW,&shell_modes))
@ -2546,11 +2537,11 @@ const wchar_t *reader_readline()
while( !finished && !data->end_loop) while( !finished && !data->end_loop)
{ {
/* /*
Sometimes strange input sequences seem to generate a zero Sometimes strange input sequences seem to generate a zero
byte. I believe these simply mean a character was pressed byte. I believe these simply mean a character was pressed
but it should be ignored. (Example: Trying to add a tilde but it should be ignored. (Example: Trying to add a tilde
(~) to digit) (~) to digit)
*/ */
while( 1 ) while( 1 )
{ {
int was_interactive_read = is_interactive_read; int was_interactive_read = is_interactive_read;
@ -2595,24 +2586,24 @@ const wchar_t *reader_readline()
if( c != 0 ) if( c != 0 )
break; break;
} }
/* /*
if( (last_char == R_COMPLETE) && (c != R_COMPLETE) && (!comp_empty) ) if( (last_char == R_COMPLETE) && (c != R_COMPLETE) && (!comp_empty) )
{ {
halloc_destroy( comp ); halloc_destroy( comp );
comp = 0; comp = 0;
} }
*/ */
if( last_char != R_YANK && last_char != R_YANK_POP ) if( last_char != R_YANK && last_char != R_YANK_POP )
yank=0; yank_len=0;
const wchar_t *buff = data->command_line.c_str(); const wchar_t *buff = data->command_line.c_str();
switch( c ) switch( c )
{ {
/* go to beginning of line*/ /* go to beginning of line*/
case R_BEGINNING_OF_LINE: case R_BEGINNING_OF_LINE:
{ {
while( ( data->buff_pos>0 ) && while( ( data->buff_pos>0 ) &&
( buff[data->buff_pos-1] != L'\n' ) ) ( buff[data->buff_pos-1] != L'\n' ) )
{ {
data->buff_pos--; data->buff_pos--;
} }
@ -2624,7 +2615,7 @@ const wchar_t *reader_readline()
case R_END_OF_LINE: case R_END_OF_LINE:
{ {
while( buff[data->buff_pos] && while( buff[data->buff_pos] &&
buff[data->buff_pos] != L'\n' ) buff[data->buff_pos] != L'\n' )
{ {
data->buff_pos++; data->buff_pos++;
} }
@ -2642,7 +2633,7 @@ const wchar_t *reader_readline()
break; break;
} }
/* go to EOL*/ /* go to EOL*/
case R_END_OF_BUFFER: case R_END_OF_BUFFER:
{ {
data->buff_pos = data->command_length(); data->buff_pos = data->command_length();
@ -2673,7 +2664,7 @@ const wchar_t *reader_readline()
break; break;
} }
/* complete */ /* complete */
case R_COMPLETE: case R_COMPLETE:
{ {
@ -2685,8 +2676,7 @@ const wchar_t *reader_readline()
const wchar_t *begin, *end; const wchar_t *begin, *end;
const wchar_t *token_begin, *token_end; const wchar_t *token_begin, *token_end;
const wchar_t *buff = data->command_line.c_str(); const wchar_t *buff = data->command_line.c_str();
int len; long cursor_steps;
int cursor_steps;
parse_util_cmdsubst_extent( buff, data->buff_pos, &begin, &end ); parse_util_cmdsubst_extent( buff, data->buff_pos, &begin, &end );
@ -2701,7 +2691,7 @@ const wchar_t *reader_readline()
reader_repaint(); reader_repaint();
len = data->buff_pos - (begin-buff); size_t len = data->buff_pos - (begin-buff);
const wcstring buffcpy = wcstring(begin, len); const wcstring buffcpy = wcstring(begin, len);
data->complete_func( buffcpy, comp, COMPLETE_DEFAULT, NULL); data->complete_func( buffcpy, comp, COMPLETE_DEFAULT, NULL);
@ -2716,7 +2706,7 @@ const wchar_t *reader_readline()
break; break;
} }
/* kill */ /* kill */
case R_KILL_LINE: case R_KILL_LINE:
{ {
const wchar_t *buff = data->command_line.c_str(); const wchar_t *buff = data->command_line.c_str();
@ -2794,31 +2784,31 @@ const wchar_t *reader_readline()
break; break;
} }
/* yank*/ /* yank*/
case R_YANK: case R_YANK:
{ {
yank_str = kill_yank(); yank_str = kill_yank();
insert_string( yank_str ); insert_string( yank_str );
yank = wcslen( yank_str ); yank_len = wcslen( yank_str );
break; break;
} }
/* rotate killring*/ /* rotate killring*/
case R_YANK_POP: case R_YANK_POP:
{ {
if( yank ) if( yank_len )
{ {
for( i=0; i<yank; i++ ) for( size_t i=0; i<yank_len; i++ )
remove_backward(); remove_backward();
yank_str = kill_yank_rotate(); yank_str = kill_yank_rotate();
insert_string(yank_str); insert_string(yank_str);
yank = wcslen(yank_str); yank_len = wcslen(yank_str);
} }
break; break;
} }
/* Escape was pressed */ /* Escape was pressed */
case L'\x1b': case L'\x1b':
{ {
if( data->search_mode ) if( data->search_mode )
@ -2844,20 +2834,20 @@ const wchar_t *reader_readline()
break; break;
} }
/* delete backward*/ /* delete backward*/
case R_BACKWARD_DELETE_CHAR: case R_BACKWARD_DELETE_CHAR:
{ {
remove_backward(); remove_backward();
break; break;
} }
/* delete forward*/ /* delete forward*/
case R_DELETE_CHAR: case R_DELETE_CHAR:
{ {
/** /**
Remove the current character in the character buffer and on the Remove the current character in the character buffer and on the
screen using syntax highlighting, etc. screen using syntax highlighting, etc.
*/ */
if( data->buff_pos < data->command_length() ) if( data->buff_pos < data->command_length() )
{ {
data->buff_pos++; data->buff_pos++;
@ -2866,19 +2856,19 @@ const wchar_t *reader_readline()
break; break;
} }
/* /*
Evaluate. If the current command is unfinished, or if Evaluate. If the current command is unfinished, or if
the charater is escaped using a backslash, insert a the charater is escaped using a backslash, insert a
newline newline
*/ */
case R_EXECUTE: case R_EXECUTE:
{ {
/* Delete any autosuggestion */ /* Delete any autosuggestion */
data->autosuggestion.clear(); data->autosuggestion.clear();
/* /*
Allow backslash-escaped newlines Allow backslash-escaped newlines
*/ */
if( is_backslashed( data->command_line.c_str(), data->buff_pos ) ) if( is_backslashed( data->command_line.c_str(), data->buff_pos ) )
{ {
insert_char( '\n' ); insert_char( '\n' );
@ -2891,8 +2881,8 @@ const wchar_t *reader_readline()
case 0: case 0:
{ {
/* /*
Finished commend, execute it Finished commend, execute it
*/ */
if( ! data->command_line.empty() ) if( ! data->command_line.empty() )
{ {
if (data->history) { if (data->history) {
@ -2905,20 +2895,20 @@ const wchar_t *reader_readline()
break; break;
} }
/* /*
We are incomplete, continue editing We are incomplete, continue editing
*/ */
case PARSER_TEST_INCOMPLETE: case PARSER_TEST_INCOMPLETE:
{ {
insert_char( '\n' ); insert_char( '\n' );
break; break;
} }
/* /*
Result must be some combination including an Result must be some combination including an
error. The error message will already be error. The error message will already be
printed, all we need to do is repaint printed, all we need to do is repaint
*/ */
default: default:
{ {
s_reset( &data->screen, true); s_reset( &data->screen, true);
@ -2931,7 +2921,7 @@ const wchar_t *reader_readline()
break; break;
} }
/* History functions */ /* History functions */
case R_HISTORY_SEARCH_BACKWARD: case R_HISTORY_SEARCH_BACKWARD:
case R_HISTORY_TOKEN_SEARCH_BACKWARD: case R_HISTORY_TOKEN_SEARCH_BACKWARD:
case R_HISTORY_SEARCH_FORWARD: case R_HISTORY_SEARCH_FORWARD:
@ -2943,7 +2933,7 @@ const wchar_t *reader_readline()
{ {
reset = 1; reset = 1;
if( ( c == R_HISTORY_SEARCH_BACKWARD ) || if( ( c == R_HISTORY_SEARCH_BACKWARD ) ||
( c == R_HISTORY_SEARCH_FORWARD ) ) ( c == R_HISTORY_SEARCH_FORWARD ) )
{ {
data->search_mode = LINE_SEARCH; data->search_mode = LINE_SEARCH;
} }
@ -2968,7 +2958,7 @@ const wchar_t *reader_readline()
case LINE_SEARCH: case LINE_SEARCH:
{ {
if( ( c == R_HISTORY_SEARCH_BACKWARD ) || if( ( c == R_HISTORY_SEARCH_BACKWARD ) ||
( c == R_HISTORY_TOKEN_SEARCH_BACKWARD ) ) ( c == R_HISTORY_TOKEN_SEARCH_BACKWARD ) )
{ {
data->history_search.go_backwards(); data->history_search.go_backwards();
} }
@ -2994,7 +2984,7 @@ const wchar_t *reader_readline()
case TOKEN_SEARCH: case TOKEN_SEARCH:
{ {
if( ( c == R_HISTORY_SEARCH_BACKWARD ) || if( ( c == R_HISTORY_SEARCH_BACKWARD ) ||
( c == R_HISTORY_TOKEN_SEARCH_BACKWARD ) ) ( c == R_HISTORY_TOKEN_SEARCH_BACKWARD ) )
{ {
handle_token_history( SEARCH_BACKWARD, reset ); handle_token_history( SEARCH_BACKWARD, reset );
} }
@ -3011,7 +3001,7 @@ const wchar_t *reader_readline()
} }
/* Move left*/ /* Move left*/
case R_BACKWARD_CHAR: case R_BACKWARD_CHAR:
{ {
if( data->buff_pos > 0 ) if( data->buff_pos > 0 )
@ -3022,7 +3012,7 @@ const wchar_t *reader_readline()
break; break;
} }
/* Move right*/ /* Move right*/
case R_FORWARD_CHAR: case R_FORWARD_CHAR:
{ {
if( data->buff_pos < data->command_length() ) if( data->buff_pos < data->command_length() )
@ -3035,28 +3025,28 @@ const wchar_t *reader_readline()
break; break;
} }
/* kill one word left */ /* kill one word left */
case R_BACKWARD_KILL_WORD: case R_BACKWARD_KILL_WORD:
{ {
move_word(0,1, last_char!=R_BACKWARD_KILL_WORD); move_word(0,1, last_char!=R_BACKWARD_KILL_WORD);
break; break;
} }
/* kill one word right */ /* kill one word right */
case R_KILL_WORD: case R_KILL_WORD:
{ {
move_word(1,1, last_char!=R_KILL_WORD); move_word(1,1, last_char!=R_KILL_WORD);
break; break;
} }
/* move one word left*/ /* move one word left*/
case R_BACKWARD_WORD: case R_BACKWARD_WORD:
{ {
move_word(0,0,0); move_word(0,0,0);
break; break;
} }
/* move one word right*/ /* move one word right*/
case R_FORWARD_WORD: case R_FORWARD_WORD:
{ {
move_word( 1,0,0); move_word( 1,0,0);
@ -3084,7 +3074,7 @@ const wchar_t *reader_readline()
case R_UP_LINE: case R_UP_LINE:
case R_DOWN_LINE: case R_DOWN_LINE:
{ {
int line_old = parse_util_get_line_from_offset( data->command_line.c_str(), data->buff_pos ); int line_old = parse_util_get_line_from_offset( data->command_line, data->buff_pos );
int line_new; int line_new;
if( c == R_UP_LINE ) if( c == R_UP_LINE )
@ -3096,19 +3086,19 @@ const wchar_t *reader_readline()
if( line_new >= 0 && line_new <= line_count) if( line_new >= 0 && line_new <= line_count)
{ {
int base_pos_new; size_t base_pos_new;
int base_pos_old; size_t base_pos_old;
int indent_old; int indent_old;
int indent_new; int indent_new;
int line_offset_old; size_t line_offset_old;
int total_offset_new; size_t total_offset_new;
base_pos_new = parse_util_get_offset_from_line( data->command_line, line_new ); base_pos_new = parse_util_get_offset_from_line( data->command_line, line_new );
base_pos_old = parse_util_get_offset_from_line( data->command_line, line_old ); base_pos_old = parse_util_get_offset_from_line( data->command_line, line_old );
assert(base_pos_new != (size_t)(-1) && base_pos_old != (size_t)(-1));
indent_old = data->indents.at(base_pos_old); indent_old = data->indents.at(base_pos_old);
indent_new = data->indents.at(base_pos_new); indent_new = data->indents.at(base_pos_new);
@ -3135,7 +3125,7 @@ const wchar_t *reader_readline()
break; break;
} }
/* Other, if a normal character, we add it to the command */ /* Other, if a normal character, we add it to the command */
default: default:
{ {
@ -3147,10 +3137,10 @@ const wchar_t *reader_readline()
else else
{ {
/* /*
Low priority debug message. These can happen if Low priority debug message. These can happen if
the user presses an unefined control the user presses an unefined control
sequnece. No reason to report. sequnece. No reason to report.
*/ */
debug( 2, _( L"Unknown keybinding %d" ), c ); debug( 2, _( L"Unknown keybinding %d" ), c );
} }
break; break;
@ -3159,10 +3149,10 @@ const wchar_t *reader_readline()
} }
if( (c != R_HISTORY_SEARCH_BACKWARD) && if( (c != R_HISTORY_SEARCH_BACKWARD) &&
(c != R_HISTORY_SEARCH_FORWARD) && (c != R_HISTORY_SEARCH_FORWARD) &&
(c != R_HISTORY_TOKEN_SEARCH_BACKWARD) && (c != R_HISTORY_TOKEN_SEARCH_BACKWARD) &&
(c != R_HISTORY_TOKEN_SEARCH_FORWARD) && (c != R_HISTORY_TOKEN_SEARCH_FORWARD) &&
(c != R_NULL) ) (c != R_NULL) )
{ {
data->search_mode = NO_SEARCH; data->search_mode = NO_SEARCH;
data->search_buff.clear(); data->search_buff.clear();
@ -3174,10 +3164,10 @@ const wchar_t *reader_readline()
} }
writestr( L"\n" ); writestr( L"\n" );
/* /*
if( comp ) if( comp )
halloc_free( comp ); halloc_free( comp );
*/ */
if( !reader_exit_forced() ) if( !reader_exit_forced() )
{ {
if( tcsetattr(0,TCSANOW,&old_modes)) /* return to previous mode */ if( tcsetattr(0,TCSANOW,&old_modes)) /* return to previous mode */

View file

@ -107,9 +107,9 @@ void reader_set_buffer( const wcstring &b, size_t p );
/** /**
Get the current cursor position in the command line. If interactive Get the current cursor position in the command line. If interactive
mode is uninitialized, return -1. mode is uninitialized, return (size_t)(-1).
*/ */
int reader_get_cursor_pos(); size_t reader_get_cursor_pos();
/** /**
Return the value of the interrupted flag, which is set by the sigint Return the value of the interrupted flag, which is set by the sigint

View file

@ -774,7 +774,7 @@ void s_write( screen_t *s,
size_t explicit_len, size_t explicit_len,
const int *c, const int *c,
const int *indent, const int *indent,
int cursor ) size_t cursor_pos )
{ {
int cursor_arr[2]; int cursor_arr[2];
@ -889,17 +889,17 @@ void s_write( screen_t *s,
prompt_width=0; prompt_width=0;
} }
int i; size_t i;
for( i=0; commandline[i]; i++ ) for( i=0; commandline[i]; i++ )
{ {
int col = c[i]; int col = c[i];
if( i == cursor ) if( i == cursor_pos )
{ {
col = 0; col = 0;
} }
if( i == cursor ) if( i == cursor_pos )
{ {
cursor_arr[0] = s->desired.cursor[0]; cursor_arr[0] = s->desired.cursor[0];
cursor_arr[1] = s->desired.cursor[1]; cursor_arr[1] = s->desired.cursor[1];
@ -907,7 +907,7 @@ void s_write( screen_t *s,
s_desired_append_char( s, commandline[i], col, indent[i], prompt_width ); s_desired_append_char( s, commandline[i], col, indent[i], prompt_width );
if( i== cursor && s->desired.cursor[1] != cursor_arr[1] && commandline[i] != L'\n' ) if( i== cursor_pos && s->desired.cursor[1] != cursor_arr[1] && commandline[i] != L'\n' )
{ {
/* /*
Ugh. We are placed exactly at the wrapping point of a Ugh. We are placed exactly at the wrapping point of a
@ -919,7 +919,7 @@ void s_write( screen_t *s,
cursor_arr[1] = s->desired.cursor[1]; cursor_arr[1] = s->desired.cursor[1];
} }
} }
if( i == cursor ) if( i == cursor_pos )
{ {
memcpy(cursor_arr, s->desired.cursor, sizeof(int)*2); memcpy(cursor_arr, s->desired.cursor, sizeof(int)*2);
} }

View file

@ -150,7 +150,7 @@ void s_write( screen_t *s,
size_t explicit_len, size_t explicit_len,
const int *colors, const int *colors,
const int *indent, const int *indent,
int cursor_pos ); size_t cursor_pos );
/** /**
This function resets the screen buffers internal knowledge about This function resets the screen buffers internal knowledge about