diff --git a/builtin.cpp b/builtin.cpp index b084ed5d7..04e3f1343 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1692,7 +1692,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) else { errno = 0; - pid = wcstol( woptarg, &end, 10 ); + pid = (pid_t)wcstol( woptarg, &end, 10 ); if( errno || !end || *end ) { append_format(stderr_buffer, @@ -1821,7 +1821,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) for( i=0; i common_get_width() ) { chars = 0; @@ -2542,7 +2542,7 @@ static int builtin_exit( parser_t &parser, wchar_t **argv ) { int argc = builtin_count_args( argv ); - int ec=0; + long ec=0; switch( argc ) { case 1: @@ -2580,7 +2580,7 @@ static int builtin_exit( parser_t &parser, wchar_t **argv ) } reader_exit( 1, 0 ); - return ec; + return (int)ec; } /** diff --git a/builtin_commandline.cpp b/builtin_commandline.cpp index b8d3868af..7c9cfd9a9 100644 --- a/builtin_commandline.cpp +++ b/builtin_commandline.cpp @@ -127,7 +127,7 @@ static void replace_part( const wchar_t *begin, } } out.append( end ); - reader_set_buffer( out, (int)out_pos ); + reader_set_buffer( out, (size_t)out_pos ); } /** @@ -387,7 +387,7 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv ) case 'I': current_buffer = woptarg; - current_cursor_pos = wcslen( woptarg ); + current_cursor_pos = (int)wcslen( woptarg ); break; case 'C': @@ -545,8 +545,8 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv ) } current_buffer = reader_get_buffer(); - new_pos = maxi( 0L, mini( (long)new_pos, (long)wcslen( current_buffer ) ) ); - reader_set_buffer( current_buffer, new_pos ); + new_pos = maxi( 0L, mini( new_pos, (long)wcslen( current_buffer ) ) ); + reader_set_buffer( current_buffer, (size_t)new_pos ); return 0; } else diff --git a/complete.cpp b/complete.cpp index 1050ef432..df95ae58e 100644 --- a/complete.cpp +++ b/complete.cpp @@ -339,7 +339,7 @@ class completer_t { void complete_cmd_desc( const wcstring &str ); - bool complete_variable(const wcstring &str, int start_offset); + bool complete_variable(const wcstring &str, size_t start_offset); bool condition_test( const wcstring &condition ); @@ -1471,7 +1471,7 @@ bool completer_t::complete_param( const wcstring &scmd_orig, const wcstring &spo int has_arg=0; /* Does this switch have any known arguments */ int req_arg=0; /* Does this switch _require_ an argument */ - int offset = 0; + size_t offset = 0; complete_flags_t flags = 0; @@ -1560,11 +1560,11 @@ void completer_t::debug_print_completions() /** Complete the specified string as an environment variable */ -bool completer_t::complete_variable(const wcstring &str, int start_offset) +bool completer_t::complete_variable(const wcstring &str, size_t start_offset) { const wchar_t * const whole_var = str.c_str(); const wchar_t *var = &whole_var[start_offset]; - int varlen = wcslen( var ); + size_t varlen = wcslen( var ); int res = 0; bool wants_description = (type != COMPLETE_AUTOSUGGEST); @@ -1572,7 +1572,7 @@ bool completer_t::complete_variable(const wcstring &str, int start_offset) for( size_t i=0; i namelen ) @@ -1667,7 +1667,7 @@ bool completer_t::try_complete_user( const wcstring &str ) if( name_end == 0 ) { struct passwd *pw; - int name_len = wcslen( user_name ); + size_t name_len = wcslen( user_name ); setpwent(); diff --git a/env_universal_common.cpp b/env_universal_common.cpp index e2c1d62de..66a97fe18 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -431,9 +431,7 @@ static int read_byte( connection_t *src ) if( src->buffer_consumed >= src->buffer_used ) { - int res; - - res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE ); + ssize_t res = read( src->fd, src->buffer, ENV_UNIVERSAL_BUFFER_SIZE ); // debug(4, L"Read chunk '%.*s'", res, src->buffer ); @@ -692,7 +690,7 @@ static int try_send( message_t *msg, debug( 3, L"before write of %d chars to fd %d", strlen(msg->body), fd ); - int res = write( fd, msg->body, strlen(msg->body) ); + ssize_t res = write( fd, msg->body, strlen(msg->body) ); if( res != -1 ) { diff --git a/env_universal_common.h b/env_universal_common.h index 1cfdd156f..14ce77d21 100644 --- a/env_universal_common.h +++ b/env_universal_common.h @@ -103,12 +103,12 @@ typedef struct connection /** Number of bytes that have already been consumed. */ - int buffer_consumed; + size_t buffer_consumed; /** Number of bytes that have been read into the buffer. */ - int buffer_used; + size_t buffer_used; /** diff --git a/fish_pager.cpp b/fish_pager.cpp index d108d1161..7c67d3481 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -480,7 +480,7 @@ static void completion_print( int cols, int row_stop, wchar_t *prefix, int is_quoted, - std::vector &lst ) + const std::vector &lst ) { size_t rows = (lst.size()-1)/cols+1; @@ -549,9 +549,9 @@ static int completion_try_print( int cols, */ int print=0; - int i, j; + long i, j; - long rows = (lst.size()-1)/cols+1; + int rows = (int)((lst.size()-1)/cols+1); int pref_tot_width=0; int min_tot_width = 0; @@ -573,7 +573,7 @@ static int completion_try_print( int cols, { int pref,min; comp_t *c; - if( (int)lst.size() <= j*rows + i ) + if( lst.size() <= j*rows + i ) continue; c = lst.at(j*rows + i ); @@ -613,7 +613,7 @@ static int completion_try_print( int cols, } else { - int next_rows = (lst.size()-1)/(cols-1)+1; + long next_rows = (lst.size()-1)/(cols-1)+1; /* fwprintf( stderr, L"cols %d, min_tot %d, term %d, rows=%d, nextrows %d, termrows %d, diff %d\n", cols, diff --git a/fishd.cpp b/fishd.cpp index bf4cfcb56..e0a2859d1 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -280,7 +280,7 @@ static int sprint_rand_digits( char *str, int maxlen ) */ static char *gen_unique_nfs_filename( const char *filename ) { - int pidlen, hnlen, orglen = strlen( filename ); + size_t pidlen, hnlen, orglen = strlen( filename ); char hostname[HOST_NAME_MAX + 1]; char *newname; @@ -452,7 +452,7 @@ done: */ static char *acquire_socket_lock( const char *sock_name ) { - int len = strlen( sock_name ); + size_t len = strlen( sock_name ); char *lockfile = (char *)malloc( len + strlen( LOCKPOSTFIX ) + 1 ); if( lockfile == NULL ) diff --git a/parse_util.cpp b/parse_util.cpp index 181d9c99a..c41a357a8 100644 --- a/parse_util.cpp +++ b/parse_util.cpp @@ -135,15 +135,15 @@ int parse_util_get_line_from_offset( const wcstring &str, int pos ) } -int parse_util_get_offset_from_line( const wcstring &str, int line ) +size_t parse_util_get_offset_from_line( const wcstring &str, int line ) { const wchar_t *buff = str.c_str(); - int i; + size_t i; int count = 0; if( line < 0 ) { - return -1; + return (size_t)(-1); } if( line == 0 ) @@ -168,19 +168,19 @@ int parse_util_get_offset_from_line( const wcstring &str, int line ) } } -int parse_util_get_offset( const wcstring &str, int line, int line_offset ) +size_t parse_util_get_offset( const wcstring &str, int line, long 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; + size_t off = parse_util_get_offset_from_line( buff, line ); + size_t off2 = parse_util_get_offset_from_line( buff, line+1 ); + long line_offset2 = line_offset; - if( off < 0 ) + if( off == (size_t)(-1) ) { return -1; } - if( off2 < 0 ) + if( off2 == (size_t)(-1) ) { off2 = (int)(wcslen( buff )+1); } @@ -292,7 +292,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in, void parse_util_cmdsubst_extent( const wchar_t *buff, - int cursor_pos, + size_t cursor_pos, const wchar_t **a, const wchar_t **b ) { @@ -477,7 +477,7 @@ void parse_util_job_extent( const wchar_t *buff, void parse_util_token_extent( const wchar_t *buff, - int cursor_pos, + size_t cursor_pos, const wchar_t **tok_begin, const wchar_t **tok_end, const wchar_t **prev_begin, diff --git a/parse_util.h b/parse_util.h index a3ffc193d..e533fb897 100644 --- a/parse_util.h +++ b/parse_util.h @@ -40,7 +40,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in, \param b the end of the searched string */ void parse_util_cmdsubst_extent( const wchar_t *buff, - int cursor_pos, + size_t cursor_pos, const wchar_t **a, const wchar_t **b ); @@ -84,7 +84,7 @@ void parse_util_job_extent( const wchar_t *buff, \param prev_end the end of the token before the current token */ void parse_util_token_extent( const wchar_t *buff, - int cursor_pos, + size_t cursor_pos, const wchar_t **tok_begin, const wchar_t **tok_end, const wchar_t **prev_begin, @@ -104,13 +104,13 @@ 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( const wcstring &str, int line ); +size_t 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( const wcstring &str, int line, int line_offset ); +size_t parse_util_get_offset( const wcstring &str, int line, long line_offset ); /** Set the argv environment variable to the specified null-terminated diff --git a/reader.cpp b/reader.cpp index 3bae07b59..9bfa1b065 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1641,7 +1641,7 @@ void reader_sanity_check() Set the specified string from the history as the current buffer. Do not modify prefix_width. */ -static void set_command_line_and_position( const wcstring &new_str, int pos ) +static void set_command_line_and_position( const wcstring &new_str, size_t pos ) { data->command_line = new_str; data->command_line_changed(); @@ -1654,7 +1654,7 @@ void reader_replace_current_token( const wchar_t *new_token ) { const wchar_t *begin, *end; - int new_pos; + size_t new_pos; /* Find current token */ const wchar_t *buff = data->command_line.c_str(); @@ -1985,7 +1985,7 @@ history_t *reader_get_history(void) { return data ? data->history : NULL; } -void reader_set_buffer( const wcstring &b, int p ) +void reader_set_buffer( const wcstring &b, size_t p ) { if( !data ) return; @@ -3232,14 +3232,12 @@ static int read_ni( int fd, io_data_t *io ) if( in_stream != 0 ) { wchar_t *str; - int acc_used; + size_t acc_used; while(!feof( in_stream )) { char buff[4096]; - int c; - - c = fread(buff, 1, 4096, in_stream); + size_t c = fread(buff, 1, 4096, in_stream); if( ferror( in_stream ) && ( errno != EINTR ) ) { diff --git a/reader.h b/reader.h index f2156b07c..846e0a0ab 100644 --- a/reader.h +++ b/reader.h @@ -100,9 +100,10 @@ history_t *reader_get_history(void); Set the string of characters in the command buffer, as well as the cursor position. \param b the new buffer value - \param p the cursor position. If \c p is less than zero, the cursor is placed on the last character. + \param p the cursor position. If \c p is larger than the length of the command line, + the cursor is placed on the last character. */ -void reader_set_buffer( const wcstring &b, int p ); +void reader_set_buffer( const wcstring &b, size_t p ); /** Get the current cursor position in the command line. If interactive diff --git a/screen.cpp b/screen.cpp index 7087f14e4..8ec4278c2 100644 --- a/screen.cpp +++ b/screen.cpp @@ -113,7 +113,7 @@ static int try_sequence( const char *seq, const wchar_t *str ) Returns the number of columns left until the next tab stop, given the current cursor postion. */ -static int next_tab_stop( int in ) +static size_t next_tab_stop( size_t in ) { /* Assume tab stops every 8 characters if undefined @@ -151,9 +151,9 @@ static int is_term256_escape(const wchar_t *str) { to detect common escape sequences that may be embeded in a prompt, such as color codes. */ -static int calc_prompt_width( const wchar_t *prompt ) +static size_t calc_prompt_width( const wchar_t *prompt ) { - int res = 0; + size_t res = 0; size_t j, k; for( j=0; prompt[j]; j++ ) @@ -416,7 +416,7 @@ static void s_desired_append_char( screen_t *s, wchar_t b, int c, int indent, - int prompt_width ) + size_t prompt_width ) { int line_no = s->desired.cursor[1]; @@ -653,7 +653,7 @@ static size_t line_shared_prefix(const line_t &a, const line_t &b) */ static void s_update( screen_t *scr, const wchar_t *prompt ) { - int prompt_width = calc_prompt_width( prompt ); + size_t prompt_width = calc_prompt_width( prompt ); int screen_width = common_get_width(); int need_clear = scr->need_clear; data_buffer_t output; @@ -673,25 +673,25 @@ static void s_update( screen_t *scr, const wchar_t *prompt ) s_move( scr, &output, 0, 0 ); s_write_str( &output, prompt ); scr->actual_prompt = prompt; - scr->actual.cursor[0] = prompt_width; + scr->actual.cursor[0] = (int)prompt_width; } for (size_t i=0; i < scr->desired.line_count(); i++) { const line_t &o_line = scr->desired.line(i); line_t &s_line = scr->actual.create_line(i); - int start_pos = (i==0 ? prompt_width : 0); + size_t start_pos = (i==0 ? prompt_width : 0); int current_width = 0; if( need_clear ) { - s_move( scr, &output, start_pos, (int)i ); + s_move( scr, &output, (int)start_pos, (int)i ); s_write_mbs( &output, clr_eol); s_line.clear(); } /* Note that skip_remaining is a width, not a character count */ - int skip_remaining = start_pos; + size_t skip_remaining = start_pos; /* Compute how much we should skip. At a minimum we skip over the prompt. But also skip over the shared prefix of what we want to output now, and what we output before, to avoid repeatedly outputting it. */ size_t shared_prefix = line_shared_prefix(o_line, s_line); @@ -771,18 +771,18 @@ static int is_dumb() void s_write( screen_t *s, const wchar_t *prompt, const wchar_t *commandline, - int explicit_len, + size_t explicit_len, const int *c, const int *indent, int cursor ) { - int i; int cursor_arr[2]; - int prompt_width; - int screen_width; + size_t prompt_width; + size_t screen_width; - int max_line_width = 0, current_line_width = 0, newline_count = 0, explicit_portion_width = 0; + int current_line_width = 0, newline_count = 0, explicit_portion_width = 0; + size_t max_line_width = 0; CHECK( s, ); CHECK( prompt, ); @@ -838,8 +838,8 @@ void s_write( screen_t *s, /* Check if we are overflowing */ - int last_char_that_fits = 0; - for( i=0; commandline[i]; i++ ) + size_t last_char_that_fits = 0; + for( size_t i=0; commandline[i]; i++ ) { if( commandline[i] == L'\n' ) { @@ -874,7 +874,7 @@ void s_write( screen_t *s, truncated_autosuggestion_line.push_back(ellipsis_char); commandline = truncated_autosuggestion_line.c_str(); } - for( i=0; idesired.cursor[0] - fish_wcwidth(commandline[i]); cursor_arr[1] = s->desired.cursor[1]; } - } if( i == cursor ) { diff --git a/screen.h b/screen.h index edaba1335..ba72d4af7 100644 --- a/screen.h +++ b/screen.h @@ -147,7 +147,7 @@ class screen_t void s_write( screen_t *s, const wchar_t *prompt, const wchar_t *commandline, - int explicit_len, + size_t explicit_len, const int *colors, const int *indent, int cursor_pos ); diff --git a/set_color.cpp b/set_color.cpp index 33f755c93..667c496cb 100644 --- a/set_color.cpp +++ b/set_color.cpp @@ -58,6 +58,10 @@ */ #define GETOPT_STRING "b:hvocu" +#ifdef _ + #undef _ +#endif + #ifdef USE_GETTEXT #define _(string) gettext(string) #else diff --git a/tokenizer.cpp b/tokenizer.cpp index ae70f3162..1e4704b40 100644 --- a/tokenizer.cpp +++ b/tokenizer.cpp @@ -141,7 +141,7 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags ) tok->accept_unfinished = !! (flags & TOK_ACCEPT_UNFINISHED); tok->show_comments = !! (flags & TOK_SHOW_COMMENTS); tok->squash_errors = !! (flags & TOK_SQUASH_ERRORS); - tok->has_next=1; + tok->has_next=true; tok->has_next = (*b != L'\0'); tok->orig_buff = tok->buff = b; @@ -153,8 +153,6 @@ void tok_destroy( tokenizer *tok ) CHECK( tok, ); free( tok->last ); - if( tok->free_orig ) - free( (void *)tok->orig_buff ); } int tok_last_type( tokenizer *tok ) @@ -432,13 +430,12 @@ static void read_string( tokenizer *tok ) static void read_comment( tokenizer *tok ) { const wchar_t *start; - int len; start = tok->buff; while( *(tok->buff)!= L'\n' && *(tok->buff)!= L'\0' ) tok->buff++; - len = tok->buff - start; + size_t len = tok->buff - start; if( !check_size( tok, len )) return; @@ -553,7 +550,7 @@ void tok_next( tokenizer *tok ) if( tok_last_type( tok ) == TOK_ERROR ) { - tok->has_next=0; + tok->has_next=false; return; } @@ -610,7 +607,7 @@ void tok_next( tokenizer *tok ) case L'\0': tok->last_type = TOK_END; /*fwprintf( stderr, L"End of string\n" );*/ - tok->has_next = 0; + tok->has_next = false; break; case 13: case L'\n': @@ -700,7 +697,7 @@ int tok_get_pos( tokenizer *tok ) { CHECK( tok, 0 ); - return tok->last_pos; + return (int)tok->last_pos; } @@ -709,7 +706,7 @@ void tok_set_pos( tokenizer *tok, int pos ) CHECK( tok, ); tok->buff = tok->orig_buff + pos; - tok->has_next = 1; + tok->has_next = true; tok_next( tok ); } diff --git a/tokenizer.h b/tokenizer.h index ff7c38e90..7287ccd0f 100644 --- a/tokenizer.h +++ b/tokenizer.h @@ -79,15 +79,13 @@ struct tokenizer /** Length of last token*/ size_t last_len; /** Offset of last token*/ - int last_pos; + size_t last_pos; /** Whether there are more tokens*/ - int has_next; + bool has_next; /** Whether incomplete tokens are accepted*/ - int accept_unfinished; + bool accept_unfinished; /** Whether commants should be returned*/ - int show_comments; - /** Flag set to true of the orig_buff points to an internal string that needs to be free()d when deallocating the tokenizer. */ - int free_orig; + bool show_comments; /** Type of last quote, can be either ' or ".*/ wchar_t last_quote; /** Last error */ diff --git a/wgetopt.cpp b/wgetopt.cpp index 517862885..b956b5a52 100644 --- a/wgetopt.cpp +++ b/wgetopt.cpp @@ -179,6 +179,10 @@ static char *posixly_correct; /** Use translation functions if available */ +#ifdef _ + #undef _ +#endif + #ifdef HAVE_TRANSLATE_H #ifdef USE_GETTEXT #define _(string) wgettext(string)