diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
commit | e49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch) | |
tree | c90bda10731ad9333ce3b404f993354c9fc104b8 /coreutils/ls.c | |
parent | c0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff) | |
download | busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2 busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip |
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r-- | coreutils/ls.c | 297 |
1 files changed, 168 insertions, 129 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 450ea1814..f23c1e086 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * tiny-ls.c version 0.1.0: A minimalist 'ls' | 3 | * tiny-ls.c version 0.1.0: A minimalist 'ls' |
3 | * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> | 4 | * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> |
@@ -40,18 +41,18 @@ | |||
40 | * 1. requires lstat (BSD) - how do you do it without? | 41 | * 1. requires lstat (BSD) - how do you do it without? |
41 | */ | 42 | */ |
42 | 43 | ||
43 | #define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */ | 44 | #define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */ |
44 | #define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */ | 45 | #define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */ |
45 | #define COLUMN_GAP 2 /* includes the file type char, if present */ | 46 | #define COLUMN_GAP 2 /* includes the file type char, if present */ |
46 | #define HAS_REWINDDIR | 47 | #define HAS_REWINDDIR |
47 | 48 | ||
48 | /************************************************************************/ | 49 | /************************************************************************/ |
49 | 50 | ||
50 | #include "internal.h" | 51 | #include "internal.h" |
51 | #if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | 52 | #if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
52 | # include <linux/types.h> | 53 | # include <linux/types.h> |
53 | #else | 54 | #else |
54 | # include <sys/types.h> | 55 | # include <sys/types.h> |
55 | #endif | 56 | #endif |
56 | #include <sys/stat.h> | 57 | #include <sys/stat.h> |
57 | #include <stdio.h> | 58 | #include <stdio.h> |
@@ -75,28 +76,28 @@ | |||
75 | #endif | 76 | #endif |
76 | 77 | ||
77 | #define FMT_AUTO 0 | 78 | #define FMT_AUTO 0 |
78 | #define FMT_LONG 1 /* one record per line, extended info */ | 79 | #define FMT_LONG 1 /* one record per line, extended info */ |
79 | #define FMT_SINGLE 2 /* one record per line */ | 80 | #define FMT_SINGLE 2 /* one record per line */ |
80 | #define FMT_ROWS 3 /* print across rows */ | 81 | #define FMT_ROWS 3 /* print across rows */ |
81 | #define FMT_COLUMNS 3 /* fill columns (same, since we don't sort) */ | 82 | #define FMT_COLUMNS 3 /* fill columns (same, since we don't sort) */ |
82 | 83 | ||
83 | #define TIME_MOD 0 | 84 | #define TIME_MOD 0 |
84 | #define TIME_CHANGE 1 | 85 | #define TIME_CHANGE 1 |
85 | #define TIME_ACCESS 2 | 86 | #define TIME_ACCESS 2 |
86 | 87 | ||
87 | #define DISP_FTYPE 1 /* show character for file type */ | 88 | #define DISP_FTYPE 1 /* show character for file type */ |
88 | #define DISP_EXEC 2 /* show '*' if regular executable file */ | 89 | #define DISP_EXEC 2 /* show '*' if regular executable file */ |
89 | #define DISP_HIDDEN 4 /* show files starting . (except . and ..) */ | 90 | #define DISP_HIDDEN 4 /* show files starting . (except . and ..) */ |
90 | #define DISP_DOT 8 /* show . and .. */ | 91 | #define DISP_DOT 8 /* show . and .. */ |
91 | #define DISP_NUMERIC 16 /* numeric uid and gid */ | 92 | #define DISP_NUMERIC 16 /* numeric uid and gid */ |
92 | #define DISP_FULLTIME 32 /* show extended time display */ | 93 | #define DISP_FULLTIME 32 /* show extended time display */ |
93 | #define DIR_NOLIST 64 /* show directory as itself, not contents */ | 94 | #define DIR_NOLIST 64 /* show directory as itself, not contents */ |
94 | #define DISP_DIRNAME 128 /* show directory name (for internal use) */ | 95 | #define DISP_DIRNAME 128 /* show directory name (for internal use) */ |
95 | #define DIR_RECURSE 256 /* -R (not yet implemented) */ | 96 | #define DIR_RECURSE 256 /* -R (not yet implemented) */ |
96 | 97 | ||
97 | static unsigned char display_fmt = FMT_AUTO; | 98 | static unsigned char display_fmt = FMT_AUTO; |
98 | static unsigned short opts = 0; | 99 | static unsigned short opts = 0; |
99 | static unsigned short column = 0; | 100 | static unsigned short column = 0; |
100 | 101 | ||
101 | #ifdef BB_FEATURE_AUTOWIDTH | 102 | #ifdef BB_FEATURE_AUTOWIDTH |
102 | static unsigned short terminal_width = 0, column_width = 0; | 103 | static unsigned short terminal_width = 0, column_width = 0; |
@@ -113,13 +114,14 @@ static unsigned char time_fmt = TIME_MOD; | |||
113 | 114 | ||
114 | static void writenum(long val, short minwidth) | 115 | static void writenum(long val, short minwidth) |
115 | { | 116 | { |
116 | char scratch[128]; | 117 | char scratch[128]; |
117 | 118 | ||
118 | char *p = scratch + sizeof(scratch); | 119 | char *p = scratch + sizeof(scratch); |
119 | short len = 0; | 120 | short len = 0; |
120 | short neg = (val < 0); | 121 | short neg = (val < 0); |
121 | 122 | ||
122 | if (neg) val = -val; | 123 | if (neg) |
124 | val = -val; | ||
123 | do | 125 | do |
124 | *--p = (val % 10) + '0', len++, val /= 10; | 126 | *--p = (val % 10) + '0', len++, val /= 10; |
125 | while (val); | 127 | while (val); |
@@ -142,8 +144,9 @@ static void newline(void) | |||
142 | static void tab(short col) | 144 | static void tab(short col) |
143 | { | 145 | { |
144 | static const char spaces[] = " "; | 146 | static const char spaces[] = " "; |
145 | #define nspaces ((sizeof spaces)-1) /* null terminator! */ | 147 | |
146 | 148 | #define nspaces ((sizeof spaces)-1) /* null terminator! */ | |
149 | |||
147 | short n = col - column; | 150 | short n = col - column; |
148 | 151 | ||
149 | if (n > 0) { | 152 | if (n > 0) { |
@@ -155,7 +158,7 @@ static void tab(short col) | |||
155 | /* must be 1...(sizeof spaces) left */ | 158 | /* must be 1...(sizeof spaces) left */ |
156 | wr(spaces, n); | 159 | wr(spaces, n); |
157 | } | 160 | } |
158 | #undef nspaces | 161 | #undef nspaces |
159 | } | 162 | } |
160 | 163 | ||
161 | #ifdef BB_FEATURE_LS_FILETYPES | 164 | #ifdef BB_FEATURE_LS_FILETYPES |
@@ -163,8 +166,8 @@ static char append_char(mode_t mode) | |||
163 | { | 166 | { |
164 | if (!(opts & DISP_FTYPE)) | 167 | if (!(opts & DISP_FTYPE)) |
165 | return '\0'; | 168 | return '\0'; |
166 | if ((opts & DISP_EXEC) && S_ISREG(mode) && (mode & (S_IXUSR|S_IXGRP|S_IXOTH))) | 169 | if ((opts & DISP_EXEC) && S_ISREG(mode) |
167 | return '*'; | 170 | && (mode & (S_IXUSR | S_IXGRP | S_IXOTH))) return '*'; |
168 | return APPCHAR(mode); | 171 | return APPCHAR(mode); |
169 | } | 172 | } |
170 | #endif | 173 | #endif |
@@ -176,89 +179,93 @@ static char append_char(mode_t mode) | |||
176 | ** | 179 | ** |
177 | **/ | 180 | **/ |
178 | 181 | ||
179 | static void list_single(const char *name, struct stat *info, const char *fullname) | 182 | static void list_single(const char *name, struct stat *info, |
183 | const char *fullname) | ||
180 | { | 184 | { |
181 | char scratch[PATH_MAX + 1]; | 185 | char scratch[PATH_MAX + 1]; |
182 | short len = strlen(name); | 186 | short len = strlen(name); |
187 | |||
183 | #ifdef BB_FEATURE_LS_FILETYPES | 188 | #ifdef BB_FEATURE_LS_FILETYPES |
184 | char append = append_char(info->st_mode); | 189 | char append = append_char(info->st_mode); |
185 | #endif | 190 | #endif |
186 | 191 | ||
187 | if (display_fmt == FMT_LONG) { | 192 | if (display_fmt == FMT_LONG) { |
188 | mode_t mode = info->st_mode; | 193 | mode_t mode = info->st_mode; |
194 | |||
189 | newline(); | 195 | newline(); |
190 | wr(modeString(mode), 10); | 196 | wr(modeString(mode), 10); |
191 | column=10; | 197 | column = 10; |
192 | writenum((long)info->st_nlink,(short)5); | 198 | writenum((long) info->st_nlink, (short) 5); |
193 | fputs(" ", stdout); | 199 | fputs(" ", stdout); |
194 | #ifdef BB_FEATURE_LS_USERNAME | 200 | #ifdef BB_FEATURE_LS_USERNAME |
195 | if (!(opts & DISP_NUMERIC)) { | 201 | if (!(opts & DISP_NUMERIC)) { |
196 | memset ( scratch, 0, sizeof (scratch)); | 202 | memset(scratch, 0, sizeof(scratch)); |
197 | my_getpwuid( scratch, info->st_uid); | 203 | my_getpwuid(scratch, info->st_uid); |
198 | if (*scratch) { | 204 | if (*scratch) { |
199 | fputs(scratch, stdout); | 205 | fputs(scratch, stdout); |
200 | if ( strlen( scratch) <= 8 ) | 206 | if (strlen(scratch) <= 8) |
201 | wr(" ", 9-strlen( scratch)); | 207 | wr(" ", 9 - strlen(scratch)); |
202 | } | 208 | } else { |
203 | else { | 209 | writenum((long) info->st_uid, (short) 8); |
204 | writenum((long) info->st_uid,(short)8); | ||
205 | fputs(" ", stdout); | 210 | fputs(" ", stdout); |
206 | } | 211 | } |
207 | } else | 212 | } else |
208 | #endif | 213 | #endif |
209 | { | 214 | { |
210 | writenum((long) info->st_uid,(short)8); | 215 | writenum((long) info->st_uid, (short) 8); |
211 | fputs(" ", stdout); | 216 | fputs(" ", stdout); |
212 | } | 217 | } |
213 | #ifdef BB_FEATURE_LS_USERNAME | 218 | #ifdef BB_FEATURE_LS_USERNAME |
214 | if (!(opts & DISP_NUMERIC)) { | 219 | if (!(opts & DISP_NUMERIC)) { |
215 | memset ( scratch, 0, sizeof (scratch)); | 220 | memset(scratch, 0, sizeof(scratch)); |
216 | my_getgrgid( scratch, info->st_gid); | 221 | my_getgrgid(scratch, info->st_gid); |
217 | if (*scratch) { | 222 | if (*scratch) { |
218 | fputs(scratch, stdout); | 223 | fputs(scratch, stdout); |
219 | if ( strlen( scratch) <= 8 ) | 224 | if (strlen(scratch) <= 8) |
220 | wr(" ", 8-strlen( scratch)); | 225 | wr(" ", 8 - strlen(scratch)); |
221 | } | 226 | } else |
222 | else | 227 | writenum((long) info->st_gid, (short) 8); |
223 | writenum((long) info->st_gid,(short)8); | ||
224 | } else | 228 | } else |
225 | #endif | 229 | #endif |
226 | writenum((long) info->st_gid,(short)8); | 230 | writenum((long) info->st_gid, (short) 8); |
227 | //tab(26); | 231 | //tab(26); |
228 | if (S_ISBLK(mode) || S_ISCHR(mode)) { | 232 | if (S_ISBLK(mode) || S_ISCHR(mode)) { |
229 | writenum((long)MAJOR(info->st_rdev),(short)3); | 233 | writenum((long) MAJOR(info->st_rdev), (short) 3); |
230 | fputs(", ", stdout); | 234 | fputs(", ", stdout); |
231 | writenum((long)MINOR(info->st_rdev),(short)3); | 235 | writenum((long) MINOR(info->st_rdev), (short) 3); |
232 | } | 236 | } else |
233 | else | 237 | writenum((long) info->st_size, (short) 8); |
234 | writenum((long)info->st_size,(short)8); | ||
235 | fputs(" ", stdout); | 238 | fputs(" ", stdout); |
236 | //tab(32); | 239 | //tab(32); |
237 | #ifdef BB_FEATURE_LS_TIMESTAMPS | 240 | #ifdef BB_FEATURE_LS_TIMESTAMPS |
238 | { | 241 | { |
239 | time_t cal; | 242 | time_t cal; |
240 | char *string; | 243 | char *string; |
241 | 244 | ||
242 | switch(time_fmt) { | 245 | switch (time_fmt) { |
243 | case TIME_CHANGE: | 246 | case TIME_CHANGE: |
244 | cal=info->st_ctime; break; | 247 | cal = info->st_ctime; |
248 | break; | ||
245 | case TIME_ACCESS: | 249 | case TIME_ACCESS: |
246 | cal=info->st_atime; break; | 250 | cal = info->st_atime; |
251 | break; | ||
247 | default: | 252 | default: |
248 | cal=info->st_mtime; break; | 253 | cal = info->st_mtime; |
254 | break; | ||
249 | } | 255 | } |
250 | string=ctime(&cal); | 256 | string = ctime(&cal); |
251 | if (opts & DISP_FULLTIME) | 257 | if (opts & DISP_FULLTIME) |
252 | wr(string,24); | 258 | wr(string, 24); |
253 | else { | 259 | else { |
254 | time_t age = time(NULL) - cal; | 260 | time_t age = time(NULL) - cal; |
255 | wr(string+4,7); /* mmm_dd_ */ | 261 | |
256 | if(age < 3600L*24*365/2 && age > -15*60) | 262 | wr(string + 4, 7); /* mmm_dd_ */ |
263 | if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) | ||
257 | /* hh:mm if less than 6 months old */ | 264 | /* hh:mm if less than 6 months old */ |
258 | wr(string+11,5); | 265 | wr(string + 11, 5); |
259 | else | 266 | else |
260 | /* _yyyy otherwise */ | 267 | /* _yyyy otherwise */ |
261 | wr(string+19,5); | 268 | wr(string + 19, 5); |
262 | } | 269 | } |
263 | wr(" ", 1); | 270 | wr(" ", 1); |
264 | } | 271 | } |
@@ -269,7 +276,8 @@ static void list_single(const char *name, struct stat *info, const char *fullnam | |||
269 | if (S_ISLNK(mode)) { | 276 | if (S_ISLNK(mode)) { |
270 | wr(" -> ", 4); | 277 | wr(" -> ", 4); |
271 | len = readlink(fullname, scratch, sizeof scratch); | 278 | len = readlink(fullname, scratch, sizeof scratch); |
272 | if (len > 0) fwrite(scratch, 1, len, stdout); | 279 | if (len > 0) |
280 | fwrite(scratch, 1, len, stdout); | ||
273 | #ifdef BB_FEATURE_LS_FILETYPES | 281 | #ifdef BB_FEATURE_LS_FILETYPES |
274 | /* show type of destination */ | 282 | /* show type of destination */ |
275 | if (opts & DISP_FTYPE) { | 283 | if (opts & DISP_FTYPE) { |
@@ -287,18 +295,17 @@ static void list_single(const char *name, struct stat *info, const char *fullnam | |||
287 | #endif | 295 | #endif |
288 | } else { | 296 | } else { |
289 | static short nexttab = 0; | 297 | static short nexttab = 0; |
290 | 298 | ||
291 | /* sort out column alignment */ | 299 | /* sort out column alignment */ |
292 | if (column == 0) | 300 | if (column == 0); /* nothing to do */ |
293 | ; /* nothing to do */ | ||
294 | else if (display_fmt == FMT_SINGLE) | 301 | else if (display_fmt == FMT_SINGLE) |
295 | newline(); | 302 | newline(); |
296 | else { | 303 | else { |
297 | if (nexttab + column_width > terminal_width | 304 | if (nexttab + column_width > terminal_width |
298 | #ifndef BB_FEATURE_AUTOWIDTH | 305 | #ifndef BB_FEATURE_AUTOWIDTH |
299 | || nexttab + len >= terminal_width | 306 | || nexttab + len >= terminal_width |
300 | #endif | 307 | #endif |
301 | ) | 308 | ) |
302 | newline(); | 309 | newline(); |
303 | else | 310 | else |
304 | tab(nexttab); | 311 | tab(nexttab); |
@@ -336,32 +343,33 @@ static int list_item(const char *name) | |||
336 | struct stat info; | 343 | struct stat info; |
337 | DIR *dir; | 344 | DIR *dir; |
338 | struct dirent *entry; | 345 | struct dirent *entry; |
339 | char fullname[MAXNAMLEN+1], *fnend; | 346 | char fullname[MAXNAMLEN + 1], *fnend; |
340 | 347 | ||
341 | if (lstat(name, &info)) | 348 | if (lstat(name, &info)) |
342 | goto listerr; | 349 | goto listerr; |
343 | 350 | ||
344 | if (!S_ISDIR(info.st_mode) || | 351 | if (!S_ISDIR(info.st_mode) || (opts & DIR_NOLIST)) { |
345 | (opts & DIR_NOLIST)) { | ||
346 | list_single(name, &info, name); | 352 | list_single(name, &info, name); |
347 | return 0; | 353 | return 0; |
348 | } | 354 | } |
349 | 355 | ||
350 | /* Otherwise, it's a directory we want to list the contents of */ | 356 | /* Otherwise, it's a directory we want to list the contents of */ |
351 | 357 | ||
352 | if (opts & DISP_DIRNAME) { /* identify the directory */ | 358 | if (opts & DISP_DIRNAME) { /* identify the directory */ |
353 | if (column) | 359 | if (column) |
354 | wr("\n\n", 2), column = 0; | 360 | wr("\n\n", 2), column = 0; |
355 | wr(name, strlen(name)); | 361 | wr(name, strlen(name)); |
356 | wr(":\n", 2); | 362 | wr(":\n", 2); |
357 | } | 363 | } |
358 | 364 | ||
359 | dir = opendir(name); | 365 | dir = opendir(name); |
360 | if (!dir) goto listerr; | 366 | if (!dir) |
367 | goto listerr; | ||
361 | #ifdef BB_FEATURE_AUTOWIDTH | 368 | #ifdef BB_FEATURE_AUTOWIDTH |
362 | column_width = 0; | 369 | column_width = 0; |
363 | while ((entry = readdir(dir)) != NULL) { | 370 | while ((entry = readdir(dir)) != NULL) { |
364 | short w = strlen(entry->d_name); | 371 | short w = strlen(entry->d_name); |
372 | |||
365 | if (column_width < w) | 373 | if (column_width < w) |
366 | column_width = w; | 374 | column_width = w; |
367 | } | 375 | } |
@@ -370,39 +378,40 @@ static int list_item(const char *name) | |||
370 | #else | 378 | #else |
371 | closedir(dir); | 379 | closedir(dir); |
372 | dir = opendir(name); | 380 | dir = opendir(name); |
373 | if (!dir) goto listerr; | 381 | if (!dir) |
382 | goto listerr; | ||
374 | #endif | 383 | #endif |
375 | #endif | 384 | #endif |
376 | 385 | ||
377 | /* List the contents */ | 386 | /* List the contents */ |
378 | 387 | ||
379 | strcpy(fullname,name); /* *** ignore '.' by itself */ | 388 | strcpy(fullname, name); /* *** ignore '.' by itself */ |
380 | fnend=fullname+strlen(fullname); | 389 | fnend = fullname + strlen(fullname); |
381 | if (fnend[-1] != '/') | 390 | if (fnend[-1] != '/') |
382 | *fnend++ = '/'; | 391 | *fnend++ = '/'; |
383 | 392 | ||
384 | while ((entry = readdir(dir)) != NULL) { | 393 | while ((entry = readdir(dir)) != NULL) { |
385 | const char *en=entry->d_name; | 394 | const char *en = entry->d_name; |
395 | |||
386 | if (en[0] == '.') { | 396 | if (en[0] == '.') { |
387 | if (!en[1] || (en[1] == '.' && !en[2])) { /* . or .. */ | 397 | if (!en[1] || (en[1] == '.' && !en[2])) { /* . or .. */ |
388 | if (!(opts & DISP_DOT)) | 398 | if (!(opts & DISP_DOT)) |
389 | continue; | 399 | continue; |
390 | } | 400 | } else if (!(opts & DISP_HIDDEN)) |
391 | else if (!(opts & DISP_HIDDEN)) | ||
392 | continue; | 401 | continue; |
393 | } | 402 | } |
394 | /* FIXME: avoid stat if not required */ | 403 | /* FIXME: avoid stat if not required */ |
395 | strcpy(fnend, entry->d_name); | 404 | strcpy(fnend, entry->d_name); |
396 | if (lstat(fullname, &info)) | 405 | if (lstat(fullname, &info)) |
397 | goto direrr; /* (shouldn't fail) */ | 406 | goto direrr; /* (shouldn't fail) */ |
398 | list_single(entry->d_name, &info, fullname); | 407 | list_single(entry->d_name, &info, fullname); |
399 | } | 408 | } |
400 | closedir(dir); | 409 | closedir(dir); |
401 | return 0; | 410 | return 0; |
402 | 411 | ||
403 | direrr: | 412 | direrr: |
404 | closedir(dir); | 413 | closedir(dir); |
405 | listerr: | 414 | listerr: |
406 | newline(); | 415 | newline(); |
407 | perror(name); | 416 | perror(name); |
408 | return 1; | 417 | return 1; |
@@ -432,50 +441,79 @@ static const char ls_usage[] = "ls [-1a" | |||
432 | #endif | 441 | #endif |
433 | "] [filenames...]\n"; | 442 | "] [filenames...]\n"; |
434 | 443 | ||
435 | extern int | 444 | extern int ls_main(int argc, char **argv) |
436 | ls_main(int argc, char * * argv) | ||
437 | { | 445 | { |
438 | int argi=1, i; | 446 | int argi = 1, i; |
439 | 447 | ||
440 | /* process options */ | 448 | /* process options */ |
441 | while (argi < argc && argv[argi][0] == '-') { | 449 | while (argi < argc && argv[argi][0] == '-') { |
442 | const char *p = &argv[argi][1]; | 450 | const char *p = &argv[argi][1]; |
443 | 451 | ||
444 | if (!*p) goto print_usage_message; /* "-" by itself not allowed */ | 452 | if (!*p) |
453 | goto print_usage_message; /* "-" by itself not allowed */ | ||
445 | if (*p == '-') { | 454 | if (*p == '-') { |
446 | if (!p[1]) { /* "--" forces end of options */ | 455 | if (!p[1]) { /* "--" forces end of options */ |
447 | argi++; | 456 | argi++; |
448 | break; | 457 | break; |
449 | } | 458 | } |
450 | /* it's a long option name - we don't support them */ | 459 | /* it's a long option name - we don't support them */ |
451 | goto print_usage_message; | 460 | goto print_usage_message; |
452 | } | 461 | } |
453 | 462 | ||
454 | while (*p) | 463 | while (*p) |
455 | switch (*p++) { | 464 | switch (*p++) { |
456 | case 'l': display_fmt = FMT_LONG; break; | 465 | case 'l': |
457 | case '1': display_fmt = FMT_SINGLE; break; | 466 | display_fmt = FMT_LONG; |
458 | case 'x': display_fmt = FMT_ROWS; break; | 467 | break; |
459 | case 'C': display_fmt = FMT_COLUMNS; break; | 468 | case '1': |
469 | display_fmt = FMT_SINGLE; | ||
470 | break; | ||
471 | case 'x': | ||
472 | display_fmt = FMT_ROWS; | ||
473 | break; | ||
474 | case 'C': | ||
475 | display_fmt = FMT_COLUMNS; | ||
476 | break; | ||
460 | #ifdef BB_FEATURE_LS_FILETYPES | 477 | #ifdef BB_FEATURE_LS_FILETYPES |
461 | case 'p': opts |= DISP_FTYPE; break; | 478 | case 'p': |
462 | case 'F': opts |= DISP_FTYPE|DISP_EXEC; break; | 479 | opts |= DISP_FTYPE; |
480 | break; | ||
481 | case 'F': | ||
482 | opts |= DISP_FTYPE | DISP_EXEC; | ||
483 | break; | ||
463 | #endif | 484 | #endif |
464 | case 'A': opts |= DISP_HIDDEN; break; | 485 | case 'A': |
465 | case 'a': opts |= DISP_HIDDEN|DISP_DOT; break; | 486 | opts |= DISP_HIDDEN; |
466 | case 'n': opts |= DISP_NUMERIC; break; | 487 | break; |
467 | case 'd': opts |= DIR_NOLIST; break; | 488 | case 'a': |
489 | opts |= DISP_HIDDEN | DISP_DOT; | ||
490 | break; | ||
491 | case 'n': | ||
492 | opts |= DISP_NUMERIC; | ||
493 | break; | ||
494 | case 'd': | ||
495 | opts |= DIR_NOLIST; | ||
496 | break; | ||
468 | #ifdef FEATURE_RECURSIVE | 497 | #ifdef FEATURE_RECURSIVE |
469 | case 'R': opts |= DIR_RECURSE; break; | 498 | case 'R': |
499 | opts |= DIR_RECURSE; | ||
500 | break; | ||
470 | #endif | 501 | #endif |
471 | #ifdef BB_FEATURE_LS_TIMESTAMPS | 502 | #ifdef BB_FEATURE_LS_TIMESTAMPS |
472 | case 'u': time_fmt = TIME_ACCESS; break; | 503 | case 'u': |
473 | case 'c': time_fmt = TIME_CHANGE; break; | 504 | time_fmt = TIME_ACCESS; |
474 | case 'e': opts |= DISP_FULLTIME; break; | 505 | break; |
506 | case 'c': | ||
507 | time_fmt = TIME_CHANGE; | ||
508 | break; | ||
509 | case 'e': | ||
510 | opts |= DISP_FULLTIME; | ||
511 | break; | ||
475 | #endif | 512 | #endif |
476 | default: goto print_usage_message; | 513 | default: |
514 | goto print_usage_message; | ||
477 | } | 515 | } |
478 | 516 | ||
479 | argi++; | 517 | argi++; |
480 | } | 518 | } |
481 | 519 | ||
@@ -483,29 +521,30 @@ ls_main(int argc, char * * argv) | |||
483 | if (display_fmt == FMT_AUTO) | 521 | if (display_fmt == FMT_AUTO) |
484 | display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE; | 522 | display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE; |
485 | if (argi < argc - 1) | 523 | if (argi < argc - 1) |
486 | opts |= DISP_DIRNAME; /* 2 or more items? label directories */ | 524 | opts |= DISP_DIRNAME; /* 2 or more items? label directories */ |
487 | #ifdef BB_FEATURE_AUTOWIDTH | 525 | #ifdef BB_FEATURE_AUTOWIDTH |
488 | /* could add a -w option and/or TIOCGWINSZ call */ | 526 | /* could add a -w option and/or TIOCGWINSZ call */ |
489 | if (terminal_width < 1) terminal_width = TERMINAL_WIDTH; | 527 | if (terminal_width < 1) |
490 | 528 | terminal_width = TERMINAL_WIDTH; | |
529 | |||
491 | for (i = argi; i < argc; i++) { | 530 | for (i = argi; i < argc; i++) { |
492 | int len = strlen(argv[i]); | 531 | int len = strlen(argv[i]); |
532 | |||
493 | if (column_width < len) | 533 | if (column_width < len) |
494 | column_width = len; | 534 | column_width = len; |
495 | } | 535 | } |
496 | #endif | 536 | #endif |
497 | 537 | ||
498 | /* process files specified, or current directory if none */ | 538 | /* process files specified, or current directory if none */ |
499 | i=0; | 539 | i = 0; |
500 | if (argi == argc) | 540 | if (argi == argc) |
501 | i = list_item("."); | 541 | i = list_item("."); |
502 | while (argi < argc) | 542 | while (argi < argc) |
503 | i |= list_item(argv[argi++]); | 543 | i |= list_item(argv[argi++]); |
504 | newline(); | 544 | newline(); |
505 | exit( i); | 545 | exit(i); |
506 | 546 | ||
507 | print_usage_message: | 547 | print_usage_message: |
508 | usage (ls_usage); | 548 | usage(ls_usage); |
509 | exit( FALSE); | 549 | exit(FALSE); |
510 | } | 550 | } |
511 | |||