Automatically resize the major and minor number fields, and DTRT if the size

field is not the same size.
This commit is contained in:
mycroft 1998-01-17 12:00:42 +00:00
parent 02f88f3555
commit 9ded7f638d
3 changed files with 32 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ls.c,v 1.22 1997/07/30 05:01:01 thorpej Exp $ */
/* $NetBSD: ls.c,v 1.23 1998/01/17 12:00:42 mycroft Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)ls.c 8.7 (Berkeley) 8/5/94";
#else
__RCSID("$NetBSD: ls.c,v 1.22 1997/07/30 05:01:01 thorpej Exp $");
__RCSID("$NetBSD: ls.c,v 1.23 1998/01/17 12:00:42 mycroft Exp $");
#endif
#endif /* not lint */
@ -390,6 +390,7 @@ display(p, list)
NAMES *np;
u_quad_t maxsize;
u_long btotal, maxblock, maxinode, maxlen, maxnlink;
u_long maxmajor, maxminor;
int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
int entries, needstats;
char *user, *group, buf[20]; /* 32 bits == 10 digits */
@ -411,6 +412,7 @@ display(p, list)
bcfile = 0;
maxuser = maxgroup = maxflags = 0;
maxsize = 0;
maxmajor = maxminor = 0;
for (cur = list, entries = 0; cur; cur = cur->fts_link) {
if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
warnx("%s: %s",
@ -450,6 +452,13 @@ display(p, list)
maxnlink = sp->st_nlink;
if (sp->st_size > maxsize)
maxsize = sp->st_size;
if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) {
bcfile = 1;
if (major(sp->st_rdev) > maxmajor)
maxmajor = major(sp->st_rdev);
if (minor(sp->st_rdev) > maxminor)
maxminor = minor(sp->st_rdev);
}
btotal += sp->st_blocks;
if (f_longform) {
@ -476,10 +485,6 @@ display(p, list)
np->group = &np->data[ulen + 1];
(void)strcpy(np->group, group);
if (S_ISCHR(sp->st_mode) ||
S_ISBLK(sp->st_mode))
bcfile = 1;
if (f_flags) {
np->flags = &np->data[ulen + glen + 2];
(void)strcpy(np->flags, flags);
@ -497,7 +502,6 @@ display(p, list)
d.entries = entries;
d.maxlen = maxlen;
if (needstats) {
d.bcfile = bcfile;
d.btotal = btotal;
(void)snprintf(buf, sizeof(buf), "%lu", maxblock);
d.s_block = strlen(buf);
@ -510,6 +514,19 @@ display(p, list)
(void)snprintf(buf, sizeof(buf), "%qu", (long long)maxsize);
d.s_size = strlen(buf);
d.s_user = maxuser;
if (bcfile) {
(void)snprintf(buf, sizeof(buf), "%lu", maxmajor);
d.s_major = strlen(buf);
(void)snprintf(buf, sizeof(buf), "%lu", maxminor);
d.s_minor = strlen(buf);
if (d.s_major + d.s_minor + 2 > d.s_size)
d.s_size = d.s_major + d.s_minor + 2;
else if (d.s_size - d.s_minor - 2 > d.s_major)
d.s_major = d.s_size - d.s_minor - 2;
} else {
d.s_major = 0;
d.s_minor = 0;
}
}
printfcn(&d);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ls.h,v 1.7 1995/03/21 09:06:33 cgd Exp $ */
/* $NetBSD: ls.h,v 1.8 1998/01/17 12:00:44 mycroft Exp $ */
/*
* Copyright (c) 1989, 1993
@ -54,7 +54,6 @@ extern int f_type; /* add type character for non-regular files */
typedef struct {
FTSENT *list;
u_long btotal;
int bcfile;
int entries;
int maxlen;
int s_block;
@ -64,6 +63,8 @@ typedef struct {
int s_nlink;
int s_size;
int s_user;
int s_major;
int s_minor;
} DISPLAY;
typedef struct {

View File

@ -1,4 +1,4 @@
/* $NetBSD: print.c,v 1.17 1997/07/30 05:01:04 thorpej Exp $ */
/* $NetBSD: print.c,v 1.18 1998/01/17 12:00:46 mycroft Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94";
#else
__RCSID("$NetBSD: print.c,v 1.17 1997/07/30 05:01:04 thorpej Exp $");
__RCSID("$NetBSD: print.c,v 1.18 1998/01/17 12:00:46 mycroft Exp $");
#endif
#endif /* not lint */
@ -115,12 +115,9 @@ printlong(dp)
if (f_flags)
(void)printf("%-*s ", dp->s_flags, np->flags);
if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
(void)printf("%3d, %3d ",
major(sp->st_rdev), minor(sp->st_rdev));
else if (dp->bcfile)
(void)printf("%*s%*qd ",
8 - dp->s_size, "", dp->s_size,
(long long)sp->st_size);
(void)printf("%*u, %*u ",
dp->s_major, major(sp->st_rdev), dp->s_minor,
minor(sp->st_rdev));
else
(void)printf("%*qd ", dp->s_size,
(long long)sp->st_size);