Optimised new file association handling. Fixed NULL pointer accesses. Const policed.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7459 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2005-09-02 16:50:51 +00:00
parent 70542d7a0c
commit ac50839423
3 changed files with 38 additions and 33 deletions

View file

@ -209,18 +209,20 @@ bool filetype_supported(int attr)
} }
/* get the "dynamic" attribute for an extension */ /* get the "dynamic" attribute for an extension */
int filetype_get_attr(char* name) int filetype_get_attr(const char* name)
{ {
int i; int i;
char *cp; const char *cp = strrchr(name,'.');
if (!cp) /* no extension? -> can't be a supported type */
return 0;
cp++;
for (i=0; i < cnt_exttypes; i++) for (i=0; i < cnt_exttypes; i++)
{ {
if (exttypes[i].extension) if (exttypes[i].extension)
{ {
cp=strrchr(name,'.'); if (!strcasecmp(cp,exttypes[i].extension))
if (cp) cp++;
if ((!strcasecmp(cp,exttypes[i].extension)) && (cp))
{ {
return ((((unsigned long)exttypes[i].type - return ((((unsigned long)exttypes[i].type -
(unsigned long)&filetypes[0]) / (unsigned long)&filetypes[0]) /

View file

@ -23,7 +23,7 @@
#include <tree.h> #include <tree.h>
#include <menu.h> #include <menu.h>
int filetype_get_attr(char*); int filetype_get_attr(const char*);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
const char* filetype_get_icon(int); const char* filetype_get_icon(int);
#else #else

View file

@ -1376,40 +1376,43 @@ static bool add_dir(char* dirname, int len, int fd)
else { else {
int x = strlen(entry->d_name); int x = strlen(entry->d_name);
unsigned int i; unsigned int i;
char *cp; char *cp = strrchr(entry->d_name,'.');
if (cp) {
cp++;
/* add all supported audio files to playlists */ /* add all supported audio files to playlists */
for (i=0; i < sizeof(filetypes); i++) { for (i=0; i < sizeof(filetypes); i++) {
if (filetypes[i].tree_attr == TREE_ATTR_MPA) { if (filetypes[i].tree_attr == TREE_ATTR_MPA) {
cp=strrchr(entry->d_name,'.'); if (!strcasecmp(cp, filetypes[i].extension))
if (cp) cp++; {
if ((!strcasecmp(cp,filetypes[i].extension)) && (cp)) char buf[8];
{ write(fd, dirname, strlen(dirname));
char buf[8]; write(fd, "/", 1);
write(fd, dirname, strlen(dirname)); write(fd, entry->d_name, x);
write(fd, "/", 1); write(fd, "\n", 1);
write(fd, entry->d_name, x);
write(fd, "\n", 1);
plsize++; plsize++;
snprintf(buf, sizeof buf, "%d", plsize); snprintf(buf, sizeof buf, "%d", plsize);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
lcd_puts(0,4,buf); lcd_puts(0,4,buf);
lcd_update(); lcd_update();
#else #else
x = 10; x = 10;
if (plsize > 999) if (plsize > 999)
x=7; x=7;
else {
if (plsize > 99)
x=8;
else { else {
if (plsize > 9) if (plsize > 99)
x=9; x=8;
else {
if (plsize > 9)
x=9;
}
} }
} lcd_puts(x,0,buf);
lcd_puts(x,0,buf);
#endif #endif
break;
}
} }
} }
} }