menu: pass extension lists as argument
authornotaz <notasas@gmail.com>
Sun, 6 Jan 2013 19:09:51 +0000 (21:09 +0200)
committernotaz <notasas@gmail.com>
Sun, 6 Jan 2013 19:09:51 +0000 (21:09 +0200)
menu.c

diff --git a/menu.c b/menu.c
index 3796f45..eb27ce6 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -922,8 +922,11 @@ static int scandir_cmp(const void *p1, const void *p2)
        return alphasort(d1, d2);\r
 }\r
 \r
+static const char **filter_exts_internal;\r
+\r
 static int scandir_filter(const struct dirent *ent)\r
 {\r
+       const char **filter = filter_exts_internal;\r
        const char *ext;\r
        int i;\r
 \r
@@ -938,8 +941,8 @@ static int scandir_filter(const struct dirent *ent)
                return 0;\r
 \r
        ext++;\r
-       for (i = 0; i < array_size(filter_exts); i++)\r
-               if (strcasecmp(ext, filter_exts[i]) == 0)\r
+       for (i = 0; filter[i] != NULL; i++)\r
+               if (strcasecmp(ext, filter[i]) == 0)\r
                        return 1;\r
 \r
        return 0;\r
@@ -961,7 +964,8 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)
        return i - 1;\r
 }\r
 \r
-static char *menu_loop_romsel(char *curr_path, int len,\r
+static const char *menu_loop_romsel(char *curr_path, int len,\r
+       const char **filter_exts,\r
        int (*extra_filter)(struct dirent **namelist, int count,\r
                            const char *basedir))\r
 {\r
@@ -971,9 +975,10 @@ static char *menu_loop_romsel(char *curr_path, int len,
        struct dirent **namelist = NULL;\r
        int n = 0, inp = 0, sel = 0, show_help = 0;\r
        char *curr_path_restore = NULL;\r
-       char *ret = NULL;\r
+       const char *ret = NULL;\r
        char cinp;\r
 \r
+       filter_exts_internal = filter_exts;\r
        sel_fname[0] = 0;\r
 \r
        // is this a dir or a full path?\r
@@ -985,7 +990,8 @@ static char *menu_loop_romsel(char *curr_path, int len,
                curr_path_restore = p;\r
                snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1);\r
 \r
-               show_help = 2;\r
+               if (rom_fname_reload[0] == 0)\r
+                       show_help = 2;\r
        }\r
 \r
 rescan:\r
@@ -1096,7 +1102,7 @@ rescan:
                                        strcat(newdir, "/");\r
                                        strcat(newdir, namelist[sel+1]->d_name);\r
                                }\r
-                               ret = menu_loop_romsel(newdir, newlen, extra_filter);\r
+                               ret = menu_loop_romsel(newdir, newlen, filter_exts, extra_filter);\r
                                free(newdir);\r
                                break;\r
                        }\r