From 351d7cdd95425ca23f1592e82701159a27720330 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 6 Apr 2025 19:30:53 +0200 Subject: [PATCH] i9e: Constify i9e_complete_option(). i9e_extract_completions() and i9e_complete_option() both take a char ** argument for the option/string list although they do not modify the pointers of the list. This commit marks these pointer variables constant. --- audioc.c | 8 ++++---- client.c | 24 ++++++++++++------------ interactive.c | 11 +++++------ interactive.h | 6 +++--- play.c | 2 +- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/audioc.c b/audioc.c index f2e4cb91..45b5e12c 100644 --- a/audioc.c +++ b/audioc.c @@ -98,7 +98,7 @@ I9E_DUMMY_COMPLETER(term); static void help_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_AUDIOD_CMD_HELP_OPTS, NULL}; + char * const opts[] = {LSG_AUDIOD_CMD_HELP_OPTS, NULL}; if (ci->word[0] == '-') { i9e_complete_option(opts, ci, cr); @@ -116,7 +116,7 @@ static void ll_completer(struct i9e_completion_info *ci, static void version_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_AUDIOD_CMD_VERSION_OPTS, NULL}; + char * const opts[] = {LSG_AUDIOD_CMD_VERSION_OPTS, NULL}; if (ci->word_num <= 2 && ci->word && ci->word[0] == '-') i9e_complete_option(opts, ci, cr); @@ -126,7 +126,7 @@ static void stat_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { char *sia[] = {STATUS_ITEMS NULL}; - char *opts[] = {LSG_AUDIOD_CMD_STAT_OPTS, NULL}; + char * const opts[] = {LSG_AUDIOD_CMD_STAT_OPTS, NULL}; if (ci->word_num <= 2 && ci->word && ci->word[0] == '-') i9e_complete_option(opts, ci, cr); @@ -137,7 +137,7 @@ static void stat_completer(struct i9e_completion_info *ci, static void grab_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_AUDIOD_CMD_GRAB_OPTS, NULL}; + char * const opts[] = {LSG_AUDIOD_CMD_GRAB_OPTS, NULL}; i9e_complete_option(opts, ci, cr); } diff --git a/client.c b/client.c index 14b98b76..a0def4ae 100644 --- a/client.c +++ b/client.c @@ -209,7 +209,7 @@ static void complete_lsblob(const char *blob_type, struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_LSIMG_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_LSIMG_OPTS, NULL}; if (ci->word[0] == '-') return i9e_complete_option(opts, ci, cr); @@ -255,7 +255,7 @@ static void ll_completer(struct i9e_completion_info *ci, static void help_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_HELP_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_HELP_OPTS, NULL}; if (ci->word[0] == '-') { i9e_complete_option(opts, ci, cr); @@ -267,14 +267,14 @@ static void help_completer(struct i9e_completion_info *ci, static void stat_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_STAT_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_STAT_OPTS, NULL}; i9e_complete_option(opts, ci, cr); } static void version_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_VERSION_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_VERSION_OPTS, NULL}; i9e_complete_option(opts, ci, cr); } @@ -311,7 +311,7 @@ static void sender_completer(struct i9e_completion_info *ci, static void add_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_ADD_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_ADD_OPTS, NULL}; if (ci->word[0] == '-') i9e_complete_option(opts, ci, cr); @@ -321,7 +321,7 @@ static void add_completer(struct i9e_completion_info *ci, static void ls_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_LS_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_LS_OPTS, NULL}; if (ci->word[0] == '-') i9e_complete_option(opts, ci, cr); cr->filename_completion_desired = true; @@ -364,7 +364,7 @@ out: static void lsatt_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_LSATT_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_LSATT_OPTS, NULL}; i9e_complete_option(opts, ci, cr); } @@ -383,14 +383,14 @@ static void rmatt_completer(struct i9e_completion_info *ci, static void check_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_CHECK_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_CHECK_OPTS, NULL}; i9e_complete_option(opts, ci, cr); } static void rm_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_RM_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_RM_OPTS, NULL}; if (ci->word[0] == '-') { i9e_complete_option(opts, ci, cr); @@ -402,7 +402,7 @@ static void rm_completer(struct i9e_completion_info *ci, static void touch_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_TOUCH_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_TOUCH_OPTS, NULL}; if (ci->word[0] == '-') i9e_complete_option(opts, ci, cr); @@ -412,7 +412,7 @@ static void touch_completer(struct i9e_completion_info *ci, static void cpsi_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_CPSI_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_CPSI_OPTS, NULL}; if (ci->word[0] == '-') i9e_complete_option(opts, ci, cr); @@ -422,7 +422,7 @@ static void cpsi_completer(struct i9e_completion_info *ci, static void select_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_SERVER_CMD_SELECT_OPTS, NULL}; + char * const opts[] = {LSG_SERVER_CMD_SELECT_OPTS, NULL}; char *mood_buf, *pl_buf, **moods, **playlists, **mops; int num_moods, num_pl, i, n, ret; diff --git a/interactive.c b/interactive.c index 3115d539..77f3fc60 100644 --- a/interactive.c +++ b/interactive.c @@ -631,15 +631,14 @@ int i9e_poll(struct pollfd *fds, nfds_t nfds, int timeout) * * \return The number of possible completions. */ -int i9e_extract_completions(const char *word, char **string_list, +int i9e_extract_completions(const char *word, char * const *string_list, char ***result) { char **matches = alloc(sizeof(char *)); int match_count = 0, matches_len = 1; - char **p; int len = strlen(word); - for (p = string_list; *p; p++) { + for (char * const *p = string_list; *p; p++) { if (!is_prefix(word, *p, len)) continue; match_count++; @@ -707,8 +706,8 @@ char **i9e_complete_commands(const char *word, struct i9e_completer *completers) * character is appended to the output. For non-flag options no space character * is appended. */ -void i9e_complete_option(char **opts, struct i9e_completion_info *ci, - struct i9e_completion_result *cr) +void i9e_complete_option(char * const *opts, + struct i9e_completion_info *ci, struct i9e_completion_result *cr) { int num_matches; @@ -808,7 +807,7 @@ create_matches: void i9e_ll_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *sev[] = {SEVERITIES, NULL}; + char * const sev[] = {SEVERITIES, NULL}; if (ci->word_num != 1) { cr->matches = NULL; diff --git a/interactive.h b/interactive.h index 1dbaaddb..7ab9778f 100644 --- a/interactive.h +++ b/interactive.h @@ -85,11 +85,11 @@ void i9e_close(void); void i9e_signal_dispatch(int sig_num); __printf_2_3 void i9e_log(int ll, const char* fmt,...); int i9e_poll(struct pollfd *fds, nfds_t nfds, int timeout); -int i9e_extract_completions(const char *word, char **string_list, +int i9e_extract_completions(const char *word, char * const *string_list, char ***result); char **i9e_complete_commands(const char *word, struct i9e_completer *completers); -void i9e_complete_option(char **opts, struct i9e_completion_info *ci, - struct i9e_completion_result *cr); +void i9e_complete_option(char * const *opts, + struct i9e_completion_info *ci, struct i9e_completion_result *cr); int i9e_print_completions(struct i9e_completer *completers); int i9e_get_error(void); void i9e_ll_completer(struct i9e_completion_info *ci, diff --git a/play.c b/play.c index 359eb371..bc789116 100644 --- a/play.c +++ b/play.c @@ -663,7 +663,7 @@ I9E_DUMMY_COMPLETER(ff); static void help_completer(struct i9e_completion_info *ci, struct i9e_completion_result *cr) { - char *opts[] = {LSG_PLAY_CMD_HELP_OPTS, NULL}; + char * const opts[] = {LSG_PLAY_CMD_HELP_OPTS, NULL}; if (ci->word[0] == '-') { i9e_complete_option(opts, ci, cr); -- 2.39.5