From 203c749e6cc2d5ac0e9e8e240c77d94e179c60d0 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sat, 14 Jan 2012 22:00:00 -0800 Subject: [PATCH] Improved const-correctness, eliminating warnings. Migrated some int to size_t --- env_universal_common.cpp | 16 ++++++++-------- fish_pager.cpp | 6 +++--- fishd.cpp | 2 +- output.cpp | 4 ++-- parser.cpp | 2 +- parser.h | 2 +- reader.cpp | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/env_universal_common.cpp b/env_universal_common.cpp index 5fa6ebe58..2672e5891 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -127,7 +127,7 @@ static int get_names_show_unexported; /** List of names for the UTF-8 character set. */ -static char *iconv_utf8_names[]= +static const char *iconv_utf8_names[]= { "utf-8", "UTF-8", "utf8", "UTF8", @@ -138,7 +138,7 @@ static char *iconv_utf8_names[]= /** List of wide character names, undefined byte length. */ -static char *iconv_wide_names_unknown[]= +static const char *iconv_wide_names_unknown[]= { "wchar_t", "WCHAR_T", "wchar", "WCHAR", @@ -149,7 +149,7 @@ static char *iconv_wide_names_unknown[]= /** List of wide character names, 4 bytes long. */ -static char *iconv_wide_names_4[]= +static const char *iconv_wide_names_4[]= { "wchar_t", "WCHAR_T", "wchar", "WCHAR", @@ -164,7 +164,7 @@ static char *iconv_wide_names_4[]= /** List of wide character names, 2 bytes long. */ -static char *iconv_wide_names_2[]= +static const char *iconv_wide_names_2[]= { "wchar_t", "WCHAR_T", "wchar", "WCHAR", @@ -192,7 +192,7 @@ static wchar_t *utf2wcs( const char *in ) really the character set used by wchar_t, but it is the best assumption we can make. */ - char **to_name=0; + const char **to_name=0; switch (sizeof (wchar_t)) { @@ -214,7 +214,7 @@ static wchar_t *utf2wcs( const char *in ) /* The line protocol fish uses is always utf-8. */ - char **from_name = iconv_utf8_names; + const char **from_name = iconv_utf8_names; size_t in_len = strlen( in ); size_t out_len = sizeof( wchar_t )*(in_len+2); @@ -306,7 +306,7 @@ static char *wcs2utf( const wchar_t *in ) really the character set used by wchar_t, but it is the best assumption we can make. */ - char **from_name=0; + const char **from_name=0; switch (sizeof (wchar_t)) { @@ -324,7 +324,7 @@ static char *wcs2utf( const wchar_t *in ) break; } - char **to_name = iconv_utf8_names; + const char **to_name = iconv_utf8_names; size_t in_len = wcslen( in ); size_t out_len = sizeof( char )*( (MAX_UTF8_BYTES*in_len)+1); diff --git a/fish_pager.cpp b/fish_pager.cpp index b054b818c..4f9c8223d 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -146,7 +146,7 @@ static buffer_t *pager_buffer; The environment variables used to specify the color of different tokens. */ -static wchar_t *hightlight_var[] = +static const wchar_t *hightlight_var[] = { L"fish_pager_color_prefix", L"fish_pager_color_completion", @@ -247,7 +247,7 @@ static void recalc_width( array_list_t *l, const wchar_t *prefix ) Test if the specified character sequence has been entered on the keyboard */ -static int try_sequence( char *seq ) +static int try_sequence( const char *seq ) { int j, k; wint_t c=0; @@ -277,7 +277,7 @@ static wint_t readch() { struct mapping { - char *seq; + const char *seq; wint_t bnd; } ; diff --git a/fishd.cpp b/fishd.cpp index 3177106e1..658aa5319 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -147,7 +147,7 @@ static int quit=0; static char *get_socket_filename() { char *name; - char *dir = getenv( "FISHD_SOCKET_DIR" ); + const char *dir = getenv( "FISHD_SOCKET_DIR" ); char *uname = getenv( "USER" ); if( dir == NULL ) diff --git a/output.cpp b/output.cpp index 8902628ac..0d2490abb 100644 --- a/output.cpp +++ b/output.cpp @@ -67,7 +67,7 @@ static int writeb_internal( char c ); /** Names of different colors. */ -static wchar_t *col[]= +static const wchar_t *col[]= { L"black", L"red", @@ -89,7 +89,7 @@ static wchar_t *col[]= in highlight.h. Non-ANSI terminals will display the wrong colors, since they use a different mapping. */ -static int col_idx[]= +static const int col_idx[]= { 0, 1, diff --git a/parser.cpp b/parser.cpp index bc0f90782..19faedfc3 100644 --- a/parser.cpp +++ b/parser.cpp @@ -1124,7 +1124,7 @@ static int printed_width( const wchar_t *str, int len ) } -wchar_t *parser_current_line() +const wchar_t *parser_current_line() { int lineno=1; diff --git a/parser.h b/parser.h index 0c82f2aae..c3f722220 100644 --- a/parser.h +++ b/parser.h @@ -228,7 +228,7 @@ void error( int ec, int p, const wchar_t *str, ... ); init.fish (line 127): ls|grep pancake */ -wchar_t *parser_current_line(); +const wchar_t *parser_current_line(); /** Returns the current line number diff --git a/reader.cpp b/reader.cpp index da9942331..da41d3a4c 100644 --- a/reader.cpp +++ b/reader.cpp @@ -656,7 +656,7 @@ void reader_write_title() proc_push_interactive(0); if( exec_subshell2( title, lst ) != -1 ) { - int i; + size_t i; if( lst.size() > 0 ) { writestr( L"\x1b]2;" ); @@ -782,7 +782,7 @@ static void remove_backward() static int insert_str(const wchar_t *str) { int len = wcslen( str ); - int old_len = data->buff_len; + size_t old_len = data->buff_len; assert( data->buff_pos >= 0 ); assert( data->buff_pos <= data->buff_len );