A better algorithm to place the numbers on the lines.

Submitted by:	satoshi
This commit is contained in:
Joerg Wunsch 1996-01-30 23:14:34 +00:00
parent a52d2adc63
commit 768efa9d3c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=13769

View File

@ -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 @@ mkfs(pp, fsys, fi, fo)
* 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;
}