From ce172e152e5918b08c6f91da6782eb214c285418 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 11 Mar 2008 21:41:56 +0100 Subject: add ls -c and -l --- commands/ls.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'commands/ls.c') diff --git a/commands/ls.c b/commands/ls.c index 276b5e2893..b9263e645a 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -27,6 +27,7 @@ #include #include #include +#include static void ls_one(const char *path, struct stat *s) { @@ -43,6 +44,9 @@ int ls(const char *path, ulong flags) struct dirent *d; char tmp[PATH_MAX]; struct stat s; + struct string_list sl; + + string_list_init(&sl); if (flags & LS_SHOWARG) printf("%s:\n", path); @@ -63,11 +67,19 @@ int ls(const char *path, ulong flags) sprintf(tmp, "%s/%s", path, d->d_name); if (stat(tmp, &s)) goto out; - ls_one(d->d_name, &s); + if (flags & LS_COLUMN) + string_list_add(&sl, d->d_name); + else + ls_one(d->d_name, &s); } closedir(dir); + if (flags & LS_COLUMN) { + string_list_print_by_column(&sl); + string_list_free(&sl); + } + if (!(flags & LS_RECURSIVE)) return 0; @@ -102,15 +114,21 @@ out: static int do_ls (cmd_tbl_t *cmdtp, int argc, char *argv[]) { int ret, opt; - ulong flags = 0; + ulong flags = LS_COLUMN; getopt_reset(); - while((opt = getopt(argc, argv, "R")) > 0) { + while((opt = getopt(argc, argv, "RCl")) > 0) { switch(opt) { case 'R': flags |= LS_RECURSIVE | LS_SHOWARG; break; + case 'C': + flags |= LS_COLUMN; + break; + case 'l': + flags &= ~LS_COLUMN; + break; } } -- cgit v1.2.3