summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-08-15 12:28:52 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-08-15 12:28:52 +0000
commit5917e8157a40e018e99086cb9328add9249f0264 (patch)
tree277298dca8fa8fc6df2504dccedd3b4bfac8e083
parent62625737a410f66a62f76f2e32fe189a1c30d5b9 (diff)
downloadrockbox-5917e8157a40e018e99086cb9328add9249f0264.zip
rockbox-5917e8157a40e018e99086cb9328add9249f0264.tar.gz
rockbox-5917e8157a40e018e99086cb9328add9249f0264.tar.bz2
rockbox-5917e8157a40e018e99086cb9328add9249f0264.tar.xz
Now we can have up to 400 files in a directory
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1761 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/applimits.h27
-rw-r--r--apps/playlist.c7
-rw-r--r--apps/playlist.h2
-rw-r--r--apps/tree.c92
4 files changed, 82 insertions, 46 deletions
diff --git a/apps/applimits.h b/apps/applimits.h
new file mode 100644
index 0000000..a18544e
--- /dev/null
+++ b/apps/applimits.h
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _APPLIMITS_H_
+#define _APPLIMITS_H_
+
+#define MAX_FILES_IN_DIR 400
+#define AVERAGE_FILENAME_LENGTH 40
+#define MAX_DIR_LEVELS 10
+#define MAX_PLAYLIST_SIZE 10000
+
+#endif
diff --git a/apps/playlist.c b/apps/playlist.c
index 692ec4b..0cb9d09 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -29,6 +29,7 @@
#include "kernel.h"
#include "settings.h"
#include "status.h"
+#include "applimits.h"
#ifdef HAVE_LCD_BITMAP
#define LINE_Y (global_settings.statusbar&&statusbar_enabled?1:0) /* Y position the entry-list starts at */
@@ -38,7 +39,7 @@
playlist_info_t playlist;
-#define PLAYLIST_BUFFER_SIZE (MAX_PATH*200)
+#define PLAYLIST_BUFFER_SIZE (AVERAGE_FILENAME_LENGTH*MAX_FILES_IN_DIR)
unsigned char playlist_buffer[PLAYLIST_BUFFER_SIZE];
static int playlist_end_pos = 0;
@@ -293,8 +294,8 @@ void add_indices_to_playlist(void)
close(fd);
lcd_clear_display();
- lcd_puts(0,0,"10000 file");
- lcd_puts(0,1,"limit reached");
+ lcd_puts(0,0,"Playlist");
+ lcd_puts(0,1,"buffer full");
lcd_update();
sleep(HZ*2);
lcd_clear_display();
diff --git a/apps/playlist.h b/apps/playlist.h
index 2e3d6a3..312964f 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -22,10 +22,10 @@
#include <stdbool.h>
#include "file.h"
+#include "applimits.h"
/* playlist data */
-#define MAX_PLAYLIST_SIZE 10000
typedef struct
{
char filename[MAX_PATH]; /* path name of m3u playlist on disk */
diff --git a/apps/tree.c b/apps/tree.c
index 8b98f2b..2230f17 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdbool.h>
+#include "applimits.h"
#include "dir.h"
#include "file.h"
#include "lcd.h"
@@ -47,17 +48,16 @@
#include "ajf.h"
#endif
-#define MAX_FILES_IN_DIR 200
-#define TREE_MAX_FILENAMELEN MAX_PATH
-#define MAX_DIR_LEVELS 10
+#define NAME_BUFFER_SIZE (AVERAGE_FILENAME_LENGTH * MAX_FILES_IN_DIR)
+char name_buffer[NAME_BUFFER_SIZE];
+int name_buffer_length;
struct entry {
- char attr; /* FAT attributes */
- char name[TREE_MAX_FILENAMELEN];
+ short attr; /* FAT attributes */
+ char *name;
};
static struct entry dircache[MAX_FILES_IN_DIR];
-static struct entry* dircacheptr[MAX_FILES_IN_DIR];
static int filesindir;
static char lastdir[MAX_PATH] = {0};
@@ -122,10 +122,10 @@ static int build_playlist(int start_index)
for(i = 0;i < filesindir;i++)
{
- if(dircacheptr[i]->attr & TREE_ATTR_MP3)
+ if(dircache[i].attr & TREE_ATTR_MP3)
{
- DEBUGF("Adding %s\n", dircacheptr[i]->name);
- playlist_add(dircacheptr[i]->name);
+ DEBUGF("Adding %s\n", dircache[i].name);
+ playlist_add(dircache[i].name);
}
else
{
@@ -140,14 +140,14 @@ static int build_playlist(int start_index)
static int compare(const void* p1, const void* p2)
{
- struct entry* e1 = *(struct entry**)p1;
- struct entry* e2 = *(struct entry**)p2;
+ struct entry* e1 = (struct entry*)p1;
+ struct entry* e2 = (struct entry*)p2;
if (( e1->attr & ATTR_DIRECTORY ) == ( e2->attr & ATTR_DIRECTORY ))
if (global_settings.sort_case)
- return strncmp(e1->name, e2->name, TREE_MAX_FILENAMELEN);
+ return strncmp(e1->name, e2->name, MAX_PATH);
else
- return strncasecmp(e1->name, e2->name, TREE_MAX_FILENAMELEN);
+ return strncasecmp(e1->name, e2->name, MAX_PATH);
else
return ( e2->attr & ATTR_DIRECTORY ) - ( e1->attr & ATTR_DIRECTORY );
}
@@ -160,6 +160,7 @@ static int showdir(char *path, int start)
#endif
int i;
int tree_max_on_screen;
+ bool dir_buffer_full;
#ifdef LOADABLE_FONTS
int fh;
unsigned char *font = lcd_getcurrentldfont();
@@ -177,7 +178,9 @@ static int showdir(char *path, int start)
if(!dir)
return -1; /* not a directory */
- memset(dircacheptr,0,sizeof(dircacheptr));
+ name_buffer_length = 0;
+ dir_buffer_full = false;
+
for ( i=0; i<MAX_FILES_IN_DIR; i++ ) {
int len;
struct dirent *entry = readdir(dir);
@@ -212,23 +215,28 @@ static int showdir(char *path, int start)
continue;
}
- strncpy(dptr->name,entry->d_name,TREE_MAX_FILENAMELEN);
- dptr->name[TREE_MAX_FILENAMELEN-1]=0;
- dircacheptr[i] = dptr;
+ if(len > NAME_BUFFER_SIZE - name_buffer_length - 1) {
+ /* Tell the world that we ran out of buffer space */
+ dir_buffer_full = true;
+ break;
+ }
+ dptr->name = &name_buffer[name_buffer_length];
+ strcpy(dptr->name,entry->d_name);
+ name_buffer_length += len + 1;
}
filesindir = i;
closedir(dir);
strncpy(lastdir,path,sizeof(lastdir));
lastdir[sizeof(lastdir)-1] = 0;
- qsort(dircacheptr,filesindir,sizeof(struct entry*),compare);
+ qsort(dircache,filesindir,sizeof(struct entry),compare);
- if ( filesindir == MAX_FILES_IN_DIR ) {
+ if ( dir_buffer_full || filesindir == MAX_FILES_IN_DIR ) {
#ifdef HAVE_NEW_CHARCELL_LCD
lcd_double_height(false);
#endif
lcd_clear_display();
- lcd_puts(0,0,"200 file");
- lcd_puts(0,1,"limit reached");
+ lcd_puts(0,0,"Dir buffer");
+ lcd_puts(0,1,"is full!");
lcd_update();
sleep(HZ*2);
lcd_clear_display();
@@ -251,13 +259,13 @@ static int showdir(char *path, int start)
if ( i >= filesindir )
break;
- len = strlen(dircacheptr[i]->name);
+ len = strlen(dircache[i].name);
#ifdef HAVE_LCD_BITMAP
- if ( dircacheptr[i]->attr & ATTR_DIRECTORY )
+ if ( dircache[i].attr & ATTR_DIRECTORY )
icon_type = Folder;
else {
- if ( dircacheptr[i]->attr & TREE_ATTR_M3U )
+ if ( dircache[i].attr & TREE_ATTR_M3U )
icon_type = Playlist;
else
icon_type = File;
@@ -269,15 +277,15 @@ static int showdir(char *path, int start)
/* if MP3 filter is on, cut off the extension */
if (global_settings.mp3filter &&
- (dircacheptr[i]->attr & (TREE_ATTR_M3U|TREE_ATTR_MP3)))
+ (dircache[i].attr & (TREE_ATTR_M3U|TREE_ATTR_MP3)))
{
- char temp = dircacheptr[i]->name[len-4];
- dircacheptr[i]->name[len-4] = 0;
- lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name);
- dircacheptr[i]->name[len-4] = temp;
+ char temp = dircache[i].name[len-4];
+ dircache[i].name[len-4] = 0;
+ lcd_puts(LINE_X, LINE_Y+i-start, dircache[i].name);
+ dircache[i].name[len-4] = temp;
}
else
- lcd_puts(LINE_X, LINE_Y+i-start, dircacheptr[i]->name);
+ lcd_puts(LINE_X, LINE_Y+i-start, dircache[i].name);
}
status_draw();
@@ -359,13 +367,13 @@ bool dirbrowse(char *root)
break;
if ((currdir[0]=='/') && (currdir[1]==0)) {
snprintf(buf,sizeof(buf),"%s%s",currdir,
- dircacheptr[dircursor+start]->name);
+ dircache[dircursor+start].name);
} else {
snprintf(buf,sizeof(buf),"%s/%s",currdir,
- dircacheptr[dircursor+start]->name);
+ dircache[dircursor+start].name);
}
- if (dircacheptr[dircursor+start]->attr & ATTR_DIRECTORY) {
+ if (dircache[dircursor+start].attr & ATTR_DIRECTORY) {
memcpy(currdir,buf,sizeof(currdir));
if ( dirlevel < MAX_DIR_LEVELS ) {
dirpos[dirlevel] = start;
@@ -376,10 +384,10 @@ bool dirbrowse(char *root)
start=0;
} else {
lcd_stop_scroll();
- if(dircacheptr[dircursor+start]->attr & TREE_ATTR_M3U )
+ if(dircache[dircursor+start].attr & TREE_ATTR_M3U )
{
play_list(currdir,
- dircacheptr[dircursor+start]->name, 0);
+ dircache[dircursor+start].name, 0);
}
else {
start_index = build_playlist(dircursor+start);
@@ -568,19 +576,19 @@ bool dirbrowse(char *root)
lasti=i;
lcd_stop_scroll();
if (global_settings.mp3filter &&
- (dircacheptr[i]->attr &
+ (dircache[i].attr &
(TREE_ATTR_M3U|TREE_ATTR_MP3)))
{
- int len = strlen(dircacheptr[i]->name);
- char temp = dircacheptr[i]->name[len-4];
- dircacheptr[i]->name[len-4] = 0;
+ int len = strlen(dircache[i].name);
+ char temp = dircache[i].name[len-4];
+ dircache[i].name[len-4] = 0;
lcd_puts_scroll(LINE_X, LINE_Y+dircursor,
- dircacheptr[i]->name);
- dircacheptr[i]->name[len-4] = temp;
+ dircache[i].name);
+ dircache[i].name[len-4] = temp;
}
else
lcd_puts_scroll(LINE_X, LINE_Y+dircursor,
- dircacheptr[i]->name);
+ dircache[i].name);
}
}
status_draw();