head	1.10;
access;
symbols;
locks; strict;
comment	@# @;


1.10
date	2002.05.06.14.43.59;	author roderick;	state Exp;
branches;
next	1.9;

1.9
date	2001.09.13.18.31.31;	author roderick;	state Exp;
branches;
next	1.8;

1.8
date	2001.08.01.13.11.47;	author roderick;	state Exp;
branches;
next	1.7;

1.7
date	2000.07.14.18.24.08;	author roderick;	state Exp;
branches;
next	1.6;

1.6
date	2000.07.14.17.49.15;	author roderick;	state Exp;
branches;
next	1.5;

1.5
date	2000.07.14.17.48.32;	author roderick;	state Exp;
branches;
next	1.4;

1.4
date	97.09.29.04.05.38;	author roderick;	state Exp;
branches;
next	1.3;

1.3
date	94.11.28.19.21.53;	author roderick;	state Exp;
branches;
next	1.2;

1.2
date	94.02.21.10.42.59;	author roderick;	state Exp;
branches;
next	1.1;

1.1
date	93.10.13.06.57.35;	author roderick;	state Exp;
branches;
next	;


desc
@du in which size excludes subdirectories, reverse sorted by size.
@


1.10
log
@s/perl5/perl/
@
text
@#!/usr/bin/perl -w
use strict;

# $Id: dunk,v 1.9 2001-09-13 14:31:31-04 roderick Exp roderick $
#
# Roderick Schertler <roderick@@argon.org>
#
# dunk == du no kids
#
# This is like du but sizes exclude subdirectories and the numbers are
# output in fixed-width format.  It relies on depth first output from
# du.  Nowadays you can GNU du's --separate-dirs switch for the same
# effect (except you'd have to postprocess it for the formatting).

# Copyright (C) 2001 Roderick Schertler
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# For a copy of the GNU General Public License write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

use Proc::WaitStat	qw(close_die waitstat_reuse);
use RS::Handy		qw(xdie);

my $du = $ENV{DUNK_DU} || 'du';
my $cmd = "$du " . join ' ', map { quotemeta } @@ARGV;
open DU, "$cmd |" or xdie "can't fork:";

my (%size, $this_size, $dir, $s);
while (<DU>) {
    chomp;
    ($this_size, $dir) = split ' ', $_, 2;

    # Remove the size of me and all my kids from my dad's (making him
    # more negative).
    $size{substr $dir, 0, rindex($dir, '/')} -= $this_size;

    # Add the size of me and all my kids to me, leaving my size without
    # my kids.
    $s = $size{$dir} += $this_size;

    printf "%8d %s\n", $s, $dir unless $s < 0;
}

close_die *DU, $du;
exit waitstat_reuse $?;
@


1.9
log
@Rename RJS::Handy to RS::Handy.
@
text
@d1 1
a1 1
#!/usr/bin/perl5 -w
d4 1
a4 1
# $Id: dunk,v 1.8 2001-08-01 09:11:47-04 roderick Exp roderick $
@


1.8
log
@Comment.
@
text
@d4 1
a4 1
# $Id: dunk,v 1.7 2000-07-14 14:24:08-04 roderick Exp roderick $
d31 1
a31 1
use RJS::Handy		qw(xdie);
@


1.7
log
@Drop sorting.

Rename to dunk.
@
text
@d4 10
a13 1
# $Id: dunk,v 1.6 2000-07-14 13:49:15-04 roderick Exp roderick $
d15 11
a25 1
# dunk == du no kids
d27 2
a28 2
# This is like du but sizes exclude subdirectories.  It relies on depth
# first output from du.
d30 2
a31 2
use Proc::WaitStat qw(waitstat_reuse);
use RJS::Handy qw(xdie);
d53 1
a53 4
close DU
    or $! == 0
    or xdie "error closing $du:";

@


1.6
log
@Comment.
@
text
@d4 1
a4 1
# $Id: dunk,v 1.5 2000-07-14 13:48:32-04 roderick Exp roderick $
d8 2
a9 2
# This is like du but sizes exclude subdirectories, and it's reverse
# sorted by size.  It relies on depth first output from du.
d12 1
d14 8
a21 8
my $du = $ENV{DUFLAT_DU} || 'du';
my @@line = `$du @@ARGV`;
chomp @@line;

my ($width, %size, $sz, $dir, $s, $l);
$width = 0;
foreach (@@line) {
    ($sz, $dir) = split ' ', $_, 2;
d25 1
a25 1
    $size{substr $dir, 0, rindex($dir, '/')} -= $sz;
d29 1
a29 1
    $s = $size{$dir} += $sz;
d31 1
a31 4
    # Keep track of the max width of the size.
    next if $s < 0;
    $l = length $s;
    $width = $l if $l > $width;
d34 3
a36 5
for my $dir (sort { $size{$b} <=> $size{$a} || $a cmp $b } keys %size) {
    # $s < 0 if it's pointing at a directory above the input.
    $s = $size{$dir};
    printf "%${width}d\t%s\n", $s, $dir unless $s < 0;
}
@


1.5
log
@Oops, handle directories with spaces in their names.
@
text
@d4 1
a4 1
# $Id: duflat,v 1.4 1997-09-29 00:05:38-04 roderick Exp roderick $
d6 4
a9 2
# du in which size excludes subdirectories, reverse sorted by size.
# Relies on depth first output from du.
@


1.4
log
@Convert to Perl 5.
@
text
@d4 1
a4 1
# $Id: duflat,v 1.3 1994-11-28 14:21:53-05 roderick Exp roderick $
d18 1
a18 1
    ($sz, $dir) = split;
@


1.3
log
@DG now ships perl as /usr/bin/perl, and their version (of course) has
@@INC set to /usr/lib/perl rather than /usr/local/lib/perl.  Rather than
modifying anything found in /usr/bin/perl (to be sure not to mess with
DG's perl programs) switch all of our perl scripts to
/usr/local/bin/perl4.036 (adding the version in anticipation of
installing perl5).
@
text
@d1 2
a2 1
#!/usr/local/bin/perl4.036
d4 1
a4 1
# $Id: duflat,v 1.2 1994/02/21 10:42:59 roderick Exp roderick $
d9 1
a9 3
$du = $ENV{DUFLAT_DU} || 'du';
@@line = `$du @@ARGV`;
chop @@line;
d11 5
d17 2
a18 3
foreach (@@line)
  {
    ($sz, $me) = split (' ');
d22 1
a22 1
    $size{substr ($me, 0, rindex ($me, '/'))} -= $sz;
d26 1
a26 1
    $s = $size{$me} += $sz;
d32 1
a32 1
  }
d34 1
a34 2
foreach $dir (sort {$size{$b} <=> $size{$a} || $a cmp $b;} keys %size)
  {
d38 1
a38 1
  } 
d40 1
a40 1
exit $?;
@


1.2
log
@Use $DUFLAT_DU as du if it's set in the environment.
@
text
@d1 1
a1 1
#!/usr/bin/perl
d3 1
a3 1
# $Id: duflat,v 1.1 1993/10/13 06:57:35 roderick Exp roderick $
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
# $Id$
d8 2
a9 1
@@line = `du @@ARGV`;
@
