diff options
author | Pedro Alves <palves@redhat.com> | 2017-04-05 19:21:34 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-04-05 19:21:34 +0100 |
commit | 67cb5b2da285175d37782f3606992b8052234b00 (patch) | |
tree | 65d0d4fa604cbe93e9650687ee66f211353a89ae /gdb/completer.c | |
parent | 7a1149643d8621541025e2c70e6391e901c8c7ef (diff) | |
download | gdb-67cb5b2da285175d37782f3606992b8052234b00.zip gdb-67cb5b2da285175d37782f3606992b8052234b00.tar.gz gdb-67cb5b2da285175d37782f3606992b8052234b00.tar.bz2 |
-Wwrite-strings: Constify word break character arrays
-Wwrite-strings flags several cases of missing casts around
initializations like:
static char *gdb_completer_command_word_break_characters =
" \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
Obviously these could/should be const. However, while at it, there's
no need for these variables to be pointers instead of arrays. They
are never changed to point to anything else.
Unfortunately, readline's rl_completer_word_break_characters is
"char *", not "const char *". So we always need a cast somewhere. The
approach taken here is to add a new
set_rl_completer_word_break_characters function that becomes the only
place that writes to rl_completer_word_break_characters, and thus the
single place that needs the cast.
gdb/ChangeLog:
2017-04-05 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_completer_word_break_characters): Now a const
array.
(ada_get_gdb_completer_word_break_characters): Constify.
* completer.c (gdb_completer_command_word_break_characters)
(gdb_completer_file_name_break_characters)
(gdb_completer_quote_characters): Now const arrays.
(get_gdb_completer_quote_characters): Constify.
(set_rl_completer_word_break_characters): New function.
(set_gdb_completion_word_break_characters)
(complete_line_internal): Use it.
* completer.h (get_gdb_completer_quote_characters): Constify.
(set_rl_completer_word_break_characters): Declare.
* f-lang.c (f_word_break_characters): Constify.
* language.c (default_word_break_characters): Constify.
* language.h (language_defn::la_word_break_characters): Constify.
(default_word_break_characters): Constify.
* top.c (init_main): Use set_rl_completer_word_break_characters.
Diffstat (limited to 'gdb/completer.c')
-rw-r--r-- | gdb/completer.c | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/gdb/completer.c b/gdb/completer.c index 45adc62..9183e2a 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -84,29 +84,30 @@ char *line_completion_function (const char *text, int matches, readline library sees one in any of the current completion strings, it thinks that the string needs to be quoted and automatically supplies a leading quote. */ -static char *gdb_completer_command_word_break_characters = +static const char gdb_completer_command_word_break_characters[] = " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,"; /* When completing on file names, we remove from the list of word break characters any characters that are commonly used in file names, such as '-', '+', '~', etc. Otherwise, readline displays incorrect completion candidates. */ -#ifdef HAVE_DOS_BASED_FILE_SYSTEM /* MS-DOS and MS-Windows use colon as part of the drive spec, and most programs support @foo style response files. */ -static char *gdb_completer_file_name_break_characters = " \t\n*|\"';?><@"; +static const char gdb_completer_file_name_break_characters[] = +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + " \t\n*|\"';?><@"; #else -static char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?><"; + " \t\n*|\"';:?><"; #endif /* Characters that can be used to quote completion strings. Note that we can't include '"' because the gdb C parser treats such quoted sequences as strings. */ -static char *gdb_completer_quote_characters = "'"; +static const char gdb_completer_quote_characters[] = "'"; /* Accessor for some completer data that may interest other files. */ -char * +const char * get_gdb_completer_quote_characters (void) { return gdb_completer_quote_characters; @@ -652,16 +653,26 @@ expression_completer (struct cmd_list_element *ignore, /* See definition in completer.h. */ void +set_rl_completer_word_break_characters (const char *break_chars) +{ + rl_completer_word_break_characters = (char *) break_chars; +} + +/* See definition in completer.h. */ + +void set_gdb_completion_word_break_characters (completer_ftype *fn) { + const char *break_chars; + /* So far we are only interested in differentiating filename completers from everything else. */ if (fn == filename_completer) - rl_completer_word_break_characters - = gdb_completer_file_name_break_characters; + break_chars = gdb_completer_file_name_break_characters; else - rl_completer_word_break_characters - = gdb_completer_command_word_break_characters; + break_chars = gdb_completer_command_word_break_characters; + + set_rl_completer_word_break_characters (break_chars); } /* Here are some useful test cases for completion. FIXME: These @@ -743,8 +754,8 @@ complete_line_internal (const char *text, then we will switch to the special word break set for command strings, which leaves out the '-' character used in some commands. */ - rl_completer_word_break_characters = - current_language->la_word_break_characters(); + set_rl_completer_word_break_characters + (current_language->la_word_break_characters()); /* Decide whether to complete on a list of gdb commands or on symbols. */ @@ -821,8 +832,8 @@ complete_line_internal (const char *text, } /* Ensure that readline does the right thing with respect to inserting quotes. */ - rl_completer_word_break_characters = - gdb_completer_command_word_break_characters; + set_rl_completer_word_break_characters + (gdb_completer_command_word_break_characters); } } else @@ -848,8 +859,8 @@ complete_line_internal (const char *text, /* Ensure that readline does the right thing with respect to inserting quotes. */ - rl_completer_word_break_characters = - gdb_completer_command_word_break_characters; + set_rl_completer_word_break_characters + (gdb_completer_command_word_break_characters); } else if (reason == handle_help) list = NULL; @@ -857,8 +868,8 @@ complete_line_internal (const char *text, { if (reason != handle_brkchars) list = complete_on_enum (c->enums, p, word); - rl_completer_word_break_characters = - gdb_completer_command_word_break_characters; + set_rl_completer_word_break_characters + (gdb_completer_command_word_break_characters); } else { @@ -879,8 +890,8 @@ complete_line_internal (const char *text, && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL; p--) ; - rl_completer_word_break_characters = - gdb_completer_file_name_break_characters; + set_rl_completer_word_break_characters + (gdb_completer_file_name_break_characters); } if (reason == handle_brkchars && c->completer_handle_brkchars != NULL) @@ -913,8 +924,8 @@ complete_line_internal (const char *text, /* Ensure that readline does the right thing with respect to inserting quotes. */ - rl_completer_word_break_characters = - gdb_completer_command_word_break_characters; + set_rl_completer_word_break_characters + (gdb_completer_command_word_break_characters); } } else if (reason == handle_help) @@ -947,8 +958,8 @@ complete_line_internal (const char *text, p[-1]) == NULL; p--) ; - rl_completer_word_break_characters = - gdb_completer_file_name_break_characters; + set_rl_completer_word_break_characters + (gdb_completer_file_name_break_characters); } if (reason == handle_brkchars && c->completer_handle_brkchars != NULL) |