From owner-p4-projects@FreeBSD.ORG Wed Jun 25 13:17:40 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 840E01065671; Wed, 25 Jun 2008 13:17:40 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2CAF1106566B for ; Wed, 25 Jun 2008 13:17:40 +0000 (UTC) (envelope-from andenore@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 21D5C8FC23 for ; Wed, 25 Jun 2008 13:17:40 +0000 (UTC) (envelope-from andenore@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5PDHdbY099432 for ; Wed, 25 Jun 2008 13:17:39 GMT (envelope-from andenore@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5PDHdwP099430 for perforce@freebsd.org; Wed, 25 Jun 2008 13:17:39 GMT (envelope-from andenore@FreeBSD.org) Date: Wed, 25 Jun 2008 13:17:39 GMT Message-Id: <200806251317.m5PDHdwP099430@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andenore@FreeBSD.org using -f From: Anders Nore To: Perforce Change Reviews Cc: Subject: PERFORCE change 144093 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jun 2008 13:17:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=144093 Change 144093 by andenore@andenore_laptop on 2008/06/25 13:16:58 pkg_info -s option prints human readable output Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#2 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#4 edit Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#3 (text+ko) ==== @@ -10,6 +10,8 @@ - Profiling showed that the default behavior for pkg_info was to read plist everytime even though not needed. Added check for this and speed improved significantly. + - Uses human readable output for -s (size option) I'm not sure if this breaks + things, but it looks Ok. (The old output is available via the -b option) Add: - Indexes information to dbcache according to the add ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#2 (text+ko) ==== @@ -15,7 +15,7 @@ .\" .\" .\" @(#)pkg_info.1 -.\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.62 2007/12/09 11:01:58 krion Exp $ +.\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.60 2007/03/04 13:30:02 ru Exp $ .\" .Dd January 9, 2006 .Dt PKG_INFO 1 @@ -72,11 +72,7 @@ .It Fl b Use the .Ev BLOCKSIZE -environment variable for output even when the -.Fl q -or -.Fl Q -flag is present. +environment variable for size output. .It Fl v Turn on verbose output. .It Fl p ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#4 (text+ko) ==== @@ -29,6 +29,19 @@ #include #include +char sizeTable[][4] = { "B", "kB", "MB", "GB", "TB" }; + +unsigned int +human_readable(unsigned int size, int *index) +{ + if (size >= 1024) { + *index = *index + 1; + return human_readable(size/1024, index); + } + + return size; +} + void show_file(const char *title, const char *fname) { @@ -250,67 +263,74 @@ } /* Calculate and show size of all installed package files (except ignored ones) - * TODO: Make size easier to read (It should be unnecessary to set BLOCKSIZE in - * environment). If the files are static in size, maybe it could be cached - * instead of calculated every time. Could also be made default to show. - * */ void show_size(const char *title, Package *plist) { - PackingList p; - Boolean ign = FALSE; - const char *dir = "."; - struct stat sb; - char tmp[FILENAME_MAX]; - unsigned long size = 0; - long blksize; - int headerlen; - char *descr; - char *prefix = NULL; + PackingList p; + Boolean ign = FALSE; + const char *dir = "."; + struct stat sb; + char tmp[FILENAME_MAX]; + unsigned long size = 0; + long blksize; + int headerlen; + char *descr; + char *prefix = NULL; + + descr = getbsize(&headerlen, &blksize); + if (!Quiet) + printf("%s%s", InfoPrefix, title); - descr = getbsize(&headerlen, &blksize); - if (!Quiet) - printf("%s%s", InfoPrefix, title); - for (p = plist->head; p != NULL; p = p->next) { + for (p = plist->head; p != NULL; p = p->next) { switch (p->type) { case PLIST_FILE: - if (!ign) { - snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name); - if (!lstat(tmp, &sb)) { - size += sb.st_size; - if (Verbose) - printf("%lu\t%s\n", (unsigned long) howmany(sb.st_size, blksize), tmp); + if (!ign) { + snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name); + if (!lstat(tmp, &sb)) { + size += sb.st_size; + + if (Verbose) + printf("%lu\t%s\n", + (unsigned long) howmany(sb.st_size, blksize), tmp); + } } - } - ign = FALSE; - break; + ign = FALSE; + break; case PLIST_CWD: - if (!prefix) - prefix = p->name; - if (p->name == NULL) - dir = prefix; - else - dir = p->name; - break; + if (!prefix) + prefix = p->name; + + if (p->name == NULL) + dir = prefix; + else + dir = p->name; + break; case PLIST_IGNORE: - ign = TRUE; - break; + ign = TRUE; + break; /* Silence GCC in the -Wall mode */ default: - break; + break; + } } - } - if (!Quiet) - printf("%lu\t(%s)\n", howmany(size, blksize), descr); - else - if (UseBlkSz) - printf("%lu\n", howmany(size, blksize)); - else - printf("%lu\n", size); + + if (!Quiet) { + if (UseBlkSz) + printf("%lu\t(%s)\n", howmany(size, blksize), descr); + else { + int index = 0; + printf("%lu ", human_readable(size, &index)); + printf("%s\n", &sizeTable[index]); + } + } else + if (UseBlkSz) + printf("%lu\n", howmany(size, blksize)); + else + printf("%lu\n", size); } /* Show files that don't match the recorded checksum */