2008-12-13 18:40:19 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2007-05-07 16:46:24 +00:00
|
|
|
#include <fcntl.h>
|
2002-11-14 23:47:11 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
2002-11-26 18:54:23 +00:00
|
|
|
#include <limits.h>
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "config.h"
|
2006-03-30 06:40:58 +00:00
|
|
|
#include "mp_msg.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "m_struct.h"
|
|
|
|
#include "m_option.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2006-08-18 13:58:03 +00:00
|
|
|
#include "libmpcodecs/img_format.h"
|
|
|
|
#include "libmpcodecs/mp_image.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_list.h"
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "input/input.h"
|
|
|
|
#include "osdep/keycodes.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2007-05-07 16:46:24 +00:00
|
|
|
#define MENU_KEEP_PATH "/tmp/mp_current_path"
|
|
|
|
|
|
|
|
int menu_keepdir = 0;
|
2007-05-29 18:49:38 +00:00
|
|
|
char *menu_chroot = NULL;
|
2007-05-07 16:46:24 +00:00
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
struct list_entry_s {
|
|
|
|
struct list_entry p;
|
|
|
|
int d;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu_priv_s {
|
|
|
|
menu_list_priv_t p;
|
|
|
|
char* dir; // current dir
|
|
|
|
/// Cfg fields
|
|
|
|
char* path;
|
|
|
|
char* title;
|
|
|
|
char* file_action;
|
|
|
|
char* dir_action;
|
2006-08-22 19:59:53 +00:00
|
|
|
char** actions;
|
2009-07-06 23:26:13 +00:00
|
|
|
char* filter;
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_priv_s cfg_dflt = {
|
|
|
|
MENU_LIST_PRIV_DFLT,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
"Select a file: %p",
|
2002-11-18 00:14:17 +00:00
|
|
|
"loadfile '%p'",
|
2002-11-14 23:47:11 +00:00
|
|
|
NULL,
|
2006-08-22 20:55:49 +00:00
|
|
|
NULL,
|
2006-08-22 19:59:53 +00:00
|
|
|
NULL
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
|
|
|
|
|
2010-04-04 16:11:20 +00:00
|
|
|
static const m_option_t cfg_fields[] = {
|
2002-11-14 23:47:11 +00:00
|
|
|
MENU_LIST_PRIV_FIELDS,
|
|
|
|
{ "path", ST_OFF(path), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
2006-08-22 19:59:53 +00:00
|
|
|
{ "actions", ST_OFF(actions), CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
|
2006-08-22 20:55:49 +00:00
|
|
|
{ "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL},
|
2002-11-14 23:47:11 +00:00
|
|
|
{ NULL, NULL, NULL, 0,0,0,NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define mpriv (menu->priv)
|
|
|
|
|
|
|
|
static void free_entry(list_entry_t* entry) {
|
|
|
|
free(entry->p.txt);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
2008-06-20 20:36:05 +00:00
|
|
|
static char* replace_path(char* title , char* dir , int escape) {
|
2002-11-14 23:47:11 +00:00
|
|
|
char *p = strstr(title,"%p");
|
|
|
|
if(p) {
|
|
|
|
int tl = strlen(title);
|
|
|
|
int dl = strlen(dir);
|
2009-07-06 23:26:13 +00:00
|
|
|
int t1l = p-title;
|
2002-11-14 23:47:11 +00:00
|
|
|
int l = tl - 2 + dl;
|
2003-08-15 18:45:35 +00:00
|
|
|
char *r, *n, *d = dir;
|
|
|
|
|
2008-06-20 20:36:05 +00:00
|
|
|
if (escape) {
|
2003-08-15 18:45:35 +00:00
|
|
|
do {
|
2008-06-20 20:36:05 +00:00
|
|
|
if (*d == '\\')
|
2003-08-15 18:45:35 +00:00
|
|
|
l++;
|
2008-06-20 20:36:05 +00:00
|
|
|
else if (*d == '\'') /* ' -> \'\\\'\' */
|
|
|
|
l+=7;
|
2003-08-15 18:45:35 +00:00
|
|
|
} while (*d++);
|
2008-06-20 20:36:05 +00:00
|
|
|
}
|
2003-08-15 18:45:35 +00:00
|
|
|
r = malloc(l + 1);
|
|
|
|
n = r + t1l;
|
2002-11-14 23:47:11 +00:00
|
|
|
memcpy(r,title,t1l);
|
2003-08-15 18:45:35 +00:00
|
|
|
do {
|
2008-06-20 20:36:05 +00:00
|
|
|
if (escape) {
|
|
|
|
if (*dir == '\\')
|
|
|
|
*n++ = '\\';
|
|
|
|
else if (*dir == '\'') { /* ' -> \'\\\'\' */
|
|
|
|
*n++ = '\\'; *n++ = '\'';
|
|
|
|
*n++ = '\\'; *n++ = '\\';
|
|
|
|
*n++ = '\\'; *n++ = '\'';
|
2003-08-15 18:45:35 +00:00
|
|
|
*n++ = '\\';
|
2008-06-20 20:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-15 18:45:35 +00:00
|
|
|
} while ((*n++ = *dir++));
|
2002-11-14 23:47:11 +00:00
|
|
|
if(tl - t1l - 2 > 0)
|
2003-08-15 18:45:35 +00:00
|
|
|
strcpy(n-1,p+2);
|
2002-11-14 23:47:11 +00:00
|
|
|
return r;
|
|
|
|
} else
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (*kill_warn)(const void*, const void*);
|
|
|
|
|
2002-12-04 23:41:04 +00:00
|
|
|
static int mylstat(char *dir, char *file,struct stat* st) {
|
|
|
|
int l = strlen(dir) + strlen(file);
|
2002-12-28 14:19:07 +00:00
|
|
|
char s[l+2];
|
2007-12-10 14:12:40 +00:00
|
|
|
if (!strcmp("..", file)) {
|
|
|
|
char *slash;
|
|
|
|
l -= 3;
|
|
|
|
strcpy(s, dir);
|
2010-02-19 09:14:01 +00:00
|
|
|
#if HAVE_DOS_PATHS
|
2007-12-10 14:12:40 +00:00
|
|
|
if (s[l] == '/' || s[l] == '\\')
|
|
|
|
#else
|
|
|
|
if (s[l] == '/')
|
|
|
|
#endif
|
|
|
|
s[l] = '\0';
|
|
|
|
slash = strrchr(s, '/');
|
2010-02-19 09:14:01 +00:00
|
|
|
#if HAVE_DOS_PATHS
|
2007-12-10 14:12:40 +00:00
|
|
|
if (!slash)
|
|
|
|
slash = strrchr(s,'\\');
|
|
|
|
#endif
|
|
|
|
if (!slash)
|
|
|
|
return stat(dir,st);
|
|
|
|
slash[1] = '\0';
|
|
|
|
return stat(s,st);
|
|
|
|
}
|
2002-12-04 23:41:04 +00:00
|
|
|
sprintf(s,"%s/%s",dir,file);
|
2003-02-03 09:33:22 +00:00
|
|
|
return stat(s,st);
|
2002-12-04 23:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int compare(char **a, char **b){
|
|
|
|
if((*a)[strlen(*a) - 1] == '/') {
|
|
|
|
if((*b)[strlen(*b) - 1] == '/')
|
|
|
|
return strcmp(*b, *a) ;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if((*b)[strlen(*b) - 1] == '/')
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return strcmp(*b, *a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-22 20:55:49 +00:00
|
|
|
static char **get_extensions(menu_t *menu){
|
|
|
|
char **extensions, ext[32];
|
|
|
|
FILE *fp;
|
|
|
|
int n = 1;
|
|
|
|
|
|
|
|
if (!mpriv->filter)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fp = fopen(mpriv->filter, "r");
|
|
|
|
if(!fp)
|
|
|
|
return NULL;
|
|
|
|
|
2010-02-26 15:01:37 +00:00
|
|
|
extensions = malloc(sizeof(*extensions));
|
2006-08-22 20:55:49 +00:00
|
|
|
*extensions = NULL;
|
|
|
|
|
|
|
|
while(fgets(ext,sizeof(ext),fp)) {
|
|
|
|
char **l, *e;
|
|
|
|
int s = strlen (ext);
|
|
|
|
|
|
|
|
if(ext[s-1] == '\n') {
|
|
|
|
ext[s-1] = '\0';
|
|
|
|
s--;
|
|
|
|
}
|
2010-02-26 15:01:37 +00:00
|
|
|
e = malloc(s+1);
|
|
|
|
extensions = realloc(extensions, ++n * sizeof(*extensions));
|
|
|
|
extensions = realloc(extensions, ++n * sizeof(*extensions));
|
2006-08-22 20:55:49 +00:00
|
|
|
strcpy (e, ext);
|
|
|
|
for (l=extensions; *l; l++);
|
|
|
|
*l++ = e;
|
|
|
|
*l = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
return extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_extensions(char **extensions){
|
|
|
|
if (extensions) {
|
|
|
|
char **l = extensions;
|
|
|
|
while (*l)
|
|
|
|
free (*l++);
|
|
|
|
free (extensions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-12 19:26:55 +00:00
|
|
|
static int open_dir(menu_t* menu,char* args) {
|
2002-12-04 23:41:04 +00:00
|
|
|
char **namelist, **tp;
|
|
|
|
struct dirent *dp;
|
2002-11-14 23:47:11 +00:00
|
|
|
struct stat st;
|
|
|
|
int n;
|
2007-05-07 16:46:24 +00:00
|
|
|
int path_fp;
|
2002-11-14 23:47:11 +00:00
|
|
|
char* p = NULL;
|
|
|
|
list_entry_t* e;
|
2002-12-04 23:41:04 +00:00
|
|
|
DIR* dirp;
|
2006-08-22 20:55:49 +00:00
|
|
|
extern int file_filter;
|
|
|
|
char **extensions, **elem, *ext;
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
menu_list_init(menu);
|
|
|
|
|
|
|
|
if(mpriv->dir)
|
|
|
|
free(mpriv->dir);
|
|
|
|
mpriv->dir = strdup(args);
|
|
|
|
if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title)
|
|
|
|
free(mpriv->p.title);
|
|
|
|
p = strstr(mpriv->title,"%p");
|
|
|
|
|
2008-06-20 20:36:05 +00:00
|
|
|
mpriv->p.title = replace_path(mpriv->title,mpriv->dir,0);
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2002-12-04 23:41:04 +00:00
|
|
|
if ((dirp = opendir (mpriv->dir)) == NULL){
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_ERR,"[MENU] opendir error: %s\n", strerror(errno));
|
2002-12-04 23:41:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-07 16:46:24 +00:00
|
|
|
if (menu_keepdir) {
|
|
|
|
path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666);
|
|
|
|
if (path_fp >= 0) {
|
|
|
|
write (path_fp, mpriv->dir, strlen (mpriv->dir));
|
|
|
|
close (path_fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 15:01:37 +00:00
|
|
|
namelist = malloc(sizeof(char *));
|
2006-08-22 20:55:49 +00:00
|
|
|
extensions = get_extensions(menu);
|
2002-12-04 23:41:04 +00:00
|
|
|
|
|
|
|
n=0;
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0)
|
|
|
|
continue;
|
2007-05-29 18:49:38 +00:00
|
|
|
if (menu_chroot && !strcmp (dp->d_name,"..")) {
|
2008-06-03 22:35:02 +00:00
|
|
|
size_t len = strlen (menu_chroot);
|
2007-05-29 18:49:38 +00:00
|
|
|
if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1)
|
|
|
|
&& !strncmp (mpriv->dir, menu_chroot, len))
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-10 14:12:40 +00:00
|
|
|
if (mylstat(args,dp->d_name,&st))
|
|
|
|
continue;
|
2006-08-22 20:55:49 +00:00
|
|
|
if (file_filter && extensions && !S_ISDIR(st.st_mode)) {
|
|
|
|
if((ext = strrchr(dp->d_name,'.')) == NULL)
|
|
|
|
continue;
|
|
|
|
ext++;
|
|
|
|
elem = extensions;
|
|
|
|
do {
|
|
|
|
if (!strcasecmp(ext, *elem))
|
|
|
|
break;
|
|
|
|
} while (*++elem);
|
|
|
|
if (*elem == NULL)
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-04 23:41:04 +00:00
|
|
|
if(n%20 == 0){ // Get some more mem
|
2010-02-26 15:01:37 +00:00
|
|
|
if((tp = realloc(namelist, (n+20) * sizeof (char *)))
|
2002-12-04 23:41:04 +00:00
|
|
|
== NULL) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_ERR,"[MENU] realloc error: %s\n", strerror(errno));
|
2003-01-26 16:03:16 +00:00
|
|
|
n--;
|
2002-12-04 23:41:04 +00:00
|
|
|
goto bailout;
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2002-12-04 23:41:04 +00:00
|
|
|
namelist=tp;
|
|
|
|
}
|
|
|
|
|
2010-02-26 15:01:37 +00:00
|
|
|
namelist[n] = malloc(strlen(dp->d_name) + 2);
|
2002-12-04 23:41:04 +00:00
|
|
|
if(namelist[n] == NULL){
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_ERR,"[MENU] memory allocation error: %s\n", strerror(errno));
|
2003-01-26 16:03:16 +00:00
|
|
|
n--;
|
2002-12-04 23:41:04 +00:00
|
|
|
goto bailout;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-12-04 23:41:04 +00:00
|
|
|
strcpy(namelist[n], dp->d_name);
|
|
|
|
if(S_ISDIR(st.st_mode))
|
|
|
|
strcat(namelist[n], "/");
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bailout:
|
2006-08-22 20:55:49 +00:00
|
|
|
free_extensions (extensions);
|
2005-07-22 22:52:13 +00:00
|
|
|
closedir(dirp);
|
|
|
|
|
2003-01-26 16:03:16 +00:00
|
|
|
qsort(namelist, n, sizeof(char *), (kill_warn)compare);
|
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
if (n < 0) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_ERR,"[MENU] readdir error: %s\n",strerror(errno));
|
2002-11-14 23:47:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
while(n--) {
|
2003-01-26 16:03:16 +00:00
|
|
|
if((e = calloc(1,sizeof(list_entry_t))) != NULL){
|
2002-12-28 14:19:07 +00:00
|
|
|
e->p.next = NULL;
|
2002-12-04 23:41:04 +00:00
|
|
|
e->p.txt = strdup(namelist[n]);
|
|
|
|
if(strchr(namelist[n], '/') != NULL)
|
2002-11-14 23:47:11 +00:00
|
|
|
e->d = 1;
|
2002-12-04 23:41:04 +00:00
|
|
|
menu_list_add_entry(menu,e);
|
2003-01-26 16:03:16 +00:00
|
|
|
}else{
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_ERR,"[MENU] memory allocation error: %s\n", strerror(errno));
|
2003-01-26 16:03:16 +00:00
|
|
|
}
|
2002-11-14 23:47:11 +00:00
|
|
|
free(namelist[n]);
|
|
|
|
}
|
|
|
|
free(namelist);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-08-22 19:59:53 +00:00
|
|
|
static char *action;
|
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
static void read_cmd(menu_t* menu,int cmd) {
|
|
|
|
switch(cmd) {
|
2006-03-25 17:32:10 +00:00
|
|
|
case MENU_CMD_LEFT:
|
|
|
|
mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../
|
|
|
|
case MENU_CMD_RIGHT:
|
2002-11-14 23:47:11 +00:00
|
|
|
case MENU_CMD_OK: {
|
|
|
|
// Directory
|
2007-12-09 10:32:05 +00:00
|
|
|
if(mpriv->p.current->d && !mpriv->dir_action) {
|
|
|
|
// Default action : open this dirctory ourself
|
2002-11-14 23:47:11 +00:00
|
|
|
int l = strlen(mpriv->dir);
|
|
|
|
char *slash = NULL, *p = NULL;
|
|
|
|
if(strcmp(mpriv->p.current->p.txt,"../") == 0) {
|
|
|
|
if(l <= 1) break;
|
|
|
|
mpriv->dir[l-1] = '\0';
|
|
|
|
slash = strrchr(mpriv->dir,'/');
|
2010-02-19 09:14:01 +00:00
|
|
|
#if HAVE_DOS_PATHS
|
2006-10-29 21:10:59 +00:00
|
|
|
if (!slash)
|
|
|
|
slash = strrchr(mpriv->dir,'\\');
|
|
|
|
#endif
|
2002-11-14 23:47:11 +00:00
|
|
|
if(!slash) break;
|
|
|
|
slash[1] = '\0';
|
|
|
|
p = strdup(mpriv->dir);
|
|
|
|
} else {
|
|
|
|
p = malloc(l + strlen(mpriv->p.current->p.txt) + 1);
|
|
|
|
sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
|
|
|
|
}
|
|
|
|
menu_list_uninit(menu,free_entry);
|
|
|
|
if(!open_dir(menu,p)) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_ERR,"[MENU] Can't open directory %s.\n",p);
|
2002-11-14 23:47:11 +00:00
|
|
|
menu->cl = 1;
|
|
|
|
}
|
|
|
|
free(p);
|
2007-12-09 10:32:05 +00:00
|
|
|
} else { // File and directory dealt with action string.
|
2002-11-14 23:47:11 +00:00
|
|
|
int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
|
|
|
|
char filename[fname_len];
|
|
|
|
char *str;
|
2007-12-09 10:32:05 +00:00
|
|
|
char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action;
|
2002-11-14 23:47:11 +00:00
|
|
|
sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
|
2008-06-20 20:36:05 +00:00
|
|
|
str = replace_path(action, filename,1);
|
2008-04-30 10:00:59 +00:00
|
|
|
mp_input_parse_and_queue_cmds(menu->input_ctx, str);
|
2007-12-09 10:32:05 +00:00
|
|
|
if (str != action)
|
2002-11-14 23:47:11 +00:00
|
|
|
free(str);
|
2007-12-09 10:32:05 +00:00
|
|
|
}
|
2002-11-14 23:47:11 +00:00
|
|
|
} break;
|
2006-08-22 19:59:53 +00:00
|
|
|
case MENU_CMD_ACTION: {
|
|
|
|
int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
|
|
|
|
char filename[fname_len];
|
|
|
|
char *str;
|
|
|
|
sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
|
2008-06-20 20:36:05 +00:00
|
|
|
str = replace_path(action, filename,1);
|
2008-04-30 10:00:59 +00:00
|
|
|
mp_input_parse_and_queue_cmds(menu->input_ctx, str);
|
2006-08-22 19:59:53 +00:00
|
|
|
if(str != action)
|
|
|
|
free(str);
|
|
|
|
} break;
|
2002-11-14 23:47:11 +00:00
|
|
|
default:
|
|
|
|
menu_list_read_cmd(menu,cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-26 13:13:48 +00:00
|
|
|
static int read_key(menu_t* menu,int c){
|
2006-08-22 19:59:53 +00:00
|
|
|
char **str;
|
|
|
|
for (str=mpriv->actions; str && *str; str++)
|
|
|
|
if (c == (*str)[0]) {
|
|
|
|
action = &(*str)[2];
|
|
|
|
read_cmd(menu,MENU_CMD_ACTION);
|
2007-12-26 13:13:48 +00:00
|
|
|
return 1;
|
2006-08-22 19:59:53 +00:00
|
|
|
}
|
2007-12-04 10:42:59 +00:00
|
|
|
if (menu_dflt_read_key(menu, c))
|
2007-12-26 13:13:48 +00:00
|
|
|
return 1;
|
|
|
|
return menu_list_jump_to_key(menu, c);
|
2002-11-14 23:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void clos(menu_t* menu) {
|
|
|
|
menu_list_uninit(menu,free_entry);
|
|
|
|
free(mpriv->dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int open_fs(menu_t* menu, char* args) {
|
2008-06-06 23:24:39 +00:00
|
|
|
char *path = mpriv->path;
|
2002-11-14 23:47:11 +00:00
|
|
|
int r = 0;
|
2007-11-26 00:28:05 +00:00
|
|
|
char wd[PATH_MAX+1], b[PATH_MAX+1];
|
2002-11-14 23:47:11 +00:00
|
|
|
args = NULL; // Warning kill
|
|
|
|
|
|
|
|
menu->draw = menu_list_draw;
|
|
|
|
menu->read_cmd = read_cmd;
|
|
|
|
menu->read_key = read_key;
|
|
|
|
menu->close = clos;
|
|
|
|
|
2007-05-07 16:46:24 +00:00
|
|
|
if (menu_keepdir) {
|
|
|
|
if (!path || path[0] == '\0') {
|
|
|
|
struct stat st;
|
|
|
|
int path_fp;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-05-07 16:46:24 +00:00
|
|
|
path_fp = open (MENU_KEEP_PATH, O_RDONLY);
|
|
|
|
if (path_fp >= 0) {
|
|
|
|
if (!fstat (path_fp, &st) && (st.st_size > 0)) {
|
|
|
|
path = malloc(st.st_size+1);
|
2008-06-05 19:46:16 +00:00
|
|
|
path[st.st_size] = '\0';
|
2008-06-06 23:24:39 +00:00
|
|
|
if (!((read(path_fp, path, st.st_size) == st.st_size) && path[0] == '/'
|
|
|
|
&& !stat(path, &st) && S_ISDIR(st.st_mode))) {
|
2007-05-07 16:46:24 +00:00
|
|
|
free(path);
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (path_fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
getcwd(wd,PATH_MAX);
|
2007-12-31 01:20:50 +00:00
|
|
|
if (!path || path[0] == '\0') {
|
2008-01-10 12:44:17 +00:00
|
|
|
#if 0
|
2007-12-31 01:20:50 +00:00
|
|
|
char *slash = NULL;
|
|
|
|
if (filename && !strstr(filename, "://") && (path=realpath(filename, b))) {
|
|
|
|
slash = strrchr(path, '/');
|
2010-02-19 09:14:01 +00:00
|
|
|
#if HAVE_DOS_PATHS
|
2007-12-31 01:20:50 +00:00
|
|
|
// FIXME: Do we need and can convert all '\\' in path to '/' on win32?
|
|
|
|
if (!slash)
|
|
|
|
slash = strrchr(path, '\\');
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (slash)
|
|
|
|
slash[1] = '\0';
|
|
|
|
else
|
2008-01-10 12:44:17 +00:00
|
|
|
#endif
|
2007-12-31 01:20:50 +00:00
|
|
|
path = wd;
|
|
|
|
}
|
2007-11-26 00:28:05 +00:00
|
|
|
if (path[0] != '/') {
|
|
|
|
if(path[strlen(path)-1] != '/')
|
|
|
|
snprintf(b,sizeof(b),"%s/%s/",wd,path);
|
2002-11-14 23:47:11 +00:00
|
|
|
else
|
2007-11-26 00:28:05 +00:00
|
|
|
snprintf(b,sizeof(b),"%s/%s",wd,path);
|
|
|
|
path = b;
|
|
|
|
} else if (path[strlen(path)-1]!='/') {
|
|
|
|
sprintf(b,"%s/",path);
|
|
|
|
path = b;
|
|
|
|
}
|
|
|
|
if (menu_chroot && menu_chroot[0] == '/') {
|
|
|
|
int l = strlen(menu_chroot);
|
|
|
|
if (l > 0 && menu_chroot[l-1] == '/')
|
|
|
|
--l;
|
|
|
|
if (strncmp(menu_chroot, path, l) || (path[l] != '\0' && path[l] != '/')) {
|
|
|
|
if (menu_chroot[l] == '/')
|
|
|
|
path = menu_chroot;
|
|
|
|
else {
|
|
|
|
sprintf(b,"%s/",menu_chroot);
|
|
|
|
path = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r = open_dir(menu,path);
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
const menu_info_t menu_info_filesel = {
|
|
|
|
"File seletor menu",
|
|
|
|
"filesel",
|
|
|
|
"Albeu",
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
"fs_cfg",
|
|
|
|
sizeof(struct menu_priv_s),
|
|
|
|
&cfg_dflt,
|
|
|
|
cfg_fields
|
|
|
|
},
|
|
|
|
open_fs
|
|
|
|
};
|