]> git.neil.brown.name Git - edlib.git/commitdiff
Mark key, str and str2 as 'const'.
authorNeilBrown <neil@brown.name>
Mon, 10 Feb 2020 06:04:51 +0000 (17:04 +1100)
committerNeilBrown <neil@brown.name>
Mon, 10 Feb 2020 20:57:21 +0000 (07:57 +1100)
Make these strings 'const', then clean up all the fall-out.

Signed-off-by: NeilBrown <neil@brown.name>
27 files changed:
core-attr.c
core-doc.c
core-editor.c
core-keymap.c
core-misc.c
core-pane.c
core.h
display-ncurses.c
doc-dir.c
doc-docs.c
doc-multipart.c
doc-rendering.c
doc-text.c
emacs-search.c
lang-python.c
lib-history.c
lib-input.c
lib-keymap.c
lib-popup.c
lib-renderline.c
lib-rfc822header.c
lib-tile.c
misc.h
mode-emacs.c
render-complete.c
rexel.c
rexel.h

index 7cc9081547034289f69987ee85ba50245f70c2ad..b371740fd82ba9064ee3bbf8fe88feb2524635a8 100644 (file)
@@ -62,9 +62,9 @@ static struct attrset *safe newattr(struct attrset *old, int size)
 /* attr_cmp just deals with bytes and ASCII digits, so it is
  * not aware for wchars
  */
