annotate libmenu/menu_filesel.c @ 8291:abe95dde3223

limits.h required to get a PATH_MAX definition (on solaris)
author jkeil
date Tue, 26 Nov 2002 18:54:23 +0000
parents 4b8fcc2af8f1
children ecf6a4cf3272
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
2 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
3 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
4 #include <dirent.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5 #include <errno.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <string.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7 #include <sys/types.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8 #include <sys/stat.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
9 #include <ctype.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
10 #include <unistd.h>
8291
abe95dde3223 limits.h required to get a PATH_MAX definition (on solaris)
jkeil
parents: 8226
diff changeset
11 #include <limits.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
12
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
13
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
14 #include "../config.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
15
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
16 #include "../m_struct.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17 #include "../m_option.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19 #include "img_format.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20 #include "mp_image.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 #include "../input/input.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 #include "../linux/keycodes.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 int d;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
31
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
32 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
33 menu_list_priv_t p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34 char* dir; // current dir
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 /// Cfg fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 char* path;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 char* title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38 char* file_action;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 char* dir_action;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 int auto_close;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 MENU_LIST_PRIV_DFLT,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 "Select a file: %p",
8226
4b8fcc2af8f1 quote the filenames
albeu
parents: 8197
diff changeset
49 "loadfile '%p'",
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 0
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 { "path", ST_OFF(path), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 { "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61 { "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 { "auto-close", ST_OFF(auto_close), CONF_TYPE_FLAG, 0, 0, 1, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 free(entry->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 static char* replace_path(char* title , char* dir) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 char *p = strstr(title,"%p");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 if(p) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 int tl = strlen(title);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 int dl = strlen(dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 int t1l = p-title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79 int l = tl - 2 + dl;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 char*r = malloc(l + 1);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 memcpy(r,title,t1l);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 memcpy(r+t1l,dir,dl);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 if(tl - t1l - 2 > 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 memcpy(r+t1l+dl,p+2,tl - t1l - 2);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 r[l] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 return r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 return title;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 typedef int (*kill_warn)(const void*, const void*);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 static int open_dir(menu_t* menu,char* args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 struct dirent **namelist;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 struct stat st;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 int n;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 char* p = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 list_entry_t* e;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 int mylstat(char *dir, char *file,struct stat* st) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 int l = strlen(dir) + strlen(file);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 char s[l+1];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 sprintf(s,"%s%s",args,file);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 return lstat(s,st);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107 int compare(struct dirent **a,struct dirent **b) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 struct stat as,bs;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 mylstat(args,(*a)->d_name,&as);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 mylstat(args,(*b)->d_name,&bs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 if(S_ISDIR(as.st_mode)) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 if(S_ISDIR(bs.st_mode))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 return alphasort(b,a);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 if(S_ISDIR(bs.st_mode))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 return -1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 return alphasort(b,a);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 int select_f(const struct dirent *d) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 if(d->d_name[0] != '.' || strcmp(d->d_name,"..") == 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
129
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
131
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
132 if(mpriv->dir)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133 free(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
134 mpriv->dir = strdup(args);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
135 if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136 free(mpriv->p.title);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 p = strstr(mpriv->title,"%p");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 mpriv->p.title = replace_path(mpriv->title,mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
140
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
141 n = scandir(mpriv->dir, &namelist, select_f, (kill_warn)compare);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142 if (n < 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143 printf("scandir error: %s\n",strerror(errno));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 while(n--) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 e = calloc(1,sizeof(list_entry_t));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 mylstat(args,namelist[n]->d_name,&st);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 if(S_ISDIR(st.st_mode)) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 int sl =strlen(namelist[n]->d_name);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
152 e->p.txt = malloc(sl + 2);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 strncpy(e->p.txt,namelist[n]->d_name,sl);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 e->p.txt[sl] = '/';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 e->p.txt[sl+1] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
156 e->d = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
157 menu_list_add_entry(menu,e);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158 } else if(strcmp(namelist[n]->d_name,"..") == 0 || namelist[n]->d_name[0] != '.') {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 e->p.txt = strdup(namelist[n]->d_name);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 menu_list_add_entry(menu,e);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 free(namelist[n]);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
163 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
164 free(namelist);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 mp_cmd_t* c = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
172 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 case MENU_CMD_OK: {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 // Directory
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 if(mpriv->p.current->d) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 if(mpriv->dir_action) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 char filename[fname_len];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179 char* str;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
180 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181 str = replace_path(mpriv->dir_action,filename);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
182 c = mp_input_parse_cmd(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
183 if(str != mpriv->dir_action)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
184 free(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
185 } else { // Default action : open this dirctory ourself
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 int l = strlen(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187 char *slash = NULL, *p = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
188 if(strcmp(mpriv->p.current->p.txt,"../") == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
189 if(l <= 1) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
190 mpriv->dir[l-1] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
191 slash = strrchr(mpriv->dir,'/');
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
192 if(!slash) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
193 slash[1] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
194 p = strdup(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
195 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
196 p = malloc(l + strlen(mpriv->p.current->p.txt) + 1);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
197 sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
198 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
199 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
200 if(!open_dir(menu,p)) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
201 printf("Can't open directory %s\n",p);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
202 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
203 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
204 free(p);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
205 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
206 } else { // Files
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
207 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
208 char filename[fname_len];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
209 char *str;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
210 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
211 str = replace_path(mpriv->file_action,filename);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
212 c = mp_input_parse_cmd(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
213 if(str != mpriv->file_action)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
214 free(str);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
215 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
216 if(c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
217 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
218 if(mpriv->auto_close)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
219 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
220 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
221 } break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
222 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
223 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
224 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
225 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
226
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
227 static void read_key(menu_t* menu,int c){
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
228 if(c == KEY_BS) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
229 mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
230 read_cmd(menu,MENU_CMD_OK);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
231 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
232 menu_list_read_key(menu,c,1);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
233 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
234
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
235 static void clos(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
236 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
237 free(mpriv->dir);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
238 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
239
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
240 static int open_fs(menu_t* menu, char* args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
241 char *path = mpriv->path;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
242 int r = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
243 char wd[PATH_MAX+1];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
244 args = NULL; // Warning kill
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
245
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
246 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
247 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
248 menu->read_key = read_key;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
249 menu->close = clos;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
250
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
251 getcwd(wd,PATH_MAX);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
252 if(!path || path[0] == '\0') {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
253 int l = strlen(wd) + 2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
254 char b[l];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
255 sprintf(b,"%s/",wd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
256 r = open_dir(menu,b);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
257 } else if(path[0] != '/') {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
258 int al = strlen(path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
259 int l = strlen(wd) + al + 3;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
260 char b[l];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
261 if(b[al-1] != '/')
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
262 sprintf(b,"%s/%s/",wd,path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
263 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
264 sprintf(b,"%s/%s",wd,path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
265 r = open_dir(menu,b);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
266 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
267 r = open_dir(menu,path);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
268
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
269 return r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
270 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
271
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
272 const menu_info_t menu_info_filesel = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
273 "File seletor menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
274 "filesel",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
275 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
276 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
277 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
278 "fs_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
279 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
280 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
281 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
282 },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
283 open_fs
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
284 };