xref: /aosp_15_r20/external/one-true-awk/bugs-fixed/ofs-rebuild.awk (revision 9a7741de182b2776d7b30d6355f2585c0780a51b)
1*9a7741deSElliott Hughes# The bug here is that nawk should use the value of OFS that
2*9a7741deSElliott Hughes# was current when $0 became invalid to rebuild the record.
3*9a7741deSElliott Hughes
4*9a7741deSElliott HughesBEGIN {
5*9a7741deSElliott Hughes	OFS = ":"
6*9a7741deSElliott Hughes	$0 = "a b c d e f g"
7*9a7741deSElliott Hughes	$3 = "3333"
8*9a7741deSElliott Hughes	# Conceptually, $0 should now be "a:b:3333:d:e:f:g"
9*9a7741deSElliott Hughes
10*9a7741deSElliott Hughes	# Change OFS after (conceptually) rebuilding the record
11*9a7741deSElliott Hughes	OFS = "<>"
12*9a7741deSElliott Hughes
13*9a7741deSElliott Hughes	# Unmodified nawk prints "a<>b<>3333<>d<>e<>f<>g" because
14*9a7741deSElliott Hughes	# it delays rebuilding $0 until it's needed, and then it uses
15*9a7741deSElliott Hughes	# the current value of OFS. Oops.
16*9a7741deSElliott Hughes	print
17*9a7741deSElliott Hughes}
18