- 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.
-# $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
-/* $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
#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 */
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
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));
}
-/* $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
#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 */
/* 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
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
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));
-/* $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
#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 */
#include <time.h>
#include <tzfile.h>
#include <unistd.h>
+#include <utmp.h>
#include "ls.h"
#include "extern.h"
}
}
-#define TAB 8
-
void
printcol(dp)
DISPLAY *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
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;
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');
}