From 29a84b5f44ed6017b2e66b92739c1e63d43b5c88 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 18 Feb 2022 14:42:25 +0100 Subject: [PATCH] [cmdline] const return value --- src/config/cmdline.c | 18 +++++++++--------- src/config/options.c | 2 +- src/config/options.h | 2 +- src/config/opttypes.c | 10 +++++----- src/config/opttypes.h | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/config/cmdline.c b/src/config/cmdline.c index 3154420a..c2f840f3 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -59,7 +59,7 @@ parse_options_(int argc, char *argv[], struct option *opt, struct option *option; char *argname = &argv[-1][1]; char *oname = stracpy(argname); - char *err; + const char *err; if (!oname) continue; @@ -132,7 +132,7 @@ parse_options(int argc, char *argv[], Options handlers **********************************************************************/ -static char * +static const char * eval_cmd(struct option *o, char ***argv, int *argc) { if (*argc < 1) return gettext("Parameter expected"); @@ -146,14 +146,14 @@ eval_cmd(struct option *o, char ***argv, int *argc) return NULL; } -static char * +static const char * forcehtml_cmd(struct option *o, char ***argv, int *argc) { safe_strncpy(get_opt_str("mime.default_type", NULL), "text/html", MAX_STR_LEN); return NULL; } -static char * +static const char * lookup_cmd(struct option *o, char ***argv, int *argc) { struct sockaddr_storage *addrs = NULL; @@ -242,7 +242,7 @@ struct remote_method { enum remote_method_enum type; }; -static char * +static const char * remote_cmd(struct option *o, char ***argv, int *argc) { struct remote_method remote_methods[] = { @@ -451,7 +451,7 @@ remote_cmd(struct option *o, char ***argv, int *argc) return NULL; } -static char * +static const char * version_cmd(struct option *o, char ***argv, int *argc) { printf("%s\n", full_static_version); @@ -697,7 +697,7 @@ print_short_help(void) #undef gettext_nonempty -static char * +static const char * printhelp_cmd(struct option *option, char ***argv, int *argc) { char *lineend = strchr(full_static_version, '\n'); @@ -724,7 +724,7 @@ printhelp_cmd(struct option *option, char ***argv, int *argc) return ""; } -static char * +static const char * redir_cmd(struct option *option, char ***argv, int *argc) { char *target; @@ -763,7 +763,7 @@ redir_cmd(struct option *option, char ***argv, int *argc) return NULL; } -static char * +static const char * printconfigdump_cmd(struct option *option, char ***argv, int *argc) { char *config_string; diff --git a/src/config/options.c b/src/config/options.c index 3d2c1e2d..4f645648 100644 --- a/src/config/options.c +++ b/src/config/options.c @@ -563,7 +563,7 @@ add_opt(struct option *tree, const char *path, const char *capt, &option->value.color); break; case OPT_COMMAND: - option->value.command = (char * (*)(struct option_elinks *, char ***, int *))value; + option->value.command = (const char * (*)(struct option_elinks *, char ***, int *))value; break; case OPT_LANGUAGE: break; diff --git a/src/config/options.h b/src/config/options.h index d21fc4ca..6bcfc9fb 100644 --- a/src/config/options.h +++ b/src/config/options.h @@ -139,7 +139,7 @@ struct session; /* session/session.h */ * * @return NULL if successful, or a localized error string that the * caller will not free. */ -typedef char *option_command_fn_T(struct option *option, +typedef const char *option_command_fn_T(struct option *option, char ***argv, int *argc); union option_value { diff --git a/src/config/opttypes.c b/src/config/opttypes.c index 108d994f..cd0e012f 100644 --- a/src/config/opttypes.c +++ b/src/config/opttypes.c @@ -29,7 +29,7 @@ * since you will parse the commandline _TWO TIMES_! Remember! :-) */ int commandline = 0; -static char * +static const char * gen_cmd(struct option *o, char ***argv, int *argc) { char *str; @@ -56,7 +56,7 @@ gen_cmd(struct option *o, char ***argv, int *argc) /* If 0 follows, disable option and eat 0. If 1 follows, enable option and * eat 1. If anything else follow, enable option and don't eat anything. */ -static char * +static const char * bool_cmd(struct option *o, char ***argv, int *argc) { o->value.number = 1; @@ -77,7 +77,7 @@ bool_cmd(struct option *o, char ***argv, int *argc) return NULL; } -static char * +static const char * exec_cmd(struct option *o, char ***argv, int *argc) { return o->value.command(o, argv, argc); @@ -90,11 +90,11 @@ exec_cmd(struct option *o, char ***argv, int *argc) * possibly changing ptr to structure containing target name and pointer to * options list? --pasky */ -static char * +static const char * redir_cmd(struct option *opt, char ***argv, int *argc) { struct option *real = get_opt_rec(config_options, opt->value.string); - char * ret = NULL; + const char *ret = NULL; assertm(real != NULL, "%s aliased to unknown option %s!", opt->name, opt->value.string); if_assert_failed { return ret; } diff --git a/src/config/opttypes.h b/src/config/opttypes.h index 8138a437..ccc23f40 100644 --- a/src/config/opttypes.h +++ b/src/config/opttypes.h @@ -10,7 +10,7 @@ extern "C" { struct option_type_info { char *name; - char *(*cmdline)(struct option *, char ***, int *); + const char *(*cmdline)(struct option *, char ***, int *); char *(*read)(struct option *, char **, int *); void (*write)(struct option *, struct string *); void (*dup)(struct option *, struct option *, int);