Add missing options required by SUSv3:

-m	List files across the page, separated by commas.
-p	Print a slash after directory names
-x	Same as -C but sort across the columns rather than down

Submitted by:	Kyle Martin <mkm@ieee.org>
This commit is contained in:
Tim J. Robbins 2002-05-19 02:51:36 +00:00
parent a9b4acea06
commit 94274c73cb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=96892
5 changed files with 100 additions and 16 deletions

View File

@ -46,6 +46,7 @@ int revstatcmp(const FTSENT *, const FTSENT *);
void printcol(DISPLAY *);
void printlong(DISPLAY *);
void printscol(DISPLAY *);
void printstream(DISPLAY *);
void usage(void);
size_t len_octal(const char *, int);
int prn_octal(const char *);

View File

@ -43,7 +43,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm
.Op Fl ABCFGHLPRTWZabcdfghiklnoqrstuw1
.Op Fl ABCFGHLPRTWZabcdfghiklmnopqrstuwx1
.Op Ar
.Sh DESCRIPTION
For each operand that names a
@ -192,6 +192,8 @@ List in long format.
(See below.)
If the output is to a terminal, a total sum for all the file
sizes is output on a line before the long listing.
.It Fl m
Stream output format; list files across the page, separated by commas.
.It Fl n
Display user and group IDs numerically rather than converting to a user
or group name in a long
@ -201,6 +203,10 @@ output.
Include the file flags in a long
.Pq Fl l
output.
.It Fl p
Write a slash
.Pq Ql /
after each filename if that file is a directory.
.It Fl q
Force printing of non-graphic characters in file names as
the character
@ -232,6 +238,11 @@ or printing
Force raw printing of non-printable characters.
This is the default
when output is not to a terminal.
.It Fl x
The same as
.Fl C ,
except that the multi-column output is produced with entries sorted
across, rather than down, the columns.
.It Fl 1
(The numeric digit
.Dq one . )
@ -242,7 +253,7 @@ output is not to a terminal.
.El
.Pp
The
.Fl 1 , C ,
.Fl 1 , C , x ,
and
.Fl l
options all override each other; the last one specified determines
@ -274,7 +285,9 @@ By default,
lists one entry per line to standard
output; the exceptions are to terminals or when the
.Fl C
option is specified.
or
.Fl x
options are specified.
.Pp
File information is displayed with one or more
.Ao blank Ac Ns s
@ -481,7 +494,8 @@ utility calculates how
many pathname text columns to display
based on the width provided.
(See
.Fl C . )
.Fl C and
.Fl x . )
.It Ev LANG
The locale to use when determining the order of day and month in the long
.Fl l
@ -619,17 +633,16 @@ KLD
.Xr termcap 5 ,
.Xr symlink 7 ,
.Xr sticky 8
.Sh STANDARDS
The
.Nm
utility conforms to
.St -p1003.1-2001 .
.Sh HISTORY
An
.Nm
command appeared in
.At v1 .
.Sh STANDARDS
The
.Nm
utility is expected to be a superset of the
.St -p1003.2
specification.
.Sh BUGS
To maintain backward compatibility, the relationships between the many
options are quite complex.

View File