-static int getcmptok(char **ap safe)
+static int getcmptok(const char **ap safe)
 {
-       char *a safe;
+       const char *a safe;
        char c;
        int i;
 
@@ -89,7 +89,7 @@ static int getcmptok(char **ap safe)
 /* Compare 'a' and 'b' treating strings of digits as numbers.
  * If bnum >= 0, it is used as a leading number on 'b'.
  */
-static int attr_cmp(char *a safe, char *b safe, int bnum)
+static int attr_cmp(const char *a safe, const char *b safe, int bnum)
 {
        while (*a && (*b || bnum >= 0)) {
                int ai, bi;
@@ -116,7 +116,7 @@ static int attr_cmp(char *a safe, char *b safe, int bnum)
 #ifdef TEST_ATTR_CMP
 #include <stdlib.h>
 #include <stdio.h>
-struct {char *a, *b; int result;} test[] = {
+struct {const char *a, *b; int result;} test[] = {
        { "hello", "there", -1},
        { "6hello", "10world", -1},
        { "0005six", "5six", 0},
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
 
 #endif
 
-static int __attr_find(struct attrset ***setpp safe, char *key safe,
+static int __attr_find(struct attrset ***setpp safe, const char *key safe,
                       int *offsetp safe, int keynum)
 {
        struct attrset **setp safe;
@@ -179,7 +179,7 @@ static int __attr_find(struct attrset ***setpp safe, char *key safe,
        return 1;
 }
 
-int attr_del(struct attrset * *setp safe, char *key safe)
+int attr_del(struct attrset * *setp safe, const char *key safe)
 {
        int offset = 0;
        int cmp;
@@ -205,7 +205,7 @@ int attr_del(struct attrset * *setp safe, char *key safe)
        return 1;
 }
 
-char *attr_get_str(struct attrset *set, char *key safe, int keynum)
+char *attr_get_str(struct attrset *set, const char *key safe, int keynum)
 {
        struct attrset **setp = &set;
        int offset = 0;
@@ -218,18 +218,18 @@ char *attr_get_str(struct attrset *set, char *key safe, int keynum)
        return set->attrs + offset;
 }
 
-char *attr_find(struct attrset *set, char *key safe)
+char *attr_find(struct attrset *set, const char *key safe)
 {
        return attr_get_str(set, key, -1);
 }
 
-char *attr_get_next_key(struct attrset *set, char *key safe, int keynum,
-                       char **valp safe)
+const char *attr_get_next_key(struct attrset *set, const char *key safe,
+                             int keynum, const char **valp safe)
 {
        struct attrset **setp = &set;
        int offset = 0;
        int cmp = __attr_find(&setp, key, &offset, keynum);
-       char *val;
+       const char *val;
 
        if (cmp < 0)
                return NULL;
@@ -258,7 +258,8 @@ char *attr_get_next_key(struct attrset *set, char *key safe, int keynum,
        return key;
 }
 
-int attr_set_str_key(struct attrset **setp safe, char *key safe, char *val,
+int attr_set_str_key(struct attrset **setp safe,
+                    const char *key safe, const char *val,
                     int keynum)
 {
        int offset = 0;
@@ -332,7 +333,8 @@ int attr_set_str_key(struct attrset **setp safe, char *key safe, char *val,
        return cmp;
 }
 
-int attr_set_str(struct attrset **setp safe, char *key safe, char *val)
+int attr_set_str(struct attrset **setp safe,
+                const char *key safe, const char *val)
 {
        return attr_set_str_key(setp, key, val, -1);
 }
@@ -415,9 +417,9 @@ int main(int argc, char *argv[])
 #endif
 
 /* Have versions that take and return numbers, '-1' for 'not found' */
-int attr_find_int(struct attrset *set, char *key safe)
+int attr_find_int(struct attrset *set, const char *key safe)
 {
-       char *val = attr_find(set, key);
+       const char *val = attr_find(set, key);
        unsigned long rv;
        char *end;
 
@@ -429,7 +431,7 @@ int attr_find_int(struct attrset *set, char *key safe)
        return rv;
 }
 
-int attr_set_int(struct attrset **setp safe, char *key safe, int val)
+int attr_set_int(struct attrset **setp safe, const char *key safe, int val)
 {
        /* 3 digits per bytes, +1 for sign and +1 for trailing nul */
        char sval[sizeof(int)*3+2];
index 6e5c4817c2c6c1be9769bb38a38146637400ab21..5df210cf0025186d06acead7f7db81a3abfd474d 100644 (file)
@@ -182,7 +182,7 @@ DEF_CMD(doc_expr)
        int dir;
        char *open;
        char *close;
-       char *wordchars = ci->str ?: "";
+       const char *wordchars = ci->str ?: "";
        const char *special safe = "[](){}'\"";
 
        if (!m)
@@ -469,7 +469,7 @@ DEF_CMD(doc_page)
 DEF_CMD(doc_set)
 {
        struct doc *d = ci->home->data;
-       char *val = ci->key + 8;
+       const char *val = ci->key + 8;
 
        if (strcmp(val, "autoclose") == 0) {
                d->autoclose = ci->num;
@@ -1031,7 +1031,7 @@ DEF_CMD(doc_attach_view)
        struct pane *doc = ci->home;
        struct pane *p, *p2;
        char *s;
-       char *type = ci->str ?: "default";
+       const char *type = ci->str ?: "default";
 
        p = doc_attach(focus);
        if (!p)
@@ -1213,7 +1213,7 @@ DEF_CMD(doc_open)
 {
        struct pane *ed = ci->home;
        int fd = ci->num;
-       char *name = ci->str;
+       const char *name = ci->str;
        struct stat stb;
        struct pane *p;
        int autoclose = ci->num2 & 1;
@@ -1228,7 +1228,7 @@ DEF_CMD(doc_open)
        stb.st_mode = 0;
        if (fd >= -1) {
                /* Try to canonicalize directory part of path */
-               char *sl;
+               const char *sl;
                sl = strrchr(name, '/');
                if (!sl) {
                        rp = realpath(".", pathbuf);
@@ -1298,8 +1298,8 @@ DEF_CMD(doc_open)
 
 DEF_CMD(doc_from_text)
 {
-       char *name = ci->str;
-       char *text = ci->str2;
+       const char *name = ci->str;
+       const char *text = ci->str2;
        struct pane *p;
 
        p = call_ret(pane, "attach-doc-text", ci->focus);
index da933079e85ae945c26da719ec3e984ba57bd446..a7b31250a3671002f63f0367410721c1c62b2d5d 100644 (file)
@@ -85,7 +85,7 @@ DEF_CMD(editor_load_module)
 {
        struct ed_info *ei = ci->home->data;
        struct map *map = ei->map;
-       char *name = ci->str;
+       const char *name = ci->str;
        char buf[PATH_MAX];
 #ifndef edlib_init
        void *h;
@@ -135,7 +135,8 @@ DEF_CMD(editor_auto_load)
        int ret;
        struct ed_info *ei = ci->home->data;
        struct map *map = ei->map;
-       char *mod = ci->key + 7;
+       const char *mod = ci->key + 7;
+       char *mod2 = NULL;
 
        /* Check the key really doesn't exist, rather than
         * it fails
@@ -152,16 +153,16 @@ DEF_CMD(editor_auto_load)
                char *m = strrchr(ci->key+6, '-');
                if (m) {
                        m += 1;
-                       mod = malloc(4+strlen(m)+1);
-                       strcpy(mod, "lib-");
-                       strcpy(mod+4, m);
+                       mod2 = malloc(4+strlen(m)+1);
+                       strcpy(mod2, "lib-");
+                       strcpy(mod2+4, m);
+                       mod = mod2;
                }
        }
 
        ret = call("global-load-module", ci->home, 0, NULL,
                    mod, 0);
-       if (mod != ci->key + 7)
-               free(mod);
+       free(mod2);
 
        if (ret > 0)
                /* auto-load succeeded */
@@ -286,7 +287,7 @@ DEF_CMD(editor_free)
        return 1;
 }
 
-void * safe memsave(struct pane *p safe, char *buf, int len)
+void * safe memsave(struct pane *p safe, const char *buf, int len)
 {
        struct ed_info *ei;
 
@@ -310,14 +311,14 @@ void * safe memsave(struct pane *p safe, char *buf, int len)
                return ei->store->space+ei->store->size;
 }
 
-char *strsave(struct pane *p safe, char *buf)
+char *strsave(struct pane *p safe, const char *buf)
 {
        if (!buf)
                return NULL;
        return memsave(p, buf, strlen(buf)+1);
 }
 
-char *strnsave(struct pane *p safe, char *buf, int len)
+char *strnsave(struct pane *p safe, const char *buf, int len)
 {
        char *s;
        if (!buf)
@@ -328,7 +329,7 @@ char *strnsave(struct pane *p safe, char *buf, int len)
        return s;
 }
 
-char * safe __strconcat(struct pane *p safe, char *s1 safe, ...)
+char * safe __strconcat(struct pane *p safe, const char *s1 safe, ...)
 {
        va_list ap;
        char *s;
index c0ccc64b6b133ab5b7c64520df27c88ef6114dda..139aa1050daad1fe84eb5500bb074001bb4ef0cb 100644 (file)
@@ -125,7 +125,7 @@ inline static int test_bit(unsigned long *set safe, int bit)
 }
 
 
-static int key_present(struct map *map safe, char *key, int klen,
+static int key_present(struct map *map safe, const char *key, int klen,
                       unsigned int *hashp safe)
 {
        int hash;
@@ -150,7 +150,7 @@ static int key_present(struct map *map safe, char *key, int klen,
 }
 
 /* Find first entry >= k */
-static int key_find_len(struct map *map safe, char *k safe, int len)
+static int key_find_len(struct map *map safe, const char *k safe, int len)
 {
        int lo = 0;
        int hi = map->size;
@@ -170,12 +170,12 @@ static int key_find_len(struct map *map safe, char *k safe, int len)
        return hi;
 }
 
-static int key_find(struct map *map safe, char *k safe)
+static int key_find(struct map *map safe, const char *k safe)
 {
        return key_find_len(map, k, strlen(k));
 }
 
-void key_add(struct map *map safe, char *k safe, struct command *comm)
+void key_add(struct map *map safe, const char *k safe, struct command *comm)
 {
        int size;
        int pos;
@@ -238,7 +238,8 @@ void key_add(struct map *map safe, char *k safe, struct command *comm)
        map->changed = 1;
 }
 
-void key_add_range(struct map *map safe, char *first safe, char *last safe,
+void key_add_range(struct map *map safe,
+                  const char *first safe, const char *last safe,
                   struct command *comm)
 {
        int size, move_size;
@@ -331,15 +332,15 @@ int key_pfx_func(const struct cmd_info *ci safe)
        return 1;
 }
 
-struct command *key_lookup_cmd(struct map *m safe, char *c safe,
-                              char **cret, int *lenret)
+struct command *key_lookup_cmd(struct map *m safe, const char *c safe,
+                              const char **cret, unsigned int *lenret)
 {
        /* If 'k' contains an ASCII US (Unit Separator, 0o37 0x1f 31),
         * it represents multiple keys.
         * Call key_find() on each of them until success.
         */
        while (*c) {
-               char *end = strchr(c, '\037');
+               const char *end = strchr(c, '\037');
                int pos;
 
                if (!end)
@@ -374,8 +375,9 @@ struct command *key_lookup_cmd(struct map *m safe, char *c safe,
 int key_lookup(struct map *m safe, const struct cmd_info *ci safe)
 {
        struct command *comm;
-       char *key;
-       int len;
+       const char *key;
+       unsigned
+               int len;
 
        if (ci->hash && !key_present(m, ci->key, strlen(ci->key), ci->hash)) {
                stat_count("bloom-miss");
@@ -391,18 +393,24 @@ int key_lookup(struct map *m safe, const struct cmd_info *ci safe)
                 * keys, we need to pass down the one that was matched.
                 */
                int ret;
-               char *oldkey = ci->key;
-               char tail = key[len];
+               const char *oldkey = ci->key;
+               char ktmp[40], *k2 = NULL;
 
                stat_count("bloom-hit-good");
-               if (key[len])
-                       key[len] = 0;
+               if (key[len] == 0) {
+                       ((struct cmd_info*)ci)->key = key;
+               } else if (len >= sizeof(ktmp)) {
+                       k2 = strndup(key, len);
+                       ((struct cmd_info*)ci)->key = k2;
+               } else {
+                       strncpy(ktmp, key, len);
+                       ktmp[len] = 0;
+                       ((struct cmd_info*)ci)->key = ktmp;
+               }
                ((struct cmd_info*)ci)->comm = comm;
-               ((struct cmd_info*)ci)->key = key;
                ret = comm->func(ci);
                ((struct cmd_info*)ci)->key = oldkey;
-               if (tail)
-                       key[len] = tail;
+               free(k2);
                return ret;
        }
 }
@@ -412,7 +420,7 @@ int key_lookup_prefix(struct map *m safe, const struct cmd_info *ci safe)
        int pos = key_find(m, ci->key);
        struct command *comm, *prev = NULL;
        int len = strlen(ci->key);
-       char *k = ci->key;
+       const char *k = ci->key;
 
        while (pos < m->size && strncmp(m->keys[pos], k, len) == 0) {
                comm = GETCOMM(m->comms[pos]);
index ff9e8d3d220d0ecec807adf4472b194e54c7f09e..5cc104c62b3fe94132557620a77795fab6fd0dbb 100644 (file)
@@ -24,7 +24,7 @@ void buf_init(struct buf *b safe)
        b->size = 0;
 }
 
-void buf_concat_len(struct buf *b safe, char *s safe, int l)
+void buf_concat_len(struct buf *b safe, const char *s safe, int l)
 {
 
        if (b->len + l >= b->size) {
@@ -37,7 +37,7 @@ void buf_concat_len(struct buf *b safe, char *s safe, int l)
        b->b[b->len] = 0;
 }
 
-void buf_concat(struct buf *b safe, char *s safe)
+void buf_concat(struct buf *b safe, const char *s safe)
 {
        int l = strlen(s);
        buf_concat_len(b, s, l);
@@ -159,7 +159,7 @@ inline static int qhash(char key, unsigned int start)
        return (start ^ key) * 0x61C88647U;
 }
 
-static int hash_str(char *key safe, int len)
+static int hash_str(const char *key safe, int len)
 {
        int i;
        int h = 0;
@@ -181,11 +181,11 @@ static struct khash *khashtab[1024];
 
 static struct kstack {
        long long tstart;
-       char *name;
+       const char *name;
 } kstack[20];
 static int ktos = 0;
 
-void time_start_key(char *key safe)
+void time_start_key(const char *key safe)
 {
        struct timespec start;
 
@@ -199,7 +199,7 @@ void time_start_key(char *key safe)
        kstack[ktos-1].name = key;
 }
 
-static struct khash *hash_find(struct khash **table, char *key safe)
+static struct khash *hash_find(struct khash **table, const char *key safe)
 {
        struct khash *h, **hp;
        int hash;
@@ -220,7 +220,7 @@ static struct khash *hash_find(struct khash **table, char *key safe)
        return h;
 }
 
-void time_stop_key(char *key safe)
+void time_stop_key(const char *key safe)
 {
        struct timespec stop;
        struct khash *h;
index 681ed102d4afdfa4dad43a8ae79dc5ae3824e6d2..1da2a486728715582b499c974b317392b437bd17 100644 (file)
@@ -278,7 +278,7 @@ void pane_refresh(struct pane *p safe)
 }
 
 void pane_add_notify(struct pane *target safe, struct pane *source safe,
-                    char *msg safe)
+                    const char *msg safe)
 {
        struct notifier *n;
 
@@ -328,10 +328,10 @@ static void pane_notify_close(struct pane *p safe)
        }
 }
 
-int do_pane_notify(struct pane *home, char *notification safe,
+int do_pane_notify(struct pane *home, const char *notification safe,
                   struct pane *p safe,
-                  int num, struct mark *m, char *str,
-                  int num2, struct mark *m2, char *str2,
+                  int num, struct mark *m, const char *str,
+                  int num2, struct mark *m2, const char *str2,
                   struct command *comm2)
 {
        /* Return the largest absolute return value. If no notifiees are found.
@@ -606,7 +606,7 @@ void pane_focus(struct pane *focus)
        call("pane:refocus", focus);
 }
 
-char *pane_attr_get(struct pane *p, char *key safe)
+char *pane_attr_get(struct pane *p, const char *key safe)
 {
        while (p) {
                char *a = attr_find(p->attrs, key);
@@ -624,7 +624,7 @@ char *pane_attr_get(struct pane *p, char *key safe)
 }
 
 char *pane_mark_attr(struct pane *p safe, struct mark *m safe,
-                    char *key safe)
+                    const char *key safe)
 {
        return call_ret(strsave, "doc:get-attr", p, 0, m, key);
 }
@@ -684,9 +684,9 @@ DEF_CMD(take_str)
 
 struct pane *do_call_pane(enum target_type type, struct pane *home,
                          struct command *comm2a,
-                         char *key safe, struct pane *focus safe,
-                         int num,  struct mark *m,  char *str,
-                         int num2, struct mark *m2, char *str2,
+                         const char *key safe, struct pane *focus safe,
+                         int num,  struct mark *m,  const char *str,
+                         int num2, struct mark *m2, const char *str2,
                          int x, int y, struct command *comm2b,
                          struct commcache *ccache)
 {
@@ -702,9 +702,9 @@ struct pane *do_call_pane(enum target_type type, struct pane *home,
 
 struct mark *do_call_mark(enum target_type type, struct pane *home,
                          struct command *comm2a,
-                         char *key safe, struct pane *focus safe,
-                         int num,  struct mark *m,  char *str,
-                         int num2, struct mark *m2, char *str2,
+                         const char *key safe, struct pane *focus safe,
+                         int num,  struct mark *m,  const char *str,
+                         int num2, struct mark *m2, const char *str2,
                          int x, int y, struct command *comm2b,
                          struct commcache *ccache)
 {
@@ -720,9 +720,9 @@ struct mark *do_call_mark(enum target_type type, struct pane *home,
 
 struct mark *do_call_mark2(enum target_type type, struct pane *home,
                           struct command *comm2a,
-                          char *key safe, struct pane *focus safe,
-                          int num,  struct mark *m,  char *str,
-                          int num2, struct mark *m2, char *str2,
+                          const char *key safe, struct pane *focus safe,
+                          int num,  struct mark *m,  const char *str,
+                          int num2, struct mark *m2, const char *str2,
                           int x, int y, struct command *comm2b,
                           struct commcache *ccache)
 {
@@ -738,9 +738,9 @@ struct mark *do_call_mark2(enum target_type type, struct pane *home,
 
 struct command *do_call_comm(enum target_type type, struct pane *home,
                             struct command *comm2a,
-                            char *key safe, struct pane *focus safe,
-                            int num,  struct mark *m,  char *str,
-                            int num2, struct mark *m2, char *str2,
+                            const char *key safe, struct pane *focus safe,
+                            int num,  struct mark *m,  const char *str,
+                            int num2, struct mark *m2, const char *str2,
                             int x, int y, struct command *comm2b,
                             struct commcache *ccache)
 {
@@ -756,9 +756,9 @@ struct command *do_call_comm(enum target_type type, struct pane *home,
 
 char *do_call_strsave(enum target_type type, struct pane *home,
                      struct command *comm2a,
-                     char *key safe, struct pane *focus safe,
-                     int num,  struct mark *m,  char *str,
-                     int num2, struct mark *m2, char *str2,
+                     const char *key safe, struct pane *focus safe,
+                     int num,  struct mark *m,  const char *str,
+                     int num2, struct mark *m2, const char *str2,
                      int x, int y, struct command *comm2b,
                      struct commcache *ccache)
 {
@@ -772,9 +772,9 @@ char *do_call_strsave(enum target_type type, struct pane *home,
 
 struct call_return do_call_all(enum target_type type, struct pane *home,
                               struct command *comm2a,
-                              char *key safe, struct pane *focus safe,
-                              int num,  struct mark *m,  char *str,
-                              int num2, struct mark *m2, char *str2,
+                              const char *key safe, struct pane *focus safe,
+                              int num,  struct mark *m,  const char *str,
+                              int num2, struct mark *m2, const char *str2,
                               int x, int y, struct command *comm2b,
                               struct commcache *ccache)
 {
@@ -788,9 +788,9 @@ struct call_return do_call_all(enum target_type type, struct pane *home,
 
 char *do_call_str(enum target_type type, struct pane *home,
                  struct command *comm2a,
-                 char *key safe, struct pane *focus safe,
-                 int num,  struct mark *m,  char *str,
-                 int num2, struct mark *m2, char *str2,
+                 const char *key safe, struct pane *focus safe,
+                 int num,  struct mark *m,  const char *str,
+                 int num2, struct mark *m2, const char *str2,
                  int x, int y, struct command *comm2b,
                  struct commcache *ccache)
 {
diff --git a/core.h b/core.h
index c4d3d70017ea2d290af08e1eb8df16b16ce9a926..f5e0106412736175fd48d199c975e95631274e73 100644 (file)
--- a/core.h
+++ b/core.h
@@ -116,21 +116,21 @@ struct notifier {
        int                     noted;
 };
 void pane_add_notify(struct pane *target safe, struct pane *source safe,
-                    char *msg safe);
-int do_pane_notify(struct pane *home, char *notification safe,
+                    const char *msg safe);
+int do_pane_notify(struct pane *home, const char *notification safe,
                   struct pane *p safe,
-                  int num, struct mark *m, char *str,
-                  int num2, struct mark *m2, char *str2,
+                  int num, struct mark *m, const char *str,
+                  int num2, struct mark *m2, const char *str2,
                   struct command *comm2);
 void pane_drop_notifiers(struct pane *p safe, char *notification);
 
 void editor_delayed_free(struct pane *ed safe, struct pane *p safe);
 void editor_delayed_mark_free(struct mark *m safe);
 struct pane *editor_new(void);
-void * safe memsave(struct pane *p safe, char *buf, int len);
-char *strsave(struct pane *p safe, char *buf);
-char *strnsave(struct pane *p safe, char *buf, int len);
-char * safe __strconcat(struct pane *p safe, char *s1 safe, ...);
+void * safe memsave(struct pane *p safe, const char *buf, int len);
+char *strsave(struct pane *p safe, const char *buf);
+char *strnsave(struct pane *p safe, const char *buf, int len);
+char * safe __strconcat(struct pane *p safe, const char *s1 safe, ...);
 #define strconcat(p, ...) __strconcat(p, __VA_ARGS__, NULL)
 
 /* This is declared here so sparse knows it is global */
@@ -275,16 +275,18 @@ static inline struct attrset **safe mark_attr(struct mark *m safe)
 }
 
 /* Attributes */
-char *attr_find(struct attrset *set, char *key safe);
-int attr_del(struct attrset **setp safe, char *key safe);
-int attr_set_str(struct attrset **setp safe, char *key safe, char *val);
-int attr_set_str_key(struct attrset **setp safe, char *key safe,
-                    char *val, int keynum);
-char *attr_get_str(struct attrset *setp, char *key safe, int keynum);
-char *attr_get_next_key(struct attrset *set, char *key safe, int keynum,
-                       char **valp safe);
-int attr_find_int(struct attrset *set, char *key safe);
-int attr_set_int(struct attrset **setp safe, char *key safe, int val);
+char *attr_find(struct attrset *set, const char *key safe);
+int attr_del(struct attrset **setp safe, const char *key safe);
+int attr_set_str(struct attrset **setp safe,
+                const char *key safe, const char *val);
+int attr_set_str_key(struct attrset **setp safe, const char *key safe,
+                    const char *val, int keynum);
+char *attr_get_str(struct attrset *setp, const char *key safe, int keynum);
+const char *attr_get_next_key(struct attrset *set, const char *key safe,
+                             int keynum,
+                             const char **valp safe);
+int attr_find_int(struct attrset *set, const char *key safe);
+int attr_set_int(struct attrset **setp safe, const char *key safe, int val);
 void attr_trim(struct attrset **setp safe, int nkey);
 struct attrset *attr_copy_tail(struct attrset *set, int nkey);
 struct attrset *attr_collect(struct attrset *set, unsigned int pos, int prefix);
@@ -341,11 +343,11 @@ int key_pfx_func(const struct cmd_info *ci safe);
  * 'mark' is moved by 'move' and 'replace' deletes between point and mark.
  */
 struct cmd_info {
-       char            *key safe;
+       const char      *key safe;
        struct pane     *home safe, *focus safe;
        int             num, num2;
        int             x,y;            /* relative to focus */
-       char            *str, *str2;
+       const char      *str, *str2;
        struct mark     *mark, *mark2;
        struct command  *comm safe;
        struct command  *comm2;
@@ -373,10 +375,11 @@ void key_free(struct map *m safe);
 int key_handle(const struct cmd_info *ci safe);
 int key_lookup(struct map *m safe, const struct cmd_info *ci safe);
 int key_lookup_prefix(struct map *m safe, const struct cmd_info *ci safe);
-struct command *key_lookup_cmd(struct map *m safe, char *c safe,
-                              char **cret, int *lenret);
-void key_add(struct map *map safe, char *k safe, struct command *comm);
-void key_add_range(struct map *map safe, char *first safe, char *last safe,
+struct command *key_lookup_cmd(struct map *m safe, const char *c safe,
+                              const char **cret, unsigned int *lenret);
+void key_add(struct map *map safe, const char *k safe, struct command *comm);
+void key_add_range(struct map *map safe,
+                  const char *first safe, const char *last safe,
                   struct command *comm);
 #define key_add_prefix(map, prefix, comm) \
        key_add_range(map, prefix, prefix "\xFF\xFF\xFF\xFF", comm)
@@ -429,8 +432,9 @@ struct pane *pane_my_child(struct pane *p, struct pane *c);
 
 int pane_masked(struct pane *p safe, short x, short y, short abs_z,
                short *w, short *h);
-char *pane_attr_get(struct pane *p, char *key safe);
-char *pane_mark_attr(struct pane *p safe, struct mark *m safe, char *key safe);
+char *pane_attr_get(struct pane *p, const char *key safe);
+char *pane_mark_attr(struct pane *p safe, struct mark *m safe,
+                    const char *key safe);
 void pane_absxy(struct pane *p, short *x safe, short *y safe,
                short *w safe, short *h safe);
 void pane_relxy(struct pane *p, short *x safe, short *y safe);
@@ -439,7 +443,7 @@ void pane_map_xy(struct pane *orig, struct pane *target,
 
 struct xy pane_scale(struct pane *p safe);
 
-static inline int pane_attr_get_int(struct pane *p safe, char *key safe)
+static inline int pane_attr_get_int(struct pane *p safe, const char *key safe)
 {
        char *c = pane_attr_get(p, key);
        int rv;
@@ -513,51 +517,51 @@ enum target_type {
 
 struct pane *do_call_pane(enum target_type type, struct pane *home,
                          struct command *comm2a,
-                         char *key safe, struct pane *focus safe,
-                         int num,  struct mark *m,  char *str,
-                         int num2, struct mark *m2, char *str2,
+                         const char *key safe, struct pane *focus safe,
+                         int num,  struct mark *m,  const char *str,
+                         int num2, struct mark *m2, const char *str2,
                          int x, int y, struct command *comm2b,
                          struct commcache *cache);
 struct mark *do_call_mark(enum target_type type, struct pane *home,
                          struct command *comm2a,
-                         char *key safe, struct pane *focus safe,
-                         int num,  struct mark *m,  char *str,
-                         int num2, struct mark *m2, char *str2,
+                         const char *key safe, struct pane *focus safe,
+                         int num,  struct mark *m,  const char *str,
+                         int num2, struct mark *m2, const char *str2,
                          int x, int y, struct command *comm2b,
                          struct commcache *cache);
 struct mark *do_call_mark2(enum target_type type, struct pane *home,
                           struct command *comm2a,
-                          char *key safe, struct pane *focus safe,
-                          int num,  struct mark *m,  char *str,
-                          int num2, struct mark *m2, char *str2,
+                          const char *key safe, struct pane *focus safe,
+                          int num,  struct mark *m,  const char *str,
+                          int num2, struct mark *m2, const char *str2,
                           int x, int y, struct command *comm2b,
                           struct commcache *cache);
 struct command *do_call_comm(enum target_type type, struct pane *home,
                             struct command *comm2a,
-                            char *key safe, struct pane *focus safe,
-                            int num,  struct mark *m,  char *str,
-                            int num2, struct mark *m2, char *str2,
+                            const char *key safe, struct pane *focus safe,
+                            int num,  struct mark *m,  const char *str,
+                            int num2, struct mark *m2, const char *str2,
                             int x, int y, struct command *comm2b,
                             struct commcache *cache);
 struct call_return do_call_all(enum target_type type, struct pane *home,
                               struct command *comm2a,
-                              char *key safe, struct pane *focus safe,
-                              int num,  struct mark *m,  char *str,
-                              int num2, struct mark *m2, char *str2,
+                              const char *key safe, struct pane *focus safe,
+                              int num,  struct mark *m,  const char *str,
+                              int num2, struct mark *m2, const char *str2,
                               int x, int y, struct command *comm2b,
                               struct commcache *cache);
 char *do_call_str(enum target_type type, struct pane *home,
                  struct command *comm2a,
-                 char *key safe, struct pane *focus safe,
-                 int num,  struct mark *m,  char *str,
-                 int num2, struct mark *m2, char *str2,
+                 const char *key safe, struct pane *focus safe,
+                 int num,  struct mark *m,  const char *str,
+                 int num2, struct mark *m2, const char *str2,
                  int x, int y, struct command *comm2b,
                  struct commcache *cache);
 char *do_call_strsave(enum target_type type, struct pane *home,
                      struct command *comm2a,
-                     char *key safe, struct pane *focus safe,
-                     int num,  struct mark *m,  char *str,
-                     int num2, struct mark *m2, char *str2,
+                     const char *key safe, struct pane *focus safe,
+                     int num,  struct mark *m,  const char *str,
+                     int num2, struct mark *m2, const char *str2,
                      int x, int y, struct command *comm2b,
                      struct commcache *cache);
 
@@ -648,9 +652,9 @@ char *do_call_strsave(enum target_type type, struct pane *home,
 
 static inline int do_call_val(enum target_type type, struct pane *home,
                              struct command *comm2a,
-                             char *key safe, struct pane *focus safe,
-                             int num,  struct mark *m,  char *str,
-                             int num2, struct mark *m2, char *str2,
+                             const char *key safe, struct pane *focus safe,
+                             int num,  struct mark *m,  const char *str,
+                             int num2, struct mark *m2, const char *str2,
                              int x, int y, struct command *comm2b,
                              struct commcache *ccache)
 {
index 538dd2d8e79a3c9a11e051bc6e35a0a28d712a3a..99a61e8a551164b61a7176c1caf9aa7d108f6308 100644 (file)
@@ -517,13 +517,13 @@ static int to_pair(struct display_data *dd safe, int fg, int bg)
 }
 
 
-static int cvt_attrs(struct pane *home safe, char *attrs)
+static int cvt_attrs(struct pane *home safe, const char *attrs)
 {
        struct display_data *dd = home->data;
 
        int attr = 0;
        char tmp[40];
-       char *a;
+       const char *a;
        int fg = COLOR_BLACK;
        int bg = COLOR_WHITE+8;
 
@@ -532,7 +532,7 @@ static int cvt_attrs(struct pane *home safe, char *attrs)
        set_screen(home);
        a = attrs;
        while (a && *a) {
-               char *c;
+               const char *c;
                if (*a == ',') {
                        a++;
                        continue;
@@ -605,7 +605,7 @@ DEF_CMD(nc_text_size)
        int size = 0;
        int offset = 0;
        mbstate_t mbs = {};
-       char *str = ci->str;
+       const char *str = ci->str;
        int len;
 
        if (!str)
@@ -637,7 +637,7 @@ DEF_CMD(nc_draw_text)
        short offset = 0;
        short x = ci->x, y = ci->y;
        mbstate_t mbs = {};
-       char *str = ci->str;
+       const char *str = ci->str;
        int len;
 
        if (!str)
@@ -688,7 +688,8 @@ DEF_CMD(nc_refresh_post)
        return 1;
 }
 
-static struct pane *ncurses_init(struct pane *ed, char *tty, char *term)
+static struct pane *ncurses_init(struct pane *ed,
+                                const char *tty, const char *term)
 {
        SCREEN *scr;
        struct pane *p;
index 2fd954f54ecb140afb80968d1d2e491b44a25e0b..e2fabbcae6d04179f1f5243472dd8d176a206698 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -147,7 +147,7 @@ DEF_CMD(dir_load_file)
 {
        struct doc *d = ci->home->data;
        int fd = ci->num2;
-       char *name = ci->str;
+       const char *name = ci->str;
        struct directory *dr = container_of(d, struct directory, doc);
        struct list_head new;
        struct dir_ent *de1, *de2;
@@ -231,7 +231,7 @@ DEF_CMD(dir_load_file)
        }
 
        if (name) {
-               char *dname;
+               const char *dname;
                int l = strlen(name);
 
                fstat(fd, &dr->stat);
@@ -413,8 +413,8 @@ static char *fmt_date(struct dir_ent *de safe, time_t t)
        return de->nbuf;
 }
 
-static char *__dir_get_attr(struct doc *d safe, struct mark *m safe,
-                           char *attr safe)
+static const char *__dir_get_attr(struct doc *d safe, struct mark *m safe,
+                           const char *attr safe)
 
 {
        struct dir_ent *de;
@@ -510,8 +510,8 @@ DEF_CMD(dir_doc_get_attr)
 {
        struct doc *d = ci->home->data;
        struct mark *m = ci->mark;
-       char *attr = ci->str;
-       char *val;
+       const char *attr = ci->str;
+       const char *val;
 
        if (!m || !attr)
                return Enoarg;
@@ -527,8 +527,8 @@ DEF_CMD(dir_get_attr)
 {
        struct doc *d = ci->home->data;
        struct directory *dr = container_of(d, struct directory, doc);
-       char *attr = ci->str;
-       char *val;
+       const char *attr = ci->str;
+       const char *val;
 
        if (!attr)
                return Enoarg;
@@ -691,7 +691,7 @@ DEF_CMD(dir_attach)
 {
        struct doc *d = ci->home->data;
        struct directory *dr = container_of(d, struct directory, doc);
-       char *type = ci->str ?: "default";
+       const char *type = ci->str ?: "default";
        struct pane *p;
 
        if (strcmp(type, "invisible") == 0 ||
index 6e5a566a7356f84fdd4ba46eab14e27a8b64f698..fef63bc483f7c82b9efe3476dedba3f8e038a014 100644 (file)
@@ -559,7 +559,7 @@ DEF_CMD(docs_set_ref)
 }
 
 static char *__docs_get_attr(struct doc *doc safe, struct mark *m safe,
-                            char *attr safe)
+                            const char *attr safe)
 {
        struct pane *p;
 
@@ -574,7 +574,7 @@ DEF_CMD(docs_doc_get_attr)
 {
        struct doc *d = ci->home->data;
        struct mark *m = ci->mark;
-       char *attr = ci->str;
+       const char *attr = ci->str;
        char *val;
 
        if (!m || !attr)
@@ -590,7 +590,7 @@ DEF_CMD(docs_doc_get_attr)
 
 DEF_CMD(docs_get_attr)
 {
-       char *attr = ci->str;
+       const char *attr = ci->str;
        char *val;
        struct doc *d = ci->home->data;
 
@@ -793,7 +793,7 @@ DEF_CMD(docs_attach)
 {
        struct doc *d = ci->home->data;
        struct docs *docs = container_of(d, struct docs, doc);
-       char *type = ci->str ?: "default";
+       const char *type = ci->str ?: "default";
        struct pane *p;
 
        if (strcmp(type, "invisible") == 0 ||
index 397cd757830950f74a403349810e5bf7bd8cb9dc..07455bc062eb62aa886d129ebef912b5a71de74a 100644 (file)
@@ -353,7 +353,7 @@ DEF_CMD(mp_attr)
        struct mark *m1 = NULL;
        int ret;
        int d;
-       char *attr = ci->str;
+       const char *attr = ci->str;
 
        if (!ci->mark || !attr)
                return Enoarg;
@@ -419,7 +419,7 @@ DEF_CMD(mp_set_attr)
        struct mark *m = ci->mark;
        struct mark *m1;
        int dn;
-       char *attr = ci->str;
+       const char *attr = ci->str;
 
        if (!attr)
                return Enoarg;
@@ -508,7 +508,7 @@ DEF_CMD(mp_forward)
         */
        struct mp_info *mpi = ci->home->data;
        struct mark *m1, *m2;
-       char *key;
+       const char *key = ci->key;
        int d;
 
        if (!ci->mark2)
@@ -522,7 +522,6 @@ DEF_CMD(mp_forward)
                /* at the wrong end of a part */
                d += 1;
 
-       key = ci->key;
        if (strncmp(key, "multipart-next:", 15) == 0) {
                d += 1;
                key += 15;
index 8fe4116ca2d86bef93fa090e501dcd8222066154..4a63962d6ca90963efda206eb6ff81d6543cc867 100644 (file)
@@ -539,7 +539,7 @@ DEF_CMD(dr_replace)
 
 DEF_CMD(dr_get_attr)
 {
-       char *attr = ci->str;
+       const char *attr = ci->str;
        char *val;
        struct doc *d = ci->home->data;
        struct dr_info *dri = container_of(d, struct dr_info, doc);
index 0d75bde4d8c7aad561bae106d754a61d8fd3936e..8f36675b6710b90652ddc7af819ffb3870db2970 100644 (file)
@@ -199,7 +199,7 @@ static struct map *text_map;
  * the last 4 bytes. (longest UTF-8 encoding of 21bit unicode is 4 bytes).
  * A start of codepoint starts with 0b0 or 0b11, not 0b10.
  */
-static int text_round_len(char *text safe, int len)
+static int text_round_len(const char *text safe, int len)
 {
        /* The string at 'text' is *longer* than 'len', or
         * at least text[len] is defined - it can be nul.  If
@@ -273,7 +273,7 @@ DEF_CMD(text_load_file)
 {
        struct doc *d = ci->home->data;
        int fd = ci->num2;
-       char *name = ci->str;
+       const char *name = ci->str;
        off_t size;
        struct text_alloc *a;
        struct text_chunk *c = NULL;
@@ -332,7 +332,7 @@ DEF_CMD(text_load_file)
                }
        }
        if (name) {
-               char *dname;
+               const char *dname;
 
                if (fstat(fd, &t->stat) < 0) {
                        t->newfile = 1;
@@ -393,14 +393,15 @@ static int do_text_output_file(struct text *t safe, struct doc_ref *start,
 
 static int do_text_write_file(struct text *t safe, struct doc_ref *start,
                              struct doc_ref *end,
-                             char *fname safe)
+                             const char *fname safe)
 {
        /* Don't worry about links for now
         * Create a temp file with #basename#~, write to that,
         * copy mode across, fsync and then rename
         */
        char *tempname = malloc(strlen(fname) + 3 + 10);
-       char *base, *tbase;
+       const char *base;
+       char *tbase;
        int cnt = 0;
        int fd = -1;
        struct stat stb;
@@ -673,7 +674,7 @@ static void text_add_edit(struct text *t safe, struct text_chunk *target safe,
 }
 
 static void text_add_str(struct text *t safe, struct doc_ref *pos safe,
-                        char *str safe,
+                        const char *str safe,
                         struct doc_ref *start, bool *first_edit safe)
 {
        /* Text is added to the end of the referenced chunk, or
@@ -1909,7 +1910,8 @@ static void text_check_consistent(struct text *t safe)
        doc_check_consistent(d);
 }
 
-static void text_add_attrs(struct attrset **attrs safe, char *new safe, int o)
+static void text_add_attrs(struct attrset **attrs safe,
+                          const char *new safe, int o)
 {
        char sep = *new++;
        char *cpy = strdup(new);
@@ -1938,8 +1940,8 @@ DEF_CMD(text_replace)
        struct text *t = container_of(d, struct text, doc);
        struct mark *pm = ci->mark2;
        struct mark *end = ci->mark;
-       char *str = ci->str;
-       char *newattrs = ci->str2;
+       const char *str = ci->str;
+       const char *newattrs = ci->str2;
        bool first = !ci->num2;
        struct mark *early = NULL;
        int status_change = 0;
@@ -2064,8 +2066,8 @@ DEF_CMD(text_doc_get_attr)
 {
        struct doc *d = ci->home->data;
        struct mark *m = ci->mark;
-       char *attr = ci->str;
-       char *val;
+       const char *attr = ci->str;
+       const char *val;
        struct attrset *a;
        int o = 0;
 
@@ -2075,7 +2077,7 @@ DEF_CMD(text_doc_get_attr)
        val = attr_get_str(a, attr, o);
        comm_call(ci->comm2, "callback:get_attr", ci->focus, 0, NULL, val);
        if (ci->num2 == 1) {
-               char *key = attr;
+               const char *key = attr;
                int len = strlen(attr);
                while ((key = attr_get_next_key(a, key, o, &val)) != NULL &&
                       strncmp(key, attr, len) == 0)
@@ -2090,8 +2092,8 @@ DEF_CMD(text_get_attr)
 {
        struct doc *d = ci->home->data;
        struct text *t = container_of(d, struct text, doc);
-       char *attr = ci->str;
-       char *val;
+       const char *attr = ci->str;
+       const char *val;
 
        if (!attr)
                return Enoarg;
@@ -2119,8 +2121,8 @@ DEF_CMD(text_get_attr)
 
 DEF_CMD(text_set_attr)
 {
-       char *attr = ci->str;
-       char *val = ci->str2;
+       const char *attr = ci->str;
+       const char *val = ci->str2;
        struct text_chunk *c;
        struct doc *d = ci->home->data;
        struct text *t = container_of(d, struct text, doc);
index 757b37e90f011f90c9d8b3ab83949f7fdbbd674d..b83cce7aee4a22e2f62f78f51dc7b9e2c45751f2 100644 (file)
@@ -449,7 +449,7 @@ DEF_CMD(search_replace)
 DEF_CMD(do_replace)
 {
        struct es_info *esi = ci->home->data;
-       char *new = ci->str;
+       const char *new = ci->str;
        struct mark *m;
        int len = esi->matched - 1;
 
index b5586ad6d3cb90b765441ccb16481c0e80c41477..94c450816a45e48068e94fd68c9c00a48ebed2e4 100644 (file)
@@ -184,7 +184,7 @@ static inline PyObject *safe Comm_Fromcomm(struct command *c safe)
 
 DEF_CMD(python_load)
 {
-       char *fname = ci->str;
+       const char *fname = ci->str;
        FILE *fp;
        PyObject *globals, *main_mod;
        PyObject *Ed;
@@ -212,7 +212,7 @@ DEF_CMD(python_load)
 
 DEF_CMD(python_load_module)
 {
-       char *name = ci->str;
+       const char *name = ci->str;
        FILE *fp;
        PyObject *globals, *main_mod;
        PyObject *Ed;
@@ -241,9 +241,9 @@ DEF_CMD(python_load_module)
        return 1;
 }
 
-static PyObject *safe python_string(char *s safe)
+static PyObject *safe python_string(const char *s safe)
 {
-       char *c = s;
+       const char *c = s;
        while (*c && !(*c & 0x80))
                c++;
        if (*c)
index 54932b11d60511bb353f19eaef3429d88a68f898..b5bb9fc8fb0bdd1e2296ebf5db8cd633ecec87ef 100644 (file)
@@ -69,9 +69,9 @@ DEF_CMD(history_notify_close)
 DEF_CMD(history_save)
 {
        struct history_info *hi = ci->home->data;
-       char *eol;
-       char *line = ci->str;
-       char *prev;
+       const char *eol;
+       const char *line = ci->str;
+       const char *prev;
 
        if (!hi->history || !ci->str)
                /* history document was destroyed */
index f09c2feb75fc999f36295669f4df892b09bd134e..ca91bf6b824bf63b87d66951ec527ccceedd67e3 100644 (file)
@@ -16,7 +16,7 @@
 #include "core.h"
 
 struct input_mode {
-       char            *mode safe;
+       const char      *mode safe;
        int             num, num2;
        struct pane     *focus, *source;
        struct mark     *point;
@@ -56,7 +56,8 @@ DEF_CMD(set_num2)
 
 DEF_CMD(keystroke)
 {
-       char *key;
+       const char *key;
+       char *vkey = NULL;
        struct input_mode *im = ci->home->data;
        struct pane *p;
        int l;
@@ -72,7 +73,7 @@ DEF_CMD(keystroke)
 
        if (im->mode[0]) {
                int cnt = 1;
-               char *k = ci->str;
+               const char *k = ci->str;
                char *end;
                while ((end = strchr(k, '\037')) != NULL) {
                        cnt += 1;
@@ -82,19 +83,20 @@ DEF_CMD(keystroke)
                }
                l = strlen(im->mode) * cnt + strlen(ci->str) + 1;
 
-               key = malloc(l);
-               memset(key, 0, l);
+               vkey = malloc(l);
+               memset(vkey, 0, l);
                k = ci->str;
                while ((end = strchr(k, '\037')) != NULL) {
                        end += 1;
-                       strcat(key, im->mode);
-                       strncat(key, k, end-k);
+                       strcat(vkey, im->mode);
+                       strncat(vkey, k, end-k);
                        k = end;
                        while (*k == '\037')
                                k++;
                }
-               strcat(key, im->mode);
-               strcat(key, k);
+               strcat(vkey, im->mode);
+               strcat(vkey, k);
+               key = vkey;
        } else
                key = ci->str;
 
@@ -122,8 +124,7 @@ DEF_CMD(keystroke)
        m = im->point;
 
        ret = call(key, p, num, m, NULL, num2);
-       if (key != ci->str)
-               free(key);
+       free(vkey);
        if (ret < 0)
                call("Message:default", ci->focus, 0, NULL,
                     "** Command Failed **");
@@ -146,7 +147,7 @@ DEF_CMD(mouse_event)
        struct timespec now;
        unsigned int b;
        int press;
-       char *mode;
+       const char *mode;
        struct mouse_state *ms = NULL;
 
        clock_gettime(CLOCK_MONOTONIC, &now);
index 6152f4cd23fde88cf52af6fc418b3ab1f9082139..5459a3639223fdd18bca871b3ee85c454e02d489 100644 (file)
@@ -36,7 +36,7 @@ struct key_data {
 
 static struct pane *safe do_keymap_attach(struct pane *p, int global);
 
-static struct command *get_command(struct pane *p safe, char *cmd)
+static struct command *get_command(struct pane *p safe, const char *cmd)
 {
        return call_ret(comm, "global-get-command", p, 0, NULL, cmd);
 }
index 348a66cc4889d1e56dec591cb8f256ef6790e87d..22a3c106105b2be175f874d2e8447eee35368905 100644 (file)
@@ -68,7 +68,7 @@ static int line_height(struct pane *p safe)
        return cr.y;
 }
 
-static void popup_resize(struct pane *p safe, char *style safe)
+static void popup_resize(struct pane *p safe, const char *style safe)
 {
        struct popup_info *ppi = p->data;
        int x,y,w,h;
@@ -289,7 +289,7 @@ DEF_CMD(popup_this)
 DEF_CMD(popup_do_close)
 {
        struct popup_info *ppi = ci->home->data;
-       char *key, *str;
+       const char *key, *str;
        struct pane *target = ppi->target;
        struct command *done;
 
@@ -328,7 +328,7 @@ DEF_CMD(popup_attach)
         */
        struct pane *root, *p;
        struct popup_info *ppi;
-       char *style = ci->str;
+       const char *style = ci->str;
        char *in_popup;
        int z;
 
index a9794138a84d72baa2af3fcbfba1b96c28ffe8c8..d4888093c31781f3bd443347d43011bcf250523d 100644 (file)
@@ -183,7 +183,7 @@ static void as_repush(struct attr_return *ar safe, struct buf *b safe)
 }
 
 static void as_add(struct attr_return *ar safe,
-                  int end, int prio, char *attr safe)
+                  int end, int prio, const char *attr safe)
 {
        struct attr_stack *new, **here;
 
@@ -204,7 +204,7 @@ static void as_add(struct attr_return *ar safe,
 }
 
 static void as_clear(struct attr_return *ar safe,
-                    int prio, char *attr safe)
+                    int prio, const char *attr safe)
 {
        struct attr_stack *st;
 
@@ -241,8 +241,8 @@ DEF_CMD(text_attr_callback)
 static void call_map_mark(struct pane *f safe, struct mark *m safe,
                          struct attr_return *ar safe)
 {
-       char *key = "render:";
-       char *val;
+       const char *key = "render:";
+       const char *val;
 
        while ((key = attr_get_next_key(m->attrs, key, -1, &val)) != NULL &&
               strncmp(key, "render:", 7) == 0)
index 1df9c719b06fa74a523ef8fccc1d9f1dc906079b..e487757101db0c4ad46fd09347e4da961e08c58d 100644 (file)
@@ -232,7 +232,8 @@ static char *safe charset_word(struct pane *doc safe, struct mark *m safe)
        return last;
 }
 
-static void copy_header(struct pane *doc safe, char *hdr safe, char *type,
+static void copy_header(struct pane *doc safe,
+                       const char *hdr safe, const char *type,
                        struct mark *start safe, struct mark *end safe,
                        struct pane *p safe, struct mark *point safe)
 {
@@ -307,7 +308,8 @@ static void copy_header(struct pane *doc safe, char *hdr safe, char *type,
        mark_free(m);
 }
 
-static void copy_headers(struct pane *p safe, char *hdr safe, char *type,
+static void copy_headers(struct pane *p safe, const char *hdr safe,
+                        const char *type,
                         struct pane *doc safe, struct mark *pt safe)
 {
        struct header_info *hi = p->data;
@@ -352,7 +354,7 @@ static char *extract_header(struct pane *p safe, struct mark *start safe,
        return buf_final(&buf);
 }
 
-static char *load_header(struct pane *home safe, char *hdr safe)
+static char *load_header(struct pane *home safe, const char *hdr safe)
 {
        struct header_info *hi = home->data;
        struct mark *m, *n;
@@ -368,8 +370,8 @@ static char *load_header(struct pane *home safe, char *hdr safe)
 
 DEF_CMD(header_get)
 {
-       char *hdr = ci->str;
-       char *type = ci->str2;
+       const char *hdr = ci->str;
+       const char *type = ci->str2;
        char *attr = NULL;
        char *c, *t;
 
index 54631ab9a63369157ef46bf028205de614528e33..96d3e22daaa59ff200bcb80ea8c6c4725c35d7b3 100644 (file)
@@ -152,7 +152,8 @@ DEF_CMD(tile_attach)
        return comm_call(ci->comm2, "callback:attach", p);
 }
 
-static struct pane *tile_split(struct pane **pp safe, int horiz, int after, char *name)
+static struct pane *tile_split(struct pane **pp safe, int horiz, int after,
+                              const char *name)
 {
        /* Create a new pane near the given one, reducing its size,
         * and possibly the size of other siblings.
@@ -643,7 +644,8 @@ static struct pane *tile_root_popup(struct tileinfo *ti safe)
        return next_child(ti->p, NULL, 1);
 }
 
-static struct tileinfo *safe tile_next_named(struct tileinfo *ti safe, char *name)
+static struct tileinfo *safe tile_next_named(struct tileinfo *ti safe,
+                                            const char *name)
 {
        struct tileinfo *t = ti;
        while ((t = list_next_entry(t, tiles)) != ti) {
diff --git a/misc.h b/misc.h
index ae74501a6798b9b9cb363183ee78f33f07ff02d3..65be4a94027bc5d60cd6a3c766f330584cff4234 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -13,8 +13,8 @@ struct buf {
 };
 
 void buf_init(struct buf *b safe);
-void buf_concat(struct buf *b safe, char *s safe);
-void buf_concat_len(struct buf *b safe, char *s safe, int l);
+void buf_concat(struct buf *b safe, const char *s safe);
+void buf_concat_len(struct buf *b safe, const char *s safe, int l);
 void buf_append(struct buf *b safe, wchar_t wch);
 void buf_append_byte(struct buf *b safe, char c);
 static inline char *safe buf_final(struct buf *b safe)
@@ -40,8 +40,8 @@ enum timetype {
 };
 void time_start(enum timetype);
 void time_stop(enum timetype);
-void time_start_key(char *key safe);
-void time_stop_key(char *key safe);
+void time_start_key(const char *key safe);
+void time_stop_key(const char *key safe);
 
 void stat_count(char *name safe);
 
index 7d5c0596fb9becb08f44f5e045bb8a641a3348e9..526a60849f24890921dc80e27ad9574a446f4688 100644 (file)
@@ -21,8 +21,8 @@
 #include "core.h"
 
 static struct map *emacs_map;
-static char * safe file_normalize(struct pane *p safe, char *path,
-                                 char *initial_path);
+static const char * safe file_normalize(struct pane *p safe, const char *path,
+                                       const char *initial_path);
 
 /* num2 is used to track if successive commands are related.
  * Only low 16 bits identify command, other bits are free.
@@ -563,7 +563,7 @@ DEF_CMD(emacs_exit)
 DEF_CMD(emacs_insert)
 {
        int ret;
-       char *str;
+       const char *str;
 
        if (!ci->mark)
                return Enoarg;
@@ -581,7 +581,7 @@ DEF_CMD(emacs_quote_insert)
 {
        int ret;
        char buf[2] = ".";
-       char *str = buf;
+       const char *str = buf;
 
        if (!ci->mark)
                return Enoarg;
@@ -838,7 +838,9 @@ static void findmap_init(void)
        key_add(fh_map, "M-Chr-n", &find_prevnext);
 }
 
-static char * safe file_normalize(struct pane *p safe, char *path, char *initial_path)
+static const char * safe file_normalize(struct pane *p safe,
+                                       const char *path,
+                                       const char *initial_path)
 {
        int len = strlen(initial_path?:"");
        char *dir;
@@ -874,7 +876,7 @@ DEF_CMD(emacs_findfile)
 {
        int fd;
        struct pane *p, *par;
-       char *path;
+       const char *path;
        char buf[PATH_MAX];
        char *e;
 
@@ -960,8 +962,8 @@ REDEF_CMD(emacs_file_complete)
         * Find a document for the directory and attach as a completing
         * popup menu
         */
-       char *str;
-       char *d, *b;
+       const char *str;
+       const char *d, *b;
        int fd;
        struct pane *pop, *docp, *p;
        struct call_return cr;
@@ -1211,7 +1213,7 @@ DEF_CMD(emacs_shell)
 DEF_CMD(emacs_num)
 {
        int rpt = ci->num;
-       char *last = ci->key + strlen(ci->key)-1;
+       const char *last = ci->key + strlen(ci->key)-1;
        int neg = 0;
 
        if (rpt < 0) {
@@ -1877,7 +1879,8 @@ DEF_CMD(attach_mode_emacs)
 
 DEF_CMD(attach_file_entry)
 {
-       pane_register(ci->focus, 0, &find_handle.c, ci->str ?: "shellcmd");
+       pane_register(ci->focus, 0, &find_handle.c,
+                     (void*) ci->str ?: "shellcmd");
        return 1;
 }
 
index 04bb4aabd535bba64a032ab3a296af53f2285cab..9307e3975e58d8486bb3faab6e3936b091c912a1 100644 (file)
@@ -28,13 +28,14 @@ struct rlcb {
        struct command c;
        int keep, plen, cmp;
        int prefix_only;
-       char *prefix safe, *str;
+       const char *prefix safe, *str;
 };
 
-static char *add_highlight_prefix(char *orig, int start, int plen, char *attr safe)
+static const char *add_highlight_prefix(const char *orig, int start, int plen,
+                                       const char *attr safe)
 {
        struct buf ret;
-       char *c safe;
+       const char *c safe;
 
        if (orig == NULL)
                return orig;
@@ -61,7 +62,7 @@ static char *add_highlight_prefix(char *orig, int start, int plen, char *attr sa
 DEF_CMD(save_highlighted)
 {
        struct rlcb *cb = container_of(ci->comm, struct rlcb, c);
-       char *start;
+       const char *start;
 
        if (!ci->str)
                return 1;
@@ -119,7 +120,7 @@ DEF_CMD(render_complete_line)
                return 0;
 
        ret = comm_call(ci->comm2, "callback:render", ci->focus, 0, NULL, cb.str);
-       free(cb.str);
+       free((void*)cb.str);
        if (ci->num != NO_NUMERIC)
                /* Was rendering to find a cursor, don't need to skip */
                return ret;
@@ -161,8 +162,10 @@ DEF_CMD(rlcb)
        return 1;
 }
 
-static int do_render_complete_prev(struct complete_data *cd safe, struct mark *m safe,
-                                  struct pane *focus safe, int n, char **savestr)
+static int do_render_complete_prev(struct complete_data *cd safe,
+                                  struct mark *m safe,
+                                  struct pane *focus safe, int n,
+                                  const char **savestr)
 {
        /* If 'n' is 0 we just need 'start of line' so use
         * underlying function.
@@ -353,7 +356,7 @@ DEF_CMD(complete_eol)
        return 1;
 }
 
-static int common_len(char *a safe, char *b safe)
+static int common_len(const char *a safe, const char *b safe)
 {
        int len = 0;
        while (*a && *a == *b) {
@@ -364,7 +367,7 @@ static int common_len(char *a safe, char *b safe)
        return len;
 }
 
-static void adjust_pre(char *common safe, char *new safe, int len)
+static void adjust_pre(char *common safe, const char *new safe, int len)
 {
        int l = strlen(common);
        int newlen = 0;
@@ -390,7 +393,7 @@ DEF_CMD(complete_set_prefix)
        struct complete_data *cd = p->data;
        struct mark *m;
        struct mark *m2 = NULL;
-       char *c;
+       const char *c;
        int cnt = 0;
        char *common = NULL;
        char *common_pre = NULL;
@@ -410,7 +413,7 @@ DEF_CMD(complete_set_prefix)
 
        while (do_render_complete_prev(cd, m, p->parent, 1, &c) > 0 && c) {
                int l;
-               char *match = c;
+               const char *match = c;
                if (!cd->prefix_only)
                        match = strstr(match, cd->prefix);
                if (!match)
diff --git a/rexel.c b/rexel.c
index b4cc403f1f2114281ecefe90d3bde15f6d95ad2c..af3d8a17eec80905ed2b48033dc51f3867176002 100644 (file)
--- a/rexel.c
+++ b/rexel.c
@@ -582,7 +582,7 @@ int rxl_advance(struct match_state *st safe, wint_t ch, int flag)
 }
 
 struct parse_state {
-       char    *patn safe;
+       const char      *patn safe;
        unsigned short  *rxl;
        int     next;
        unsigned short  *sets;
@@ -799,7 +799,7 @@ static void add_class(struct parse_state *st safe, int plane, wctype_t cls)
        return;
 }
 
-static int is_set_element(char *p safe)
+static int is_set_element(const char *p safe)
 {
        int i;
        if (*p != '[')
@@ -820,7 +820,7 @@ static int is_set_element(char *p safe)
 static int do_parse_set(struct parse_state *st safe, int plane)
 {
        mbstate_t ps = {};
-       char *p safe = st->patn;
+       const char *p safe = st->patn;
        wchar_t ch;
        int newplane = 0xFFFFFF;
        int planes = 0;
@@ -841,7 +841,8 @@ static int do_parse_set(struct parse_state *st safe, int plane)
                                return -1;
                        case ':': /* character class */
                        {
-                               char *e, *cls;
+                               const char *e;
+                               char *cls;
                                wctype_t wct;
                                p += 2;
                                e = strchr(p, ':');
@@ -915,7 +916,7 @@ static int do_parse_set(struct parse_state *st safe, int plane)
 static int parse_set(struct parse_state *st safe)
 {
        int plane;
-       char *patn;
+       const char *patn;
        int set;
 
        if (*st->patn++ != '[')
@@ -946,7 +947,7 @@ static int parse_set(struct parse_state *st safe)
        return 1;
 }
 
-static int cvt_hex(char *s safe, int len)
+static int cvt_hex(const char *s safe, int len)
 {
        long rv = 0;
        while (len) {
@@ -1257,7 +1258,7 @@ static int parse_re(struct parse_state *st safe)
        return 1;
 }
 
-unsigned short *rxl_parse(char *patn safe, int *lenp, int nocase)
+unsigned short *rxl_parse(const char *patn safe, int *lenp, int nocase)
 {
        struct parse_state st;
        st.patn = patn;
@@ -1286,7 +1287,7 @@ unsigned short *rxl_parse(char *patn safe, int *lenp, int nocase)
        return st.rxl;
 }
 
-unsigned short *safe rxl_parse_verbatim(char *patn safe, int nocase)
+unsigned short *safe rxl_parse_verbatim(const char *patn safe, int nocase)
 {
        struct parse_state st;
        int i, l;
diff --git a/rexel.h b/rexel.h
index 159e2e824b15e191e71841351e979d39de6f8908..7b94f52211904ff68c5e3f499f8dfee7e5545865 100644 (file)
--- a/rexel.h
+++ b/rexel.h
@@ -3,8 +3,8 @@
  * May be distributed under terms of GPLv2 - see file:COPYING
  */
 struct match_state;
-unsigned short *rxl_parse(char *patn safe, int *lenp, int nocase);
-unsigned short *safe rxl_parse_verbatim(char *patn safe, int nocase);
+unsigned short *rxl_parse(const char *patn safe, int *lenp, int nocase);
+unsigned short *safe rxl_parse_verbatim(const char *patn safe, int nocase);
 struct match_state *safe rxl_prepare(unsigned short *rxl safe,
                                     int anchored, int *lenp);
 void rxl_free_state(struct match_state *s safe);