sync with 3.4 and FreeBSD

This commit is contained in:
naddy 2003-08-27 00:41:51 +00:00
parent c50020e757
commit b43a162ff6
9 changed files with 104 additions and 232 deletions

View File

@ -1,8 +1,8 @@
# $OpenBSD: Makefile,v 1.4 2003/01/20 01:45:14 naddy Exp $
# $OpenBSD: Makefile,v 1.5 2003/08/27 00:41:51 naddy Exp $
COMMENT= "ls that can use color to display file attributes"
DISTNAME= ls-3.2
DISTNAME= ls-3.4
PKGNAME= color${DISTNAME}
CATEGORIES= sysutils

View File

@ -1,3 +1,3 @@
MD5 (ls-3.2.tar.gz) = 16266a0492d8ced0a80ed69421a2ba76
RMD160 (ls-3.2.tar.gz) = b7a039b4415bccdd24bd637ff6698eb01a278aa8
SHA1 (ls-3.2.tar.gz) = ea15bc9406ba6c91354b6197bea30d249c5f3590
MD5 (ls-3.4.tar.gz) = 5e5cb493e798bfe5d5b92aa7c3edb718
RMD160 (ls-3.4.tar.gz) = 494a78815f4bf3dabde0912c3d9114399b87d9f5
SHA1 (ls-3.4.tar.gz) = e3e32c582d21a347e292c3324ab583e756c96f8a

View File

@ -1,18 +1,20 @@
$OpenBSD: patch-Makefile,v 1.2 2003/01/20 01:45:14 naddy Exp $
--- Makefile.orig Mon Jan 20 00:08:15 2003
+++ Makefile Mon Jan 20 02:20:28 2003
@@ -1,6 +1,13 @@
# $OpenBSD: patch-Makefile,v 1.2 2003/01/20 01:45:14 naddy Exp $
$OpenBSD: patch-Makefile,v 1.3 2003/08/27 00:41:51 naddy Exp $
--- Makefile.orig 2003-08-06 21:09:09.000000000 +0200
+++ Makefile 2003-08-27 00:27:03.000000000 +0200
@@ -1,8 +1,13 @@
# $OpenBSD: patch-Makefile,v 1.3 2003/08/27 00:41:51 naddy Exp $
-PROG= ls
+PROG= colorls
SRCS= cmp.c ls.c main.c print.c util.c
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+BINDIR= ${TRUEPREFIX}/bin
+MANDIR= ${TRUEPREFIX}/man/man
+
+CFLAGS+= -DCOLORLS
+LDADD+= -ltermcap
+DPADD+= ${LIBTERMCAP}
+LDSTATIC=${STATIC}
+DPADD= ${LIBCURSES} ${LIBUTIL}
+LDADD= -lcurses -lutil
.include <bsd.prog.mk>

View File

