filetree.c move static and stack allocated buffers around

it makes more sense to make the main buffer static and make the
second (infrequently needed) buffer as stack allocated

Change-Id: Ide7c1a7a312124e47a23ed0ab75a90d7b8be982e
This commit is contained in:
William Wilgus 2021-10-20 16:05:21 -04:00
parent e1553d860d
commit 9878226e4d
3 changed files with 17 additions and 15 deletions

View File

@ -435,7 +435,8 @@ static void ft_load_font(char *file)
int ft_enter(struct tree_context* c)
{
int rc = GO_TO_PREVIOUS;
char buf[MAX_PATH];
static char buf[MAX_PATH];
struct entry* file = tree_get_entry_at(c, c->selected_item);
if (!file)
{
@ -634,17 +635,18 @@ int ft_enter(struct tree_context* c)
case FILE_ATTR_LUA:
case FILE_ATTR_OPX:
{
char *plugin = buf, *argument = NULL, lua_path[MAX_PATH];
char *plugin = buf, *argument = NULL;
char plugin_path[MAX_PATH];
int ret;
if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) {
snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */
plugin = lua_path;
snprintf(plugin_path, sizeof(plugin_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */
plugin = plugin_path;
argument = buf;
}
else if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_OPX) {
snprintf(lua_path, sizeof(lua_path)-1, "%s/open_plugins.rock", VIEWERS_DIR); /* Use a #define here ? */
plugin = lua_path;
snprintf(plugin_path, sizeof(plugin_path)-1, "%s/open_plugins.rock", VIEWERS_DIR); /* Use a #define here ? */
plugin = plugin_path;
argument = buf;
}
@ -685,7 +687,8 @@ int ft_enter(struct tree_context* c)
default:
{
const char* plugin;
char plugin_path[MAX_PATH];
const char *argument = buf;
if (global_settings.party_mode && audio_status()) {
splash(HZ, ID2P(LANG_PARTY_MODE));
break;
@ -698,10 +701,10 @@ int ft_enter(struct tree_context* c)
return rc;
}
plugin = filetype_get_plugin(file);
plugin = filetype_get_plugin(file, plugin_path, sizeof(plugin_path));
if (plugin)
{
switch (plugin_load(plugin,buf))
switch (plugin_load(plugin, argument))
{
case PLUGIN_USB_CONNECTED:
rc = GO_TO_FILEBROWSER;

View File

@ -531,17 +531,16 @@ int filetype_get_icon(int attr)
return filetypes[index].icon;
}
char* filetype_get_plugin(const struct entry* file)
char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len)
{
static char plugin_name[MAX_PATH];
int index = find_attr(file->attr);
if (index < 0)
if (index < 0 || !buffer)
return NULL;
if (filetypes[index].plugin == NULL)
return NULL;
snprintf(plugin_name, MAX_PATH, "%s/%s.%s",
snprintf(buffer, buffer_len, "%s/%s.%s",
PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION);
return plugin_name;
return buffer;
}
bool filetype_supported(int attr)

View File

@ -73,7 +73,7 @@ int filetype_get_color(const char* name, int attr);
#endif
int filetype_get_icon(int attr);
/* return the plugin filename associated with the file */
char* filetype_get_plugin(const struct entry* file);
char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len);
/* returns true if the attr is supported */
bool filetype_supported(int attr);