forked from MidnightCommander/mc
/
panel.c
5176 lines (4237 loc) · 139 KB
/
panel.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
/*
Panel managing.
Copyright (C) 1994-2016
Free Software Foundation, Inc.
Written by:
Miguel de Icaza, 1995
Timur Bakeyev, 1997, 1999
Slava Zanko <slavazanko@gmail.com>, 2013
Andrew Borodin <aborodin@vmail.ru>, 2013-2016
This file is part of the Midnight Commander.
The Midnight Commander 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 3 of the License,
or (at your option) any later version.
The Midnight Commander 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file panel.c
* \brief Source: panel managin module
*/
#include <config.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib/global.h"
#include "lib/tty/tty.h"
#include "lib/tty/key.h" /* XCTRL and ALT macros */
#include "lib/skin.h"
#include "lib/strescape.h"
#include "lib/mcconfig.h"
#include "lib/vfs/vfs.h"
#include "lib/unixcompat.h"
#include "lib/search.h"
#include "lib/timefmt.h" /* file_date() */
#include "lib/util.h"
#include "lib/widget.h"
#ifdef HAVE_CHARSET
#include "lib/charsets.h" /* get_codepage_id () */
#endif
#include "lib/event.h"
#include "lib/scripting.h" /* scripting_trigger_widget_event() */
#include "src/setup.h" /* For loading/saving panel options */
#include "src/execute.h"
#ifdef HAVE_CHARSET
#include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
#endif
#include "src/keybind-defaults.h" /* global_keymap_t */
#ifdef ENABLE_SUBSHELL
#include "src/subshell/subshell.h" /* do_subshell_chdir() */
#endif
#include "dir.h"
#include "boxes.h"
#include "tree.h"
#include "ext.h" /* regexp_command */
#include "layout.h" /* Most layout variables are here */
#include "cmd.h"
#include "command.h" /* cmdline */
#include "usermenu.h"
#include "midnight.h"
#include "mountlist.h" /* my_statfs */
#include "panel.h"
#ifdef ENABLE_LUA
#include "src/lua/modules/fields.h" /* mc_lua_set_current_field() */
#endif
/*** global variables ****************************************************************************/
/* The hook list for the select file function */
hook_t *select_file_hook = NULL;
/* *INDENT-OFF* */
panelized_panel_t panelized_panel = { {NULL, 0, -1}, NULL };
/* *INDENT-ON* */
static const char *string_file_name (file_entry_t *, int);
static const char *string_file_size (file_entry_t *, int);
static const char *string_file_size_brief (file_entry_t *, int);
static const char *string_file_type (file_entry_t *, int);
static const char *string_file_mtime (file_entry_t *, int);
static const char *string_file_atime (file_entry_t *, int);
static const char *string_file_ctime (file_entry_t *, int);
static const char *string_file_permission (file_entry_t *, int);
static const char *string_file_perm_octal (file_entry_t *, int);
static const char *string_file_nlinks (file_entry_t *, int);
static const char *string_inode (file_entry_t *, int);
static const char *string_file_nuid (file_entry_t *, int);
static const char *string_file_ngid (file_entry_t *, int);
static const char *string_file_owner (file_entry_t *, int);
static const char *string_file_group (file_entry_t *, int);
static const char *string_marked (file_entry_t *, int);
static const char *string_space (file_entry_t *, int);
static const char *string_dot (file_entry_t *, int);
mc_fhl_t *mc_filehighlight = NULL;
/*** file scope macro definitions ****************************************************************/
#define NORMAL 0
#define SELECTED 1
#define MARKED 2
#define MARKED_SELECTED 3
#define STATUS 5
/*** file scope type declarations ****************************************************************/
typedef enum
{
MARK_DONT_MOVE = 0,
MARK_DOWN = 1,
MARK_FORCE_DOWN = 2,
MARK_FORCE_UP = 3
} mark_act_t;
/*
* This describes a format item. The parse_display_format routine parses
* the user specified format and creates a linked list of format_e structures.
*/
typedef struct format_e
{
struct format_e *next;
int requested_field_len;
int field_len;
align_crt_t just_mode;
gboolean expand;
const char *(*string_fn) (file_entry_t *, int len);
char *title;
const char *id;
} format_e;
/* File name scroll states */
typedef enum
{
FILENAME_NOSCROLL = 1,
FILENAME_SCROLL_LEFT = 2,
FILENAME_SCROLL_RIGHT = 4
} filename_scroll_flag_t;
/*** file scope variables ************************************************************************/
/* *INDENT-OFF* */
static panel_field_t panel_fields_initializers[] = {
{
"unsorted", 12, TRUE, J_LEFT_FIT,
/* TRANSLATORS: one single character to represent 'unsorted' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|u"),
N_("&Unsorted"), TRUE, FALSE,
string_file_name,
(GCompareFunc) unsorted
}
,
{
"name", 12, TRUE, J_LEFT_FIT,
/* TRANSLATORS: one single character to represent 'name' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|n"),
N_("&Name"), TRUE, TRUE,
string_file_name,
(GCompareFunc) sort_name
}
,
{
"version", 12, TRUE, J_LEFT_FIT,
/* TRANSLATORS: one single character to represent 'version' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|v"),
N_("&Version"), TRUE, FALSE,
string_file_name,
(GCompareFunc) sort_vers
}
,
{
"extension", 12, TRUE, J_LEFT_FIT,
/* TRANSLATORS: one single character to represent 'extension' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|e"),
N_("E&xtension"), TRUE, FALSE,
string_file_name, /* TODO: string_file_ext */
(GCompareFunc) sort_ext
}
,
{
"size", 7, FALSE, J_RIGHT,
/* TRANSLATORS: one single character to represent 'size' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|s"),
N_("&Size"), TRUE, TRUE,
string_file_size,
(GCompareFunc) sort_size
}
,
{
"bsize", 7, FALSE, J_RIGHT,
"",
N_("Block Size"), FALSE, FALSE,
string_file_size_brief,
(GCompareFunc) sort_size
}
,
{
"type", 1, FALSE, J_LEFT,
"",
"", FALSE, TRUE,
string_file_type,
NULL
}
,
{
"mtime", 12, FALSE, J_RIGHT,
/* TRANSLATORS: one single character to represent 'Modify time' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|m"),
N_("&Modify time"), TRUE, TRUE,
string_file_mtime,
(GCompareFunc) sort_time
}
,
{
"atime", 12, FALSE, J_RIGHT,
/* TRANSLATORS: one single character to represent 'Access time' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|a"),
N_("&Access time"), TRUE, TRUE,
string_file_atime,
(GCompareFunc) sort_atime
}
,
{
"ctime", 12, FALSE, J_RIGHT,
/* TRANSLATORS: one single character to represent 'Change time' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|h"),
N_("C&hange time"), TRUE, TRUE,
string_file_ctime,
(GCompareFunc) sort_ctime
}
,
{
"perm", 10, FALSE, J_LEFT,
"",
N_("Permission"), FALSE, TRUE,
string_file_permission,
NULL
}
,
{
"mode", 6, FALSE, J_RIGHT,
"",
N_("Perm"), FALSE, TRUE,
string_file_perm_octal,
NULL
}
,
{
"nlink", 2, FALSE, J_RIGHT,
"",
N_("Nl"), FALSE, TRUE,
string_file_nlinks, NULL
}
,
{
"inode", 5, FALSE, J_RIGHT,
/* TRANSLATORS: one single character to represent 'inode' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|i"),
N_("&Inode"), TRUE, TRUE,
string_inode,
(GCompareFunc) sort_inode
}
,
{
"nuid", 5, FALSE, J_RIGHT,
"",
N_("UID"), FALSE, FALSE,
string_file_nuid,
NULL
}
,
{
"ngid", 5, FALSE, J_RIGHT,
"",
N_("GID"), FALSE, FALSE,
string_file_ngid,
NULL
}
,
{
"owner", 8, FALSE, J_LEFT_FIT,
"",
N_("Owner"), FALSE, TRUE,
string_file_owner,
NULL
}
,
{
"group", 8, FALSE, J_LEFT_FIT,
"",
N_("Group"), FALSE, TRUE,
string_file_group,
NULL
}
,
{
"mark", 1, FALSE, J_RIGHT,
"",
" ", FALSE, TRUE,
string_marked,
NULL
}
,
{
"|", 1, FALSE, J_RIGHT,
"",
" ", FALSE, TRUE,
NULL,
NULL
}
,
{
"space", 1, FALSE, J_RIGHT,
"",
" ", FALSE, TRUE,
string_space,
NULL
}
,
{
"dot", 1, FALSE, J_RIGHT,
"",
" ", FALSE, FALSE,
string_dot,
NULL
}
,
{
NULL, 0, FALSE, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL
}
};
/* *INDENT-ON* */
/* --------------------------------------------------------------------------------------------- */
/*
* To allow users to register fields (via scripts), we store the fields not
* in a static C array but in a GArray.
*
* We conveniently #define 'panel_fields' to make the rest of the code work
* as if nothing has changed.
*/
GArray *panel_fields__array = NULL;
#define panel_fields ((panel_field_t *) panel_fields__array->data)
#define BUILTIN_FIELDS_COUNT (G_N_ELEMENTS (panel_fields_initializers) - 1)
#define MAX_USER_FIELDS 100
#define MAX_FIELDS (BUILTIN_FIELDS_COUNT + MAX_USER_FIELDS)
void
panel_fields_init (void)
{
/* We allow calling this function again later to clear all user-registered fields. */
if (panel_fields__array == NULL)
panel_fields__array =
g_array_sized_new (TRUE, TRUE, sizeof (panel_field_t), MAX_FIELDS + 1);
g_array_set_size (panel_fields__array, 0); /* @FIXME: Since we're not g_free()ing the fields' title/id/hotkey, there's memory leak here. */
g_array_append_vals (panel_fields__array, panel_fields_initializers, BUILTIN_FIELDS_COUNT);
}
/**
* Allow for registering fields at runtime.
*/
gboolean
panel_fields_register (const panel_field_t * field)
{
panel_field_t *found;
found = const_cast (panel_field_t *, panel_get_field_by_id (field->id));
if (found != NULL)
{
/* Override an existing field. */
*found = *field; /* @FIXME: See note in panel_fields_init() about memory leak. */
}
else
{
/* A new field. */
if (panel_fields__array->len < MAX_FIELDS)
g_array_append_val (panel_fields__array, *field);
else
{
/*
* We don't let the array grow. If it grows (that is, reallocated),
* the panel->sort_field pointer will become invalid and we'll crash.
* That's the reason we pre-allocate MAX_FIELDS in panel_fields_init().
* See also the notes in fields.lua.
*
* We'll remove this limitation once we tackle panel->sort_field. @FIXME.
*/
return FALSE;
}
}
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
static char *panel_sort_up_sign = NULL;
static char *panel_sort_down_sign = NULL;
static char *panel_hiddenfiles_sign_show = NULL;
static char *panel_hiddenfiles_sign_hide = NULL;
static char *panel_history_prev_item_sign = NULL;
static char *panel_history_next_item_sign = NULL;
static char *panel_history_show_list_sign = NULL;
static char *panel_filename_scroll_left_char = NULL;
static char *panel_filename_scroll_right_char = NULL;
/* Panel that selection started */
static WPanel *mouse_mark_panel = NULL;
static int mouse_marking = 0;
static int state_mark = 0;
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static void
set_colors (const WPanel * panel)
{
(void) panel;
tty_set_normal_attrs ();
tty_setcolor (NORMAL_COLOR);
}
/* --------------------------------------------------------------------------------------------- */
/** Delete format string, it is a linked list */
static void
delete_format (format_e * format)
{
while (format != NULL)
{
format_e *next = format->next;
g_free (format->title);
g_free (format);
format = next;
}
}
/* --------------------------------------------------------------------------------------------- */
/** Extract the number of available lines in a panel */
static int
panel_lines (const WPanel * p)
{
/* 3 lines are: top frame, column header, botton frame */
return (CONST_WIDGET (p)->lines - 3 - (panels_options.show_mini_info ? 2 : 0));
}
/* --------------------------------------------------------------------------------------------- */
/** This code relies on the default justification!!! */
static void
add_permission_string (const char *dest, int width, file_entry_t * fe, int attr, int color,
gboolean is_octal)
{
int i, r, l;
l = get_user_permissions (&fe->st);
if (is_octal)
{
/* Place of the access bit in octal mode */
l = width + l - 3;
r = l + 1;
}
else
{
/* The same to the triplet in string mode */
l = l * 3 + 1;
r = l + 3;
}
for (i = 0; i < width; i++)
{
if (i >= l && i < r)
{
if (attr == SELECTED || attr == MARKED_SELECTED)
tty_setcolor (MARKED_SELECTED_COLOR);
else
tty_setcolor (MARKED_COLOR);
}
else if (color >= 0)
tty_setcolor (color);
else
tty_lowlevel_setcolor (-color);
tty_print_char (dest[i]);
}
}
/* --------------------------------------------------------------------------------------------- */
/** String representations of various file attributes name */
static const char *
string_file_name (file_entry_t * fe, int len)
{
static char buffer[MC_MAXPATHLEN * MB_LEN_MAX + 1];
(void) len;
g_strlcpy (buffer, fe->fname, sizeof (buffer));
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
static unsigned int
ilog10 (dev_t n)
{
unsigned int digits = 0;
do
{
digits++, n /= 10;
}
while (n != 0);
return digits;
}
/* --------------------------------------------------------------------------------------------- */
static void
format_device_number (char *buf, size_t bufsize, dev_t dev)
{
dev_t major_dev = major (dev);
dev_t minor_dev = minor (dev);
unsigned int major_digits = ilog10 (major_dev);
unsigned int minor_digits = ilog10 (minor_dev);
g_assert (bufsize >= 1);
if (major_digits + 1 + minor_digits + 1 <= bufsize)
g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
else
g_strlcpy (buf, _("[dev]"), bufsize);
}
/* --------------------------------------------------------------------------------------------- */
/** size */
static const char *
string_file_size (file_entry_t * fe, int len)
{
static char buffer[BUF_TINY];
/* Don't ever show size of ".." since we don't calculate it */
if (DIR_IS_DOTDOT (fe->fname))
return _("UP--DIR");
#ifdef HAVE_STRUCT_STAT_ST_RDEV
if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
format_device_number (buffer, len + 1, fe->st.st_rdev);
else
#endif
size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0, panels_options.kilobyte_si);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** bsize */
static const char *
string_file_size_brief (file_entry_t * fe, int len)
{
if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir)
return _("SYMLINK");
if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && !DIR_IS_DOTDOT (fe->fname))
return _("SUB-DIR");
return string_file_size (fe, len);
}
/* --------------------------------------------------------------------------------------------- */
/** This functions return a string representation of a file entry type */
static const char *
string_file_type (file_entry_t * fe, int len)
{
static char buffer[2];
(void) len;
if (S_ISDIR (fe->st.st_mode))
buffer[0] = PATH_SEP;
else if (S_ISLNK (fe->st.st_mode))
{
if (fe->f.link_to_dir)
buffer[0] = '~';
else if (fe->f.stale_link)
buffer[0] = '!';
else
buffer[0] = '@';
}
else if (S_ISCHR (fe->st.st_mode))
buffer[0] = '-';
else if (S_ISSOCK (fe->st.st_mode))
buffer[0] = '=';
else if (S_ISDOOR (fe->st.st_mode))
buffer[0] = '>';
else if (S_ISBLK (fe->st.st_mode))
buffer[0] = '+';
else if (S_ISFIFO (fe->st.st_mode))
buffer[0] = '|';
else if (S_ISNAM (fe->st.st_mode))
buffer[0] = '#';
else if (!S_ISREG (fe->st.st_mode))
buffer[0] = '?'; /* non-regular of unknown kind */
else if (is_exe (fe->st.st_mode))
buffer[0] = '*';
else
buffer[0] = ' ';
buffer[1] = '\0';
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** mtime */
static const char *
string_file_mtime (file_entry_t * fe, int len)
{
(void) len;
return file_date (fe->st.st_mtime);
}
/* --------------------------------------------------------------------------------------------- */
/** atime */
static const char *
string_file_atime (file_entry_t * fe, int len)
{
(void) len;
return file_date (fe->st.st_atime);
}
/* --------------------------------------------------------------------------------------------- */
/** ctime */
static const char *
string_file_ctime (file_entry_t * fe, int len)
{
(void) len;
return file_date (fe->st.st_ctime);
}
/* --------------------------------------------------------------------------------------------- */
/** perm */
static const char *
string_file_permission (file_entry_t * fe, int len)
{
(void) len;
return string_perm (fe->st.st_mode);
}
/* --------------------------------------------------------------------------------------------- */
/** mode */
static const char *
string_file_perm_octal (file_entry_t * fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** nlink */
static const char *
string_file_nlinks (file_entry_t * fe, int len)
{
static char buffer[BUF_TINY];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** inode */
static const char *
string_inode (file_entry_t * fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** nuid */
static const char *
string_file_nuid (file_entry_t * fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** ngid */
static const char *
string_file_ngid (file_entry_t * fe, int len)
{
static char buffer[10];
(void) len;
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
return buffer;
}
/* --------------------------------------------------------------------------------------------- */
/** owner */
static const char *
string_file_owner (file_entry_t * fe, int len)
{
(void) len;
return get_owner (fe->st.st_uid);
}
/* --------------------------------------------------------------------------------------------- */
/** group */
static const char *
string_file_group (file_entry_t * fe, int len)
{
(void) len;
return get_group (fe->st.st_gid);
}
/* --------------------------------------------------------------------------------------------- */
/** mark */
static const char *
string_marked (file_entry_t * fe, int len)
{
(void) len;
return fe->f.marked ? "*" : " ";
}
/* --------------------------------------------------------------------------------------------- */
/** space */
static const char *
string_space (file_entry_t * fe, int len)
{
(void) fe;
(void) len;
return " ";
}
/* --------------------------------------------------------------------------------------------- */
/** dot */
static const char *
string_dot (file_entry_t * fe, int len)
{
(void) fe;
(void) len;
return ".";
}
/* --------------------------------------------------------------------------------------------- */
static int
file_compute_color (int attr, file_entry_t * fe)
{
switch (attr)
{
case SELECTED:
return (SELECTED_COLOR);
case MARKED:
return (MARKED_COLOR);
case MARKED_SELECTED:
return (MARKED_SELECTED_COLOR);
case STATUS:
return (NORMAL_COLOR);
case NORMAL:
default:
if (!panels_options.filetype_mode)
return (NORMAL_COLOR);
}
return mc_fhl_get_color (mc_filehighlight, fe);
}
/* --------------------------------------------------------------------------------------------- */
/** Returns the number of items in the given panel */
static int
panel_items (const WPanel * p)
{
return panel_lines (p) * p->list_cols;
}
/* --------------------------------------------------------------------------------------------- */
/** Formats the file number file_index of panel in the buffer dest */
static filename_scroll_flag_t
format_file (WPanel * panel, int file_index, int width, int attr, gboolean isstatus,
int *field_length)
{
int color = NORMAL_COLOR;
int length = 0;
format_e *format, *home;
file_entry_t *fe = NULL;
filename_scroll_flag_t res = FILENAME_NOSCROLL;
*field_length = 0;
if (file_index < panel->dir.len)
{
fe = &panel->dir.list[file_index];
color = file_compute_color (attr, fe);
}
home = isstatus ? panel->status_format : panel->format;
for (format = home; format != NULL && length != width; format = format->next)
{
if (format->string_fn != NULL)
{
const char *txt = " ";
int len, perm = 0;
const char *prepared_text;
int name_offset = 0;
#ifdef ENABLE_LUA
mc_lua_set_current_field (panel, format->id);
#endif
if (fe != NULL)
txt = format->string_fn (fe, format->field_len);
len = format->field_len;
if (len + length > width)
len = width - length;
if (len <= 0)
break;
if (!isstatus && panel->content_shift > -1 && strcmp (format->id, "name") == 0)
{
int str_len;
int i;
*field_length = len + 1;
str_len = str_length (txt);
i = MAX (0, str_len - len);
panel->max_shift = MAX (panel->max_shift, i);
i = MIN (panel->content_shift, i);
if (i > -1)
{
name_offset = str_offset_to_pos (txt, i);
if (str_len > len)
{
res = FILENAME_SCROLL_LEFT;
if (str_length (txt + name_offset) > len)
res |= FILENAME_SCROLL_RIGHT;
}
}
}
if (panels_options.permission_mode)
{
if (strcmp (format->id, "perm") == 0)
perm = 1;
else if (strcmp (format->id, "mode") == 0)
perm = 2;
}
if (color >= 0)
tty_setcolor (color);
else
tty_lowlevel_setcolor (-color);
if (!isstatus && panel->content_shift > -1)
prepared_text =
str_fit_to_term (txt + name_offset, len, HIDE_FIT (format->just_mode));
else
prepared_text = str_fit_to_term (txt, len, format->just_mode);
if (perm != 0 && fe != NULL)
add_permission_string (prepared_text, format->field_len, fe, attr, color,
perm != 1);
else
tty_print_string (prepared_text);
length += len;
}
else
{
if (attr == SELECTED || attr == MARKED_SELECTED)
tty_setcolor (SELECTED_COLOR);
else
tty_setcolor (NORMAL_COLOR);
tty_print_one_vline (TRUE);
length++;
}
}
if (length < width)
{
int y, x;
tty_getyx (&y, &x);
tty_draw_hline (y, x, ' ', width - length);
}
return res;
}
/* --------------------------------------------------------------------------------------------- */
static void
repaint_file (WPanel * panel, int file_index, gboolean mv, int attr, gboolean isstatus)
{
Widget *w = WIDGET (panel);
int nth_column = 0;
int width;
int offset = 0;
filename_scroll_flag_t ret_frm;
int ypos = 0;
gboolean panel_is_split;
int fln = 0;
panel_is_split = !isstatus && panel->list_cols > 1;
width = w->cols - 2;
if (panel_is_split)
{
nth_column = (file_index - panel->top_file) / panel_lines (panel);
width /= panel->list_cols;
offset = width * nth_column;