MCPcopy Create free account
hub / github.com/coreutils/coreutils / get_header

Function get_header

src/df.c:567–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565/* Obtain the appropriate header entries. */
566
567static void
568get_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

Callers 1

mainFunction · 0.85

Calls 2

alloc_table_rowFunction · 0.85

Tested by

no test coverage detected