From 768efa9d3c10af6e7b3fcbb75ffb980c08acc219 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 30 Jan 1996 23:14:34 +0000 Subject: [PATCH] A better algorithm to place the numbers on the lines. Submitted by: satoshi --- sbin/newfs/mkfs.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 2d1f03ca0d46..29e1cdd44601 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -122,7 +122,7 @@ struct dinode zino[MAXBSIZE / sizeof(struct dinode)]; int fsi, fso; daddr_t alloc(); -static int numbersperline(); +static int charsperline(); mkfs(pp, fsys, fi, fo) struct partition *pp; @@ -138,6 +138,8 @@ mkfs(pp, fsys, fi, fo) time_t utime; quad_t sizepb; void started(); + int width; + char tmpbuf[100]; /* XXX this will break in about 2,500 years */ #ifndef STANDALONE time(&utime); @@ -621,15 +623,21 @@ next: * then print out indices of cylinder groups. */ if (!mfs) - printf("super-block backups (for fsck -b #) at:"); - i = numbersperline(sblock.fs_size * NSPF(&sblock)); + printf("super-block backups (for fsck -b #) at:\n"); + i = 0; + width = charsperline(); for (cylno = 0; cylno < sblock.fs_ncg; cylno++) { initcg(cylno, utime); if (mfs) continue; - if (cylno % i == 0) + j = sprintf(tmpbuf, " %d,", + fsbtodb(&sblock, cgsblock(&sblock, cylno))); + if (i+j >= width) { printf("\n"); - printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno))); + i = 0; + } + i += j; + printf("%s", tmpbuf); fflush(stdout); } if (!mfs) @@ -1268,23 +1276,18 @@ setblock(fs, cp, h) } /* - * Determine the number of block numbers that will nicely fit into a + * Determine the number of characters in a * single line. */ static int -numbersperline(seccount) - long seccount; +charsperline() { - int i, columns; + int columns; char *cp; struct winsize ws; extern char *getenv(); - for (i = 0; seccount; i++, seccount /= 10) - ; - i += 2; /* account for comma+space */ - columns = 0; if (ioctl(0, TIOCGWINSZ, &ws) != -1) columns = ws.ws_col; @@ -1292,8 +1295,5 @@ numbersperline(seccount) columns = atoi(cp); if (columns == 0) columns = 80; /* last resort */ - i = columns / i; - if (i < 3) - i = 3; /* don't care */ - return i; + return columns; }