@ -1,11 +1,11 @@
$OpenBSD: patch-colorls_1,v 1.3 2003/01/20 01:45:14 naddy Exp $
--- colorls.1.orig Mon Jan 20 01:15:00 2003
+++ colorls.1 Mon Jan 20 02:06:53 2003
@@ -45,9 +45,17 @@
$OpenBSD: patch-colorls_1,v 1.4 2003/08/27 00:41:51 naddy Exp $
--- colorls.1.orig 2003-08-27 02:00:19.000000000 +0200
+++ colorls.1 2003-08-27 02:01:20.000000000 +0200
@@ -41,9 +41,17 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm ls
-.Op Fl 1ACFLRSTWacdfgiklmnopqrstux
-.Op Fl 1ACFLRSTWacdfghiklmnopqrstux
+.Op Fl 1ACFGLRSTWacdfghiklmnopqrstux
.Op Ar file ...
.Sh DESCRIPTION
@ -20,7 +20,7 @@ $OpenBSD: patch-colorls_1,v 1.3 2003/01/20 01:45:14 naddy Exp $
For each operand that names a
.Ar file
of a type other than directory,
@@ -96,6 +104,12 @@ after each socket,
@@ -92,6 +100,12 @@ after each socket,
and a vertical bar
.Pq Sq \&|
after each that is a FIFO.
@ -33,29 +33,16 @@ $OpenBSD: patch-colorls_1,v 1.3 2003/01/20 01:45:14 naddy Exp $
.It Fl L
If argument is a symbolic link, list the file or directory the link references
rather than the link itself.
@@ -129,6 +143,12 @@ Output is not sorted.
.It Fl g
Does nothing; kept for compatibility with older versions of
.Xr ls 1 .
+.It Fl h
+When used with the
+.Fl l
+option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte
+and Petabyte in order to reduce the number of digits to three or less
+using base 2 for sizes.
.It Fl i
For each file, print its inode number.
.It Fl k
@@ -412,7 +432,7 @@ List the files in
sorting the output such that the mostly recently modified entries are
printed first.
@@ -395,7 +409,7 @@ The
.Nm
utility exits 0 on success or >0 if an error occurred.
.Sh ENVIRONMENT
-.Bl -tag -width BLOCKSIZE
+.Bl -tag -width CLICOLOR_FORCE
.It Ev BLOCKSIZE
If the environment variable
.Ev BLOCKSIZE
@@ -422,6 +442,44 @@ option is not specified, the block count
@@ -405,6 +419,44 @@ option is not specified, the block count
(see
.Fl s )
will be displayed in units of that size block.
@ -100,7 +87,7 @@ $OpenBSD: patch-colorls_1,v 1.3 2003/01/20 01:45:14 naddy Exp $
.It COLUMNS
If this variable contains a string representing a
decimal integer, it is used as the
@@ -434,6 +492,99 @@ many pathname text columns to display
@@ -417,6 +469,99 @@ many pathname text columns to display
based on the width provided
(see
.Fl C ) .
@ -200,7 +187,7 @@ $OpenBSD: patch-colorls_1,v 1.3 2003/01/20 01:45:14 naddy Exp $
.It Ev TZ
The timezone to use when displaying dates.
See
@@ -448,6 +599,7 @@ specification.
@@ -444,6 +589,7 @@ printed first.
.Sh SEE ALSO
.Xr chflags 1 ,
.Xr chmod 1 ,

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-extern_h,v 1.3 2003/01/20 01:45:14 naddy Exp $
--- extern.h.orig Mon Jan 20 00:08:15 2003
+++ extern.h Mon Jan 20 00:36:43 2003
@@ -56,3 +56,13 @@ void printlong(DISPLAY *);
$OpenBSD: patch-extern_h,v 1.4 2003/08/27 00:41:51 naddy Exp $
--- extern.h.orig 2003-06-03 01:32:08.000000000 +0200
+++ extern.h 2003-08-27 00:28:16.000000000 +0200
@@ -52,3 +52,13 @@ void printlong(DISPLAY *);
void printscol(DISPLAY *);
void printstream(DISPLAY *);
void usage(void);

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-ls_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
--- ls.c.orig Mon Jan 20 00:08:15 2003
+++ ls.c Mon Jan 20 01:51:13 2003
@@ -65,6 +65,10 @@ static char rcsid[] = "$OpenBSD: ls.c,v
$OpenBSD: patch-ls_c,v 1.4 2003/08/27 00:41:51 naddy Exp $
--- ls.c.orig 2003-08-27 00:37:00.000000000 +0200
+++ ls.c 2003-08-27 00:47:19.000000000 +0200
@@ -61,6 +61,10 @@ static char rcsid[] = "$OpenBSD: ls.c,v
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -12,15 +12,7 @@ $OpenBSD: patch-ls_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
#include "ls.h"
#include "extern.h"
@@ -89,6 +93,7 @@ int f_accesstime; /* use time of last a
int f_column; /* columnated format */
int f_columnacross; /* columnated format, sorted across */
int f_flags; /* show flags associated with a file */
+int f_humanval; /* show human-readable file sizes */
int f_inode; /* print inode */
int f_listdir; /* list actual directory, not contents */
int f_listdot; /* list files beginning with . */
@@ -108,6 +113,15 @@ int f_dirname; /* if precede with dire
@@ -105,6 +109,15 @@ int f_dirname; /* if precede with dire
int f_type; /* add type character for non-regular files */
int f_typedir; /* add type character for directories */
int f_whiteout; /* show whiteout entries */
@ -36,29 +28,28 @@ $OpenBSD: patch-ls_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
int rval;
@@ -122,6 +136,12 @@ ls_main(argc, argv)
@@ -116,6 +129,11 @@ ls_main(int argc, char *argv[])
int ch, fts_options, notused;
int kflag = 0;
char *p;
+#ifdef COLORLS
+ char termcapbuf[1024]; /* termcap definition buffer */
+ char tcapbuf[512]; /* capability buffer */
+ char *bp = tcapbuf;
+#endif
+
/* Terminal defaults to -Cq, non-terminal defaults to -1. */
if (isatty(STDOUT_FILENO)) {
if ((p = getenv("COLUMNS")) != NULL)
@@ -138,7 +158,7 @@ ls_main(argc, argv)
@@ -133,7 +151,7 @@ ls_main(int argc, char *argv[])
f_listdot = 1;
fts_options = FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklmnopqrstux")) != -1) {
- while ((ch = getopt(argc, argv, "1ACFLRSTWacdfghiklmnopqrstux")) != -1) {
+ while ((ch = getopt(argc, argv, "1ACFGLRSTWacdfghiklmnopqrstux")) != -1) {
switch (ch) {
/*
* The -1, -C and -l, -m and -x options all override each
@@ -183,6 +203,9 @@ ls_main(argc, argv)
@@ -178,6 +196,9 @@ ls_main(int argc, char *argv[])
case 'F':
f_type = 1;
break;
@ -68,17 +59,7 @@ $OpenBSD: patch-ls_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
case 'L':
fts_options &= ~FTS_PHYSICAL;
fts_options |= FTS_LOGICAL;
@@ -206,6 +229,9 @@ ls_main(argc, argv)
break;
case 'g': /* Compatibility with 4.3BSD. */
break;
+ case 'h':
+ f_humanval = 1;
+ break;
case 'i':
f_inode = 1;
break;
@@ -247,11 +273,46 @@ ls_main(argc, argv)
@@ -245,11 +266,46 @@ ls_main(int argc, char *argv[])
argc -= optind;
argv += optind;
@ -104,7 +85,7 @@ $OpenBSD: patch-ls_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
+#else
+ warnx("color support not compiled in");
+#endif /*COLORLS*/
+
+
+#ifdef COLORLS
+ if (f_color) {
+ (void)signal(SIGINT, colorquit);

View File

@ -1,15 +1,7 @@
$OpenBSD: patch-ls_h,v 1.2 2003/01/20 01:45:14 naddy Exp $
--- ls.h.orig Mon Jan 20 00:08:15 2003
+++ ls.h Mon Jan 20 01:51:54 2003
@@ -45,6 +45,7 @@ extern long blocksize; /* block size un
extern int f_accesstime; /* use time of last access */
extern int f_flags; /* show flags associated with a file */
+extern int f_humanval; /* show human-readable file sizes */
extern int f_inode; /* print inode */
extern int f_longform; /* long listing format */
extern int f_nonprint; /* show unprintables as ? */
@@ -53,6 +54,9 @@ extern int f_size; /* list size in shor
$OpenBSD: patch-ls_h,v 1.3 2003/08/27 00:41:51 naddy Exp $
--- ls.h.orig 2003-08-06 21:09:09.000000000 +0200
+++ ls.h 2003-08-27 00:31:29.000000000 +0200
@@ -50,6 +50,9 @@ extern int f_size; /* list size in shor
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 */

View File

@ -1,17 +1,10 @@
$OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
--- print.c.orig Mon Jan 20 00:08:15 2003
+++ print.c Mon Jan 20 02:10:19 2003
@@ -53,12 +53,18 @@ static char rcsid[] = "$OpenBSD: print.c
#include <fts.h>
#include <grp.h>
#include <pwd.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
$OpenBSD: patch-print_c,v 1.4 2003/08/27 00:41:51 naddy Exp $
--- print.c.orig 2003-08-27 00:56:42.000000000 +0200
+++ print.c 2003-08-27 01:16:49.000000000 +0200
@@ -56,6 +56,11 @@ static char rcsid[] = "$OpenBSD: print.c
#include <tzfile.h>
#include <unistd.h>
#include <util.h>
+#ifdef COLORLS
+#include <ctype.h>
+#include <termcap.h>
@ -20,11 +13,9 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
#include "ls.h"
#include "extern.h"
@@ -67,10 +73,44 @@ static int printaname(FTSENT *, u_long,
static void printlink(FTSENT *);
@@ -66,9 +71,39 @@ static void printsize(size_t, off_t);
static void printtime(time_t);
static int printtype(u_int);
+static void printsize(size_t, off_t);
static int compute_columns(DISPLAY *, int *);
+#ifdef COLORLS
+static void endcolor(int);
@ -33,9 +24,6 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
+typedef enum { NONE = 0, KILO, MEGA, GIGA, TERA, PETA /* , EXA */ } unit_t;
+static unit_t unit_adjust(double *);
+
+#ifdef COLORLS
+/* Most of these are taken from <sys/stat.h> */
+typedef enum Colors {
@ -63,9 +51,9 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
+#endif
+
void
printscol(dp)
DISPLAY *dp;
@@ -93,6 +133,9 @@ printlong(dp)
printscol(DISPLAY *dp)
{
@@ -89,6 +124,9 @@ printlong(DISPLAY *dp)
FTSENT *p;
NAMES *np;
char buf[20];
@ -75,19 +63,7 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
(void)printf("total %lu\n", howmany(dp->btotal, blocksize));
@@ -117,17 +160,25 @@ printlong(dp)
(void)printf("%3d, %3d ",
major(sp->st_rdev), minor(sp->st_rdev));
else if (dp->bcfile)
- (void)printf("%*s%*qd ",
+ (void)printf("%*s%*lld ",
8 - dp->s_size, "", dp->s_size, sp->st_size);
else
- (void)printf("%*qd ", dp->s_size, sp->st_size);
+ printsize(dp->s_size, sp->st_size);
if (f_accesstime)
printtime(sp->st_atime);
else if (f_statustime)
@@ -123,7 +161,15 @@ printlong(DISPLAY *dp)
printtime(sp->st_ctime);
else
printtime(sp->st_mtime);
@ -103,7 +79,7 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
(void)printtype(sp->st_mode);
if (S_ISLNK(sp->st_mode))
@@ -228,6 +279,9 @@ printaname(p, inodefield, sizefield)
@@ -219,6 +265,9 @@ printaname(FTSENT *p, u_long inodefield,
{
struct stat *sp;
int chcnt;
@ -113,48 +89,45 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
sp = p->fts_statp;
chcnt = 0;
@@ -236,7 +290,15 @@ printaname(p, inodefield, sizefield)
@@ -227,7 +276,15 @@ printaname(FTSENT *p, u_long inodefield,
if (f_size)
chcnt += printf("%*qd ",
(int)sizefield, howmany(sp->st_blocks, blocksize));
+#ifdef COLORLS
+ if (f_color)
+ color_printed = colortype(sp->st_mode);
+#endif
+#endif
chcnt += putname(p->fts_name);
+#ifdef COLORLS
+ if (f_color && color_printed)
+ endcolor(0);
+#endif
+#endif
if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
chcnt += printtype(sp->st_mode);
return (chcnt);
@@ -359,6 +421,156 @@ printtype(mode)
@@ -346,6 +403,150 @@ printtype(u_int mode)
return (0);
}
+#ifdef COLORLS
+static int
+putch(c)
+ int c;
+putch(int c)
+{
+ (void) putchar(c);
+ (void)putchar(c);
+ return 0;
+}
+
+static int
+writech(c)
+ int c;
+writech(int c)
+{
+ char tmp = c;
+
+ (void) write(STDOUT_FILENO, &tmp, 1);
+ (void)write(STDOUT_FILENO, &tmp, 1);
+ return 0;
+}
+
+static void
+printcolor(c)
+ Colors c;
+printcolor(Colors c)
+{
+ char *ansiseq;
+
@ -174,42 +147,40 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
+}
+
+static void
+endcolor(sig)
+ int sig;
+endcolor(int sig)
+{
+ tputs(ansi_coloff, 1, sig ? writech : putch);
+ tputs(attrs_off, 1, sig ? writech : putch);
+}
+
+static int
+colortype(mode)
+ mode_t mode;
+colortype(mode_t mode)
+{
+ switch (mode & S_IFMT) {
+ case S_IFDIR:
+ if (mode & S_IWOTH)
+ if (mode & S_ISTXT)
+ printcolor(C_WSDIR);
+ else
+ printcolor(C_WDIR);
+ case S_IFDIR:
+ if (mode & S_IWOTH)
+ if (mode & S_ISTXT)
+ printcolor(C_WSDIR);
+ else
+ printcolor(C_DIR);
+ return (1);
+ case S_IFLNK:
+ printcolor(C_LNK);
+ return (1);
+ case S_IFSOCK:
+ printcolor(C_SOCK);
+ return (1);
+ case S_IFIFO:
+ printcolor(C_FIFO);
+ return (1);
+ case S_IFBLK:
+ printcolor(C_BLK);
+ return (1);
+ case S_IFCHR:
+ printcolor(C_CHR);
+ return (1);
+ printcolor(C_WDIR);
+ else
+ printcolor(C_DIR);
+ return (1);
+ case S_IFLNK:
+ printcolor(C_LNK);
+ return (1);
+ case S_IFSOCK:
+ printcolor(C_SOCK);
+ return (1);
+ case S_IFIFO:
+ printcolor(C_FIFO);
+ return (1);
+ case S_IFBLK:
+ printcolor(C_BLK);
+ return (1);
+ case S_IFCHR:
+ printcolor(C_CHR);
+ return (1);
+ }
+ if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
+ if (mode & S_ISUID)
@ -224,8 +195,7 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
+}
+
+void
+parsecolors(cs)
+ const char *cs;
+parsecolors(const char *cs)
+{
+ int i;
+ int j;
@ -281,66 +251,8 @@ $OpenBSD: patch-print_c,v 1.3 2003/01/20 01:45:14 naddy Exp $
+ (void)kill(getpid(), sig);
+}
+
+#endif /*COLORLS*/
+#endif /* COLORLS */
+
static void
printlink(p)
FTSENT *p;
@@ -378,4 +590,57 @@ printlink(p)
path[lnklen] = '\0';
(void)printf(" -> ");
(void)putname(path);
+}
+
+static void
+printsize(size_t width, off_t bytes)
+{
+ double dbytes;
+ unit_t unit;
+
+ if (f_humanval) {
+ dbytes = bytes;
+ unit = unit_adjust(&dbytes);
+
+ if (dbytes == 0)
+ (void)printf("%*s ", width, "0B");
+ else
+ (void)printf("%*.*f%c ", width - 1, dbytes > 10 ? 0 : 1,
+ dbytes, "BKMGTPE"[unit]);
+ } else
+ (void)printf("%*lld ", width, bytes);
+}
+
+/*
+ * Output in "human-readable" format. Uses 3 digits max and puts
+ * unit suffixes at the end. Makes output compact and easy to read,
+ * especially on huge disks.
+ *
+ */
+static unit_t
+unit_adjust(double *val)
+{
+ double abval;
+ unit_t unit;
+
+ abval = fabs(*val);
+ if (abval < 1024)
+ unit = NONE;
+ else if (abval < 1048576ULL) {
+ unit = KILO;
+ *val /= 1024;
+ } else if (abval < 1073741824ULL) {
+ unit = MEGA;
+ *val /= 1048576;
+ } else if (abval < 1099511627776ULL) {
+ unit = GIGA;
+ *val /= 1073741824ULL;
+ } else if (abval < 1125899906842624ULL) {
+ unit = TERA;
+ *val /= 1099511627776ULL;
+ } else /* if (abval < 1152921504606846976ULL) */ {
+ unit = PETA;
+ *val /= 1125899906842624ULL;
+ }
+ return (unit);
}
printlink(FTSENT *p)
{

View File

@ -1,17 +1,15 @@
$OpenBSD: patch-util_c,v 1.2 2003/01/20 01:45:14 naddy Exp $
--- util.c.orig Mon Jan 20 00:08:15 2003
+++ util.c Mon Jan 20 01:54:08 2003
@@ -72,7 +72,11 @@ void
usage()
$OpenBSD: patch-util_c,v 1.3 2003/08/27 00:41:51 naddy Exp $
--- util.c.orig 2003-08-27 00:32:47.000000000 +0200
+++ util.c 2003-08-27 00:33:44.000000000 +0200
@@ -67,7 +67,11 @@ void
usage(void)
{
(void)fprintf(stderr,
- "usage: %s [-1ACFLRSTWacdfiklmnopqrstux] [file ...]\n",
- __progname);
+#ifdef COLORLS
+ "usage: %s [-1ACFGLRSTWacdfhiklmnopqrstux]"
+ "usage: %s [-1ACFGLRSTWacdfhiklmnopqrstux] [file ...]\n",
+#else
+ "usage: %s [-1ACFLRSTWacdfhiklmnopqrstux]"
"usage: %s [-1ACFLRSTWacdfhiklmnopqrstux] [file ...]\n",
+#endif
+ " [file ...]\n", __progname);
__progname);
exit(1);
}