[hackers] [sbase] Add the -F flag to ls || Daniel Bainton
commit 080db637f8f76fb1a433963c08248f574cd07db7
Author: Daniel Bainton <dpb_AT_driftaway.org>
Date: Mon Feb 17 14:41:09 2014 +0000
Add the -F flag to ls
diff --git a/ls.c b/ls.c
index f4433ae..bc6c463 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -31,6 +31,7 @@ static void output(Entry *);
static bool aflag = false;
static bool dflag = false;
+static bool Fflag = false;
static bool iflag = false;
static bool lflag = false;
static bool rflag = false;
_AT_@ -42,7 +43,7 @@ static bool many;
static void
usage(void)
{
- eprintf("usage: %s [-adilrtU] [FILE...]
", argv0);
+ eprintf("usage: %s [-adFilrtU] [FILE...]
", argv0);
}
int
_AT_@ -58,6 +59,9 @@ main(int argc, char *argv[])
case 'd':
dflag = true;
break;
+ case 'F':
+ Fflag = true;
+ break;
case 'i':
iflag = true;
break;
_AT_@ -140,7 +144,7 @@ lsdir(const char *path)
if(d->d_name[0] == '.' && !aflag)
continue;
if(Uflag){
- mkent(&ent, d->d_name, lflag || iflag);
+ mkent(&ent, d->d_name, Fflag || lflag || iflag);
output(&ent);
} else {
if(!(ents = realloc(ents, ++n * sizeof *ents)))
_AT_@ -148,7 +152,7 @@ lsdir(const char *path)
if(!(p = malloc((sz = strlen(d->d_name)+1))))
eprintf("malloc:");
memcpy(p, d->d_name, sz);
- mkent(&ents[n-1], p, tflag || lflag || iflag);
+ mkent(&ents[n-1], p, tflag || Fflag || lflag || iflag);
}
}
closedir(dp);
_AT_@ -184,6 +188,28 @@ mkent(Entry *ent, char *path, bool dostat)
ent->ino = st.st_ino;
}
+char *
+indicator(mode_t mode)
+{
+ if(!Fflag)
+ return "";
+
+ if(S_ISLNK(mode))
+ return "_AT_";
+ else if(S_ISDIR(mode))
+ return "/";
+ else if(S_ISFIFO(mode))
+ return "|";
+ else if(S_ISSOCK(mode))
+ return "=";
+ else if(mode & S_IXUSR ||
+ mode & S_IXGRP ||
+ mode & S_IXOTH)
+ return "*";
+ else
+ return "";
+}
+
void
output(Entry *ent)
{
_AT_@ -192,11 +218,12 @@ output(Entry *ent)
ssize_t len;
struct group *gr;
struct passwd *pw;
+ Entry entlnk;
if (iflag)
printf("%lu ", (unsigned long)ent->ino);
if(!lflag) {
- puts(ent->name);
+ printf("%s%s
", ent->name, indicator(ent->mode));
return;
}
if(S_ISREG(ent->mode))
_AT_@ -250,13 +277,14 @@ output(Entry *ent)
fmt = "%b %d %H:%M";
strftime(buf, sizeof buf, fmt, localtime(&ent->mtime));
- 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);
+ printf("%s %2ld %-4s %-5s %6lu %s %s%s", mode, (long)ent->nlink, pw->pw_name,
+ gr->gr_name, (unsigned long)ent->size, buf, ent->name, indicator(ent->mode));
if(S_ISLNK(ent->mode)) {
if((len = readlink(ent->name, buf, sizeof buf)) == -1)
eprintf("readlink %s:", ent->name);
buf[len] = '
Received on Tue Feb 18 2014 - 13:54:22 CET
This archive was generated by hypermail 2.3.0
: Tue Feb 18 2014 - 14:00:13 CET