From owner-freebsd-commit Fri Jan 26 02:43:46 1996 Return-Path: owner-commit Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id CAA29493 for freebsd-commit-outgoing; Fri, 26 Jan 1996 02:43:46 -0800 (PST) Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id CAA29485 for cvs-all-outgoing; Fri, 26 Jan 1996 02:43:31 -0800 (PST) Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id CAA29478 for cvs-sbin-outgoing; Fri, 26 Jan 1996 02:43:28 -0800 (PST) Received: from silvia.HIP.Berkeley.EDU (silvia.HIP.Berkeley.EDU [136.152.64.181]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id CAA29465 Fri, 26 Jan 1996 02:43:08 -0800 (PST) Received: (from asami@localhost) by silvia.HIP.Berkeley.EDU (8.7.3/8.6.9) id CAA01515; Fri, 26 Jan 1996 02:43:06 -0800 (PST) Date: Fri, 26 Jan 1996 02:43:06 -0800 (PST) Message-Id: <199601261043.CAA01515@silvia.HIP.Berkeley.EDU> To: joerg@freefall.freebsd.org CC: CVS-committers@freefall.freebsd.org, cvs-sbin@freefall.freebsd.org In-reply-to: <199601252344.PAA18190@freefall.freebsd.org> (message from Joerg Wunsch on Thu, 25 Jan 1996 15:44:34 -0800 (PST)) Subject: Re: cvs commit: src/sbin/newfs mkfs.c From: asami@cs.berkeley.edu (Satoshi Asami) Sender: owner-commit@FreeBSD.ORG Precedence: bulk * Make the numbers for the "superblock backups" fit nicely on the screen, * even for larger partitions. Until now, partition sizes > 500 MB messed * up the screen. Hey, how about this one. I think the output looks even nicer, especially when you go over >5GB or >50GB. :) Satoshi P.S. I'm not sure if the terminal routine is supposed to wrap to the beginning of the line when you write to the last char...it works here, but if it looks funny at your place, you may need to change "i+j>width" to "i+j>=width">... ------- Index: mkfs.c =================================================================== RCS file: /usr/cvs/src/sbin/newfs/mkfs.c,v retrieving revision 1.9 diff -c -r1.9 mkfs.c *** 1.9 1996/01/25 23:44:32 --- mkfs.c 1996/01/26 10:36:55 *************** *** 122,128 **** int fsi, fso; daddr_t alloc(); ! static int numbersperline(); mkfs(pp, fsys, fi, fo) struct partition *pp; --- 122,128 ---- int fsi, fso; daddr_t alloc(); ! static int charsperline(); mkfs(pp, fsys, fi, fo) struct partition *pp; *************** *** 138,143 **** --- 138,145 ---- 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,635 **** * then print out indices of cylinder groups. */ if (!mfs) ! printf("super-block backups (for fsck -b #) at:"); ! i = numbersperline(sblock.fs_size * NSPF(&sblock)); for (cylno = 0; cylno < sblock.fs_ncg; cylno++) { initcg(cylno, utime); if (mfs) continue; ! if (cylno % i == 0) printf("\n"); ! printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno))); fflush(stdout); } if (!mfs) --- 623,643 ---- * then print out indices of cylinder groups. */ if (!mfs) ! 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; ! j = sprintf(tmpbuf, " %d,", ! fsbtodb(&sblock, cgsblock(&sblock, cylno))); ! if (i+j > width) { printf("\n"); ! i = 0; ! } ! i += j; ! printf("%s", tmpbuf); fflush(stdout); } if (!mfs) *************** *** 1268,1290 **** } /* ! * Determine the number of block numbers that will nicely fit into a * single line. */ static int ! numbersperline(seccount) ! long seccount; { ! int i, 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; --- 1276,1293 ---- } /* ! * Determine the number of characters in a * single line. */ static int ! charsperline() { ! int columns; char *cp; struct winsize ws; extern char *getenv(); columns = 0; if (ioctl(0, TIOCGWINSZ, &ws) != -1) columns = ws.ws_col; *************** *** 1292,1299 **** columns = atoi(cp); if (columns == 0) columns = 80; /* last resort */ ! i = columns / i; ! if (i < 3) ! i = 3; /* don't care */ ! return i; } --- 1295,1299 ---- columns = atoi(cp); if (columns == 0) columns = 80; /* last resort */ ! return columns; }