From 194bc8660de133a2ff983209ab0ad4e18bb9ad89 Mon Sep 17 00:00:00 2001 From: Teruaki Kawashima Date: Sat, 27 Nov 2010 12:57:19 +0000 Subject: [PATCH] Add helper function to get index from file extension. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28684 a1c6a512-1295-4272-9138-f99709370657 --- apps/filetypes.c | 76 ++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/apps/filetypes.c b/apps/filetypes.c index cd4f4e79b7..f23026ea69 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -196,6 +196,21 @@ static char *filetypes_store_plugin(char *plugin, int n) viewers[viewer_count++] = n; return filetypes_strdup(plugin); } + +static int find_extension(const char* extension) +{ + int i; + if (!extension) + return -1; + for (i=1; i= 0) + hex_to_rgb(color, &custom_colors[i]); } close(fd); } @@ -268,23 +277,19 @@ void read_viewer_theme_file(void) { if (!settings_parseline(buffer, &ext, &icon)) continue; - for (i=0; i= 0) { - if (filetypes[i].extension && - !strcasecmp(ext, filetypes[i].extension)) + if (*icon == '*') + custom_filetype_icons[i] = atoi(icon+1); + else if (*icon == '-') + custom_filetype_icons[i] = Icon_NOICON; + else if (*icon >= '0' && *icon <= '9') { - if (*icon == '*') - custom_filetype_icons[i] = atoi(icon+1); - else if (*icon == '-') - custom_filetype_icons[i] = Icon_NOICON; - else if (*icon >= '0' && *icon <= '9') - { - int number = atoi(icon); - if (number > global_status.viewer_icon_count) - global_status.viewer_icon_count++; - custom_filetype_icons[i] = Icon_Last_Themeable + number; - } - break; + int number = atoi(icon); + if (number > global_status.viewer_icon_count) + global_status.viewer_icon_count++; + custom_filetype_icons[i] = Icon_Last_Themeable + number; } } } @@ -363,7 +368,7 @@ static void read_config(const char* config_file) break; } rm_whitespaces(line); - /* get the extention */ + /* get the extension */ s = line; e = strchr(s, ','); if (!e) @@ -406,12 +411,10 @@ int filetype_get_attr(const char* file) if (!extension) return 0; extension++; - for (i=0; i= 0) + return (filetypes[i].attr<<8)&FILE_ATTR_MASK; return 0; } @@ -440,13 +443,10 @@ int filetype_get_color(const char * name, int attr) if (!extension) return custom_colors[MAX_FILETYPES]; extension++; - - for (i=1; i= 0) + return custom_colors[i]; return custom_colors[MAX_FILETYPES]; } #endif