[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Make some things const which need to be
From: |
John Darrington |
Subject: |
[PATCH] Make some things const which need to be |
Date: |
Sun, 1 Mar 2020 19:38:38 +0100 |
---
src/pk-cmd.c | 62 ++++++++++++++++++++++++-------------------------
src/pk-cmd.h | 2 +-
src/pk-def.c | 4 ++--
src/pk-editor.c | 2 +-
src/pk-help.c | 4 ++--
src/pk-info.c | 6 ++---
src/pk-ios.c | 12 +++++-----
src/pk-misc.c | 8 +++----
src/pk-set.c | 24 +++++++++----------
src/pk-vm.c | 20 ++++++++--------
src/pvm-val.c | 2 +-
11 files changed, 73 insertions(+), 73 deletions(-)
diff --git a/src/pk-cmd.c b/src/pk-cmd.c
index e920f5a9..07b3d6c3 100644
--- a/src/pk-cmd.c
+++ b/src/pk-cmd.c
@@ -41,24 +41,24 @@
/* Table of supported commands. */
-extern struct pk_cmd ios_cmd; /* pk-ios.c */
-extern struct pk_cmd file_cmd; /* pk-ios.c */
-extern struct pk_cmd mem_cmd; /* pk-ios.c */
-extern struct pk_cmd close_cmd; /* pk-file.c */
-extern struct pk_cmd load_cmd; /* pk-file.c */
-extern struct pk_cmd info_cmd; /* pk-info.c */
-extern struct pk_cmd exit_cmd; /* pk-misc.c */
-extern struct pk_cmd version_cmd; /* pk-misc.c */
-extern struct pk_cmd doc_cmd; /* pk-misc.c */
-extern struct pk_cmd jmd_cmd; /* pk-misc.c */
-extern struct pk_cmd help_cmd; /* pk-help.c */
-extern struct pk_cmd vm_cmd; /* pk-vm.c */
-extern struct pk_cmd set_cmd; /* pk-set.c */
-extern struct pk_cmd editor_cmd; /* pk-editor.c */
-
-struct pk_cmd null_cmd = {};
-
-static struct pk_cmd *dot_cmds[] =
+extern const struct pk_cmd ios_cmd; /* pk-ios.c */
+extern const struct pk_cmd file_cmd; /* pk-ios.c */
+extern const struct pk_cmd mem_cmd; /* pk-ios.c */
+extern const struct pk_cmd close_cmd; /* pk-file.c */
+extern const struct pk_cmd load_cmd; /* pk-file.c */
+extern const struct pk_cmd info_cmd; /* pk-info.c */
+extern const struct pk_cmd exit_cmd; /* pk-misc.c */
+extern const struct pk_cmd version_cmd; /* pk-misc.c */
+extern const struct pk_cmd doc_cmd; /* pk-misc.c */
+extern const struct pk_cmd jmd_cmd; /* pk-misc.c */
+extern const struct pk_cmd help_cmd; /* pk-help.c */
+extern const struct pk_cmd vm_cmd; /* pk-vm.c */
+extern const struct pk_cmd set_cmd; /* pk-set.c */
+extern const struct pk_cmd editor_cmd; /* pk-editor.c */
+
+const struct pk_cmd null_cmd = {};
+
+static const struct pk_cmd *dot_cmds[] =
{
&ios_cmd,
&file_cmd,
@@ -116,7 +116,7 @@ struct pk_trie
struct pk_trie *parent;
int num_children;
struct pk_trie *children[256];
- struct pk_cmd *cmd;
+ const struct pk_cmd *cmd;
};
static struct pk_trie *
@@ -176,12 +176,12 @@ pk_trie_expand_cmds (struct pk_trie *root,
}
static struct pk_trie *
-pk_trie_from_cmds (struct pk_cmd *cmds[])
+pk_trie_from_cmds (const struct pk_cmd *cmds[])
{
size_t i;
struct pk_trie *root;
struct pk_trie *t;
- struct pk_cmd *cmd;
+ const struct pk_cmd *cmd;
root = pk_trie_new (' ', NULL);
t = root;
@@ -213,7 +213,7 @@ pk_trie_from_cmds (struct pk_cmd *cmds[])
return root;
}
-static struct pk_cmd *
+static const struct pk_cmd *
pk_trie_get_cmd (struct pk_trie *trie, const char *str)
{
const char *pc;
@@ -264,7 +264,7 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char
*prefix)
int ret = 1;
size_t i;
char cmd_name[MAX_CMD_NAME], *p;
- struct pk_cmd *cmd;
+ const struct pk_cmd *cmd;
int argc = 0;
struct pk_cmd_arg argv[8];
uint64_t uflags;
@@ -575,19 +575,19 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char
*prefix)
#undef GOTO_USAGE
}
-extern struct pk_cmd *info_cmds[]; /* pk-info.c */
+extern const struct pk_cmd *info_cmds[]; /* pk-info.c */
extern struct pk_trie *info_trie; /* pk-info.c */
-extern struct pk_cmd *help_cmds[]; /* pk-help.c */
+extern const struct pk_cmd *help_cmds[]; /* pk-help.c */
extern struct pk_trie *help_trie; /* pk-help.c */
-extern struct pk_cmd *vm_cmds[]; /* pk-vm.c */
+extern const struct pk_cmd *vm_cmds[]; /* pk-vm.c */
extern struct pk_trie *vm_trie; /* pk-vm.c */
-extern struct pk_cmd *vm_disas_cmds[]; /* pk-vm.c */
+extern const struct pk_cmd *vm_disas_cmds[]; /* pk-vm.c */
extern struct pk_trie *vm_disas_trie; /* pk-vm.c */
-extern struct pk_cmd *set_cmds[]; /* pk-set.c */
+extern const struct pk_cmd *set_cmds[]; /* pk-set.c */
extern struct pk_trie *set_trie; /* pk-set.c */
static struct pk_trie *cmds_trie;
@@ -784,7 +784,7 @@ pk_cmd_get_next_match (int *idx, const char *x, size_t len)
/* Dot commands */
for (;;)
{
- struct pk_cmd **c = dot_cmds + *idx;
+ const struct pk_cmd **c = dot_cmds + *idx;
if (*c == &null_cmd)
break;
@@ -807,12 +807,12 @@ pk_cmd_get_next_match (int *idx, const char *x, size_t
len)
/* Search for a command which matches cmdname.
Returns NULL if no such command exists. */
-struct pk_cmd *
+const struct pk_cmd *
pk_cmd_find (const char *cmdname)
{
if (cmdname != NULL)
{
- struct pk_cmd **c;
+ const struct pk_cmd **c;
for (c = dot_cmds; *c != &null_cmd; ++c)
{
/* Check if the command name matches.
diff --git a/src/pk-cmd.h b/src/pk-cmd.h
index 90d31e4f..c2ecc3fa 100644
--- a/src/pk-cmd.h
+++ b/src/pk-cmd.h
@@ -111,6 +111,6 @@ void pk_cmd_shutdown (void);
char *pk_cmd_get_next_match (int *idx, const char *x, size_t len);
-struct pk_cmd *pk_cmd_find (const char *cmdname);
+const struct pk_cmd *pk_cmd_find (const char *cmdname);
#endif /* ! PK_H_CMD */
diff --git a/src/pk-def.c b/src/pk-def.c
index 9325009e..f718c525 100644
--- a/src/pk-def.c
+++ b/src/pk-def.c
@@ -127,10 +127,10 @@ pk_cmd_info_fun (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
return 1;
}
-struct pk_cmd info_var_cmd =
+const struct pk_cmd info_var_cmd =
{"variable", "", "", 0, NULL, pk_cmd_info_var,
"info variable", NULL};
-struct pk_cmd info_fun_cmd =
+const struct pk_cmd info_fun_cmd =
{"function", "", "", 0, NULL, pk_cmd_info_fun,
"info funtion", NULL};
diff --git a/src/pk-editor.c b/src/pk-editor.c
index ad2f33cc..652cb4c4 100644
--- a/src/pk-editor.c
+++ b/src/pk-editor.c
@@ -136,5 +136,5 @@ pk_cmd_editor (int argc, struct pk_cmd_arg argv[], uint64_t
uflags)
return 1;
}
-struct pk_cmd editor_cmd =
+const struct pk_cmd editor_cmd =
{"editor", "", "", 0, NULL, pk_cmd_editor, ".editor", NULL};
diff --git a/src/pk-help.c b/src/pk-help.c
index ae5cc665..d0fad926 100644
--- a/src/pk-help.c
+++ b/src/pk-help.c
@@ -21,12 +21,12 @@
extern struct pk_cmd null_cmd; /* pk-cmd.c */
-struct pk_cmd *help_cmds[] =
+const struct pk_cmd *help_cmds[] =
{
&null_cmd
};
struct pk_trie *help_trie;
-struct pk_cmd help_cmd =
+const struct pk_cmd help_cmd =
{"help", "", "", 0, &help_trie, NULL, "help COMMAND", NULL};
diff --git a/src/pk-info.c b/src/pk-info.c
index bcb9a002..b2261d9e 100644
--- a/src/pk-info.c
+++ b/src/pk-info.c
@@ -24,7 +24,7 @@ extern struct pk_cmd info_ios_cmd; /* pk-ios.c */
extern struct pk_cmd info_var_cmd; /* pk-def.c */
extern struct pk_cmd info_fun_cmd; /* pk-def.c */
-struct pk_cmd *info_cmds[] =
+const struct pk_cmd * info_cmds[] =
{
&info_ios_cmd,
&info_var_cmd,
@@ -46,7 +46,7 @@ info_completion_function (const char *x, int state)
size_t len = strlen (x);
while (1)
{
- struct pk_cmd **c = info_cmds + idx;
+ const struct pk_cmd **c = info_cmds + idx;
if (*c == &null_cmd)
break;
@@ -63,6 +63,6 @@ info_completion_function (const char *x, int state)
}
-struct pk_cmd info_cmd =
+const struct pk_cmd info_cmd =
{"info", "", "", 0, &info_trie, NULL, "info (ios|variable|function)",
info_completion_function};
diff --git a/src/pk-ios.c b/src/pk-ios.c
index 01896d87..b8853c45 100644
--- a/src/pk-ios.c
+++ b/src/pk-ios.c
@@ -310,20 +310,20 @@ pk_cmd_mem (int argc, struct pk_cmd_arg argv[], uint64_t
uflags)
return 1;
}
-struct pk_cmd ios_cmd =
+const struct pk_cmd ios_cmd =
{"ios", "t", "", 0, NULL, pk_cmd_ios, "ios #ID", ios_completion_function};
-struct pk_cmd file_cmd =
+const struct pk_cmd file_cmd =
{"file", "f", "", 0, NULL, pk_cmd_file, "file FILENAME",
rl_filename_completion_function};
-struct pk_cmd mem_cmd =
+const struct pk_cmd mem_cmd =
{"mem", "s", "", 0, NULL, pk_cmd_mem, "mem NAME", NULL};
-struct pk_cmd close_cmd =
+const struct pk_cmd close_cmd =
{"close", "?t", "", PK_CMD_F_REQ_IO, NULL, pk_cmd_close, "close [#ID]",
ios_completion_function};
-struct pk_cmd info_ios_cmd =
+const struct pk_cmd info_ios_cmd =
{"ios", "", "", 0, NULL, pk_cmd_info_ios, "info ios", NULL};
-struct pk_cmd load_cmd =
+const struct pk_cmd load_cmd =
{"load", "f", "", 0, NULL, pk_cmd_load_file, "load FILENAME",
rl_filename_completion_function};
diff --git a/src/pk-misc.c b/src/pk-misc.c
index 44717e6b..b72d647a 100644
--- a/src/pk-misc.c
+++ b/src/pk-misc.c
@@ -207,14 +207,14 @@ doc_completion_function (const char *x, int state)
}
-struct pk_cmd exit_cmd =
+const struct pk_cmd exit_cmd =
{"exit", "?i", "", 0, NULL, pk_cmd_exit, "exit [CODE]", NULL};
-struct pk_cmd version_cmd =
+const struct pk_cmd version_cmd =
{"version", "", "", 0, NULL, pk_cmd_version, "version", NULL};
-struct pk_cmd jmd_cmd =
+const struct pk_cmd jmd_cmd =
{"jmd", "", "", 0, NULL, pk_cmd_jmd, "jmd", NULL};
-struct pk_cmd doc_cmd =
+const struct pk_cmd doc_cmd =
{"doc", "?s", "", 0, NULL, pk_cmd_doc, "doc [section]",
doc_completion_function};
diff --git a/src/pk-set.c b/src/pk-set.c
index fbad933d..2c0f72be 100644
--- a/src/pk-set.c
+++ b/src/pk-set.c
@@ -393,36 +393,36 @@ pk_cmd_set_error_on_warning (int argc, struct pk_cmd_arg
argv[],
extern struct pk_cmd null_cmd; /* pk-cmd.c */
-struct pk_cmd set_oacutoff_cmd =
+const struct pk_cmd set_oacutoff_cmd =
{"oacutoff", "?i", "", 0, NULL, pk_cmd_set_oacutoff, "set oacutoff
[CUTOFF]", NULL};
-struct pk_cmd set_oindent_cmd =
+const struct pk_cmd set_oindent_cmd =
{"oindent", "?i", "", 0, NULL, pk_cmd_set_oindent, "set oindent [INDENT]",
NULL};
-struct pk_cmd set_odepth_cmd =
+const struct pk_cmd set_odepth_cmd =
{"odepth", "?i", "", 0, NULL, pk_cmd_set_odepth, "set odepth [DEPTH]", NULL};
-struct pk_cmd set_omode_cmd =
+const struct pk_cmd set_omode_cmd =
{"omode", "?s", "", 0, NULL, pk_cmd_set_omode, "set omode (normal|tree)",
NULL};
-struct pk_cmd set_obase_cmd =
+const struct pk_cmd set_obase_cmd =
{"obase", "?i", "", 0, NULL, pk_cmd_set_obase, "set obase (2|8|10|16)",
NULL};
-struct pk_cmd set_endian_cmd =
+const struct pk_cmd set_endian_cmd =
{"endian", "?s", "", 0, NULL, pk_cmd_set_endian, "set endian
(little|big|host)", NULL};
-struct pk_cmd set_nenc_cmd =
+const struct pk_cmd set_nenc_cmd =
{"nenc", "?s", "", 0, NULL, pk_cmd_set_nenc, "set nenc (1c|2c)", NULL};
-struct pk_cmd set_pretty_print_cmd =
+const struct pk_cmd set_pretty_print_cmd =
{"pretty-print", "s?", "", 0, NULL, pk_cmd_set_pretty_print,
"set pretty-print (yes|no)", NULL};
-struct pk_cmd set_error_on_warning_cmd =
+const struct pk_cmd set_error_on_warning_cmd =
{"error-on-warning", "s?", "", 0, NULL, pk_cmd_set_error_on_warning,
"set error-on-warning (yes|no)", NULL};
-struct pk_cmd *set_cmds[] =
+const struct pk_cmd *set_cmds[] =
{
&set_oacutoff_cmd,
&set_obase_cmd,
@@ -448,7 +448,7 @@ set_completion_function (const char *x, int state)
int len = strlen (x);
while (1)
{
- struct pk_cmd **c = set_cmds + idx;
+ const struct pk_cmd **c = set_cmds + idx;
if (*c == &null_cmd)
break;
@@ -471,5 +471,5 @@ set_completion_function (const char *x, int state)
struct pk_trie *set_trie;
-struct pk_cmd set_cmd =
+const struct pk_cmd set_cmd =
{"set", "", "", 0, &set_trie, NULL, "set PROPERTY", set_completion_function};
diff --git a/src/pk-vm.c b/src/pk-vm.c
index 8a9dfb6f..5935bd56 100644
--- a/src/pk-vm.c
+++ b/src/pk-vm.c
@@ -177,31 +177,31 @@ pk_cmd_vm_disas_writ (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
extern struct pk_cmd null_cmd; /* pk-cmd.c */
-struct pk_cmd vm_disas_exp_cmd =
+const struct pk_cmd vm_disas_exp_cmd =
{"expression", "e", PK_VM_DIS_UFLAGS, 0, NULL, pk_cmd_vm_disas_exp,
"vm disassemble expression[/n] EXP\n\
Flags:\n\
n (do a native disassemble)", NULL};
-struct pk_cmd vm_disas_fun_cmd =
+const struct pk_cmd vm_disas_fun_cmd =
{"function", "s", PK_VM_DIS_UFLAGS, 0, NULL, pk_cmd_vm_disas_fun,
"vm disassemble function[/n] FUNCTION_NAME\n\
Flags:\n\
n (do a native disassemble)", NULL};
-struct pk_cmd vm_disas_map_cmd =
+const struct pk_cmd vm_disas_map_cmd =
{"mapper", "e", PK_VM_DIS_UFLAGS, 0, NULL, pk_cmd_vm_disas_map,
"vm disassemble mapper[/n] EXPRESSION\n\
Flags:\n\
n (do a native disassemble)", NULL};
-struct pk_cmd vm_disas_wri_cmd =
+const struct pk_cmd vm_disas_wri_cmd =
{"writter", "e", PK_VM_DIS_UFLAGS, 0, NULL, pk_cmd_vm_disas_writ,
"vm disassemble writer[/n] EXPRESSION\n\
Flags:\n\
n (do a native disassemble)", NULL};
-struct pk_cmd *vm_disas_cmds[] =
+const struct pk_cmd *vm_disas_cmds[] =
{
&vm_disas_exp_cmd,
&vm_disas_fun_cmd,
@@ -212,17 +212,17 @@ struct pk_cmd *vm_disas_cmds[] =
struct pk_trie *vm_disas_trie;
-struct pk_cmd vm_disas_cmd =
+const struct pk_cmd vm_disas_cmd =
{"disassemble", "e", PK_VM_DIS_UFLAGS, 0, &vm_disas_trie, NULL,
"vm disassemble (expression|function)", NULL};
-struct pk_cmd *vm_cmds[] =
+struct pk_trie *vm_trie;
+
+const struct pk_cmd *vm_cmds[] =
{
&vm_disas_cmd,
&null_cmd
};
-struct pk_trie *vm_trie;
-
-struct pk_cmd vm_cmd =
+const struct pk_cmd vm_cmd =
{"vm", "", "", 0, &vm_trie, NULL, "vm (disassemble)", NULL};
diff --git a/src/pvm-val.c b/src/pvm-val.c
index 92ed3367..e44e9544 100644
--- a/src/pvm-val.c
+++ b/src/pvm-val.c
@@ -30,7 +30,7 @@
#define STREQ(a, b) (strcmp (a, b) == 0)
-unsigned int pk_odepth;
+static unsigned int pk_odepth;
pvm_val
pvm_make_int (int32_t value, int size)
--
2.20.1
- [PATCH] Make some things const which need to be,
John Darrington <=