@ -113,7 +113,10 @@ static int f_reversesort; /* reverse whatever sort is used */
int f_sectime; /* print the real time for all files */
static int f_singlecol; /* use single column output */
int f_size; /* list size in short listing */
int f_slash; /* similar to f_type, but only for dirs */
int f_sortacross; /* sort across rows, not down columns */
int f_statustime; /* use time of last mode change */
int f_stream; /* stream the output, seperate with commas */
static int f_timesort; /* sort by time vice name */
int f_type; /* add type character for non-regular files */
static int f_whiteout; /* show whiteout entries */
@ -167,15 +170,17 @@ main(int argc, char *argv[])
f_listdot = 1;
fts_options = FTS_PHYSICAL;
while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfghiklnoqrstuw")) != -1) {
while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfghiklmnopqrstuwx"))
!= -1) {
switch (ch) {
/*
* The -1, -C and -l options all override each other so shell
* aliasing works right.
* The -1, -C, -x and -l options all override each other so
* shell aliasing works right.
*/
case '1':
f_singlecol = 1;
f_longform = 0;
f_stream = 0;
break;
case 'B':
f_nonprint = 0;
@ -183,11 +188,17 @@ main(int argc, char *argv[])
f_octal_escape = 0;
break;
case 'C':
f_longform = f_singlecol = 0;
f_sortacross = f_longform = f_singlecol = 0;
break;
case 'l':
f_longform = 1;
f_singlecol = 0;
f_stream = 0;
break;
case 'x':
f_sortacross = 1;
f_longform = 0;
f_singlecol = 0;
break;
/* The -c and -u options override each other. */
case 'c':
@ -200,6 +211,7 @@ main(int argc, char *argv[])
break;
case 'F':
f_type = 1;
f_slash = 0;
break;
case 'H':
fts_options |= FTS_COMFOLLOW;
@ -244,12 +256,21 @@ main(int argc, char *argv[])
case 'k':
f_kblocks = 1;
break;
case 'm':
f_stream = 1;
f_singlecol = 0;
f_longform = 0;
break;
case 'n':
f_numericonly = 1;
break;
case 'o':
f_flags = 1;
break;
case 'p':
f_slash = 1;
f_type = 1;
break;
case 'q':
f_nonprint = 1;
f_octal = 0;
@ -390,6 +411,8 @@ main(int argc, char *argv[])
printfcn = printscol;
else if (f_longform)
printfcn = printlong;
else if (f_stream)
printfcn = printstream;
else
printfcn = printcol;

View File

@ -53,6 +53,8 @@ extern int f_octal_escape; /* like f_octal but use C escapes if possible */
extern int f_nonprint; /* show unprintables as ? */
extern int f_sectime; /* print the real time for all files */
extern int f_size; /* list size in short listing */
extern int f_slash; /* append a '/' if the file is a directory */
extern int f_sortacross; /* sort across rows, not down columns */
extern int f_statustime; /* use time of last mode change */
extern int f_notabs; /* don't use tab-separated multi-col output */
extern int f_type; /* add type character for non-regular files */

View File

@ -222,6 +222,31 @@ printlong(DISPLAY *dp)
}
}
void
printstream(DISPLAY *dp)
{
FTSENT *p;
extern int termwidth;
int chcnt;
for (p = dp->list, chcnt = 0; p; p = p->fts_link) {
if (p->fts_number == NO_PRINT)
continue;
if (strlen(p->fts_name) + chcnt +
(p->fts_link ? 2 : 0) >= (unsigned)termwidth) {
putchar('\n');
chcnt = 0;
}
chcnt += printaname(p, dp->s_inode, dp->s_block);
if (p->fts_link) {
printf(", ");
chcnt += 2;
}
}
if (chcnt)
putchar('\n');
}
void
printcol(DISPLAY *dp)
{
@ -282,15 +307,26 @@ printcol(DISPLAY *dp)
if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
(void)printf("total %lu\n", howmany(dp->btotal, blocksize));
if (f_sortacross)
base = 0;
for (row = 0; row < numrows; ++row) {
endcol = colwidth;
for (base = row, chcnt = col = 0; col < numcols; ++col) {
if (!f_sortacross)
base = row;
for (col = 0, chcnt = 0; col < numcols; ++col) {
chcnt += printaname(array[base], dp->s_inode,
dp->s_block);
if ((base += numrows) >= num)
if (f_sortacross)
base++;
else
base += numrows;
if (base >= num)
break;
while ((cnt = ((chcnt + tabwidth) & ~(tabwidth - 1)))
<= endcol) {
if (f_sortacross && col + 1 >= numcols)
break;
(void)putchar(f_notabs ? ' ' : '\t');
chcnt = cnt;
}
@ -364,6 +400,15 @@ printtime(time_t ftime)
static int
printtype(u_int mode)
{
if (f_slash) {
if ((mode & S_IFMT) == S_IFDIR) {
(void)putchar('/');
return (1);
}
return (0);
}
switch (mode & S_IFMT) {
case S_IFDIR:
(void)putchar('/');