diff options
author | tjr <tjr@FreeBSD.org> | 2002-05-19 02:51:36 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-05-19 02:51:36 +0000 |
commit | 18037eb7abbc88a96356f5301de4264b7e15e365 (patch) | |
tree | 28b290e569abcd5762e812b539f2164dfff413d9 | |
parent | 1f1f792674c9b3099aaa76909c7265fd5b213123 (diff) | |
download | FreeBSD-src-18037eb7abbc88a96356f5301de4264b7e15e365.zip FreeBSD-src-18037eb7abbc88a96356f5301de4264b7e15e365.tar.gz |
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>
-rw-r--r-- | bin/ls/extern.h | 1 | ||||
-rw-r--r-- | bin/ls/ls.1 | 33 | ||||
-rw-r--r-- | bin/ls/ls.c | 31 | ||||
-rw-r--r-- | bin/ls/ls.h | 2 | ||||
-rw-r--r-- | bin/ls/print.c | 49 |
5 files changed, 100 insertions, 16 deletions
diff --git a/bin/ls/extern.h b/bin/ls/extern.h index e0d4b6a..d6b4208 100644 --- a/bin/ls/extern.h +++ b/bin/ls/extern.h @@ -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 *); diff --git a/bin/ls/ls.1 b/bin/ls/ls.1 index 79def54..f427c07 100644 --- a/bin/ls/ls.1 +++ b/bin/ls/ls.1 @@ -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. diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 60505cb..9791f01 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -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; diff --git a/bin/ls/ls.h b/bin/ls/ls.h index e206c56..ac1aaed 100644 --- a/bin/ls/ls.h +++ b/bin/ls/ls.h @@ -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 */ diff --git a/bin/ls/print.c b/bin/ls/print.c index 5887b70..5068419 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -223,6 +223,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) { extern int termwidth; @@ -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('/'); |