Blame test/pty1.awk

Packit 575503
# Message-ID: <1312419482.36133.YahooMailNeo@web110416.mail.gq1.yahoo.com>
Packit 575503
# Date: Wed, 3 Aug 2011 17:58:02 -0700 (PDT)
Packit 575503
# From: "T. X. G." <leopardie333@yahoo.com>
Packit 575503
# To: "bug-gawk@gnu.org" <bug-gawk@gnu.org>
Packit 575503
# Subject: [bug-gawk] two bugs in gawk 4.0.0 with FPAT and pty
Packit 575503
# 
Packit 575503
# $ gawk --version
Packit 575503
# GNU Awk 4.0.0
Packit 575503
# Copyright (C) 1989, 1991-2011 Free Software Foundation.
Packit 575503
# 
Packit 575503
# # bug due to trying to make field splitting more efficient by not parse all fields 
Packit 575503
# $ echo a,b,,c |gawk '{for(i=1;i<=4;++i)print i, $i}' FPAT='[^,]*'
Packit 575503
# 1 a
Packit 575503
# 2 
Packit 575503
# 3 b
Packit 575503
# 4 
Packit 575503
# 
Packit 575503
# # work around
Packit 575503
# $ echo a,b,,c |gawk '{NF;for(i=1;i<=4;++i)print i, $i}' FPAT='[^,]*'
Packit 575503
# 1 a
Packit 575503
# 2 b
Packit 575503
# 3 
Packit 575503
# 4 c
Packit 575503
# 
Packit 575503
# This bug, as you commented in function fpat_parse_field, is subtle. The null matches of previous call should be remembered across calls. You could make the auto variable non_empty static, but then any calls to patsplit between references of fields will cause it to be wrong. I guess you can either forgo the field splitting optimization by always parse all field in the case of FPAT or make a separate function for splitting $0 only (or pass an extra arg to it?) I am sure you will find the best fix.
Packit 575503
# 
Packit 575503
# 
Packit 575503
# The next bug is with pty:
Packit 575503
# 
Packit 575503
# $ gawk 'BEGIN{
Packit 575503
# c = "echo 123 > /dev/tty; read x < /dev/tty; echo \"x is $x\""
Packit 575503
# PROCINFO[c, "pty"] = 1
Packit 575503
# c |& getline;print
Packit 575503
# print "abc" |& c
Packit 575503
# c |& getline;print
Packit 575503
# }'
Packit 575503
# 123
Packit 575503
# ^C
Packit 575503
# 
Packit 575503
# Adding a call to setsid() in the function two_way_open right after fork in the child process seems to fix it.
Packit 575503
# 
Packit 575503
# One request for feature:
Packit 575503
# Currently the format for mktime is not configurable. Could you please make it configurable just like strftime through PROCINFO["mktime"]? In fact I have already done it myself. But I don't think you would like my style. It should be pretty simple for you to implement.
Packit 575503
# 
Packit 575503
# Thank you, Arnold. Again as I have said before, I enjoy your writings and appreciate your contributions to the FSF. 
Packit 575503
# W. G.
Packit 575503
# 
Packit 575503
BEGIN	{
Packit 575503
	c = "echo 123 > /dev/tty; read x < /dev/tty; echo \"x is $x\""
Packit 575503
	PROCINFO[c, "pty"] = 1
Packit 575503
	c |& getline; print
Packit 575503
	print "abc" |& c
Packit 575503
	c |& getline; print
Packit 575503
}