1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-02 22:35:36 -08:00

Improve horizontal alignment in long format when printing minor

device numbers greater than 999 by measuring the two widths needed
for device numbers just like it is already done for other numbers.
In the output, this only changes whitespace, but not the text.

Ugly formatting reported by
Crystal Kolipe <kolipe dot c at exoticsilicon dot com>.

OK millert.  Also tested by Crystal Kolipe.
This commit is contained in:
schwarze 2023-10-07 11:51:08 +00:00
parent 6b6a24c484
commit 09b34e9cf9
3 changed files with 27 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ls.c,v 1.54 2020/10/07 21:03:09 millert Exp $ */
/* $OpenBSD: ls.c,v 1.55 2023/10/07 11:51:08 schwarze Exp $ */
/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */
/*
@ -436,6 +436,7 @@ display(FTSENT *p, FTSENT *list)
unsigned long long btotal;
blkcnt_t maxblock;
ino_t maxinode;
unsigned int maxmajor, maxminor;
int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser, maxlen;
int entries, needstats;
int width;
@ -449,6 +450,7 @@ display(FTSENT *p, FTSENT *list)
btotal = maxblock = maxinode = maxlen = maxnlink = 0;
bcfile = 0;
maxuser = maxgroup = maxflags = 0;
maxmajor = maxminor = 0;
maxsize = 0;
for (cur = list, entries = 0; cur != NULL; cur = cur->fts_link) {
if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
@ -523,9 +525,13 @@ display(FTSENT *p, FTSENT *list)
(void)strlcpy(np->group, group, glen + 1);
if (S_ISCHR(sp->st_mode) ||
S_ISBLK(sp->st_mode))
S_ISBLK(sp->st_mode)) {
bcfile = 1;
if (maxmajor < major(sp->st_rdev))
maxmajor = major(sp->st_rdev);
if (maxminor < minor(sp->st_rdev))
maxminor = minor(sp->st_rdev);
}
if (f_flags) {
np->flags = &np->data[ulen + 1 + glen + 1];
(void)strlcpy(np->flags, flags, flen + 1);
@ -551,7 +557,6 @@ display(FTSENT *p, FTSENT *list)
d.entries = entries;
d.maxlen = maxlen;
if (needstats) {
d.bcfile = bcfile;
d.btotal = btotal;
(void)snprintf(buf, sizeof(buf), "%llu",
(unsigned long long)maxblock);
@ -570,6 +575,17 @@ display(FTSENT *p, FTSENT *list)
d.s_size = strlen(buf);
} else
d.s_size = FMT_SCALED_STRSIZE-2; /* no - or '\0' */
d.s_major = d.s_minor = 3;
if (bcfile) {
(void)snprintf(buf, sizeof(buf), "%u", maxmajor);
d.s_major = strlen(buf);
(void)snprintf(buf, sizeof(buf), "%u", maxminor);
d.s_minor = strlen(buf);
if (d.s_size <= d.s_major + 2 + d.s_minor)
d.s_size = d.s_major + 2 + d.s_minor;
else
d.s_major = d.s_size - 2 - d.s_minor;
}
d.s_user = maxuser;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ls.h,v 1.9 2013/05/30 16:34:32 guenther Exp $ */
/* $OpenBSD: ls.h,v 1.10 2023/10/07 11:51:08 schwarze Exp $ */
/* $NetBSD: ls.h,v 1.7 1995/03/21 09:06:33 cgd Exp $ */
/*
@ -55,7 +55,6 @@ extern int f_typedir; /* add type character for directories */
typedef struct {
FTSENT *list;
unsigned long long btotal;
int bcfile;
int entries;
int maxlen;
int s_block;
@ -64,6 +63,8 @@ typedef struct {
int s_inode;
int s_nlink;
int s_size;
int s_major;
int s_minor;
int s_user;
} DISPLAY;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: print.c,v 1.39 2020/10/07 21:03:09 millert Exp $ */
/* $OpenBSD: print.c,v 1.40 2023/10/07 11:51:08 schwarze Exp $ */
/* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */
/*
@ -110,12 +110,9 @@ printlong(DISPLAY *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("%3u, %3u ",
major(sp->st_rdev), minor(sp->st_rdev));
else if (dp->bcfile)
(void)printf("%*s%*lld ",
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
printsize(dp->s_size, sp->st_size);
if (f_accesstime)