Repository navigation
Expand file tree
/
Copy pathfile.c
More file actions
901 lines (805 loc) · 22.2 KB
/
Copy pathfile.c
File metadata and controls
901 lines (805 loc) · 22.2 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425<
8000
/div>
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
/*
* file.c Functions to handle file selector.
*
* This file is part of the minicom communications package,
* Copyright 1991-1995 Miquel van Smoorenburg.
*
* This file created from code mostly cadged from "dial.c"
* by Miquel van Smoorenburg. Written by James S. Seymour.
* Copyright (c) 1998 by James S. Seymour (jseymour@jimsun.LinxNet.com)
* Some mods for i18n
* Copyright (c) 1998 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
*
* This program 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <limits.h>
#include "port.h"
#include "minicom.h"
#include "intl.h"
#include "getsdir.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#define FILE_MWTR 1 /* main window top row */
#define SUBM_OKAY 5 /* last entry in sub-menu */
static int nrents = 1;
static void file_tell(const char *s);
static void dhili(int k);
static void prdir(WIN *dirw, int top, int cur, GETSDIR_ENTRY *dirdat, int longest);
static void prone(WIN *dirw, GETSDIR_ENTRY *dirdat, int longest, int inverse);
static void *set_work_dir(void *existing, size_t min_len);
static int new_filedir(GETSDIR_ENTRY *dirdat, int flushit);
static void goto_filedir(char *new_dir, int absolut);
static int tag_untag(char *pat, int tag);
static char *concat_list(GETSDIR_ENTRY *d);
static WIN *dsub;
static const char *const what[] =
{
/* TRANSLATORS: Translation of each of these menu items should not be
* longer than 7 characters. The upper-case letter is a shortcut,
* so keep them unique and ASCII; 'h', 'j', 'k', 'l' are reserved */
N_("[Goto]"), N_("[Prev]"), N_("[Show]"), N_("[Tag]"), N_("[Untag]"),
N_("[Okay]")
};
#define WHAT_NR_OPTIONS (sizeof (what) / sizeof (*what))
#define WHAT_WIDTH 8 /* Width of one entry */
/* Number of bytes for <= 7 characters */
static int what_lens[WHAT_NR_OPTIONS];
/* Number of ' ' padding entries at left and right, left is >= 1 */
static int what_padding[WHAT_NR_OPTIONS][2];
static int dprev;
/* Little menu. */
static const char *d_yesno[] = { N_(" Yes "), N_(" No "), NULL };
/*
* Tell a little message
*/
static void file_tell(const char *s)
{
WIN *w;
w = mc_tell("%s", s);
sleep(1);
mc_wclose(w, 1);
}
/* Draw an entry in the horizontal menu */
static void horiz_draw(size_t k, char start_attr, char end_attr)
{
static const char spaces[] = " ";
mc_wprintf(dsub, "%.*s", what_padding[k][0], spaces);
mc_wsetattr(dsub, start_attr);
mc_wprintf(dsub, "%.*s", what_lens[k], _(what[k]));
mc_wsetattr(dsub, end_attr);
mc_wprintf(dsub, "%.*s", what_padding[k][1], spaces);
}
/*
* Highlight a choice in the horizontal menu.
*/
static void dhili(int k)
{
int initial_y = (76 - (WHAT_NR_OPTIONS * WHAT_WIDTH >= 76
? 74 : WHAT_NR_OPTIONS * WHAT_WIDTH)) / 2;
if (k == dprev)
return;
if (dprev >= 0) {
mc_wlocate(dsub, initial_y + WHAT_WIDTH * dprev, 0);
if (!useattr)
mc_wputs(dsub, " ");
else
horiz_draw(dprev, stdattr, stdattr);
}
dprev = k;
mc_wlocate(dsub, initial_y + WHAT_WIDTH * k, 0);
if (!useattr)
mc_wputs(dsub, ">");
else
horiz_draw(k, XA_REVERSE | stdattr, stdattr);
}
static inline GETSDIR_ENTRY *getno(int no, GETSDIR_ENTRY *d)
{
if (no >= nrents)
return NULL;
return d + no;
}
/*
* Print the directory. Only draw from "cur" to bottom.
*/
static void prdir(WIN *dirw, int top, int cur,
GETSDIR_ENTRY *dirdat, int longest)
{
int f, start;
char f_str[BUFSIZ];
char t_str[BUFSIZ];
start = cur - top;
dirflush = 0;
sprintf(f_str, " %%-%ds", longest + 2);
mc_wlocate(dirw, 0, start + FILE_MWTR);
for (f = start; f < dirw->ys - (1 + FILE_MWTR); f++) {
GETSDIR_ENTRY *d;
if (!(d = getno(f + top, dirdat)))
break;
if (d->cflags & FL_TAG)
mc_wsetattr(dirw, XA_REVERSE | stdattr);
if (S_ISDIR(d->mode)) {
snprintf(t_str, sizeof(t_str), "[%s]", d->fname);
mc_wprintf(dirw, f_str, t_str);
} else
mc_wprintf(dirw, f_str, d->fname);
mc_wsetattr(dirw, XA_NORMAL | stdattr);
mc_wputc(dirw, '\n');
}
dirflush = 1;
mc_wflush();
}
/*
* Print one directory entry.
*/
static void prone(WIN *dirw, GETSDIR_ENTRY *dirdat, int longest, int inverse)
{
char f_str[BUFSIZ];
char t_str[BUFSIZ];
dirflush = 0;
sprintf(f_str, " %%-%ds", longest + 2);
/*
if (dirdat->cflags & FL_TAG)
mc_wsetattr(dirw, XA_REVERSE | stdattr);
*/
if (inverse)
mc_wsetattr(dirw, XA_REVERSE | stdattr);
if (S_ISDIR(dirdat->mode)) {
snprintf(t_str, sizeof(t_str), "[%s]", dirdat->fname);
mc_wprintf(dirw, f_str, t_str);
} else
mc_wprintf(dirw, f_str, dirdat->fname);
mc_wsetattr(dirw, XA_NORMAL | stdattr);
dirflush = 1;
mc_wflush();
}
static WIN *main_w;
static GETSDIR_ENTRY *global_dirdat;
static int cur = 0;
static int ocur = 0;
static int subm = SUBM_OKAY;
static int quit = 0;
static int top = 0;
static int c = 0;
static int pgud = 0;
static int first = 1;
static char *s;
static int longest;
static char file_title[BUFSIZ];
static char cwd_str[BUFSIZ];
static char *prev_dir = NULL;
static char *work_dir = NULL;
static char *d_work_dir = NULL;
static char *u_work_dir = NULL;
static int min_len = 1;
static char wc_str[128] = "";
static char wc_mem[128] = "";
static int tag_cnt = 0;
static int how_many = 0;
static int down_loading = 0;
static char *ret_buf = NULL;
/* Init up/down work directories to make sure we start from
* the configuration defaults on the next up/download. jl 6/2000
*/
void init_dir(char dir)
{
char *p = NULL;
switch (dir) {
case 'u':
p = u_work_dir;
u_work_dir = NULL;
break;
case 'd':
p = d_work_dir;
d_work_dir = NULL;
break;
}
free((void *) p);
return;
}
static void *set_work_dir(void *existing, size_t min_len)
{
void *vp = realloc(existing, min_len);
if (down_loading)
d_work_dir = vp;
else
u_work_dir = vp;
return vp;
}
/*
* Initialize new file directory.
*
* Sets the current working directory. Non-0 return = no change.
*/
static int new_filedir(GETSDIR_ENTRY *dirdat, int flushit)
{
static size_t dp_len = 0;
static char cwd_str_fmt[BUFSIZ] = "";
size_t new_dp_len, fmt_len;
char disp_dir[80];
int initial_y = (76 - (WHAT_NR_OPTIONS * WHAT_WIDTH >= 76
? 74 : WHAT_NR_OPTIONS * WHAT_WIDTH)) / 2;
size_t i;
char * new_prev_dir;
cur = 0;
ocur = 0;
subm = SUBM_OKAY;
quit = 0;
top = 0;
c = 0;
pgud = 0;
first = 1;
min_len = 1;
dprev = -1;
tag_cnt = 0;
/*
* get last directory
*/
work_dir = down_loading ? d_work_dir : u_work_dir;
/*
* init working directory to default?
*/
if (work_dir == NULL) {
char *s = down_loading? P_DOWNDIR : P_UPDIR;
min_len = 1;
if (*s != '/')
min_len += strlen(homedir) + 1;
min_len += strlen(s);
if (min_len < BUFSIZ)
min_len = BUFSIZ;
work_dir = set_work_dir(NULL, min_len);
if (*s == '/')
strncpy(work_dir, s, min_len);
else
snprintf(work_dir, min_len, "%s/%s", homedir, s);
}
/* lop-off trailing "/" for consistency */
if (strlen(work_dir) > 1 && work_dir[strlen(work_dir) - 1] == '/')
work_dir[strlen(work_dir) - 1] = (char)0;
/* get the current working directory, which will become the prev_dir, on success */
new_prev_dir = getcwd(NULL, BUFSIZ);
if (!new_prev_dir)
return -1;
if (!access(work_dir, R_OK | X_OK) && !chdir(work_dir)) {
/* was able to change to new working directory */
free(prev_dir);
prev_dir = new_prev_dir;
}
else {
/* Could not change to the new working directory */
mc_wbell();
werror(
_("Could not change to directory %s (%s)"),
work_dir,
strerror(errno));
/* restore the previous working directory */
free(work_dir);
work_dir = set_work_dir(new_prev_dir, strlen(new_prev_dir));
}
/* All right, draw the file directory! */
if (flushit) {
dirflush = 0;
mc_winclr(main_w);
mc_wredraw(main_w, 1);
}
mc_wcursor(main_w, CNORMAL);
{
char *s;
if (down_loading) {
if (how_many < 0)
s = _("Select one or more files for download");
else if (how_many)
s = _("Select a file for download");
else
s = _("Select a directory for download");
} else {
if (how_many < 0)
s = _("Select one or more files for upload");
else if (how_many)
s = _("Select a file for upload");
else
s = _("Select a directory for upload");
}
snprintf(file_title, sizeof(file_title), "%s", s);
}
mc_wtitle(main_w, TMID, file_title);
if ((new_dp_len = strlen(work_dir)) > dp_len) {
dp_len = new_dp_len;
snprintf(cwd_str_fmt, sizeof(cwd_str_fmt),
_("Directory: %%-%ds"), (int)dp_len);
}
new_dp_len = mbslen (work_dir);
if (new_dp_len + (fmt_len = mbslen(cwd_str_fmt)) > 75) {
size_t i;
char *tmp_dir = work_dir;
/* We want the last 73 characters */
for (i = 0; 73 + i < new_dp_len + fmt_len; i++) {
wchar_t wc;
tmp_dir += one_mbtowc(&wc, work_dir, MB_LEN_MAX);
}
snprintf(disp_dir, sizeof(disp_dir), "...%s", tmp_dir);
snprintf(cwd_str, sizeof(cwd_str), cwd_str_fmt, disp_dir);
} else
snprintf(cwd_str, sizeof(cwd_str), cwd_str_fmt, work_dir);
mc_wlocate(main_w, 0, 0);
mc_wputs(main_w, cwd_str);
for (i = 0; i < WHAT_NR_OPTIONS; i++) {
const char *str, *c;
size_t j;
str = _(what[i]);
c = str;
for (j = 0; j < WHAT_WIDTH - 1 && *c != 0; j++) {
wchar_t wc;
c += one_mbtowc (&wc, c, MB_LEN_MAX);
}
what_lens[i] = c - str;
j = WHAT_WIDTH - j; /* Characters left for padding */
what_padding[i][1] = j / 2; /* Rounding down */
what_padding[i][0] = j - what_padding[i][1]; /* >= 1 */
}
mc_wlocate(dsub, initial_y, 0);
for (i = 0; i < WHAT_NR_OPTIONS; i++)
horiz_draw(i, mc_wgetattr(dsub), mc_wgetattr(dsub));
mc_wsetregion(main_w, 1, main_w->ys - FILE_MWTR);
main_w->doscroll = 0;
/* old dir to discard? */
free(dirdat);
dirdat = NULL;
/* get sorted directory */
if ((nrents = getsdir(".", wc_str,
GETSDIR_PARNT|GETSDIR_NSORT|GETSDIR_DIRSF,
0, &dirdat, &longest)) < 0) {
/* we really want to announce the error here!!! */
mc_wclose(main_w, 1);
mc_wclose(dsub, 1);
free(dirdat);
dirdat = NULL;
return -1;
}
global_dirdat = dirdat; // Hmm...
prdir(main_w, top, top, dirdat, longest);
mc_wlocate(main_w, initial_y, main_w->ys - FILE_MWTR);
mc_wputs(main_w, _("( Escape to exit, Space to tag )"));
dhili(subm);
/* this really needs to go in dhili !!!*/
mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
if (flushit) {
dirflush = 1;
mc_wredraw(dsub, 1);
}
return 0;
}
/*
* Goto a new directory
*/
static void goto_filedir(char *new_dir, int absolut)
{
if (strcmp(new_dir, "..") == 0) {
if (strcmp(work_dir, "/")) {
char *sp = strrchr(work_dir, '/');
*sp = (char)0;
if (strlen(work_dir) == 0)
strcpy(work_dir, "/");
} else {
file_tell(_("Can't back up!"));
return;
} else if (!absolut) {
int new_len = strlen(work_dir) + 1; /* + '/' */
if ((new_len += strlen(new_dir) + 1) > min_len) {
min_len = new_len;
work_dir = set_work_dir(work_dir, min_len);
}
if (strcmp(work_dir, "/") != 0)
strcat(work_dir, "/");
strcat(work_dir, new_dir);
} else {
int new_len = 1;
if (*new_dir != '/')
new_len += strlen(homedir) + 1;
new_len += strlen(new_dir);
if (min_len < new_len)
min_len = new_len;
work_dir = set_work_dir(work_dir, min_len);
if (*new_dir == '/')
strncpy(work_dir, new_dir, min_len);
else
snprintf(work_dir, min_len, "%s/%s", homedir, new_dir);
}
new_filedir(global_dirdat, 1);
}
/*
* Initialize the file directory.
*/
static int init_filedir(void)
{
int x1, x2;
int retstat = -1;
dirflush = 0;
x1 = (COLS / 2) - 37;
x2 = (COLS / 2) + 37;
dsub = mc_wopen(x1 - 1, LINES - 3, x2 + 1, LINES - 3, BNONE,
stdattr, mfcolor, mbcolor, 0, 0, 1);
main_w = mc_wopen(x1, 2, x2, LINES - 6, BSINGLE, stdattr, mfcolor,
mbcolor, 0, 0, 1);
if (ret_buf != NULL ||
(retstat = ((ret_buf = (char *)malloc(BUFSIZ)) == NULL)? -1 : 0) == 0) {
retstat = new_filedir(NULL, 0);
dirflush = 1;
mc_wredraw(dsub, 1);
}
return retstat;
}
static int tag_untag(char *pat, int tag)
{
GETSDIR_ENTRY *d = global_dirdat;
int indxr, cntr;
if (nrents < 1)
return 0;
for (indxr = nrents, cntr = 0; indxr; --indxr, ++d)
if (S_ISREG(d->mode) && wildmat(d->fname, pat)) {
if (tag) {
d->cflags |= FL_TAG;
++cntr;
} else if (d->cflags & FL_TAG) {
d->cflags &= ~FL_TAG;
++cntr;
}
}
return cntr;
}
/*
* concatenate tagged files into a buffer
*/
static char *concat_list(GETSDIR_ENTRY *dirdat)
{
GETSDIR_ENTRY *d;
int indxr, len;
int i;
char *j;
d = dirdat;
for (indxr = nrents, len = 0; indxr; --indxr, ++d)
if (d->cflags & FL_TAG)
len += strlen(d->fname) + 1;
if (len) {
if (len > BUFSIZ) {
if ((ret_buf = (char *)realloc(ret_buf, len)) == NULL) {
file_tell(_("Too many files tagged - buffer would overflow"));
return NULL;
}
}
*ret_buf = (char)0;
d = dirdat;
for (indxr = nrents; indxr; --indxr, ++d)
if (d->cflags & FL_TAG) {
/* this could be *much* more efficient */
for (i = strlen(ret_buf), j = d->fname; *j; j++) {
if (*j == ' ') {
if ((ret_buf = (char*)realloc(ret_buf, ++len)) == NULL) {
file_tell(_("Too many files tagged - buffer would overflow"));
return(NULL);
}
ret_buf[i++] = '\\';
}
ret_buf[i++] = *j;
}
ret_buf[i++] = ' ';
ret_buf[i] = '\0';
}
ret_buf[strlen(ret_buf) - 1] = (char)0;
return ret_buf;
}
return NULL;
}
/*
* Draw the file directory.
*
* howmany - How many files can be selected
* 0 = none (for directory selection only, as in "rz")
* 1 = one (for single-file up-/down-loads, as in "rx")
* -1 = any number (for multiple files, as in "sz")
*
* downloading - Is this for download selection?
* 0 = no
* 1 = yes - when single file selected, see if it exists
*/
char * filedir(int howmany, int downloading)
{
time_t click_time = (time_t) 0;
size_t i;
how_many = howmany;
down_loading = downloading;
init_filedir();
again:
mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
if (first) {
mc_wredraw(main_w, 1);
first = 0;
}
while (!quit) {
GETSDIR_ENTRY *d = getno(cur, global_dirdat);
/*
if(S_ISDIR(d->mode))
prone(main_w, d, longest, 0);
*/
switch (c = wxgetch()) {
case K_UP:
case 'k':
/*
if(S_ISDIR(d->mode))
prone(main_w, d, longest, 1);
*/
cur -= cur > 0;
break;
case K_DN:
case 'j':
/*
if(S_ISDIR(d->mode))
prone(main_w, d, longest, 1);
*/
cur += cur < nrents - 1;
break;
case K_LT:
case 'h':
subm--;
if (subm < 0)
subm = SUBM_OKAY;
break;
case K_RT:
case 'l':
subm = (subm + 1) % 6;
break;
case K_PGUP:
case '\002': /* Control-B */
pgud = 1;
quit = 1;
break;
case K_PGDN:
case '\006': /* Control-F */
pgud = 2;
quit = 1;
break;
case ' ': /* Tag if not directory */
if (S_ISDIR(d->mode)) {
time_t this_time = time((time_t *)NULL);
if (this_time - click_time < 2) {
GETSDIR_ENTRY *d2 = getno(cur, global_dirdat);
goto_filedir(d2->fname, 0);
click_time = (time_t)0;
} else
click_time = this_time;
}
else {
if (how_many) {
if ((d->cflags ^= FL_TAG) & FL_TAG) {
if (tag_cnt && how_many == 1) {
d->cflags &= ~FL_TAG;
file_tell(_("Can select only one!"));
break;
}
++tag_cnt;
} else
--tag_cnt;
mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
prone(main_w, d, longest, d->cflags & FL_TAG);
mc_wputc(main_w, '\n');
cur += cur < nrents - 1;
}
}
break;
case '\033':
case '\r':
case '\n':
quit = 1;
break;
default:
for (i = 0; i < WHAT_NR_OPTIONS; i++) {
if (strchr (_(what[i]), toupper (c)) != NULL) {
subm = i;
c = '\n';
quit = 1;
break;
}
}
break;
}
if (c != ' ')
click_time = (time_t)0;
if (cur < top) {
top--;
prdir(main_w, top, top, global_dirdat, longest);
}
if (cur - top > main_w->ys - (2 + FILE_MWTR)) {
top++;
prdir(main_w, top, top, global_dirdat, longest);
}
/*
if(cur != ocur)
mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
*/
ocur = cur;
dhili(subm);
/* this really needs to go in dhili !!!*/
mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
}
quit = 0;
/* ESC means quit */
if (c == '\033') {
mc_wclose(main_w, 1);
mc_wclose(dsub, 1);
free(global_dirdat);
global_dirdat = NULL;
return NULL;
}
/* Page up or down ? */
if (pgud == 1) { /* Page up */
ocur = top;
top -= main_w->ys - (1 + FILE_MWTR);
if (top < 0)
top = 0;
cur = top;
pgud = 0;
if (ocur != top)
prdir(main_w, top, cur, global_dirdat, longest);
ocur = cur;
goto again;
}
if (pgud == 2) { /* Page down */
ocur = top;
if (top < nrents - main_w->ys + (1 + FILE_MWTR)) {
top += main_w->ys - (1 + FILE_MWTR);
if (top > nrents - main_w->ys + (1 + FILE_MWTR)) {
top = nrents - main_w->ys + (1 + FILE_MWTR);
}
cur = top;
} else
cur = nrents - 1;
pgud = 0;
if (ocur != top)
prdir(main_w, top, cur, global_dirdat, longest);
ocur = cur;
goto again;
}
if (c =='\r' || c == '\n') {
switch(subm) {
case 0:
/* Goto directory */
{
char buf[128];
char *s;
strncpy(buf, down_loading? P_DOWNDIR : P_UPDIR, sizeof(buf) -1);
s = input(_("Goto directory:"), buf);
/* if(s == NULL || *s == (char) 0) */
if (s == NULL)
break;
goto_filedir(buf, 1);
}
break;
case 1:
/* Previous directory */
goto_filedir(prev_dir, 1);
break;
case 2:
/* File (wildcard) spec */
{
char *s = input(_("Filename pattern:"), wc_mem);
if (s == NULL || *s == (char) 0)
break;
strcpy(wc_str, wc_mem);
new_filedir(global_dirdat, 1);
wc_str[0] = (char)0;
}
break;
case 3:
/* Tag */
if (how_many == 1)
file_tell(_("Can select only one!"));
else if (how_many == -1) {
char tag_buf[128];
char *s;
strncpy(tag_buf, wc_mem, 128);
s = input(_("Tag pattern:"), tag_buf);
if (s != NULL && *s != (char)0) {
int newly_tagged;
if ((newly_tagged = tag_untag(tag_buf, 1)) == 0) {
file_tell(_("No file(s) tagged"));
goto tag_end;
}
tag_cnt += newly_tagged;
prdir(main_w, top, top, global_dirdat, longest);
}
}
tag_end:
break;
case 4:
/* Untag */
{
char tag_buf[128];
char *s;
int untagged;
strncpy(tag_buf, wc_mem, 128);
s = input(_("Untag pattern:"), tag_buf);
if (s == NULL || *s == (char)0)
goto untag_end;
if ((untagged = tag_untag(tag_buf, 0)) == 0) {
file_tell(_("No file(s) untagged"));
goto untag_end;
}
tag_cnt -= untagged;
prdir(main_w, top, top, global_dirdat, longest);
}
untag_end:
break;
case 5:
{
/* Done */
char *ret_ptr = NULL; /* failsafe: assume failure */
if (how_many != 0 && !tag_cnt) {
while (1) {
s = input(_("No file selected - enter filename:"),
ret_buf);
if (s != NULL && *s != (char) 0) {
int f_exist = access(ret_buf, F_OK);
if (down_loading) {
if (f_exist != -1) {
/* ask 'em if they're *sure* */
char buf[BUFSIZ];
snprintf(buf, sizeof(buf),
_("File: \"%s\" exists! Overwrite?"), ret_buf);
if (ask(buf, d_yesno) == 0) {
ret_ptr = ret_buf;
break;
}
} else {
ret_ptr = ret_buf;
break;
}
} else {
if (f_exist == -1)
file_tell(_("no such file!"));
else {
ret_ptr = ret_buf;
break;
}
}
} else {
/* maybe want to ask: "abort?", here */
goto again;
}
}
}
else {
/* put 'em in a buffer for return */
if (how_many == 0) {
/* current working directory */
ret_ptr = work_dir;
} else {
ret_ptr = concat_list(global_dirdat);
}
}
mc_wclose(main_w, 1);
mc_wclose(dsub, 1);
free(global_dirdat);
global_dirdat = NULL;
return ret_ptr;
}
break;
default:
/* should "beep", I guess (? shouldn't get here) */
file_tell("BEEP!");
break;
} /* switch */
}
goto again;
}