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