2
* This file is part of MPlayer.
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.
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.
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.
71
87
{ "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
72
88
{ "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
73
89
{ "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
74
{ "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
75
90
{ "actions", ST_OFF(actions), CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
76
91
{ "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL},
77
92
{ NULL, NULL, NULL, 0,0,0,NULL }
87
static char* replace_path(char* title , char* dir) {
102
static char* replace_path(char* title , char* dir , int escape) {
88
103
char *p = strstr(title,"%p");
90
105
int tl = strlen(title);
92
107
int t1l = p-title;
93
108
int l = tl - 2 + dl;
94
109
char *r, *n, *d = dir;
98
if (*d == '\\' || *d == term)
115
else if (*d == '\'') /* ' -> \'\\\'\' */
101
119
r = malloc(l + 1);
103
121
memcpy(r,title,t1l);
105
if (*dir == '\\' || *dir == term)
126
else if (*dir == '\'') { /* ' -> \'\\\'\' */
127
*n++ = '\\'; *n++ = '\'';
128
*n++ = '\\'; *n++ = '\\';
129
*n++ = '\\'; *n++ = '\'';
107
133
} while ((*n++ = *dir++));
108
134
if(tl - t1l - 2 > 0)
117
143
static int mylstat(char *dir, char *file,struct stat* st) {
118
144
int l = strlen(dir) + strlen(file);
146
if (!strcmp("..", file)) {
150
#if defined(__MINGW32__) || defined(__CYGWIN__)
151
if (s[l] == '/' || s[l] == '\\')
156
slash = strrchr(s, '/');
157
#if defined(__MINGW32__) || defined(__CYGWIN__)
159
slash = strrchr(s,'\\');
120
166
sprintf(s,"%s/%s",dir,file);
121
167
return stat(s,st);
201
247
free(mpriv->p.title);
202
248
p = strstr(mpriv->title,"%p");
204
mpriv->p.title = replace_path(mpriv->title,mpriv->dir);
250
mpriv->p.title = replace_path(mpriv->title,mpriv->dir,0);
206
252
if ((dirp = opendir (mpriv->dir)) == NULL){
207
253
mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_OpendirError, strerror(errno));
224
270
if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0)
226
272
if (menu_chroot && !strcmp (dp->d_name,"..")) {
227
int len = strlen (menu_chroot);
273
size_t len = strlen (menu_chroot);
228
274
if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1)
229
275
&& !strncmp (mpriv->dir, menu_chroot, len))
232
mylstat(args,dp->d_name,&st);
278
if (mylstat(args,dp->d_name,&st))
233
280
if (file_filter && extensions && !S_ISDIR(st.st_mode)) {
234
281
if((ext = strrchr(dp->d_name,'.')) == NULL)
296
342
static char *action;
298
344
static void read_cmd(menu_t* menu,int cmd) {
301
346
case MENU_CMD_LEFT:
302
347
mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../
303
348
case MENU_CMD_RIGHT:
304
349
case MENU_CMD_OK: {
306
if(mpriv->p.current->d) {
307
if(mpriv->dir_action) {
308
int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
309
char filename[fname_len];
311
sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
312
str = replace_path(mpriv->dir_action,filename);
313
c = mp_input_parse_cmd(str);
314
if(str != mpriv->dir_action)
316
} else { // Default action : open this dirctory ourself
351
if(mpriv->p.current->d && !mpriv->dir_action) {
352
// Default action : open this dirctory ourself
317
353
int l = strlen(mpriv->dir);
318
354
char *slash = NULL, *p = NULL;
319
355
if(strcmp(mpriv->p.current->p.txt,"../") == 0) {
376
} else { // File and directory dealt with action string.
342
377
int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
343
378
char filename[fname_len];
380
char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action;
345
381
sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
346
str = replace_path(mpriv->file_action,filename);
347
c = mp_input_parse_cmd(str);
348
if(str != mpriv->file_action)
382
str = replace_path(action, filename,1);
383
mp_input_parse_and_queue_cmds(str);
352
mp_input_queue_cmd(c);
353
if(mpriv->auto_close)
357
388
case MENU_CMD_ACTION: {
359
390
char filename[fname_len];
361
392
sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
362
str = replace_path(action, filename);
363
mp_input_queue_cmd(mp_input_parse_cmd(str));
393
str = replace_path(action, filename,1);
394
mp_input_parse_and_queue_cmds(str);
364
395
if(str != action)
372
static void read_key(menu_t* menu,int c){
374
read_cmd(menu,MENU_CMD_LEFT);
403
static int read_key(menu_t* menu,int c){
377
405
for (str=mpriv->actions; str && *str; str++)
378
406
if (c == (*str)[0]) {
379
407
action = &(*str)[2];
380
408
read_cmd(menu,MENU_CMD_ACTION);
384
menu_list_read_key(menu,c,1);
411
if (menu_dflt_read_key(menu, c))
413
return menu_list_jump_to_key(menu, c);
388
416
static void clos(menu_t* menu) {
393
421
static int open_fs(menu_t* menu, char* args) {
394
char *path = mpriv->path, *freepath = NULL;
422
char *path = mpriv->path;
424
char wd[PATH_MAX+1], b[PATH_MAX+1];
397
425
args = NULL; // Warning kill
399
427
menu->draw = menu_list_draw;
410
438
if (path_fp >= 0) {
411
439
if (!fstat (path_fp, &st) && (st.st_size > 0)) {
412
440
path = malloc(st.st_size+1);
413
if ((read(path_fp, path, st.st_size) == st.st_size) && path[0] != '\0'){
415
path[st.st_size] = '\0';
441
path[st.st_size] = '\0';
442
if (!((read(path_fp, path, st.st_size) == st.st_size) && path[0] == '/'
443
&& !stat(path, &st) && S_ISDIR(st.st_mode))) {
427
453
getcwd(wd,PATH_MAX);
428
if(!path || path[0] == '\0') {
429
int l = strlen(wd) + 2;
432
r = open_dir(menu,b);
433
} else if(path[0] != '/') {
434
int al = strlen(path);
435
int l = strlen(wd) + al + 3;
438
sprintf(b,"%s/%s/",wd,path);
440
sprintf(b,"%s/%s",wd,path);
441
r = open_dir(menu,b);
443
r = open_dir(menu,path);
454
if (!path || path[0] == '\0') {
457
if (filename && !strstr(filename, "://") && (path=realpath(filename, b))) {
458
slash = strrchr(path, '/');
459
#if defined(__MINGW32__) || defined(__CYGWIN__)
460
// FIXME: Do we need and can convert all '\\' in path to '/' on win32?
462
slash = strrchr(path, '\\');
471
if (path[0] != '/') {
472
if(path[strlen(path)-1] != '/')
473
snprintf(b,sizeof(b),"%s/%s/",wd,path);
475
snprintf(b,sizeof(b),"%s/%s",wd,path);
477
} else if (path[strlen(path)-1]!='/') {
478
sprintf(b,"%s/",path);
481
if (menu_chroot && menu_chroot[0] == '/') {
482
int l = strlen(menu_chroot);
483
if (l > 0 && menu_chroot[l-1] == '/')
485
if (strncmp(menu_chroot, path, l) || (path[l] != '\0' && path[l] != '/')) {
486
if (menu_chroot[l] == '/')
489
sprintf(b,"%s/",menu_chroot);
494
r = open_dir(menu,path);