Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Aug 2000 00:59:29 +0100
From:      Mark Ovens <marko@freebsd.org>
To:        current@freebsd.org
Subject:   Request for review/comments - new option for uname(1)
Message-ID:  <20000809005929.K250@parish>

next in thread | raw e-mail | index | archive | help

--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

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.44°N  FreeBSD - The Power To Serve http://www.freebsd.org
2.057°W  My Webpage http://ukug.uk.freebsd.org/~mark
mailto:marko@freebsd.org                http://www.radan.com


--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Description: Diff for uname.c
Content-Disposition: attachment; filename="uname.diff"

--- 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 = " ";
 	}

--82I3+IH0IqGh5yIs--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000809005929.K250>