-
Notifications
You must be signed in to change notification settings - Fork 3
/
filesel.c
295 lines (267 loc) · 6.46 KB
/
filesel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* CFLIB, a GEM library for ATARI/TOS
* Copyright (C) 1999, 2000 Christian Felsch
*
* Modified for FreeMiNT CVS by Frank Naumann <fnaumann@freemint.de>
*
* Please send suggestions, patches or bug reports to me or
* the MiNT mailing list.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "intern.h"
#include "app.h"
#ifdef __PUREC__
#include <wdlgfslx.h>
#endif
/* -- Selectric -------------------------------------------------------------- */
typedef struct
{
unsigned long id; /* Selectric ID (SLCT) */
unsigned short version; /* version (BCD-Format) */
struct
{
unsigned : 7; /* reserved */
unsigned todaytime : 1;
unsigned pthsav : 1; /* save GEMDOS paths */
unsigned stdest : 1; /* stay in destination path */
unsigned : 1; /* reserved */
unsigned numsrt : 1; /* numsort */
unsigned lower : 1; /* use lowercase letters */
unsigned dclick : 1; /* open folder on dclick */
unsigned hidden : 1; /* show hidden files */
unsigned bypass : 1; /* Selectric ON/OFF */
} config;
short sort; /* sort-mode (neg. = rev.) */
short num_ext; /* number of extensions */
char *(*ext)[]; /* preset extensions */
short num_paths; /* number of paths */
char *(*paths)[]; /* preset paths */
short comm; /* communication word */
short in_count; /* input counter */
void *in_ptr; /* input pointer */
short out_count; /* output counter */
void *out_ptr; /* output pointer */
void *f1;
void *f2;
void *f3;
} SLCT;
#define SLCT_ANZ 10
static SLCT *slct = NULL;
static int slct_check(void)
{
long l;
if (getcookie("FSEL", &l))
{
slct = (SLCT *)l;
if (slct && slct->id != 0x534c4354L) /* 'SLCT' */
slct = NULL;
if (slct && !slct->config.bypass) /* Selectric auch aktiv? */
slct = NULL;
}
if (slct && (slct->version >= 0x100))
return TRUE;
else
return FALSE;
}
/* -- MagiC ------------------------------------------------------------------ */
static int do_magx(char *path, char *name, char *mask, char *title, FSEL_CB open_cb)
{
int ok = FALSE;
void *fsl;
char def_mask[] = "*\0\0";
char pat[50];
char *p;
char hist_path[256] = "\0\0";
_WORD num, flags = 0, but, i, j, win, ret;
EVNT ev;
j = 0;
if ((mask[0] != '\0') && strcmp(mask, "*") != 0)
{
p = mask;
j = 0;
while (*p != '\0')
{
pat[j++] = *p;
p++;
}
pat[j++] = '\0';
}
for (i = 0; i < 3; i++)
pat[j++] = def_mask[i];
if (path[0] != '\0')
{
strcpy(hist_path, path);
i = (int)strlen(path);
hist_path[i + 1] = '\0'; /* Doppelnull am Ende! */
}
if (open_cb != NULL)
flags |= GETMULTI;
if (!cf_msg_cb) /* keine Msg-Routine -> modal */
{
i = SORTBYNAME;
fsl = fslx_do(title, path, 256, name, 60, pat, 0L, hist_path, &i, flags, &but, &num, &p);
if (fsl)
{
}
}
else
{
fsl = fslx_open(title, -1, -1, &win, path, 256, name, 60, pat, 0L, hist_path, SORTBYNAME, flags);
if (fsl)
{
disable_menu();
do
{
ev.mwhich = evnt_multi(MU_KEYBD | MU_MESAG | MU_BUTTON,
2, 1, 1,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
ev.msg,
#if defined(__PUREC__) && !defined(_GEMLIB_COMPATIBLE)
0, 0,
#else
0,
#endif
&ev.mx, &ev.my, &ev.mbutton, &ev.kstate, &ev.key, &ev.mclicks);
if (ev.mwhich & MU_MESAG)
{
switch (ev.msg[0])
{
case WM_REDRAW:
case WM_MOVED:
case WM_SIZED:
if (ev.msg[3] != win) /* fr fremdes Fenster */
{
handle_mdial_msg(ev.msg);
}
break;
case WM_BOTTOMED: /* nicht erlaubt! */
break;
case WM_TOPPED:
case WM_NEWTOP:
case WM_ONTOP:
ev.msg[0] = WM_TOPPED; /* immer Filebox toppen! */
ev.msg[3] = win;
break;
}
}
ret = fslx_evnt(fsl, &ev, path, name, &but, &num, &i, &p);
} while (ret == 1);
enable_menu();
}
}
if (fsl)
{
if (but == 1)
{
if (flags & GETMULTI)
{
do
{
open_cb(path, name);
i = fslx_getnxtfile(fsl, name);
} while (i);
/* leeren */
path[0] = '\0';
name[0] = '\0';
}
else
{
p = strrchr (path, '\\'); /* Maske abhacken */
p[1] = '\0';
make_normalpath(path);
}
ok = TRUE;
}
fslx_close(fsl);
}
return ok;
}
/* --------------------------------------------------------------------------- */
int select_file(char *path, char *name, char *mask, char *title, FSEL_CB open_cb)
{
int ok = FALSE;
_WORD slct_multi = FALSE;
_WORD but, i, d;
char *p;
char *files[SLCT_ANZ];
if (path[0] == '\0') /* kein Pfad -> aktuellen holen */
get_path(path, 0);
else
make_normalpath(path);
if (slct_check())
{
if (open_cb != NULL) /* Selectric-mehrfach Auswahl */
{
for (i = 0; i < SLCT_ANZ; i++)
files[i] = (char *) cf_malloc(256, "select_file", FALSE);
slct->comm = 1;
slct->out_count = SLCT_ANZ;
slct->out_ptr = files;
slct_multi = TRUE;
}
}
else if (appl_xgetinfo(7, &i, &d, &d, &d) && (i & 8))
{
return do_magx(path, name, mask, title, open_cb);
}
/* normale Auswahl */
if (mask[0] == '\0')
strcat(path, "*.*");
else
strcat(path, mask);
wind_update(BEG_UPDATE);
/* wind_update(BEG_MCTRL); */
if (slct || gl_gem >= 0x140)
fsel_exinput(path, name, &but, title);
else
fsel_input(path, name, &but);
/* wind_update(END_MCTRL); */
wind_update(END_UPDATE);
ok = (but == 1);
if (ok)
{
p = strrchr (path, '\\'); /* Maske abhacken */
p[1] = '\0';
make_normalpath(path);
if (slct_multi) /* Mehrfach-Selectrics */
{
_WORD cont = TRUE;
i = 0;
while (cont && (i < slct->out_count))
{
cont = open_cb(path, files[i]);
i++;
}
for (i = 0; i < SLCT_ANZ; i++)
if (files[i] != NULL)
free(files[i]);
/* leeren */
path[0] = '\0';
name[0] = '\0';
}
else if (open_cb) /* Callback, aber keine Mahrfachauswahl */
{
open_cb(path, name);
/* leeren */
path[0] = '\0';
name[0] = '\0';
}
}
return ok;
}