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 */
int filetype_get_attr(char* name)
int filetype_get_attr(const char* name)
{
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++)
{
if (exttypes[i].extension)
{
cp=strrchr(name,'.');
if (cp) cp++;
if ((!strcasecmp(cp,exttypes[i].extension)) && (cp))
if (!strcasecmp(cp,exttypes[i].extension))
{
return ((((unsigned long)exttypes[i].type -
(unsigned long)&filetypes[0]) /

View file

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

View file

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