Hi!

I have have made two additions to the du utility that I thought you 
might want to take a look at.

First. The addition of a -p flag. When this is used the file's size in 
percent relative to the total number of shown files will be printed. A 
downside to this is that du has to go through all files first before it 
can start producing output, thus making it silent for a moment.

Example:
% src/du  -p /Users/kim/temp/fileutils-4.1.11/tests/
3.94%   /Users/kim/temp/fileutils-4.1.11/tests/chgrp
4.33%   /Users/kim/temp/fileutils-4.1.11/tests/chmod
3.15%   /Users/kim/temp/fileutils-4.1.11/tests/chown
11.81%  /Users/kim/temp/fileutils-4.1.11/tests/cp
...

Second. The three kinds of output flags -kmbB, -hH and -p can now be 
given simultaneously and will all output their respective data followed 
by a tab. -kmb will print first, then -hH and last -p.

Like this:
% src/du  -p /Users/kim/temp/fileutils-4.1.11/tests/
40      40K     3.94%   /Users/kim/temp/fileutils-4.1.11/tests/chgrp
44      44K     4.33%   /Users/kim/temp/fileutils-4.1.11/tests/chmod
32      32K     3.15%   /Users/kim/temp/fileutils-4.1.11/tests/chown
120     120K    11.81%  /Users/kim/temp/fileutils-4.1.11/tests/cp
...

or:
% src/du  -bh /Users/kim/temp/fileutils-4.1.11/tests/
40960   40K     /Users/kim/temp/fileutils-4.1.11/tests/chgrp
45056   44K     /Users/kim/temp/fileutils-4.1.11/tests/chmod
32768   32K     /Users/kim/temp/fileutils-4.1.11/tests/chown
122880  120K    /Users/kim/temp/fileutils-4.1.11/tests/cp
...

or:
% src/du -p -B 5K /Users/kim/temp/fileutils-4.1.11/tests/
8       3.94%   /Users/kim/temp/fileutils-4.1.11/tests/chgrp
9       4.33%   /Users/kim/temp/fileutils-4.1.11/tests/chmod
7       3.15%   /Users/kim/temp/fileutils-4.1.11/tests/chown
24      11.81%  /Users/kim/temp/fileutils-4.1.11/tests/cp
...

Included is a diff file that was made with du.c of version 4.1.11 of the 
GNU Fileutils. If you want one that was made with the latest stable 
(4.1) instead I will more than gladly send one over.

I have tried to adhere to the GNU coding standards as thoroughly as 
possible and commented the code where I thought needed. I also wrote a 
ChangeLog entry to clarify code changes.

ChangeLog:
2002-09-18  Kim Ahlstrom  <[EMAIL PROTECTED]>

        Added -p flag that prints percentage of file's size relative to all 
printed
        files' size. New output handling.

        * src/du.c: Added global variables to handle the new -p flag and 
output options.
        (print_size): Rewrite to allow output from both the -kmb flags,
        the -hH flags and the new -p flag at the same time. Added code to 
accumulate
        data for percentage calculation (-p flag).
        (du_files): Print files and data accumulated by percentage 
calculation (-p flag).
        (main): Added -p flag switch-case. Modified h,H,k,m,b,B 
switch-cases to allow
        the -h and -H flags being active while either -kmbB flags are active.
        (usage): Explain -p flag.


If you have any questions I will be more than happy to answer!

Best Regards

Kim Ahlstrom
[EMAIL PROTECTED]
http://kim.animanga.nu/ (Swedish only)

Attachment: du.c.diff
Description: Binary data

Reply via email to