The output of ``uname -a'' appears in hundreds of e-mails and PRs yet
the output format is not ideal for this (especially e-mail in
80-column mail readers) as it is a single line.

Attached is a patch for an enhancement I've made that adds a new
option ``-A'' (rather than change ``-a'') that splits it up into 3
lines thus making it better for including verbatim in e-mails and PRs:

      # uname -A
      FreeBSD parish 4.1-STABLE FreeBSD 4.1-STABLE #0:
      Tue Aug  8 00:51:02 BST 2000
          mark@parish:/usr/src/sys/compile/PARISH i386

The only thing I couldn't work out is why sysctl() adds 5 spaces after
the date sub-string, so I've haven't stripped them out (hence the
indented third line).

Is there any reason why this is unacceptable and could not be committed?

BTW, please Cc: me.

Thanks for your time.

-- 
                4.4 - The number of the Beastie
________________________________________________________________
51.44N  FreeBSD - The Power To Serve http://www.freebsd.org
2.057W  My Webpage http://ukug.uk.freebsd.org/~mark
mailto:[EMAIL PROTECTED]                http://www.radan.com

--- uname.c.orig        Tue Aug  8 21:32:36 2000
+++ uname.c     Tue Aug  8 21:53:20 2000
@@ -61,16 +61,20 @@
 #define        RFLAG   0x04
 #define        SFLAG   0x08
 #define        VFLAG   0x10
+#define        AFLAG   0x20
        u_int flags;
        int ch, mib[2];
        size_t len, tlen;
        char *p, *prefix, buf[1024];
 
        flags = 0;
-       while ((ch = getopt(argc, argv, "amnprsv")) != -1)
+       while ((ch = getopt(argc, argv, "Aamnprsv")) != -1)
                switch(ch) {
+               case 'A':
                case 'a':
                        flags |= (MFLAG | NFLAG | RFLAG | SFLAG | VFLAG);
+                       if (ch == 'A')
+                               flags |= AFLAG;
                        break;
                case 'p':
                case 'm':
@@ -137,9 +141,22 @@
                len = sizeof(buf);
                if (sysctl(mib, 2, &buf, &len, NULL, 0) == -1)
                        err(1, "sysctl");
-               for (p = buf, tlen = len; tlen--; ++p)
-                       if (*p == '\n' || *p == '\t')
-                               *p = ' ';
+
+               if (flags & AFLAG) {
+                       for (p = buf, tlen = len; tlen--; ++p)
+                               if (*p == ':') {
+                                       *++p = '\n';
+                                       break;
+                               }
+
+                       if (buf[strlen(buf) - 1] == '\n')
+                               buf[strlen(buf) - 1] = '\0';
+               } else {
+                       for (p = buf, tlen = len; tlen--; ++p)
+                               if (*p == '\n' || *p == '\t')
+                                       *p = ' ';
+               }
+
                (void)printf("%s%.*s", prefix, (int)len, buf);
                prefix = " ";
        }

Reply via email to