]> git.neil.brown.name Git - edlib.git/commitdiff
Make struct cmd_info mostly read-only
authorNeilBrown <neil@brown.name>
Wed, 9 Dec 2015 22:45:15 +0000 (09:45 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 06:47:18 +0000 (17:47 +1100)
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 <neil@brown.name>
core-keymap.c
core.h
lib-keymap.c
lib-view.c

index 1a6d3d559c25d20428e51ee615790d2560684888..60f60948cc32067c4f5380bdb1f5b6694c26abae 100644 (file)
@@ -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 f4d594593c5dd57786b123d60ab729bb4c634851..4e3c8ce4f7d948500cab93c89b32647c2fc893ae 100644 (file)
--- 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,
index def507379d0a3dc567ea000e0ac564dd603e6a10..360be3654b11218f67cc15f310220473a8f3a3c5 100644 (file)
@@ -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;
index 4d3b193b1786509066d12fc1748e5506196d9db8..dda9f2c7e5f2519a5a2ce95cb1cc0571b885fd38 100644 (file)
@@ -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;