/
ls.c
5047 lines (4345 loc) · 137 KB
/
ls.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
/* `dir', `vdir' and `ls' directory listing programs for GNU.
Copyright (C) 85, 88, 90, 91, 1995-2001 Free Software Foundation, Inc.
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, or (at your option)
any later version.
This program 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, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* $Id: ls.c,v 1.18 2011/01/27 22:19:56 cvsalan Exp $ */
/* If ls_mode is LS_MULTI_COL,
the multi-column format is the default regardless
of the type of output device.
This is for the `dir' program.
If ls_mode is LS_LONG_FORMAT,
the long format is the default regardless of the
type of output device.
This is for the `vdir' program.
If ls_mode is LS_LS,
the output format depends on whether the output
device is a terminal.
This is for the `ls' program. */
/* Written by Richard Stallman and David MacKenzie. */
/* Color support by Peter Anvin <Peter.Anvin@linux.org> and Dennis
Flaherty <dennisf@denix.elk.miles.com> based on original patches by
Greg Lee <lee@uhunix.uhcc.hawaii.edu>. */
/* Microsoft Windows modifications copyright (c) 2011, Algin Technology LLC
Written by Alan Klietz. Distributed under
GNU General Public License version 2. */
#ifdef _AIX
#pragma alloca
#endif
#include <config.h>
#include <sys/types.h>
#if HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#if HAVE_TERMIOS_H
# include <termios.h>
#endif
#ifdef GWINSZ_IN_SYS_IOCTL
# include <sys/ioctl.h>
#endif
#ifdef WINSIZE_IN_PTEM
# include <sys/stream.h>
# include <sys/ptem.h>
#endif
#if HAVE_SYS_ACL_H
# include <sys/acl.h>
#endif
#include <stdio.h>
#include <assert.h>
#ifndef WIN32 // AEK
#include <grp.h>
#include <pwd.h>
#endif
#include <getopt.h>
/* Get MB_CUR_MAX. */
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <time.h> // AEK
#include <signal.h> // AEK
#ifdef WIN32
#include <crtdbg.h> // AEK
#endif
/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
#if HAVE_WCHAR_H
# include <wchar.h>
#endif
#include <mbstring.h> // AEK - multibyte character set (MBCS) string functions
#include <mbctype.h>
/* Get iswprint(). */
#if HAVE_WCTYPE_H
# include <wctype.h>
#endif
#if !defined iswprint && !HAVE_ISWPRINT
# define iswprint(wc) 1
#endif
#ifndef HAVE_DECL_WCWIDTH
"this configure-time declaration test was not run"
#endif
#if !HAVE_DECL_WCWIDTH
int wcwidth ();
#endif
/* If wcwidth() doesn't exist, assume all printable characters have
width 1. */
#ifndef wcwidth
# if !HAVE_WCWIDTH
# define wcwidth(wc) ((wc) == 0 ? 0 : iswprint (wc) ? 1 : -1)
# endif
#endif
#include "system.h"
#include <fnmatch.h>
#include "argmatch.h"
#include "error.h"
#include "human.h"
#include "filemode.h"
#include "ls.h"
#include "mbswidth.h"
#include "obstack.h"
#include "path-concat.h"
#include "quotearg.h"
#include "strverscmp.h"
#include "xstrtol.h"
#include "xmbrtowc.h" // AEK
#include "FindFiles.h" // AEK, for __time64_t
#include "glob.h" // AEK
#include "more.h" // AEK
extern void InitVersion(); // AEK
#undef strrchr
#define strrchr _mbsrchr // use multi-byte version of strrchr - AEK
#ifdef WIN32
#undef strcoll
#define strcoll _mbsicoll // use multi-byte case-insensitive collation order
//
// Win32 BUG: strcoll() and _mbscoll() are wrongly case sensitive!
//
#endif
#pragma warning(disable: 4244) // ignore loss of precision int-to-char // AEK
#pragma warning(disable: 4245) // ignore signed/unsigned mismatch
#pragma warning(disable: 4057) // ignore unsigned char* vs char*
#pragma warning(disable: 4706) // ignore assignment within conditional expr
/* Use access control lists only under all the following conditions.
Some systems (OSF4, Irix5, Irix6) have the acl function, but not
sys/acl.h or don't define the GETACLCNT macro. */
#if HAVE_SYS_ACL_H && HAVE_ACL && defined GETACLCNT
# define USE_ACL 1
#endif
static int ls_mode = LS_LS;
#define PROGRAM_NAME (ls_mode == LS_LS ? "ls" \
: (ls_mode == LS_MULTI_COL \
? "dir" : "vdir"))
#define AUTHORS "Richard Stallman and David MacKenzie" \
"\nMicrosoft Windows extensions by Alan Klietz"
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
/* Return an int indicating the result of comparing two integers.
Subtracting doesn't always work, due to overflow. */
#define longdiff(a, b) ((a) < (b) ? -1 : (a) > (b))
/* The field width for inode numbers. On some hosts inode numbers are
64 bits, so columns won't line up exactly when a huge inode number
is encountered, but in practice 7 digits is usually enough. */
#ifndef INODE_DIGITS
# define INODE_DIGITS 7
#endif
#ifdef S_ISLNK
# define HAVE_SYMLINKS 1
#else
# define HAVE_SYMLINKS 0
#endif
/* If any of the S_* macros are undefined, define them here so each
use doesn't have to be guarded with e.g., #ifdef S_ISLNK. */
#ifndef S_ISLNK
# define S_ISLNK(Mode) 0
#endif
#ifndef S_ISFIFO
# define S_ISFIFO(Mode) 0
#endif
#ifndef S_ISSOCK
# define S_ISSOCK(Mode) 0
#endif
#ifndef S_ISCHR
# define S_ISCHR(Mode) 0
#endif
#ifndef S_ISBLK
# define S_ISBLK(Mode) 0
#endif
#ifndef S_ISDOOR
# define S_ISDOOR(Mode) 0
#endif
#ifndef S_ISSTREAM
# define S_ISSTREAM(Mode) 0
#endif
/* Arrange to make lstat calls go through the wrapper function
on systems with an lstat function that does not dereference symlinks
that are specified with a trailing slash. */
#if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
int rpl_lstat PARAMS((const char *, struct stat *));
# undef lstat
# define lstat(Name, Stat_buf) rpl_lstat(Name, Stat_buf)
#endif
#if defined _DIRENT_HAVE_D_TYPE || defined DTTOIF
# define HAVE_STRUCT_DIRENT_D_TYPE 1
# define DT_INIT(Val) = Val
#else
# define HAVE_STRUCT_DIRENT_D_TYPE 0
# define DT_INIT(Val) /* empty */
#endif
#ifdef ST_MTIM_NSEC
# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC)
#else
# define TIMESPEC_NS(timespec) 0
#endif
//
// if --recent=n, then st_mtime within n minutes is considered
// to be 'recent' and is flagged with a different color.
//
#define DEFAULT_RECENT_FILE_MOD 60 // default 60 minutes - AEK
#ifdef WIN32
//
// Because Win32 paths often contain a colon (C:\),
// do not quote with an escape to \: - looks ugly.
//
#define quotearg_colon(n) (n)
#endif
enum filetype
{
unknown DT_INIT (DT_UNKNOWN),
fifo DT_INIT (DT_FIFO),
chardev DT_INIT (DT_CHR),
directory DT_INIT (DT_DIR),
blockdev DT_INIT (DT_BLK),
normal DT_INIT (DT_REG),
symbolic_link DT_INIT (DT_LNK),
sock DT_INIT (DT_SOCK),
arg_directory DT_INIT (2 * (DT_UNKNOWN | DT_FIFO | DT_CHR | DT_DIR | DT_BLK
| DT_REG | DT_LNK | DT_SOCK))
};
struct fileinfo
{
/* The file name. */
char *name;
struct stat stat;
/* For symbolic link, name of the file linked to, otherwise zero. */
char *linkname;
/* For symbolic link and long listing, st_mode of file linked to, otherwise
zero. */
unsigned int linkmode;
/* For symbolic link and color printing, 1 if linked-to file
exists, otherwise 0. */
int linkok;
enum filetype filetype;
#if USE_ACL
/* For long listings, nonzero if the file has an access control list,
otherwise zero. */
int have_acl;
#endif
};
#if USE_ACL
# define FILE_HAS_ACL(F) ((F)->have_acl)
#else
# define FILE_HAS_ACL(F) 0
#endif
#define LEN_STR_PAIR(s) sizeof (s) - 1, s
/* Null is a valid character in a color indicator (think about Epson
printers, for example) so we have to use a length/buffer string
type. */
struct bin_str
{
int len; /* Number of bytes */
const char *string; /* Pointer to the same */
};
#ifndef STDC_HEADERS
time_t time ();
#endif
char *getgroup () { return "group"; }; // AEK
#define MSLS_PREFIX "MSLS" // AEK
#define LS_PREFIX "LS"
static size_t quote_name PARAMS ((MORE *out, const char *name,
struct quoting_options const *options));
static char *make_link_path PARAMS ((const char *path, const char *linkname));
static void mark_if_file_changed_recently PARAMS ((struct stat *pst)); // AEK
static int compare_atime PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_atime PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int compare_ctime PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_ctime PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int compare_mtime PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_mtime PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int compare_size PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_size PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int compare_name PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_name PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int compare_extension PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_extension PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int compare_version PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_version PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
// AEK
static int compare_case_sensitive PARAMS ((const struct fileinfo *file1,
const struct fileinfo *file2));
static int rev_cmp_case_sensitive PARAMS ((const struct fileinfo *file2,
const struct fileinfo *file1));
static int decode_switches PARAMS ((int argc, char **argv));
static int file_interesting PARAMS ((const struct dirent *next));
static uintmax_t gobble_file PARAMS ((const char *name, enum filetype type,
int explicit_arg, const char *dirname));
static void print_color_indicator PARAMS ((const char *name, unsigned int mode,
int linkok));
static void put_indicator PARAMS ((const struct bin_str *ind));
static int length_of_file_name_and_frills PARAMS ((const struct fileinfo *f));
static void add_ignore_pattern PARAMS ((const char *pattern));
static void attach PARAMS ((char *dest, const char *dirname, const char *name));
static void clear_files PARAMS ((void));
static void extract_dirs_from_files PARAMS ((const char *dirname,
int recursive));
static void get_link_name PARAMS ((const char *filename, struct fileinfo *f));
static void indent PARAMS ((int from, int to));
static void init_column_info PARAMS ((void));
static void print_current_files PARAMS ((void));
static void print_dir PARAMS ((const char *name, const char *realname));
static void print_file_name_and_frills PARAMS ((const struct fileinfo *f));
static void print_horizontal PARAMS ((void));
static void print_long_format PARAMS ((const struct fileinfo *f));
static void print_many_per_line PARAMS ((void));
static void print_name_with_quoting PARAMS ((const char *p, unsigned int mode,
int linkok,
struct obstack *stack));
static void prep_non_filename_text PARAMS ((void));
//static void print_type_indicator PARAMS ((unsigned int mode));
static void print_type_indicator PARAMS ((struct stat *pst,
unsigned int mode)); // AEK
static void print_with_commas PARAMS ((void));
static void queue_directory PARAMS ((const char *name, const char *realname));
static void sort_files PARAMS ((void));
static void parse_ls_color PARAMS ((void));
void usage PARAMS ((int status));
/* The name the program was run with, stripped of any leading path. */
char *program_name;
/* The table of files in the current directory:
`files' points to a vector of `struct fileinfo', one per file.
`nfiles' is the number of elements space has been allocated for.
`files_index' is the number actually in use. */
/* Address of block containing the files that are described. */
static struct fileinfo *files; /* FIXME: rename this to e.g. cwd_file */
/* Length of block that `files' points to, measured in files. */
static int nfiles; /* FIXME: rename this to e.g. cwd_n_alloc */
/* Index of first unused in `files'. */
static int files_index; /* FIXME: rename this to e.g. cwd_n_used */
/* When nonzero, in a color listing, color each symlink name according to the
type of file it points to. Otherwise, color them according to the `ln'
directive in LS_COLORS. Dangling (orphan) symlinks are treated specially,
regardless. This is set when `ln=target' appears in LS_COLORS. */
static int color_symlink_as_referent;
/* mode of appropriate file for colorization */
#define FILE_OR_LINK_MODE(File) \
((color_symlink_as_referent && (File)->linkok) \
? (File)->linkmode : (File)->stat.st_mode)
/* Record of one pending directory waiting to be listed. */
struct pending
{
char *name;
/* If the directory is actually the file pointed to by a symbolic link we
were told to list, `realname' will contain the name of the symbolic
link, otherwise zero. */
char *realname;
struct pending *next;
};
static struct pending *pending_dirs;
/* Current time in seconds and nanoseconds since 1970, updated as
needed when deciding whether a file is recent. */
static time_t current_time = TYPE_MINIMUM (time_t);
static int current_time_ns = -1;
/* The number of digits to use for block sizes.
4, or more if needed for bigger numbers. */
static int block_size_size;
// Ditto for -l output AEK
static int long_block_size_size;
/* Option flags */
/* long_format for lots of info, one per line.
one_per_line for just names, one per line.
many_per_line for just names, many per line, sorted vertically.
horizontal for just names, many per line, sorted horizontally.
with_commas for just names, many per line, separated by commas.
-l, -1, -C, -x and -m control this parameter. */
enum format format; // make global for security.cpp and dirent.c - AEK
/* `full-iso' uses full ISO-style dates and times. `long-iso' uses longer
ISO-style time stamps, though shorter than `full-iso'. `iso' uses shorter
ISO-style time stamps. `locale' uses locale-dependent time stamps. */
enum time_style
{
full_iso_time_style, /* --time-style=full-iso */
long_iso_time_style, /* --time-style=long-iso */
iso_time_style, /* --time-style=iso */
locale_time_style /* --time-style=locale */
};
static char const *const time_style_args[] =
{
"full-iso", "long-iso", "iso", "locale", NULL
};
static enum time_style const time_style_types[] =
{
full_iso_time_style, long_iso_time_style, iso_time_style,
locale_time_style
};
int run_fast = 1; // default, implicitly turned off sometimes unless..
static int explicit_run_fast_or_slow; // explicit --fast or --slow
int phys_size; // --phys_size
int short_names; // --short-names
int color_compressed; // --compressed
static int command_line; // LS_OPTIONS vs command line arg
static char const *const yes_no_args[] =
{
"always", "yes", "y",
"never", "none", "no", "n",
0
};
static enum yes_no_type const yes_no_types[] =
{
yes_arg, yes_arg, yes_arg,
no_arg, no_arg, no_arg, no_arg
};
enum yes_no_type show_streams = no_arg; // AEK
#ifdef WIN32
BOOL gbReg; // AEK show registry via -K
BOOL gb32bit; // AEK show 32-bit view of files and registry (--32)
BOOL gbRegDelVal; // AEK delete registry test-value
BOOL gbRegSetVal; // AEK set registry test-value
BOOL gbOemCp; // AEK are we using the OEM console codepage?
BOOL gbExpandMui; // AEK expand MUI registry strings
extern BOOL IsVista;
#endif
/* Type of time to print or sort by. Controlled by -c and -u. */
enum time_type
{
time_mtime, /* default */
time_ctime, /* -c */
time_atime /* -u */
};
static enum time_type time_type;
/* print the full time, otherwise the standard unix heuristics. */
static int full_time;
/* The file characteristic to sort by. Controlled by -t, -S, -U, -X, -v. */
enum sort_type
{
sort_none, /* -U */
sort_name, /* default */
sort_extension, /* -X */
sort_time, /* -t */
sort_size, /* -S */
sort_version, /* -v */
sort_case /* -sort=case */ /* AEK */
};
static enum sort_type sort_type;
/* Direction of sort.
0 means highest first if numeric,
lowest first if alphabetic;
these are the defaults.
1 means the opposite order in each case. -r */
static int sort_reverse;
/* Nonzero means to NOT display group information. -G */
#ifdef WIN32
static int inhibit_group = 1; // inhibit groups by default on Win32 - AEK
#else
static int inhibit_group;
#endif
/* Nonzero means print the user and group id's as numbers rather
than as names. -n */
int numeric_ids; // make global - AEK
/* Nonzero means mention the size in blocks of each file. -s */
static int print_block_size;
/* If positive, the units to use when printing sizes;
if negative, the human-readable base. */
static int output_block_size;
/* Precede each line of long output (per file) with a string like `m,n:'
where M is the number of characters after the `:' and before the
filename and N is the length of the filename. Using this format,
Emacs' dired mode starts up twice as fast, and can handle all
strange characters in file names. */
static int dired;
/* `none' means don't mention the type of files.
`classify' means mention file types and mark executables.
`file_type' means mention only file types.
Controlled by -F, -p, and --indicator-style. */
enum indicator_style
{
none, /* --indicator-style=none */
classify, /* -F, --indicator-style=classify */
file_type /* -p, --indicator-style=file-type */
};
static enum indicator_style indicator_style;
/* Names of indicator styles. */
static char const *const indicator_style_args[] =
{
"none", "classify", "file-type", 0
};
static enum indicator_style const indicator_style_types[]=
{
none, classify, file_type
};
/* Nonzero means use colors to mark types. Also define the different
colors as well as the stuff for the LS_COLORS environment variable.
The LS_COLORS variable is now in a termcap-like format. */
static int print_with_color;
enum color_type
{
color_never, /* 0: default or --color=never */
color_always, /* 1: --color=always */
color_if_tty /* 2: --color=tty */
};
enum indicator_no
{
C_LEFT, C_RIGHT, C_END, C_NORM, C_FILE, C_DIR, C_LINK, C_FIFO, C_SOCK,
C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR,
C_RECENT, // AEK
C_COMPRESSED, // AEK
C_STREAMS // AEK
};
static const char *const indicator_name[]=
{
"lc", "rc", "ec", "no", "fi", "di", "ln", "pi", "so",
"bd", "cd", "mi", "or", "ex", "do",
"re", // AEK C_RECENT
"co", // AEK C_COMPRESSED
"st", // AEK C_STREAMS
NULL
};
struct color_ext_type
{
struct bin_str ext; /* The extension we're looking for */
struct bin_str seq; /* The sequence to output when we do */
struct color_ext_type *next; /* Next in list */
};
static struct bin_str color_indicator[] =
{
{ LEN_STR_PAIR ("\033[") }, /* lc: Left of color sequence */
{ LEN_STR_PAIR ("m") }, /* rc: Right of color sequence */
{ 0, NULL }, /* ec: End color (replaces lc+no+rc) */
{ LEN_STR_PAIR ("0") }, /* no: Normal */
{ LEN_STR_PAIR ("0") }, /* fi: File: default */
{ LEN_STR_PAIR ("01;32") }, /* di: Directory: bright green */
{ LEN_STR_PAIR ("01;34") }, /* ln: Symlink: bright blue */
{ LEN_STR_PAIR ("33") }, /* pi: Pipe: yellow/brown */
{ LEN_STR_PAIR ("01;35") }, /* so: Socket: bright magenta */
{ LEN_STR_PAIR ("33") }, /* bd: Block device: brown */
{ LEN_STR_PAIR ("33") }, /* cd: Char device: bright yellow */
{ LEN_STR_PAIR ("01;31") }, /* mi: Missing symlink target: bright red */
{ LEN_STR_PAIR ("01;31") }, /* or: Orphaned symlink source: bright red */
{ LEN_STR_PAIR ("01;33") }, /* ex: Executable: bright yellow */
{ LEN_STR_PAIR ("01;35") }, /* do: Door: bright magenta */
{ LEN_STR_PAIR (";04") }, /* re: Recent: underscore - AEK */
{ LEN_STR_PAIR (";01;36") }, /* co: Compressed: bright cyan - AEK */
{ LEN_STR_PAIR (";01;34") }, /* co: Streams: bright blue - AEK */
};
//
// Default colors for popular file extensions. String generated
// from the dircolors utility - AEK
//
#define MSLS_COLORS_DEFAULT "*.cmd=01;33:*.bat=01;33:*.exe=01;33:*.com=01;33:*.tar=01;36:*.tgz=01;36:*.arj=01;36:*.taz=01;36:*.lzh=01;36:*.zip=01;36:*.z=01;36:*.Z=01;36:*.gz=01;36:*.bz2=01;36:*.deb=01;36:*.rpm=01;36:*.jpg=01;35:*.png=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.cdr=01;35:*.mpg=01;35:*.wmv=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35"
/* FIXME: comment */
static struct color_ext_type *color_ext_list = NULL;
/* Buffer for color sequences */
static char *color_buf;
/* Nonzero means to check for orphaned symbolic link, for displaying
colors. */
static int check_symlink_color;
/* Nonzero means mention the inode number of each file. -i */
int print_inode; // make global for dirent.c - AEK
/* Nonzero means use the built-in more paginator -M (AEK) */
static int use_more; // AEK
/* Nonzero means when a symbolic link is found, display info on
the file linked to. -L */
static int trace_links;
/* Nonzero means when a directory is found, display info on its
contents. -R */
static int trace_dirs;
/* Nonzero means when an argument is a directory name, display info
on it itself. -d */
static int immediate_dirs;
/* Nonzero means don't omit files whose names start with `.'. -A */
static int all_files;
/* Nonzero means don't omit files `.' and `..'
This flag implies `all_files'. -a */
static int really_all_files;
/* A linked list of shell-style globbing patterns. If a non-argument
file name matches any of these patterns, it is omitted.
Controlled by -I. Multiple -I options accumulate.
The -B option adds `*~' and `.*~' to this list. */
struct ignore_pattern
{
const char *pattern;
struct ignore_pattern *next;
};
static struct ignore_pattern *ignore_patterns;
/* Nonzero means output nongraphic chars in file names as `?'.
(-q, --hide-control-chars)
qmark_funny_chars and the quoting style (-Q, --quoting-style=WORD) are
independent. The algorithm is: first, obey the quoting style to get a
string representing the file name; then, if qmark_funny_chars is set,
replace all nonprintable chars in that string with `?'. It's necessary
to replace nonprintable chars even in quoted strings, because we don't
want to mess up the terminal if control chars get sent to it, and some
quoting methods pass through control chars as-is. */
static int qmark_funny_chars;
/* Quoting options for file and dir name output. */
static struct quoting_options *filename_quoting_options;
static struct quoting_options *dirname_quoting_options;
/* The number of chars per hardware tab stop. Setting this to zero
inhibits the use of TAB characters for separating columns. -T */
int tabsize;
/* Nonzero means we are listing the working directory because no
non-option arguments were given. */
static int dir_defaulted;
/* Nonzero means print each directory name before listing it. */
static int print_dir_name;
/* The line length to use for breaking lines in many-per-line format.
Can be set with -w. */
static int line_length;
/* If nonzero, the file listing format requires that stat be called on
each file. */
static int format_needs_stat;
/* Similar to `format_needs_stat', but set if only the file type is
needed. */
static int format_needs_type;
/* strftime formats for non-recent and recent files, respectively, in
-l output. */
static char const *long_time_format[2];
/* The exit status to use if we don't get any fatal errors. */
static int exit_status;
/* For long options that have no equivalent short option, use a
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
BIT32_OPTION = CHAR_MAX + 1, // AEK
BIT64_OPTION, // AEK
BLOCK_SIZE_OPTION,
COLOR_OPTION,
FORMAT_OPTION,
FULL_TIME_OPTION,
INDICATOR_STYLE_OPTION,
QUOTING_STYLE_OPTION,
SHOW_CONTROL_CHARS_OPTION,
SI_OPTION,
SORT_OPTION,
TIME_OPTION,
TIME_STYLE_OPTION,
#ifdef WIN32
FAST_OPTION, // AEK
SLOW_OPTION, // AEK
RECENT_OPTION, // AEK
PHYS_SIZE_OPTION, // AEK
SHORT_NAMES_OPTION, // AEK
COMPRESSED_OPTION, // AEK
SHOW_STREAMS_OPTION, // AEK
SIDS_OPTION, // AEK
GIDS_OPTION, // AEK
ACLS_OPTION, // AEK
ENCRYPTION_OPTION, // AEK
OBJECTID_OPTION, // AEK
USER_OPTION, // AEK
VIEW_SECURITY_OPTION, // AEK
REGSETVAL_OPTION, // AEK
REGDELVAL_OPTION,
TOKEN_OPTION, // AEK
VIRTUAL_OPTION, // AEK
ANSICP_OPTION, // AEK
OEMCP_OPTION, // AEK
EXPANDMUI_OPTION, // AEK
#endif
COMMAND_LINE_OPTION, // AEK
};
// Mark the end of LS_OPTIONS and the start of real command line args - AEK
#define COMMAND_LINE_OPTION_MARKER "\001\001\001"
static struct option const long_options[] =
{
#ifdef WIN32
{"32", no_argument, 0, BIT32_OPTION},
{"64", no_argument, 0, BIT64_OPTION},
#endif
{"all", no_argument, 0, 'a'},
{"escape", no_argument, 0, 'b'},
{"directory", no_argument, 0, 'd'},
{"dired", no_argument, 0, 'D'},
{"full-time", no_argument, 0, FULL_TIME_OPTION},
{"human-readable", no_argument, 0, 'h'},
{"inode", no_argument, 0, 'i'},
{"kilobytes", no_argument, 0, 'k'},
#ifdef WIN32
{"registry", no_argument, 0, 'K'}, // AEK
#endif
{"numeric-uid-gid", no_argument, 0, 'n'},
{"no-group", no_argument, 0, 'G'}, // backward compatbility; undoc
{"groups", optional_argument, 0, 'g'}, // AEK
{"hide-control-chars", no_argument, 0, 'q'},
{"reverse", no_argument, 0, 'r'},
{"size", no_argument, 0, 's'},
{"width", required_argument, 0, 'w'},
{"almost-all", no_argument, 0, 'A'},
{"ignore-backups", no_argument, 0, 'B'},
{"classify", no_argument, 0, 'F'},
{"file-type", no_argument, 0, 'p'},
{"si", no_argument, 0, SI_OPTION},
{"ignore", required_argument, 0, 'I'},
{"indicator-style", required_argument, 0, INDICATOR_STYLE_OPTION},
{"dereference", no_argument, 0, 'L'},
{"literal", no_argument, 0, 'N'},
{"quote-name", no_argument, 0, 'Q'},
{"quoting-style", required_argument, 0, QUOTING_STYLE_OPTION},
{"recursive", no_argument, 0, 'R'},
{"format", required_argument, 0, FORMAT_OPTION},
{"show-control-chars", no_argument, 0, SHOW_CONTROL_CHARS_OPTION},
{"sort", required_argument, 0, SORT_OPTION},
{"tabsize", required_argument, 0, 'T'},
{"time", required_argument, 0, TIME_OPTION},
{"color", optional_argument, 0, COLOR_OPTION},
{"block-size", required_argument, 0, BLOCK_SIZE_OPTION},
{"time-style", required_argument, 0, TIME_STYLE_OPTION},
#ifdef WIN32
{"fast", no_argument, 0, FAST_OPTION}, // AEK
{"slow", no_argument, 0, SLOW_OPTION}, // AEK
{"recent", optional_argument, 0, RECENT_OPTION}, // AEK
{"more", no_argument, 0, 'M'}, // AEK
{"phys-size", no_argument, 0, PHYS_SIZE_OPTION}, // AEK
{"short-names", no_argument, 0, SHORT_NAMES_OPTION}, // AEK
{"compressed", no_argument, 0, COMPRESSED_OPTION}, // AEK
{"streams", optional_argument, 0, SHOW_STREAMS_OPTION}, // AEK
{"sids", optional_argument, 0, SIDS_OPTION}, // AEK
{"gids", optional_argument, 0, GIDS_OPTION}, // AEK
{"acls", optional_argument, 0, ACLS_OPTION}, // AEK
{"encryption-users", no_argument, 0, ENCRYPTION_OPTION}, // AEK
{"object-id", no_argument, 0, OBJECTID_OPTION}, // AEK
{"user", required_argument, 0, USER_OPTION}, // AEK
{"view-security", no_argument, 0, VIEW_SECURITY_OPTION}, // AEK
{"regsetval", no_argument, 0, REGSETVAL_OPTION}, // AEK
{"regdelval", no_argument, 0, REGDELVAL_OPTION}, // AEK
{"tokens", no_argument, 0, TOKEN_OPTION}, // AEK
{"virtual", no_argument, 0, VIRTUAL_OPTION}, // AEK
{"ansi-cp", no_argument, 0, ANSICP_OPTION}, // AEK
{"oem-cp", no_argument, 0, OEMCP_OPTION}, // AEK
{"expandmui", no_argument, 0, EXPANDMUI_OPTION}, // AEK
#endif
// Mark the end of LS_OPTIONS and the start of real command line args - AEK
{COMMAND_LINE_OPTION_MARKER, no_argument, 0, COMMAND_LINE_OPTION}, // AEK
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
};
static char const *const format_args[] =
{
"verbose", "long", "commas", "horizontal", "across",
"vertical", "single-column", 0
};
static enum format const format_types[] =
{
long_format, long_format, with_commas, horizontal, horizontal,
many_per_line, one_per_line
};
static char const *const sort_args[] =
{
"none", "time", "size", "extension", "version",
"case", // AE
0
};
static enum sort_type const sort_types[] =
{
sort_none, sort_time, sort_size, sort_extension, sort_version,
sort_case // AEK
};
static char const *const time_args[] =
{
"atime", "access", "use",
"ctime",
#ifndef WIN32
"status",
#endif
"mtime", "modify",
0
};
static enum time_type const time_types[] =
{
time_atime, time_atime, time_atime,
time_ctime,
#ifndef WIN32
time_ctime,
#endif
time_mtime, time_mtime
};
static char const *const color_args[] =
{
/* force and none are for compatibility with another color-ls version */
"always", "yes", "force",
"never", "no", "none",
"auto", "tty", "if-tty", 0
};
static enum color_type const color_types[] =
{
color_always, color_always, color_always,
color_never, color_never, color_never,
color_if_tty, color_if_tty, color_if_tty
};
static int recent_file_mod; // AEK
static char const *const sids_args[] =
{
"long", "yes", "always",
"none", "no", "never",
"short",
0
};
enum sids_format const sids_formats[] =
{
sids_long, sids_long, sids_long,
sids_none, sids_none, sids_none,
sids_short,
};