From 011a325e32c05f6e4817dcdc555615e6b7b6c102 Mon Sep 17 00:00:00 2001 From: Kevin Ferrare Date: Fri, 20 Jul 2007 17:06:55 +0000 Subject: Makes apps and plugins interract with directories using a posix-like api instead of calling dircache / simulator functions (no additionnal layer added, only a cosmetic change) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13943 a1c6a512-1295-4272-9138-f99709370657 --- apps/filetree.c | 21 ++++++++-------- apps/playlist.c | 1 - apps/plugin.c | 17 ++++--------- apps/plugin.h | 23 ++++++----------- apps/plugins/doom/rockdoom.c | 8 +++--- apps/plugins/doom/rockmacros.h | 11 +------- apps/plugins/properties.c | 53 +-------------------------------------- apps/plugins/rockboy/rockboy.c | 6 ++--- apps/plugins/rockboy/rockmacros.h | 13 ++-------- apps/plugins/rockpaint.c | 22 ++++++++-------- apps/tagcache.c | 24 +++++++++--------- apps/tree.c | 10 ++++---- 12 files changed, 61 insertions(+), 148 deletions(-) (limited to 'apps') diff --git a/apps/filetree.c b/apps/filetree.c index 90b234a605..bc4709baab 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -38,7 +38,6 @@ #include "plugin.h" #include "rolo.h" #include "sprintf.h" -#include "dircache.h" #include "splash.h" #include "yesno.h" #include "cuesheet.h" @@ -84,11 +83,11 @@ int ft_build_playlist(struct tree_context* c, int start_index) static void check_file_thumbnails(struct tree_context* c) { int i; - struct dircache_entry *entry; + struct dirent *entry; struct entry* dircache = c->dircache; - DIRCACHED *dir; + DIR *dir; - dir = opendir_cached(c->currdir); + dir = opendir(c->currdir); if(!dir) return; /* mark all files as non talking, except the .talk ones */ @@ -109,7 +108,7 @@ static void check_file_thumbnails(struct tree_context* c) } } - while((entry = readdir_cached(dir)) != 0) /* walk directory */ + while((entry = readdir(dir)) != 0) /* walk directory */ { int ext_pos; @@ -135,7 +134,7 @@ static void check_file_thumbnails(struct tree_context* c) } } } - closedir_cached(dir); + closedir(dir); } /* support function for qsort() */ @@ -209,12 +208,12 @@ int ft_load(struct tree_context* c, const char* tempdir) { int i; int name_buffer_used = 0; - DIRCACHED *dir; + DIR *dir; if (tempdir) - dir = opendir_cached(tempdir); + dir = opendir(tempdir); else - dir = opendir_cached(c->currdir); + dir = opendir(c->currdir); if(!dir) return -1; /* not a directory */ @@ -223,7 +222,7 @@ int ft_load(struct tree_context* c, const char* tempdir) for ( i=0; i < global_settings.max_files_in_dir; i++ ) { int len; - struct dircache_entry *entry = readdir_cached(dir); + struct dirent *entry = readdir(dir); struct entry* dptr = (struct entry*)(c->dircache + i * sizeof(struct entry)); if (!entry) @@ -301,7 +300,7 @@ int ft_load(struct tree_context* c, const char* tempdir) } c->filesindir = i; c->dirlength = i; - closedir_cached(dir); + closedir(dir); qsort(c->dircache,i,sizeof(struct entry),compare); diff --git a/apps/playlist.c b/apps/playlist.c index 7b1b91e123..f0ac29d1ef 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -88,7 +88,6 @@ #include "button.h" #include "filetree.h" #include "abrepeat.h" -#include "dircache.h" #include "thread.h" #include "usb.h" #include "filetypes.h" diff --git a/apps/plugin.c b/apps/plugin.c index aff24e0059..68b430d2f3 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -222,18 +222,11 @@ static const struct plugin_api rockbox_api = { create_numbered_filename, /* dir */ - PREFIX(opendir), - PREFIX(closedir), - PREFIX(readdir), - PREFIX(mkdir), - PREFIX(rmdir), - - /* dir, cached */ -#ifdef HAVE_DIRCACHE - opendir_cached, - readdir_cached, - closedir_cached, -#endif + opendir, + closedir, + readdir, + mkdir, + rmdir, /* kernel/ system */ PREFIX(sleep), diff --git a/apps/plugin.h b/apps/plugin.h index 920d804ab5..ac6988152a 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -37,9 +37,6 @@ #include "config.h" #include "system.h" #include "dir.h" -#ifndef SIMULATOR -#include "dircache.h" -#endif #include "kernel.h" #include "thread.h" #include "button.h" @@ -115,12 +112,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 62 +#define PLUGIN_API_VERSION 63 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 62 +#define PLUGIN_MIN_API_VERSION 63 /* plugin return codes */ enum plugin_status { @@ -316,17 +313,11 @@ struct plugin_api { int numberlen IF_CNFN_NUM_(, int *num)); /* dir */ - DIR* (*PREFIX(opendir))(const char* name); - int (*PREFIX(closedir))(DIR* dir); - struct dirent* (*PREFIX(readdir))(DIR* dir); - int (*PREFIX(mkdir))(const char *name); - int (*PREFIX(rmdir))(const char *name); - /* dir, cached */ -#ifdef HAVE_DIRCACHE - DIRCACHED* (*opendir_cached)(const char* name); - struct dircache_entry* (*readdir_cached)(DIRCACHED* dir); - int (*closedir_cached)(DIRCACHED* dir); -#endif + DIR* (*opendir)(const char* name); + int (*closedir)(DIR* dir); + struct dirent* (*readdir)(DIR* dir); + int (*mkdir)(const char *name); + int (*rmdir)(const char *name); /* kernel/ system */ void (*PREFIX(sleep))(int ticks); diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index 90c446b9eb..a9e348160f 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c @@ -329,7 +329,7 @@ int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory char *startpt; struct menu_item *temp; - filedir=opendir(directory); + filedir=rb->opendir(directory); if(filedir==NULL) { @@ -345,8 +345,8 @@ int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory i++; // Reset the directory - closedir(filedir); - filedir=opendir(directory); + rb->closedir(filedir); + filedir=rb->opendir(directory); i++; temp=malloc(i*sizeof(struct opt_items)); @@ -365,7 +365,7 @@ int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory i++; } } - closedir(filedir); + rb->closedir(filedir); *names=temp; return i; } diff --git a/apps/plugins/doom/rockmacros.h b/apps/plugins/doom/rockmacros.h index 86de4cbe13..1541ef48fd 100644 --- a/apps/plugins/doom/rockmacros.h +++ b/apps/plugins/doom/rockmacros.h @@ -40,26 +40,17 @@ char *my_strtok( char * s, const char * delim ); #define read_line(a,b,c) rb->read_line((a),(b),(c)) #ifdef SIMULATOR -#undef opendir -#undef closedir -#undef mkdir #undef open #undef lseek #undef filesize -#define opendir(a) rb->sim_opendir((a)) -#define closedir(a) rb->sim_closedir((a)) -#define mkdir(a) rb->sim_mkdir((a)) #define open(a,b) rb->sim_open((a),(b)) #define lseek(a,b,c) rb->sim_lseek((a),(b),(c)) #define filesize(a) rb->sim_filesize((a)) #else /* !SIMULATOR */ -#define opendir(a) rb->opendir((a)) -#define closedir(a) rb->closedir((a)) -#define filesize(a) rb->filesize((a)) -#define mkdir(a) rb->mkdir((a)) #define open(a,b) my_open((a),(b)) #define close(a) my_close((a)) #define lseek(a,b,c) rb->lseek((a),(b),(c)) +#define filesize(a) rb->filesize((a)) #endif /* !SIMULATOR */ #define strtok(a,b) my_strtok((a),(b)) diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c index 3b4f2797af..86817e2cc7 100644 --- a/apps/plugins/properties.c +++ b/apps/plugins/properties.c @@ -59,30 +59,18 @@ static bool file_properties(char* selected_file) { bool found = false; char tstr[MAX_PATH]; -#ifdef HAVE_DIRCACHE - DIRCACHED* dir; - struct dircache_entry* entry; -#else DIR* dir; struct dirent* entry; -#endif + char* ptr = rb->strrchr(selected_file, '/') + 1; int dirlen = (ptr - selected_file); rb->strncpy(tstr, selected_file, dirlen); tstr[dirlen] = 0; -#ifdef HAVE_DIRCACHE - dir = rb->opendir_cached(tstr); -#else dir = rb->opendir(tstr); -#endif if (dir) { -#ifdef HAVE_DIRCACHE - while(0 != (entry = rb->readdir_cached(dir))) -#else while(0 != (entry = rb->readdir(dir))) -#endif { if(!rb->strcmp(entry->d_name, selected_file+dirlen)) { @@ -103,11 +91,7 @@ static bool file_properties(char* selected_file) break; } } -#ifdef HAVE_DIRCACHE - rb->closedir_cached(dir); -#else rb->closedir(dir); -#endif } return found; } @@ -128,30 +112,17 @@ static bool _dir_properties(DPS* dps) and informs the user of the progress */ bool result; int dirlen; -#ifdef HAVE_DIRCACHE - DIRCACHED* dir; - struct dircache_entry* entry; -#else DIR* dir; struct dirent* entry; -#endif result = true; dirlen = rb->strlen(dps->dirname); -#ifdef HAVE_DIRCACHE - dir = rb->opendir_cached(dps->dirname); -#else dir = rb->opendir(dps->dirname); -#endif if (!dir) return false; /* open error */ /* walk through the directory content */ -#ifdef HAVE_DIRCACHE - while(result && (0 != (entry = rb->readdir_cached(dir)))) -#else while(result && (0 != (entry = rb->readdir(dir)))) -#endif { /* append name to current directory */ rb->snprintf(dps->dirname+dirlen, dps->len-dirlen, "/%s", @@ -189,12 +160,7 @@ static bool _dir_properties(DPS* dps) result = false; rb->yield(); } -#ifdef HAVE_DIRCACHE - rb->closedir_cached(dir); -#else rb->closedir(dir); -#endif - return result; } @@ -256,30 +222,17 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file) /* determine if it's a file or a directory */ bool found = false; -#ifdef HAVE_DIRCACHE - DIRCACHED* dir; - struct dircache_entry* entry; -#else DIR* dir; struct dirent* entry; -#endif char* ptr = rb->strrchr((char*)file, '/') + 1; int dirlen = (ptr - (char*)file); rb->strncpy(str_dirname, (char*)file, dirlen); str_dirname[dirlen] = 0; -#ifdef HAVE_DIRCACHE - dir = rb->opendir_cached(str_dirname); -#else dir = rb->opendir(str_dirname); -#endif if (dir) { -#ifdef HAVE_DIRCACHE - while(0 != (entry = rb->readdir_cached(dir))) -#else while(0 != (entry = rb->readdir(dir))) -#endif { if(!rb->strcmp(entry->d_name, file+dirlen)) { @@ -288,11 +241,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file) break; } } -#ifdef HAVE_DIRCACHE - rb->closedir_cached(dir); -#else rb->closedir(dir); -#endif } /* now we know if it's a file or a dir or maybe something failed */ diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index 46a0aa56c3..93bd98ca78 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c @@ -71,11 +71,11 @@ void setoptions (void) DIR* dir; char optionsave[sizeof(savedir)+sizeof(optionname)]; - dir=opendir(savedir); + dir=rb->opendir(savedir); if(!dir) - mkdir(savedir); + rb->mkdir(savedir); else - closedir(dir); + rb->closedir(dir); snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h index ecf8a1ef6a..5d60d3f3e3 100644 --- a/apps/plugins/rockboy/rockmacros.h +++ b/apps/plugins/rockboy/rockmacros.h @@ -71,22 +71,13 @@ void dynamic_recompile (struct dynarec_block *newblock); #define isalnum(c) (isdigit(c) || (isalpha(c))) #ifdef SIMULATOR -#undef opendir -#define opendir(a) rb->sim_opendir((a)) -#undef closedir -#define closedir(a) rb->sim_closedir((a)) -#undef mkdir -#define mkdir(a) rb->sim_mkdir((a)) #undef open #define open(a,b) rb->sim_open((a),(b)) -#undef close -#define close(a) rb->close((a)) #undef lseek #define lseek(a,b,c) rb->sim_lseek((a),(b),(c)) +#undef close +#define close(a) rb->close((a)) #else /* !SIMULATOR */ -#define opendir(a) rb->opendir((a)) -#define closedir(a) rb->closedir((a)) -#define mkdir(a) rb->mkdir((a)) #define open(a,b) rb->open((a),(b)) #define lseek(a,b,c) rb->lseek((a),(b),(c)) #define close(a) rb->close((a)) diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index d478bf9947..a273e4ca37 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c @@ -688,7 +688,7 @@ static bool browse( char *dst, int dst_size, const char *start ) while( 1 ) { - d = rb->PREFIX(opendir)( bbuf ); + d = rb->opendir( bbuf ); if( !d ) { /* @@ -702,7 +702,7 @@ static bool browse( char *dst, int dst_size, const char *start ) else if( errno == EACCES || errno == ENOENT ) { bbuf[0] = '/'; bbuf[1] = '\0'; - d = rb->PREFIX(opendir)( "/" ); + d = rb->opendir( "/" ); } else { @@ -714,12 +714,12 @@ static bool browse( char *dst, int dst_size, const char *start ) li = -1; while( i < fvi ) { - rb->PREFIX(readdir)( d ); + rb->readdir( d ); i++; } while( top_inside+(i-fvi)*(fh+LINE_SPACE) < HEIGHT ) { - de = rb->PREFIX(readdir)( d ); + de = rb->readdir( d ); if( !de ) { li = i-1; @@ -737,12 +737,12 @@ static bool browse( char *dst, int dst_size, const char *start ) lvi = i-1; if( li == -1 ) { - if( !rb->PREFIX(readdir)( d ) ) + if( !rb->readdir( d ) ) { li = lvi; } } - rb->PREFIX(closedir)( d ); + rb->closedir( d ); rb->lcd_update(); @@ -863,7 +863,7 @@ static bool browse_fonts( char *dst, int dst_size ) { b_need_redraw = 0; - d = rb->PREFIX(opendir)( FONT_DIR "/" ); + d = rb->opendir( FONT_DIR "/" ); if( !d ) { return false; @@ -873,7 +873,7 @@ static bool browse_fonts( char *dst, int dst_size ) li = -1; while( i < fvi ) { - rb->PREFIX(readdir)( d ); + rb->readdir( d ); i++; } cp = top_inside+LINE_SPACE; @@ -883,7 +883,7 @@ static bool browse_fonts( char *dst, int dst_size ) while( cp < top+HEIGHT ) { - de = rb->PREFIX(readdir)( d ); + de = rb->readdir( d ); if( !de ) { li = i-1; @@ -920,7 +920,7 @@ static bool browse_fonts( char *dst, int dst_size ) lvi = i-1; if( li == -1 ) { - if( !(de = rb->PREFIX(readdir)( d ) ) ) + if( !(de = rb->readdir( d ) ) ) { li = lvi; } @@ -936,7 +936,7 @@ static bool browse_fonts( char *dst, int dst_size ) } } rb->font_load( old_font ); - rb->PREFIX(closedir)( d ); + rb->closedir( d ); } rb->lcd_set_drawmode(DRMODE_COMPLEMENT); diff --git a/apps/tagcache.c b/apps/tagcache.c index 41138ddf2c..f832f1e543 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -70,7 +70,7 @@ #include "crc32.h" #include "misc.h" #include "settings.h" -#include "dircache.h" +#include "dir.h" #include "structec.h" #ifndef __PCTOOL__ #include "atoi.h" @@ -327,7 +327,7 @@ static bool do_timed_yield(void) #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) static long find_entry_ram(const char *filename, - const struct dircache_entry *dc) + const struct dirent *dc) { static long last_pos = 0; int i; @@ -626,7 +626,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx, # ifdef HAVE_DIRCACHE if (tag == tag_filename && idx->flag & FLAG_DIRCACHE) { - dircache_copy_path((struct dircache_entry *)seek, + dircache_copy_path((struct dirent *)seek, buf, size); return true; } @@ -1329,7 +1329,7 @@ static bool get_next(struct tagcache_search *tcs) # ifdef HAVE_DIRCACHE if (tcs->type == tag_filename) { - dircache_copy_path((struct dircache_entry *)tcs->position, + dircache_copy_path((struct dirent *)tcs->position, buf, sizeof buf); tcs->result = buf; tcs->result_len = strlen(buf) + 1; @@ -1583,7 +1583,7 @@ static int check_if_empty(char **tag) offset += entry.tag_length[tag] #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) -static void add_tagcache(char *path, const struct dircache_entry *dc) +static void add_tagcache(char *path, const struct dirent *dc) #else static void add_tagcache(char *path) #endif @@ -3464,7 +3464,7 @@ static bool load_tagcache(void) if (tag == tag_filename) { # ifdef HAVE_DIRCACHE - const struct dircache_entry *dc; + const struct dirent *dc; # endif // FIXME: This is wrong! @@ -3647,14 +3647,14 @@ static bool check_deleted_files(void) static bool check_dir(const char *dirname) { - DIRCACHED *dir; + DIR *dir; int len; int success = false; - dir = opendir_cached(dirname); + dir = opendir(dirname); if (!dir) { - logf("tagcache: opendir_cached() failed"); + logf("tagcache: opendir() failed"); return false; } @@ -3665,9 +3665,9 @@ static bool check_dir(const char *dirname) while (!check_event_queue()) #endif { - struct dircache_entry *entry; + struct dirent *entry; - entry = readdir_cached(dir); + entry = readdir(dir); if (entry == NULL) { @@ -3698,7 +3698,7 @@ static bool check_dir(const char *dirname) curpath[len] = '\0'; } - closedir_cached(dir); + closedir(dir); return success; } diff --git a/apps/tree.c b/apps/tree.c index b54238b08c..ccdbd69d0a 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -931,20 +931,20 @@ static long pltick; static bool add_dir(char* dirname, int len, int fd) { bool abort = false; - DIRCACHED* dir; + DIR* dir; /* check for user abort */ if (action_userabort(TIMEOUT_NOBLOCK)) return true; - dir = opendir_cached(dirname); + dir = opendir(dirname); if(!dir) return true; while (true) { - struct dircache_entry *entry; + struct dirent *entry; - entry = readdir_cached(dir); + entry = readdir(dir); if (!entry) break; if (entry->attribute & ATTR_DIRECTORY) { @@ -1021,7 +1021,7 @@ static bool add_dir(char* dirname, int len, int fd) } } } - closedir_cached(dir); + closedir(dir); return abort; } -- cgit v1.2.3