From f29228bbdcffdc8810ff8c766a05c6ca63a42086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 12 Feb 2016 15:57:26 +0100 Subject: Mark some tables as const This allows them to be placed into the read only ELF section. --- main.c | 4 ++-- view.c | 2 +- vis-cmds.c | 16 ++++++++-------- vis-core.h | 6 +++--- vis-motions.c | 2 +- vis-operators.c | 4 ++-- vis-text-objects.c | 2 +- vis.c | 2 +- vis.h | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/main.c b/main.c index 30e559a..9169005 100644 --- a/main.c +++ b/main.c @@ -281,7 +281,7 @@ enum { VIS_ACTION_NOP, }; -static KeyAction vis_action[] = { +static const KeyAction vis_action[] = { [VIS_ACTION_EDITOR_SUSPEND] = { "editor-suspend", "Suspend the editor", @@ -1769,7 +1769,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; for (int i = 0; i < LENGTH(vis_action); i++) { - KeyAction *action = &vis_action[i]; + const KeyAction *action = &vis_action[i]; if (!vis_action_register(vis, action)) vis_die(vis, "Could not register action: %s\n", action->name); } diff --git a/view.c b/view.c index abbc3a5..3afa3e8 100644 --- a/view.c +++ b/view.c @@ -1006,7 +1006,7 @@ const char *view_syntax_get(View *view) { } void view_options_set(View *view, enum UiOption options) { - int mapping[] = { + const int mapping[] = { [SYNTAX_SYMBOL_SPACE] = UI_OPTION_SYMBOL_SPACE, [SYNTAX_SYMBOL_TAB] = UI_OPTION_SYMBOL_TAB, [SYNTAX_SYMBOL_TAB_FILL] = UI_OPTION_SYMBOL_TAB_FILL, diff --git a/vis-cmds.c b/vis-cmds.c index ecb13c0..1aa8445 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -94,7 +94,7 @@ static bool cmd_unmap(Vis*, Filerange*, enum CmdOpt, const char *argv[]); * prefix match. that is if a command should be available under an abbreviation * which is a prefix for another command it has to be added as an alias. the * long human readable name should always come first */ -static Command cmds[] = { +static const Command cmds[] = { /* command name / optional alias, function, options */ { { "bdelete" }, cmd_bdelete, CMD_OPT_FORCE }, { { "edit", "e" }, cmd_edit, CMD_OPT_FORCE }, @@ -290,8 +290,8 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * vis_info_show(vis, "Expecting: spaces, tabs, newlines"); return false; } - char *keys[] = { "spaces", "tabs", "newlines" }; - int values[] = { + const char *keys[] = { "spaces", "tabs", "newlines" }; + const int values[] = { UI_OPTION_SYMBOL_SPACE, UI_OPTION_SYMBOL_TAB|UI_OPTION_SYMBOL_TAB_FILL, UI_OPTION_SYMBOL_EOL, @@ -1003,7 +1003,7 @@ static bool cmd_help(Vis *vis, Filerange *range, enum CmdOpt opt, const char *ar print_mode(&vis_modes[VIS_MODE_INSERT], txt); text_appendf(txt, "\n :-Commands\n\n"); - for (Command *cmd = cmds; cmd && cmd->name[0]; cmd++) + for (const Command *cmd = cmds; cmd && cmd->name[0]; cmd++) text_appendf(txt, " %s\n", cmd->name[0]); text_appendf(txt, "\n Key binding actions\n\n"); @@ -1191,13 +1191,13 @@ static Filerange parse_range(Win *win, char **cmd) { return r; } -static Command *lookup_cmd(Vis *vis, const char *name) { +static const Command *lookup_cmd(Vis *vis, const char *name) { if (!vis->cmds) { if (!(vis->cmds = map_new())) return NULL; - for (Command *cmd = cmds; cmd && cmd->name[0]; cmd++) { - for (const char **name = cmd->name; *name; name++) + for (const Command *cmd = cmds; cmd && cmd->name[0]; cmd++) { + for (const char *const *name = cmd->name; *name; name++) map_put(vis->cmds, *name, cmd); } } @@ -1253,7 +1253,7 @@ bool vis_cmd(Vis *vis, const char *cmdline) { memmove(param+1, param, strlen(param)+1); *param++ = '\0'; /* separate command name from parameters */ - Command *cmd = lookup_cmd(vis, name); + const Command *cmd = lookup_cmd(vis, name); if (!cmd) { vis_info_show(vis, "Not an editor command"); free(line); diff --git a/vis-core.h b/vis-core.h index 74b8940..5939115 100644 --- a/vis-core.h +++ b/vis-core.h @@ -168,9 +168,9 @@ struct Vis { /** stuff used by multiple of the vis-* files */ extern Mode vis_modes[VIS_MODE_INVALID]; -extern Movement vis_motions[VIS_MOVE_INVALID]; -extern Operator vis_operators[VIS_OP_INVALID]; -extern TextObject vis_textobjects[VIS_TEXTOBJECT_INVALID]; +extern const Movement vis_motions[VIS_MOVE_INVALID]; +extern const Operator vis_operators[VIS_OP_INVALID]; +extern const TextObject vis_textobjects[VIS_TEXTOBJECT_INVALID]; void macro_operator_stop(Vis *vis); void macro_operator_record(Vis *vis); diff --git a/vis-motions.c b/vis-motions.c index 63cb0dc..e0db048 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -296,7 +296,7 @@ err: return false; } -Movement vis_motions[] = { +const Movement vis_motions[] = { [VIS_MOVE_LINE_UP] = { .cur = view_line_up, .type = LINEWISE }, [VIS_MOVE_LINE_DOWN] = { .cur = view_line_down, .type = LINEWISE }, [VIS_MOVE_SCREEN_LINE_UP] = { .cur = view_screenline_up, }, diff --git a/vis-operators.c b/vis-operators.c index d4fdb21..6d47055 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -256,7 +256,7 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { } if (id >= LENGTH(vis_operators)) goto err; - Operator *op = &vis_operators[id]; + const Operator *op = &vis_operators[id]; if (vis->mode->visual) { vis->action.op = op; action_do(vis, &vis->action); @@ -287,7 +287,7 @@ err: return false; } -Operator vis_operators[] = { +const Operator vis_operators[] = { [VIS_OP_DELETE] = { op_delete }, [VIS_OP_CHANGE] = { op_change }, [VIS_OP_YANK] = { op_yank }, diff --git a/vis-text-objects.c b/vis-text-objects.c index 14f299d..93dc8d4 100644 --- a/vis-text-objects.c +++ b/vis-text-objects.c @@ -17,7 +17,7 @@ static Filerange search_backward(Vis *vis, Text *txt, size_t pos) { return text_object_search_backward(txt, pos, vis->search_pattern); } -TextObject vis_textobjects[] = { +const TextObject vis_textobjects[] = { [VIS_TEXTOBJECT_INNER_WORD] = { .txt = text_object_word }, [VIS_TEXTOBJECT_OUTER_WORD] = { .txt = text_object_word_outer }, [VIS_TEXTOBJECT_INNER_LONGWORD] = { .txt = text_object_longword }, diff --git a/vis.c b/vis.c index 32deb80..489957a 100644 --- a/vis.c +++ b/vis.c @@ -414,7 +414,7 @@ void vis_delete(Vis *vis, size_t pos, size_t len) { windows_invalidate(vis, pos, pos + len); } -bool vis_action_register(Vis *vis, KeyAction *action) { +bool vis_action_register(Vis *vis, const KeyAction *action) { if (!vis->actions) vis->actions = map_new(); if (!vis->actions) diff --git a/vis.h b/vis.h index 519d327..6652f72 100644 --- a/vis.h +++ b/vis.h @@ -44,7 +44,7 @@ typedef struct { /* a KeyAction can be bound to a key binding */ typedef struct { /* a key binding either refers to an action or an alias */ const char *key; /* symbolic key to trigger this binding */ - KeyAction *action; /* action to launch upon triggering this binding */ + const KeyAction *action; /* action to launch upon triggering this binding */ const char *alias; /* replaces key with alias in the input queue */ } KeyBinding; @@ -137,7 +137,7 @@ bool vis_window_mode_unmap(Win*, enum VisMode, const char *key); const char *vis_mode_status(Vis*); /* associates the special pseudo key name> with the given key action. * after successfull registration the pseudo key can be used key binding aliases */ -bool vis_action_register(Vis*, KeyAction*); +bool vis_action_register(Vis*, const KeyAction*); enum VisOperator { VIS_OP_DELETE, -- cgit v1.2.3