diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-01-30 18:03:11 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-01-30 18:03:11 +0000 |
commit | e57d54b456bf091aded43fc95bee9b05e7461dd0 (patch) | |
tree | ab02892c3929a64304d457f6857a68e01efea145 /ls.c | |
parent | 201dc0d5a99b8ef765f2b79e6a492a70772a0774 (diff) | |
download | busybox-w32-e57d54b456bf091aded43fc95bee9b05e7461dd0.tar.gz busybox-w32-e57d54b456bf091aded43fc95bee9b05e7461dd0.tar.bz2 busybox-w32-e57d54b456bf091aded43fc95bee9b05e7461dd0.zip |
Fix ls behavior for broken or very narrow terminals. Fix my_*
functions so they comply with the original interface (i.e. don't
exit on error, stringify uids and gids when no amtching name found).
-Erik
Diffstat (limited to 'ls.c')
-rw-r--r-- | ls.c | 42 |
1 files changed, 25 insertions, 17 deletions
@@ -41,9 +41,12 @@ | |||
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 | static const int TERMINAL_WIDTH = 80; /* use 79 if your terminal has linefold bug */ | 44 | enum { |
45 | static const int COLUMN_WIDTH = 14; /* default if AUTOWIDTH not defined */ | 45 | TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */ |
46 | static const int COLUMN_GAP = 2; /* includes the file type char, if present */ | 46 | COLUMN_WIDTH = 14, /* default if AUTOWIDTH not defined */ |
47 | COLUMN_GAP = 2, /* includes the file type char */ | ||
48 | }; | ||
49 | |||
47 | 50 | ||
48 | /************************************************************************/ | 51 | /************************************************************************/ |
49 | 52 | ||
@@ -173,9 +176,9 @@ static unsigned int follow_links=FALSE; | |||
173 | 176 | ||
174 | static unsigned short column = 0; | 177 | static unsigned short column = 0; |
175 | #ifdef BB_FEATURE_AUTOWIDTH | 178 | #ifdef BB_FEATURE_AUTOWIDTH |
176 | static unsigned short terminal_width; | 179 | static unsigned short terminal_width = TERMINAL_WIDTH; |
177 | static unsigned short column_width; | 180 | static unsigned short column_width = COLUMN_WIDTH; |
178 | static unsigned short tabstops; | 181 | static unsigned short tabstops = COLUMN_GAP; |
179 | #else | 182 | #else |
180 | static unsigned short column_width = COLUMN_WIDTH; | 183 | static unsigned short column_width = COLUMN_WIDTH; |
181 | #endif | 184 | #endif |
@@ -434,9 +437,15 @@ void showfiles(struct dnode **dn, int nfiles) | |||
434 | ((list_fmt & LIST_INO) ? 8 : 0) + | 437 | ((list_fmt & LIST_INO) ? 8 : 0) + |
435 | ((list_fmt & LIST_BLOCKS) ? 5 : 0) | 438 | ((list_fmt & LIST_BLOCKS) ? 5 : 0) |
436 | ; | 439 | ; |
437 | if (column_width < len) column_width= len; | 440 | if (column_width < len) |
441 | column_width= len; | ||
442 | } | ||
443 | if (column_width >= 6) | ||
444 | ncols = (int)(terminal_width / (column_width + COLUMN_GAP)); | ||
445 | else { | ||
446 | ncols = 1; | ||
447 | column_width = COLUMN_WIDTH; | ||
438 | } | 448 | } |
439 | ncols= (int)(terminal_width / (column_width + COLUMN_GAP)); | ||
440 | #else | 449 | #else |
441 | ncols= TERMINAL_WIDTH; | 450 | ncols= TERMINAL_WIDTH; |
442 | #endif | 451 | #endif |
@@ -447,7 +456,12 @@ void showfiles(struct dnode **dn, int nfiles) | |||
447 | break; | 456 | break; |
448 | } | 457 | } |
449 | 458 | ||
450 | nrows= nfiles / ncols; | 459 | if (ncols > 1) { |
460 | nrows = nfiles / ncols; | ||
461 | } else { | ||
462 | nrows = nfiles; | ||
463 | ncols = 1; | ||
464 | } | ||
451 | if ((nrows * ncols) < nfiles) nrows++; /* round up fractionals */ | 465 | if ((nrows * ncols) < nfiles) nrows++; /* round up fractionals */ |
452 | 466 | ||
453 | if (nrows > nfiles) nrows= nfiles; | 467 | if (nrows > nfiles) nrows= nfiles; |
@@ -617,15 +631,9 @@ int list_single(struct dnode *dn) | |||
617 | case LIST_ID_NAME: | 631 | case LIST_ID_NAME: |
618 | #ifdef BB_FEATURE_LS_USERNAME | 632 | #ifdef BB_FEATURE_LS_USERNAME |
619 | my_getpwuid(scratch, dn->dstat.st_uid); | 633 | my_getpwuid(scratch, dn->dstat.st_uid); |
620 | if (*scratch) | 634 | printf("%-8.8s ", scratch); |
621 | printf("%-8.8s ", scratch); | ||
622 | else | ||
623 | printf("%-8d ", dn->dstat.st_uid); | ||
624 | my_getgrgid(scratch, dn->dstat.st_gid); | 635 | my_getgrgid(scratch, dn->dstat.st_gid); |
625 | if (*scratch) | 636 | printf("%-8.8s", scratch); |
626 | printf("%-8.8s", scratch); | ||
627 | else | ||
628 | printf("%-8d", dn->dstat.st_gid); | ||
629 | column += 17; | 637 | column += 17; |
630 | break; | 638 | break; |
631 | #endif | 639 | #endif |