xref: /illumos-gate/usr/src/cmd/oawk/README (revision 4774dff6)
1*7c478bd9Sstevel@tonic-gate#
2*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate#
4*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate# with the License.
8*7c478bd9Sstevel@tonic-gate#
9*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate# and limitations under the License.
13*7c478bd9Sstevel@tonic-gate#
14*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate#
20*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate#
22*7c478bd9Sstevel@tonic-gateCHANGES as of July 12:
23*7c478bd9Sstevel@tonic-gate
24*7c478bd9Sstevel@tonic-gate1. \ddd allowed in regular expressions.
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate2. exit <expression> causes the expression to
27*7c478bd9Sstevel@tonic-gateto be the status return upon completion.
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate3. a new builtin called "getline" causes the next
30*7c478bd9Sstevel@tonic-gateinput line to be read immediately.  Fields, NR, etc.,
31*7c478bd9Sstevel@tonic-gateare all set, but you are left at exactly the same place
32*7c478bd9Sstevel@tonic-gatein the awk program.  Getline returns 0 for end of file;
33*7c478bd9Sstevel@tonic-gate1 for a normal record.
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gateCHANGES SINCE MEMO:
37*7c478bd9Sstevel@tonic-gateUpdate to TM of Sept 1, 1978:
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate1. A new form of for loop
40*7c478bd9Sstevel@tonic-gate	for (i in array)
41*7c478bd9Sstevel@tonic-gate		statement
42*7c478bd9Sstevel@tonic-gateis now available. It provides a way to walk
43*7c478bd9Sstevel@tonic-gatealong the members of an array, most usefully
44*7c478bd9Sstevel@tonic-gatefor associative arrays with non-numeric subscripts.
45*7c478bd9Sstevel@tonic-gateElements are accessed in an unpredictable order,
46*7c478bd9Sstevel@tonic-gateso don't count on anything.
47*7c478bd9Sstevel@tonic-gateFuthermore, havoc ensues if elements are created
48*7c478bd9Sstevel@tonic-gateduring this operation, or if the index variable
49*7c478bd9Sstevel@tonic-gateis fiddled.
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate2. index(s1, s2) returns the position in s1
52*7c478bd9Sstevel@tonic-gatewhere s2 first occurs, or 0 if it doesn't.
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate3. Multi-line records are now supported more
55*7c478bd9Sstevel@tonic-gateconveniently. If the record separator is null
56*7c478bd9Sstevel@tonic-gate	RS = ""
57*7c478bd9Sstevel@tonic-gatethen a blank line terminates a record, and newline
58*7c478bd9Sstevel@tonic-gateis a default field separator, along with
59*7c478bd9Sstevel@tonic-gateblank and tab.
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate4. The syntax of split has been changed.
62*7c478bd9Sstevel@tonic-gate	n = split(str, arrayname, sep)
63*7c478bd9Sstevel@tonic-gatesplits the string str into the array using
64*7c478bd9Sstevel@tonic-gatethe separator sep (a single character).
65*7c478bd9Sstevel@tonic-gateIf no sep field is given, FS is used instead.
66*7c478bd9Sstevel@tonic-gateThe elements are array[1] ... array[n]; n
67*7c478bd9Sstevel@tonic-gateis the function value.
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate5. some minor bugs have been fixed.
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gateIMPLEMENTATION NOTES:
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gateThings to watch out for when trying to make awk:
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate1. The yacc -d business creates a new file y.tab.h
76*7c478bd9Sstevel@tonic-gatewith the yacc #defines in it. this is compared to
77*7c478bd9Sstevel@tonic-gateawk.h on each successive compile, and major recompilation
78*7c478bd9Sstevel@tonic-gateis done only if the files differ. (This permits editing
79*7c478bd9Sstevel@tonic-gatethe grammar file without causing everything in sight
80*7c478bd9Sstevel@tonic-gateto be recompiled, so long as the definitions don't
81*7c478bd9Sstevel@tonic-gatechange.)
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate2. The program proc.c is compiled into proc, which
84*7c478bd9Sstevel@tonic-gateis used to create proctab.c. proctab.c is the
85*7c478bd9Sstevel@tonic-gatetable of function pointers used by run to actually
86*7c478bd9Sstevel@tonic-gateexecute things. Don't try to load proc.c with the
87*7c478bd9Sstevel@tonic-gateother .c files; it also contains a "main()".
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate3. Awk uses structure assignment. Be sure your
90*7c478bd9Sstevel@tonic-gateversion of the C compiler has it.
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate4. The loader flag -lm is used to fetch the standard
93*7c478bd9Sstevel@tonic-gatemath library on the Research system. It is more likely
94*7c478bd9Sstevel@tonic-gatethat you will want to use -lS on yours.
95*7c478bd9Sstevel@tonic-gaterun.c also includes "math.h", which contains sensible
96*7c478bd9Sstevel@tonic-gatedefinitions for log(), sqrt(), etc. If you don't have this
97*7c478bd9Sstevel@tonic-gateinclude file, comment the line out, and all will be well
98*7c478bd9Sstevel@tonic-gateanyway.
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate5. The basic sequence of events (in case make doesn't
101*7c478bd9Sstevel@tonic-gateseem to do the job) is
102*7c478bd9Sstevel@tonic-gate	yacc -d awk.g.y
103*7c478bd9Sstevel@tonic-gate	cc -O -c y.tab.c
104*7c478bd9Sstevel@tonic-gate	mv y.tab.o awk.g.o
105*7c478bd9Sstevel@tonic-gate	lex awk.lx.l
106*7c478bd9Sstevel@tonic-gate	cc -O -c lex.yy.c
107*7c478bd9Sstevel@tonic-gate	mv lex.yy.o awk.lx.o
108*7c478bd9Sstevel@tonic-gate	cc -O -c b.c
109*7c478bd9Sstevel@tonic-gate	cc -O -c main.c
110*7c478bd9Sstevel@tonic-gate	e - <tokenscript
111*7c478bd9Sstevel@tonic-gate	cc -O -c token.c
112*7c478bd9Sstevel@tonic-gate	cc -O -c tran.c
113*7c478bd9Sstevel@tonic-gate	cc -O -c lib.c
114*7c478bd9Sstevel@tonic-gate	cc -O -c run.c
115*7c478bd9Sstevel@tonic-gate	cc -O -c parse.c
116*7c478bd9Sstevel@tonic-gate	cc -O -c proc.c
117*7c478bd9Sstevel@tonic-gate	cc -o proc proc.c token.o
118*7c478bd9Sstevel@tonic-gate	proc >proctab.c
119*7c478bd9Sstevel@tonic-gate	cc -O -c proctab.c
120*7c478bd9Sstevel@tonic-gate	cc -i -O awk.g.o awk.lx.o b.o main.o token.o tran.o lib.o run.o parse.o proctab.o -lm
121