diff options
author | Bernhard Voelker <mail@bernhard-voelker.de> | 2012-08-30 14:58:22 +0200 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-11-08 16:11:48 +0000 |
commit | dae8d223b69bdea7c8913d33640a7b36ef0ff755 (patch) | |
tree | 93680ec2b9cb67161cd6c94a007b469778b4c992 /NEWS | |
parent | 801cd6216bd8c913af9bca44a87c3cc9997f6125 (diff) | |
download | coreutils-dae8d223b69bdea7c8913d33640a7b36ef0ff755.tar.xz |
df: add --output to select which fields to display
This supports changing the order of the fields displayed,
and also allows the simultaneous display of inode and block fields.
src/df.c (get_dev): Factor out calling get_header to ...
(main): ... here. Call print_table only if file_systems_processed.
src/df.c (Displayable fields): Rename DEV_FIELD to SOURCE_FIELD.
Rename TYPE_FIELD to FSTYPE_FIELD. Rename FREE_FIELD to AVAIL_FIELD.
Rename MNT_FIELD to TARGET_FIELD.
* src/df.c (display_field_t): Turn loose enum definition of the
displayable fields into a typedef. Add the inode fields ITOTAL_FIELD,
IUSED_FIELD, IAVAIL_FIELD, IPCENT_FIELD.
(field_data_t): Define structure to hold the display field, the
caption, the width and the alignment for each field of the above
type.
(field_data): Add array the values of field data for each display
field.
(headers, alignments, widths): Remove arrays.
(columns): Add a pointer to the storage for the array of the actual
output columns, i.e., fields.
(ncolumns): Add counter for the current output columns.
(alloc_table_row): Allocate the dynamic ncolumns value of strings.
(print_table): Loop over ncolumns instead of constant NFIELDS. Rename
loop variable 'field' to 'col' to avoid ambiguity with the 'field'
element in the columns structure. Adjust the condition for printing
the last column by comparing with the column number instead of the
field name (TARGET_FIELD). Use the width and the alignment stored in
the columns data.
(alloc_field): Add new function to allocate a field in the columns
array.
(get_field_list): Add new function to fill the array of output columns
for each mode.
(get_header): Loop over ncolumns instead of constant NFIELDS. Rename
the loop variable 'field' to 'col' to avoid ambiguity with the 'field'
element in the columns structure. Remove the code for continuing the
loop if the current column is the file system type and print_type is not
active (which is now impossible). Store the cell in the columns store
along with the new width.
(get_dev): Loop over ncolumns instead of the constant NFIELDS. Rename
the loop variable 'field' to 'col' to avoid ambiguity with the 'field'
element in the columns structure; move the definition down to where it
is used first. Add cases for the inode fields ITOTAL_FIELD,
IUSED_FIELD, IAVAIL_FIELD and IPCENT_FIELD. Store the cell in the
columns store along with the new width.
(main): Use new get_field_list function to fill the list of output
columns.
* src/df.c (print_table): Instead of fputs()ing directly, apply
ambsalign on the last field, too. Use the new MBA_NO_RIGHT_PAD flag
for this.
* src/df.c (TOTAL_OPTION): Add new enum value.
(long_options): Use it for the "total" option instead of 'c'.
(main): Likewise.
* src/df.c (get_dev): Remove condition to copy the fstype into the
FSTYPE_FIELD - based on whether print_type is non-Null. Since the
introduction of get_field_list(), there are only fields added to
the columns array which have to be added.
* src/df.c (get_dev): Guard the summing up of the values for the
grand total: only do it if we have to print the total and if the
current invocation is not for processing it.
* src/df.c (main): Pass a hyphen "-" for the mount point name
to get_dev.
(get_dev): As the mount_point is now always there,
remove the condition and the else case for the TARGET_FIELD.
Instead, simply copy the mount_point.
All cells are now always present. Therefore, add an assertion
statement if one was not. Furthermore, hide the problematic
characters unconditionally.
(print_table): Remove the skipping of empty cells.
* tests/df/total-verify.sh: Accommodate to the new "-" in the
target field of the summary line.
* NEWS: Mention the change in behavior.
* src/df.c (field_type_t): Add new typedef of 3 enums to distinguish
between block, inode and other fields.
(field_data_t): Add field_type member of the above new type.
(field_data): Add default values for the above field_type,
indicating whether a field contains block values, inode values
or other, generic values.
(field_values_t): Add this struct to store the field values, used
by and factored out from get_dev to be able to define such a struct
for both the inode and the block values.
(get_field_values): Add this function to obtain the block values
and the inode values from the file system usage, used by and
factored out from get_dev.
(add_to_grand_total): Add this function to sum the values of the
current mount point up for the grand total, used by and factored
out from get_dev.
(get_dev): Move the definition of the variables fsu, buf, pct and
cell down to where they are used first to give them a better scope.
Factor out input_units, output_units, total, available,
negate_available, available_to_root, used and negate_used into the
above struct field_values_t.
Factor out the mapping of the fsu values to the above variables
into above function get_field_values.
Factor out the summing up of the grand total values into the
above function add_to_grand_total.
Define block_values and inode_values of the new type and call the
new get_field_values to fill them from the fsu values.
Call the above function add_to_grand_total for summing up the
values for the grand total.
Inside the loop over all fields, define a variable 'v' to point
to either the block_values or the inode_values, depending on the
current field's field_type. Change the code in the cases
TOTAL_FIELD/ITOTAL_FIELD, USED_FIELD/IUSED_FIELD, AVAIL_FIELD/
IAVAIL_FIELD and PCENT_FIELD/IPCENT_FIELD to use the field values
where 'v' is pointing to, i.e., either the block_values or the
inode_values.
* src/df.c (main): Remove setting of grand_fsu.fsu_blocks in the
inode_format case as this is no longer needed and would lead to
wrong results once when mixed block/inode fields will be used.
* src/df.c (main): Cleanup the code at the end regarding
file_systems_processed to make the code clearer.
* src/df.c (inode_format): Remove variable.
(main): Remove initialization of the above variable.
In getopts loop, directly set the header_mode to INODES_MODE
instead of using the above variable. Afterwards, remove the
mapping to INODES_MODE as it is already set.
* src/df.c (posix_format): Move variable ...
(main): ... to here.
* src/df.c (print_table): Enhance the comment about 2-line format
in cases where the SOURCE_FIELD exceeds 20 chars, as such
behavior has been removed long ago by commit v8.10-40-g99679ff.
* src/df.c (Display modes): Add OUTPUT_MODE, remove unused NMODES.
(display_field_t): Remove unnecessary NFIELDS.
(field_data_t): Add member 'arg' for the field name in the --output
argument. Add member 'used' to remember if a field is already used
in the columns array.
(field_data): Add values for the above new members arg and used.
(all_args_string): Add variable which represents the argument for
the --output option which includes all fields.
(OUTPUT_OPTION): Add enum to identify the long --output option.
(long_options): Add optional-argument --output option.
(alloc_field): Assert that the field is not already used.
Mark the field as used.
(decode_output_arg): Add function to parse the comma-separated
field list passed to the --output option in order to add the
appropriate fields to the columns array.
(get_field_list): Add case for the new OUTPUT_MODE to add all
available fields to columns in the case the --output option
has been passed without any values. Use the comma-separated
field list form to pass to decode_output_arg to keep the field
header mapping for the OUTPUT_MODE only on one place.
(main): Define format string msg_mut_excl to be used in the
following checks whether the use of --output and the other
option is mutually exclusive.
In the getopt_long loop, add a check to the case for the -i option
to issue an error message when it is used together with --output;
Likewise for -T and -P.
Add a new case for OUTPUT_OPTION, together with similar checks as
above and eventually passing the optarg to decode_output_arg.
After the getopt_long loop, consider the OUTPUT_MODE case in order
not to run into -h or -P mode.
* src/df.c (get_dev): Also xstrdup the dev_name, and free it
afterwards to silence a valgrind warning about definitely lost
memory.
(main): Free the columns store to silence valgrind, guarded by
the IF_LINT macro.
* src/df.c (main): Pass "total" as the mount point to get_dev if
the SOURCE_FIELD is not among the columns to output.
* tests/df/df-output.sh: Change the test to ensure the content of
the target field of the grand total line: if the source field is
present, then the target should be "-", else the target field should
be "target".
* NEWS (Changes in behavior): Enhance the exiting NEWS entry.
* doc/coreutils.texi (df invocation): Document the content of the
source and target field in the grand total line.
* src/df.c (main): Add another condition to the need_fs_type
parameter of read_file_system_list whether the FSTYPE_FIELD is
used or not.
* src/df.c (get_header): Indicate the block size used,
in the "size" header, when using --output without -h.
* tests/df/df-output.sh: Adjust for, and add an extra test for,
the new behavior.
Diffstat (limited to 'NEWS')
0 files changed, 0 insertions, 0 deletions