diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-12-19 07:06:44 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-12-19 07:06:44 +0100 |
commit | 2f7d9e8903029b1b5e51a15f9cb0dcb6ca17c3ac (patch) | |
tree | 91a8a24915d4c80e8f9e44c391b6fc70ce7d25a8 /coreutils | |
parent | 163d86435729cc53d6d4088129f2cde106dd1318 (diff) | |
download | busybox-w32-2f7d9e8903029b1b5e51a15f9cb0dcb6ca17c3ac.tar.gz busybox-w32-2f7d9e8903029b1b5e51a15f9cb0dcb6ca17c3ac.tar.bz2 busybox-w32-2f7d9e8903029b1b5e51a15f9cb0dcb6ca17c3ac.zip |
ls: print a space after each column. Closes bug 2941
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/ls.c | 83 |
1 files changed, 72 insertions, 11 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 02e26bedb..7bc7b28c8 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -29,6 +29,70 @@ | |||
29 | * [2009-03] | 29 | * [2009-03] |
30 | * ls sorts listing now, and supports almost all options. | 30 | * ls sorts listing now, and supports almost all options. |
31 | */ | 31 | */ |
32 | |||
33 | //usage:#define ls_trivial_usage | ||
34 | //usage: "[-1AaCxd" | ||
35 | //usage: IF_FEATURE_LS_FOLLOWLINKS("L") | ||
36 | //usage: IF_FEATURE_LS_RECURSIVE("R") | ||
37 | //usage: IF_FEATURE_LS_FILETYPES("Fp") "lins" | ||
38 | //usage: IF_FEATURE_LS_TIMESTAMPS("e") | ||
39 | //usage: IF_FEATURE_HUMAN_READABLE("h") | ||
40 | //usage: IF_FEATURE_LS_SORTFILES("rSXv") | ||
41 | //usage: IF_FEATURE_LS_TIMESTAMPS("ctu") | ||
42 | //usage: IF_SELINUX("kKZ") "]" | ||
43 | //usage: IF_FEATURE_AUTOWIDTH(" -w WIDTH") " [FILE]..." | ||
44 | //usage:#define ls_full_usage "\n\n" | ||
45 | //usage: "List directory contents\n" | ||
46 | //usage: "\nOptions:" | ||
47 | //usage: "\n -1 List in a single column" | ||
48 | //usage: "\n -A Don't list . and .." | ||
49 | //usage: "\n -a Don't hide entries starting with ." | ||
50 | //usage: "\n -C List by columns" | ||
51 | //usage: "\n -x List by lines" | ||
52 | //usage: "\n -d List directory entries instead of contents" | ||
53 | //usage: IF_FEATURE_LS_FOLLOWLINKS( | ||
54 | //usage: "\n -L List entries pointed to by symlinks" | ||
55 | //usage: ) | ||
56 | //usage: IF_FEATURE_LS_RECURSIVE( | ||
57 | //usage: "\n -R Recurse" | ||
58 | //usage: ) | ||
59 | //usage: IF_FEATURE_LS_FILETYPES( | ||
60 | //usage: "\n -F Append indicator (one of */=@|) to entries" | ||
61 | //usage: "\n -p Append indicator (one of /=@|) to entries" | ||
62 | //usage: ) | ||
63 | //usage: "\n -l Long listing format" | ||
64 | //usage: "\n -i List inode numbers" | ||
65 | //usage: "\n -n List numeric UIDs and GIDs instead of names" | ||
66 | //usage: "\n -s List the size of each file, in blocks" | ||
67 | //usage: IF_FEATURE_LS_TIMESTAMPS( | ||
68 | //usage: "\n -e List full date and time" | ||
69 | //usage: ) | ||
70 | //usage: IF_FEATURE_HUMAN_READABLE( | ||
71 | //usage: "\n -h List sizes in human readable format (1K 243M 2G)" | ||
72 | //usage: ) | ||
73 | //usage: IF_FEATURE_LS_SORTFILES( | ||
74 | //usage: "\n -r Sort in reverse order" | ||
75 | //usage: "\n -S Sort by file size" | ||
76 | //usage: "\n -X Sort by extension" | ||
77 | //usage: "\n -v Sort by version" | ||
78 | //usage: ) | ||
79 | //usage: IF_FEATURE_LS_TIMESTAMPS( | ||
80 | //usage: "\n -c With -l: sort by ctime" | ||
81 | //usage: "\n -t With -l: sort by modification time" | ||
82 | //usage: "\n -u With -l: sort by access time" | ||
83 | //usage: ) | ||
84 | //usage: IF_SELINUX( | ||
85 | //usage: "\n -k List security context" | ||
86 | //usage: "\n -K List security context in long format" | ||
87 | //usage: "\n -Z List security context and permission" | ||
88 | //usage: ) | ||
89 | //usage: IF_FEATURE_AUTOWIDTH( | ||
90 | //usage: "\n -w N Assume the terminal is N columns wide" | ||
91 | //usage: ) | ||
92 | //usage: IF_FEATURE_LS_COLOR( | ||
93 | //usage: "\n --color[={always,never,auto}] Control coloring" | ||
94 | //usage: ) | ||
95 | |||
32 | #include "libbb.h" | 96 | #include "libbb.h" |
33 | #include "unicode.h" | 97 | #include "unicode.h" |
34 | 98 | ||
@@ -53,7 +117,6 @@ | |||
53 | 117 | ||
54 | enum { | 118 | enum { |
55 | TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */ | 119 | TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */ |
56 | COLUMN_GAP = 2, /* includes the file type char */ | ||
57 | 120 | ||
58 | /* what is the overall style of the listing */ | 121 | /* what is the overall style of the listing */ |
59 | STYLE_COLUMNAR = 1 << 21, /* many records per line */ | 122 | STYLE_COLUMNAR = 1 << 21, /* many records per line */ |
@@ -241,7 +304,6 @@ struct globals { | |||
241 | smallint exit_code; | 304 | smallint exit_code; |
242 | unsigned all_fmt; | 305 | unsigned all_fmt; |
243 | #if ENABLE_FEATURE_AUTOWIDTH | 306 | #if ENABLE_FEATURE_AUTOWIDTH |
244 | unsigned tabstops; // = COLUMN_GAP; | ||
245 | unsigned terminal_width; // = TERMINAL_WIDTH; | 307 | unsigned terminal_width; // = TERMINAL_WIDTH; |
246 | #endif | 308 | #endif |
247 | #if ENABLE_FEATURE_LS_TIMESTAMPS | 309 | #if ENABLE_FEATURE_LS_TIMESTAMPS |
@@ -258,11 +320,9 @@ enum { show_color = 0 }; | |||
258 | #define exit_code (G.exit_code ) | 320 | #define exit_code (G.exit_code ) |
259 | #define all_fmt (G.all_fmt ) | 321 | #define all_fmt (G.all_fmt ) |
260 | #if ENABLE_FEATURE_AUTOWIDTH | 322 | #if ENABLE_FEATURE_AUTOWIDTH |
261 | # define tabstops (G.tabstops ) | ||
262 | # define terminal_width (G.terminal_width) | 323 | # define terminal_width (G.terminal_width) |
263 | #else | 324 | #else |
264 | enum { | 325 | enum { |
265 | tabstops = COLUMN_GAP, | ||
266 | terminal_width = TERMINAL_WIDTH, | 326 | terminal_width = TERMINAL_WIDTH, |
267 | }; | 327 | }; |
268 | #endif | 328 | #endif |
@@ -270,7 +330,6 @@ enum { | |||
270 | #define INIT_G() do { \ | 330 | #define INIT_G() do { \ |
271 | /* we have to zero it out because of NOEXEC */ \ | 331 | /* we have to zero it out because of NOEXEC */ \ |
272 | memset(&G, 0, sizeof(G)); \ | 332 | memset(&G, 0, sizeof(G)); \ |
273 | IF_FEATURE_AUTOWIDTH(tabstops = COLUMN_GAP;) \ | ||
274 | IF_FEATURE_AUTOWIDTH(terminal_width = TERMINAL_WIDTH;) \ | 333 | IF_FEATURE_AUTOWIDTH(terminal_width = TERMINAL_WIDTH;) \ |
275 | IF_FEATURE_LS_TIMESTAMPS(time(¤t_time_t);) \ | 334 | IF_FEATURE_LS_TIMESTAMPS(time(¤t_time_t);) \ |
276 | } while (0) | 335 | } while (0) |
@@ -732,8 +791,8 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |||
732 | static void showfiles(struct dnode **dn, unsigned nfiles) | 791 | static void showfiles(struct dnode **dn, unsigned nfiles) |
733 | { | 792 | { |
734 | unsigned i, ncols, nrows, row, nc; | 793 | unsigned i, ncols, nrows, row, nc; |
735 | unsigned column = 0; | 794 | unsigned column; |
736 | unsigned nexttab = 0; | 795 | unsigned nexttab; |
737 | unsigned column_width = 0; /* used only by STYLE_COLUMNAR */ | 796 | unsigned column_width = 0; /* used only by STYLE_COLUMNAR */ |
738 | 797 | ||
739 | if (all_fmt & STYLE_LONG) { /* STYLE_LONG or STYLE_SINGLE */ | 798 | if (all_fmt & STYLE_LONG) { /* STYLE_LONG or STYLE_SINGLE */ |
@@ -745,7 +804,7 @@ static void showfiles(struct dnode **dn, unsigned nfiles) | |||
745 | if (column_width < len) | 804 | if (column_width < len) |
746 | column_width = len; | 805 | column_width = len; |
747 | } | 806 | } |
748 | column_width += tabstops + | 807 | column_width += 1 + |
749 | IF_SELINUX( ((all_fmt & LIST_CONTEXT) ? 33 : 0) + ) | 808 | IF_SELINUX( ((all_fmt & LIST_CONTEXT) ? 33 : 0) + ) |
750 | ((all_fmt & LIST_INO) ? 8 : 0) + | 809 | ((all_fmt & LIST_INO) ? 8 : 0) + |
751 | ((all_fmt & LIST_BLOCKS) ? 5 : 0); | 810 | ((all_fmt & LIST_BLOCKS) ? 5 : 0); |
@@ -761,6 +820,8 @@ static void showfiles(struct dnode **dn, unsigned nfiles) | |||
761 | ncols = 1; | 820 | ncols = 1; |
762 | } | 821 | } |
763 | 822 | ||
823 | column = 0; | ||
824 | nexttab = 0; | ||
764 | for (row = 0; row < nrows; row++) { | 825 | for (row = 0; row < nrows; row++) { |
765 | for (nc = 0; nc < ncols; nc++) { | 826 | for (nc = 0; nc < ncols; nc++) { |
766 | /* reach into the array based on the column and row */ | 827 | /* reach into the array based on the column and row */ |
@@ -771,8 +832,8 @@ static void showfiles(struct dnode **dn, unsigned nfiles) | |||
771 | if (i < nfiles) { | 832 | if (i < nfiles) { |
772 | if (column > 0) { | 833 | if (column > 0) { |
773 | nexttab -= column; | 834 | nexttab -= column; |
774 | printf("%*s", nexttab, ""); | 835 | printf("%*s ", nexttab, ""); |
775 | column += nexttab; | 836 | column += nexttab + 1; |
776 | } | 837 | } |
777 | nexttab = column + column_width; | 838 | nexttab = column + column_width; |
778 | column += list_single(dn[i]); | 839 | column += list_single(dn[i]); |
@@ -993,7 +1054,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
993 | /* -T NUM, -w NUM: */ | 1054 | /* -T NUM, -w NUM: */ |
994 | IF_FEATURE_AUTOWIDTH(":T+:w+"); | 1055 | IF_FEATURE_AUTOWIDTH(":T+:w+"); |
995 | opt = getopt32(argv, ls_options | 1056 | opt = getopt32(argv, ls_options |
996 | IF_FEATURE_AUTOWIDTH(, &tabstops, &terminal_width) | 1057 | IF_FEATURE_AUTOWIDTH(, NULL, &terminal_width) |
997 | IF_FEATURE_LS_COLOR(, &color_opt) | 1058 | IF_FEATURE_LS_COLOR(, &color_opt) |
998 | ); | 1059 | ); |
999 | for (i = 0; opt_flags[i] != (1U<<31); i++) { | 1060 | for (i = 0; opt_flags[i] != (1U<<31); i++) { |