diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-03 22:36:09 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-03 22:36:09 +0000 |
commit | a07e8cc3030f8743a5d3b39bd97994fb54aa76fb (patch) | |
tree | 54bf075e78894ab030dfe86c8d7537e602d04e44 | |
parent | b3e85814e581c12d86755a6215992e1cbb47a912 (diff) |
From NetBSD:
- Correct sorting behaviour.
- Do multicolumn output in a way that's a more likely to line up evenly.
From D'Arcy J.M. Cain <darcy@druid.com>, NetBSD PR #2965.
-rw-r--r-- | bin/ls/Makefile | 3 | ||||
-rw-r--r-- | bin/ls/cmp.c | 90 | ||||
-rw-r--r-- | bin/ls/ls.c | 28 | ||||
-rw-r--r-- | bin/ls/print.c | 28 |
4 files changed, 102 insertions, 47 deletions
diff --git a/bin/ls/Makefile b/bin/ls/Makefile index 20a160063a7..9abd3e64224 100644 --- a/bin/ls/Makefile +++ b/bin/ls/Makefile @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile,v 1.2 1996/06/23 14:20:17 deraadt Exp $ +# $OpenBSD: Makefile,v 1.3 1997/01/03 22:36:07 millert Exp $ # $NetBSD: Makefile,v 1.8 1995/03/21 09:06:18 cgd Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/2/93 PROG= ls SRCS= cmp.c stat_flags.c ls.c print.c util.c diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c index 3ac4f52ad3c..2b62e7ecc4a 100644 --- a/bin/ls/cmp.c +++ b/bin/ls/cmp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmp.c,v 1.2 1996/06/23 14:20:18 deraadt Exp $ */ -/* $NetBSD: cmp.c,v 1.8 1995/03/21 09:06:20 cgd Exp $ */ +/* $OpenBSD: cmp.c,v 1.3 1997/01/03 22:36:07 millert Exp $ */ +/* $NetBSD: cmp.c,v 1.10 1996/07/08 10:32:01 mycroft Exp $ */ /* * Copyright (c) 1989, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: cmp.c,v 1.2 1996/06/23 14:20:18 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmp.c,v 1.3 1997/01/03 22:36:07 millert Exp $"; #endif #endif /* not lint */ @@ -72,42 +72,96 @@ int modcmp(a, b) const FTSENT *a, *b; { - return (b->fts_statp->st_mtime - a->fts_statp->st_mtime); + if (b->fts_statp->st_mtime > a->fts_statp->st_mtime) + return (1); + else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime) + return (-1); + else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec) + return (1); + else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec) + return (-1); + else + return (namecmp(a, b)); } int revmodcmp(a, b) const FTSENT *a, *b; { - return (a->fts_statp->st_mtime - b->fts_statp->st_mtime); + if (b->fts_statp->st_mtime > a->fts_statp->st_mtime) + return (-1); + else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime) + return (1); + else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec) + return (-1); + else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec) + return (1); + else + return (revnamecmp(a, b)); } int acccmp(a, b) const FTSENT *a, *b; { - return (b->fts_statp->st_atime - a->fts_statp->st_atime); + if (b->fts_statp->st_atime > a->fts_statp->st_atime) + return (1); + else if (b->fts_statp->st_atime < a->fts_statp->st_atime) + return (-1); + else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec) + return (1); + else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec) + return (-1); + else + return (namecmp(a, b)); } int revacccmp(a, b) const FTSENT *a, *b; { - return (a->fts_statp->st_atime - b->fts_statp->st_atime); + if (b->fts_statp->st_atime > a->fts_statp->st_atime) + return (-1); + else if (b->fts_statp->st_atime < a->fts_statp->st_atime) + return (1); + else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec) + return (-1); + else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec) + return (1); + else + return (revnamecmp(a, b)); } int statcmp(a, b) const FTSENT *a, *b; { - return (b->fts_statp->st_ctime - a->fts_statp->st_ctime); + if (b->fts_statp->st_ctime > a->fts_statp->st_ctime) + return (1); + else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime) + return (-1); + else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec) + return (1); + else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec) + return (-1); + else + return (namecmp(a, b)); } int revstatcmp(a, b) const FTSENT *a, *b; { - return (a->fts_statp->st_ctime - b->fts_statp->st_ctime); + if (b->fts_statp->st_ctime > a->fts_statp->st_ctime) + return (-1); + else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime) + return (1); + else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec) + return (-1); + else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec) + return (1); + else + return (revnamecmp(a, b)); } int @@ -115,19 +169,21 @@ sizecmp(a, b) const FTSENT *a, *b; { if (b->fts_statp->st_size > a->fts_statp->st_size) - return 1; + return (1); if (b->fts_statp->st_size < a->fts_statp->st_size) - return -1; - return 0; + return (-1); + else + return (namecmp(a, b)); } int revsizecmp(a, b) const FTSENT *a, *b; { - if (a->fts_statp->st_size > b->fts_statp->st_size) - return 1; - if (a->fts_statp->st_size < b->fts_statp->st_size) - return -1; - return 0; + if (b->fts_statp->st_size > a->fts_statp->st_size) + return (-1); + if (b->fts_statp->st_size < a->fts_statp->st_size) + return (1); + else + return (revnamecmp(a, b)); } diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 3004687589a..7dc75185714 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ls.c,v 1.5 1996/12/14 12:18:03 mickey Exp $ */ -/* $NetBSD: ls.c,v 1.16 1996/02/14 05:58:53 jtc Exp $ */ +/* $OpenBSD: ls.c,v 1.6 1997/01/03 22:36:08 millert Exp $ */ +/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -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.5 1996/12/14 12:18:03 mickey Exp $"; +static char rcsid[] = "$OpenBSD: ls.c,v 1.6 1997/01/03 22:36:08 millert Exp $"; #endif #endif /* not lint */ @@ -119,10 +119,10 @@ main(argc, argv) /* Terminal defaults to -Cq, non-terminal defaults to -1. */ if (isatty(STDOUT_FILENO)) { - if ((p = getenv("COLUMNS")) != NULL) - termwidth = atoi(p); - else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && - win.ws_col > 0) + if ((p = getenv("COLUMNS")) != NULL) + termwidth = atoi(p); + else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && + win.ws_col > 0) termwidth = win.ws_col; f_column = f_nonprint = 1; } else @@ -391,11 +391,8 @@ display(p, list) u_long btotal, maxblock, maxinode, maxlen, maxnlink; int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser; int entries, needstats; - char *user, *group, *flags, buf[20]; /* 32 bits == 10 digits */ - -#ifdef lint - flags = NULL; -#endif + char *user, *group, buf[20]; /* 32 bits == 10 digits */ + char *flags = NULL; /* * If list is NULL there are two possibilities: that the parent @@ -542,7 +539,12 @@ mastercmp(a, b) return (0); if (a_info == FTS_NS || b_info == FTS_NS) - return (namecmp(*a, *b)); + if (b_info != FTS_NS) + return (1); + else if (a_info != FTS_NS) + return (-1); + else + return (namecmp(*a, *b)); if (a_info == b_info) return (sortfcn(*a, *b)); diff --git a/bin/ls/print.c b/bin/ls/print.c index 3587d81eac6..aacf602beb2 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -1,5 +1,5 @@ -/* $OpenBSD: print.c,v 1.5 1996/12/17 18:52:52 tholo Exp $ */ -/* $NetBSD: print.c,v 1.14 1995/09/07 06:43:00 jtc Exp $ */ +/* $OpenBSD: print.c,v 1.6 1997/01/03 22:36:08 millert Exp $ */ +/* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -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.5 1996/12/17 18:52:52 tholo Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.6 1997/01/03 22:36:08 millert Exp $"; #endif #endif /* not lint */ @@ -59,6 +59,7 @@ static char rcsid[] = "$OpenBSD: print.c,v 1.5 1996/12/17 18:52:52 tholo Exp $"; #include <time.h> #include <tzfile.h> #include <unistd.h> +#include <utmp.h> #include "ls.h" #include "extern.h" @@ -135,8 +136,6 @@ printlong(dp) } } -#define TAB 8 - void printcol(dp) DISPLAY *dp; @@ -145,8 +144,8 @@ printcol(dp) static FTSENT **array; static int lastentries = -1; FTSENT *p; - int base, chcnt, cnt, col, colwidth, num; - int endcol, numcols, numrows, row; + int base, chcnt, col, colwidth, num; + int numcols, numrows, row; /* * Have to do random access in the linked list -- build a table @@ -172,13 +171,15 @@ printcol(dp) if (f_type) colwidth += 1; - colwidth = (colwidth + TAB) & ~(TAB - 1); + colwidth += 1; + if (termwidth < 2 * colwidth) { printscol(dp); return; } numcols = termwidth / colwidth; + colwidth = termwidth / numcols; /* spread out if possible */ numrows = num / numcols; if (num % numcols) ++numrows; @@ -186,17 +187,12 @@ printcol(dp) if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) (void)printf("total %lu\n", howmany(dp->btotal, blocksize)); for (row = 0; row < numrows; ++row) { - endcol = colwidth; for (base = row, chcnt = col = 0; col < numcols; ++col) { - chcnt += printaname(array[base], dp->s_inode, - dp->s_block); + chcnt = printaname(array[base], dp->s_inode, dp->s_block); if ((base += numrows) >= num) break; - while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol) { - (void)putchar('\t'); - chcnt = cnt; - } - endcol += colwidth; + while (chcnt++ < colwidth) + putchar(' '); } (void)putchar('\n'); } |