Mercurial > mplayer.hg
annotate libmenu/menu_filesel.c @ 36924:5e22164b4b82
configure: add HAVE_INLINE_ASM_NONLOCAL_LABELS / HAVE_INLINE_ASM_DIRECT_SYMBOL_REF
This prevents breaking the build with the next ffmpeg revission
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
author | michael |
---|---|
date | Tue, 18 Mar 2014 23:18:02 +0000 |
parents | b28f3ff37ae7 |
children |
rev | line source |
---|---|
28113 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
8197 | 18 |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
21 #include <dirent.h> | |
22 #include <errno.h> | |
23 #include <string.h> | |
35903 | 24 #include <strings.h> |
8197 | 25 #include <sys/types.h> |
26 #include <sys/stat.h> | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
27 #include <fcntl.h> |
8197 | 28 #include <ctype.h> |
29 #include <unistd.h> | |
8291
abe95dde3223
limits.h required to get a PATH_MAX definition (on solaris)
jkeil
parents:
8226
diff
changeset
|
30 #include <limits.h> |
8197 | 31 |
36582
b28f3ff37ae7
Use av_unused for unused arguments instead of various hacks.
reimar
parents:
36556
diff
changeset
|
32 #include "libavutil/attributes.h" |
8197 | 33 |
16862 | 34 #include "config.h" |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
35 #include "mp_msg.h" |
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
36 #include "help_mp.h" |
8197 | 37 |
16862 | 38 #include "m_struct.h" |
39 #include "m_option.h" | |
32004
c536d4b0ce3d
Add proper #includes instead of filename/file_filter extern declarations.
diego
parents:
30957
diff
changeset
|
40 #include "mp_core.h" |
c536d4b0ce3d
Add proper #includes instead of filename/file_filter extern declarations.
diego
parents:
30957
diff
changeset
|
41 #include "mplayer.h" |
8197 | 42 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
43 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
44 #include "libmpcodecs/mp_image.h" |
8197 | 45 |
46 #include "menu.h" | |
47 #include "menu_list.h" | |
16862 | 48 #include "input/input.h" |
49 #include "osdep/keycodes.h" | |
8197 | 50 |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
51 #define MENU_KEEP_PATH "/tmp/mp_current_path" |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
52 |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
53 int menu_keepdir = 0; |
23391
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
54 char *menu_chroot = NULL; |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
55 |
8197 | 56 struct list_entry_s { |
57 struct list_entry p; | |
58 int d; | |
59 }; | |
60 | |
61 struct menu_priv_s { | |
62 menu_list_priv_t p; | |
63 char* dir; // current dir | |
64 /// Cfg fields | |
65 char* path; | |
66 char* title; | |
67 char* file_action; | |
68 char* dir_action; | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
69 char** actions; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
70 char* filter; |
8197 | 71 }; |
72 | |
73 static struct menu_priv_s cfg_dflt = { | |
74 MENU_LIST_PRIV_DFLT, | |
75 NULL, | |
76 | |
77 NULL, | |
78 "Select a file: %p", | |
8226 | 79 "loadfile '%p'", |
8197 | 80 NULL, |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
81 NULL, |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
82 NULL |
8197 | 83 }; |
84 | |
85 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
86 | |
30957 | 87 static const m_option_t cfg_fields[] = { |
8197 | 88 MENU_LIST_PRIV_FIELDS, |
89 { "path", ST_OFF(path), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
90 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
91 { "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
92 { "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
93 { "actions", ST_OFF(actions), CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
94 { "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL}, |
8197 | 95 { NULL, NULL, NULL, 0,0,0,NULL } |
96 }; | |
97 | |
98 #define mpriv (menu->priv) | |
99 | |
100 static void free_entry(list_entry_t* entry) { | |
101 free(entry->p.txt); | |
102 free(entry); | |
103 } | |
104 | |
27086 | 105 static char* replace_path(char* title , char* dir , int escape) { |
8197 | 106 char *p = strstr(title,"%p"); |
107 if(p) { | |
108 int tl = strlen(title); | |
109 int dl = strlen(dir); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
110 int t1l = p-title; |
8197 | 111 int l = tl - 2 + dl; |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
112 char *r, *n, *d = dir; |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
113 |
27086 | 114 if (escape) { |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
115 do { |
27086 | 116 if (*d == '\\') |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
117 l++; |
27086 | 118 else if (*d == '\'') /* ' -> \'\\\'\' */ |
119 l+=7; | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
120 } while (*d++); |
27086 | 121 } |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
122 r = malloc(l + 1); |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
123 n = r + t1l; |
8197 | 124 memcpy(r,title,t1l); |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
125 do { |
27086 | 126 if (escape) { |
127 if (*dir == '\\') | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
128 *n++ = '\\'; |
27086 | 129 else if (*dir == '\'') { /* ' -> \'\\\'\' */ |
130 *n++ = '\\'; *n++ = '\''; | |
131 *n++ = '\\'; *n++ = '\\'; | |
132 *n++ = '\\'; *n++ = '\''; | |
133 *n++ = '\\'; | |
134 } | |
135 } | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
136 } while ((*n++ = *dir++)); |
8197 | 137 if(tl - t1l - 2 > 0) |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
138 strcpy(n-1,p+2); |
8197 | 139 return r; |
140 } else | |
141 return title; | |
142 } | |
143 | |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
144 static int mylstat(char *dir, char *file,struct stat* st) { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
145 int l = strlen(dir) + strlen(file); |
8613 | 146 char s[l+2]; |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
147 if (!strcmp("..", file)) { |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
148 char *slash; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
149 l -= 3; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
150 strcpy(s, dir); |
30608
c05fbacce55f
Replace platform preprocessor check by HAVE_DOS_PATHS.
komh
parents:
29263
diff
changeset
|
151 #if HAVE_DOS_PATHS |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
152 if (s[l] == '/' || s[l] == '\\') |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
153 #else |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
154 if (s[l] == '/') |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
155 #endif |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
156 s[l] = '\0'; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
157 slash = strrchr(s, '/'); |
30608
c05fbacce55f
Replace platform preprocessor check by HAVE_DOS_PATHS.
komh
parents:
29263
diff
changeset
|
158 #if HAVE_DOS_PATHS |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
159 if (!slash) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
160 slash = strrchr(s,'\\'); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
161 #endif |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
162 if (!slash) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
163 return stat(dir,st); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
164 slash[1] = '\0'; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
165 return stat(s,st); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
166 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
167 sprintf(s,"%s/%s",dir,file); |
9249 | 168 return stat(s,st); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
169 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
170 |
35216
4c2104e9e0d1
Use correct function prototype instead of casting away the warnings.
reimar
parents:
35215
diff
changeset
|
171 static int compare(const void *av, const void *bv){ |
4c2104e9e0d1
Use correct function prototype instead of casting away the warnings.
reimar
parents:
35215
diff
changeset
|
172 const char * const *a = av; |
4c2104e9e0d1
Use correct function prototype instead of casting away the warnings.
reimar
parents:
35215
diff
changeset
|
173 const char * const *b = bv; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
174 if((*a)[strlen(*a) - 1] == '/') { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
175 if((*b)[strlen(*b) - 1] == '/') |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
176 return strcmp(*b, *a) ; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
177 else |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
178 return 1; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
179 } else { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
180 if((*b)[strlen(*b) - 1] == '/') |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
181 return -1; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
182 else |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
183 return strcmp(*b, *a); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
184 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
185 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
186 |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
187 static char **get_extensions(menu_t *menu){ |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
188 char **extensions, ext[32]; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
189 FILE *fp; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
190 int n = 1; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
191 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
192 if (!mpriv->filter) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
193 return NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
194 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
195 fp = fopen(mpriv->filter, "r"); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
196 if(!fp) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
197 return NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
198 |
30702 | 199 extensions = malloc(sizeof(*extensions)); |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
200 *extensions = NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
201 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
202 while(fgets(ext,sizeof(ext),fp)) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
203 char **l, *e; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
204 int s = strlen (ext); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
205 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
206 if(ext[s-1] == '\n') { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
207 ext[s-1] = '\0'; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
208 s--; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
209 } |
30702 | 210 e = malloc(s+1); |
211 extensions = realloc(extensions, ++n * sizeof(*extensions)); | |
212 extensions = realloc(extensions, ++n * sizeof(*extensions)); | |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
213 strcpy (e, ext); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
214 for (l=extensions; *l; l++); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
215 *l++ = e; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
216 *l = NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
217 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
218 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
219 fclose (fp); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
220 return extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
221 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
222 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
223 static void free_extensions(char **extensions){ |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
224 if (extensions) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
225 char **l = extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
226 while (*l) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
227 free (*l++); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
228 free (extensions); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
229 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
230 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
231 |
25354
a4c4b56e933d
reverted r25323: deprecated by ulion's recent patches
ben
parents:
25320
diff
changeset
|
232 static int open_dir(menu_t* menu,char* args) { |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
233 char **namelist, **tp; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
234 struct dirent *dp; |
8197 | 235 struct stat st; |
236 int n; | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
237 int path_fp; |
8197 | 238 list_entry_t* e; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
239 DIR* dirp; |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
240 char **extensions, **elem, *ext; |
8197 | 241 |
242 menu_list_init(menu); | |
243 | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32004
diff
changeset
|
244 free(mpriv->dir); |
8197 | 245 mpriv->dir = strdup(args); |
246 if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title) | |
247 free(mpriv->p.title); | |
248 | |
27086 | 249 mpriv->p.title = replace_path(mpriv->title,mpriv->dir,0); |
8197 | 250 |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
251 if ((dirp = opendir (mpriv->dir)) == NULL){ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
252 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_OpendirError, strerror(errno)); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
253 return 0; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
254 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
255 |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
256 if (menu_keepdir) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
257 path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
258 if (path_fp >= 0) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
259 write (path_fp, mpriv->dir, strlen (mpriv->dir)); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
260 close (path_fp); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
261 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
262 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
263 |
30702 | 264 namelist = malloc(sizeof(char *)); |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
265 extensions = get_extensions(menu); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
266 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
267 n=0; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
268 while ((dp = readdir(dirp)) != NULL) { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
269 if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
270 continue; |
23391
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
271 if (menu_chroot && !strcmp (dp->d_name,"..")) { |
26945
b105b2c1f8ae
Use size_t instead of int for a variable that is compared to the result
diego
parents:
25632
diff
changeset
|
272 size_t len = strlen (menu_chroot); |
23391
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
273 if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1) |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
274 && !strncmp (mpriv->dir, menu_chroot, len)) |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
275 continue; |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
276 } |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
277 if (mylstat(args,dp->d_name,&st)) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
278 continue; |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
279 if (file_filter && extensions && !S_ISDIR(st.st_mode)) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
280 if((ext = strrchr(dp->d_name,'.')) == NULL) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
281 continue; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
282 ext++; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
283 elem = extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
284 do { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
285 if (!strcasecmp(ext, *elem)) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
286 break; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
287 } while (*++elem); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
288 if (*elem == NULL) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
289 continue; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
290 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
291 if(n%20 == 0){ // Get some more mem |
30702 | 292 if((tp = realloc(namelist, (n+20) * sizeof (char *))) |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
293 == NULL) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
294 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReallocError, strerror(errno)); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
295 n--; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
296 goto bailout; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
297 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
298 namelist=tp; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
299 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
300 |
30702 | 301 namelist[n] = malloc(strlen(dp->d_name) + 2); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
302 if(namelist[n] == NULL){ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
303 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno)); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
304 n--; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
305 goto bailout; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
306 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
307 |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
308 strcpy(namelist[n], dp->d_name); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
309 if(S_ISDIR(st.st_mode)) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
310 strcat(namelist[n], "/"); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
311 n++; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
312 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
313 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
314 bailout: |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
315 free_extensions (extensions); |
16061 | 316 closedir(dirp); |
317 | |
8197 | 318 if (n < 0) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
319 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReaddirError,strerror(errno)); |
36556
0803f123d737
menu_filesel: Fix memory leak in case of readdir error.
reimar
parents:
35903
diff
changeset
|
320 free(namelist); |
8197 | 321 return 0; |
322 } | |
35216
4c2104e9e0d1
Use correct function prototype instead of casting away the warnings.
reimar
parents:
35215
diff
changeset
|
323 qsort(namelist, n, sizeof(char *), compare); |
8197 | 324 while(n--) { |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
325 if((e = calloc(1,sizeof(list_entry_t))) != NULL){ |
8613 | 326 e->p.next = NULL; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
327 e->p.txt = strdup(namelist[n]); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
328 if(strchr(namelist[n], '/') != NULL) |
8197 | 329 e->d = 1; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
330 menu_list_add_entry(menu,e); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
331 }else{ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
332 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno)); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
333 } |
8197 | 334 free(namelist[n]); |
335 } | |
336 free(namelist); | |
337 | |
338 return 1; | |
339 } | |
340 | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
341 static char *action; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
342 |
8197 | 343 static void read_cmd(menu_t* menu,int cmd) { |
344 switch(cmd) { | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
345 case MENU_CMD_LEFT: |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
346 mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../ |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
347 case MENU_CMD_RIGHT: |
8197 | 348 case MENU_CMD_OK: { |
349 // Directory | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
350 if(mpriv->p.current->d && !mpriv->dir_action) { |
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
351 // Default action : open this dirctory ourself |
8197 | 352 int l = strlen(mpriv->dir); |
353 char *slash = NULL, *p = NULL; | |
354 if(strcmp(mpriv->p.current->p.txt,"../") == 0) { | |
355 if(l <= 1) break; | |
356 mpriv->dir[l-1] = '\0'; | |
357 slash = strrchr(mpriv->dir,'/'); | |
30608
c05fbacce55f
Replace platform preprocessor check by HAVE_DOS_PATHS.
komh
parents:
29263
diff
changeset
|
358 #if HAVE_DOS_PATHS |
20505 | 359 if (!slash) |
360 slash = strrchr(mpriv->dir,'\\'); | |
361 #endif | |
8197 | 362 if(!slash) break; |
363 slash[1] = '\0'; | |
364 p = strdup(mpriv->dir); | |
365 } else { | |
366 p = malloc(l + strlen(mpriv->p.current->p.txt) + 1); | |
367 sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt); | |
368 } | |
369 menu_list_uninit(menu,free_entry); | |
370 if(!open_dir(menu,p)) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
371 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_CantOpenDirectory,p); |
8197 | 372 menu->cl = 1; |
373 } | |
374 free(p); | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
375 } else { // File and directory dealt with action string. |
8197 | 376 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; |
377 char filename[fname_len]; | |
378 char *str; | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
379 char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action; |
8197 | 380 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); |
27086 | 381 str = replace_path(action, filename,1); |
25505
8d329f7bbc3c
Remove redundant option 'auto-close' from cmdlist and filesel.
ulion
parents:
25502
diff
changeset
|
382 mp_input_parse_and_queue_cmds(str); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
383 if (str != action) |
8197 | 384 free(str); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
385 } |
8197 | 386 } break; |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
387 case MENU_CMD_ACTION: { |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
388 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
389 char filename[fname_len]; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
390 char *str; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
391 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); |
27086 | 392 str = replace_path(action, filename,1); |
25320
4fbf536cc033
Support to run multiple mplayer commands set in menu.conf
ulion
parents:
25311
diff
changeset
|
393 mp_input_parse_and_queue_cmds(str); |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
394 if(str != action) |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
395 free(str); |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
396 } break; |
8197 | 397 default: |
398 menu_list_read_cmd(menu,cmd); | |
399 } | |
400 } | |
401 | |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
402 static int read_key(menu_t* menu,int c){ |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
403 char **str; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
404 for (str=mpriv->actions; str && *str; str++) |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
405 if (c == (*str)[0]) { |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
406 action = &(*str)[2]; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
407 read_cmd(menu,MENU_CMD_ACTION); |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
408 return 1; |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
409 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25134
diff
changeset
|
410 if (menu_dflt_read_key(menu, c)) |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
411 return 1; |
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
412 return menu_list_jump_to_key(menu, c); |
8197 | 413 } |
414 | |
415 static void clos(menu_t* menu) { | |
416 menu_list_uninit(menu,free_entry); | |
417 free(mpriv->dir); | |
418 } | |
419 | |
36582
b28f3ff37ae7
Use av_unused for unused arguments instead of various hacks.
reimar
parents:
36556
diff
changeset
|
420 static int open_fs(menu_t* menu, char* av_unused args) { |
26970 | 421 char *path = mpriv->path; |
8197 | 422 int r = 0; |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
423 char wd[PATH_MAX+1], b[PATH_MAX+1]; |
8197 | 424 |
425 menu->draw = menu_list_draw; | |
426 menu->read_cmd = read_cmd; | |
427 menu->read_key = read_key; | |
428 menu->close = clos; | |
429 | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
430 if (menu_keepdir) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
431 if (!path || path[0] == '\0') { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
432 struct stat st; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
433 int path_fp; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
434 |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
435 path_fp = open (MENU_KEEP_PATH, O_RDONLY); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
436 if (path_fp >= 0) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
437 if (!fstat (path_fp, &st) && (st.st_size > 0)) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
438 path = malloc(st.st_size+1); |
26960 | 439 path[st.st_size] = '\0'; |
26970 | 440 if (!((read(path_fp, path, st.st_size) == st.st_size) && path[0] == '/' |
441 && !stat(path, &st) && S_ISDIR(st.st_mode))) { | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
442 free(path); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
443 path = NULL; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
444 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
445 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
446 close (path_fp); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
447 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
448 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
449 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
450 |
8197 | 451 getcwd(wd,PATH_MAX); |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
452 if (!path || path[0] == '\0') { |
25632 | 453 #if 0 |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
454 char *slash = NULL; |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
455 if (filename && !strstr(filename, "://") && (path=realpath(filename, b))) { |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
456 slash = strrchr(path, '/'); |
30608
c05fbacce55f
Replace platform preprocessor check by HAVE_DOS_PATHS.
komh
parents:
29263
diff
changeset
|
457 #if HAVE_DOS_PATHS |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
458 // FIXME: Do we need and can convert all '\\' in path to '/' on win32? |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
459 if (!slash) |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
460 slash = strrchr(path, '\\'); |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
461 #endif |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
462 } |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
463 if (slash) |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
464 slash[1] = '\0'; |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
465 else |
25632 | 466 #endif |
25528
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
467 path = wd; |
e3f6092fb640
Default use the dir where the current playing file located if path not set.
ulion
parents:
25505
diff
changeset
|
468 } |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
469 if (path[0] != '/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
470 if(path[strlen(path)-1] != '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
471 snprintf(b,sizeof(b),"%s/%s/",wd,path); |
8197 | 472 else |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
473 snprintf(b,sizeof(b),"%s/%s",wd,path); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
474 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
475 } else if (path[strlen(path)-1]!='/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
476 sprintf(b,"%s/",path); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
477 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
478 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
479 if (menu_chroot && menu_chroot[0] == '/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
480 int l = strlen(menu_chroot); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
481 if (l > 0 && menu_chroot[l-1] == '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
482 --l; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
483 if (strncmp(menu_chroot, path, l) || (path[l] != '\0' && path[l] != '/')) { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
484 if (menu_chroot[l] == '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
485 path = menu_chroot; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
486 else { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
487 sprintf(b,"%s/",menu_chroot); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
488 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
489 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
490 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
491 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
492 r = open_dir(menu,path); |
8197 | 493 |
494 return r; | |
495 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
496 |
8197 | 497 const menu_info_t menu_info_filesel = { |
498 "File seletor menu", | |
499 "filesel", | |
500 "Albeu", | |
501 "", | |
502 { | |
503 "fs_cfg", | |
504 sizeof(struct menu_priv_s), | |
505 &cfg_dflt, | |
506 cfg_fields | |
507 }, | |
508 open_fs | |
509 }; |