size(1) output is not padded and uses a single tab between each column
which often looks ugly:

        $ size bsd /usr/lib/libc.so.96.4 `which echo cc`
        text    data    bss     dec     hex
        896234  31208   54664   982106  efc5a   /usr/lib/libc.so.96.4
        106152  11200   12640   129992  1fbc8   /bin/echo
        84398221        41416   343049  84782686        50dae5e /usr/bin/cc


The GNU implementation looks less off:

        # pkg_add binutils
        binutils-2.39: ok

        $ gsize bsd /usr/lib/libc.so.96.4 `which echo cc`
           text    data     bss     dec     hex filename
         896234   31208   54664  982106   efc5a /usr/lib/libc.so.96.4
         106152   11200   12640  129992   1fbc8 /bin/echo
        84398221          41416  343049 84782686        50dae5e /usr/bin/cc

I haven't checked their code, but padding fields to seven chars and
delimiting with a tab yields their format (modulo "filename" printing):

        $ obj/size bsd /usr/lib/libc.so.96.4 `which echo cc`
           text    data     bss     dec     hex
         896234   31208   54664  982106   efc5a /usr/lib/libc.so.96.4
         106152   11200   12640  129992   1fbc8 /bin/echo
        84398221          41416  343049 84782686        50dae5e /usr/bin/cc

Big files are still off, but at least fields are now aligned.

Another alternative could be to pad fields to eight chars and delimit
with a space, causing both small and big files to align nicely whilst
staying under 80 chars total width with reasonable file names
(which I left delimited with a tab... coulde be space for consistency):

        $ grep %8 nm.c
                                printf("%8s %8s %8s %8s %8s\n",
                        printf("%8lu %8lu %8lu %8lu %8lx",
        $ obj/size bsd /usr/lib/libc.so.96.4 `which echo cc`
            text     data      bss      dec      hex
          896234    31208    54664   982106    efc5a    /usr/lib/libc.so.96.4
          106152    11200    12640   129992    1fbc8    /bin/echo
        84398221    41416   343049 84782686  50dae5e    /usr/bin/cc

What do others think?
Diff below switches to the GNU format, keeping tabs in outputs.

One possible concern is scripts parsing size(1) output with anything but
awk(1), but at least base does not seem to contain Makefiles that depend
on the exact current format.

Index: nm.c
===================================================================
RCS file: /cvs/src/usr.bin/nm/nm.c,v
retrieving revision 1.54
diff -u -p -r1.54 nm.c
--- nm.c        3 Mar 2019 16:07:39 -0000       1.54
+++ nm.c        30 Oct 2022 20:54:05 -0000
@@ -682,11 +682,12 @@ show_file(int count, int warn_fmt, const
 
                if (first) {
                        first = 0;
-                       printf("text\tdata\tbss\tdec\thex\n");
+                       printf("%7s\t%7s\t%7s\t%7s\t%7s\n",
+                           "text", "data", "bss", "dec", "hex");
                }
 
                total = text + data + bss;
-               printf("%lu\t%lu\t%lu\t%lu\t%lx",
+               printf("%7lu\t%7lu\t%7lu\t%7lu\t%7lx",
                    text, data, bss, total, total);
                if (count > 1)
                        (void)printf("\t%s", name);

Reply via email to