mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 18:03:37 +08:00
Lots of warnings fixes and const correctness
This commit is contained in:
parent
a359f45df2
commit
f3e2d2f68f
184
builtin_set.cpp
184
builtin_set.cpp
|
@ -177,7 +177,7 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
|
|||
static int my_env_set2( const wchar_t *key, wcstring_list_t &val, int scope )
|
||||
{
|
||||
string_buffer_t sb;
|
||||
int i;
|
||||
size_t i;
|
||||
int retcode = 0;
|
||||
wchar_t *val_str=0;
|
||||
|
||||
|
@ -304,84 +304,7 @@ static int my_env_set2( const wchar_t *key, wcstring_list_t &val, int scope )
|
|||
|
||||
\return the total number of indexes parsed, or -1 on error
|
||||
*/
|
||||
static int parse_index( array_list_t *indexes,
|
||||
const wchar_t *src,
|
||||
const wchar_t *name,
|
||||
int var_count )
|
||||
{
|
||||
size_t len;
|
||||
|
||||
int count = 0;
|
||||
const wchar_t *src_orig = src;
|
||||
|
||||
if (src == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
|
||||
{
|
||||
src++;
|
||||
}
|
||||
|
||||
if (*src != L'[')
|
||||
{
|
||||
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = src-src_orig;
|
||||
|
||||
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
|
||||
L"set",
|
||||
name,
|
||||
len,
|
||||
src_orig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
src++;
|
||||
|
||||
while (iswspace(*src))
|
||||
{
|
||||
src++;
|
||||
}
|
||||
|
||||
while (*src != L']')
|
||||
{
|
||||
wchar_t *end;
|
||||
|
||||
long l_ind;
|
||||
|
||||
errno = 0;
|
||||
|
||||
l_ind = wcstol(src, &end, 10);
|
||||
|
||||
if( end==src || errno )
|
||||
{
|
||||
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( l_ind < 0 )
|
||||
{
|
||||
l_ind = var_count+l_ind+1;
|
||||
}
|
||||
|
||||
al_push_long(indexes, l_ind);
|
||||
src = end;
|
||||
count++;
|
||||
while (iswspace(*src)) src++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
static int parse_index2( std::vector<long> &indexes,
|
||||
static int parse_index( std::vector<long> &indexes,
|
||||
const wchar_t *src,
|
||||
const wchar_t *name,
|
||||
int var_count )
|
||||
|
@ -457,46 +380,11 @@ static int parse_index2( std::vector<long> &indexes,
|
|||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
Update a list \c list by writing copies (using wcsdup) of the
|
||||
values specified by \c values to the indexes specified by \c
|
||||
indexes. The previous entries at the specidied position will be
|
||||
free'd.
|
||||
|
||||
\return 0 if the operation was successfull, non-zero otherwise
|
||||
*/
|
||||
static int update_values( array_list_t *list,
|
||||
array_list_t *indexes,
|
||||
array_list_t *values )
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Replace values where needed */
|
||||
for( i = 0; i < al_get_count(indexes); i++ )
|
||||
{
|
||||
/*
|
||||
The '- 1' below is because the indices in fish are
|
||||
one-based, but the array_list_t uses zero-based indices
|
||||
*/
|
||||
long ind = al_get_long(indexes, i) - 1;
|
||||
const wchar_t *newv = (const wchar_t*) al_get(values, i);
|
||||
if( ind < 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
free((void *) al_get(list, ind));
|
||||
al_set(list, ind, newv != 0 ? wcsdup(newv) : wcsdup(L""));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int update_values2( wcstring_list_t &list,
|
||||
static int update_values( wcstring_list_t &list,
|
||||
std::vector<long> &indexes,
|
||||
wcstring_list_t &values )
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
/* Replace values where needed */
|
||||
for( i = 0; i < indexes.size(); i++ )
|
||||
|
@ -518,61 +406,13 @@ static int update_values2( wcstring_list_t &list,
|
|||
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
Return 1 if an array list of longs contains the specified
|
||||
value, 0 otherwise
|
||||
*/
|
||||
static int al_contains_long( array_list_t *list,
|
||||
long val)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < al_get_count(list); i++)
|
||||
{
|
||||
long current = al_get_long(list, i);
|
||||
if( current != 0 && current == val )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Erase from a list values at specified indexes
|
||||
*/
|
||||
static void erase_values(array_list_t *list, array_list_t *indexes)
|
||||
{
|
||||
long i;
|
||||
array_list_t result;
|
||||
|
||||
al_init(&result);
|
||||
|
||||
for (i = 0; i < al_get_count(list); i++)
|
||||
{
|
||||
if (!al_contains_long(indexes, i + 1))
|
||||
{
|
||||
al_push(&result, al_get(list, i));
|
||||
}
|
||||
else
|
||||
{
|
||||
free( (void *)al_get(list, i));
|
||||
}
|
||||
}
|
||||
|
||||
al_truncate(list,0);
|
||||
al_push_all( list, &result );
|
||||
al_destroy(&result);
|
||||
}
|
||||
|
||||
/**
|
||||
Erase from a list of wcstring values at specified indexes
|
||||
*/
|
||||
static void erase_values2 (wcstring_list_t &list, std::vector<long> &indexes)
|
||||
static void erase_values(wcstring_list_t &list, std::vector<long> &indexes)
|
||||
{
|
||||
long i;
|
||||
size_t i;
|
||||
wcstring_list_t result;
|
||||
|
||||
// al_init(&result);
|
||||
|
@ -878,7 +718,7 @@ static int builtin_set( wchar_t **argv )
|
|||
{
|
||||
std::vector<long> indexes;
|
||||
wcstring_list_t result;
|
||||
int j;
|
||||
size_t j;
|
||||
|
||||
// al_init( &result );
|
||||
// al_init( &indexes );
|
||||
|
@ -886,7 +726,7 @@ static int builtin_set( wchar_t **argv )
|
|||
if (! dest_str.missing())
|
||||
tokenize_variable_array2( dest_str, result );
|
||||
|
||||
if( !parse_index2( indexes, arg, dest, result.size() ) )
|
||||
if( !parse_index( indexes, arg, dest, result.size() ) )
|
||||
{
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
|
@ -895,7 +735,7 @@ static int builtin_set( wchar_t **argv )
|
|||
for( j=0; j < indexes.size() ; j++ )
|
||||
{
|
||||
long idx = indexes[j];
|
||||
if( idx < 1 || idx > result.size() )
|
||||
if( idx < 1 || (size_t)idx > result.size() )
|
||||
{
|
||||
retcode++;
|
||||
}
|
||||
|
@ -1006,7 +846,7 @@ static int builtin_set( wchar_t **argv )
|
|||
|
||||
for( ; woptind<argc; woptind++ )
|
||||
{
|
||||
if( !parse_index2( indexes, argv[woptind], dest, result.size() ) )
|
||||
if( !parse_index( indexes, argv[woptind], dest, result.size() ) )
|
||||
{
|
||||
builtin_print_help( argv[0], sb_err );
|
||||
retcode = 1;
|
||||
|
@ -1041,7 +881,7 @@ static int builtin_set( wchar_t **argv )
|
|||
|
||||
if( erase )
|
||||
{
|
||||
erase_values2(result, indexes);
|
||||
erase_values(result, indexes);
|
||||
my_env_set2( dest, result, scope);
|
||||
}
|
||||
else
|
||||
|
@ -1054,7 +894,7 @@ static int builtin_set( wchar_t **argv )
|
|||
value.push_back( argv[woptind++] );
|
||||
}
|
||||
|
||||
if( update_values2( result,
|
||||
if( update_values( result,
|
||||
indexes,
|
||||
value ) )
|
||||
{
|
||||
|
|
10
common.cpp
10
common.cpp
|
@ -620,16 +620,16 @@ int read_blocked(int fd, void *buf, size_t count)
|
|||
return res;
|
||||
}
|
||||
|
||||
ssize_t write_loop(int fd, char *buff, size_t count)
|
||||
ssize_t write_loop(int fd, const char *buff, size_t count)
|
||||
{
|
||||
ssize_t out=0;
|
||||
ssize_t out_cum=0;
|
||||
size_t out=0;
|
||||
size_t out_cum=0;
|
||||
while( 1 )
|
||||
{
|
||||
out = write( fd,
|
||||
&buff[out_cum],
|
||||
count - out_cum );
|
||||
if (out == -1)
|
||||
if (out < 0)
|
||||
{
|
||||
if( errno != EAGAIN &&
|
||||
errno != EINTR )
|
||||
|
@ -638,7 +638,7 @@ ssize_t write_loop(int fd, char *buff, size_t count)
|
|||
}
|
||||
} else
|
||||
{
|
||||
out_cum += out;
|
||||
out_cum += (size_t)out;
|
||||
}
|
||||
if( out_cum >= count )
|
||||
{
|
||||
|
|
2
common.h
2
common.h
|
@ -432,7 +432,7 @@ int read_blocked(int fd, void *buf, size_t count);
|
|||
Loop a write request while failiure is non-critical. Return -1 and set errno
|
||||
in case of critical error.
|
||||
*/
|
||||
ssize_t write_loop(int fd, char *buff, size_t count);
|
||||
ssize_t write_loop(int fd, const char *buff, size_t count);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -380,7 +380,6 @@ static int find_process( const wchar_t *proc,
|
|||
array_list_t *out )
|
||||
{
|
||||
DIR *dir;
|
||||
struct wdirent *next;
|
||||
wchar_t *pdir_name;
|
||||
wchar_t *pfile_name;
|
||||
wchar_t *cmd=0;
|
||||
|
@ -1775,7 +1774,6 @@ int expand_string2( const wcstring &input, std::vector<wcstring> &output, int fl
|
|||
size_t i;
|
||||
int cmdsubst_ok = 1;
|
||||
int res = EXPAND_OK;
|
||||
int start_count = output.size();
|
||||
|
||||
if( (!(flags & ACCEPT_INCOMPLETE)) && expand_is_clean( input.c_str() ) )
|
||||
{
|
||||
|
@ -2179,7 +2177,7 @@ int expand_string( void *context,
|
|||
if( ((flags & ACCEPT_INCOMPLETE) && (!(flags & EXPAND_SKIP_WILDCARDS))) ||
|
||||
wildcard_has( next, 1 ) )
|
||||
{
|
||||
wchar_t *start, *rest;
|
||||
const wchar_t *start, *rest;
|
||||
array_list_t *list = out;
|
||||
|
||||
if( next[0] == '/' )
|
||||
|
|
6
kill.cpp
6
kill.cpp
|
@ -202,12 +202,12 @@ void kill_replace( wchar_t *old, wchar_t *newv )
|
|||
kill_add( newv );
|
||||
}
|
||||
|
||||
wchar_t *kill_yank_rotate()
|
||||
const wchar_t *kill_yank_rotate()
|
||||
{
|
||||
if( kill_current == 0 )
|
||||
return L"";
|
||||
kill_current = kill_current->prev;
|
||||
return (wchar_t *)kill_current->data;
|
||||
return (const wchar_t *)kill_current->data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -256,7 +256,7 @@ static void kill_check_x_buffer()
|
|||
}
|
||||
|
||||
|
||||
wchar_t *kill_yank()
|
||||
const wchar_t *kill_yank()
|
||||
{
|
||||
kill_check_x_buffer();
|
||||
if( kill_current == 0 )
|
||||
|
|
4
kill.h
4
kill.h
|
@ -22,11 +22,11 @@ void kill_add( wchar_t *str );
|
|||
/**
|
||||
Rotate the killring
|
||||
*/
|
||||
wchar_t *kill_yank_rotate();
|
||||
const wchar_t *kill_yank_rotate();
|
||||
/**
|
||||
Paste from the killring
|
||||
*/
|
||||
wchar_t *kill_yank();
|
||||
const wchar_t *kill_yank();
|
||||
/**
|
||||
Sanity check
|
||||
*/
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
#define HELP_ERR "Could not show help message\n"
|
||||
|
||||
/* defined in common.h */
|
||||
ssize_t write_loop(int fd, char *buff, size_t count);
|
||||
ssize_t write_loop(int fd, const char *buff, size_t count);
|
||||
|
||||
|
||||
void print_help( char *c, int fd )
|
||||
void print_help( const char *c, int fd )
|
||||
{
|
||||
char cmd[ CMD_LEN];
|
||||
int printed = snprintf( cmd, CMD_LEN, "fish -c '__fish_print_help %s >&%d'", c, fd );
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
Print help message for the specified command
|
||||
*/
|
||||
|
||||
void print_help( char *cmd, int fd );
|
||||
void print_help( const char *cmd, int fd );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -779,7 +779,7 @@ static void remove_backward()
|
|||
Insert the characters of the string into the command line buffer
|
||||
and print them to the screen using syntax highlighting, etc.
|
||||
*/
|
||||
static int insert_str(wchar_t *str)
|
||||
static int insert_str(const wchar_t *str)
|
||||
{
|
||||
int len = wcslen( str );
|
||||
int old_len = data->buff_len;
|
||||
|
@ -2679,7 +2679,7 @@ wchar_t *reader_readline()
|
|||
wint_t c;
|
||||
int i;
|
||||
int last_char=0, yank=0;
|
||||
wchar_t *yank_str;
|
||||
const wchar_t *yank_str;
|
||||
array_list_t *comp=0;
|
||||
int comp_empty=1;
|
||||
int finished=0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user