Would be nice if DU could print out the cost of the storage rather than the number of blocks. The following code shows an example of this (option -$ reads a cost from /usr/share/du-cost and applies it before printout out the result).
Tim N. --- du.c.orig Fri Jun 18 15:51:04 2004 +++ du.c Fri Jun 18 16:09:07 2004 @@ -29,6 +29,7 @@ -H Similar, but use powers of 1000 not 1024. -k Print sizes in kilobytes. -m Print sizes in megabytes. + -$ Print sizes in dollars. -b Print sizes in bytes. -S Count the size of each directory separately, not including the sizes of subdirectories. @@ -137,9 +138,13 @@ static int max_depth = INT_MAX; /* If positive, the units to use when printing sizes; - if negative, the human-readable base. */ + if negative, the human-readable base. + if zero, the storage cost */ static int output_block_size; +#define COSTNAME SHAREDIR "/du-cost" +static float byte_cost = 0.0; + /* Accumulated path for file or directory being processed. */ static String *path; @@ -219,6 +224,7 @@ -s, --summarize display only a total for each argument\n\ -x, --one-file-system skip directories on different filesystems\n\ -X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE.\n\ + -$ show sizes in dollars. --exclude=PAT Exclude files that match PAT.\n\ --max-depth=N print the total for a directory (or file, with --all)\n\ only if it is N or fewer levels below the command\n\ @@ -300,10 +306,17 @@ print_size (uintmax_t n_blocks, const char *string) { char buf[LONGEST_HUMAN_READABLE + 1]; - printf ("%s\t%s\n", + if(output_block_size == 0) { + /* this would be better as a fix to human_readable_inexact, but + * this is easier for a quick prototype (single file) + */ + printf ("$%.2f\t%s\n", n_blocks * (ST_NBLOCKSIZE * byte_cost), string); + } else { + printf ("%s\t%s\n", human_readable_inexact (n_blocks, buf, ST_NBLOCKSIZE, output_block_size, human_ceiling), string); + } fflush (stdout); } @@ -668,7 +681,7 @@ human_block_size (getenv ("DU_BLOCK_SIZE"), 0, &output_block_size); - while ((c = getopt_long (argc, argv, "abchHklmsxDLSX:", long_options, NULL)) + while ((c = getopt_long (argc, argv, "abchHklmsxDLSX:$", long_options, NULL)) != -1) { long int tmp_long; @@ -743,6 +756,10 @@ error (1, errno, "%s", quote (optarg)); break; + case '$': + output_block_size = 0; + break; + case EXCLUDE_OPTION: add_exclude (exclude, optarg); break; @@ -758,6 +775,26 @@ default: usage (1); } + } + + /* + * ick! look at these indents! placement of braces and + * spaces around parenthesis! Who wrote this, the french!? + * oh well, I will try to abide by their horrible style rules. + */ + if (output_block_size == 0) + { + FILE *fp = fopen (COSTNAME, "r"); + if (!fp) + { + error (0, errno, COSTNAME); + usage (1); + } + if (fscanf (fp, "%f", &byte_cost) != 1) + { + error (0, 0, "Error reading cost file"); + } + fclose (fp); } if (opt_all && opt_summarize_only) _______________________________________________ Bug-fileutils mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/bug-fileutils