xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/getnr2tm.awk (revision e6d6c189fa3a95d7aa27bbe0aeacf7c1a6b57c8c)
1*e6d6c189SCody Peter Mello#From dhw@gamgee.acad.emich.edu  Sat Oct 31 22:54:07 1998
2*e6d6c189SCody Peter Mello#Return-Path: <dhw@gamgee.acad.emich.edu>
3*e6d6c189SCody Peter Mello#Received: from cssun.mathcs.emory.edu (cssun.mathcs.emory.edu [170.140.150.1])
4*e6d6c189SCody Peter Mello#	by amx.netvision.net.il (8.9.0.Beta5/8.8.6) with ESMTP id HAA08891
5*e6d6c189SCody Peter Mello#	for <arobbins@netvision.net.il>; Sat, 31 Oct 1998 07:14:07 +0200 (IST)
6*e6d6c189SCody Peter Mello#Received: from mescaline.gnu.org (we-refuse-to-spy-on-our-users@mescaline.gnu.org [158.121.106.21]) by cssun.mathcs.emory.edu (8.7.5/8.6.9-940818.01cssun) with ESMTP id AAA14947 for <arnold@mathcs.emory.edu>; Sat, 31 Oct 1998 00:14:32 -0500 (EST)
7*e6d6c189SCody Peter Mello#Received: from gamgee.acad.emich.edu (gamgee.acad.emich.edu [164.76.102.76])
8*e6d6c189SCody Peter Mello#	by mescaline.gnu.org (8.9.1a/8.9.1) with SMTP id AAA20645
9*e6d6c189SCody Peter Mello#	for <arnold@gnu.ai.mit.edu>; Sat, 31 Oct 1998 00:17:54 -0500
10*e6d6c189SCody Peter Mello#Received: by gamgee.acad.emich.edu (Smail3.1.29.1 #57)
11*e6d6c189SCody Peter Mello#	id m0zZUKY-000IDSC; Sat, 31 Oct 98 00:16 CST
12*e6d6c189SCody Peter Mello#Message-Id: <m0zZUKY-000IDSC@gamgee.acad.emich.edu>
13*e6d6c189SCody Peter Mello#Date: Sat, 31 Oct 98 00:16 CST
14*e6d6c189SCody Peter Mello#From: dhw@gamgee.acad.emich.edu (David H. West)
15*e6d6c189SCody Peter Mello#To: bug-gnu-utils@gnu.org
16*e6d6c189SCody Peter Mello#Subject: gawk 3.0.3 bug report
17*e6d6c189SCody Peter Mello#Cc: arnold@gnu.org
18*e6d6c189SCody Peter Mello#X-UIDL: 7474b825cff989adf38f13883d84fdd7
19*e6d6c189SCody Peter Mello#Status: RO
20*e6d6c189SCody Peter Mello#
21*e6d6c189SCody Peter Mello#gawk version: 3.03
22*e6d6c189SCody Peter Mello#System used: Linux, kernel 2.0.28, libc 5.4.33, AMD K5PR133 (i586 clone)
23*e6d6c189SCody Peter Mello#Remark: There seems to be at least one bug shown by the demo below.
24*e6d6c189SCody Peter Mello#        There may also be a Dark Corner involving the value of NR in an
25*e6d6c189SCody Peter Mello#        END block, a topic on which the info file is silent.  In gawk
26*e6d6c189SCody Peter Mello#        3.0.3, NR often seems to have the least-surprise value in an
27*e6d6c189SCody Peter Mello#        END block, but sometimes it doesn't - see example below.
28*e6d6c189SCody Peter Mello#Problem descr: the log below shows a case where:
29*e6d6c189SCody Peter Mello#        a) (this may be a red herring) the output of the gawk script
30*e6d6c189SCody Peter Mello#           is different depending on whether its input file is named on
31*e6d6c189SCody Peter Mello#           the command line or catted to stdin, without any use of the
32*e6d6c189SCody Peter Mello#           legitimate means which could produce this effect.
33*e6d6c189SCody Peter Mello#        b) NR is clearly getting clobbered; I have tried to simplify
34*e6d6c189SCody Peter Mello#           the 19-line script "awkerr1" below, but seemingly unrelated
35*e6d6c189SCody Peter Mello#           changes, like shortening constant strings which appear only in
36*e6d6c189SCody Peter Mello#           print statements, or removing unexecuted or irrelevant code,
37*e6d6c189SCody Peter Mello#           cause the clobbering to go away.  Some previous (larger)
38*e6d6c189SCody Peter Mello#           versions of this code would clobber NR also when reading from
39*e6d6c189SCody Peter Mello#           stdin, but I thought you'd prefer a shorter example :-).
40*e6d6c189SCody Peter Mello#Reproduce-By: using the gawk script "awkerr1", the contents of
41*e6d6c189SCody Peter Mello#              which appear in the transcript below as the output of the
42*e6d6c189SCody Peter Mello#              command "cat awkerr1".  Comments following # were added
43*e6d6c189SCody Peter Mello#              to the transcript later as explanation.
44*e6d6c189SCody Peter Mello#---------------------------------------------- Script started on Fri
45*e6d6c189SCody Peter Mello#Oct 30 20:04:16 1998 chipmunk:/ram0# ls -l a1 awkerr1 -rw-r--r--   1
46*e6d6c189SCody Peter Mello#root     root            2 Oct 30 18:42 a1 -rwxr-xr-x   1 root     root
47*e6d6c189SCody Peter Mello#389 Oct 30 19:54 awkerr1 chipmunk:/ram0# cat a1            #a1 contains
48*e6d6c189SCody Peter Mello#one printable char and a newline a chipmunk:/ram0# od -c xc a1
49*e6d6c189SCody Peter Mello#0000000 0a61
50*e6d6c189SCody Peter Mello#          a  \n
51*e6d6c189SCody Peter Mello#0000002 chipmunk:/ram0# cat a1 | awkerr1           #no surprises here
52*e6d6c189SCody Peter Mello#1 lines in 1 sec: 1 lines/sec;  nlines=1 chipmunk:/ram0# awkerr1 a1 �
53*e6d6c189SCody Peter Mello#lines in 1 sec: 1 lines/sec;  nlines=1    #?! first char is an uppercase
54*e6d6c189SCody Peter Mello#E-grave chipmunk:/ram0# awkerr1 a1 | od -N1 -xc 0000000 00c8
55*e6d6c189SCody Peter Mello#        310  \0
56*e6d6c189SCody Peter Mello#0000001 chipmunk:/ram0# cat awkerr1   #the apparent ^M's are not
57*e6d6c189SCody Peter Mello#actually in the file
58*e6d6c189SCody Peter Mello#!/usr/bin/awk -f
59*e6d6c189SCody Peter Mellofunction process(w) {
60*e6d6c189SCody Peter Mello   if(w in ws) {
61*e6d6c189SCody Peter Mello      printf " : found\n"; lc[p " " w]++; rc[w " " n]++; }
62*e6d6c189SCody Peter Mello   }
63*e6d6c189SCody Peter MelloBEGIN {
64*e6d6c189SCody Peter Mello      }
65*e6d6c189SCody Peter Mello/^/ {if(NR % 10 ==0)print "processing line " NR;
66*e6d6c189SCody Peter Mello     process($1); nlines++;
67*e6d6c189SCody Peter Mello    }
68*e6d6c189SCody Peter MelloEND {p=w; w=n; n="";
69*e6d6c189SCody Peter Mello     if(w)process(w); t=1; print NR " lines in " t " sec: " NR+0 " lines/sec;  nlines=" nlines;
70*e6d6c189SCody Peter Mello    }
71*e6d6c189SCody Peter Mello#chipmunk:/ram0# exit Script done on Fri Oct 30 20:07:31 1998
72*e6d6c189SCody Peter Mello#---------------------------------------------
73*e6d6c189SCody Peter Mello#
74*e6d6c189SCody Peter Mello#-David West     dhw@gamgee.acad.emich.edu
75*e6d6c189SCody Peter Mello#
76