mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 10:07:38 -04:00
filetypes.c compress builtin filetypes
the builtin audio filetypes all use an int to signal (FILE_ATTR_AUDIO) it takes less space to give them their own array and apply the attrib at runtime bit of const correctness and some other small cleanup Change-Id: I1cc3de9fe4ec1d5e49c8154cffdef3f05cf0b235
This commit is contained in:
parent
75282a1683
commit
8bf6dc521f
2 changed files with 61 additions and 101 deletions
157
apps/filetypes.c
157
apps/filetypes.c
|
@ -50,74 +50,24 @@ static void read_builtin_types_init(void) INIT_ATTR;
|
||||||
static void read_viewers_config_init(void) INIT_ATTR;
|
static void read_viewers_config_init(void) INIT_ATTR;
|
||||||
static void read_config_init(int fd) INIT_ATTR;
|
static void read_config_init(int fd) INIT_ATTR;
|
||||||
|
|
||||||
/* a table for the known file types */
|
/* string array for known audio file types (tree_attr == FILE_ATTR_AUDIO) */
|
||||||
static const struct filetype inbuilt_filetypes[] = {
|
static const char* inbuilt_audio_filetypes[] = {
|
||||||
{ "mp3", FILE_ATTR_AUDIO },
|
"mp3", "mp2", "mpa", "mp1", "ogg", "oga", "wma", "wmv", "asf", "wav",
|
||||||
{ "mp2", FILE_ATTR_AUDIO },
|
"flac", "ac3", "a52", "mpc", "wv", "m4a", "m4b", "mp4", "mod", "mpga",
|
||||||
{ "mpa", FILE_ATTR_AUDIO },
|
"shn", "aif", "aiff", "spx", "opus", "sid", "adx", "nsf", "nsfe", "spc",
|
||||||
{ "mp1", FILE_ATTR_AUDIO },
|
"ape", "mac", "sap", "rm", "ra", "rmvb", "cmc", "cm3", "cmr", "cms", "dmc",
|
||||||
{ "ogg", FILE_ATTR_AUDIO },
|
"dlt", "mpt", "mpd", "rmt", "tmc", "tm8", "tm2", "oma", "aa3", "at3", "mmf",
|
||||||
{ "oga", FILE_ATTR_AUDIO },
|
"au", "snd", "vox", "w64", "tta", "ay", "vtx", "gbs", "hes", "sgc", "vgm",
|
||||||
{ "wma", FILE_ATTR_AUDIO },
|
"vgz", "kss", "aac",
|
||||||
{ "wmv", FILE_ATTR_AUDIO },
|
};
|
||||||
{ "asf", FILE_ATTR_AUDIO },
|
|
||||||
{ "wav", FILE_ATTR_AUDIO },
|
struct filetype_inbuilt {
|
||||||
{ "flac", FILE_ATTR_AUDIO },
|
const char* extension;
|
||||||
{ "ac3", FILE_ATTR_AUDIO },
|
int tree_attr;
|
||||||
{ "a52", FILE_ATTR_AUDIO },
|
};
|
||||||
{ "mpc", FILE_ATTR_AUDIO },
|
|
||||||
{ "wv", FILE_ATTR_AUDIO },
|
/* a table for the known file types, besides audio */
|
||||||
{ "m4a", FILE_ATTR_AUDIO },
|
static const struct filetype_inbuilt inbuilt_filetypes[] = {
|
||||||
{ "m4b", FILE_ATTR_AUDIO },
|
|
||||||
{ "mp4", FILE_ATTR_AUDIO },
|
|
||||||
{ "mod", FILE_ATTR_AUDIO },
|
|
||||||
{ "mpga", FILE_ATTR_AUDIO },
|
|
||||||
{ "shn", FILE_ATTR_AUDIO },
|
|
||||||
{ "aif", FILE_ATTR_AUDIO },
|
|
||||||
{ "aiff", FILE_ATTR_AUDIO },
|
|
||||||
{ "spx" , FILE_ATTR_AUDIO },
|
|
||||||
{ "opus", FILE_ATTR_AUDIO },
|
|
||||||
{ "sid", FILE_ATTR_AUDIO },
|
|
||||||
{ "adx", FILE_ATTR_AUDIO },
|
|
||||||
{ "nsf", FILE_ATTR_AUDIO },
|
|
||||||
{ "nsfe", FILE_ATTR_AUDIO },
|
|
||||||
{ "spc", FILE_ATTR_AUDIO },
|
|
||||||
{ "ape", FILE_ATTR_AUDIO },
|
|
||||||
{ "mac", FILE_ATTR_AUDIO },
|
|
||||||
{ "sap" , FILE_ATTR_AUDIO },
|
|
||||||
{ "rm", FILE_ATTR_AUDIO },
|
|
||||||
{ "ra", FILE_ATTR_AUDIO },
|
|
||||||
{ "rmvb", FILE_ATTR_AUDIO },
|
|
||||||
{ "cmc", FILE_ATTR_AUDIO },
|
|
||||||
{ "cm3", FILE_ATTR_AUDIO },
|
|
||||||
{ "cmr", FILE_ATTR_AUDIO },
|
|
||||||
{ "cms", FILE_ATTR_AUDIO },
|
|
||||||
{ "dmc", FILE_ATTR_AUDIO },
|
|
||||||
{ "dlt", FILE_ATTR_AUDIO },
|
|
||||||
{ "mpt", FILE_ATTR_AUDIO },
|
|
||||||
{ "mpd", FILE_ATTR_AUDIO },
|
|
||||||
{ "rmt", FILE_ATTR_AUDIO },
|
|
||||||
{ "tmc", FILE_ATTR_AUDIO },
|
|
||||||
{ "tm8", FILE_ATTR_AUDIO },
|
|
||||||
{ "tm2", FILE_ATTR_AUDIO },
|
|
||||||
{ "oma", FILE_ATTR_AUDIO },
|
|
||||||
{ "aa3", FILE_ATTR_AUDIO },
|
|
||||||
{ "at3", FILE_ATTR_AUDIO },
|
|
||||||
{ "mmf", FILE_ATTR_AUDIO },
|
|
||||||
{ "au", FILE_ATTR_AUDIO },
|
|
||||||
{ "snd", FILE_ATTR_AUDIO },
|
|
||||||
{ "vox", FILE_ATTR_AUDIO },
|
|
||||||
{ "w64", FILE_ATTR_AUDIO },
|
|
||||||
{ "tta", FILE_ATTR_AUDIO },
|
|
||||||
{ "ay", FILE_ATTR_AUDIO },
|
|
||||||
{ "vtx", FILE_ATTR_AUDIO },
|
|
||||||
{ "gbs", FILE_ATTR_AUDIO },
|
|
||||||
{ "hes", FILE_ATTR_AUDIO },
|
|
||||||
{ "sgc", FILE_ATTR_AUDIO },
|
|
||||||
{ "vgm", FILE_ATTR_AUDIO },
|
|
||||||
{ "vgz", FILE_ATTR_AUDIO },
|
|
||||||
{ "kss", FILE_ATTR_AUDIO },
|
|
||||||
{ "aac", FILE_ATTR_AUDIO },
|
|
||||||
{ "m3u", FILE_ATTR_M3U },
|
{ "m3u", FILE_ATTR_M3U },
|
||||||
{ "m3u8", FILE_ATTR_M3U },
|
{ "m3u8", FILE_ATTR_M3U },
|
||||||
{ "cfg", FILE_ATTR_CFG },
|
{ "cfg", FILE_ATTR_CFG },
|
||||||
|
@ -219,17 +169,20 @@ long tree_get_filetype_voiceclip(int attr)
|
||||||
struct file_type {
|
struct file_type {
|
||||||
enum themable_icons icon; /* the icon which shall be used for it, NOICON if unknown */
|
enum themable_icons icon; /* the icon which shall be used for it, NOICON if unknown */
|
||||||
unsigned char attr; /* FILE_ATTR_MASK >> 8 */
|
unsigned char attr; /* FILE_ATTR_MASK >> 8 */
|
||||||
char* plugin; /* Which plugin to use, NULL if unknown, or builtin */
|
const char* plugin; /* Which plugin to use, NULL if unknown, or builtin */
|
||||||
char* extension; /* NULL for none */
|
const char* extension; /* NULL for none */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct file_type filetypes[MAX_FILETYPES];
|
static struct file_type filetypes[MAX_FILETYPES];
|
||||||
static int custom_filetype_icons[MAX_FILETYPES];
|
|
||||||
|
static enum themable_icons custom_filetype_icons[MAX_FILETYPES];
|
||||||
|
|
||||||
static bool custom_icons_loaded = false;
|
static bool custom_icons_loaded = false;
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
static int custom_colors[MAX_FILETYPES];
|
static int custom_colors[MAX_FILETYPES];
|
||||||
#endif
|
#endif
|
||||||
struct filetype_unknown {
|
struct filetype_unknown {
|
||||||
int icon;
|
enum themable_icons icon;
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
int color;
|
int color;
|
||||||
#endif
|
#endif
|
||||||
|
@ -269,14 +222,14 @@ static struct buflib_callbacks ops = {
|
||||||
.shrink_callback = NULL,
|
.shrink_callback = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *filetypes_strdup(char* string)
|
static const char *filetypes_strdup(char* string)
|
||||||
{
|
{
|
||||||
char *buffer = core_get_data(strdup_handle) + strdup_cur_idx;
|
char *buffer = core_get_data(strdup_handle) + strdup_cur_idx;
|
||||||
strdup_cur_idx += strlcpy(buffer, string, strdup_bufsize-strdup_cur_idx)+1;
|
strdup_cur_idx += strlcpy(buffer, string, strdup_bufsize-strdup_cur_idx)+1;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *filetypes_store_plugin(char *plugin, int n)
|
static const char *filetypes_store_plugin(char *plugin, int n)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
/* if the plugin is in the list already, use it. */
|
/* if the plugin is in the list already, use it. */
|
||||||
|
@ -353,7 +306,7 @@ void read_viewer_theme_file(void)
|
||||||
int fd;
|
int fd;
|
||||||
char *ext, *icon;
|
char *ext, *icon;
|
||||||
int i;
|
int i;
|
||||||
int *icon_dest;
|
enum themable_icons *icon_dest;
|
||||||
global_status.viewer_icon_count = 0;
|
global_status.viewer_icon_count = 0;
|
||||||
custom_icons_loaded = false;
|
custom_icons_loaded = false;
|
||||||
custom_filetype_icons[0] = Icon_Folder;
|
custom_filetype_icons[0] = Icon_Folder;
|
||||||
|
@ -456,31 +409,43 @@ static void rm_whitespaces(char* str)
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fill_from_builtin(const char *ext, int tree_attr)
|
||||||
|
{
|
||||||
|
size_t icon_count = ARRAY_SIZE(inbuilt_attr_icons_voices);
|
||||||
|
if (filetype_count >= MAX_FILETYPES)
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct file_type *filetype = &filetypes[filetype_count];
|
||||||
|
filetype->icon = unknown_file.icon;
|
||||||
|
filetype->attr = tree_attr>>8;
|
||||||
|
filetype->plugin = NULL;
|
||||||
|
filetype->extension = ext;
|
||||||
|
|
||||||
|
if (filetype->attr > highest_attr)
|
||||||
|
highest_attr = filetype->attr;
|
||||||
|
|
||||||
|
for (size_t j = icon_count - 1; j < icon_count; j--)
|
||||||
|
{
|
||||||
|
if (tree_attr == inbuilt_attr_icons_voices[j].tree_attr)
|
||||||
|
{
|
||||||
|
filetype->icon = inbuilt_attr_icons_voices[j].icon;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filetype_count++;
|
||||||
|
}
|
||||||
|
|
||||||
static void read_builtin_types_init(void)
|
static void read_builtin_types_init(void)
|
||||||
{
|
{
|
||||||
int tree_attr;
|
for(size_t i = 0; (i < ARRAY_SIZE(inbuilt_audio_filetypes)); i++)
|
||||||
size_t count = ARRAY_SIZE(inbuilt_filetypes);
|
|
||||||
size_t icon_count = ARRAY_SIZE(inbuilt_attr_icons_voices);
|
|
||||||
for(size_t i = 0; (i < count) && (filetype_count < MAX_FILETYPES); i++)
|
|
||||||
{
|
{
|
||||||
filetypes[filetype_count].extension = inbuilt_filetypes[i].extension;
|
fill_from_builtin(inbuilt_audio_filetypes[i], FILE_ATTR_AUDIO);
|
||||||
filetypes[filetype_count].plugin = NULL;
|
}
|
||||||
|
|
||||||
tree_attr = inbuilt_filetypes[i].tree_attr;
|
for(size_t i = 0; (i < ARRAY_SIZE(inbuilt_filetypes)); i++)
|
||||||
filetypes[filetype_count].attr = tree_attr>>8;
|
{
|
||||||
if (filetypes[filetype_count].attr > highest_attr)
|
fill_from_builtin(inbuilt_filetypes[i].extension,
|
||||||
highest_attr = filetypes[filetype_count].attr;
|
inbuilt_filetypes[i].tree_attr);
|
||||||
|
|
||||||
filetypes[filetype_count].icon = unknown_file.icon;
|
|
||||||
for (size_t j = icon_count - 1; j < icon_count; j--)
|
|
||||||
{
|
|
||||||
if (tree_attr == inbuilt_attr_icons_voices[j].tree_attr)
|
|
||||||
{
|
|
||||||
filetypes[filetype_count].icon = inbuilt_attr_icons_voices[j].icon;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filetype_count++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,6 @@
|
||||||
#define FILE_ATTR_LOG 0x1500 /* log file */
|
#define FILE_ATTR_LOG 0x1500 /* log file */
|
||||||
#define FILE_ATTR_MASK 0xFF00 /* which bits tree.c uses for file types */
|
#define FILE_ATTR_MASK 0xFF00 /* which bits tree.c uses for file types */
|
||||||
|
|
||||||
struct filetype {
|
|
||||||
char* extension;
|
|
||||||
int tree_attr;
|
|
||||||
};
|
|
||||||
|
|
||||||
long tree_get_filetype_voiceclip(int attr);
|
long tree_get_filetype_voiceclip(int attr);
|
||||||
|
|
||||||
/* init the filetypes structs.
|
/* init the filetypes structs.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue