bin/143367: [patch] awk(1) treats -Ft as -F <tab>
Mikolaj Golub
to.my.trociny at gmail.com
Sat Jan 30 10:30:03 UTC 2010
>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:
>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 at 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:
>Unformatted:
More information about the freebsd-bugs
mailing list