aboutsummaryrefslogtreecommitdiff
path: root/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'ls.c')
-rw-r--r--ls.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/ls.c b/ls.c
index 754a6d450..080768027 100644
--- a/ls.c
+++ b/ls.c
@@ -41,9 +41,9 @@
41 * 1. requires lstat (BSD) - how do you do it without? 41 * 1. requires lstat (BSD) - how do you do it without?
42 */ 42 */
43 43
44#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */ 44static const int TERMINAL_WIDTH = 80; /* use 79 if your terminal has linefold bug */
45#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */ 45static const int COLUMN_WIDTH = 14; /* default if AUTOWIDTH not defined */
46#define COLUMN_GAP 2 /* includes the file type char, if present */ 46static const int COLUMN_GAP = 2; /* includes the file type char, if present */
47 47
48/************************************************************************/ 48/************************************************************************/
49 49
@@ -66,10 +66,12 @@
66#endif 66#endif
67 67
68/* what is the overall style of the listing */ 68/* what is the overall style of the listing */
69#define STYLE_AUTO 0 69enum {
70#define STYLE_LONG 1 /* one record per line, extended info */ 70STYLE_AUTO = 0,
71#define STYLE_SINGLE 2 /* one record per line */ 71STYLE_LONG = 1, /* one record per line, extended info */
72#define STYLE_COLUMNS 3 /* fill columns */ 72STYLE_SINGLE = 2, /* one record per line */
73STYLE_COLUMNS = 3 /* fill columns */
74};
73 75
74/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ 76/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
75/* what file information will be listed */ 77/* what file information will be listed */
@@ -99,23 +101,23 @@
99 101
100#ifdef BB_FEATURE_LS_SORTFILES 102#ifdef BB_FEATURE_LS_SORTFILES
101/* how will the files be sorted */ 103/* how will the files be sorted */
102#define SORT_FORWARD 0 /* sort in reverse order */ 104static const int SORT_FORWARD = 0; /* sort in reverse order */
103#define SORT_REVERSE 1 /* sort in reverse order */ 105static const int SORT_REVERSE = 1; /* sort in reverse order */
104#define SORT_NAME 2 /* sort by file name */ 106static const int SORT_NAME = 2; /* sort by file name */
105#define SORT_SIZE 3 /* sort by file size */ 107static const int SORT_SIZE = 3; /* sort by file size */
106#define SORT_ATIME 4 /* sort by last access time */ 108static const int SORT_ATIME = 4; /* sort by last access time */
107#define SORT_CTIME 5 /* sort by last change time */ 109static const int SORT_CTIME = 5; /* sort by last change time */
108#define SORT_MTIME 6 /* sort by last modification time */ 110static const int SORT_MTIME = 6; /* sort by last modification time */
109#define SORT_VERSION 7 /* sort by version */ 111static const int SORT_VERSION = 7; /* sort by version */
110#define SORT_EXT 8 /* sort by file name extension */ 112static const int SORT_EXT = 8; /* sort by file name extension */
111#define SORT_DIR 9 /* sort by file or directory */ 113static const int SORT_DIR = 9; /* sort by file or directory */
112#endif 114#endif
113 115
114#ifdef BB_FEATURE_LS_TIMESTAMPS 116#ifdef BB_FEATURE_LS_TIMESTAMPS
115/* which of the three times will be used */ 117/* which of the three times will be used */
116#define TIME_MOD 0 118static const int TIME_MOD = 0;
117#define TIME_CHANGE 1 119static const int TIME_CHANGE = 1;
118#define TIME_ACCESS 2 120static const int TIME_ACCESS = 2;
119#endif 121#endif
120 122
121#define LIST_SHORT (LIST_FILENAME) 123#define LIST_SHORT (LIST_FILENAME)
@@ -125,9 +127,9 @@
125 LIST_SYMLINK) 127 LIST_SYMLINK)
126#define LIST_ILONG (LIST_INO | LIST_LONG) 128#define LIST_ILONG (LIST_INO | LIST_LONG)
127 129
128#define SPLIT_DIR 0 130static const int SPLIT_DIR = 0;
129#define SPLIT_FILE 1 131static const int SPLIT_FILE = 1;
130#define SPLIT_SUBDIR 2 132static const int SPLIT_SUBDIR = 2;
131 133
132#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) 134#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
133#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) 135#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
@@ -150,15 +152,15 @@ struct dnode **list_dir(char *);
150struct dnode **dnalloc(int); 152struct dnode **dnalloc(int);
151int list_single(struct dnode *); 153int list_single(struct dnode *);
152 154
153static unsigned int disp_opts= DISP_NORMAL; 155static unsigned int disp_opts;
154static unsigned int style_fmt= STYLE_AUTO ; 156static unsigned int style_fmt;
155static unsigned int list_fmt= LIST_SHORT ; 157static unsigned int list_fmt;
156#ifdef BB_FEATURE_LS_SORTFILES 158#ifdef BB_FEATURE_LS_SORTFILES
157static unsigned int sort_opts= SORT_FORWARD; 159static unsigned int sort_opts;
158static unsigned int sort_order= SORT_FORWARD; 160static unsigned int sort_order;
159#endif 161#endif
160#ifdef BB_FEATURE_LS_TIMESTAMPS 162#ifdef BB_FEATURE_LS_TIMESTAMPS
161static unsigned int time_fmt= TIME_MOD; 163static unsigned int time_fmt;
162#endif 164#endif
163#ifdef BB_FEATURE_LS_FOLLOWLINKS 165#ifdef BB_FEATURE_LS_FOLLOWLINKS
164static unsigned int follow_links=FALSE; 166static unsigned int follow_links=FALSE;
@@ -166,12 +168,9 @@ static unsigned int follow_links=FALSE;
166 168
167static unsigned short column = 0; 169static unsigned short column = 0;
168#ifdef BB_FEATURE_AUTOWIDTH 170#ifdef BB_FEATURE_AUTOWIDTH
169static unsigned short terminal_width = TERMINAL_WIDTH; 171static unsigned short terminal_width;
170static unsigned short column_width = COLUMN_WIDTH; 172static unsigned short column_width;
171static unsigned short tabstops = 8; 173static unsigned short tabstops;
172#else
173#define terminal_width TERMINAL_WIDTH
174#define column_width COLUMN_WIDTH
175#endif 174#endif
176 175
177static int status = EXIT_SUCCESS; 176static int status = EXIT_SUCCESS;
@@ -710,10 +709,16 @@ extern int ls_main(int argc, char **argv)
710 list_fmt= LIST_SHORT; 709 list_fmt= LIST_SHORT;
711#ifdef BB_FEATURE_LS_SORTFILES 710#ifdef BB_FEATURE_LS_SORTFILES
712 sort_opts= SORT_NAME; 711 sort_opts= SORT_NAME;
712 sort_order= SORT_FORWARD;
713#endif 713#endif
714#ifdef BB_FEATURE_LS_TIMESTAMPS 714#ifdef BB_FEATURE_LS_TIMESTAMPS
715 time_fmt= TIME_MOD; 715 time_fmt= TIME_MOD;
716#endif 716#endif
717#ifdef BB_FEATURE_AUTOWIDTH
718 terminal_width = TERMINAL_WIDTH;
719 column_width = COLUMN_WIDTH;
720 tabstops = 8;
721#endif
717 nfiles=0; 722 nfiles=0;
718 723
719 /* process options */ 724 /* process options */