ls: add support for -p
This commit is contained in:
parent
d02327d0eb
commit
51b707e91e
2
README
2
README
|
@ -40,7 +40,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
||||||
=* ln yes none
|
=* ln yes none
|
||||||
=* logger yes none
|
=* logger yes none
|
||||||
=* logname 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
|
=* md5sum non-posix none
|
||||||
=* mkdir yes none
|
=* mkdir yes none
|
||||||
=* mkfifo yes none
|
=* mkfifo yes none
|
||||||
|
|
4
ls.1
4
ls.1
|
@ -22,7 +22,7 @@ modification time for sorting or printing.
|
||||||
.It Fl d
|
.It Fl d
|
||||||
List directories themselves, not their contents.
|
List directories themselves, not their contents.
|
||||||
.It Fl F
|
.It Fl F
|
||||||
Append a file type indicator to files.
|
Append a file type indicator to all special files.
|
||||||
.It Fl H
|
.It Fl H
|
||||||
List information about the targets of symbolic links specified on the command
|
List information about the targets of symbolic links specified on the command
|
||||||
line instead of the links themselves.
|
line instead of the links themselves.
|
||||||
|
@ -36,6 +36,8 @@ themselves.
|
||||||
.It Fl l
|
.It Fl l
|
||||||
List detailed information about each file, including their type, permissions,
|
List detailed information about each file, including their type, permissions,
|
||||||
links, owner, group, size, and last file status/modification time.
|
links, owner, group, size, and last file status/modification time.
|
||||||
|
.It Fl p
|
||||||
|
Append a file type indicator to directories.
|
||||||
.It Fl q
|
.It Fl q
|
||||||
Replace non-printable characters in filenames with '?'.
|
Replace non-printable characters in filenames with '?'.
|
||||||
.It Fl r
|
.It Fl r
|
||||||
|
|
19
ls.c
19
ls.c
|
@ -33,6 +33,7 @@ static int hflag = 0;
|
||||||
static int iflag = 0;
|
static int iflag = 0;
|
||||||
static int Lflag = 0;
|
static int Lflag = 0;
|
||||||
static int lflag = 0;
|
static int lflag = 0;
|
||||||
|
static int pflag = 0;
|
||||||
static int qflag = 0;
|
static int qflag = 0;
|
||||||
static int rflag = 0;
|
static int rflag = 0;
|
||||||
static int tflag = 0;
|
static int tflag = 0;
|
||||||
|
@ -70,20 +71,21 @@ mkent(struct entry *ent, char *path, int dostat, int follow)
|
||||||
static char *
|
static char *
|
||||||
indicator(mode_t mode)
|
indicator(mode_t mode)
|
||||||
{
|
{
|
||||||
if (!Fflag)
|
if (pflag || Fflag)
|
||||||
return "";
|
if (S_ISDIR(mode))
|
||||||
|
return "/";
|
||||||
|
|
||||||
|
if (Fflag) {
|
||||||
if (S_ISLNK(mode))
|
if (S_ISLNK(mode))
|
||||||
return "@";
|
return "@";
|
||||||
else if (S_ISDIR(mode))
|
|
||||||
return "/";
|
|
||||||
else if (S_ISFIFO(mode))
|
else if (S_ISFIFO(mode))
|
||||||
return "|";
|
return "|";
|
||||||
else if (S_ISSOCK(mode))
|
else if (S_ISSOCK(mode))
|
||||||
return "=";
|
return "=";
|
||||||
else if (mode & S_IXUSR || mode & S_IXGRP || mode & S_IXOTH)
|
else if (mode & S_IXUSR || mode & S_IXGRP || mode & S_IXOTH)
|
||||||
return "*";
|
return "*";
|
||||||
else
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +207,7 @@ lsdir(const char *path)
|
||||||
if (d->d_name[0] == '.' && !aflag)
|
if (d->d_name[0] == '.' && !aflag)
|
||||||
continue;
|
continue;
|
||||||
if (Uflag){
|
if (Uflag){
|
||||||
mkent(&ent, d->d_name, Fflag || lflag || iflag, Lflag);
|
mkent(&ent, d->d_name, Fflag || lflag || pflag || iflag, Lflag);
|
||||||
output(&ent);
|
output(&ent);
|
||||||
} else {
|
} else {
|
||||||
ents = erealloc(ents, ++n * sizeof(*ents));
|
ents = erealloc(ents, ++n * sizeof(*ents));
|
||||||
|
@ -224,7 +226,7 @@ lsdir(const char *path)
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*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);
|
closedir(dp);
|
||||||
|
@ -295,6 +297,9 @@ main(int argc, char *argv[])
|
||||||
case 'l':
|
case 'l':
|
||||||
lflag = 1;
|
lflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
pflag = 1;
|
||||||
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
qflag = 1;
|
qflag = 1;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user