diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-02-20 18:59:27 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-02-20 18:59:27 +0000 |
commit | e92fd9159fb6edd717fedda1a9ddc053b30649d8 (patch) | |
tree | 1c296a2c25a241031362d723d7bb889fdfd62f42 /bin | |
parent | bbbc0796d6175153f1d371444f8f8127a6f008e8 (diff) |
add -x, -p, and -m options, based on netbsd work
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ls/extern.h | 4 | ||||
-rw-r--r-- | bin/ls/ls.1 | 17 | ||||
-rw-r--r-- | bin/ls/ls.c | 39 | ||||
-rw-r--r-- | bin/ls/ls.h | 3 | ||||
-rw-r--r-- | bin/ls/print.c | 88 | ||||
-rw-r--r-- | bin/ls/util.c | 6 |
6 files changed, 134 insertions, 23 deletions
diff --git a/bin/ls/extern.h b/bin/ls/extern.h index 8cf45e32dee..5126f0057d0 100644 --- a/bin/ls/extern.h +++ b/bin/ls/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.2 1996/06/23 14:20:18 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.3 1999/02/20 18:59:24 deraadt Exp $ */ /* $NetBSD: extern.h,v 1.5 1995/03/21 09:06:24 cgd Exp $ */ /*- @@ -50,6 +50,8 @@ int revsizecmp __P((const FTSENT *, const FTSENT *)); char *flags_to_string __P((u_long, char *)); void prcopy __P((char *, char *, int)); void printcol __P((DISPLAY *)); +void printacol __P((DISPLAY *)); void printlong __P((DISPLAY *)); void printscol __P((DISPLAY *)); +void printstream __P((DISPLAY *)); void usage __P((void)); diff --git a/bin/ls/ls.1 b/bin/ls/ls.1 index cfdb8f3483f..461602cc678 100644 --- a/bin/ls/ls.1 +++ b/bin/ls/ls.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ls.1,v 1.13 1998/12/15 01:20:23 aaron Exp $ +.\" $OpenBSD: ls.1,v 1.14 1999/02/20 18:59:25 deraadt Exp $ .\" $NetBSD: ls.1,v 1.14 1995/12/05 02:44:01 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 @@ -45,7 +45,7 @@ .Nd list directory contents .Sh SYNOPSIS .Nm ls -.Op Fl ACFLRSTWacdfgiklnoqrstu1 +.Op Fl 1ACFLRSTWacdfgiklmnopqrstux .Op Ar file ... .Sh DESCRIPTION For each operand that names a @@ -138,12 +138,16 @@ option, causing the sizes to be reported in kilobytes. 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 List in long format as in .Fl l , but retain user and group IDs in a numeric format. .It Fl o Include the file flags in a long +.It Fl p +Display a slash (/) immediately after each pathname that is a directory. .Pq Fl l output. .It Fl q @@ -176,6 +180,11 @@ or printing Force output to be one entry per line. This is the default when output is not to a terminal. +.It Fl x +Multi-column output sorted across the page rather than down the page. +.It Fl \&1 +(The numeric digit ``one.'') Force output to be +one entry per line. .El .Pp The @@ -199,7 +208,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 m +options are specified. .Pp File information is displayed with one or more <blank>s separating the information associated with the diff --git a/bin/ls/ls.c b/bin/ls/ls.c index b2459346374..17c83dba1a3 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ls.c,v 1.9 1998/08/07 19:45:06 deraadt Exp $ */ +/* $OpenBSD: ls.c,v 1.10 1999/02/20 18:59:25 deraadt Exp $ */ /* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94"; #else -static char rcsid[] = "$OpenBSD: ls.c,v 1.9 1998/08/07 19:45:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ls.c,v 1.10 1999/02/20 18:59:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -88,6 +88,7 @@ int sortkey = BY_NAME; /* flags */ int f_accesstime; /* use time of last access */ int f_column; /* columnated format */ +int f_columnacross; /* columnated format, sorted across */ int f_flags; /* show flags associated with a file */ int f_inode; /* print inode */ int f_listdir; /* list actual directory, not contents */ @@ -103,8 +104,10 @@ int f_sectime; /* print the real time for all files */ int f_singlecol; /* use single column output */ int f_size; /* list size in short listing */ int f_statustime; /* use time of last mode change */ +int f_stream; /* stream format */ int f_dirname; /* if precede with directory name */ int f_type; /* add type character for non-regular files */ +int f_typedir; /* add type character for directories */ int f_whiteout; /* show whiteout entries */ int rval; @@ -136,24 +139,33 @@ main(argc, argv) f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklnoqrstu")) != -1) { + while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklmnopqrstux")) != -1) { switch (ch) { /* - * The -1, -C and -l options all override each other so shell - * aliasing works right. + * The -1, -C and -l, -m and -x options all override each + * other so shell aliasing works right. */ case '1': f_singlecol = 1; - f_column = f_longform = 0; + f_column = f_columnacross = f_longform = f_stream = 0; break; case 'C': f_column = 1; - f_longform = f_singlecol = 0; + f_longform = f_columnacross = f_singlecol = f_stream = 0; break; case 'l': f_longform = 1; f_numericonly = 0; - f_column = f_singlecol = 0; + f_column = f_columnacross = f_singlecol = f_stream = 0; + break; + case 'm': + f_stream = 1; + f_column = f_columnacross = f_singlecol = 0; + f_singlecol = 0; + break; + case 'x': + f_columnacross = 1; + f_column = f_longform = f_singlecol = f_stream = 0; break; case 'n': f_longform = 1; @@ -205,6 +217,9 @@ main(argc, argv) case 'o': f_flags = 1; break; + case 'p': + f_typedir = 1; + break; case 'q': f_nonprint = 1; break; @@ -234,10 +249,10 @@ main(argc, argv) argv += optind; /* - * If not -F, -i, -l, -S, -s or -t options, don't require stat + * If not -F, -i, -l, -p, -S, -s or -t options, don't require stat * information. */ - if (!f_inode && !f_longform && !f_size && !f_type && + if (!f_inode && !f_longform && !f_size && !f_type && !f_typedir && sortkey == BY_NAME) fts_options |= FTS_NOSTAT; @@ -303,8 +318,12 @@ main(argc, argv) /* Select a print function. */ if (f_singlecol) printfcn = printscol; + else if (f_columnacross) + printfcn = printacol; 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 1257a392aa8..3152a15bd23 100644 --- a/bin/ls/ls.h +++ b/bin/ls/ls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ls.h,v 1.2 1996/06/23 14:20:20 deraadt Exp $ */ +/* $OpenBSD: ls.h,v 1.3 1999/02/20 18:59:25 deraadt Exp $ */ /* $NetBSD: ls.h,v 1.7 1995/03/21 09:06:33 cgd Exp $ */ /* @@ -51,6 +51,7 @@ extern int f_sectime; /* print the real time for all files */ extern int f_size; /* list size in short listing */ extern int f_statustime; /* use time of last mode change */ extern int f_type; /* add type character for non-regular files */ +extern int f_typedir; /* add type character for directories */ typedef struct { FTSENT *list; diff --git a/bin/ls/print.c b/bin/ls/print.c index 5405201a234..fe64e5024a2 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.9 1998/08/15 20:23:20 deraadt Exp $ */ +/* $OpenBSD: print.c,v 1.10 1999/02/20 18:59:25 deraadt Exp $ */ /* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94"; #else -static char rcsid[] = "$OpenBSD: print.c,v 1.9 1998/08/15 20:23:20 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.10 1999/02/20 18:59:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -128,7 +128,7 @@ printlong(dp) else printtime(sp->st_mtime); (void)printf("%s", p->fts_name); - if (f_type) + if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) (void)printtype(sp->st_mode); if (S_ISLNK(sp->st_mode)) printlink(p); @@ -172,7 +172,7 @@ printcol(dp) colwidth += dp->s_inode + 1; if (f_size) colwidth += dp->s_block + 1; - if (f_type) + if (f_type || f_typedir) colwidth += 1; colwidth += 1; @@ -222,7 +222,7 @@ printaname(p, inodefield, sizefield) chcnt += printf("%*qd ", (int)sizefield, howmany(sp->st_blocks, blocksize)); chcnt += printf("%s", p->fts_name); - if (f_type) + if (f_type || (f_typedir && S_ISDIR(sp->st_mode))) chcnt += printtype(sp->st_mode); return (chcnt); } @@ -253,6 +253,84 @@ printtime(ftime) (void)putchar(' '); } +void +printacol(dp) + DISPLAY *dp; +{ + extern int termwidth; + FTSENT *p; + int chcnt, col, colwidth; + int numcols; + + colwidth = dp->maxlen; + if (f_inode) + colwidth += dp->s_inode + 1; + if (f_size) + colwidth += dp->s_block + 1; + if (f_type || f_typedir) + colwidth += 1; + + colwidth += 1; + + if (termwidth < 2 * colwidth) { + printscol(dp); + return; + } + + numcols = termwidth / colwidth; + colwidth = termwidth / numcols; /* spread out if possible */ + + if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) + (void)printf("total %llu\n", + (long long)(howmany(dp->btotal, blocksize))); + chcnt = col = 0; + for (p = dp->list; p; p = p->fts_link) { + if (IS_NOPRINT(p)) + continue; + if (col >= numcols) { + chcnt = col = 0; + (void)putchar('\n'); + } + chcnt = printaname(p, dp->s_inode, dp->s_block); + while (chcnt++ < colwidth) + (void)putchar(' '); + col++; + } + (void)putchar('\n'); +} + +void +printstream(dp) + DISPLAY *dp; +{ + extern int termwidth; + FTSENT *p; + int col; + int extwidth; + + extwidth = 0; + if (f_inode) + extwidth += dp->s_inode + 1; + if (f_size) + extwidth += dp->s_block + 1; + if (f_type) + extwidth += 1; + + for (col = 0, p = dp->list; p != NULL; p = p->fts_link) { + if (IS_NOPRINT(p)) + continue; + if (col > 0) { + (void)putchar(','), col++; + if (col + 1 + extwidth + p->fts_namelen >= termwidth) + (void)putchar('\n'), col = 0; + else + (void)putchar(' '), col++; + } + col += printaname(p, dp->s_inode, dp->s_block); + } + (void)putchar('\n'); +} + static int printtype(mode) u_int mode; diff --git a/bin/ls/util.c b/bin/ls/util.c index e42c54790dc..16ad4e9c159 100644 --- a/bin/ls/util.c +++ b/bin/ls/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.3 1997/09/01 18:29:37 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.4 1999/02/20 18:59:26 deraadt Exp $ */ /* $NetBSD: util.c,v 1.12 1995/09/07 06:43:02 jtc Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)util.c 8.5 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: util.c,v 1.3 1997/09/01 18:29:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.4 1999/02/20 18:59:26 deraadt Exp $"; #endif #endif /* not lint */ @@ -74,6 +74,6 @@ void usage() { (void)fprintf(stderr, - "usage: ls [-1ACFLRSTWacdfikloqrstu] [file ...]\n"); + "usage: ls [-1ACFLRSTWacdfiklmnopqrstux] [file ...]\n"); exit(1); } |