-
Notifications
You must be signed in to change notification settings - Fork 7
/
we_fl_unix.c
3979 lines (3537 loc) · 103 KB
/
we_fl_unix.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
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
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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* we_fl_unix.c */
/* Copyright (C) 1993 Fred Kruse */
/* This is free software; you can redistribute it and/or */
/* modify it under the terms of the */
/* GNU General Public License, see the file COPYING. */
#include "messages.h"
#include "edit.h"
#ifdef UNIX
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
struct dirfile *e_make_win_list(FENSTER * f);
extern char *e_tmp_dir;
#ifdef NOSYMLINKS
#define readlink(x, y, z) -1
#define WpeRenameLink(x, y, z, f) 0
#define WpeLinkFile(x, y, sw, f) link(x, y)
#define lstat(x,y) stat(x,y)
#undef S_ISLNK
#define S_ISLNK(x) 0
#else
#include <unistd.h>
#endif
#define WPE_PATHMAX 2048
/* buffer size for copying */
#define E_C_BUFFERSIZE 524288 /* 1/2 Mega Byte */
#ifdef DEBUG
int SpecialError(char *text, int sw, FARBE *f, char *file, int line)
{
fprintf(stderr, "\nFile \"%s\" line %d\n", file, line);
return e_error(text, sw, f);
}
#define e_error(text, sw, f) SpecialError(text, sw, f, __FILE__, __LINE__)
#endif
/* setup the file-manager structures
'dirct' or the current dir. is used to
search for directories and files */
/* sw | file manager type
------------------------
0 | open/new file
1 | read block of text from file
2 | write block of text to file
3 | execute file
4 | save as
5 | add file to project
6 | wastebasket
*/
int WpeCreateFileManager(int sw, ECNT *cn, char *dirct)
{
extern char *e_hlp_str[];
extern WOPT *fblst, *rblst, *wblst, *xblst, *sblst, *ablst;
FENSTER *f;
int i, j;
FLBFFR *b;
int allocate_size; /* inital memory size for allocation */
char *sfile;
/* check whether we reached the maximum number of windows */
if(cn->mxedt >= MAXEDT)
{
e_error(e_msg[ERR_MAXWINS], 0, cn->fb);
return(-1);
}
/* search for a not used window ID number (j) */
for(j = 1; j <= MAXEDT; j++)
{
for(i = 1; i <= cn->mxedt && cn->edt[i] != j; i++)
;
if(i > cn->mxedt)
break;
}
/* change the shape of the mouse :-) */
WpeMouseChangeShape(WpeWorkingShape);
/* currently active window,
one more window in the system,
its number is j */
cn->curedt = j;
(cn->mxedt)++;
cn->edt[cn->mxedt] = j;
/* allocate window structure */
if((f = (FENSTER *)MALLOC(sizeof(FENSTER))) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
/* allocate buffer related to the window (NOT proper type, later casted) */
if((b = (FLBFFR *) MALLOC(sizeof(FLBFFR))) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
f->fb = cn->fb;
cn->f[cn->mxedt] = f; /* store the window structure at appropriate place */
f->a = e_set_pnt(11, 2); /* beginning of the box */
f->e = e_set_pnt(f->a.x + 55, f->a.y + 20); /* other coord. of the box */
f->winnum = cn->curedt;
f->dtmd = DTMD_FILEMANAGER;
f->ins = 1;
f->save = 0;
f->zoom = 0;
f->ed = cn;
f->c_sw = NULL;
f->c_st = NULL;
f->pic = NULL;
if(sw == 6)
{
sw = 0;
f->datnam = "Wastebasket";
f->save = 1;
}
else
f->datnam = "File-Manager"; /* window header text */
/* status line text for different mode */
if(sw == 0)
{
f->blst = fblst;
f->nblst = 8;
}
else if(sw == 1)
{
f->blst = rblst;
f->nblst = 4;
}
else if(sw == 2)
{
f->blst = wblst;
f->nblst = 4;
}
else if(sw == 3)
{
f->blst = xblst;
f->nblst = 4;
}
else if(sw == 4)
{
f->blst = sblst;
f->nblst = 5;
}
else if(sw == 5)
{
f->blst = ablst;
f->nblst = 4;
}
if(sw == 3)
f->hlp_str = e_hlp_str[5];
else
f->hlp_str = e_hlp_str[4];
if(!dirct || dirct[0] == '\0')
{
/* no working directory has been given */
f->dirct = WpeGetCurrentDir(cn);
}
else
{
/* working directory is given, copy it over */
allocate_size = strlen(dirct);
if((f->dirct = MALLOC(allocate_size+1)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
strcpy(f->dirct, dirct);
}
strcpy(f->fd.search, "");
strcpy(f->fd.replace, "");
strcpy(f->fd.file, SUDIR);
f->fd.dirct = WpeStrdup(f->dirct);
f->fd.sw = 16;
f->fd.sn = 0;
f->fd.rn = 0;
f->b = (BUFFER *)b;
/* the find pattern can only be 79 see FIND structure */
if((b->rdfile = MALLOC(80)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
strcpy(b->rdfile, f->fd.file); /* find file pattern */
b->sw = sw;
/* window for files */
if((b->fw = (FLWND *) MALLOC(sizeof(FLWND))) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
/* window for directory */
if((b->dw = (FLWND *) MALLOC(sizeof(FLWND))) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
if((sfile = MALLOC(strlen(f->dirct)+strlen(b->rdfile)+2)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
/* determine current directory */
b->cd = WpeCreateWorkingDirTree(f->save, cn);
/* it is necessary to do this, because the file manager may not be
in the appropriate directory here */
sprintf(sfile, "%s/%s", f->dirct, SUDIR);
/* find all other directories in the current */
b->dd = e_find_dir(sfile, f->ed->flopt & FM_SHOW_HIDDEN_DIRS ? 1 : 0);
/* setup the drawing in the dir tree window */
b->dw->df = WpeGraphicalDirTree(b->cd, b->dd, cn);
i = f->ed->flopt & FM_SHOW_HIDDEN_FILES ? 1 : 0;
if(sw == 3)
i |= 2;
/* finds all files matching the pattern */
sprintf(sfile, "%s/%s", f->dirct, b->rdfile);
b->df = e_find_files(sfile, i);
FREE(sfile);
/* setup the drawing in the file list window */
b->fw->df = WpeGraphicalFileList(b->df, f->ed->flopt >> 9, cn);
/* file box - geometry and vertical slider settings */
b->fw->mxa = f->a.x;
b->fw->mxe = f->e.x;
b->fw->mya = f->a.y;
b->fw->mye = f->e.y;
b->fw->xa = f->e.x - 33;
b->fw->xe = f->e.x - 17;
b->fw->ya = f->a.y + 6;
b->fw->ye = f->a.y + 17;
b->fw->f = f;
b->fw->ia = b->fw->nf = b->fw->nxfo = b->fw->nyfo = 0;
b->fw->srcha = b->fw->ja = 12;
/* directory box - geometry and vertical slider settings */
b->dw->mxa = f->a.x;
b->dw->mxe = f->e.x;
b->dw->mya = f->a.y;
b->dw->mye = f->e.y;
b->dw->xa = f->a.x + 3;
b->dw->xe = f->a.x + 28;
b->dw->ya = f->a.y + 6;
b->dw->ye = f->a.y + 17;
b->dw->f = f;
b->dw->ia = b->dw->ja = b->dw->nxfo = 0;
b->dw->srcha = -1;
b->dw->nf = b->dw->nyfo = b->cd->anz - 1;
if(cn->mxedt > 1)
e_ed_rahmen(cn->f[cn->mxedt - 1], 0);
e_firstl(f, 1);
/* basically it draws the window out */
WpeDrawFileManager(f);
/* restore the shape of the mouse */
WpeMouseRestoreShape();
return(0);
}
/* drawing out the file-manager,
first buttons, than the dir tree and file list */
int WpeDrawFileManager(FENSTER * f)
{
FLBFFR *b = (FLBFFR *)f->b;
int i, j;
int bx1 = 1, bx2 = 1, bx3 = 1, by = 4;
for(j = f->a.y + 1; j < f->e.y; j++)
for(i = f->a.x + 1; i < f->e.x; i++)
e_pr_char(i, j, ' ', f->fb->nt.fb);
if(NUM_LINES_ON_SCREEN <= 17)
by = -1;
else if(b->sw != 0 || NUM_LINES_ON_SCREEN <= 19)
by = 2;
if(NUM_LINES_ON_SCREEN > 17)
{
e_pr_str((f->a.x + 4), f->e.y - by, "Cancel", f->fb->nz.fb, -1, -1,
f->fb->ns.fb, f->fb->nt.fb);
e_pr_str((f->a.x + 14), f->e.y - by, "Change Dir", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
if(b->sw == 1 && NUM_COLS_ON_SCREEN >= 34)
e_pr_str((f->a.x + 28), f->e.y - by, "Read", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
else if(b->sw == 2 && NUM_COLS_ON_SCREEN >= 35)
e_pr_str((f->a.x + 28), f->e.y - by, "Write", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
else if(b->sw == 4)
{
if(NUM_COLS_ON_SCREEN >= 34)
e_pr_str((f->a.x + 28), f->e.y - by, "Save", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
}
else if(b->sw == 3 && NUM_COLS_ON_SCREEN >= 37)
e_pr_str((f->a.x + 28), f->e.y - by, "Execute", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
else if(b->sw == 5 && NUM_COLS_ON_SCREEN >= 33)
e_pr_str((f->a.x + 28), f->e.y - by, "Add", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
else if(b->sw == 0)
{
if(NUM_COLS_ON_SCREEN >= 35)
e_pr_str((f->a.x + 28), f->e.y - by, "MKdir", f->fb->nz.fb, 1, -1,
f->fb->ns.fb, f->fb->nt.fb);
if(NUM_COLS_ON_SCREEN >= 49)
e_pr_str((f->a.x + 37), f->e.y - by, "Attributes", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
}
}
if(b->sw == 0 && NUM_LINES_ON_SCREEN > 19)
{
e_pr_str((f->a.x + 4), f->e.y - 2, "Move", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
if(NUM_COLS_ON_SCREEN >= 21)
e_pr_str((f->a.x + 13), f->e.y - 2, "Remove", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
if(NUM_COLS_ON_SCREEN >= 30)
e_pr_str((f->a.x + 24), f->e.y - 2, "Link", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
if(NUM_COLS_ON_SCREEN >= 39)
e_pr_str((f->a.x + 33), f->e.y - 2, "COpy", f->fb->nz.fb, 1, -1,
f->fb->ns.fb, f->fb->nt.fb);
if(NUM_COLS_ON_SCREEN >= 48)
e_pr_str((f->a.x + 42), f->e.y - 2, "Edit", f->fb->nz.fb, 0, -1,
f->fb->ns.fb, f->fb->nt.fb);
}
if(NUM_COLS_ON_SCREEN < 45)
bx3 = 0;
if(NUM_COLS_ON_SCREEN < 44)
bx2 = 0;
if(NUM_COLS_ON_SCREEN < 43)
bx1 = 0;
b->xfd = (NUM_COLS_ON_SCREEN - bx1 - bx2 - bx3 - 6) / 2;
b->xdd = NUM_COLS_ON_SCREEN - bx1 - bx2 - bx3 - b->xfd - 6;
b->xda = 2 + bx1;
b->xfa = 4 + bx1 + bx2 + b->xdd;
e_pr_str((f->a.x + b->xfa), f->a.y + 2, "Name:", f->fb->nt.fb, 0, 1,
f->fb->nsnt.fb, f->fb->nt.fb);
/* e_schr_nchar(b->rdfile, f->a.x+b->xfa, f->a.y+3, 0, b->xfd+1, f->fb->fr.fb); */
e_schr_nchar_wsv(b->rdfile, f->a.x + b->xfa, f->a.y + 3, 0, b->xfd + 1,
f->fb->fr.fb, f->fb->fz.fb);
e_pr_str((f->a.x + b->xfa), f->a.y + 5, "Files:", f->fb->nt.fb, 0, 1,
f->fb->nsnt.fb, f->fb->nt.fb);
e_pr_str((f->a.x + b->xda), f->a.y + 2, "Directory:", f->fb->nt.fb, 0, 1,
f->fb->nsnt.fb, f->fb->nt.fb);
/* e_schr_nchar(f->dirct, f->a.x+b->xda, f->a.y+3, 0, b->xdd+1, f->fb->fr.fb); */
e_schr_nchar_wsv(f->dirct, f->a.x + b->xda, f->a.y + 3, 0, b->xdd + 1,
f->fb->fr.fb, f->fb->fz.fb);
e_pr_str((f->a.x + b->xda), f->a.y + 5, "DirTree:", f->fb->nt.fb, 3, 1,
f->fb->nsnt.fb, f->fb->nt.fb);
b->fw->mxa = f->a.x;
b->fw->mxe = f->e.x;
b->fw->mya = f->a.y;
b->fw->mye = f->e.y;
b->fw->xa = f->a.x + b->xfa;
b->fw->xe = b->fw->xa + b->xfd;
b->fw->ya = f->a.y + 6;
b->fw->ye = f->e.y - 2 - by;
b->dw->mxa = f->a.x;
b->dw->mxe = f->e.x;
b->dw->mya = f->a.y;
b->dw->mye = f->e.y;
b->dw->xa = f->a.x + b->xda;
b->dw->xe = b->dw->xa + b->xdd;
b->dw->ya = f->a.y + 6;
b->dw->ye = f->e.y - 2 - by;
/* slider bars for file list */
e_mouse_bar(b->fw->xe, b->fw->ya, b->fw->ye - b->fw->ya, 0, b->fw->f->fb->em.fb);
e_mouse_bar(b->fw->xa, b->fw->ye, b->fw->xe - b->fw->xa, 1, b->fw->f->fb->em.fb);
/* file list window */
e_pr_file_window(b->fw, 0, 1, f->fb->ft.fb, f->fb->fz.fb, f->fb->frft.fb);
/* slide bars for directory window */
e_mouse_bar(b->dw->xe, b->dw->ya, b->dw->ye - b->dw->ya, 0, b->dw->f->fb->em.fb);
e_mouse_bar(b->dw->xa, b->dw->ye, b->dw->xe - b->dw->xa, 1, b->dw->f->fb->em.fb);
/* directory window */
e_pr_file_window(b->dw, 0, 1, f->fb->ft.fb, f->fb->fz.fb, f->fb->frft.fb);
return(0);
}
/* tries to find the required style file manager */
int WpeCallFileManager(int sw, FENSTER * f)
{
int i, ret;
FLBFFR *b;
for(i = f->ed->mxedt; i > 0; i--)
if(f->ed->f[i]->dtmd == DTMD_FILEMANAGER) /* check only file manager windows */
{
b = (FLBFFR *)f->ed->f[i]->b;
/* open/new file manager and it is not in save mode */
if(sw == 0 && b->sw == sw && f->ed->f[i]->save != 1)
break;
/* wastebasket mode required,
the window is "open/new" file manager and save mode turned on */
else if(sw == 6 && b->sw == 0 && f->ed->f[i]->save == 1)
break;
/* not open/new or wastebasket filemanager and it is the required style */
else if(sw != 0 && sw != 6 && b->sw == sw)
break;
}
if(i <= 0) /* we did not find the required style file-manager */
{
if(sw == 6) /* wastebasket mode */
{
char *tmp;
if ((tmp = WpeGetWastefile("")))
{
ret = WpeCreateFileManager(sw, f->ed, tmp);
FREE(tmp);
return(ret);
}
else
{
e_error(e_msg[ERR_NOWASTE], 0, f->ed->fb);
return 0; /* Error -- no wastebasket */
}
}
/* create the required style file manager */
return(WpeCreateFileManager(sw, f->ed, ""));
}
/* switch to the found file manager */
e_switch_window(f->ed->edt[i], f);
return(0);
}
/* It will always create a new file manager */
int WpeManagerFirst(FENSTER * f)
{
return(WpeCreateFileManager(0, f->ed, ""));
}
/* try to find an "open/new" style file manager or create one */
int WpeManager(FENSTER * f)
{
return(WpeCallFileManager(0, f));
}
/* try to find an "execute" style file manager or create one */
int WpeExecuteManager(FENSTER * f)
{
return(WpeCallFileManager(3, f));
}
/* try to find a "save as" style file manager or create one */
int WpeSaveAsManager(FENSTER * f)
{
return(WpeCreateFileManager(4, f->ed, ""));
}
/* File Manager Handler */
int WpeHandleFileManager(ECNT * cn)
{
FENSTER *f = cn->f[cn->mxedt], *fe = NULL;
FLBFFR *b = (FLBFFR *) f->b;
BUFFER *be = NULL;
SCHIRM *se = NULL;
int c = AltC, i, j, t;
int winnum = 0, nco, svmode = -1, fmode, len, start;
int g[4], cold = AltN;
char filen[128], *ftmp, *dtp = NULL, *ftp = NULL, *svdir = NULL;
char *dirtmp = NULL;
PIC *outp = NULL;
FILE *fp;
struct stat buf;
char dtmd;
/* check whether we really get a file-manager window here */
if(f->dtmd != DTMD_FILEMANAGER)
return(0);
if(f->save == 1)
{
svmode = f->ed->flopt;
f->ed->flopt = FM_SHOW_HIDDEN_FILES | FM_SHOW_HIDDEN_DIRS |
FM_MOVE_OVERWRITE | FM_REKURSIVE_ACTIONS;
}
/* if it is project management or saving mode
save the current directory to return to it */
if(f->save == 1 || b->sw == 5)
{
if((svdir = MALLOC(strlen(f->ed->dirct) + 1)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
strcpy(svdir, f->ed->dirct);
}
nco = b->cd->anz - 1;
/* when searching among files, search hidden ones as well */
fmode = f->ed->flopt & FM_SHOW_HIDDEN_FILES ? 1 : 0;
/* in execution mode show hidden dirs as well */
if(b->sw == 3)
fmode |= 2;
/* searching for the last edited/touched file on the desktop */
for(i = cn->mxedt; i > 0; i--)
{
if (DTMD_ISTEXT(cn->f[i]->dtmd))
{
fe = cn->f[i];
be = fe->b;
se = fe->s;
winnum = cn->edt[i];
break;
}
}
strcpy(f->fd.file, b->rdfile);
/* go until quit */
while(c != WPE_ESC)
{
/* draw out dir tree and file list windows */
e_pr_file_window(b->fw, 0, 1, f->fb->ft.fb, f->fb->fz.fb, f->fb->frft.fb);
e_pr_file_window(b->dw, 0, 1, f->fb->ft.fb, f->fb->fz.fb, f->fb->frft.fb);
switch(c)
{
/* filename entry box activation */
case AltN:
cold = c;
fk_cursor(1);
/* get some answer from the name entry box,
result file copied into b->rdfile, max 79 char + '\0' */
c = e_schr_lst_wsv(b->rdfile, f->a.x + b->xfa, f->a.y + 3, b->xfd + 1, 79,
f->fb->fr.fb, f->fb->fz.fb, &f->ed->fdf, f);
/* determine the entered filename, going backward */
for(i = strlen(b->rdfile); i >= 0 && b->rdfile[i] != DIRC; i--)
;
strcpy(f->fd.file, b->rdfile + 1 + i);
/* there is some directory structure in the filename */
if(i >= 0)
{
if(i == 0)
i++;
b->rdfile[i] = '\0';
/* change the working directory */
FREE(f->dirct);
if((f->dirct = MALLOC(strlen(b->rdfile) + 1)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
strcpy(f->dirct, b->rdfile);
/* restore original filename */
strcpy(b->rdfile, f->fd.file);
c = AltC;
}
#if MOUSE
/* if mouse was used (the reason it returned) get appropriate key interpretation */
if(c == -1)
c = WpeMngMouseInFileManager(f);
#endif
if((c >= Alt1 && c <= Alt9) || (c >= 1024 && c <= 1049))
{
/* window changing, make the entry unhighlighted */
e_schr_nchar_wsv(b->rdfile, f->a.x + b->xfa, f->a.y + 3, 0, b->xfd + 1,
f->fb->fr.fb, f->fb->fz.fb);
break;
}
if(c == CLE || c == CCLE) /* goto dir name window */
c = AltD;
else if(c == CDO || c == BDO || c == WPE_TAB) /* goto file list window */
c = AltF;
else if(c == WPE_BTAB) /* goto dir tree window */
c = AltT;
else if( ( c == WPE_CR
|| (b->sw == 0 && c == AltE)
|| (b->sw == 1 && c == AltR)
|| (b->sw == 2 && c == AltW)
|| (b->sw == 3 && c == AltE)
|| (b->sw == 5 && c == AltA)
|| (b->sw == 4 && (c == AltS || c == AltY)) )
&& ( strstr(b->rdfile, "*")
|| strstr(b->rdfile, "?")
|| strstr(b->rdfile, "[") ) )
{
WpeMouseChangeShape(WpeWorkingShape);
/* free up existing structures */
freedf(b->df);
freedf(b->fw->df);
/* find files according to the new pattern */
b->df = e_find_files(b->rdfile, fmode);
/* setup the drawing in the dir tree window */
b->fw->df = WpeGraphicalFileList(b->df, f->ed->flopt >> 9, cn);
b->fw->ia = b->fw->nf = 0;
b->fw->ja = b->fw->srcha;
/* jump to file list window */
c = AltF;
WpeMouseRestoreShape();
}
else
{
strcpy(filen, b->rdfile); /* !!! alloc for filen ??? */
if(c == WPE_CR)
{
if(b->sw == 1)
c = AltR;
else if(b->sw == 2)
c = AltW;
else if(b->sw == 4)
c = AltS;
else if(b->sw == 5)
c = AltA;
else
c = AltE;
}
}
/* entry window is left, make the entry unhighlighted */
if(c != AltN)
e_schr_nchar_wsv(b->rdfile, f->a.x + b->xfa, f->a.y + 3, 0, b->xfd + 1,
f->fb->fr.fb, f->fb->fz.fb);
fk_cursor(0);
break;
/* directory name entry box activation */
case AltD:
cold = c;
fk_cursor(1);
/* get the directory name */
if ((dirtmp = WpeMalloc(WPE_PATHMAX)) == NULL) /* dirct mat not have enough memory */
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
if (strlen(f->dirct) >= WPE_PATHMAX)
{
strncpy(dirtmp, f->dirct, WPE_PATHMAX - 1);
dirtmp[WPE_PATHMAX - 1] = '\0';
}
else
strcpy(dirtmp, f->dirct);
c = e_schr_lst_wsv(dirtmp, f->a.x + b->xda, f->a.y + 3, b->xdd + 1, WPE_PATHMAX,
f->fb->fr.fb, f->fb->fz.fb, &f->ed->ddf, f);
FREE(f->dirct);
f->dirct = WpeStrdup(dirtmp);
WpeFree(dirtmp);
#if MOUSE
if(c == -1)
c = WpeMngMouseInFileManager(f);
#endif
if(c == CRI || c == CCRI) /* goto name entry windwow */
c = AltN;
else if(c == CDO || c == BDO || c == WPE_TAB) /* goto dir tree window */
c = AltT;
else if(c == WPE_BTAB) /* goto file list window */
c = AltF;
else if(c == WPE_CR) /* change dir */
c = AltC;
/* window left, make the entry unhighlighted */
if(c != AltD)
e_schr_nchar_wsv(f->dirct, f->a.x + b->xda, f->a.y + 3, 0, b->xdd + 1,
f->fb->fr.fb, f->fb->fz.fb);
fk_cursor(0);
break;
/* directory tree list window activation */
case AltT:
cold = c;
c = e_file_window(1, b->dw, f->fb->ft.fb, f->fb->fz.fb);
#if MOUSE
if(c == MBKEY) /* handle mouse actions in the window */
c = WpeMngMouseInFileManager(f);
else if(c < 0)
c = WpeMouseInFileDirList(c, 1, f);
#endif
if(c == CCRI)
c = AltF;
else if(c == BUP)
c = AltD;
else if(c == WPE_TAB)
c = AltN;
else if(c == WPE_BTAB)
c = AltD;
else if(c == AltC || (c == WPE_CR && b->dw->nf != nco))
{
if ((dirtmp = WpeAssemblePath(f->dirct, b->cd, b->dd, b->dw->nf, f)))
{
FREE(f->dirct);
f->dirct = dirtmp;
e_schr_nchar_wsv(f->dirct, f->a.x + b->xda, f->a.y + 3, 0, b->xdd + 1,
f->fb->fr.fb, f->fb->fz.fb);
f->ed->ddf = e_add_df(f->dirct, f->ed->ddf);
c = AltC;
}
/* there is only one case when it cannot assemble the path,
that it cannot access wastebasket, then quit the file manager */
else
c = WPE_ESC;
}
else if(c == WPE_CR)
c = AltT;
break;
/* file list window activation */
case AltF:
if(b->df->anz < 1)
{
c = cold;
break;
}
cold = c;
c = e_file_window(1, b->fw, f->fb->ft.fb, f->fb->fz.fb);
#if MOUSE
if(c == MBKEY)
c = WpeMngMouseInFileManager(f);
else if(c < 0)
c = WpeMouseInFileDirList(c, 0, f);
#endif
if(c == BUP) /* goto file name entry window */
c = AltN;
else if(c == CCLE) /* goto dir tree window */
c = AltT;
else if(c == WPE_TAB) /* goto dir entry window */
c = AltD;
else if(c == WPE_BTAB) /* goto file name entry window */
c = AltN;
else if(c == WPE_CR) /* action selected */
{
if(b->sw == 1)
c = AltR;
else if(b->sw == 2)
c = AltW;
else if(b->sw == 4)
c = AltS;
else if(b->sw == 5)
c = AltA;
else
c = AltE;
}
if( (b->sw == 1 && c == AltR) /* in case of action store the filename */
|| (b->sw == 2 && c == AltW)
|| (b->sw == 3 && c == AltE)
|| (b->sw == 0 && c == AltE)
|| (b->sw == 4 && (c == AltS || c == AltY)) )
{
strcpy(filen, *(b->df->name + b->fw->nf)); /* !!! alloc for filen ??? */
}
break;
/* change dir button activation */
case AltC:
c = cold;
/* if the current dir is equal to the "newly" entered dir, break */
if(!strcmp(f->ed->dirct, f->dirct))
break;
/* in wastebasket mode, we do not allow to go out of it through
a soft link */
if((b->sw == 0) && (f->save == 1))
{
if(lstat(f->dirct, &buf))
{
e_error(e_msg[ERR_ACCFILE], 0, f->ed->fb);
break;
}
if(S_ISLNK(buf.st_mode))
{
/* cannot go out through a softlink, restore dir name */
if((f->dirct = REALLOC(f->dirct, strlen(f->ed->dirct) + 1)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, f->fb);
else
strcpy(f->dirct, f->ed->dirct);
break;
}
}
/* change to the desired dir with system error checking */
if(chdir(f->dirct))
{
e_error(e_msg[ERR_WORKDIRACCESS], 0, f->fb);
/* we cannot determine where we are, try the home */
if((dirtmp = getenv("HOME")) == NULL)
e_error(e_msg[ERR_HOMEDIRACCESS], 1, cn->fb);
if(chdir(dirtmp))
e_error(e_msg[ERR_HOMEDIRACCESS], 1, cn->fb);
}
/* get current directory */
dirtmp = WpeGetCurrentDir(f->ed);
/* change the shape of the mouse */
WpeMouseChangeShape(WpeWorkingShape);
FREE(f->dirct);
f->dirct = dirtmp;
/* free up all relevant structures */
freedf(b->df);
freedf(b->fw->df);
freedf(b->cd);
freedf(b->dw->df);
freedf(b->dd);
/* reset the current dir path in the control structure */
if((f->ed->dirct = REALLOC(f->ed->dirct, strlen(f->dirct) + 1)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, f->fb);
else
strcpy(f->ed->dirct, f->dirct);
/* setup current directory structure */
b->cd = WpeCreateWorkingDirTree(f->save, cn);
/* find all other directories in the current dir */
b->dd = e_find_dir(SUDIR, f->ed->flopt & FM_SHOW_HIDDEN_DIRS ? 1 : 0);
/* setup the drawing in the dir tree window */
b->dw->df = WpeGraphicalDirTree(b->cd, b->dd, cn);
nco = b->dw->nf = b->cd->anz - 1;
b->dw->ia = b->dw->ja = 0;
/* finds all files matching the pattern */
b->df = e_find_files(b->rdfile, fmode);
/* setup the drawing in the file list window */
b->fw->df = WpeGraphicalFileList(b->df, f->ed->flopt >> 9, cn);
b->fw->nf = b->fw->ia = 0;
b->fw->ja = 12;
/* change the shape of the mouse back */
WpeMouseRestoreShape();
break;
/* link file activation */
case AltL:
/* copy file activation */
case AltO:
/* move file activation */
case AltM:
/* moving/copying a file is valid only in mode 0 (open/new file) */
if(b->sw != 0)
{
c = cold;
break;
}
j = c;
/* we are coming from files */
if(cold == AltF)
{
if((ftmp = MALLOC(129)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
if(strlen(*(b->df->name + b->fw->nf)) > 128)
{
strncpy(ftmp, *(b->df->name + b->fw->nf), 128);
ftmp[128] = '\0';
}
else
strcpy(ftmp, *(b->df->name + b->fw->nf));
/* make the file name editable */
c = e_schreib_leiste(ftmp, b->fw->xa, b->fw->ya + b->fw->nf - b->fw->ia,
b->fw->xe - b->fw->xa, 128, f->fb->fr.fb, f->fb->fz.fb);
if(c == WPE_CR)
{
if(j == AltM)
e_rename(*(b->df->name + b->fw->nf), ftmp, f); /* move */
else if(j == AltL)
WpeLinkFile(*(b->df->name + b->fw->nf), ftmp, /* link */
f->ed->flopt & FM_TRY_HARDLINK, f);
else if(j == AltO)
e_copy(*(b->df->name + b->fw->nf), ftmp, f); /* copy */
/* after copying/moving/linking, free up the old structures */
freedf(b->df);
freedf(b->fw->df);
/* generate the new file list */
b->df = e_find_files(b->rdfile, fmode);
/* setup the drawing of it */
b->fw->df = WpeGraphicalFileList(b->df, f->ed->flopt >> 9, cn);
b->fw->ia = b->fw->nf = 0;
b->fw->ja = b->fw->srcha;
}
FREE(ftmp);
}
/* we are coming from dirs */
else if(cold == AltT && b->dw->nf >= b->cd->anz)
{
if((ftmp = MALLOC(129)) == NULL)
e_error(e_msg[ERR_LOWMEM], 1, cn->fb);
/* selected dir */
t = b->dw->nf - b->cd->anz;
if(strlen(*(b->dd->name + t)) > 128)
{
strncpy(ftmp, *(b->dd->name + t), 128);
ftmp[128] = '\0';
}
else
strcpy(ftmp, *(b->dd->name + t));
/* separate the dir name from other drawings in the line */
for(i = 0; *(b->dw->df->name[b->dw->nf] + i) &&
(*(b->dw->df->name[b->dw->nf] + i) <= 32 ||
*(b->dw->df->name[b->dw->nf] + i) >= 127); i++)
;
if(!WpeIsXwin())
i += 3;
b->dw->ja = i;
e_pr_file_window(b->dw, 0, 1, f->fb->ft.fb, f->fb->fz.fb, f->fb->frft.fb);
/* make the name editable */
c = e_schreib_leiste(ftmp, b->dw->xa, b->dw->ya + b->dw->nf - b->dw->ia,
b->dw->xe - b->dw->xa, 128, f->fb->fr.fb, f->fb->fz.fb);
if(c == WPE_CR)
{
if(j == AltM)
e_rename(*(b->dd->name + t), ftmp, f); /* move */
else if(j == AltL)
e_link(*(b->dd->name + t), ftmp, f); /* link */
else if(j == AltO)
e_copy(*(b->dd->name + t), ftmp, f); /* copy */
/* free up structures */
freedf(b->cd);
freedf(b->dw->df);
freedf(b->dd);
/* determine current directory */
b->cd = WpeCreateWorkingDirTree(f->save, cn);
/* find all other directories in the current */
b->dd = e_find_dir(SUDIR, f->ed->flopt & FM_SHOW_HIDDEN_DIRS ? 1 : 0);
/* setup drawing */
b->dw->df = WpeGraphicalDirTree(b->cd, b->dd, cn);
nco = b->dw->nf = b->cd->anz - 1;
b->dw->ia = b->dw->ja = 0;
}
FREE(ftmp);
}
c = cold;
cold = AltN; /* go back to name entry */
break;
/* remove button activation */
case ENTF:
if(b->sw != 0)
{
c = cold;
break;
}
/* remove button activation */
case AltR:
if(b->sw == 0)
{
/* coming from file list */
if(cold == AltF)
{
WpeRemove(*(b->df->name + b->fw->nf), f); /* remove the file */
/* free up structures */
freedf(b->df);
freedf(b->fw->df);
/* find files according to the pattern */
b->df = e_find_files(b->rdfile, fmode);
/* setup drawing */
b->fw->df = WpeGraphicalFileList(b->df, f->ed->flopt >> 9, cn);
b->fw->ia = b->fw->nf = 0;
b->fw->ja = b->fw->srcha;
}
/* coming from the dir tree list and the selected dir is a subdir of
the current directory */
else if(cold == AltT && b->dw->nf >= b->cd->anz)
{
t = b->dw->nf - b->cd->anz;
WpeRemove(*(b->dd->name + t), f); /* remove the dir */
/* free up structures */
freedf(b->cd);
freedf(b->dw->df);
freedf(b->dd);
/* determine current directory */