xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit d84f9c96d4e871fd5c588bbc4145ec01457830ad

Make engine/keys copy description of foreign keys
Lua part no longer needs to keep the string alive.
Author: xaizek
Author date (UTC): 2025-06-13 12:56
Committer name: xaizek
Committer date (UTC): 2025-06-14 08:36
Parent(s): e3e16ec7d163bb6dc9cf7354c6ba9e7215e706db
Signing key: 99DC5E4DB05F6BE2
Tree: ea0fb2ee14966d17ceb2b20ebe86c6b7b4341aad
File Lines added Lines deleted
src/engine/keys.c 17 1
src/engine/keys.h 6 3
src/lua/vifm_keys.c 2 2
File src/engine/keys.c changed (mode: 100644) (index b40db994d..1c1d49df6)
... ... free_chunk_data(key_chunk_t *chunk)
305 305 { {
306 306 free(chunk->conf.data.cmd); free(chunk->conf.data.cmd);
307 307 } }
308
309 if(chunk->foreign)
310 {
311 free((char *)chunk->conf.descr);
312 }
308 313 } }
309 314
310 315 void void
 
... ... vle_keys_foreign_add(const wchar_t lhs[], const key_conf_t *info,
1015 1020 return -1; return -1;
1016 1021 } }
1017 1022
1023 key_conf_t conf = *info;
1024 if(conf.descr != NULL)
1025 {
1026 conf.descr = strdup(conf.descr);
1027 if(conf.descr == NULL)
1028 {
1029 return -1;
1030 }
1031 }
1032
1018 1033 key_chunk_t *curr = add_keys_inner(root, lhs); key_chunk_t *curr = add_keys_inner(root, lhs);
1019 1034 if(curr == NULL) if(curr == NULL)
1020 1035 { {
1036 free((char *)conf.descr);
1021 1037 return -1; return -1;
1022 1038 } }
1023 1039
1024 1040 curr->type = (info->followed == FOLLOWED_BY_NONE) ? BUILTIN_KEYS curr->type = (info->followed == FOLLOWED_BY_NONE) ? BUILTIN_KEYS
1025 1041 : BUILTIN_WAIT_POINT; : BUILTIN_WAIT_POINT;
1026 1042 curr->foreign = 1; curr->foreign = 1;
1027 curr->conf = *info;
1043 curr->conf = conf;
1028 1044 return 0; return 0;
1029 1045 } }
1030 1046
File src/engine/keys.h changed (mode: 100644) (index 967fc894f..1d1a0ec5e)
... ... typedef struct
129 129
130 130 vle_suggest_func suggest; /* Suggestion function (can be NULL). Invoked for vle_suggest_func suggest; /* Suggestion function (can be NULL). Invoked for
131 131 multikeys. */ multikeys. */
132 const char *descr; /* Brief description of the key (can be NULL). */
132 const char *descr; /* Brief description of the key (can be NULL).
133 Not a literal for foreign keys, but needs
134 to be `const` for arrays of builtin keys. */
133 135 void *user_data; /* User data for the key (can be NULL). */ void *user_data; /* User data for the key (can be NULL). */
134 136 } }
135 137 key_conf_t; key_conf_t;
 
... ... int vle_keys_add(keys_add_info_t cmds[], size_t len, int mode);
180 182 int vle_keys_add_selectors(keys_add_info_t cmds[], size_t len, int mode); int vle_keys_add_selectors(keys_add_info_t cmds[], size_t len, int mode);
181 183
182 184 /* Registers a foreign builtin-like key (but among user's keys) or a selector /* Registers a foreign builtin-like key (but among user's keys) or a selector
183 * (among builtin selectors, so they can't clash). Returns non-zero on error,
184 * otherwise zero is returned. */
185 * (among builtin selectors, so they can't clash). The string pointed to by
186 * info->descr field is copied. Returns non-zero on error, otherwise zero is
187 * returned. */
185 188 int vle_keys_foreign_add(const wchar_t lhs[], const key_conf_t *info, int vle_keys_foreign_add(const wchar_t lhs[], const key_conf_t *info,
186 189 int is_selector, int mode); int is_selector, int mode);
187 190
File src/lua/vifm_keys.c changed (mode: 100644) (index 9a26c6369..63283d4dc)
... ... VLUA_API(keys_add)(lua_State *lua)
80 80 wcscpy(lhs, tmp_lhs); wcscpy(lhs, tmp_lhs);
81 81 free(tmp_lhs); free(tmp_lhs);
82 82
83 const char *descr = "";
83 const char *descr = NULL;
84 84 if(vlua_cmn_check_opt_field(lua, 1, "description", LUA_TSTRING)) if(vlua_cmn_check_opt_field(lua, 1, "description", LUA_TSTRING))
85 85 { {
86 descr = vlua_state_store_string(vlua, lua_tostring(lua, -1));
86 descr = lua_tostring(lua, -1);
87 87 } }
88 88
89 89 int is_selector = 0; int is_selector = 0;
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master