From 557453cbd0f0f61b12c3dc4582bd0a9fb0d15133 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 10 Dec 2015 09:45:15 +1100 Subject: [PATCH] Make struct cmd_info mostly read-only I want this to be treated readonly except for a few places where explicit write access is requested. Partly because it used to be changed a lot and I want to stop that. Signed-off-by: NeilBrown --- core-keymap.c | 23 ++++++++++++----------- core.h | 14 +++++++------- lib-keymap.c | 4 ++-- lib-view.c | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/core-keymap.c b/core-keymap.c index 1a6d3d55..60f60948 100644 --- a/core-keymap.c +++ b/core-keymap.c @@ -234,7 +234,7 @@ struct modmap { struct command comm; }; -static int key_prefix(struct cmd_info *ci) +static int key_prefix(const struct cmd_info *ci) { struct modmap *m = container_of(ci->comm, struct modmap, comm); @@ -267,7 +267,7 @@ struct command *key_lookup_cmd(struct map *m, char *c) return NULL; } -int key_lookup(struct map *m, struct cmd_info *ci) +int key_lookup(struct map *m, const struct cmd_info *ci) { int pos = key_find(m, ci->key); struct command *comm; @@ -282,39 +282,40 @@ int key_lookup(struct map *m, struct cmd_info *ci) comm = GETCOMM(m->comms[pos-1]); } else return 0; - ci->comm = comm; + ((struct cmd_info*)ci)->comm = comm; return comm->func(ci); } -int key_lookup_cmd_func(struct cmd_info *ci) +int key_lookup_cmd_func(const struct cmd_info *ci) { struct lookup_cmd *l = container_of(ci->comm, struct lookup_cmd, c); return key_lookup(*l->m, ci); } -int key_handle(struct cmd_info *ci) +int key_handle(const struct cmd_info *ci) { + struct cmd_info *vci = (struct cmd_info*)ci; struct pane *p = ci->focus; int ret = 0; if (ci->comm) return ci->comm->func(ci); - ci->hx = ci->x; - ci->hy = ci->y; + vci->hx = ci->x; + vci->hy = ci->y; while (ret == 0 && p) { if (p->handle) { - ci->home = p; - ci->comm = p->handle; + vci->home = p; + vci->comm = p->handle; ret = p->handle->func(ci); } if (ret) /* 'p' might have been destroyed */ break; if (ci->hx >= 0) { - ci->hx += p->x; - ci->hy += p->y; + vci->hx += p->x; + vci->hy += p->y; } p = p->parent; } diff --git a/core.h b/core.h index f4d59459..4e3c8ce4 100644 --- a/core.h +++ b/core.h @@ -58,7 +58,7 @@ struct pane { }; struct command { - int (*func)(struct cmd_info *ci); + int (*func)(const struct cmd_info *ci); }; /* this is ->data for a document pane. Only core-doc and @@ -252,16 +252,16 @@ struct lookup_cmd { #define CMD(_name) {_name ## _func } #define DEF_CMD(_name) \ - static int _name ## _func(struct cmd_info *ci); \ + static int _name ## _func(const struct cmd_info *ci); \ static struct command _name = CMD(_name); \ - static int _name ## _func(struct cmd_info *ci) + static int _name ## _func(const struct cmd_info *ci) #define REDEF_CMD(_name) \ - static int _name ## _func(struct cmd_info *ci) + static int _name ## _func(const struct cmd_info *ci) #define DEF_LOOKUP_CMD(_name, _map) \ static struct lookup_cmd _name = { { key_lookup_cmd_func }, &_map }; -int key_lookup_cmd_func(struct cmd_info *ci); +int key_lookup_cmd_func(const struct cmd_info *ci); #define ARRAY_SIZE(ra) (sizeof(ra) / sizeof(ra[0])) @@ -290,12 +290,12 @@ struct cmd_info { struct map *key_alloc(void); void key_free(struct map *m); -int key_handle(struct cmd_info *ci); +int key_handle(const struct cmd_info *ci); int key_handle_focus(struct cmd_info *ci); int key_handle_xy(struct cmd_info *ci); int key_handle_focus_point(struct cmd_info *ci); int key_handle_xy_point(struct cmd_info *ci); -int key_lookup(struct map *m, struct cmd_info *ci); +int key_lookup(struct map *m, const const struct cmd_info *ci); struct command *key_lookup_cmd(struct map *m, char *c); void key_add(struct map *map, char *k, struct command *comm); void key_add_range(struct map *map, char *first, char *last, diff --git a/lib-keymap.c b/lib-keymap.c index def50737..360be365 100644 --- a/lib-keymap.c +++ b/lib-keymap.c @@ -66,7 +66,7 @@ DEF_CMD(keymap_handle) ci2.focus = p; keymap_attach_func(&ci2); pane_attach(p, "local-keymap", NULL, NULL); - return key_handle_focus(ci); + return key_handle_focus((struct cmd_info*)ci); } } if (kd->global && strncmp(ci->key, "global-set-key", 14) == 0) { @@ -107,7 +107,7 @@ DEF_CMD(keymap_handle) for (i = 0; i < kd->cmdcount; i++) { int ret; - ci->comm = kd->cmds[i]; + ((struct cmd_info*)ci)->comm = kd->cmds[i]; ret = kd->cmds[i]->func(ci); if (ret) return ret; diff --git a/lib-view.c b/lib-view.c index 4d3b193b..dda9f2c7 100644 --- a/lib-view.c +++ b/lib-view.c @@ -38,7 +38,7 @@ enum { static struct map *view_map; static struct pane *do_view_attach(struct pane *par, int border); -static int view_refresh(struct cmd_info *ci) +static int view_refresh(const struct cmd_info *ci) { struct pane *p = ci->home; struct view_data *vd = p->data; -- 2.39.5