Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Plug-in program run time error, for jpg viewer scrolling.

Plug-in program run time error, for jpg viewer scrolling.

From: XavierGr <xaviergr_at_gmail.com>
Date: 2005-08-09

Hello all.

These days I am trying to make some change in jpg viewer in order to scroll
to other files instead of quiting first.

So, to test this I changed hellowrold plugin to use it as a canvas for my
work.
I have succeed in loading other jpgs by explicitly telling the name of the
file to the viewer. But in order to make the jpg viewer to find the previous
(or next) file I need a small tree context. For this I used part of the
ft_load function of apps/filetree.c.

The problem is that both the simulator and my unit hangs with a runtime
error whenever I try to change a value in the pointer structure (renamed
my_context) tree_context (defined in apps/tree.h)

Do you think that i must avoid the use of the structure tree_context? Also
do I need the Boot information in the code?
I hope that this isn't much of a hassle.

Thanks in advance.

Here is my code:

#include "plugin.h"
#include "dir.h"
#include "file.h"
#include "settings.h"
#include "filetypes.h"
#include "tree.h"

static struct plugin_api* rb;

struct my_context {
int dirlevel;
int dircursor;
int dirstart;
int firstpos; /* which dir entry is on first
position in dir buffer */
int pos_history[MAX_DIR_LEVELS];
int dirpos[MAX_DIR_LEVELS];
int cursorpos[MAX_DIR_LEVELS];
char currdir[MAX_PATH]; /* file use */
int *dirfilter; /* file use */
int filesindir;
int dirsindir; /* file use */
int dirlength; /* total number of entries in dir, incl. those not loaded */
int table_history[MAX_DIR_LEVELS]; /* db use */
int extra_history[MAX_DIR_LEVELS]; /* db use */
int currtable; /* db use */
int currextra; /* db use */

void* dircache;
int dircache_size;
char* name_buffer;
int name_buffer_size;
int dentry_size;
bool dirfull;
}*dir_stat;

int load_dir(struct my_context* c,char* tempdir)
{
int i;
int name_buffer_used = 0;
DIR *dir;

dir = rb->opendir(tempdir);
if(!dir)
return -1; /* not a directory */

c->dirsindir = 0; ------------------------------------------At this point
the error occurs and I can't do anything to prevent this.
c->dirfull = false;

rb->splash(HZ,true,tempdir);

for ( i=0; i < 400; i++ ) {
int len;
struct dirent *entry = rb->readdir(dir);
struct entry* dptr =
(struct entry*)(c->dircache + i * sizeof(struct entry));
if (!entry)
break;

len = rb->strlen(entry->d_name);

/* skip directories . and .. */
if ((entry->attribute & ATTR_DIRECTORY) &&
(((len == 1) &&
(!rb->strncmp(entry->d_name, ".", 1))) ||
((len == 2) &&
(!rb->strncmp(entry->d_name, "..", 2))))) {
i--;
continue;
}

/* Skip FAT volume ID */
if (entry->attribute & ATTR_VOLUME_ID) {
i--;
continue;
}

/* filter out dotfiles and hidden files */
if (*c->dirfilter != SHOW_ALL &&
((entry->d_name[0]=='.') ||
(entry->attribute & ATTR_HIDDEN))) {
i--;
continue;
}

dptr->attr = entry->attribute;

/* Check if file is a jpeg. */
char *dotpos;
dotpos = rb->strrchr(entry->d_name, '.');
*dotpos = 0;

if((len > 4) && (dotpos != ".jpg")){
i--;
continue;
}

dptr->name = &c->name_buffer[name_buffer_used];
dptr->time_write =
(long)entry->wrtdate<<16 |
(long)entry->wrttime; /* in one # */
rb->strcpy(dptr->name,entry->d_name);
name_buffer_used += len + 1;

if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */
c->dirsindir++;
}

c->filesindir = i;
c->dirlength = i;
rb->closedir(dir);

return 0;
}

/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
/* this macro should be called as the first thing you do in the plugin.
it test that the api version and model the plugin was compiled for
matches the machine it is running on */
TEST_PLUGIN_API(api);

rb = api; /* copy to global api pointer */

(void)parameter;

char *path,*file;
int files, count;
path = "/.rockbox";

int check = load_dir(dir_stat,path);

if(!check)
rb->splash(HZ, true,path);

file = dir_stat->dircache;
files = dir_stat->filesindir;

for (count=0;count<=files;count++)
rb->splash(HZ*count,true,path);

return PLUGIN_OK;
}
_______________________________________________
http://cool.haxx.se/mailman/listinfo/rockbox
Received on Tue Aug 9 16:26:19 2005


Page was last modified "Jan 10 2012" The Rockbox Crew
aaa