sbase

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

commit 51b707e91e39f70adbf68bf6fca130756c3f14af
parent d02327d0ebf564101421f8c1312b86a8b3c8ea48
Author: Quentin Rameau <quinq@quinq.eu.org>
Date:   Thu, 19 Feb 2015 19:48:15 +0100

ls: add support for -p

Diffstat:
MREADME | 2+-
Mls.1 | 4+++-
Mls.c | 37+++++++++++++++++++++----------------
3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/README b/README @@ -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 @@ -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. @@ -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 @@ -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; @@ -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 "@"; - 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 "@"; + 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 @@ -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)); @@ -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); @@ -295,6 +297,9 @@ main(int argc, char *argv[]) case 'l': lflag = 1; break; + case 'p': + pflag = 1; + break; case 'q': qflag = 1; break;