pkgsrc-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
pkg/30551: human readable format for pkgsrc/misc/colorls
>Number: 30551
>Category: pkg
>Synopsis: human readable format for pkgsrc/misc/colorls
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: pkg-manager
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sat Jun 18 21:15:00 +0000 2005
>Originator: Holger Weiss
>Release: NetBSD 2.0_STABLE
>Organization:
Individual Network Berlin e.V.
>Environment:
System: NetBSD pandora.jhweiss.de 2.0_STABLE NetBSD 2.0_STABLE (PANDORA) #0:
Fri Jun 3 18:25:06 CEST 2005
holger%pandora.jhweiss.de@localhost:/usr/build/obj/sys/arch/i386/compile/PANDORA
i386
Architecture: i386
Machine: i386
>Description:
pkgsrc/misc/colorls doesn't provide an "human readable" size format option.
>How-To-Repeat:
$ colorls -h
>Fix:
The following patch adds "-h" from base ls to colorls on NetBSD >= 2.0.
Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/misc/colorls/Makefile,v
retrieving revision 1.18
diff -u -r1.18 Makefile
--- Makefile 24 Mar 2005 21:12:57 -0000 1.18
+++ Makefile 11 Jun 2005 00:36:40 -0000
@@ -2,6 +2,7 @@
DISTNAME= ls
PKGNAME= colorls-2.2
+PKGREVISION= 1
CATEGORIES= misc
MASTER_SITES= ${MASTER_SITE_LOCAL}
Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/misc/colorls/distinfo,v
retrieving revision 1.4
diff -u -r1.4 distinfo
--- distinfo 24 Feb 2005 11:02:51 -0000 1.4
+++ distinfo 11 Jun 2005 00:36:40 -0000
@@ -4,7 +4,8 @@
RMD160 (ls.tar.gz) = 7b607b7ab953ad0dc603c269fa03648cd54ac04f
Size (ls.tar.gz) = 11768 bytes
SHA1 (patch-aa) = 831f286605126a136b540b4456916db8cc8ff7e4
-SHA1 (patch-ab) = 8f26c3e16bb85371bbb16c5f77a667b3a456af68
-SHA1 (patch-ac) = 89f775c18318c4ca8a7dbebc2daba7c52ae0878f
-SHA1 (patch-ad) = d502e96261a950c5307794f01422147430c76aba
-SHA1 (patch-ae) = 9b15ef9f8ab3e77b34a0f7ee401fbe8dcae4a854
+SHA1 (patch-ab) = 181bfcbfbaa095fa82492594ccd8831cc81c3e72
+SHA1 (patch-ac) = fec6cb91aaeb8a9fb2aa557eb827845ca35cd198
+SHA1 (patch-ad) = 645f950f48f945493bf2b8792ad1da9b93f952bd
+SHA1 (patch-ae) = 771f4ceb50656481050a3a017abb02862cc24f34
+SHA1 (patch-af) = 3d758fe9ef977751a1b6da13ce74d8b4c72e33b1
Index: patches/patch-ab
===================================================================
RCS file: /cvsroot/pkgsrc/misc/colorls/patches/patch-ab,v
retrieving revision 1.7
diff -u -r1.7 patch-ab
--- patches/patch-ab 13 Oct 2004 18:50:13 -0000 1.7
+++ patches/patch-ab 11 Jun 2005 00:36:40 -0000
@@ -2,8 +2,7 @@
--- colorls.1.orig Wed Oct 13 14:49:05 2004
+++ colorls.1
-@@ -37,14 +37,22 @@
- .\"
+@@ -38,12 +38,20 @@
.Dd July 29, 1994
-.Dt LS 1
+.Dt COLORLS 1
@@ -29,9 +28,7 @@
+is for color display.)
+.Pp
For each operand that names a
- .Ar file
-@@ -88,4 +96,10 @@ a percent sign (%) after each whiteout,
- and a vertical bar (|) after each that is a
+@@ -89,2 +97,8 @@ and a vertical bar (|) after each that i
.Tn FIFO .
+.It Fl G
+Use ANSI color sequences to distinguish file types. (See
@@ -40,9 +37,20 @@
+.Fl F ,
+some extra attributes (setuid bit set, etc.) are also displayed.
.It Fl L
- If argument is a symbolic link, list the file or directory the link references
-@@ -319,4 +333,72 @@ See
- .Xr environ 7
+@@ -109,2 +123,12 @@ symbolic links in the argument list are
+ Output is not sorted.
++.It Fl h
++Modifies the
++.Fl s
++and
++.Fl l
++options, causing the sizes to be reported in bytes displayed in a human
++readable format.
++Overrides
++.Fl k .
++This option is not available on all systems.
+ .It Fl i
+@@ -320,2 +344,70 @@ See
for more information.
+.It LSCOLORS
+The value of this variable describes what color to use for which
@@ -113,4 +121,3 @@
+default background for regular directories, black foreground and red
+background for setuid executables, etc.
.El
- .Sh COMPATIBILITY
Index: patches/patch-ac
===================================================================
RCS file: /cvsroot/pkgsrc/misc/colorls/patches/patch-ac,v
retrieving revision 1.3
diff -u -r1.3 patch-ac
--- patches/patch-ac 28 Dec 1998 22:13:05 -0000 1.3
+++ patches/patch-ac 11 Jun 2005 00:36:40 -0000
@@ -1,8 +1,8 @@
$NetBSD: patch-ac,v 1.3 1998/12/28 22:13:05 marc Exp $
--- ls.c.orig Sat Dec 21 18:40:58 1996
-+++ ls.c Mon Dec 28 17:10:04 1998
-@@ -59,6 +59,8 @@
++++ ls.c
+@@ -59,6 +59,8 @@ static char const sccsid[] = "@(#)ls.c 8
#include <string.h>
#include <unistd.h>
#include <locale.h>
@@ -11,7 +11,17 @@
#include "ls.h"
#include "extern.h"
-@@ -94,6 +96,7 @@
+@@ -77,6 +79,9 @@ int termwidth = 80; /* default terminal
+ int f_accesstime; /* use time of last access */
+ int f_column; /* columnated format */
+ int f_flags; /* show flags associated with a file */
++#if HAVE_HUMANIZE_NUMBER
++int f_humanize; /* humanize the size field */
++#endif
+ int f_inode; /* print inode */
+ int f_kblocks; /* print size in kilobytes */
+ int f_listdir; /* list actual directory, not contents
*/
+@@ -94,6 +99,7 @@ int f_statustime; /* use time of last m
int f_dirname; /* if precede with directory name */
int f_timesort; /* sort by time vice name */
int f_type; /* add type character for non-regular files */
@@ -19,19 +29,25 @@
#ifndef BSD4_4_LITE
int f_whiteout; /* show whiteout entries */
#endif
-@@ -135,9 +138,9 @@
+@@ -134,10 +140,14 @@ main(argc, argv)
+ f_listdot = 1;
fts_options = FTS_PHYSICAL;
- #ifdef BSD4_4_LITE
+-#ifdef BSD4_4_LITE
- while ((ch = getopt(argc, argv, "1ACFLRTacdfgikloqrstu")) != EOF) {
++#if defined(BSD4_4_LITE) && HAVE_HUMANIZE_NUMBER
++ while ((ch = getopt(argc, argv, "1ACFGLRTacdfghikloqrstu")) != EOF) {
++#elif defined(BSD4_4_LITE)
+ while ((ch = getopt(argc, argv, "1ACFGLRTacdfgikloqrstu")) != EOF) {
++#elif HAVE_HUMANIZE_NUMBER
++ while ((ch = getopt(argc, argv, "1ACFGLRTWacdfghikloqrstu")) != EOF) {
#else
- while ((ch = getopt(argc, argv, "1ACFLRTWacdfgikloqrstu")) != EOF) {
+ while ((ch = getopt(argc, argv, "1ACFGLRTWacdfgikloqrstu")) != EOF) {
#endif
switch (ch) {
/*
-@@ -168,6 +171,10 @@
+@@ -168,6 +178,10 @@ main(argc, argv)
case 'F':
f_type = 1;
break;
@@ -42,7 +58,23 @@
case 'L':
fts_options &= ~FTS_PHYSICAL;
fts_options |= FTS_LOGICAL;
-@@ -228,18 +235,21 @@
+@@ -191,6 +205,15 @@ main(argc, argv)
+ break;
+ case 'g': /* Compatibility with 4.3BSD. */
+ break;
++#if HAVE_HUMANIZE_NUMBER
++ /*
++ * The -h option forces all sizes to be measured in bytes.
++ * It also makes -l suppress -s.
++ */
++ case 'h':
++ f_humanize = 1;
++ break;
++#endif
+ case 'i':
+ f_inode = 1;
+ break;
+@@ -228,18 +251,21 @@ main(argc, argv)
argc -= optind;
argv += optind;
@@ -66,8 +98,13 @@
fts_options |= FTS_COMFOLLOW;
#ifndef BSD4_4_LITE
-@@ -384,7 +394,8 @@
+@@ -382,9 +408,13 @@ display(p, list)
+ NAMES *np;
+ u_quad_t maxsize;
u_long btotal, maxblock, maxinode, maxlen, maxnlink;
++#if HAVE_HUMANIZE_NUMBER
++ u_long stotal;
++#endif
int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
int entries, needstats;
- char *user, *group, *flags, buf[20]; /* 32 bits == 10 digits */
@@ -76,3 +113,62 @@
/*
* If list is NULL there are two possibilities: that the parent
+@@ -399,6 +429,9 @@ display(p, list)
+ needstats = f_inode || f_longform || f_size;
+ flen = 0;
+ btotal = maxblock = maxinode = maxlen = maxnlink = 0;
++#if HAVE_HUMANIZE_NUMBER
++ stotal = 0;
++#endif
+ bcfile = 0;
+ maxuser = maxgroup = maxflags = 0;
+ flags = NULL;
+@@ -445,6 +478,9 @@ display(p, list)
+ maxsize = sp->st_size;
+
+ btotal += sp->st_blocks;
++#if HAVE_HUMANIZE_NUMBER
++ stotal += sp->st_size;
++#endif
+ if (f_longform) {
+ user = user_from_uid(sp->st_uid, 0);
+ if ((ulen = strlen(user)) > maxuser)
+@@ -492,16 +528,34 @@ display(p, list)
+ if (needstats) {
+ d.bcfile = bcfile;
+ d.btotal = btotal;
+- (void)snprintf(buf, sizeof(buf), "%lu", maxblock);
+- d.s_block = strlen(buf);
++#if HAVE_HUMANIZE_NUMBER
++ d.stotal = stotal;
++ if (f_humanize) {
++ d.s_block = 4; /* min buf length for humanize_number */
++ } else {
++#endif
++ (void)snprintf(buf, sizeof(buf), "%lu", maxblock);
++ d.s_block = strlen(buf);
++#if HAVE_HUMANIZE_NUMBER
++ }
++#endif
+ d.s_flags = maxflags;
+ d.s_group = maxgroup;
+ (void)snprintf(buf, sizeof(buf), "%lu", maxinode);
+ d.s_inode = strlen(buf);
+ (void)snprintf(buf, sizeof(buf), "%lu", maxnlink);
+ d.s_nlink = strlen(buf);
+- (void)snprintf(buf, sizeof(buf), "%qu", maxsize);
+- d.s_size = strlen(buf);
++#if HAVE_HUMANIZE_NUMBER
++ d.stotal = stotal;
++ if (f_humanize) {
++ d.s_size = 4; /* min buf length for humanize_number */
++ } else {
++#endif
++ (void)snprintf(buf, sizeof(buf), "%qu", maxsize);
++ d.s_size = strlen(buf);
++#if HAVE_HUMANIZE_NUMBER
++ }
++#endif
+ d.s_user = maxuser;
+ }
+
Index: patches/patch-ad
===================================================================
RCS file: /cvsroot/pkgsrc/misc/colorls/patches/patch-ad,v
retrieving revision 1.2
diff -u -r1.2 patch-ad
--- patches/patch-ad 7 Aug 1998 11:10:12 -0000 1.2
+++ patches/patch-ad 11 Jun 2005 00:36:40 -0000
@@ -1,12 +1,43 @@
$NetBSD: patch-ad,v 1.2 1998/08/07 11:10:12 agc Exp $
--- ls.h.orig Sun Dec 22 00:40:58 1996
-+++ ls.h Thu May 21 15:42:08 1998
-@@ -54,6 +54,7 @@
- extern int f_size; /* list size in short listing */
++++ ls.h
+@@ -38,4 +38,6 @@
+ */
+
++#include <sys/param.h>
++
+ #define NO_PRINT 1
+ /*
+@@ -44,4 +46,10 @@
+ */
+ #define BSD4_4_LITE
++/*
++ * humanize_number(3) is needed for human-readable format.
++ */
++#if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 200000000
++#define HAVE_HUMANIZE_NUMBER 1
++#endif
+
+ extern long blocksize; /* block size units */
+@@ -49,4 +57,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 */
++#if HAVE_HUMANIZE_NUMBER
++extern int f_humanize; /* humanize size field */
++#endif
+ extern int f_inode; /* print inode */
+ extern int f_longform; /* long listing format */
+@@ -55,8 +66,12 @@ 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_color; /* add type in color for non-regular files */
typedef struct {
FTSENT *list;
+ u_long btotal;
++#if HAVE_HUMANIZE_NUMBER
++ u_long stotal;
++#endif
+ int bcfile;
+ int entries;
Index: patches/patch-ae
===================================================================
RCS file: /cvsroot/pkgsrc/misc/colorls/patches/patch-ae,v
retrieving revision 1.2
diff -u -r1.2 patch-ae
--- patches/patch-ae 7 Aug 1998 11:10:13 -0000 1.2
+++ patches/patch-ae 11 Jun 2005 00:36:41 -0000
@@ -1,11 +1,27 @@
$NetBSD: patch-ae,v 1.2 1998/08/07 11:10:13 agc Exp $
--- print.c.orig Sun Dec 22 00:40:58 1996
-+++ print.c Thu May 21 15:42:08 1998
-@@ -64,6 +64,26 @@
++++ print.c
+@@ -57,12 +57,41 @@ static char const sccsid[] = "@(#)print.
+ #include "ls.h"
+ #include "extern.h"
- #define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
++#if HAVE_HUMANIZE_NUMBER
++#include <util.h>
++#endif
++
+ static int printaname __P((FTSENT *, u_long, u_long));
+ static void printlink __P((FTSENT *));
+ static void printtime __P((time_t));
+ static int printtype __P((u_int));
+ #define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
++#if HAVE_HUMANIZE_NUMBER
++#define HUMANIZE_NUMBER(buf, len, num) humanize_number(buf, len, num,
"", \
++ HN_AUTOSCALE,
\
++ (HN_DECIMAL | HN_B |
HN_NOSPACE))
++#endif
++
+/* Most of these are taken from <sys/stat.h> */
+typedef enum Colors {
+ C_DIR, /* directory */
@@ -25,11 +41,80 @@
+char *defcolors = "4x5x2x3x1x464301060203";
+
+static int colors[C_NUMCOLORS][2];
-+
+
void
printscol(dp)
- DISPLAY *dp;
-@@ -124,10 +144,14 @@
+@@ -86,9 +115,21 @@ printlong(dp)
+ FTSENT *p;
+ NAMES *np;
+ char buf[20];
++#if HAVE_HUMANIZE_NUMBER
++ char szbuf[5];
++#endif
+
+- if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
+- (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
++ if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
++#if HAVE_HUMANIZE_NUMBER
++ if (f_humanize) {
++ if (HUMANIZE_NUMBER(szbuf, sizeof(szbuf), dp->stotal)
++ == -1)
++ err(1, "humanize_number");
++ (void)printf("total %s\n", szbuf);
++ } else
++#endif
++ (void)printf("total %lu\n", howmany(dp->btotal,
blocksize));
++ }
+
+ for (p = dp->list; p; p = p->fts_link) {
+ if (IS_NOPRINT(p))
+@@ -96,7 +137,11 @@ printlong(dp)
+ sp = p->fts_statp;
+ if (f_inode)
+ (void)printf("%*lu ", dp->s_inode, (u_long)sp->st_ino);
++#if HAVE_HUMANIZE_NUMBER
++ if (f_size && !f_humanize)
++#else
+ if (f_size)
++#endif
+ (void)printf("%*qd ",
+ dp->s_block, howmany(sp->st_blocks, blocksize));
+ (void)strmode(sp->st_mode, buf);
+@@ -106,28 +151,42 @@ printlong(dp)
+ np->group);
+ if (f_flags)
+ (void)printf("%-*s ", dp->s_flags, np->flags);
+- if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
+- if (minor(sp->st_rdev) > 255)
++ if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) {
++ if (minor(sp->st_rdev) > 255) {
+ (void)printf("%3d, 0x%08x ",
+ major(sp->st_rdev), minor(sp->st_rdev));
+- else
++ } else {
+ (void)printf("%3d, %3d ",
+ major(sp->st_rdev), minor(sp->st_rdev));
+- else if (dp->bcfile)
++ }
++ } else if (dp->bcfile) {
+ (void)printf("%*s%*qd ",
+ 8 - dp->s_size, "", dp->s_size, sp->st_size);
+- else
+- (void)printf("%*qd ", dp->s_size, sp->st_size);
++ } else {
++#if HAVE_HUMANIZE_NUMBER
++ if (f_humanize) {
++ if (HUMANIZE_NUMBER(szbuf, sizeof(szbuf),
++ sp->st_size) == -1)
++ err(1, "humanize_number");
++ (void)printf("%*s ", dp->s_size, szbuf);
++ } else
++#endif
++ (void)printf("%*qd ", dp->s_size, sp->st_size);
++ }
+ if (f_accesstime)
+ printtime(sp->st_atime);
+ else if (f_statustime)
printtime(sp->st_ctime);
else
printtime(sp->st_mtime);
@@ -45,8 +130,61 @@
printlink(p);
(void)putchar('\n');
}
-@@ -190,10 +214,22 @@
+@@ -145,6 +204,9 @@ printcol(dp)
+ FTSENT *p;
+ int base, chcnt, cnt, col, colwidth, num;
+ int endcol, numcols, numrows, row;
++#if HAVE_HUMANIZE_NUMBER
++ char szbuf[5];
++#endif
+
+ /*
+ * Have to do random access in the linked list -- build a table
+@@ -165,8 +227,14 @@ printcol(dp)
+ colwidth = dp->maxlen;
+ if (f_inode)
+ colwidth += dp->s_inode + 1;
+- if (f_size)
+- colwidth += dp->s_block + 1;
++ if (f_size) {
++#if HAVE_HUMANIZE_NUMBER
++ if (f_humanize)
++ colwidth += dp->s_size + 1;
++ else
++#endif
++ colwidth += dp->s_block + 1;
++ }
+ if (f_type)
+ colwidth += 1;
+
+@@ -181,19 +249,46 @@ printcol(dp)
+ if (num % numcols)
+ ++numrows;
+
+- if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
+- (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
++ if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) {
++#if HAVE_HUMANIZE_NUMBER
++ if (f_humanize) {
++ if (HUMANIZE_NUMBER(szbuf, sizeof(szbuf), dp->stotal) ==
++ -1)
++ err(1, "humanize_number");
++ (void)printf("total %s\n", szbuf);
++ } else
++#endif
++ (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) {
++#if HAVE_HUMANIZE_NUMBER
++ chcnt += printaname(array[base], dp->s_inode,
++ f_humanize ? dp->s_size : dp->s_block);
++#else
+ chcnt += printaname(array[base], dp->s_inode,
dp->s_block);
++#endif
if ((base += numrows) >= num)
break;
- while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol){
@@ -72,10 +210,33 @@
endcol += colwidth;
}
(void)putchar('\n');
-@@ -219,9 +255,13 @@
- if (f_size)
- chcnt += printf("%*qd ",
- (int)sizefield, howmany(sp->st_blocks, blocksize));
+@@ -211,17 +306,33 @@ printaname(p, inodefield, sizefield)
+ {
+ struct stat *sp;
+ int chcnt;
++#if HAVE_HUMANIZE_NUMBER
++ char szbuf[5];
++#endif
+
+ sp = p->fts_statp;
+ chcnt = 0;
+ if (f_inode)
+ chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino);
+- if (f_size)
+- chcnt += printf("%*qd ",
+- (int)sizefield, howmany(sp->st_blocks, blocksize));
++ if (f_size) {
++#if HAVE_HUMANIZE_NUMBER
++ if (f_humanize) {
++ if (HUMANIZE_NUMBER(szbuf, sizeof(szbuf), sp->st_size)
++ == -1)
++ err(1, "humanize_number");
++ chcnt += printf("%*s ", sizefield, szbuf);
++ } else
++#endif
++ chcnt += printf("%*qd ",
++ (int)sizefield, howmany(sp->st_blocks, blocksize));
++ }
+ if (f_color)
+ (void)colortype(sp->st_mode);
chcnt += printf("%s", p->fts_name);
@@ -86,7 +247,7 @@
return (chcnt);
}
-@@ -281,6 +321,95 @@
+@@ -281,6 +392,95 @@ printtype(mode)
return (0);
}
Index: patches/patch-af
===================================================================
RCS file: patches/patch-af
diff -N patches/patch-af
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-af 11 Jun 2005 00:36:41 -0000
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- util.c.orig 1996-12-22 00:40:58.000000000 +0100
++++ util.c
+@@ -68,8 +68,12 @@ prcopy(src, dest, len)
+ void
+ usage()
+ {
+-#ifdef BSD4_4_LITE
++#if defined(BSD4_4_LITE) && HAVE_HUMANIZE_NUMBER
++ (void)fprintf(stderr, "usage: ls [-1ACFLRTacdfhiklqrstu] [file ...]\n");
++#elif defined(BSD4_4_LITE)
+ (void)fprintf(stderr, "usage: ls [-1ACFLRTacdfiklqrstu] [file ...]\n");
++#elif HAVE_HUMANIZE_NUMBER
++ (void)fprintf(stderr, "usage: ls [-1ACFLRTWacdfhiklqrstu] [file
...]\n");
+ #else
+ (void)fprintf(stderr, "usage: ls [-1ACFLRTWacdfiklqrstu] [file ...]\n");
+ #endif
Home |
Main Index |
Thread Index |
Old Index