mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Const correctness changes
This commit is contained in:
parent
737589ec01
commit
a534c397f5
9 changed files with 63 additions and 62 deletions
|
@ -2145,7 +2145,7 @@ static int builtin_read( parser_t &parser, wchar_t **argv )
|
|||
*/
|
||||
if( isatty(0) && builtin_stdin == 0 )
|
||||
{
|
||||
wchar_t *line;
|
||||
const wchar_t *line;
|
||||
|
||||
reader_push( mode_name );
|
||||
reader_set_prompt( prompt );
|
||||
|
|
|
@ -56,7 +56,7 @@ enum
|
|||
Pointer to what the commandline builtin considers to be the current
|
||||
contents of the command line buffer.
|
||||
*/
|
||||
static wchar_t *current_buffer=0;
|
||||
static const wchar_t *current_buffer=0;
|
||||
/**
|
||||
What the commandline builtin considers to be the current cursor
|
||||
position.
|
||||
|
@ -66,7 +66,7 @@ static int current_cursor_pos = -1;
|
|||
/**
|
||||
Returns the current commandline buffer.
|
||||
*/
|
||||
static wchar_t *get_buffer()
|
||||
static const wchar_t *get_buffer()
|
||||
{
|
||||
return current_buffer;
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
|
|||
int cursor_mode = 0;
|
||||
int line_mode = 0;
|
||||
int search_mode = 0;
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
|
||||
current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
|
||||
if( current_buffer )
|
||||
|
@ -575,7 +575,7 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
|
|||
if( line_mode )
|
||||
{
|
||||
int pos = reader_get_cursor_pos();
|
||||
wchar_t *buff = reader_get_buffer();
|
||||
const wchar_t *buff = reader_get_buffer();
|
||||
sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
|
|||
array_list_t gnu_opt, old_opt;
|
||||
const wchar_t *comp=L"", *desc=L"", *condition=L"";
|
||||
|
||||
wchar_t *do_complete = 0;
|
||||
const wchar_t *do_complete = 0;
|
||||
|
||||
array_list_t cmd;
|
||||
array_list_t path;
|
||||
|
@ -545,7 +545,7 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
|
|||
|
||||
const wchar_t *prev_temporary_buffer = temporary_buffer;
|
||||
|
||||
wchar_t *token;
|
||||
const wchar_t *token;
|
||||
|
||||
parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 );
|
||||
|
||||
|
|
18
complete.cpp
18
complete.cpp
|
@ -1543,11 +1543,11 @@ static int complete_param( const wchar_t *cmd_orig,
|
|||
/**
|
||||
Perform file completion on the specified string
|
||||
*/
|
||||
static void complete_param_expand( wchar_t *str,
|
||||
static void complete_param_expand( const wchar_t *str,
|
||||
std::vector<completion_t> &comp_out,
|
||||
int do_file )
|
||||
{
|
||||
wchar_t *comp_str;
|
||||
const wchar_t *comp_str;
|
||||
int flags;
|
||||
|
||||
if( (wcsncmp( str, L"--", 2 )) == 0 && (comp_str = wcschr(str, L'=' ) ) )
|
||||
|
@ -1758,10 +1758,10 @@ static int try_complete_user( const wchar_t *cmd,
|
|||
void complete( const wchar_t *cmd,
|
||||
std::vector<completion_t> &comp )
|
||||
{
|
||||
wchar_t *tok_begin, *tok_end, *cmdsubst_begin, *cmdsubst_end, *prev_begin, *prev_end;
|
||||
const wchar_t *tok_begin, *tok_end, *cmdsubst_begin, *cmdsubst_end, *prev_begin, *prev_end;
|
||||
wchar_t *buff;
|
||||
tokenizer tok;
|
||||
wchar_t *current_token=0, *current_command=0, *prev_token=0;
|
||||
const wchar_t *current_token=0, *current_command=0, *prev_token=0;
|
||||
int on_command=0;
|
||||
int pos;
|
||||
int done=0;
|
||||
|
@ -1854,7 +1854,7 @@ void complete( const wchar_t *cmd,
|
|||
{
|
||||
int token_end;
|
||||
|
||||
free( current_command );
|
||||
free( (void *)current_command );
|
||||
current_command = wcsdup( ncmd );
|
||||
|
||||
token_end = tok_get_pos( &tok ) + wcslen( ncmd );
|
||||
|
@ -1928,7 +1928,7 @@ void complete( const wchar_t *cmd,
|
|||
(current_token[0] == L'-') &&
|
||||
!(use_command && use_function && use_builtin ) )
|
||||
{
|
||||
free( current_command );
|
||||
free( (void *)current_command );
|
||||
if( use_command == 0 )
|
||||
current_command = wcsdup( L"builtin" );
|
||||
else
|
||||
|
@ -2009,9 +2009,9 @@ void complete( const wchar_t *cmd,
|
|||
}
|
||||
}
|
||||
|
||||
free( current_token );
|
||||
free( current_command );
|
||||
free( prev_token );
|
||||
free( (void *)current_token );
|
||||
free( (void *)current_command );
|
||||
free( (void *)prev_token );
|
||||
|
||||
condition_cache_clear();
|
||||
|
||||
|
|
4
env.cpp
4
env.cpp
|
@ -1143,7 +1143,7 @@ env_var_t env_get_string( const wchar_t *key )
|
|||
if( wcscmp( key, L"history" ) == 0 )
|
||||
{
|
||||
wcstring result;
|
||||
wchar_t *current;
|
||||
const wchar_t *current;
|
||||
int i;
|
||||
int add_current=0;
|
||||
|
||||
|
@ -1251,7 +1251,7 @@ const wchar_t *env_get( const wchar_t *key )
|
|||
|
||||
if( wcscmp( key, L"history" ) == 0 )
|
||||
{
|
||||
wchar_t *current;
|
||||
const wchar_t *current;
|
||||
dyn_var.clear();
|
||||
|
||||
current = reader_get_buffer();
|
||||
|
|
|
@ -992,8 +992,7 @@ void highlight_shell( const wchar_t *buff, int *color, int pos, array_list_t *er
|
|||
if( pos >= 0 && pos <= len )
|
||||
{
|
||||
|
||||
wchar_t *tok_begin, *tok_end;
|
||||
wchar_t *token;
|
||||
const wchar_t *tok_begin, *tok_end, *token;
|
||||
|
||||
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
|
||||
if( tok_begin && tok_end )
|
||||
|
|
|
@ -109,10 +109,10 @@ int parse_util_lineno( const wchar_t *str, int len )
|
|||
}
|
||||
|
||||
|
||||
int parse_util_get_line_from_offset( wchar_t *buff, int pos )
|
||||
int parse_util_get_line_from_offset( const wcstring &str, int pos )
|
||||
{
|
||||
// return parse_util_lineno( buff, pos );
|
||||
|
||||
const wchar_t *buff = str.c_str();
|
||||
int i;
|
||||
int count = 0;
|
||||
if( pos < 0 )
|
||||
|
@ -136,8 +136,9 @@ int parse_util_get_line_from_offset( wchar_t *buff, int pos )
|
|||
}
|
||||
|
||||
|
||||
int parse_util_get_offset_from_line( wchar_t *buff, int line )
|
||||
int parse_util_get_offset_from_line( const wcstring &str, int line )
|
||||
{
|
||||
const wchar_t *buff = str.c_str();
|
||||
int i;
|
||||
int count = 0;
|
||||
|
||||
|
@ -168,8 +169,9 @@ int parse_util_get_offset_from_line( wchar_t *buff, int line )
|
|||
}
|
||||
}
|
||||
|
||||
int parse_util_get_offset( wchar_t *buff, int line, int line_offset )
|
||||
int parse_util_get_offset( const wcstring &str, int line, int line_offset )
|
||||
{
|
||||
const wchar_t *buff = str.c_str();
|
||||
int off = parse_util_get_offset_from_line( buff, line );
|
||||
int off2 = parse_util_get_offset_from_line( buff, line+1 );
|
||||
int line_offset2 = line_offset;
|
||||
|
@ -292,8 +294,8 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
|||
|
||||
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b )
|
||||
const wchar_t **a,
|
||||
const wchar_t **b )
|
||||
{
|
||||
wchar_t *begin, *end;
|
||||
wchar_t *pos;
|
||||
|
@ -363,11 +365,11 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
|||
*/
|
||||
static void job_or_process_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b,
|
||||
const wchar_t **a,
|
||||
const wchar_t **b,
|
||||
int process )
|
||||
{
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
int pos;
|
||||
wchar_t *buffcpy;
|
||||
int finished=0;
|
||||
|
@ -460,16 +462,16 @@ static void job_or_process_extent( const wchar_t *buff,
|
|||
|
||||
void parse_util_process_extent( const wchar_t *buff,
|
||||
int pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b )
|
||||
const wchar_t **a,
|
||||
const wchar_t **b )
|
||||
{
|
||||
job_or_process_extent( buff, pos, a, b, 1 );
|
||||
}
|
||||
|
||||
void parse_util_job_extent( const wchar_t *buff,
|
||||
int pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b )
|
||||
const wchar_t **a,
|
||||
const wchar_t **b )
|
||||
{
|
||||
job_or_process_extent( buff,pos,a, b, 0 );
|
||||
}
|
||||
|
@ -477,18 +479,18 @@ void parse_util_job_extent( const wchar_t *buff,
|
|||
|
||||
void parse_util_token_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **tok_begin,
|
||||
wchar_t **tok_end,
|
||||
wchar_t **prev_begin,
|
||||
wchar_t **prev_end )
|
||||
const wchar_t **tok_begin,
|
||||
const wchar_t **tok_end,
|
||||
const wchar_t **prev_begin,
|
||||
const wchar_t **prev_end )
|
||||
{
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
int pos;
|
||||
wchar_t *buffcpy;
|
||||
|
||||
tokenizer tok;
|
||||
|
||||
wchar_t *a, *b, *pa, *pb;
|
||||
const wchar_t *a, *b, *pa, *pb;
|
||||
|
||||
CHECK( buff, );
|
||||
|
||||
|
@ -505,9 +507,9 @@ void parse_util_token_extent( const wchar_t *buff,
|
|||
|
||||
pos = cursor_pos - (begin - buff);
|
||||
|
||||
a = (wchar_t *)buff + pos;
|
||||
a = buff + pos;
|
||||
b = a;
|
||||
pa = (wchar_t *)buff + pos;
|
||||
pa = buff + pos;
|
||||
pb = pa;
|
||||
|
||||
assert( begin >= buff );
|
||||
|
|
28
parse_util.h
28
parse_util.h
|
@ -41,8 +41,8 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
|
|||
*/
|
||||
void parse_util_cmdsubst_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b );
|
||||
const wchar_t **a,
|
||||
const wchar_t **b );
|
||||
|
||||
/**
|
||||
Find the beginning and end of the process definition under the cursor
|
||||
|
@ -54,8 +54,8 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
|
|||
*/
|
||||
void parse_util_process_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b );
|
||||
const wchar_t **a,
|
||||
const wchar_t **b );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -68,12 +68,12 @@ void parse_util_process_extent( const wchar_t *buff,
|
|||
*/
|
||||
void parse_util_job_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **a,
|
||||
wchar_t **b );
|
||||
const wchar_t **a,
|
||||
const wchar_t **b );
|
||||
|
||||
/**
|
||||
Find the beginning and end of the token under the cursor and the
|
||||
toekn before the current token. Any combination of tok_begin,
|
||||
token before the current token. Any combination of tok_begin,
|
||||
tok_end, prev_begin and prev_end may be null.
|
||||
|
||||
\param buff the string to search for subshells
|
||||
|
@ -85,10 +85,10 @@ void parse_util_job_extent( const wchar_t *buff,
|
|||
*/
|
||||
void parse_util_token_extent( const wchar_t *buff,
|
||||
int cursor_pos,
|
||||
wchar_t **tok_begin,
|
||||
wchar_t **tok_end,
|
||||
wchar_t **prev_begin,
|
||||
wchar_t **prev_end );
|
||||
const wchar_t **tok_begin,
|
||||
const wchar_t **tok_end,
|
||||
const wchar_t **prev_begin,
|
||||
const wchar_t **prev_end );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -99,18 +99,18 @@ int parse_util_lineno( const wchar_t *str, int len );
|
|||
/**
|
||||
Calculate the line number of the specified cursor position
|
||||
*/
|
||||
int parse_util_get_line_from_offset( wchar_t *buff, int pos );
|
||||
int parse_util_get_line_from_offset( const wcstring &str, int pos );
|
||||
|
||||
/**
|
||||
Get the offset of the first character on the specified line
|
||||
*/
|
||||
int parse_util_get_offset_from_line( wchar_t *buff, int line );
|
||||
int parse_util_get_offset_from_line( const wcstring &str, int line );
|
||||
|
||||
|
||||
/**
|
||||
Return the total offset of the buffer for the cursor position nearest to the specified poition
|
||||
*/
|
||||
int parse_util_get_offset( wchar_t *buff, int line, int line_offset );
|
||||
int parse_util_get_offset( const wcstring &str, int line, int line_offset );
|
||||
|
||||
/**
|
||||
Set the argv environment variable to the specified null-terminated
|
||||
|
|
14
reader.cpp
14
reader.cpp
|
@ -1028,7 +1028,7 @@ static void completion_insert( const wchar_t *val, int flags )
|
|||
{
|
||||
|
||||
int tok_start, tok_len, move_cursor;
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
string_buffer_t sb;
|
||||
wchar_t *escaped;
|
||||
|
||||
|
@ -1225,7 +1225,7 @@ static void run_pager( wchar_t *prefix, int is_quoted, const std::vector<complet
|
|||
{
|
||||
if( base_len == -1 )
|
||||
{
|
||||
wchar_t *begin;
|
||||
const wchar_t *begin;
|
||||
|
||||
parse_util_token_extent( data->buff, data->buff_pos, &begin, 0, 0, 0 );
|
||||
base_len = data->buff_pos - (begin-data->buff);
|
||||
|
@ -1402,7 +1402,7 @@ static int handle_completions( std::vector<completion_t> &comp )
|
|||
int done = 0;
|
||||
int count = 0;
|
||||
int flags=0;
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
wchar_t *tok;
|
||||
|
||||
parse_util_token_extent( data->buff, data->buff_pos, &begin, 0, 0, 0 );
|
||||
|
@ -1757,7 +1757,7 @@ void reader_sanity_check()
|
|||
void reader_replace_current_token( const wchar_t *new_token )
|
||||
{
|
||||
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
string_buffer_t sb;
|
||||
int new_pos;
|
||||
|
||||
|
@ -1804,7 +1804,7 @@ static void handle_history( const wcstring &new_str )
|
|||
*/
|
||||
static void reset_token_history()
|
||||
{
|
||||
wchar_t *begin, *end;
|
||||
const wchar_t *begin, *end;
|
||||
|
||||
parse_util_token_extent( data->buff, data->buff_pos, &begin, &end, 0, 0 );
|
||||
|
||||
|
@ -2818,8 +2818,8 @@ wchar_t *reader_readline()
|
|||
|
||||
if( comp_empty || last_char != R_COMPLETE)
|
||||
{
|
||||
wchar_t *begin, *end;
|
||||
wchar_t *token_begin, *token_end;
|
||||
const wchar_t *begin, *end;
|
||||
const wchar_t *token_begin, *token_end;
|
||||
wchar_t *buffcpy;
|
||||
int len;
|
||||
int cursor_steps;
|
||||
|
|
Loading…
Reference in a new issue