[hackers] [sbase] ls: add support for -p || Quentin Rameau
commit 014ecb5db7625169902a8f93b0fea19528b18885
Author: Quentin Rameau <quinq_AT_quinq.eu.org>
Date: Thu Feb 19 19:48:15 2015 +0100
ls: add support for -p
diff --git a/README b/README
index 025d25f..af54067 100644
--- a/README
+++ b/README
_AT_@ -40,7 +40,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
=* ln yes none
=* logger yes none
=* logname yes none
-= ls no -A, (-C), -R, -S, -f, -m, -n, -p, -s, -x
+= ls no -A, (-C), -R, -S, -f, -m, -n, -s, -x
=* md5sum non-posix none
=* mkdir yes none
=* mkfifo yes none
diff --git a/ls.1 b/ls.1
index 5d8f1b2..d46e97c 100644
--- a/ls.1
+++ b/ls.1
_AT_@ -22,7 +22,7 @@ modification time for sorting or printing.
.It Fl d
List directories themselves, not their contents.
.It Fl F
-Append a file type indicator to files.
+Append a file type indicator to all special files.
.It Fl H
List information about the targets of symbolic links specified on the command
line instead of the links themselves.
_AT_@ -36,6 +36,8 @@ themselves.
.It Fl l
List detailed information about each file, including their type, permissions,
links, owner, group, size, and last file status/modification time.
+.It Fl p
+Append a file type indicator to directories.
.It Fl q
Replace non-printable characters in filenames with '?'.
.It Fl r
diff --git a/ls.c b/ls.c
index e036e57..8d2c3f6 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -33,6 +33,7 @@ static int hflag = 0;
static int iflag = 0;
static int Lflag = 0;
static int lflag = 0;
+static int pflag = 0;
static int qflag = 0;
static int rflag = 0;
static int tflag = 0;
_AT_@ -70,21 +71,22 @@ mkent(struct entry *ent, char *path, int dostat, int follow)
static char *
indicator(mode_t mode)
{
- if (!Fflag)
- return "";
+ if (pflag || Fflag)
+ if (S_ISDIR(mode))
+ 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 "";
+ if (Fflag) {
+ if (S_ISLNK(mode))
+ return "_AT_";
+ else if (S_ISFIFO(mode))
+ return "|";
+ else if (S_ISSOCK(mode))
+ return "=";
+ else if (mode & S_IXUSR || mode & S_IXGRP || mode & S_IXOTH)
+ return "*";
+ }
+
+ return "";
}
static void
_AT_@ -205,7 +207,7 @@ lsdir(const char *path)
if (d->d_name[0] == '.' && !aflag)
continue;
if (Uflag){
- mkent(&ent, d->d_name, Fflag || lflag || iflag, Lflag);
+ mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag, Lflag);
output(&ent);
} else {
ents = erealloc(ents, ++n * sizeof(*ents));
_AT_@ -224,7 +226,7 @@ lsdir(const char *path)
}
*p = '\0';
}
- mkent(&ents[n - 1], name, tflag || Fflag || lflag || iflag, Lflag);
+ mkent(&ents[n - 1], name, tflag || Fflag || iflag || lflag || pflag, Lflag);
}
}
closedir(dp);
_AT_@ -295,6 +297,9 @@ main(int argc, char *argv[])
case 'l':
lflag = 1;
break;
+ case 'p':
+ pflag = 1;
+ break;
case 'q':
qflag = 1;
break;
Received on Thu Feb 19 2015 - 19:52:57 CET
This archive was generated by hypermail 2.3.0
: Thu Feb 19 2015 - 20:00:17 CET