diff --git a/builtin_set.cpp b/builtin_set.cpp index 97ec6be76..126ca1f11 100644 --- a/builtin_set.cpp +++ b/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 &indexes, +static int parse_index( std::vector &indexes, const wchar_t *src, const wchar_t *name, int var_count ) @@ -457,46 +380,11 @@ static int parse_index2( std::vector &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 &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 &indexes) +static void erase_values(wcstring_list_t &list, std::vector &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 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= count ) { diff --git a/common.h b/common.h index b8cb8d5bb..88e583614 100644 --- a/common.h +++ b/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); /** diff --git a/expand.cpp b/expand.cpp index f909bde44..cf0030c3f 100644 --- a/expand.cpp +++ b/expand.cpp @@ -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 &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] == '/' ) diff --git a/kill.cpp b/kill.cpp index 6161a4b0e..3cc947963 100644 --- a/kill.cpp +++ b/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 ) diff --git a/kill.h b/kill.h index 543a07d6a..68f143bc0 100644 --- a/kill.h +++ b/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 */ diff --git a/print_help.cpp b/print_help.cpp index 40c1723ef..18a0f9653 100644 --- a/print_help.cpp +++ b/print_help.cpp @@ -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 ); diff --git a/print_help.h b/print_help.h index 570b43a6a..1020ca759 100644 --- a/print_help.h +++ b/print_help.h @@ -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 diff --git a/reader.cpp b/reader.cpp index 8f41f25d3..da9942331 100644 --- a/reader.cpp +++ b/reader.cpp @@ -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;