From nobody@FreeBSD.org  Sat Jan 30 10:21:45 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 774E11065670
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jan 2010 10:21:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 4DF8D8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jan 2010 10:21:45 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0UALjh6072172
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jan 2010 10:21:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o0UALjCL072171;
	Sat, 30 Jan 2010 10:21:45 GMT
	(envelope-from nobody)
Message-Id: <201001301021.o0UALjCL072171@www.freebsd.org>
Date: Sat, 30 Jan 2010 10:21:45 GMT
From: Mikolaj Golub <to.my.trociny@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] awk(1) treats -Ft as -F <tab>
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         143367
>Category:       bin
>Synopsis:       [patch] awk(1) treats -Ft as -F <tab>
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 30 10:30:02 UTC 2010
>Closed-Date:    
>Last-Modified:  Tue Feb 15 00:50:06 UTC 2011
>Originator:     Mikolaj Golub
>Release:        
>Organization:
>Environment:
FreeBSD zhuzha.ua1 8.0-STABLE FreeBSD 8.0-STABLE #6: Sun Jan 24 21:36:17 EET 2010     root@zhuzha.ua1:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
This problem with awk(1) regexp working incorrectly was reported to NetBSD by Aleksey Cheusov and it was fixed there.

http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=39133

FreeBSD version still has this bug:

zhuzha:~% echo supertable | awk  -Ft '{print $1, $2}'
supertable 
zhuzha:~% echo -e "super\ttable" | awk  -Ft '{print $1, $2}'
super table

>How-To-Repeat:
echo supertable | awk  -Ft '{print $1, $2}'
>Fix:
See the attached patch adopted from NetBSD (PR/39133: cheusov at tut dot by: Don't treat -Ft as -F <tab>).

Patch attached with submission follows:

diff -ru contrib/one-true-awk.orig/main.c contrib/one-true-awk/main.c
--- contrib/one-true-awk.orig/main.c	2007-06-05 18:33:51.000000000 +0300
+++ contrib/one-true-awk/main.c	2010-01-30 12:06:16.000000000 +0200
@@ -53,6 +53,20 @@
 
 int	safe	= 0;	/* 1 => "safe" mode */
 
+static char *
+setfs(char *p)
+{
+#ifdef notdef
+	/* wart: t=>\t */
+	if (p[0] == 't' && p[1] == 0)
+		return "\t";
+	else
+#endif
+	if (p[0] != 0)
+		return p;
+	return NULL;
+}
+
 int main(int argc, char *argv[])
 {
 	const char *fs = NULL;
@@ -96,16 +110,11 @@
 			break;
 		case 'F':	/* set field separator */
 			if (argv[1][2] != 0) {	/* arg is -Fsomething */
-				if (argv[1][2] == 't' && argv[1][3] == 0)	/* wart: t=>\t */
-					fs = "\t";
-				else if (argv[1][2] != 0)
-					fs = &argv[1][2];
+				fs = setfs(argv[1] + 2);
 			} else {		/* arg is -F something */
 				argc--; argv++;
-				if (argc > 1 && argv[1][0] == 't' && argv[1][1] == 0)	/* wart: t=>\t */
-					fs = "\t";
-				else if (argc > 1 && argv[1][0] != 0)
-					fs = &argv[1][0];
+				if (argc > 1)
+					fs = setfs(argv[1]);
 			}
 			if (fs == NULL || *fs == '\0')
 				WARNING("field separator FS is empty");
Only in contrib/one-true-awk: main.c.orig


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->arundel 
Responsible-Changed-By: arundel 
Responsible-Changed-When: Mon Nov 15 20:40:53 UTC 2010 
Responsible-Changed-Why:  
Over to me. I'll try to get this one committed upstream. Stay tuned. ;) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143367 

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/143367: [patch] awk(1) treats -Ft as -F <tab>
Date: Mon, 15 Nov 2010 20:40:43 +0000

 it seems the netbsd folks however didn't report this isse upstream. i'll
 contact Brian Kernighan and see if he wants to fix this bug in the upstream
 awk version.
 
 if that works out i might try getting the other awk-related patches the netbsd
 folks came up with committed upstream.
 
 cheers.
 alex
 
 -- 
 a13x

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/143367: [patch] awk(1) treats -Ft as -F <tab>
Date: Wed, 17 Nov 2010 01:53:56 +0000

 unfortunately i wasn't able to find Brian Kernighan's current email address.
 the old atlabs one bounces. can somebody help me out here?
 
 cheers.
 alex
 
 -- 
 a13x
Responsible-Changed-From-To: arundel->freebsd-bugs 
Responsible-Changed-By: arundel 
Responsible-Changed-When: Sat Dec 11 19:56:39 UTC 2010 
Responsible-Changed-Why:  
Back into the pool, since i was not able to contact Brian Kernighan. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143367 

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/143367: [patch] awk(1) treats -Ft as -F <tab>
Date: Tue, 15 Feb 2011 00:47:51 +0000

 for the record:
 
 i talked to Brian Kernighan (his current mail address is bwk at CS dot
 Princeton dot EDU btw). he seems like a nice guy, but quite obviously is more
 of a thinker and not that much of a do'er. ;)
 
 chances this will get fixed upstream are very slim imo.
 
 this is what he had to say:
 
 Hi --
  
 That behavior is a feature, not a bug, though it's kind of embarrassing
 in hindsight.  It was meant to make it really easy to do the most common
 exceptional case, but it sure is kludgy.  I'm torn.
  
 Brian
 
 cheers.
 alex
 
 -- 
 a13x
>Unformatted:
