X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=menu.c;h=04c0410c80a27fcd8f683d145cfe97afd6cf112a;hb=c54d04fd84f59c60c6ecdbd2502fbda5de735b4b;hp=3796f45bcee7563295c3de2b6e8c296ea9708b3e;hpb=8a0998fb31e440f7f7566510128049142bc3ad74;p=libpicofe.git diff --git a/menu.c b/menu.c index 3796f45..04c0410 100644 --- a/menu.c +++ b/menu.c @@ -31,10 +31,8 @@ void *g_menuscreen_ptr; void *g_menubg_src_ptr; void *g_menubg_ptr; -#if !MSCREEN_SIZE_FIXED int g_menuscreen_w; int g_menuscreen_h; -#endif static unsigned char *menu_font_data = NULL; static int menu_text_color = 0xfffe; // default to white @@ -922,8 +920,11 @@ static int scandir_cmp(const void *p1, const void *p2) return alphasort(d1, d2); } +static const char **filter_exts_internal; + static int scandir_filter(const struct dirent *ent) { + const char **filter = filter_exts_internal; const char *ext; int i; @@ -938,8 +939,8 @@ static int scandir_filter(const struct dirent *ent) return 0; ext++; - for (i = 0; i < array_size(filter_exts); i++) - if (strcasecmp(ext, filter_exts[i]) == 0) + for (i = 0; filter[i] != NULL; i++) + if (strcasecmp(ext, filter[i]) == 0) return 1; return 0; @@ -961,7 +962,8 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c) return i - 1; } -static char *menu_loop_romsel(char *curr_path, int len, +static const char *menu_loop_romsel(char *curr_path, int len, + const char **filter_exts, int (*extra_filter)(struct dirent **namelist, int count, const char *basedir)) { @@ -971,21 +973,23 @@ static char *menu_loop_romsel(char *curr_path, int len, struct dirent **namelist = NULL; int n = 0, inp = 0, sel = 0, show_help = 0; char *curr_path_restore = NULL; - char *ret = NULL; + const char *ret = NULL; char cinp; + filter_exts_internal = filter_exts; sel_fname[0] = 0; // is this a dir or a full path? if (!plat_is_dir(curr_path)) { - char *p = curr_path + strlen(curr_path) - 1; - for (; p > curr_path && *p != '/'; p--) - ; - *p = 0; - curr_path_restore = p; - snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1); + char *p = strrchr(curr_path, '/'); + if (p != NULL) { + *p = 0; + curr_path_restore = p; + snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1); + } - show_help = 2; + if (rom_fname_reload[0] == 0) + show_help = 2; } rescan: @@ -1096,7 +1100,7 @@ rescan: strcat(newdir, "/"); strcat(newdir, namelist[sel+1]->d_name); } - ret = menu_loop_romsel(newdir, newlen, extra_filter); + ret = menu_loop_romsel(newdir, newlen, filter_exts, extra_filter); free(newdir); break; }