sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit c2d89afa167aac2e040ac4d0c951e29955bf82b0
parent 25947af743fc68b00261d235aa692284c3921ae0
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Thu, 16 Jun 2011 01:13:46 +0100

ls: sort argv
Diffstat:
Mls.c | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/ls.c b/ls.c @@ -39,6 +39,8 @@ int main(int argc, char *argv[]) { char c; + int i, n; + Entry *ents; while((c = getopt(argc, argv, "adlt")) != -1) switch(c) { @@ -59,10 +61,17 @@ main(int argc, char *argv[]) } many = (argc > optind+1); - if(optind == argc) + if((n = argc - optind) > 0) { + if(!(ents = malloc((argc-1) * sizeof *ents))) + eprintf("malloc:"); + for(i = 0; i < n; i++) + mkent(&ents[i], argv[optind+i]); + qsort(ents, n, sizeof *ents, (int (*)(const void *, const void *))entcmp); + for(i = 0; i < n; i++) + ls(ents[i].name); + } + else ls("."); - else for(; optind < argc; optind++) - ls(argv[optind]); return EXIT_SUCCESS; } @@ -210,7 +219,7 @@ output(Entry *ent) fmt = "%b %d %H:%M"; strftime(buf, sizeof buf, fmt, localtime(&ent->mtime)); - printf("%s %2ld %s %s %6lu %s %s", mode, (long)ent->nlink, pw->pw_name, + printf("%s %2ld %-4s %-5s %6lu %s %s", mode, (long)ent->nlink, pw->pw_name, gr->gr_name, (unsigned long)ent->size, buf, ent->name); if(S_ISLNK(ent->mode)) { if((len = readlink(ent->name, buf, sizeof buf)) == -1)