| 565 | /* Obtain the appropriate header entries. */ |
| 566 | |
| 567 | static void |
| 568 | get_header (void) |
| 569 | { |
| 570 | alloc_table_row (); |
| 571 | |
| 572 | for (idx_t col = 0; col < ncolumns; col++) |
| 573 | { |
| 574 | char *cell; |
| 575 | char const *header = _(columns[col]->caption); |
| 576 | |
| 577 | if (columns[col]->field == SIZE_FIELD |
| 578 | && (header_mode == DEFAULT_MODE |
| 579 | || (header_mode == OUTPUT_MODE |
| 580 | && !(human_output_opts & human_autoscale)))) |
| 581 | { |
| 582 | char buf[LONGEST_HUMAN_READABLE + 1]; |
| 583 | |
| 584 | int opts = (human_suppress_point_zero |
| 585 | | human_autoscale | human_SI |
| 586 | | (human_output_opts |
| 587 | & (human_group_digits | human_base_1024 | human_B))); |
| 588 | |
| 589 | /* Prefer the base that makes the human-readable value more exact, |
| 590 | if there is a difference. */ |
| 591 | |
| 592 | uintmax_t q1000 = output_block_size; |
| 593 | uintmax_t q1024 = output_block_size; |
| 594 | bool divisible_by_1000; |
| 595 | bool divisible_by_1024; |
| 596 | |
| 597 | do |
| 598 | { |
| 599 | divisible_by_1000 = q1000 % 1000 == 0; q1000 /= 1000; |
| 600 | divisible_by_1024 = q1024 % 1024 == 0; q1024 /= 1024; |
| 601 | } |
| 602 | while (divisible_by_1000 & divisible_by_1024); |
| 603 | |
| 604 | if (divisible_by_1000 < divisible_by_1024) |
| 605 | opts |= human_base_1024; |
| 606 | if (divisible_by_1024 < divisible_by_1000) |
| 607 | opts &= ~human_base_1024; |
| 608 | if (! (opts & human_base_1024)) |
| 609 | opts |= human_B; |
| 610 | |
| 611 | char *num = human_readable (output_block_size, buf, opts, 1, 1); |
| 612 | |
| 613 | /* Reset the header back to the default in OUTPUT_MODE. */ |
| 614 | header = _("blocks"); |
| 615 | |
| 616 | /* TRANSLATORS: this is the "1K-blocks" header in "df" output. */ |
| 617 | cell = xasprintf (_("%s-%s"), num, header); |
| 618 | } |
| 619 | else if (header_mode == POSIX_MODE && columns[col]->field == SIZE_FIELD) |
| 620 | { |
| 621 | /* TRANSLATORS: this is the "1024-blocks" header in "df -P". */ |
| 622 | cell = xasprintf (_("%ju-%s"), output_block_size, header); |
| 623 | } |
| 624 | else |
no test coverage detected