diff options
37 files changed, 2482 insertions, 2435 deletions
@@ -11905,7 +11905,7 @@ f usr/share/man/man1/at.1 0444 root bin f usr/share/man/man1/atq.1 0444 root bin f usr/share/man/man1/atrm.1 0444 root bin f usr/share/man/man1/auths.1 0444 root bin -s usr/share/man/man1/awk.1=nawk.1 +f usr/share/man/man1/awk.1 0444 root bin f usr/share/man/man1/banner.1 0444 root bin f usr/share/man/man1/basename.1 0444 root bin s usr/share/man/man1/batch.1=at.1 @@ -12122,7 +12122,7 @@ f usr/share/man/man1/mpss.so.1.1 0444 root bin f usr/share/man/man1/msgfmt.1 0444 root bin f usr/share/man/man1/mt.1 0444 root bin f usr/share/man/man1/mv.1 0444 root bin -f usr/share/man/man1/nawk.1 0444 root bin +s usr/share/man/man1/nawk.1=awk.1 f usr/share/man/man1/nc.1 0444 root bin s usr/share/man/man1/neqn.1=eqn.1 f usr/share/man/man1/newform.1 0444 root bin diff --git a/usr/src/cmd/awk/Makefile b/usr/src/cmd/awk/Makefile index 046f0b739e..339f22d821 100644 --- a/usr/src/cmd/awk/Makefile +++ b/usr/src/cmd/awk/Makefile @@ -24,11 +24,12 @@ # Copyright 2005 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# Copyright (c) 2018, Joyent, Inc. +# Copyright 2020 Joyent, Inc. -# NOTE: awk is oawk. +# NOTE: awk is now nawk. PROG= nawk +LINKPROG= awk OBJ1= b.o lib.o main.o parse.o proctab.o run.o tran.o lex.o OBJ2= awk.g.o @@ -37,6 +38,8 @@ SRCS= $(OBJ1:%.o=%.c) include ../Makefile.cmd +ROOTLINK = $(LINKPROG:%=$(ROOTBIN)/%) + CERRWARN += -_gcc=-Wno-unused-label CERRWARN += -_gcc=-Wno-parentheses CERRWARN += -_gcc=-Wno-unused-variable @@ -61,12 +64,15 @@ CLEANFILES= maketab proctab.c awk.g.c y.tab.h .KEEP_STATE: -all: $(PROG) +all: $(PROG) $(ROOTLINK) $(PROG): $(OBJS) $(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) +$(ROOTLINK): $(ROOTPROG) + $(RM) $@; $(LN) $(ROOTPROG) $@ + # # message catalog # @@ -87,8 +93,6 @@ install: all $(ROOTPROG) $(ROOTLINK) clean: $(RM) $(OBJS) $(CLEANFILES) -lint: awk.g.c lint_SRCS - awk.g.c + y.tab.h: awk.g.y awk.g.o: awk.g.c diff --git a/usr/src/cmd/oawk/Makefile b/usr/src/cmd/oawk/Makefile index 37a2f60f09..0745ca3cfc 100644 --- a/usr/src/cmd/oawk/Makefile +++ b/usr/src/cmd/oawk/Makefile @@ -28,7 +28,6 @@ include ../Makefile.cmd PROG = oawk -LINKPROG = awk SRCS = b.c lib.c main.c parse.c run.c tran.c @@ -62,8 +61,6 @@ LDLIBS += -lm CPPFLAGS = -I. $(CPPFLAGS.master) CPPFLAGS += -D_FILE_OFFSET_BITS=64 -ROOTLINK = $(LINKPROG:%=$(ROOTBIN)/%) - CERRWARN += -_gcc=-Wno-implicit-function-declaration CERRWARN += -_gcc=-Wno-unused-label CERRWARN += -_gcc=-Wno-unused-variable @@ -105,7 +102,7 @@ proctab.c : $(MAKEPRCTAB) $(MAKEPRCTAB) : $(NATIVEDIR) $(NATIVEOBJS) $(LINK.c) $(NATIVEOBJS) -o $@ $(XLDLIBS5CC) -install : all $(ROOTPROG) $(ROOTLINK) +install : all $(ROOTPROG) $(NATIVEDIR) : -@mkdir -p $(NATIVEDIR) @@ -113,9 +110,6 @@ $(NATIVEDIR) : $(NATIVEDIR)/%.o : %.c $(COMPILE.c) -o $@ $< -$(ROOTLINK) : $(ROOTPROG) - $(RM) $@; $(LN) $(ROOTPROG) $@ - clean: $(RM) $(OBJS) $(CLEANFILES) diff --git a/usr/src/man/man1/Makefile b/usr/src/man/man1/Makefile index c80c00d8ed..237f02e1aa 100644 --- a/usr/src/man/man1/Makefile +++ b/usr/src/man/man1/Makefile @@ -250,7 +250,6 @@ MANFILES= acctcom.1 \ msgget.1 \ mt.1 \ mv.1 \ - nawk.1 \ nc.1 \ nca.1 \ ncab2clf.1 \ @@ -264,6 +263,7 @@ MANFILES= acctcom.1 \ nm.1 \ nohup.1 \ nroff.1 \ + oawk.1 \ od.1 \ optisa.1 \ pack.1 \ @@ -484,6 +484,7 @@ MANLINKS= batch.1 \ ksh.1 \ ldapadd.1 \ mailq.1 \ + nawk.1 \ neqn.1 \ notify.1 \ onintr.1 \ @@ -626,6 +627,8 @@ dmake.1 := LINKSRC = make.1 checkeq.1 := LINKSRC = eqn.1 neqn.1 := LINKSRC = eqn.1 +nawk.1 := LINKSRC = awk.1 + eval.1 := LINKSRC = exec.1 source.1 := LINKSRC = exec.1 diff --git a/usr/src/man/man1/awk.1 b/usr/src/man/man1/awk.1 index c5bf3da770..b2983dada4 100644 --- a/usr/src/man/man1/awk.1 +++ b/usr/src/man/man1/awk.1 @@ -41,221 +41,841 @@ .\" .\" .\" Copyright 1989 AT&T -.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. -.\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved +.\" Copyright 1992, X/Open Company Limited All Rights Reserved +.\" Portions Copyright (c) 2005, 2006 Sun Microsystems, Inc. All Rights Reserved +.\" Copyright 2020 Joyent, Inc. .\" -.TH AWK 1 "Jun 22, 2005" +.TH AWK 1 "Apr 20, 2020" .SH NAME awk \- pattern scanning and processing language .SH SYNOPSIS +.nf +\fB/usr/bin/awk\fR [\fB-F\fR \fIERE\fR] [\fB-v\fR \fIassignment\fR] \fI\&'program'\fR | \fB-f\fR \fIprogfile\fR... + [\fIargument\fR]... +.fi + .LP .nf -\fB/usr/bin/awk\fR [\fB-f\fR \fIprogfile\fR] [\fB-F\fIc\fR\fR] [' \fIprog\fR '] [\fIparameters\fR] - [\fIfilename\fR]... +\fB/usr/bin/nawk\fR [\fB-F\fR \fIERE\fR] [\fB-v\fR \fIassignment\fR] \fI\&'program'\fR | \fB-f\fR \fIprogfile\fR... + [\fIargument\fR]... .fi .LP .nf -\fB/usr/xpg4/bin/awk\fR [\fB-F\fR\fIcERE\fR] [\fB-v\fR \fIassignment\fR]... \fI\&'program'\fR \fB-f\fR \fIprogfile\fR... +\fB/usr/xpg4/bin/awk\fR [\fB-F\fR \fIERE\fR] [\fB-v\fR \fIassignment\fR]... \fI\&'program'\fR | \fB-f\fR \fIprogfile\fR... [\fIargument\fR]... .fi .SH DESCRIPTION -.sp +NOTE: The \fBnawk\fR command is now the system default awk for illumos. .LP -The \fB/usr/xpg4/bin/awk\fR utility is described on the \fBnawk\fR(1) manual -page. +The \fB/usr/bin/awk\fR and \fB/usr/xpg4/bin/awk\fR utilities execute +\fIprogram\fRs written in the \fBawk\fR programming language, which is +specialized for textual data manipulation. A \fBawk\fR \fIprogram\fR is a +sequence of patterns and corresponding actions. The string specifying +\fIprogram\fR must be enclosed in single quotes (') to protect it from +interpretation by the shell. The sequence of pattern - action statements can be +specified in the command line as \fIprogram\fR or in one, or more, file(s) +specified by the \fB-f\fR\fIprogfile\fR option. When input is read that matches +a pattern, the action associated with the pattern is performed. .sp .LP -The \fB/usr/bin/awk\fR utility scans each input \fIfilename\fR for lines that -match any of a set of patterns specified in \fIprog\fR. The \fIprog\fR string -must be enclosed in single quotes (\fB a\'\fR) to protect it from the shell. -For each pattern in \fIprog\fR there can be an associated action performed when -a line of a \fIfilename\fR matches the pattern. The set of pattern-action -statements can appear literally as \fIprog\fR or in a file specified with the -\fB-f\fR\fI progfile\fR option. Input files are read in order; if there are no -files, the standard input is read. The file name \fB\&'\(mi'\fR means the -standard input. -.SH OPTIONS +Input is interpreted as a sequence of records. By default, a record is a line, +but this can be changed by using the \fBRS\fR built-in variable. Each record of +input is matched to each pattern in the \fIprogram\fR. For each pattern +matched, the associated action is executed. .sp .LP +The \fBawk\fR utility interprets each input record as a sequence of fields +where, by default, a field is a string of non-blank characters. This default +white-space field delimiter (blanks and/or tabs) can be changed by using the +\fBFS\fR built-in variable or the \fB-F\fR\fIERE\fR option. The \fBawk\fR +utility denotes the first field in a record \fB$1\fR, the second \fB$2\fR, and +so forth. The symbol \fB$0\fR refers to the entire record; setting any other +field causes the reevaluation of \fB$0\fR. Assigning to \fB$0\fR resets the +values of all fields and the \fBNF\fR built-in variable. + +.SH OPTIONS The following options are supported: .sp .ne 2 .na -\fB\fB-f\fR\fI progfile\fR \fR +\fB\fB-F\fR \fIERE\fR\fR .ad -.RS 16n -\fBawk\fR uses the set of patterns it reads from \fIprogfile\fR. +.RS 17n +Define the input field separator to be the extended regular expression +\fIERE\fR, before any input is read (can be a character). .RE .sp .ne 2 .na -\fB\fB-F\fR\fIc\fR \fR +\fB\fB-f\fR \fIprogfile\fR\fR .ad -.RS 16n -Uses the character \fIc\fR as the field separator (FS) character. See the -discussion of \fBFS\fR below. +.RS 17n +Specifies the pathname of the file \fIprogfile\fR containing a \fBawk\fR +program. If multiple instances of this option are specified, the concatenation +of the files specified as \fIprogfile\fR in the order specified is the +\fBawk\fR program. The \fBawk\fR program can alternatively be specified in +the command line as a single argument. .RE -.SH USAGE -.SS "Input Lines" +.sp +.ne 2 +.na +\fB\fB-v\fR \fIassignment\fR\fR +.ad +.RS 17n +The \fIassignment\fR argument must be in the same form as an \fIassignment\fR +operand. The assignment is of the form \fIvar=value\fR, where \fIvar\fR is the +name of one of the variables described below. The specified assignment occurs +before executing the \fBawk\fR program, including the actions associated with +\fBBEGIN\fR patterns (if any). Multiple occurrences of this option can be +specified. +.RE + +.sp +.ne 2 +.na +\fB\fB-safe\fR\fR +.ad +.RS 17n +When passed to \fBawk\fR, this flag will prevent the program from opening new +files or running child processes. The \fBENVIRON\fR array will also not be +initialized. +.RE + +.SH OPERANDS +The following operands are supported: +.sp +.ne 2 +.na +\fB\fIprogram\fR\fR +.ad +.RS 12n +If no \fB-f\fR option is specified, the first operand to \fBawk\fR is the text +of the \fBawk\fR program. The application supplies the \fIprogram\fR operand +as a single argument to \fBawk.\fR If the text does not end in a newline +character, \fBawk\fR interprets the text as if it did. +.RE + +.sp +.ne 2 +.na +\fB\fIargument\fR\fR +.ad +.RS 12n +Either of the following two types of \fIargument\fR can be intermixed: +.sp +.ne 2 +.na +\fB\fIfile\fR\fR +.ad +.RS 14n +A pathname of a file that contains the input to be read, which is matched +against the set of patterns in the program. If no \fIfile\fR operands are +specified, or if a \fIfile\fR operand is \fB\(mi\fR, the standard input is +used. +.RE + +.sp +.ne 2 +.na +\fB\fIassignment\fR\fR +.ad +.RS 14n +An operand that begins with an underscore or alphabetic character from the +portable character set, followed by a sequence of underscores, digits and +alphabetics from the portable character set, followed by the \fB=\fR character +specifies a variable assignment rather than a pathname. The characters before +the \fB=\fR represent the name of a \fBawk\fR variable. If that name is a +\fBawk\fR reserved word, the behavior is undefined. The characters following +the equal sign is interpreted as if they appeared in the \fBawk\fR program +preceded and followed by a double-quote (\fB"\fR) character, as a \fBSTRING\fR +token , except that if the last character is an unescaped backslash, it is +interpreted as a literal backslash rather than as the first character of the +sequence \fB\e\fR\&.. The variable is assigned the value of that \fBSTRING\fR +token. If the value is considered a \fInumeric\fRstring\fI,\fR the variable is +assigned its numeric value. Each such variable assignment is performed just +before the processing of the following \fIfile\fR, if any. Thus, an assignment +before the first \fBfile\fR argument is executed after the \fBBEGIN\fR actions +(if any), while an assignment after the last \fIfile\fR argument is executed +before the \fBEND\fR actions (if any). If there are no \fIfile\fR arguments, +assignments are executed before processing the standard input. +.RE + +.RE + +.SH INPUT FILES +Input files to the \fBawk\fR program from any of the following sources: +.RS +4 +.TP +.ie t \(bu +.el o +any \fIfile\fR operands or their equivalents, achieved by modifying the +\fBawk\fR variables \fBARGV\fR and \fBARGC\fR +.RE +.RS +4 +.TP +.ie t \(bu +.el o +standard input in the absence of any \fIfile\fR operands +.RE +.RS +4 +.TP +.ie t \(bu +.el o +arguments to the \fBgetline\fR function +.RE .sp .LP -Each input line is matched against the pattern portion of every pattern-action -statement; the associated action is performed for each matched pattern. Any -\fIfilename\fR of the form \fIvar=value\fR is treated as an assignment, not a -filename, and is executed at the time it would have been opened if it were a -filename. \fIVariables\fR assigned in this manner are not available inside a -\fBBEGIN\fR rule, and are assigned after previously specified files have been -read. +must be text files. Whether the variable \fBRS\fR is set to a value other than +a newline character or not, for these files, implementations support records +terminated with the specified separator up to \fB{LINE_MAX}\fR bytes and can +support longer records. .sp .LP -An input line is normally made up of fields separated by white spaces. (This -default can be changed by using the \fBFS\fR built-in variable or the -\fB-F\fR\fIc\fR option.) The default is to ignore leading blanks and to -separate fields by blanks and/or tab characters. However, if \fBFS\fR is -assigned a value that does not include any of the white spaces, then leading -blanks are not ignored. The fields are denoted \fB$1\fR, \fB$2\fR, -\fB\&.\|.\|.\fR\|; \fB$0\fR refers to the entire line. -.SS "Pattern-action Statements" +If \fB-\fR\fBf\fR \fIprogfile\fR is specified, the files named by each of the +\fIprogfile\fR option-arguments must be text files containing an \fBawk\fR +program. .sp .LP -A pattern-action statement has the form: +The standard input are used only if no \fIfile\fR operands are specified, or if +a \fIfile\fR operand is \fB\(mi\fR\&. + +.SH EXTENDED DESCRIPTION +A \fBawk\fR program is composed of pairs of the form: .sp .in +2 .nf -\fIpattern\fR\fB { \fR\fIaction\fR\fB } \fR +pattern { \fIaction\fR } .fi .in -2 -.sp .sp .LP -Either pattern or action can be omitted. If there is no action, the matching -line is printed. If there is no pattern, the action is performed on every input -line. Pattern-action statements are separated by newlines or semicolons. +Either the pattern or the action (including the enclosing brace characters) can +be omitted. Pattern-action statements are separated by a semicolon or by a +newline. +.sp +.LP +A missing pattern matches any record of input, and a missing action is +equivalent to an action that writes the matched record of input to standard +output. +.sp +.LP +Execution of the \fBawk\fR program starts by first executing the actions +associated with all \fBBEGIN\fR patterns in the order they occur in the +program. Then each \fIfile\fR operand (or standard input if no files were +specified) is processed by reading data from the file until a record separator +is seen (a newline character by default), splitting the current record into +fields using the current value of \fBFS\fR, evaluating each pattern in the +program in the order of occurrence, and executing the action associated with +each pattern that matches the current record. The action for a matching pattern +is executed before evaluating subsequent patterns. Last, the actions associated +with all \fBEND\fR patterns is executed in the order they occur in the program. + +.SS "Expressions in awk" +Expressions describe computations used in \fIpatterns\fR and \fIactions\fR. In +the following table, valid expression operations are given in groups from +highest precedence first to lowest precedence last, with equal-precedence +operators grouped between horizontal lines. In expression evaluation, where the +grammar is formally ambiguous, higher precedence operators are evaluated before +lower precedence operators. In this table \fIexpr,\fR \fIexpr1,\fR +\fIexpr2,\fR and \fIexpr3\fR represent any expression, while \fIlvalue\fR +represents any entity that can be assigned to (that is, on the left side of an +assignment operator). +.sp + +.sp +.TS +c c c c +l l l l . +\fBSyntax\fR \fBName\fR \fBType of Result\fR \fBAssociativity\fR +_ +( \fIexpr\fR ) Grouping type of \fIexpr\fR n/a +_ +$\fIexpr\fR Field reference string n/a +_ +++ \fIlvalue\fR Pre-increment numeric n/a +\(mi\(mi \fIlvalue\fR Pre-decrement numeric n/a +\fIlvalue\fR ++ Post-increment numeric n/a +\fIlvalue\fR \(mi\(mi Post-decrement numeric n/a +_ +\fIexpr\fR ^ \fIexpr\fR Exponentiation numeric right +_ +! \fIexpr\fR Logical not numeric n/a ++ \fIexpr\fR Unary plus numeric n/a +\(mi \fIexpr\fR Unary minus numeric n/a +_ +\fIexpr\fR * \fIexpr\fR Multiplication numeric left +\fIexpr\fR / \fIexpr\fR Division numeric left +\fIexpr\fR % \fIexpr\fR Modulus numeric left +_ +\fIexpr\fR + \fIexpr\fR Addition numeric left +\fIexpr\fR \(mi \fIexpr\fR Subtraction numeric left +_ +\fIexpr\fR \fIexpr\fR String concatenation string left +_ +\fIexpr\fR < \fIexpr\fR Less than numeric none +\fIexpr\fR <= \fIexpr\fR Less than or equal to numeric none +\fIexpr\fR != \fIexpr\fR Not equal to numeric none +\fIexpr\fR == \fIexpr\fR Equal to numeric none +\fIexpr\fR > \fIexpr\fR Greater than numeric none +\fIexpr\fR >= \fIexpr\fR Greater than or equal to numeric none +_ +\fIexpr\fR ~ \fIexpr\fR ERE match numeric none +\fIexpr\fR !~ \fIexpr\fR ERE non-match numeric none +_ +\fIexpr\fR in array Array membership numeric left +( \fIindex\fR ) in Multi-dimension array numeric left + \fIarray\fR membership +_ +\fBexpr\fR && \fIexpr\fR Logical AND numeric left +_ +\fBexpr\fR |\|| \fIexpr\fR Logical OR numeric left +_ +\fIexpr1\fR ? \fIexpr2\fR Conditional expression type of selected right + : \fIexpr3\fR \fIexpr2\fR or \fIexpr3\fR +_ +\fIlvalue\fR ^= \fIexpr\fR Exponentiation numeric right + assignment +\fIlvalue\fR %= \fIexpr\fR Modulus assignment numeric right +\fIlvalue\fR *= \fIexpr\fR Multiplication numeric right + assignment +\fIlvalue\fR /= \fIexpr\fR Division assignment numeric right +\fIlvalue\fR += \fIexpr\fR Addition assignment numeric right +\fIlvalue\fR \(mi= \fIexpr\fR Subtraction assignment numeric right +\fIlvalue\fR = \fIexpr\fR Assignment type of \fIexpr\fR right +.TE + .sp .LP -Patterns are arbitrary Boolean combinations ( \fB!\fR, ||, \fB&&\fR, and -parentheses) of relational expressions and regular expressions. A relational -expression is one of the following: +Each expression has either a string value, a numeric value or both. Except as +stated for specific contexts, the value of an expression is implicitly +converted to the type needed for the context in which it is used. A string +value is converted to a numeric value by the equivalent of the following calls: .sp .in +2 .nf -\fIexpression relop expression -expression matchop regular_expression\fR +setlocale(LC_NUMERIC, ""); +\fInumeric_value\fR = atof(\fIstring_value\fR); .fi .in -2 .sp .LP -where a \fIrelop\fR is any of the six relational operators in C, and a -\fImatchop\fR is either \fB~\fR (contains) or \fB!~\fR (does not contain). An -\fIexpression\fR is an arithmetic expression, a relational expression, the -special expression +A numeric value that is exactly equal to the value of an integer is converted +to a string by the equivalent of a call to the \fBsprintf\fR function with the +string \fB%d\fR as the \fBfmt\fR argument and the numeric value being converted +as the first and only \fIexpr\fR argument. Any other numeric value is +converted to a string by the equivalent of a call to the \fBsprintf\fR function +with the value of the variable \fBCONVFMT\fR as the \fBfmt\fR argument and the +numeric value being converted as the first and only \fIexpr\fR argument. +.sp +.LP +A string value is considered to be a \fInumeric string\fR in the following +case: +.RS +4 +.TP +1. +Any leading and trailing blank characters is ignored. +.RE +.RS +4 +.TP +2. +If the first unignored character is a \fB+\fR or \fB\(mi\fR, it is ignored. +.RE +.RS +4 +.TP +3. +If the remaining unignored characters would be lexically recognized as a +\fBNUMBER\fR token, the string is considered a \fInumeric string\fR. +.RE +.sp +.LP +If a \fB\(mi\fR character is ignored in the above steps, the numeric value of +the \fInumeric string\fR is the negation of the numeric value of the recognized +\fBNUMBER\fR token. Otherwise the numeric value of the \fInumeric string\fR is +the numeric value of the recognized \fBNUMBER\fR token. Whether or not a string +is a \fInumeric string\fR is relevant only in contexts where that term is used +in this section. +.sp +.LP +When an expression is used in a Boolean context, if it has a numeric value, a +value of zero is treated as false and any other value is treated as true. +Otherwise, a string value of the null string is treated as false and any other +value is treated as true. A Boolean context is one of the following: +.RS +4 +.TP +.ie t \(bu +.el o +the first subexpression of a conditional expression. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +an expression operated on by logical NOT, logical \fBAND,\fR or logical OR. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +the second expression of a \fBfor\fR statement. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +the expression of an \fBif\fR statement. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +the expression of the \fBwhile\fR clause in either a \fBwhile\fR or \fBdo\fR +\fB\&.\|.\|.\fR \fBwhile\fR statement. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +an expression used as a pattern (as in Overall Program Structure). +.RE +.sp +.LP +The \fBawk\fR language supplies arrays that are used for storing numbers or +strings. Arrays need not be declared. They are initially empty, and their sizes +changes dynamically. The subscripts, or element identifiers, are strings, +providing a type of associative array capability. An array name followed by a +subscript within square brackets can be used as an \fIlvalue\fR and as an +expression, as described in the grammar. Unsubscripted array names are used in +only the following contexts: +.RS +4 +.TP +.ie t \(bu +.el o +a parameter in a function definition or function call. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +the \fBNAME\fR token following any use of the keyword \fBin\fR. +.RE +.sp +.LP +A valid array \fIindex\fR consists of one or more comma-separated expressions, +similar to the way in which multi-dimensional arrays are indexed in some +programming languages. Because \fBawk\fR arrays are really one-dimensional, +such a comma-separated list is converted to a single string by concatenating +the string values of the separate expressions, each separated from the other by +the value of the \fBSUBSEP\fR variable. +.sp +.LP +Thus, the following two index operations are equivalent: .sp .in +2 .nf -\fIvar \fRin \fIarray\fR +var[expr1, expr2, ... exprn] +var[expr1 SUBSEP expr2 SUBSEP ... SUBSEP exprn] .fi .in -2 .sp .LP -or a Boolean combination of these. +A multi-dimensioned \fIindex\fR used with the \fBin\fR operator must be put in +parentheses. The \fBin\fR operator, which tests for the existence of a +particular array element, does not create the element if it does not exist. +Any other reference to a non-existent array element automatically creates it. + +.SS "Variables and Special Variables" +Variables can be used in an \fBawk\fR program by referencing them. With the +exception of function parameters, they are not explicitly declared. +Uninitialized scalar variables and array elements have both a numeric value of +zero and a string value of the empty string. .sp .LP -Regular expressions are as in \fBegrep\fR(1). In patterns they must be -surrounded by slashes. Isolated regular expressions in a pattern apply to the -entire line. Regular expressions can also occur in relational expressions. A -pattern can consist of two patterns separated by a comma; in this case, the -action is performed for all lines between the occurrence of the first pattern -to the occurrence of the second pattern. +Field variables are designated by a \fB$\fR followed by a number or numerical +expression. The effect of the field number \fIexpression\fR evaluating to +anything other than a non-negative integer is unspecified. Uninitialized +variables or string values need not be converted to numeric values in this +context. New field variables are created by assigning a value to them. +References to non-existent fields (that is, fields after \fB$NF\fR) produce the +null string. However, assigning to a non-existent field (for example, +\fB$(NF+2) = 5\fR) increases the value of \fBNF\fR, create any intervening +fields with the null string as their values and cause the value of \fB$0\fR to +be recomputed, with the fields being separated by the value of \fBOFS\fR. Each +field variable has a string value when created. If the string, with any +occurrence of the decimal-point character from the current locale changed to a +period character, is considered a \fInumeric string\fR (see \fBExpressions in +awk\fR above), the field variable also has the numeric value of the \fInumeric +string\fR. + +.SS "/usr/bin/awk, /usr/xpg4/bin/awk" +\fBawk\fR sets the following special variables that are supported by both +\fB/usr/bin/awk\fR and \fB/usr/xpg4/bin/awk\fR: .sp -.LP -The special patterns \fBBEGIN\fR and \fBEND\fR can be used to capture control -before the first input line has been read and after the last input line has -been read respectively. These keywords do not combine with any other patterns. -.SS "Built-in Variables" +.ne 2 +.na +\fB\fBARGC\fR\fR +.ad +.RS 12n +The number of elements in the \fBARGV\fR array. +.RE + .sp -.LP -Built-in variables include: +.ne 2 +.na +\fB\fBARGV\fR\fR +.ad +.RS 12n +An array of command line arguments, excluding options and the \fIprogram\fR +argument, numbered from zero to \fBARGC\fR\(mi1. +.sp +The arguments in \fBARGV\fR can be modified or added to; \fBARGC\fR can be +altered. As each input file ends, \fBawk\fR treats the next non-null element +of \fBARGV\fR, up to the current value of \fBARGC\fR\(mi1, inclusive, as the +name of the next input file. Setting an element of \fBARGV\fR to null means +that it is not treated as an input file. The name \fB\(mi\fR indicates the +standard input. If an argument matches the format of an \fIassignment\fR +operand, this argument is treated as an assignment rather than a \fIfile\fR +argument. +.RE + +.sp +.ne 2 +.na +\fB\fBCONVFMT\fR\fR +.ad +.RS 12n +The \fBprintf\fR format for converting numbers to strings (except for output +statements, where \fBOFMT\fR is used). The default is \fB%.6g\fR. +.RE + +.sp +.ne 2 +.na +\fB\fBENVIRON\fR\fR +.ad +.RS 12n +The variable \fBENVIRON\fR is an array representing the value of the +environment. The indices of the array are strings consisting of the names of +the environment variables, and the value of each array element is a string +consisting of the value of that variable. If the value of an environment +variable is considered a \fInumeric string\fR, the array element also has its +numeric value. +.sp +In all cases where \fBawk\fR behavior is affected by environment variables +(including the environment of any commands that \fBawk\fR executes via the +\fBsystem\fR function or via pipeline redirections with the \fBprint\fR +statement, the \fBprintf\fR statement, or the \fBgetline\fR function), the +environment used is the environment at the time \fBawk\fR began executing. +.RE + +.sp +.ne 2 +.na +\fB\fBFILENAME\fR\fR +.ad +.RS 12n +A pathname of the current input file. Inside a \fBBEGIN\fR action the value is +undefined. Inside an \fBEND\fR action the value is the name of the last input +file processed. +.RE + +.sp +.ne 2 +.na +\fB\fBFNR\fR\fR +.ad +.RS 12n +The ordinal number of the current record in the current file. Inside a +\fBBEGIN\fR action the value is zero. Inside an \fBEND\fR action the value is +the number of the last record processed in the last file processed. +.RE + .sp .ne 2 .na -\fB\fBFILENAME\fR \fR +\fB\fBFS\fR\fR .ad -.RS 13n -name of the current input file +.RS 12n +Input field separator regular expression; a space character by default. .RE .sp .ne 2 .na -\fB\fBFS\fR \fR +\fB\fBNF\fR\fR .ad -.RS 13n -input field separator regular expression (default blank and tab) +.RS 12n +The number of fields in the current record. Inside a \fBBEGIN\fR action, the +use of \fBNF\fR is undefined unless a \fBgetline\fR function without a +\fIvar\fR argument is executed previously. Inside an \fBEND\fR action, \fBNF\fR +retains the value it had for the last record read, unless a subsequent, +redirected, \fBgetline\fR function without a \fIvar\fR argument is performed +prior to entering the \fBEND\fR action. .RE .sp .ne 2 .na -\fB\fBNF\fR \fR +\fB\fBNR\fR\fR .ad -.RS 13n -number of fields in the current record +.RS 12n +The ordinal number of the current record from the start of input. Inside a +\fBBEGIN\fR action the value is zero. Inside an \fBEND\fR action the value is +the number of the last record processed. .RE .sp .ne 2 .na -\fB\fBNR\fR \fR +\fB\fBOFMT\fR\fR .ad -.RS 13n -ordinal number of the current record +.RS 12n +The \fBprintf\fR format for converting numbers to strings in output statements +\fB"%.6g"\fR by default. The result of the conversion is unspecified if the +value of \fBOFMT\fR is not a floating-point format specification. .RE .sp .ne 2 .na -\fB\fBOFMT\fR \fR +\fB\fBOFS\fR\fR .ad -.RS 13n -output format for numbers (default \fB%.6g\fR) +.RS 12n +The \fBprint\fR statement output field separator; a space character by default. .RE .sp .ne 2 .na -\fB\fBOFS\fR \fR +\fB\fBORS\fR\fR .ad -.RS 13n -output field separator (default blank) +.RS 12n +The \fBprint\fR output record separator; a newline character by default. .RE .sp .ne 2 .na -\fB\fBORS\fR \fR +\fB\fBRLENGTH\fR\fR .ad -.RS 13n -output record separator (default new-line) +.RS 12n +The length of the string matched by the \fBmatch\fR function. .RE .sp .ne 2 .na -\fB\fBRS\fR \fR +\fB\fBRS\fR\fR .ad -.RS 13n -input record separator (default new-line) +.RS 12n +The first character of the string value of \fBRS\fR is the input record +separator; a newline character by default. If \fBRS\fR contains more than one +character, the results are unspecified. If \fBRS\fR is null, then records are +separated by sequences of one or more blank lines. Leading or trailing blank +lines do not produce empty records at the beginning or end of input, and the +field separator is always newline, no matter what the value of \fBFS\fR. +.RE + +.sp +.ne 2 +.na +\fB\fBRSTART\fR\fR +.ad +.RS 12n +The starting position of the string matched by the \fBmatch\fR function, +numbering from 1. This is always equivalent to the return value of the +\fBmatch\fR function. +.RE + +.sp +.ne 2 +.na +\fB\fBSUBSEP\fR\fR +.ad +.RS 12n +The subscript separator string for multi-dimensional arrays. The default value +is \fB\e034\fR\&. +.RE + +.SS "/usr/bin/awk" +The following variable is supported for \fB/usr/bin/awk\fR only: +.sp +.ne 2 +.na +\fB\fBRT\fR\fR +.ad +.RS 12n +The record terminator for the most recent record read. For most records this +will be the same value as \fBRS\fR. At the end of a file with no trailing +separator value, though, this will be set to the empty string (\fB""\fR). +.RE + +.SS "Regular Expressions" +The \fBawk\fR utility makes use of the extended regular expression notation +(see \fBregex\fR(5)) except that it allows the use of C-language conventions to +escape special characters within the EREs, namely \fB\e\e\fR, \fB\ea\fR, +\fB\eb\fR, \fB\ef\fR, \fB\en\fR, \fB\er\fR, \fB\et\fR, \fB\ev\fR, and those +specified in the following table. These escape sequences are recognized both +inside and outside bracket expressions. Note that records need not be +separated by newline characters and string constants can contain newline +characters, so even the \fB\en\fR sequence is valid in \fBawk\fR EREs. Using +a slash character within the regular expression requires escaping as shown in +the table below: +.sp + +.sp +.TS +l l l +l l l . +\fBEscape Sequence\fR \fBDescription\fR \fBMeaning\fR +_ +\fB\e"\fR Backslash quotation-mark Quotation-mark character +_ +\fB\e/\fR Backslash slash Slash character +_ +\fB\e\fR\fIddd\fR T{ +A backslash character followed by the longest sequence of one, two, or three octal-digit characters (01234567). If all of the digits are 0, (that is, representation of the NULL character), the behavior is undefined. +T} T{ +The character encoded by the one-, two- or three-digit octal integer. Multi-byte characters require multiple, concatenated escape sequences, including the leading \e for each byte. +T} +_ +\fB\e\fR\fIc\fR T{ +A backslash character followed by any character not described in this table or special characters (\fB\e\e\fR, \fB\ea\fR, \fB\eb\fR, \fB\ef\fR, \fB\en\fR, \fB\er\fR, \fB\et\fR, \fB\ev\fR). +T} Undefined +.TE + +.sp +.LP +A regular expression can be matched against a specific field or string by using +one of the two regular expression matching operators, \fB~\fR and \fB!\|~\fR. +These operators interpret their right-hand operand as a regular expression and +their left-hand operand as a string. If the regular expression matches the +string, the \fB~\fR expression evaluates to the value \fB1\fR, and the +\fB!\|~\fR expression evaluates to the value \fB0\fR. If the regular expression +does not match the string, the \fB~\fR expression evaluates to the value +\fB0\fR, and the \fB!\|~\fR expression evaluates to the value \fB1\fR. If the +right-hand operand is any expression other than the lexical token \fBERE\fR, +the string value of the expression is interpreted as an extended regular +expression, including the escape conventions described above. Notice that these +same escape conventions also are applied in the determining the value of a +string literal (the lexical token \fBSTRING\fR), and is applied a second time +when a string literal is used in this context. +.sp +.LP +When an \fBERE\fR token appears as an expression in any context other than as +the right-hand of the \fB~\fR or \fB!\|~\fR operator or as one of the built-in +function arguments described below, the value of the resulting expression is +the equivalent of: +.sp +.in +2 +.nf +$0 ~ /\fIere\fR/ +.fi +.in -2 + +.sp +.LP +The \fIere\fR argument to the \fBgsub,\fR \fBmatch,\fR \fBsub\fR functions, and +the \fIfs\fR argument to the \fBsplit\fR function (see \fBString Functions\fR) +is interpreted as extended regular expressions. These can be either \fBERE\fR +tokens or arbitrary expressions, and are interpreted in the same manner as the +right-hand side of the \fB~\fR or \fB!\|~\fR operator. +.sp +.LP +An extended regular expression can be used to separate fields by using the +\fB-F\fR \fIERE\fR option or by assigning a string containing the expression to +the built-in variable \fBFS\fR. The default value of the \fBFS\fR variable is a +single space character. The following describes \fBFS\fR behavior: +.RS +4 +.TP +1. +If \fBFS\fR is a single character: +.RS +4 +.TP +.ie t \(bu +.el o +If \fBFS\fR is the space character, skip leading and trailing blank characters; +fields are delimited by sets of one or more blank characters. .RE +.RS +4 +.TP +.ie t \(bu +.el o +Otherwise, if \fBFS\fR is any other character \fIc\fR, fields are delimited by +each single occurrence of \fIc\fR. +.RE +.RE +.RS +4 +.TP +2. +Otherwise, the string value of \fBFS\fR is considered to be an extended +regular expression. Each occurrence of a sequence matching the extended regular +expression delimits fields. +.RE +.sp +.LP +Except in the \fBgsub\fR, \fBmatch\fR, \fBsplit\fR, and \fBsub\fR built-in +functions, regular expression matching is based on input records. That is, +record separator characters (the first character of the value of the variable +\fBRS\fR, a newline character by default) cannot be embedded in the expression, +and no expression matches the record separator character. If the record +separator is not a newline character, newline characters embedded in the +expression can be matched. In those four built-in functions, regular expression +matching are based on text strings. So, any character (including the newline +character and the record separator) can be embedded in the pattern and an +appropriate pattern matches any character. However, in all \fBawk\fR regular +expression matching, the use of one or more NULL characters in the pattern, +input record or text string produces undefined results. + +.SS "Patterns" +A \fIpattern\fR is any valid \fIexpression,\fR a range specified by two +expressions separated by comma, or one of the two special patterns \fBBEGIN\fR +or \fBEND\fR. +.SS "Special Patterns" +The \fBawk\fR utility recognizes two special patterns, \fBBEGIN\fR and +\fBEND\fR. Each \fBBEGIN\fR pattern is matched once and its associated action +executed before the first record of input is read (except possibly by use of +the \fBgetline\fR function in a prior \fBBEGIN\fR action) and before command +line assignment is done. Each \fBEND\fR pattern is matched once and its +associated action executed after the last record of input has been read. These +two patterns have associated actions. +.sp +.LP +\fBBEGIN\fR and \fBEND\fR do not combine with other patterns. Multiple +\fBBEGIN\fR and \fBEND\fR patterns are allowed. The actions associated with the +\fBBEGIN\fR patterns are executed in the order specified in the program, as are +the \fBEND\fR actions. An \fBEND\fR pattern can precede a \fBBEGIN\fR pattern +in a program. .sp .LP +If an \fBawk\fR program consists of only actions with the pattern \fBBEGIN\fR, +and the \fBBEGIN\fR action contains no \fBgetline\fR function, \fBawk\fR exits +without reading its input when the last statement in the last \fBBEGIN\fR +action is executed. If an \fBawk\fR program consists of only actions with the +pattern \fBEND\fR or only actions with the patterns \fBBEGIN\fR and \fBEND\fR, +the input is read before the statements in the \fBEND\fR actions are executed. + +.SS "Expression Patterns" +An expression pattern is evaluated as if it were an expression in a Boolean +context. If the result is true, the pattern is considered to match, and the +associated action (if any) is executed. If the result is false, the action is +not executed. + +.SS "Pattern Ranges" +A pattern range consists of two expressions separated by a comma. In this case, +the action is performed for all records between a match of the first expression +and the following match of the second expression, inclusive. At this point, the +pattern range can be repeated starting at input records subsequent to the end +of the matched range. + +.SS "Actions" An action is a sequence of statements. A statement can be one of the following: .sp .in +2 @@ -265,50 +885,213 @@ while ( \fIexpression\fR ) \fIstatement\fR do \fIstatement\fR while ( \fIexpression\fR ) for ( \fIexpression\fR ; \fIexpression\fR ; \fIexpression\fR ) \fIstatement\fR for ( \fIvar\fR in \fIarray\fR ) \fIstatement\fR +delete \fIarray\fR[\fIsubscript\fR] #delete an array element +delete \fIarray\fR #delete all elements within an array break continue { [ \fIstatement\fR ] .\|.\|. } -\fIexpression\fR # commonly variable = expression +\fIexpression\fR # commonly variable = expression print [ \fIexpression-list\fR ] [ >\fIexpression\fR ] printf format [ ,\fIexpression-list\fR ] [ >\fIexpression\fR ] -next # skip remaining patterns on this input line -exit [expr] # skip the rest of the input; exit status is expr +next # skip remaining patterns on this input line +nextfile # skip remaining patterns on this input file +exit [expr] # skip the rest of the input; exit status is expr +return [expr] .fi .in -2 .sp .LP -Statements are terminated by semicolons, newlines, or right braces. An empty -expression-list stands for the whole input line. Expressions take on string or -numeric values as appropriate, and are built using the operators \fB+\fR, -\fB\(mi\fR, \fB*\fR, \fB/\fR, \fB%\fR, \fB^\fR and concatenation (indicated by -a blank). The operators \fB++\fR, \fB\(mi\(mi\fR, \fB+=\fR, \fB\(mi=\fR, -\fB*=\fR, \fB/=\fR, \fB%=\fR, \fB^=\fR, \fB>\fR, \fB>=\fR, \fB<\fR, \fB<=\fR, -\fB==\fR, \fB!=\fR, and \fB?:\fR are also available in expressions. Variables -can be scalars, array elements (denoted x[i]), or fields. Variables are -initialized to the null string or zero. Array subscripts can be any string, not -necessarily numeric; this allows for a form of associative memory. String -constants are quoted (\fB""\fR), with the usual C escapes recognized within. +Any single statement can be replaced by a statement list enclosed in braces. +The statements are terminated by newline characters or semicolons, and are +executed sequentially in the order that they appear. +.sp +.LP +The \fBnext\fR statement causes all further processing of the current input +record to be abandoned. The behavior is undefined if a \fBnext\fR statement +appears or is invoked in a \fBBEGIN\fR or \fBEND\fR action. +.sp +.LP +The \fBnextfile\fR statement is similar to \fBnext\fR, but also skips all other +records in the current file, and moves on to processing the next input file if +available (or exits the program if there are none). (Note that this keyword is +not supported by \fB/usr/xpg4/bin/awk\fR.) .sp .LP -The \fBprint\fR statement prints its arguments on the standard output, or on a -file if \fB>\fR\fIexpression\fR is present, or on a pipe if '\fB|\fR\fIcmd\fR' -is present. The output resulted from the print statement is terminated by the -output record separator with each argument separated by the current output -field separator. The \fBprintf\fR statement formats its expression list -according to the format (see \fBprintf\fR(3C)). -.SS "Built-in Functions" +The \fBexit\fR statement invokes all \fBEND\fR actions in the order in which +they occur in the program source and then terminate the program without reading +further input. An \fBexit\fR statement inside an \fBEND\fR action terminates +the program without further execution of \fBEND\fR actions. If an expression +is specified in an \fBexit\fR statement, its numeric value is the exit status +of \fBawk\fR, unless subsequent errors are encountered or a subsequent +\fBexit\fR statement with an expression is executed. + +.SS "Output Statements" +Both \fBprint\fR and \fBprintf\fR statements write to standard output by +default. The output is written to the location specified by +\fIoutput_redirection\fR if one is supplied, as follows: +.sp +.in +2 +.nf +\fB>\fR \fIexpression\fR\fB>>\fR \fIexpression\fR\fB|\fR \fIexpression\fR +.fi +.in -2 + .sp .LP -The arithmetic functions are as follows: +In all cases, the \fIexpression\fR is evaluated to produce a string that is +used as a full pathname to write into (for \fB>\fR or \fB>>\fR) or as a command +to be executed (for \fB|\fR). Using the first two forms, if the file of that +name is not currently open, it is opened, creating it if necessary and using +the first form, truncating the file. The output then is appended to the file. +As long as the file remains open, subsequent calls in which \fIexpression\fR +evaluates to the same string value simply appends output to the file. The file +remains open until the \fBclose\fR function, which is called with an expression +that evaluates to the same string value. +.sp +.LP +The third form writes output onto a stream piped to the input of a command. The +stream is created if no stream is currently open with the value of +\fIexpression\fR as its command name. The stream created is equivalent to one +created by a call to the \fBpopen\fR(3C) function with the value of +\fIexpression\fR as the \fIcommand\fR argument and a value of \fBw\fR as the +\fImode\fR argument. As long as the stream remains open, subsequent calls in +which \fIexpression\fR evaluates to the same string value writes output to the +existing stream. The stream remains open until the \fBclose\fR function is +called with an expression that evaluates to the same string value. At that +time, the stream is closed as if by a call to the \fBpclose\fR function. +.sp +.LP +These output statements take a comma-separated list of \fIexpression\fR \fIs\fR +referred in the grammar by the non-terminal symbols \fBexpr_list,\fR +\fBprint_expr_list\fR or \fBprint_expr_list_opt.\fR This list is referred to +here as the \fIexpression list\fR, and each member is referred to as an +\fIexpression argument\fR. +.sp +.LP +The \fBprint\fR statement writes the value of each expression argument onto the +indicated output stream separated by the current output field separator (see +variable \fBOFS\fR above), and terminated by the output record separator (see +variable \fBORS\fR above). All expression arguments is taken as strings, being +converted if necessary; with the exception that the \fBprintf\fR format in +\fBOFMT\fR is used instead of the value in \fBCONVFMT\fR. An empty expression +list stands for the whole input record \fB(\fR$0\fB)\fR. +.sp +.LP +The \fBprintf\fR statement produces output based on a notation similar to the +File Format Notation used to describe file formats in this document Output is +produced as specified with the first expression argument as the string +\fBformat\fR and subsequent expression arguments as the strings \fBarg1\fR to +\fBargn,\fR inclusive, with the following exceptions: +.RS +4 +.TP +1. +The \fIformat\fR is an actual character string rather than a graphical +representation. Therefore, it cannot contain empty character positions. The +space character in the \fIformat\fR string, in any context other than a +\fIflag\fR of a conversion specification, is treated as an ordinary character +that is copied to the output. +.RE +.RS +4 +.TP +2. +If the character set contains a Delta character and that character appears +in the \fIformat\fR string, it is treated as an ordinary character that is +copied to the output. +.RE +.RS +4 +.TP +3. +The \fIescape sequences\fR beginning with a backslash character is treated +as sequences of ordinary characters that are copied to the output. Note that +these same sequences is interpreted lexically by \fBawk\fR when they appear in +literal strings, but they is not treated specially by the \fBprintf\fR +statement. +.RE +.RS +4 +.TP +4. +A \fIfield width\fR or \fIprecision\fR can be specified as the \fB*\fR +character instead of a digit string. In this case the next argument from the +expression list is fetched and its numeric value taken as the field width or +precision. +.RE +.RS +4 +.TP +5. +The implementation does not precede or follow output from the \fBd\fR or +\fBu\fR conversion specifications with blank characters not specified by the +\fIformat\fR string. +.RE +.RS +4 +.TP +6. +The implementation does not precede output from the \fBo\fR conversion +specification with leading zeros not specified by the \fIformat\fR string. +.RE +.RS +4 +.TP +7. +For the \fBc\fR conversion specification: if the argument has a numeric +value, the character whose encoding is that value is output. If the value is +zero or is not the encoding of any character in the character set, the behavior +is undefined. If the argument does not have a numeric value, the first +character of the string value is output; if the string does not contain any +characters the behavior is undefined. +.RE +.RS +4 +.TP +8. +For each conversion specification that consumes an argument, the next +expression argument is evaluated. With the exception of the \fBc\fR conversion, +the value is converted to the appropriate type for the conversion +specification. +.RE +.RS +4 +.TP +9. +If there are insufficient expression arguments to satisfy all the conversion +specifications in the \fIformat\fR string, the behavior is undefined. +.RE +.RS +4 +.TP +10. +If any character sequence in the \fIformat\fR string begins with a % +character, but does not form a valid conversion specification, the behavior is +unspecified. +.RE +.sp +.LP +Both \fBprint\fR and \fBprintf\fR can output at least \fB{LINE_MAX}\fR bytes. + +.SS "Functions" +The \fBawk\fR language has a variety of built-in functions: arithmetic, +string, input/output and general. + +.SS "Arithmetic Functions" +The arithmetic functions, except for \fBint\fR, are based on the \fBISO\fR +\fBC\fR standard. The behavior is undefined in cases where the \fBISO\fR +\fBC\fR standard specifies that an error be returned or that the behavior is +undefined. Although the grammar permits built-in functions to appear with no +arguments or parentheses, unless the argument or parentheses are indicated as +optional in the following list (by displaying them within the \fB[ ]\fR +brackets), such use is undefined. +.sp +.ne 2 +.na +\fB\fBatan2(\fR\fIy\fR,\fIx\fR\fB)\fR\fR +.ad +.RS 17n +Return arctangent of \fIy\fR/\fIx\fR. +.RE + .sp .ne 2 .na \fB\fBcos\fR(\fIx\fR)\fR .ad -.RS 11n -Return cosine of \fIx\fR, where \fIx\fR is in radians. (In -\fB/usr/xpg4/bin/awk\fR only. See \fBnawk\fR(1).) +.RS 17n +Return cosine of \fIx,\fR where \fIx\fR is in radians. .RE .sp @@ -316,9 +1099,8 @@ Return cosine of \fIx\fR, where \fIx\fR is in radians. (In .na \fB\fBsin\fR(\fIx\fR)\fR .ad -.RS 11n -Return sine of \fIx\fR, where \fIx\fR is in radians. (In -\fB/usr/xpg4/bin/awk\fR only. See \fBnawk\fR(1).) +.RS 17n +Return sine of \fIx,\fR where \fIx\fR is in radians. .RE .sp @@ -326,7 +1108,7 @@ Return sine of \fIx\fR, where \fIx\fR is in radians. (In .na \fB\fBexp\fR(\fIx\fR)\fR .ad -.RS 11n +.RS 17n Return the exponential function of \fIx\fR. .RE @@ -335,7 +1117,7 @@ Return the exponential function of \fIx\fR. .na \fB\fBlog\fR(\fIx\fR)\fR .ad -.RS 11n +.RS 17n Return the natural logarithm of \fIx\fR. .RE @@ -344,7 +1126,7 @@ Return the natural logarithm of \fIx\fR. .na \fB\fBsqrt\fR(\fIx\fR)\fR .ad -.RS 11n +.RS 17n Return the square root of \fIx\fR. .RE @@ -353,191 +1135,558 @@ Return the square root of \fIx\fR. .na \fB\fBint\fR(\fIx\fR)\fR .ad -.RS 11n -Truncate its argument to an integer. It is truncated toward \fB0\fR when -\fIx\fR >\fB 0\fR. +.RS 17n +Truncate its argument to an integer. It is truncated toward 0 when \fIx\fR > 0. .RE .sp -.LP -The string functions are as follows: +.ne 2 +.na +\fB\fBrand()\fR\fR +.ad +.RS 17n +Return a random number \fIn\fR, such that 0 \(<= \fIn\fR < 1. +.RE + +.sp +.ne 2 +.na +\fB\fBsrand\fR([\fBexpr\fR])\fR +.ad +.RS 17n +Set the seed value for \fBrand\fR to \fIexpr\fR or use the time of day if +\fIexpr\fR is omitted. The previous seed value is returned. +.RE + +.SS "String Functions" +The string functions in the following list shall be supported. Although the +grammar permits built-in functions to appear with no arguments or parentheses, +unless the argument or parentheses are indicated as optional in the following +list (by displaying them within the \fB[ ]\fR brackets), such use is undefined. +.sp +.ne 2 +.na +\fB\fBgsub\fR(\fIere\fR,\fIrepl\fR[,\|\fIin\fR])\fR +.ad +.sp .6 +.RS 4n +Behave like \fBsub\fR (see below), except that it replaces all occurrences of +the regular expression (like the \fBed\fR utility global substitute) in +\fB$0\fR or in the \fIin\fR argument, when specified. +.RE + .sp .ne 2 .na -\fB\fBindex(\fR\fIs\fR\fB, \fR\fIt\fR\fB)\fR\fR +\fB\fBindex\fR(\fIs\fR,\fIt\fR)\fR .ad .sp .6 .RS 4n -Return the position in string \fIs\fR where string \fIt\fR first occurs, or -\fB0\fR if it does not occur at all. +Return the position, in characters, numbering from 1, in string \fIs\fR where +string \fIt\fR first occurs, or zero if it does not occur at all. .RE .sp .ne 2 .na -\fB\fBint(\fR\fIs\fR\fB)\fR\fR +\fB\fBlength\fR[([\fIv\fR])]\fR .ad .sp .6 .RS 4n -truncates \fIs\fR to an integer value. If \fIs\fR is not specified, $0 is used. +Given no argument, this function returns the length of the whole record, +\fB$0\fR. If given an array as an argument (and using \fB/usr/bin/awk\fR), +then this returns the number of elements it contains. Otherwise, this function +interprets the argument as a string (performing any needed conversions) and +returns its length in characters. .RE .sp .ne 2 .na -\fB\fBlength(\fR\fIs\fR\fB)\fR\fR +\fB\fBmatch\fR(\fIs\fR,\fIere\fR)\fR .ad .sp .6 .RS 4n -Return the length of its argument taken as a string, or of the whole line if -there is no argument. +Return the position, in characters, numbering from 1, in string \fIs\fR where +the extended regular expression \fIere\fR occurs, or zero if it does not occur +at all. \fBRSTART\fR is set to the starting position (which is the same as the +returned value), zero if no match is found; \fBRLENGTH\fR is set to the length +of the matched string, \(mi1 if no match is found. .RE .sp .ne 2 .na -\fB\fBsplit(\fR\fIs\fR, \fIa\fR, \fIfs\fR\fB)\fR\fR +\fB\fBsplit\fR(\fIs\fR,\fIa\fR[,\|\fIfs\fR])\fR .ad .sp .6 .RS 4n -Split the string \fIs\fR into array elements \fIa\fR[\fI1\fR], -\fIa\fR[\fI2\fR], \|.\|.\|. \fIa\fR[\fIn\fR], and returns \fIn\fR. The -separation is done with the regular expression \fIfs\fR or with the field -separator \fBFS\fR if \fIfs\fR is not given. +Split the string \fIs\fR into array elements \fIa\fR[1], \fIa\fR[2], +\fB\&...,\fR \fIa\fR[\fIn\fR], and return \fIn\fR. The separation is done with +the extended regular expression \fIfs\fR or with the field separator \fBFS\fR +if \fIfs\fR is not given. Each array element has a string value when created. +If the string assigned to any array element, with any occurrence of the +decimal-point character from the current locale changed to a period character, +would be considered a \fInumeric string\fR; the array element also has the +numeric value of the \fInumeric string\fR. The effect of a null string as the +value of \fIfs\fR is unspecified. .RE .sp .ne 2 .na -\fB\fBsprintf(\fR\fIfmt\fR, \fIexpr\fR, \fIexpr\fR,\|.\|.\|.\|\fB)\fR\fR +\fB\fBsprintf\fR(\fBfmt\fR,\fIexpr\fR,\fIexpr\fR,\fB\&...\fR)\fR .ad .sp .6 .RS 4n -Format the expressions according to the \fBprintf\fR(3C) format given by -\fIfmt\fR and returns the resulting string. +Format the expressions according to the \fBprintf\fR format given by \fIfmt\fR +and return the resulting string. .RE .sp .ne 2 .na -\fB\fBsubstr(\fR\fIs\fR, \fIm\fR, \fIn\fR\fB)\fR\fR +\fB\fBsub\fR(\fIere\fR,\fIrepl\fR[,\|\fIin\fR])\fR .ad .sp .6 .RS 4n -returns the \fIn\fR-character substring of \fIs\fR that begins at position -\fIm\fR. +Substitute the string \fIrepl\fR in place of the first instance of the extended +regular expression \fBERE\fR in string in and return the number of +substitutions. An ampersand ( \fB&\fR ) appearing in the string \fIrepl\fR is +replaced by the string from in that matches the regular expression. An +ampersand preceded with a backslash ( \fB\e\fR ) is interpreted as the literal +ampersand character. An occurrence of two consecutive backslashes is +interpreted as just a single literal backslash character. Any other occurrence +of a backslash (for example, preceding any other character) is treated as a +literal backslash character. If \fIrepl\fR is a string literal, the handling of +the ampersand character occurs after any lexical processing, including any +lexical backslash escape sequence processing. If \fBin\fR is specified and it +is not an \fBlvalue\fR the behavior is undefined. If in is omitted, \fBawk\fR +uses the current record (\fB$0\fR) in its place. +.RE + +.sp +.ne 2 +.na +\fB\fBsubstr\fR(\fIs\fR,\fIm\fR[,\|\fIn\fR])\fR +.ad +.sp .6 +.RS 4n +Return the at most \fIn\fR-character substring of \fIs\fR that begins at +position \fIm,\fR numbering from 1. If \fIn\fR is missing, the length of the +substring is limited by the length of the string \fIs\fR. +.RE + +.sp +.ne 2 +.na +\fB\fBtolower\fR(\fIs\fR)\fR +.ad +.sp .6 +.RS 4n +Return a string based on the string \fIs\fR. Each character in \fIs\fR that is +an upper-case letter specified to have a \fBtolower\fR mapping by the +\fBLC_CTYPE\fR category of the current locale is replaced in the returned +string by the lower-case letter specified by the mapping. Other characters in +\fIs\fR are unchanged in the returned string. +.RE + +.sp +.ne 2 +.na +\fB\fBtoupper\fR(\fIs\fR)\fR +.ad +.sp .6 +.RS 4n +Return a string based on the string \fIs\fR. Each character in \fIs\fR that is +a lower-case letter specified to have a \fBtoupper\fR mapping by the +\fBLC_CTYPE\fR category of the current locale is replaced in the returned +string by the upper-case letter specified by the mapping. Other characters in +\fIs\fR are unchanged in the returned string. .RE .sp .LP -The input/output function is as follows: +All of the preceding functions that take \fIERE\fR as a parameter expect a +pattern or a string valued expression that is a regular expression as defined +below. + +.SS "Input/Output and General Functions" +The input/output and general functions are: +.sp +.ne 2 +.na +\fB\fBclose(\fR\fIexpression\fR)\fR +.ad +.RS 27n +Close the file or pipe opened by a \fBprint\fR or \fBprintf\fR statement or a +call to \fBgetline\fR with the same string-valued \fIexpression\fR. If the +close was successful, the function returns \fB0\fR; otherwise, it returns +non-zero. +.RE + +.sp +.ne 2 +.na +\fB\fBfflush(\fR\fIexpression\fR)\fR +.ad +.RS 27n +Flush any buffered output for the file or pipe opened by a \fBprint\fR or +\fBprintf\fR statement or a call to \fBgetline\fR with the same string-valued +\fIexpression\fR. If the flush was successful, the function returns \fB0\fR; +otherwise, it returns \fBEOF\fR. If no arguments or the empty string +(\fB""\fR) are given, then all open files will be flushed. (Note that +\fBfflush\fR is supported in \fB/usr/bin/awk\fR only.) +.RE + +.sp +.ne 2 +.na +\fB\fIexpression\fR|\fBgetline\fR[\fIvar\fR]\fR +.ad +.RS 27n +Read a record of input from a stream piped from the output of a command. The +stream is created if no stream is currently open with the value of +\fIexpression\fR as its command name. The stream created is equivalent to one +created by a call to the \fBpopen\fR function with the value of +\fIexpression\fR as the \fIcommand\fR argument and a value of \fBr\fR as the +\fImode\fR argument. As long as the stream remains open, subsequent calls in +which \fIexpression\fR evaluates to the same string value reads subsequent +records from the file. The stream remains open until the \fBclose\fR function +is called with an expression that evaluates to the same string value. At that +time, the stream is closed as if by a call to the \fBpclose\fR function. If +\fIvar\fR is missing, \fB$0\fR and \fBNF\fR is set. Otherwise, \fIvar\fR is +set. +.sp +The \fBgetline\fR operator can form ambiguous constructs when there are +operators that are not in parentheses (including concatenate) to the left of +the \fB|\fR (to the beginning of the expression containing \fBgetline\fR). In +the context of the \fB$\fR operator, \fB|\fR behaves as if it had a lower +precedence than \fB$\fR. The result of evaluating other operators is +unspecified, and all such uses of portable applications must be put in +parentheses properly. +.RE + .sp .ne 2 .na \fB\fBgetline\fR\fR .ad -.RS 11n -Set \fB$0\fR to the next input record from the current input file. -\fBgetline\fR returns \fB1\fR for successful input, \fB0\fR for end of file, -and \fB\(mi1\fR for an error. +.RS 27n +Set \fB$0\fR to the next input record from the current input file. This form of +\fBgetline\fR sets the \fBNF\fR, \fBNR\fR, and \fBFNR\fR variables. +.RE + +.sp +.ne 2 +.na +\fB\fBgetline\fR \fIvar\fR\fR +.ad +.RS 27n +Set variable \fIvar\fR to the next input record from the current input file. +This form of \fBgetline\fR sets the \fBFNR\fR and \fBNR\fR variables. +.RE + +.sp +.ne 2 +.na +\fB\fBgetline\fR [\fIvar\fR] \fB<\fR \fIexpression\fR\fR +.ad +.RS 27n +Read the next record of input from a named file. The \fIexpression\fR is +evaluated to produce a string that is used as a full pathname. If the file of +that name is not currently open, it is opened. As long as the stream remains +open, subsequent calls in which \fIexpression\fR evaluates to the same string +value reads subsequent records from the file. The file remains open until the +\fBclose\fR function is called with an expression that evaluates to the same +string value. If \fIvar\fR is missing, \fB$0\fR and \fBNF\fR is set. Otherwise, +\fIvar\fR is set. +.sp +The \fBgetline\fR operator can form ambiguous constructs when there are binary +operators that are not in parentheses (including concatenate) to the right of +the \fB<\fR (up to the end of the expression containing the \fBgetline\fR). The +result of evaluating such a construct is unspecified, and all such uses of +portable applications must be put in parentheses properly. .RE -.SS "Large File Behavior" +.sp +.ne 2 +.na +\fB\fBsystem\fR(\fIexpression\fR)\fR +.ad +.RS 27n +Execute the command given by \fIexpression\fR in a manner equivalent to the +\fBsystem\fR(3C) function and return the exit status of the command. +.RE + +.sp +.LP +All forms of \fBgetline\fR return \fB1\fR for successful input, \fB0\fR for end +of file, and \fB\(mi1\fR for an error. +.sp +.LP +Where strings are used as the name of a file or pipeline, the strings must be +textually identical. The terminology ``same string value'' implies that +``equivalent strings'', even those that differ only by space characters, +represent different files. + +.SS "User-defined Functions" +The \fBawk\fR language also provides user-defined functions. Such functions +can be defined as: +.sp +.in +2 +.nf +\fBfunction\fR \fIname\fR(\fIargs\fR,\|.\|.\|.) { \fIstatements\fR } +.fi +.in -2 + +.sp +.LP +A function can be referred to anywhere in an \fBawk\fR program; in particular, +its use can precede its definition. The scope of a function is global. +.sp +.LP +Function arguments can be either scalars or arrays; the behavior is undefined +if an array name is passed as an argument that the function uses as a scalar, +or if a scalar expression is passed as an argument that the function uses as an +array. Function arguments are passed by value if scalar and by reference if +array name. Argument names are local to the function; all other variable names +are global. The same name is not used as both an argument name and as the name +of a function or a special \fBawk\fR variable. The same name must not be used +both as a variable name with global scope and as the name of a function. The +same name must not be used within the same scope both as a scalar variable and +as an array. +.sp +.LP +The number of parameters in the function definition need not match the number +of parameters in the function call. Excess formal parameters can be used as +local variables. If fewer arguments are supplied in a function call than are in +the function definition, the extra parameters that are used in the function +body as scalars are initialized with a string value of the null string and a +numeric value of zero, and the extra parameters that are used in the function +body as arrays are initialized as empty arrays. If more arguments are supplied +in a function call than are in the function definition, the behavior is +undefined. +.sp +.LP +When invoking a function, no white space can be placed between the function +name and the opening parenthesis. Function calls can be nested and recursive +calls can be made upon functions. Upon return from any nested or recursive +function call, the values of all of the calling function's parameters are +unchanged, except for array parameters passed by reference. The \fBreturn\fR +statement can be used to return a value. If a \fBreturn\fR statement appears +outside of a function definition, the behavior is undefined. +.sp +.LP +In the function definition, newline characters are optional before the opening +brace and after the closing brace. Function definitions can appear anywhere in +the program where a \fIpattern-action\fR pair is allowed. + +.SH USAGE +The \fBindex\fR, \fBlength\fR, \fBmatch\fR, and \fBsubstr\fR functions should +not be confused with similar functions in the \fBISO C\fR standard; the +\fBawk\fR versions deal with characters, while the \fBISO C\fR standard deals +with bytes. +.sp +.LP +Because the concatenation operation is represented by adjacent expressions +rather than an explicit operator, it is often necessary to use parentheses to +enforce the proper evaluation precedence. .sp .LP See \fBlargefile\fR(5) for the description of the behavior of \fBawk\fR when -encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). +encountering files greater than or equal to 2 Gbyte (2^31 bytes). + .SH EXAMPLES +The \fBawk\fR program specified in the command line is most easily specified +within single-quotes (for example, \fB\&'\fR\fIprogram\fR\fB\&'\fR) for +applications using \fBsh\fR, because \fBawk\fR programs commonly contain +characters that are special to the shell, including double-quotes. In the cases +where a \fBawk\fR program contains single-quote characters, it is usually +easiest to specify most of the program as strings within single-quotes +concatenated by the shell with quoted single-quote characters. For example: +.sp +.in +2 +.nf +awk '/'\e''/ { print "quote:", $0 }' +.fi +.in -2 + +.sp .LP -\fBExample 1 \fRPrinting Lines Longer Than 72 Characters +prints all lines from the standard input containing a single-quote character, +prefixed with \fBquote:\fR. .sp .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints lines longer than seventy two -characters: +The following are examples of simple \fBawk\fR programs: +.LP +\fBExample 1 \fRWrite to the standard output all input lines for which field 3 +is greater than 5: +.sp +.in +2 +.nf +\fB$3 > 5\fR +.fi +.in -2 +.sp +.LP +\fBExample 2 \fRWrite every tenth line: .sp .in +2 .nf -\fBlength > 72\fR +\fB(NR % 10) == 0\fR .fi .in -2 .sp .LP -\fBExample 2 \fRPrinting Fields in Opposite Order +\fBExample 3 \fRWrite any line with a substring matching the regular +expression: +.sp +.in +2 +.nf +\fB/(G|D)(2[0-9][[:alpha:]]*)/\fR +.fi +.in -2 +.sp + +.LP +\fBExample 4 \fRPrint any line with a substring containing a G or D, followed +by a sequence of digits and characters: .sp .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints the first two fields in opposite -order: +This example uses character classes \fBdigit\fR and \fBalpha\fR to match +language-independent digit and alphabetic characters, respectively. .sp .in +2 .nf -\fB{ print $2, $1 }\fR +\fB/(G|D)([[:digit:][:alpha:]]*)/\fR +.fi +.in -2 +.sp + +.LP +\fBExample 5 \fRWrite any line in which the second field matches the regular +expression and the fourth field does not: +.sp +.in +2 +.nf +\fB$2 ~ /xyz/ && $4 !~ /xyz/\fR .fi .in -2 .sp .LP -\fBExample 3 \fRPrinting Fields in Opposite Order with the Input Fields -Separated +\fBExample 6 \fRWrite any line in which the second field contains a backslash: .sp +.in +2 +.nf +\fB$2 ~ /\e\e/\fR +.fi +.in -2 +.sp + .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints the first two input fields in -opposite order, separated by a comma, blanks or tabs: +\fBExample 7 \fRWrite any line in which the second field contains a backslash +(alternate method): +.sp +.LP +Notice that backslash escapes are interpreted twice, once in lexical processing +of the string and once in processing the regular expression. .sp .in +2 .nf -\fBBEGIN { FS = ",[ \et]*|[ \et]+" } - { print $2, $1 }\fR +\fB$2 ~ "\e\e\e\e"\fR .fi .in -2 .sp .LP -\fBExample 4 \fRAdding Up the First Column, Printing the Sum and Average +\fBExample 8 \fRWrite the second to the last and the last field in each line, +separating the fields by a colon: +.sp +.in +2 +.nf +\fB{OFS=":";print $(NF-1), $NF}\fR +.fi +.in -2 +.sp + +.LP +\fBExample 9 \fRWrite the line number and number of fields in each line: .sp .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It adds up the first column, and prints the -sum and average: +The three strings representing the line number, the colon and the number of +fields are concatenated and that string is written to standard output. .sp .in +2 .nf -\fB{ s += $1 } -END { print "sum is", s, " average is", s/NR }\fR +\fB{print NR ":" NF}\fR .fi .in -2 .sp .LP -\fBExample 5 \fRPrinting Fields in Reverse Order +\fBExample 10 \fRWrite lines longer than 72 characters: .sp +.in +2 +.nf +\fB{length($0) > 72}\fR +.fi +.in -2 +.sp + .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints fields in reverse order: +\fBExample 11 \fRWrite first two fields in opposite order separated by the OFS: +.sp +.in +2 +.nf +\fB{ print $2, $1 }\fR +.fi +.in -2 +.sp +.LP +\fBExample 12 \fRSame, with input fields separated by comma or space and tab +characters, or both: .sp .in +2 .nf -\fB{ for (i = NF; i > 0; \(mi\(mii) print $i }\fR +\fBBEGIN { FS = ",[\et]*|[\et]+" } + { print $2, $1 }\fR .fi .in -2 .sp .LP -\fBExample 6 \fRPrinting All lines Between \fBstart/stop\fR Pairs +\fBExample 13 \fRAdd up first column, print sum and average: .sp +.in +2 +.nf +\fB{s += $1 } +END {print "sum is ", s, " average is", s/NR}\fR +.fi +.in -2 +.sp + .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints all lines between start/stop -pairs. +\fBExample 14 \fRWrite fields in reverse order, one per line (many lines out +for each line in): +.sp +.in +2 +.nf +\fB{ for (i = NF; i > 0; --i) print $i }\fR +.fi +.in -2 +.sp +.LP +\fBExample 15 \fRWrite all lines between occurrences of the strings "start" and +"stop": .sp .in +2 .nf @@ -547,61 +1696,89 @@ pairs. .sp .LP -\fBExample 7 \fRPrinting All Lines Whose First Field is Different from the -Previous One +\fBExample 16 \fRWrite all lines whose first field is different from the +previous one: .sp +.in +2 +.nf +\fB$1 != prev { print; prev = $1 }\fR +.fi +.in -2 +.sp + .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints all lines whose first field is -different from the previous one. +\fBExample 17 \fRSimulate the echo command: +.sp +.in +2 +.nf +\fBBEGIN { + for (i = 1; i < ARGC; ++i) + printf "%s%s", ARGV[i], i==ARGC-1?"\en":"" + }\fR +.fi +.in -2 +.sp +.LP +\fBExample 18 \fRWrite the path prefixes contained in the PATH environment +variable, one per line: .sp .in +2 .nf -\fB$1 != prev { print; prev = $1 }\fR +\fBBEGIN { + n = split (ENVIRON["PATH"], path, ":") + for (i = 1; i <= n; ++i) + print path[i] + }\fR .fi .in -2 .sp .LP -\fBExample 8 \fRPrinting a File and Filling in Page numbers +\fBExample 19 \fRPrint the file "input", filling in page numbers starting at 5: .sp .LP -The following example is an \fBawk\fR script that can be executed by an \fBawk --f examplescript\fR style command. It prints a file and fills in page numbers -starting at 5: +If there is a file named \fBinput\fR containing page headers of the form .sp .in +2 .nf -\fB/Page/ { $2 = n++; } - { print }\fR +Page# .fi .in -2 -.sp +.sp .LP -\fBExample 9 \fRPrinting a File and Numbering Its Pages +and a file named \fBprogram\fR that contains + +.sp +.in +2 +.nf +/Page/{ $2 = n++; } +{ print } +.fi +.in -2 + .sp .LP -Assuming this program is in a file named \fBprog\fR, the following example -prints the file \fBinput\fR numbering its pages starting at \fB5\fR: +then the command line .sp .in +2 .nf -example% \fBawk -f prog n=5 input\fR +\fBawk -f program n=5 input\fR .fi .in -2 .sp -.SH ENVIRONMENT VARIABLES .sp .LP +prints the file \fBinput\fR, filling in page numbers starting at 5. + +.SH ENVIRONMENT VARIABLES See \fBenviron\fR(5) for descriptions of the following environment variables -that affect the execution of \fBawk\fR: \fBLANG\fR, \fBLC_ALL\fR, -\fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, \fBNLSPATH\fR, and -\fBPATH\fR. +that affect execution: \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and +\fBNLSPATH\fR. .sp .ne 2 .na @@ -615,49 +1792,55 @@ POSIX locale) is the decimal-point character recognized in processing \fBawk\fR programs (including assignments in command-line arguments). .RE -.SH ATTRIBUTES +.SH EXIT STATUS +The following exit values are returned: .sp -.LP -See \fBattributes\fR(5) for descriptions of the following attributes: -.SS "/usr/bin/awk" -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -CSI Not Enabled -.TE +.ne 2 +.na +\fB\fB0\fR\fR +.ad +.RS 6n +All input files were processed successfully. +.RE -.SS "/usr/xpg4/bin/awk" .sp +.ne 2 +.na +\fB\fB>0\fR\fR +.ad +.RS 6n +An error occurred. +.RE .sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -CSI Enabled -_ -Interface Stability Standard -.TE +.LP +The exit status can be altered within the program by using an \fBexit\fR +expression. .SH SEE ALSO +\fBed\fR(1), \fBegrep\fR(1), \fBgrep\fR(1), \fBlex\fR(1), \fBoawk\fR(1), +\fBsed\fR(1), \fBpopen\fR(3C), \fBprintf\fR(3C), \fBsystem\fR(3C), +\fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBregex\fR(5), +\fBXPG4\fR(5) .sp .LP -\fBegrep\fR(1), \fBgrep\fR(1), \fBnawk\fR(1), \fBsed\fR(1), \fBprintf\fR(3C), -\fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5) -.SH NOTES +Aho, A. V., B. W. Kernighan, and P. J. Weinberger, \fIThe AWK Programming +Language\fR, Addison-Wesley, 1988. + +.SH DIAGNOSTICS +If any \fIfile\fR operand is specified and the named file cannot be accessed, +\fBawk\fR writes a diagnostic message to standard error and terminate without +any further action. .sp .LP +If the program specified by either the \fIprogram\fR operand or a +\fIprogfile\fR operand is not a valid \fBawk\fR program (as specified in +\fBEXTENDED DESCRIPTION\fR), the behavior is undefined. + +.SH NOTES Input white space is not preserved on output if fields are involved. .sp .LP There are no explicit conversions between numbers and strings. To force an -expression to be treated as a number, add \fB0\fR to it. To force an expression -to be treated as a string, concatenate the null string (\fB""\fR) to it. +expression to be treated as a number add 0 to it; to force it to be treated as +a string concatenate the null string (\fB""\fR) to it. diff --git a/usr/src/man/man1/nawk.1 b/usr/src/man/man1/nawk.1 deleted file mode 100644 index 5fec573a52..0000000000 --- a/usr/src/man/man1/nawk.1 +++ /dev/null @@ -1,1874 +0,0 @@ -.\" -.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for -.\" permission to reproduce portions of its copyrighted documentation. -.\" Original documentation from The Open Group can be obtained online at -.\" http://www.opengroup.org/bookstore/. -.\" -.\" The Institute of Electrical and Electronics Engineers and The Open -.\" Group, have given us permission to reprint portions of their -.\" documentation. -.\" -.\" In the following statement, the phrase ``this text'' refers to portions -.\" of the system documentation. -.\" -.\" Portions of this text are reprinted and reproduced in electronic form -.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, -.\" Standard for Information Technology -- Portable Operating System -.\" Interface (POSIX), The Open Group Base Specifications Issue 6, -.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics -.\" Engineers, Inc and The Open Group. In the event of any discrepancy -.\" between these versions and the original IEEE and The Open Group -.\" Standard, the original IEEE and The Open Group Standard is the referee -.\" document. The original Standard can be obtained online at -.\" http://www.opengroup.org/unix/online.html. -.\" -.\" This notice shall appear on any product containing this material. -.\" -.\" The contents of this file are subject to the terms of the -.\" Common Development and Distribution License (the "License"). -.\" You may not use this file except in compliance with the License. -.\" -.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -.\" or http://www.opensolaris.org/os/licensing. -.\" See the License for the specific language governing permissions -.\" and limitations under the License. -.\" -.\" When distributing Covered Code, include this CDDL HEADER in each -.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. -.\" If applicable, add the following below this CDDL HEADER, with the -.\" fields enclosed by brackets "[]" replaced with your own identifying -.\" information: Portions Copyright [yyyy] [name of copyright owner] -.\" -.\" -.\" Copyright 1989 AT&T -.\" Copyright 1992, X/Open Company Limited All Rights Reserved -.\" Portions Copyright (c) 2005, 2006 Sun Microsystems, Inc. All Rights Reserved -.\" Copyright 2018, Joyent, Inc. -.\" -.TH NAWK 1 "Nov 9, 2018" -.SH NAME -nawk \- pattern scanning and processing language -.SH SYNOPSIS -.LP -.nf -\fB/usr/bin/awk\fR [\fB-F\fR \fIERE\fR] [\fB-v\fR \fIassignment\fR] \fI\&'program'\fR | \fB-f\fR \fIprogfile\fR... - [\fIargument\fR]... -.fi - -.LP -.nf -\fB/usr/bin/nawk\fR [\fB-F\fR \fIERE\fR] [\fB-v\fR \fIassignment\fR] \fI\&'program'\fR | \fB-f\fR \fIprogfile\fR... - [\fIargument\fR]... -.fi - -.LP -.nf -\fB/usr/xpg4/bin/awk\fR [\fB-F\fR \fIERE\fR] [\fB-v\fR \fIassignment\fR]... \fI\&'program'\fR | \fB-f\fR \fIprogfile\fR... - [\fIargument\fR]... -.fi - -.SH DESCRIPTION -.LP -The \fB/usr/bin/awk\fR, \fB/usr/bin/nawk\fR and \fB/usr/xpg4/bin/awk\fR -utilities execute -\fIprogram\fRs written in the \fBnawk\fR programming language, which is -specialized for textual data manipulation. A \fBnawk\fR \fIprogram\fR is a -sequence of patterns and corresponding actions. The string specifying -\fIprogram\fR must be enclosed in single quotes (') to protect it from -interpretation by the shell. The sequence of pattern - action statements can be -specified in the command line as \fIprogram\fR or in one, or more, file(s) -specified by the \fB-f\fR\fIprogfile\fR option. When input is read that matches -a pattern, the action associated with the pattern is performed. -.sp -.LP -Input is interpreted as a sequence of records. By default, a record is a line, -but this can be changed by using the \fBRS\fR built-in variable. Each record of -input is matched to each pattern in the \fIprogram\fR. For each pattern -matched, the associated action is executed. -.sp -.LP -The \fBnawk\fR utility interprets each input record as a sequence of fields -where, by default, a field is a string of non-blank characters. This default -white-space field delimiter (blanks and/or tabs) can be changed by using the -\fBFS\fR built-in variable or the \fB-F\fR\fIERE\fR option. The \fBnawk\fR -utility denotes the first field in a record \fB$1\fR, the second \fB$2\fR, and -so forth. The symbol \fB$0\fR refers to the entire record; setting any other -field causes the reevaluation of \fB$0\fR. Assigning to \fB$0\fR resets the -values of all fields and the \fBNF\fR built-in variable. - -.SH OPTIONS -.LP -The following options are supported: -.sp -.ne 2 -.na -\fB\fB-F\fR \fIERE\fR\fR -.ad -.RS 17n -Define the input field separator to be the extended regular expression -\fIERE\fR, before any input is read (can be a character). -.RE - -.sp -.ne 2 -.na -\fB\fB-f\fR \fIprogfile\fR\fR -.ad -.RS 17n -Specifies the pathname of the file \fIprogfile\fR containing a \fBnawk\fR -program. If multiple instances of this option are specified, the concatenation -of the files specified as \fIprogfile\fR in the order specified is the -\fBnawk\fR program. The \fBnawk\fR program can alternatively be specified in -the command line as a single argument. -.RE - -.sp -.ne 2 -.na -\fB\fB-v\fR \fIassignment\fR\fR -.ad -.RS 17n -The \fIassignment\fR argument must be in the same form as an \fIassignment\fR -operand. The assignment is of the form \fIvar=value\fR, where \fIvar\fR is the -name of one of the variables described below. The specified assignment occurs -before executing the \fBnawk\fR program, including the actions associated with -\fBBEGIN\fR patterns (if any). Multiple occurrences of this option can be -specified. -.RE - -.sp -.ne 2 -.na -\fB\fB-safe\fR\fR -.ad -.RS 17n -When passed to \fBnawk\fR, this flag will prevent the program from opening new -files or running child processes. The \fBENVIRON\fR array will also not be -initialized. -.RE - -.SH OPERANDS -.LP -The following operands are supported: -.sp -.ne 2 -.na -\fB\fIprogram\fR\fR -.ad -.RS 12n -If no \fB-f\fR option is specified, the first operand to \fBnawk\fR is the text -of the \fBnawk\fR program. The application supplies the \fIprogram\fR operand -as a single argument to \fBnawk.\fR If the text does not end in a newline -character, \fBnawk\fR interprets the text as if it did. -.RE - -.sp -.ne 2 -.na -\fB\fIargument\fR\fR -.ad -.RS 12n -Either of the following two types of \fIargument\fR can be intermixed: -.sp -.ne 2 -.na -\fB\fIfile\fR\fR -.ad -.RS 14n -A pathname of a file that contains the input to be read, which is matched -against the set of patterns in the program. If no \fIfile\fR operands are -specified, or if a \fIfile\fR operand is \fB\(mi\fR, the standard input is -used. -.RE - -.sp -.ne 2 -.na -\fB\fIassignment\fR\fR -.ad -.RS 14n -An operand that begins with an underscore or alphabetic character from the -portable character set, followed by a sequence of underscores, digits and -alphabetics from the portable character set, followed by the \fB=\fR character -specifies a variable assignment rather than a pathname. The characters before -the \fB=\fR represent the name of a \fBnawk\fR variable. If that name is a -\fBnawk\fR reserved word, the behavior is undefined. The characters following -the equal sign is interpreted as if they appeared in the \fBnawk\fR program -preceded and followed by a double-quote (\fB"\fR) character, as a \fBSTRING\fR -token , except that if the last character is an unescaped backslash, it is -interpreted as a literal backslash rather than as the first character of the -sequence \fB\e\fR\&.. The variable is assigned the value of that \fBSTRING\fR -token. If the value is considered a \fInumeric\fRstring\fI,\fR the variable is -assigned its numeric value. Each such variable assignment is performed just -before the processing of the following \fIfile\fR, if any. Thus, an assignment -before the first \fBfile\fR argument is executed after the \fBBEGIN\fR actions -(if any), while an assignment after the last \fIfile\fR argument is executed -before the \fBEND\fR actions (if any). If there are no \fIfile\fR arguments, -assignments are executed before processing the standard input. -.RE - -.RE - -.SH INPUT FILES -.LP -Input files to the \fBnawk\fR program from any of the following sources: -.RS +4 -.TP -.ie t \(bu -.el o -any \fIfile\fR operands or their equivalents, achieved by modifying the -\fBnawk\fR variables \fBARGV\fR and \fBARGC\fR -.RE -.RS +4 -.TP -.ie t \(bu -.el o -standard input in the absence of any \fIfile\fR operands -.RE -.RS +4 -.TP -.ie t \(bu -.el o -arguments to the \fBgetline\fR function -.RE -.sp -.LP -must be text files. Whether the variable \fBRS\fR is set to a value other than -a newline character or not, for these files, implementations support records -terminated with the specified separator up to \fB{LINE_MAX}\fR bytes and can -support longer records. -.sp -.LP -If \fB-\fR\fBf\fR \fIprogfile\fR is specified, the files named by each of the -\fIprogfile\fR option-arguments must be text files containing an \fBnawk\fR -program. -.sp -.LP -The standard input are used only if no \fIfile\fR operands are specified, or if -a \fIfile\fR operand is \fB\(mi\fR\&. - -.SH EXTENDED DESCRIPTION -.LP -A \fBnawk\fR program is composed of pairs of the form: -.sp -.in +2 -.nf -pattern { \fIaction\fR } -.fi -.in -2 - -.sp -.LP -Either the pattern or the action (including the enclosing brace characters) can -be omitted. Pattern-action statements are separated by a semicolon or by a -newline. -.sp -.LP -A missing pattern matches any record of input, and a missing action is -equivalent to an action that writes the matched record of input to standard -output. -.sp -.LP -Execution of the \fBnawk\fR program starts by first executing the actions -associated with all \fBBEGIN\fR patterns in the order they occur in the -program. Then each \fIfile\fR operand (or standard input if no files were -specified) is processed by reading data from the file until a record separator -is seen (a newline character by default), splitting the current record into -fields using the current value of \fBFS\fR, evaluating each pattern in the -program in the order of occurrence, and executing the action associated with -each pattern that matches the current record. The action for a matching pattern -is executed before evaluating subsequent patterns. Last, the actions associated -with all \fBEND\fR patterns is executed in the order they occur in the program. - -.SS "Expressions in nawk" -.LP -Expressions describe computations used in \fIpatterns\fR and \fIactions\fR. In -the following table, valid expression operations are given in groups from -highest precedence first to lowest precedence last, with equal-precedence -operators grouped between horizontal lines. In expression evaluation, where the -grammar is formally ambiguous, higher precedence operators are evaluated before -lower precedence operators. In this table \fIexpr,\fR \fIexpr1,\fR -\fIexpr2,\fR and \fIexpr3\fR represent any expression, while \fIlvalue\fR -represents any entity that can be assigned to (that is, on the left side of an -assignment operator). -.sp - -.sp -.TS -c c c c -l l l l . -\fBSyntax\fR \fBName\fR \fBType of Result\fR \fBAssociativity\fR -_ -( \fIexpr\fR ) Grouping type of \fIexpr\fR n/a -_ -$\fIexpr\fR Field reference string n/a -_ -++ \fIlvalue\fR Pre-increment numeric n/a -\(mi\(mi \fIlvalue\fR Pre-decrement numeric n/a -\fIlvalue\fR ++ Post-increment numeric n/a -\fIlvalue\fR \(mi\(mi Post-decrement numeric n/a -_ -\fIexpr\fR ^ \fIexpr\fR Exponentiation numeric right -_ -! \fIexpr\fR Logical not numeric n/a -+ \fIexpr\fR Unary plus numeric n/a -\(mi \fIexpr\fR Unary minus numeric n/a -_ -\fIexpr\fR * \fIexpr\fR Multiplication numeric left -\fIexpr\fR / \fIexpr\fR Division numeric left -\fIexpr\fR % \fIexpr\fR Modulus numeric left -_ -\fIexpr\fR + \fIexpr\fR Addition numeric left -\fIexpr\fR \(mi \fIexpr\fR Subtraction numeric left -_ -\fIexpr\fR \fIexpr\fR String concatenation string left -_ -\fIexpr\fR < \fIexpr\fR Less than numeric none -\fIexpr\fR <= \fIexpr\fR Less than or equal to numeric none -\fIexpr\fR != \fIexpr\fR Not equal to numeric none -\fIexpr\fR == \fIexpr\fR Equal to numeric none -\fIexpr\fR > \fIexpr\fR Greater than numeric none -\fIexpr\fR >= \fIexpr\fR Greater than or equal to numeric none -_ -\fIexpr\fR ~ \fIexpr\fR ERE match numeric none -\fIexpr\fR !~ \fIexpr\fR ERE non-match numeric none -_ -\fIexpr\fR in array Array membership numeric left -( \fIindex\fR ) in Multi-dimension array numeric left - \fIarray\fR membership -_ -\fBexpr\fR && \fIexpr\fR Logical AND numeric left -_ -\fBexpr\fR |\|| \fIexpr\fR Logical OR numeric left -_ -\fIexpr1\fR ? \fIexpr2\fR Conditional expression type of selected right - : \fIexpr3\fR \fIexpr2\fR or \fIexpr3\fR -_ -\fIlvalue\fR ^= \fIexpr\fR Exponentiation numeric right - assignment -\fIlvalue\fR %= \fIexpr\fR Modulus assignment numeric right -\fIlvalue\fR *= \fIexpr\fR Multiplication numeric right - assignment -\fIlvalue\fR /= \fIexpr\fR Division assignment numeric right -\fIlvalue\fR += \fIexpr\fR Addition assignment numeric right -\fIlvalue\fR \(mi= \fIexpr\fR Subtraction assignment numeric right -\fIlvalue\fR = \fIexpr\fR Assignment type of \fIexpr\fR right -.TE - -.sp -.LP -Each expression has either a string value, a numeric value or both. Except as -stated for specific contexts, the value of an expression is implicitly -converted to the type needed for the context in which it is used. A string -value is converted to a numeric value by the equivalent of the following calls: -.sp -.in +2 -.nf -setlocale(LC_NUMERIC, ""); -\fInumeric_value\fR = atof(\fIstring_value\fR); -.fi -.in -2 - -.sp -.LP -A numeric value that is exactly equal to the value of an integer is converted -to a string by the equivalent of a call to the \fBsprintf\fR function with the -string \fB%d\fR as the \fBfmt\fR argument and the numeric value being converted -as the first and only \fIexpr\fR argument. Any other numeric value is -converted to a string by the equivalent of a call to the \fBsprintf\fR function -with the value of the variable \fBCONVFMT\fR as the \fBfmt\fR argument and the -numeric value being converted as the first and only \fIexpr\fR argument. -.sp -.LP -A string value is considered to be a \fInumeric string\fR in the following -case: -.RS +4 -.TP -1. -Any leading and trailing blank characters is ignored. -.RE -.RS +4 -.TP -2. -If the first unignored character is a \fB+\fR or \fB\(mi\fR, it is ignored. -.RE -.RS +4 -.TP -3. -If the remaining unignored characters would be lexically recognized as a -\fBNUMBER\fR token, the string is considered a \fInumeric string\fR. -.RE -.sp -.LP -If a \fB\(mi\fR character is ignored in the above steps, the numeric value of -the \fInumeric string\fR is the negation of the numeric value of the recognized -\fBNUMBER\fR token. Otherwise the numeric value of the \fInumeric string\fR is -the numeric value of the recognized \fBNUMBER\fR token. Whether or not a string -is a \fInumeric string\fR is relevant only in contexts where that term is used -in this section. -.sp -.LP -When an expression is used in a Boolean context, if it has a numeric value, a -value of zero is treated as false and any other value is treated as true. -Otherwise, a string value of the null string is treated as false and any other -value is treated as true. A Boolean context is one of the following: -.RS +4 -.TP -.ie t \(bu -.el o -the first subexpression of a conditional expression. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -an expression operated on by logical NOT, logical \fBAND,\fR or logical OR. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -the second expression of a \fBfor\fR statement. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -the expression of an \fBif\fR statement. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -the expression of the \fBwhile\fR clause in either a \fBwhile\fR or \fBdo\fR -\fB\&.\|.\|.\fR \fBwhile\fR statement. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -an expression used as a pattern (as in Overall Program Structure). -.RE -.sp -.LP -The \fBnawk\fR language supplies arrays that are used for storing numbers or -strings. Arrays need not be declared. They are initially empty, and their sizes -changes dynamically. The subscripts, or element identifiers, are strings, -providing a type of associative array capability. An array name followed by a -subscript within square brackets can be used as an \fIlvalue\fR and as an -expression, as described in the grammar. Unsubscripted array names are used in -only the following contexts: -.RS +4 -.TP -.ie t \(bu -.el o -a parameter in a function definition or function call. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -the \fBNAME\fR token following any use of the keyword \fBin\fR. -.RE -.sp -.LP -A valid array \fIindex\fR consists of one or more comma-separated expressions, -similar to the way in which multi-dimensional arrays are indexed in some -programming languages. Because \fBnawk\fR arrays are really one-dimensional, -such a comma-separated list is converted to a single string by concatenating -the string values of the separate expressions, each separated from the other by -the value of the \fBSUBSEP\fR variable. -.sp -.LP -Thus, the following two index operations are equivalent: -.sp -.in +2 -.nf -var[expr1, expr2, ... exprn] -var[expr1 SUBSEP expr2 SUBSEP ... SUBSEP exprn] -.fi -.in -2 - -.sp -.LP -A multi-dimensioned \fIindex\fR used with the \fBin\fR operator must be put in -parentheses. The \fBin\fR operator, which tests for the existence of a -particular array element, does not create the element if it does not exist. -Any other reference to a non-existent array element automatically creates it. - -.SS "Variables and Special Variables" -.LP -Variables can be used in an \fBnawk\fR program by referencing them. With the -exception of function parameters, they are not explicitly declared. -Uninitialized scalar variables and array elements have both a numeric value of -zero and a string value of the empty string. -.sp -.LP -Field variables are designated by a \fB$\fR followed by a number or numerical -expression. The effect of the field number \fIexpression\fR evaluating to -anything other than a non-negative integer is unspecified. Uninitialized -variables or string values need not be converted to numeric values in this -context. New field variables are created by assigning a value to them. -References to non-existent fields (that is, fields after \fB$NF\fR) produce the -null string. However, assigning to a non-existent field (for example, -\fB$(NF+2) = 5\fR) increases the value of \fBNF\fR, create any intervening -fields with the null string as their values and cause the value of \fB$0\fR to -be recomputed, with the fields being separated by the value of \fBOFS\fR. Each -field variable has a string value when created. If the string, with any -occurrence of the decimal-point character from the current locale changed to a -period character, is considered a \fInumeric string\fR (see \fBExpressions in -nawk\fR above), the field variable also has the numeric value of the \fInumeric -string\fR. - -.SS "/usr/bin/nawk, /usr/xpg4/bin/awk" -.LP -\fBnawk\fR sets the following special variables that are supported by both -\fB/usr/bin/nawk\fR and \fB/usr/xpg4/bin/awk\fR: -.sp -.ne 2 -.na -\fB\fBARGC\fR\fR -.ad -.RS 12n -The number of elements in the \fBARGV\fR array. -.RE - -.sp -.ne 2 -.na -\fB\fBARGV\fR\fR -.ad -.RS 12n -An array of command line arguments, excluding options and the \fIprogram\fR -argument, numbered from zero to \fBARGC\fR\(mi1. -.sp -The arguments in \fBARGV\fR can be modified or added to; \fBARGC\fR can be -altered. As each input file ends, \fBnawk\fR treats the next non-null element -of \fBARGV\fR, up to the current value of \fBARGC\fR\(mi1, inclusive, as the -name of the next input file. Setting an element of \fBARGV\fR to null means -that it is not treated as an input file. The name \fB\(mi\fR indicates the -standard input. If an argument matches the format of an \fIassignment\fR -operand, this argument is treated as an assignment rather than a \fIfile\fR -argument. -.RE - -.sp -.ne 2 -.na -\fB\fBCONVFMT\fR\fR -.ad -.RS 12n -The \fBprintf\fR format for converting numbers to strings (except for output -statements, where \fBOFMT\fR is used). The default is \fB%.6g\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBENVIRON\fR\fR -.ad -.RS 12n -The variable \fBENVIRON\fR is an array representing the value of the -environment. The indices of the array are strings consisting of the names of -the environment variables, and the value of each array element is a string -consisting of the value of that variable. If the value of an environment -variable is considered a \fInumeric string\fR, the array element also has its -numeric value. -.sp -In all cases where \fBnawk\fR behavior is affected by environment variables -(including the environment of any commands that \fBnawk\fR executes via the -\fBsystem\fR function or via pipeline redirections with the \fBprint\fR -statement, the \fBprintf\fR statement, or the \fBgetline\fR function), the -environment used is the environment at the time \fBnawk\fR began executing. -.RE - -.sp -.ne 2 -.na -\fB\fBFILENAME\fR\fR -.ad -.RS 12n -A pathname of the current input file. Inside a \fBBEGIN\fR action the value is -undefined. Inside an \fBEND\fR action the value is the name of the last input -file processed. -.RE - -.sp -.ne 2 -.na -\fB\fBFNR\fR\fR -.ad -.RS 12n -The ordinal number of the current record in the current file. Inside a -\fBBEGIN\fR action the value is zero. Inside an \fBEND\fR action the value is -the number of the last record processed in the last file processed. -.RE - -.sp -.ne 2 -.na -\fB\fBFS\fR\fR -.ad -.RS 12n -Input field separator regular expression; a space character by default. -.RE - -.sp -.ne 2 -.na -\fB\fBNF\fR\fR -.ad -.RS 12n -The number of fields in the current record. Inside a \fBBEGIN\fR action, the -use of \fBNF\fR is undefined unless a \fBgetline\fR function without a -\fIvar\fR argument is executed previously. Inside an \fBEND\fR action, \fBNF\fR -retains the value it had for the last record read, unless a subsequent, -redirected, \fBgetline\fR function without a \fIvar\fR argument is performed -prior to entering the \fBEND\fR action. -.RE - -.sp -.ne 2 -.na -\fB\fBNR\fR\fR -.ad -.RS 12n -The ordinal number of the current record from the start of input. Inside a -\fBBEGIN\fR action the value is zero. Inside an \fBEND\fR action the value is -the number of the last record processed. -.RE - -.sp -.ne 2 -.na -\fB\fBOFMT\fR\fR -.ad -.RS 12n -The \fBprintf\fR format for converting numbers to strings in output statements -\fB"%.6g"\fR by default. The result of the conversion is unspecified if the -value of \fBOFMT\fR is not a floating-point format specification. -.RE - -.sp -.ne 2 -.na -\fB\fBOFS\fR\fR -.ad -.RS 12n -The \fBprint\fR statement output field separator; a space character by default. -.RE - -.sp -.ne 2 -.na -\fB\fBORS\fR\fR -.ad -.RS 12n -The \fBprint\fR output record separator; a newline character by default. -.RE - -.sp -.ne 2 -.na -\fB\fBRLENGTH\fR\fR -.ad -.RS 12n -The length of the string matched by the \fBmatch\fR function. -.RE - -.sp -.ne 2 -.na -\fB\fBRS\fR\fR -.ad -.RS 12n -The first character of the string value of \fBRS\fR is the input record -separator; a newline character by default. If \fBRS\fR contains more than one -character, the results are unspecified. If \fBRS\fR is null, then records are -separated by sequences of one or more blank lines. Leading or trailing blank -lines do not produce empty records at the beginning or end of input, and the -field separator is always newline, no matter what the value of \fBFS\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBRSTART\fR\fR -.ad -.RS 12n -The starting position of the string matched by the \fBmatch\fR function, -numbering from 1. This is always equivalent to the return value of the -\fBmatch\fR function. -.RE - -.sp -.ne 2 -.na -\fB\fBSUBSEP\fR\fR -.ad -.RS 12n -The subscript separator string for multi-dimensional arrays. The default value -is \fB\e034\fR\&. -.RE - -.SS "/usr/bin/nawk" -.LP -The following variable is supported for \fB/usr/bin/nawk\fR only: -.sp -.ne 2 -.na -\fB\fBRT\fR\fR -.ad -.RS 12n -The record terminator for the most recent record read. For most records this -will be the same value as \fBRS\fR. At the end of a file with no trailing -separator value, though, this will be set to the empty string (\fB""\fR). -.RE - -.SS "Regular Expressions" -.LP -The \fBnawk\fR utility makes use of the extended regular expression notation -(see \fBregex\fR(5)) except that it allows the use of C-language conventions to -escape special characters within the EREs, namely \fB\e\e\fR, \fB\ea\fR, -\fB\eb\fR, \fB\ef\fR, \fB\en\fR, \fB\er\fR, \fB\et\fR, \fB\ev\fR, and those -specified in the following table. These escape sequences are recognized both -inside and outside bracket expressions. Note that records need not be -separated by newline characters and string constants can contain newline -characters, so even the \fB\en\fR sequence is valid in \fBnawk\fR EREs. Using -a slash character within the regular expression requires escaping as shown in -the table below: -.sp - -.sp -.TS -l l l -l l l . -\fBEscape Sequence\fR \fBDescription\fR \fBMeaning\fR -_ -\fB\e"\fR Backslash quotation-mark Quotation-mark character -_ -\fB\e/\fR Backslash slash Slash character -_ -\fB\e\fR\fIddd\fR T{ -A backslash character followed by the longest sequence of one, two, or three octal-digit characters (01234567). If all of the digits are 0, (that is, representation of the NULL character), the behavior is undefined. -T} T{ -The character encoded by the one-, two- or three-digit octal integer. Multi-byte characters require multiple, concatenated escape sequences, including the leading \e for each byte. -T} -_ -\fB\e\fR\fIc\fR T{ -A backslash character followed by any character not described in this table or special characters (\fB\e\e\fR, \fB\ea\fR, \fB\eb\fR, \fB\ef\fR, \fB\en\fR, \fB\er\fR, \fB\et\fR, \fB\ev\fR). -T} Undefined -.TE - -.sp -.LP -A regular expression can be matched against a specific field or string by using -one of the two regular expression matching operators, \fB~\fR and \fB!\|~\fR. -These operators interpret their right-hand operand as a regular expression and -their left-hand operand as a string. If the regular expression matches the -string, the \fB~\fR expression evaluates to the value \fB1\fR, and the -\fB!\|~\fR expression evaluates to the value \fB0\fR. If the regular expression -does not match the string, the \fB~\fR expression evaluates to the value -\fB0\fR, and the \fB!\|~\fR expression evaluates to the value \fB1\fR. If the -right-hand operand is any expression other than the lexical token \fBERE\fR, -the string value of the expression is interpreted as an extended regular -expression, including the escape conventions described above. Notice that these -same escape conventions also are applied in the determining the value of a -string literal (the lexical token \fBSTRING\fR), and is applied a second time -when a string literal is used in this context. -.sp -.LP -When an \fBERE\fR token appears as an expression in any context other than as -the right-hand of the \fB~\fR or \fB!\|~\fR operator or as one of the built-in -function arguments described below, the value of the resulting expression is -the equivalent of: -.sp -.in +2 -.nf -$0 ~ /\fIere\fR/ -.fi -.in -2 - -.sp -.LP -The \fIere\fR argument to the \fBgsub,\fR \fBmatch,\fR \fBsub\fR functions, and -the \fIfs\fR argument to the \fBsplit\fR function (see \fBString Functions\fR) -is interpreted as extended regular expressions. These can be either \fBERE\fR -tokens or arbitrary expressions, and are interpreted in the same manner as the -right-hand side of the \fB~\fR or \fB!\|~\fR operator. -.sp -.LP -An extended regular expression can be used to separate fields by using the -\fB-F\fR \fIERE\fR option or by assigning a string containing the expression to -the built-in variable \fBFS\fR. The default value of the \fBFS\fR variable is a -single space character. The following describes \fBFS\fR behavior: -.RS +4 -.TP -1. -If \fBFS\fR is a single character: -.RS +4 -.TP -.ie t \(bu -.el o -If \fBFS\fR is the space character, skip leading and trailing blank characters; -fields are delimited by sets of one or more blank characters. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -Otherwise, if \fBFS\fR is any other character \fIc\fR, fields are delimited by -each single occurrence of \fIc\fR. -.RE -.RE -.RS +4 -.TP -2. -Otherwise, the string value of \fBFS\fR is considered to be an extended -regular expression. Each occurrence of a sequence matching the extended regular -expression delimits fields. -.RE -.sp -.LP -Except in the \fBgsub\fR, \fBmatch\fR, \fBsplit\fR, and \fBsub\fR built-in -functions, regular expression matching is based on input records. That is, -record separator characters (the first character of the value of the variable -\fBRS\fR, a newline character by default) cannot be embedded in the expression, -and no expression matches the record separator character. If the record -separator is not a newline character, newline characters embedded in the -expression can be matched. In those four built-in functions, regular expression -matching are based on text strings. So, any character (including the newline -character and the record separator) can be embedded in the pattern and an -appropriate pattern matches any character. However, in all \fBnawk\fR regular -expression matching, the use of one or more NULL characters in the pattern, -input record or text string produces undefined results. - -.SS "Patterns" -.LP -A \fIpattern\fR is any valid \fIexpression,\fR a range specified by two -expressions separated by comma, or one of the two special patterns \fBBEGIN\fR -or \fBEND\fR. - -.SS "Special Patterns" -.LP -The \fBnawk\fR utility recognizes two special patterns, \fBBEGIN\fR and -\fBEND\fR. Each \fBBEGIN\fR pattern is matched once and its associated action -executed before the first record of input is read (except possibly by use of -the \fBgetline\fR function in a prior \fBBEGIN\fR action) and before command -line assignment is done. Each \fBEND\fR pattern is matched once and its -associated action executed after the last record of input has been read. These -two patterns have associated actions. -.sp -.LP -\fBBEGIN\fR and \fBEND\fR do not combine with other patterns. Multiple -\fBBEGIN\fR and \fBEND\fR patterns are allowed. The actions associated with the -\fBBEGIN\fR patterns are executed in the order specified in the program, as are -the \fBEND\fR actions. An \fBEND\fR pattern can precede a \fBBEGIN\fR pattern -in a program. -.sp -.LP -If an \fBnawk\fR program consists of only actions with the pattern \fBBEGIN\fR, -and the \fBBEGIN\fR action contains no \fBgetline\fR function, \fBnawk\fR exits -without reading its input when the last statement in the last \fBBEGIN\fR -action is executed. If an \fBnawk\fR program consists of only actions with the -pattern \fBEND\fR or only actions with the patterns \fBBEGIN\fR and \fBEND\fR, -the input is read before the statements in the \fBEND\fR actions are executed. - -.SS "Expression Patterns" -.LP -An expression pattern is evaluated as if it were an expression in a Boolean -context. If the result is true, the pattern is considered to match, and the -associated action (if any) is executed. If the result is false, the action is -not executed. - -.SS "Pattern Ranges" -.LP -A pattern range consists of two expressions separated by a comma. In this case, -the action is performed for all records between a match of the first expression -and the following match of the second expression, inclusive. At this point, the -pattern range can be repeated starting at input records subsequent to the end -of the matched range. - -.SS "Actions" -.LP -An action is a sequence of statements. A statement can be one of the following: -.sp -.in +2 -.nf -if ( \fIexpression\fR ) \fIstatement\fR [ else \fIstatement\fR ] -while ( \fIexpression\fR ) \fIstatement\fR -do \fIstatement\fR while ( \fIexpression\fR ) -for ( \fIexpression\fR ; \fIexpression\fR ; \fIexpression\fR ) \fIstatement\fR -for ( \fIvar\fR in \fIarray\fR ) \fIstatement\fR -delete \fIarray\fR[\fIsubscript\fR] #delete an array element -delete \fIarray\fR #delete all elements within an array -break -continue -{ [ \fIstatement\fR ] .\|.\|. } -\fIexpression\fR # commonly variable = expression -print [ \fIexpression-list\fR ] [ >\fIexpression\fR ] -printf format [ ,\fIexpression-list\fR ] [ >\fIexpression\fR ] -next # skip remaining patterns on this input line -nextfile # skip remaining patterns on this input file -exit [expr] # skip the rest of the input; exit status is expr -return [expr] -.fi -.in -2 - -.sp -.LP -Any single statement can be replaced by a statement list enclosed in braces. -The statements are terminated by newline characters or semicolons, and are -executed sequentially in the order that they appear. -.sp -.LP -The \fBnext\fR statement causes all further processing of the current input -record to be abandoned. The behavior is undefined if a \fBnext\fR statement -appears or is invoked in a \fBBEGIN\fR or \fBEND\fR action. -.sp -.LP -The \fBnextfile\fR statement is similar to \fBnext\fR, but also skips all other -records in the current file, and moves on to processing the next input file if -available (or exits the program if there are none). (Note that this keyword is -not supported by \fB/usr/xpg4/bin/awk\fR.) -.sp -.LP -The \fBexit\fR statement invokes all \fBEND\fR actions in the order in which -they occur in the program source and then terminate the program without reading -further input. An \fBexit\fR statement inside an \fBEND\fR action terminates -the program without further execution of \fBEND\fR actions. If an expression -is specified in an \fBexit\fR statement, its numeric value is the exit status -of \fBnawk\fR, unless subsequent errors are encountered or a subsequent -\fBexit\fR statement with an expression is executed. - -.SS "Output Statements" -.LP -Both \fBprint\fR and \fBprintf\fR statements write to standard output by -default. The output is written to the location specified by -\fIoutput_redirection\fR if one is supplied, as follows: -.sp -.in +2 -.nf -\fB>\fR \fIexpression\fR\fB>>\fR \fIexpression\fR\fB|\fR \fIexpression\fR -.fi -.in -2 - -.sp -.LP -In all cases, the \fIexpression\fR is evaluated to produce a string that is -used as a full pathname to write into (for \fB>\fR or \fB>>\fR) or as a command -to be executed (for \fB|\fR). Using the first two forms, if the file of that -name is not currently open, it is opened, creating it if necessary and using -the first form, truncating the file. The output then is appended to the file. -As long as the file remains open, subsequent calls in which \fIexpression\fR -evaluates to the same string value simply appends output to the file. The file -remains open until the \fBclose\fR function, which is called with an expression -that evaluates to the same string value. -.sp -.LP -The third form writes output onto a stream piped to the input of a command. The -stream is created if no stream is currently open with the value of -\fIexpression\fR as its command name. The stream created is equivalent to one -created by a call to the \fBpopen\fR(3C) function with the value of -\fIexpression\fR as the \fIcommand\fR argument and a value of \fBw\fR as the -\fImode\fR argument. As long as the stream remains open, subsequent calls in -which \fIexpression\fR evaluates to the same string value writes output to the -existing stream. The stream remains open until the \fBclose\fR function is -called with an expression that evaluates to the same string value. At that -time, the stream is closed as if by a call to the \fBpclose\fR function. -.sp -.LP -These output statements take a comma-separated list of \fIexpression\fR \fIs\fR -referred in the grammar by the non-terminal symbols \fBexpr_list,\fR -\fBprint_expr_list\fR or \fBprint_expr_list_opt.\fR This list is referred to -here as the \fIexpression list\fR, and each member is referred to as an -\fIexpression argument\fR. -.sp -.LP -The \fBprint\fR statement writes the value of each expression argument onto the -indicated output stream separated by the current output field separator (see -variable \fBOFS\fR above), and terminated by the output record separator (see -variable \fBORS\fR above). All expression arguments is taken as strings, being -converted if necessary; with the exception that the \fBprintf\fR format in -\fBOFMT\fR is used instead of the value in \fBCONVFMT\fR. An empty expression -list stands for the whole input record \fB(\fR$0\fB)\fR. -.sp -.LP -The \fBprintf\fR statement produces output based on a notation similar to the -File Format Notation used to describe file formats in this document Output is -produced as specified with the first expression argument as the string -\fBformat\fR and subsequent expression arguments as the strings \fBarg1\fR to -\fBargn,\fR inclusive, with the following exceptions: -.RS +4 -.TP -1. -The \fIformat\fR is an actual character string rather than a graphical -representation. Therefore, it cannot contain empty character positions. The -space character in the \fIformat\fR string, in any context other than a -\fIflag\fR of a conversion specification, is treated as an ordinary character -that is copied to the output. -.RE -.RS +4 -.TP -2. -If the character set contains a Delta character and that character appears -in the \fIformat\fR string, it is treated as an ordinary character that is -copied to the output. -.RE -.RS +4 -.TP -3. -The \fIescape sequences\fR beginning with a backslash character is treated -as sequences of ordinary characters that are copied to the output. Note that -these same sequences is interpreted lexically by \fBnawk\fR when they appear in -literal strings, but they is not treated specially by the \fBprintf\fR -statement. -.RE -.RS +4 -.TP -4. -A \fIfield width\fR or \fIprecision\fR can be specified as the \fB*\fR -character instead of a digit string. In this case the next argument from the -expression list is fetched and its numeric value taken as the field width or -precision. -.RE -.RS +4 -.TP -5. -The implementation does not precede or follow output from the \fBd\fR or -\fBu\fR conversion specifications with blank characters not specified by the -\fIformat\fR string. -.RE -.RS +4 -.TP -6. -The implementation does not precede output from the \fBo\fR conversion -specification with leading zeros not specified by the \fIformat\fR string. -.RE -.RS +4 -.TP -7. -For the \fBc\fR conversion specification: if the argument has a numeric -value, the character whose encoding is that value is output. If the value is -zero or is not the encoding of any character in the character set, the behavior -is undefined. If the argument does not have a numeric value, the first -character of the string value is output; if the string does not contain any -characters the behavior is undefined. -.RE -.RS +4 -.TP -8. -For each conversion specification that consumes an argument, the next -expression argument is evaluated. With the exception of the \fBc\fR conversion, -the value is converted to the appropriate type for the conversion -specification. -.RE -.RS +4 -.TP -9. -If there are insufficient expression arguments to satisfy all the conversion -specifications in the \fIformat\fR string, the behavior is undefined. -.RE -.RS +4 -.TP -10. -If any character sequence in the \fIformat\fR string begins with a % -character, but does not form a valid conversion specification, the behavior is -unspecified. -.RE -.sp -.LP -Both \fBprint\fR and \fBprintf\fR can output at least \fB{LINE_MAX}\fR bytes. - -.SS "Functions" -.LP -The \fBnawk\fR language has a variety of built-in functions: arithmetic, -string, input/output and general. - -.SS "Arithmetic Functions" -.LP -The arithmetic functions, except for \fBint\fR, are based on the \fBISO\fR -\fBC\fR standard. The behavior is undefined in cases where the \fBISO\fR -\fBC\fR standard specifies that an error be returned or that the behavior is -undefined. Although the grammar permits built-in functions to appear with no -arguments or parentheses, unless the argument or parentheses are indicated as -optional in the following list (by displaying them within the \fB[ ]\fR -brackets), such use is undefined. -.sp -.ne 2 -.na -\fB\fBatan2(\fR\fIy\fR,\fIx\fR\fB)\fR\fR -.ad -.RS 17n -Return arctangent of \fIy\fR/\fIx\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBcos\fR(\fIx\fR)\fR -.ad -.RS 17n -Return cosine of \fIx,\fR where \fIx\fR is in radians. -.RE - -.sp -.ne 2 -.na -\fB\fBsin\fR(\fIx\fR)\fR -.ad -.RS 17n -Return sine of \fIx,\fR where \fIx\fR is in radians. -.RE - -.sp -.ne 2 -.na -\fB\fBexp\fR(\fIx\fR)\fR -.ad -.RS 17n -Return the exponential function of \fIx\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBlog\fR(\fIx\fR)\fR -.ad -.RS 17n -Return the natural logarithm of \fIx\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBsqrt\fR(\fIx\fR)\fR -.ad -.RS 17n -Return the square root of \fIx\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBint\fR(\fIx\fR)\fR -.ad -.RS 17n -Truncate its argument to an integer. It is truncated toward 0 when \fIx\fR > 0. -.RE - -.sp -.ne 2 -.na -\fB\fBrand()\fR\fR -.ad -.RS 17n -Return a random number \fIn\fR, such that 0 \(<= \fIn\fR < 1. -.RE - -.sp -.ne 2 -.na -\fB\fBsrand\fR([\fBexpr\fR])\fR -.ad -.RS 17n -Set the seed value for \fBrand\fR to \fIexpr\fR or use the time of day if -\fIexpr\fR is omitted. The previous seed value is returned. -.RE - -.SS "String Functions" -.LP -The string functions in the following list shall be supported. Although the -grammar permits built-in functions to appear with no arguments or parentheses, -unless the argument or parentheses are indicated as optional in the following -list (by displaying them within the \fB[ ]\fR brackets), such use is undefined. -.sp -.ne 2 -.na -\fB\fBgsub\fR(\fIere\fR,\fIrepl\fR[,\|\fIin\fR])\fR -.ad -.sp .6 -.RS 4n -Behave like \fBsub\fR (see below), except that it replaces all occurrences of -the regular expression (like the \fBed\fR utility global substitute) in -\fB$0\fR or in the \fIin\fR argument, when specified. -.RE - -.sp -.ne 2 -.na -\fB\fBindex\fR(\fIs\fR,\fIt\fR)\fR -.ad -.sp .6 -.RS 4n -Return the position, in characters, numbering from 1, in string \fIs\fR where -string \fIt\fR first occurs, or zero if it does not occur at all. -.RE - -.sp -.ne 2 -.na -\fB\fBlength\fR[([\fIv\fR])]\fR -.ad -.sp .6 -.RS 4n -Given no argument, this function returns the length of the whole record, -\fB$0\fR. If given an array as an argument (and using \fB/usr/bin/nawk\fR), -then this returns the number of elements it contains. Otherwise, this function -interprets the argument as a string (performing any needed conversions) and -returns its length in characters. -.RE - -.sp -.ne 2 -.na -\fB\fBmatch\fR(\fIs\fR,\fIere\fR)\fR -.ad -.sp .6 -.RS 4n -Return the position, in characters, numbering from 1, in string \fIs\fR where -the extended regular expression \fIere\fR occurs, or zero if it does not occur -at all. \fBRSTART\fR is set to the starting position (which is the same as the -returned value), zero if no match is found; \fBRLENGTH\fR is set to the length -of the matched string, \(mi1 if no match is found. -.RE - -.sp -.ne 2 -.na -\fB\fBsplit\fR(\fIs\fR,\fIa\fR[,\|\fIfs\fR])\fR -.ad -.sp .6 -.RS 4n -Split the string \fIs\fR into array elements \fIa\fR[1], \fIa\fR[2], -\fB\&...,\fR \fIa\fR[\fIn\fR], and return \fIn\fR. The separation is done with -the extended regular expression \fIfs\fR or with the field separator \fBFS\fR -if \fIfs\fR is not given. Each array element has a string value when created. -If the string assigned to any array element, with any occurrence of the -decimal-point character from the current locale changed to a period character, -would be considered a \fInumeric string\fR; the array element also has the -numeric value of the \fInumeric string\fR. The effect of a null string as the -value of \fIfs\fR is unspecified. -.RE - -.sp -.ne 2 -.na -\fB\fBsprintf\fR(\fBfmt\fR,\fIexpr\fR,\fIexpr\fR,\fB\&...\fR)\fR -.ad -.sp .6 -.RS 4n -Format the expressions according to the \fBprintf\fR format given by \fIfmt\fR -and return the resulting string. -.RE - -.sp -.ne 2 -.na -\fB\fBsub\fR(\fIere\fR,\fIrepl\fR[,\|\fIin\fR])\fR -.ad -.sp .6 -.RS 4n -Substitute the string \fIrepl\fR in place of the first instance of the extended -regular expression \fBERE\fR in string in and return the number of -substitutions. An ampersand ( \fB&\fR ) appearing in the string \fIrepl\fR is -replaced by the string from in that matches the regular expression. An -ampersand preceded with a backslash ( \fB\e\fR ) is interpreted as the literal -ampersand character. An occurrence of two consecutive backslashes is -interpreted as just a single literal backslash character. Any other occurrence -of a backslash (for example, preceding any other character) is treated as a -literal backslash character. If \fIrepl\fR is a string literal, the handling of -the ampersand character occurs after any lexical processing, including any -lexical backslash escape sequence processing. If \fBin\fR is specified and it -is not an \fBlvalue\fR the behavior is undefined. If in is omitted, \fBnawk\fR -uses the current record (\fB$0\fR) in its place. -.RE - -.sp -.ne 2 -.na -\fB\fBsubstr\fR(\fIs\fR,\fIm\fR[,\|\fIn\fR])\fR -.ad -.sp .6 -.RS 4n -Return the at most \fIn\fR-character substring of \fIs\fR that begins at -position \fIm,\fR numbering from 1. If \fIn\fR is missing, the length of the -substring is limited by the length of the string \fIs\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBtolower\fR(\fIs\fR)\fR -.ad -.sp .6 -.RS 4n -Return a string based on the string \fIs\fR. Each character in \fIs\fR that is -an upper-case letter specified to have a \fBtolower\fR mapping by the -\fBLC_CTYPE\fR category of the current locale is replaced in the returned -string by the lower-case letter specified by the mapping. Other characters in -\fIs\fR are unchanged in the returned string. -.RE - -.sp -.ne 2 -.na -\fB\fBtoupper\fR(\fIs\fR)\fR -.ad -.sp .6 -.RS 4n -Return a string based on the string \fIs\fR. Each character in \fIs\fR that is -a lower-case letter specified to have a \fBtoupper\fR mapping by the -\fBLC_CTYPE\fR category of the current locale is replaced in the returned -string by the upper-case letter specified by the mapping. Other characters in -\fIs\fR are unchanged in the returned string. -.RE - -.sp -.LP -All of the preceding functions that take \fIERE\fR as a parameter expect a -pattern or a string valued expression that is a regular expression as defined -below. - -.SS "Input/Output and General Functions" -.LP -The input/output and general functions are: -.sp -.ne 2 -.na -\fB\fBclose(\fR\fIexpression\fR)\fR -.ad -.RS 27n -Close the file or pipe opened by a \fBprint\fR or \fBprintf\fR statement or a -call to \fBgetline\fR with the same string-valued \fIexpression\fR. If the -close was successful, the function returns \fB0\fR; otherwise, it returns -non-zero. -.RE - -.sp -.ne 2 -.na -\fB\fBfflush(\fR\fIexpression\fR)\fR -.ad -.RS 27n -Flush any buffered output for the file or pipe opened by a \fBprint\fR or -\fBprintf\fR statement or a call to \fBgetline\fR with the same string-valued -\fIexpression\fR. If the flush was successful, the function returns \fB0\fR; -otherwise, it returns \fBEOF\fR. If no arguments or the empty string -(\fB""\fR) are given, then all open files will be flushed. (Note that -\fBfflush\fR is supported in \fB/usr/bin/nawk\fR only.) -.RE - -.sp -.ne 2 -.na -\fB\fIexpression\fR|\fBgetline\fR[\fIvar\fR]\fR -.ad -.RS 27n -Read a record of input from a stream piped from the output of a command. The -stream is created if no stream is currently open with the value of -\fIexpression\fR as its command name. The stream created is equivalent to one -created by a call to the \fBpopen\fR function with the value of -\fIexpression\fR as the \fIcommand\fR argument and a value of \fBr\fR as the -\fImode\fR argument. As long as the stream remains open, subsequent calls in -which \fIexpression\fR evaluates to the same string value reads subsequent -records from the file. The stream remains open until the \fBclose\fR function -is called with an expression that evaluates to the same string value. At that -time, the stream is closed as if by a call to the \fBpclose\fR function. If -\fIvar\fR is missing, \fB$0\fR and \fBNF\fR is set. Otherwise, \fIvar\fR is -set. -.sp -The \fBgetline\fR operator can form ambiguous constructs when there are -operators that are not in parentheses (including concatenate) to the left of -the \fB|\fR (to the beginning of the expression containing \fBgetline\fR). In -the context of the \fB$\fR operator, \fB|\fR behaves as if it had a lower -precedence than \fB$\fR. The result of evaluating other operators is -unspecified, and all such uses of portable applications must be put in -parentheses properly. -.RE - -.sp -.ne 2 -.na -\fB\fBgetline\fR\fR -.ad -.RS 27n -Set \fB$0\fR to the next input record from the current input file. This form of -\fBgetline\fR sets the \fBNF\fR, \fBNR\fR, and \fBFNR\fR variables. -.RE - -.sp -.ne 2 -.na -\fB\fBgetline\fR \fIvar\fR\fR -.ad -.RS 27n -Set variable \fIvar\fR to the next input record from the current input file. -This form of \fBgetline\fR sets the \fBFNR\fR and \fBNR\fR variables. -.RE - -.sp -.ne 2 -.na -\fB\fBgetline\fR [\fIvar\fR] \fB<\fR \fIexpression\fR\fR -.ad -.RS 27n -Read the next record of input from a named file. The \fIexpression\fR is -evaluated to produce a string that is used as a full pathname. If the file of -that name is not currently open, it is opened. As long as the stream remains -open, subsequent calls in which \fIexpression\fR evaluates to the same string -value reads subsequent records from the file. The file remains open until the -\fBclose\fR function is called with an expression that evaluates to the same -string value. If \fIvar\fR is missing, \fB$0\fR and \fBNF\fR is set. Otherwise, -\fIvar\fR is set. -.sp -The \fBgetline\fR operator can form ambiguous constructs when there are binary -operators that are not in parentheses (including concatenate) to the right of -the \fB<\fR (up to the end of the expression containing the \fBgetline\fR). The -result of evaluating such a construct is unspecified, and all such uses of -portable applications must be put in parentheses properly. -.RE - -.sp -.ne 2 -.na -\fB\fBsystem\fR(\fIexpression\fR)\fR -.ad -.RS 27n -Execute the command given by \fIexpression\fR in a manner equivalent to the -\fBsystem\fR(3C) function and return the exit status of the command. -.RE - -.sp -.LP -All forms of \fBgetline\fR return \fB1\fR for successful input, \fB0\fR for end -of file, and \fB\(mi1\fR for an error. -.sp -.LP -Where strings are used as the name of a file or pipeline, the strings must be -textually identical. The terminology ``same string value'' implies that -``equivalent strings'', even those that differ only by space characters, -represent different files. - -.SS "User-defined Functions" -.LP -The \fBnawk\fR language also provides user-defined functions. Such functions -can be defined as: -.sp -.in +2 -.nf -\fBfunction\fR \fIname\fR(\fIargs\fR,\|.\|.\|.) { \fIstatements\fR } -.fi -.in -2 - -.sp -.LP -A function can be referred to anywhere in an \fBnawk\fR program; in particular, -its use can precede its definition. The scope of a function is global. -.sp -.LP -Function arguments can be either scalars or arrays; the behavior is undefined -if an array name is passed as an argument that the function uses as a scalar, -or if a scalar expression is passed as an argument that the function uses as an -array. Function arguments are passed by value if scalar and by reference if -array name. Argument names are local to the function; all other variable names -are global. The same name is not used as both an argument name and as the name -of a function or a special \fBnawk\fR variable. The same name must not be used -both as a variable name with global scope and as the name of a function. The -same name must not be used within the same scope both as a scalar variable and -as an array. -.sp -.LP -The number of parameters in the function definition need not match the number -of parameters in the function call. Excess formal parameters can be used as -local variables. If fewer arguments are supplied in a function call than are in -the function definition, the extra parameters that are used in the function -body as scalars are initialized with a string value of the null string and a -numeric value of zero, and the extra parameters that are used in the function -body as arrays are initialized as empty arrays. If more arguments are supplied -in a function call than are in the function definition, the behavior is -undefined. -.sp -.LP -When invoking a function, no white space can be placed between the function -name and the opening parenthesis. Function calls can be nested and recursive -calls can be made upon functions. Upon return from any nested or recursive -function call, the values of all of the calling function's parameters are -unchanged, except for array parameters passed by reference. The \fBreturn\fR -statement can be used to return a value. If a \fBreturn\fR statement appears -outside of a function definition, the behavior is undefined. -.sp -.LP -In the function definition, newline characters are optional before the opening -brace and after the closing brace. Function definitions can appear anywhere in -the program where a \fIpattern-action\fR pair is allowed. - -.SH USAGE -.LP -The \fBindex\fR, \fBlength\fR, \fBmatch\fR, and \fBsubstr\fR functions should -not be confused with similar functions in the \fBISO C\fR standard; the -\fBnawk\fR versions deal with characters, while the \fBISO C\fR standard deals -with bytes. -.sp -.LP -Because the concatenation operation is represented by adjacent expressions -rather than an explicit operator, it is often necessary to use parentheses to -enforce the proper evaluation precedence. -.sp -.LP -See \fBlargefile\fR(5) for the description of the behavior of \fBnawk\fR when -encountering files greater than or equal to 2 Gbyte (2^31 bytes). - -.SH EXAMPLES -.LP -The \fBnawk\fR program specified in the command line is most easily specified -within single-quotes (for example, \fB\&'\fR\fIprogram\fR\fB\&'\fR) for -applications using \fBsh\fR, because \fBnawk\fR programs commonly contain -characters that are special to the shell, including double-quotes. In the cases -where a \fBnawk\fR program contains single-quote characters, it is usually -easiest to specify most of the program as strings within single-quotes -concatenated by the shell with quoted single-quote characters. For example: -.sp -.in +2 -.nf -nawk '/'\e''/ { print "quote:", $0 }' -.fi -.in -2 - -.sp -.LP -prints all lines from the standard input containing a single-quote character, -prefixed with \fBquote:\fR. -.sp -.LP -The following are examples of simple \fBnawk\fR programs: -.LP -\fBExample 1 \fRWrite to the standard output all input lines for which field 3 -is greater than 5: -.sp -.in +2 -.nf -\fB$3 > 5\fR -.fi -.in -2 -.sp - -.LP -\fBExample 2 \fRWrite every tenth line: -.sp -.in +2 -.nf -\fB(NR % 10) == 0\fR -.fi -.in -2 -.sp - -.LP -\fBExample 3 \fRWrite any line with a substring matching the regular -expression: -.sp -.in +2 -.nf -\fB/(G|D)(2[0-9][[:alpha:]]*)/\fR -.fi -.in -2 -.sp - -.LP -\fBExample 4 \fRPrint any line with a substring containing a G or D, followed -by a sequence of digits and characters: -.sp -.LP -This example uses character classes \fBdigit\fR and \fBalpha\fR to match -language-independent digit and alphabetic characters, respectively. - -.sp -.in +2 -.nf -\fB/(G|D)([[:digit:][:alpha:]]*)/\fR -.fi -.in -2 -.sp - -.LP -\fBExample 5 \fRWrite any line in which the second field matches the regular -expression and the fourth field does not: -.sp -.in +2 -.nf -\fB$2 ~ /xyz/ && $4 !~ /xyz/\fR -.fi -.in -2 -.sp - -.LP -\fBExample 6 \fRWrite any line in which the second field contains a backslash: -.sp -.in +2 -.nf -\fB$2 ~ /\e\e/\fR -.fi -.in -2 -.sp - -.LP -\fBExample 7 \fRWrite any line in which the second field contains a backslash -(alternate method): -.sp -.LP -Notice that backslash escapes are interpreted twice, once in lexical processing -of the string and once in processing the regular expression. - -.sp -.in +2 -.nf -\fB$2 ~ "\e\e\e\e"\fR -.fi -.in -2 -.sp - -.LP -\fBExample 8 \fRWrite the second to the last and the last field in each line, -separating the fields by a colon: -.sp -.in +2 -.nf -\fB{OFS=":";print $(NF-1), $NF}\fR -.fi -.in -2 -.sp - -.LP -\fBExample 9 \fRWrite the line number and number of fields in each line: -.sp -.LP -The three strings representing the line number, the colon and the number of -fields are concatenated and that string is written to standard output. - -.sp -.in +2 -.nf -\fB{print NR ":" NF}\fR -.fi -.in -2 -.sp - -.LP -\fBExample 10 \fRWrite lines longer than 72 characters: -.sp -.in +2 -.nf -\fB{length($0) > 72}\fR -.fi -.in -2 -.sp - -.LP -\fBExample 11 \fRWrite first two fields in opposite order separated by the OFS: -.sp -.in +2 -.nf -\fB{ print $2, $1 }\fR -.fi -.in -2 -.sp - -.LP -\fBExample 12 \fRSame, with input fields separated by comma or space and tab -characters, or both: -.sp -.in +2 -.nf -\fBBEGIN { FS = ",[\et]*|[\et]+" } - { print $2, $1 }\fR -.fi -.in -2 -.sp - -.LP -\fBExample 13 \fRAdd up first column, print sum and average: -.sp -.in +2 -.nf -\fB{s += $1 } -END {print "sum is ", s, " average is", s/NR}\fR -.fi -.in -2 -.sp - -.LP -\fBExample 14 \fRWrite fields in reverse order, one per line (many lines out -for each line in): -.sp -.in +2 -.nf -\fB{ for (i = NF; i > 0; --i) print $i }\fR -.fi -.in -2 -.sp - -.LP -\fBExample 15 \fRWrite all lines between occurrences of the strings "start" and -"stop": -.sp -.in +2 -.nf -\fB/start/, /stop/\fR -.fi -.in -2 -.sp - -.LP -\fBExample 16 \fRWrite all lines whose first field is different from the -previous one: -.sp -.in +2 -.nf -\fB$1 != prev { print; prev = $1 }\fR -.fi -.in -2 -.sp - -.LP -\fBExample 17 \fRSimulate the echo command: -.sp -.in +2 -.nf -\fBBEGIN { - for (i = 1; i < ARGC; ++i) - printf "%s%s", ARGV[i], i==ARGC-1?"\en":"" - }\fR -.fi -.in -2 -.sp - -.LP -\fBExample 18 \fRWrite the path prefixes contained in the PATH environment -variable, one per line: -.sp -.in +2 -.nf -\fBBEGIN { - n = split (ENVIRON["PATH"], path, ":") - for (i = 1; i <= n; ++i) - print path[i] - }\fR -.fi -.in -2 -.sp - -.LP -\fBExample 19 \fRPrint the file "input", filling in page numbers starting at 5: -.sp -.LP -If there is a file named \fBinput\fR containing page headers of the form - -.sp -.in +2 -.nf -Page# -.fi -.in -2 - -.sp -.LP -and a file named \fBprogram\fR that contains - -.sp -.in +2 -.nf -/Page/{ $2 = n++; } -{ print } -.fi -.in -2 - -.sp -.LP -then the command line - -.sp -.in +2 -.nf -\fBnawk -f program n=5 input\fR -.fi -.in -2 -.sp - -.sp -.LP -prints the file \fBinput\fR, filling in page numbers starting at 5. - -.SH ENVIRONMENT VARIABLES -.LP -See \fBenviron\fR(5) for descriptions of the following environment variables -that affect execution: \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and -\fBNLSPATH\fR. -.sp -.ne 2 -.na -\fB\fBLC_NUMERIC\fR\fR -.ad -.RS 14n -Determine the radix character used when interpreting numeric input, performing -conversions between numeric and string values and formatting numeric output. -Regardless of locale, the period character (the decimal-point character of the -POSIX locale) is the decimal-point character recognized in processing \fBawk\fR -programs (including assignments in command-line arguments). -.RE - -.SH EXIT STATUS -.LP -The following exit values are returned: -.sp -.ne 2 -.na -\fB\fB0\fR\fR -.ad -.RS 6n -All input files were processed successfully. -.RE - -.sp -.ne 2 -.na -\fB\fB>0\fR\fR -.ad -.RS 6n -An error occurred. -.RE - -.sp -.LP -The exit status can be altered within the program by using an \fBexit\fR -expression. - -.SH SEE ALSO -.LP -\fBawk\fR(1), \fBed\fR(1), \fBegrep\fR(1), \fBgrep\fR(1), \fBlex\fR(1), -\fBsed\fR(1), \fBpopen\fR(3C), \fBprintf\fR(3C), \fBsystem\fR(3C), -\fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBregex\fR(5), -\fBXPG4\fR(5) -.sp -.LP -Aho, A. V., B. W. Kernighan, and P. J. Weinberger, \fIThe AWK Programming -Language\fR, Addison-Wesley, 1988. - -.SH DIAGNOSTICS -.LP -If any \fIfile\fR operand is specified and the named file cannot be accessed, -\fBnawk\fR writes a diagnostic message to standard error and terminate without -any further action. -.sp -.LP -If the program specified by either the \fIprogram\fR operand or a -\fIprogfile\fR operand is not a valid \fBnawk\fR program (as specified in -\fBEXTENDED DESCRIPTION\fR), the behavior is undefined. - -.SH NOTES -.LP -Input white space is not preserved on output if fields are involved. -.sp -.LP -There are no explicit conversions between numbers and strings. To force an -expression to be treated as a number add 0 to it; to force it to be treated as -a string concatenate the null string (\fB""\fR) to it. diff --git a/usr/src/man/man1/oawk.1 b/usr/src/man/man1/oawk.1 new file mode 100644 index 0000000000..da7626418c --- /dev/null +++ b/usr/src/man/man1/oawk.1 @@ -0,0 +1,597 @@ +.\" +.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for +.\" permission to reproduce portions of its copyrighted documentation. +.\" Original documentation from The Open Group can be obtained online at +.\" http://www.opengroup.org/bookstore/. +.\" +.\" The Institute of Electrical and Electronics Engineers and The Open +.\" Group, have given us permission to reprint portions of their +.\" documentation. +.\" +.\" In the following statement, the phrase ``this text'' refers to portions +.\" of the system documentation. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, +.\" Standard for Information Technology -- Portable Operating System +.\" Interface (POSIX), The Open Group Base Specifications Issue 6, +.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics +.\" Engineers, Inc and The Open Group. In the event of any discrepancy +.\" between these versions and the original IEEE and The Open Group +.\" Standard, the original IEEE and The Open Group Standard is the referee +.\" document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" This notice shall appear on any product containing this material. +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" +.\" Copyright 1989 AT&T +.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. +.\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved +.\" Copyright 2020 Joyent, Inc. +.\" +.TH OAWK 1 "Apr 20, 2020" +.SH NAME +oawk \- (older) pattern scanning and processing language +.SH SYNOPSIS +.nf +\fB/usr/bin/oawk\fR [\fB-f\fR \fIprogfile\fR] [\fB-F\fIc\fR\fR] [' \fIprog\fR '] [\fIparameters\fR] + [\fIfilename\fR]... +.fi + +.SH DESCRIPTION +This command is now obsolete, and will be removed from illumos at some point. +.sp +.LP +The \fB/usr/bin/oawk\fR utility scans each input \fIfilename\fR for lines that +match any of a set of patterns specified in \fIprog\fR. The \fIprog\fR string +must be enclosed in single quotes (\fB a\'\fR) to protect it from the shell. +For each pattern in \fIprog\fR there can be an associated action performed when +a line of a \fIfilename\fR matches the pattern. The set of pattern-action +statements can appear literally as \fIprog\fR or in a file specified with the +\fB-f\fR\fI progfile\fR option. Input files are read in order; if there are no +files, the standard input is read. The file name \fB\&'\(mi'\fR means the +standard input. +.SH OPTIONS +The following options are supported: +.sp +.ne 2 +.na +\fB\fB-f\fR\fI progfile\fR \fR +.ad +.RS 16n +\fBoawk\fR uses the set of patterns it reads from \fIprogfile\fR. +.RE + +.sp +.ne 2 +.na +\fB\fB-F\fR\fIc\fR \fR +.ad +.RS 16n +Uses the character \fIc\fR as the field separator (FS) character. See the +discussion of \fBFS\fR below. +.RE + +.SH USAGE +.SS "Input Lines" +Each input line is matched against the pattern portion of every pattern-action +statement; the associated action is performed for each matched pattern. Any +\fIfilename\fR of the form \fIvar=value\fR is treated as an assignment, not a +filename, and is executed at the time it would have been opened if it were a +filename. \fIVariables\fR assigned in this manner are not available inside a +\fBBEGIN\fR rule, and are assigned after previously specified files have been +read. +.sp +.LP +An input line is normally made up of fields separated by white spaces. (This +default can be changed by using the \fBFS\fR built-in variable or the +\fB-F\fR\fIc\fR option.) The default is to ignore leading blanks and to +separate fields by blanks and/or tab characters. However, if \fBFS\fR is +assigned a value that does not include any of the white spaces, then leading +blanks are not ignored. The fields are denoted \fB$1\fR, \fB$2\fR, +\fB\&.\|.\|.\fR\|; \fB$0\fR refers to the entire line. +.SS "Pattern-action Statements" +A pattern-action statement has the form: +.sp +.in +2 +.nf +\fIpattern\fR\fB { \fR\fIaction\fR\fB } \fR +.fi +.in -2 +.sp + +.sp +.LP +Either pattern or action can be omitted. If there is no action, the matching +line is printed. If there is no pattern, the action is performed on every input +line. Pattern-action statements are separated by newlines or semicolons. +.sp +.LP +Patterns are arbitrary Boolean combinations ( \fB!\fR, ||, \fB&&\fR, and +parentheses) of relational expressions and regular expressions. A relational +expression is one of the following: +.sp +.in +2 +.nf +\fIexpression relop expression +expression matchop regular_expression\fR +.fi +.in -2 + +.sp +.LP +where a \fIrelop\fR is any of the six relational operators in C, and a +\fImatchop\fR is either \fB~\fR (contains) or \fB!~\fR (does not contain). An +\fIexpression\fR is an arithmetic expression, a relational expression, the +special expression +.sp +.in +2 +.nf +\fIvar \fRin \fIarray\fR +.fi +.in -2 + +.sp +.LP +or a Boolean combination of these. +.sp +.LP +Regular expressions are as in \fBegrep\fR(1). In patterns they must be +surrounded by slashes. Isolated regular expressions in a pattern apply to the +entire line. Regular expressions can also occur in relational expressions. A +pattern can consist of two patterns separated by a comma; in this case, the +action is performed for all lines between the occurrence of the first pattern +to the occurrence of the second pattern. +.sp +.LP +The special patterns \fBBEGIN\fR and \fBEND\fR can be used to capture control +before the first input line has been read and after the last input line has +been read respectively. These keywords do not combine with any other patterns. +.SS "Built-in Variables" +Built-in variables include: +.sp +.ne 2 +.na +\fB\fBFILENAME\fR \fR +.ad +.RS 13n +name of the current input file +.RE + +.sp +.ne 2 +.na +\fB\fBFS\fR \fR +.ad +.RS 13n +input field separator regular expression (default blank and tab) +.RE + +.sp +.ne 2 +.na +\fB\fBNF\fR \fR +.ad +.RS 13n +number of fields in the current record +.RE + +.sp +.ne 2 +.na +\fB\fBNR\fR \fR +.ad +.RS 13n +ordinal number of the current record +.RE + +.sp +.ne 2 +.na +\fB\fBOFMT\fR \fR +.ad +.RS 13n +output format for numbers (default \fB%.6g\fR) +.RE + +.sp +.ne 2 +.na +\fB\fBOFS\fR \fR +.ad +.RS 13n +output field separator (default blank) +.RE + +.sp +.ne 2 +.na +\fB\fBORS\fR \fR +.ad +.RS 13n +output record separator (default new-line) +.RE + +.sp +.ne 2 +.na +\fB\fBRS\fR \fR +.ad +.RS 13n +input record separator (default new-line) +.RE + +.sp +.LP +An action is a sequence of statements. A statement can be one of the following: +.sp +.in +2 +.nf +if ( \fIexpression\fR ) \fIstatement\fR [ else \fIstatement\fR ] +while ( \fIexpression\fR ) \fIstatement\fR +do \fIstatement\fR while ( \fIexpression\fR ) +for ( \fIexpression\fR ; \fIexpression\fR ; \fIexpression\fR ) \fIstatement\fR +for ( \fIvar\fR in \fIarray\fR ) \fIstatement\fR +break +continue +{ [ \fIstatement\fR ] .\|.\|. } +\fIexpression\fR # commonly variable = expression +print [ \fIexpression-list\fR ] [ >\fIexpression\fR ] +printf format [ ,\fIexpression-list\fR ] [ >\fIexpression\fR ] +next # skip remaining patterns on this input line +exit [expr] # skip the rest of the input; exit status is expr +.fi +.in -2 + +.sp +.LP +Statements are terminated by semicolons, newlines, or right braces. An empty +expression-list stands for the whole input line. Expressions take on string or +numeric values as appropriate, and are built using the operators \fB+\fR, +\fB\(mi\fR, \fB*\fR, \fB/\fR, \fB%\fR, \fB^\fR and concatenation (indicated by +a blank). The operators \fB++\fR, \fB\(mi\(mi\fR, \fB+=\fR, \fB\(mi=\fR, +\fB*=\fR, \fB/=\fR, \fB%=\fR, \fB^=\fR, \fB>\fR, \fB>=\fR, \fB<\fR, \fB<=\fR, +\fB==\fR, \fB!=\fR, and \fB?:\fR are also available in expressions. Variables +can be scalars, array elements (denoted x[i]), or fields. Variables are +initialized to the null string or zero. Array subscripts can be any string, not +necessarily numeric; this allows for a form of associative memory. String +constants are quoted (\fB""\fR), with the usual C escapes recognized within. +.sp +.LP +The \fBprint\fR statement prints its arguments on the standard output, or on a +file if \fB>\fR\fIexpression\fR is present, or on a pipe if '\fB|\fR\fIcmd\fR' +is present. The output resulted from the print statement is terminated by the +output record separator with each argument separated by the current output +field separator. The \fBprintf\fR statement formats its expression list +according to the format (see \fBprintf\fR(3C)). +.SS "Built-in Functions" +The arithmetic functions are as follows: +.sp +.ne 2 +.na +\fB\fBexp\fR(\fIx\fR)\fR +.ad +.RS 11n +Return the exponential function of \fIx\fR. +.RE + +.sp +.ne 2 +.na +\fB\fBlog\fR(\fIx\fR)\fR +.ad +.RS 11n +Return the natural logarithm of \fIx\fR. +.RE + +.sp +.ne 2 +.na +\fB\fBsqrt\fR(\fIx\fR)\fR +.ad +.RS 11n +Return the square root of \fIx\fR. +.RE + +.sp +.ne 2 +.na +\fB\fBint\fR(\fIx\fR)\fR +.ad +.RS 11n +Truncate its argument to an integer. It is truncated toward \fB0\fR when +\fIx\fR >\fB 0\fR. +.RE + +.sp +.LP +The string functions are as follows: +.sp +.ne 2 +.na +\fB\fBindex(\fR\fIs\fR\fB, \fR\fIt\fR\fB)\fR\fR +.ad +.sp .6 +.RS 4n +Return the position in string \fIs\fR where string \fIt\fR first occurs, or +\fB0\fR if it does not occur at all. +.RE + +.sp +.ne 2 +.na +\fB\fBint(\fR\fIs\fR\fB)\fR\fR +.ad +.sp .6 +.RS 4n +truncates \fIs\fR to an integer value. If \fIs\fR is not specified, $0 is used. +.RE + +.sp +.ne 2 +.na +\fB\fBlength(\fR\fIs\fR\fB)\fR\fR +.ad +.sp .6 +.RS 4n +Return the length of its argument taken as a string, or of the whole line if +there is no argument. +.RE + +.sp +.ne 2 +.na +\fB\fBsplit(\fR\fIs\fR, \fIa\fR, \fIfs\fR\fB)\fR\fR +.ad +.sp .6 +.RS 4n +Split the string \fIs\fR into array elements \fIa\fR[\fI1\fR], +\fIa\fR[\fI2\fR], \|.\|.\|. \fIa\fR[\fIn\fR], and returns \fIn\fR. The +separation is done with the regular expression \fIfs\fR or with the field +separator \fBFS\fR if \fIfs\fR is not given. +.RE + +.sp +.ne 2 +.na +\fB\fBsprintf(\fR\fIfmt\fR, \fIexpr\fR, \fIexpr\fR,\|.\|.\|.\|\fB)\fR\fR +.ad +.sp .6 +.RS 4n +Format the expressions according to the \fBprintf\fR(3C) format given by +\fIfmt\fR and returns the resulting string. +.RE + +.sp +.ne 2 +.na +\fB\fBsubstr(\fR\fIs\fR, \fIm\fR, \fIn\fR\fB)\fR\fR +.ad +.sp .6 +.RS 4n +returns the \fIn\fR-character substring of \fIs\fR that begins at position +\fIm\fR. +.RE + +.sp +.LP +The input/output function is as follows: +.sp +.ne 2 +.na +\fB\fBgetline\fR\fR +.ad +.RS 11n +Set \fB$0\fR to the next input record from the current input file. +\fBgetline\fR returns \fB1\fR for successful input, \fB0\fR for end of file, +and \fB\(mi1\fR for an error. +.RE + +.SS "Large File Behavior" +See \fBlargefile\fR(5) for the description of the behavior of \fBoawk\fR when +encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). +.SH EXAMPLES +\fBExample 1 \fRPrinting Lines Longer Than 72 Characters +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints lines longer than +seventy two characters: + +.sp +.in +2 +.nf +\fBlength > 72\fR +.fi +.in -2 +.sp + +.LP +\fBExample 2 \fRPrinting Fields in Opposite Order +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints the first two fields in +opposite order: + +.sp +.in +2 +.nf +\fB{ print $2, $1 }\fR +.fi +.in -2 +.sp + +.LP +\fBExample 3 \fRPrinting Fields in Opposite Order with the Input Fields +Separated +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints the first two input +fields in opposite order, separated by a comma, blanks or tabs: + +.sp +.in +2 +.nf +\fBBEGIN { FS = ",[ \et]*|[ \et]+" } + { print $2, $1 }\fR +.fi +.in -2 +.sp + +.LP +\fBExample 4 \fRAdding Up the First Column, Printing the Sum and Average +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It adds up the first column, and +prints the sum and average: + +.sp +.in +2 +.nf +\fB{ s += $1 } +END { print "sum is", s, " average is", s/NR }\fR +.fi +.in -2 +.sp + +.LP +\fBExample 5 \fRPrinting Fields in Reverse Order +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints fields in reverse order: + +.sp +.in +2 +.nf +\fB{ for (i = NF; i > 0; \(mi\(mii) print $i }\fR +.fi +.in -2 +.sp + +.LP +\fBExample 6 \fRPrinting All lines Between \fBstart/stop\fR Pairs +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints all lines between +start/stop pairs. + +.sp +.in +2 +.nf +\fB/start/, /stop/\fR +.fi +.in -2 +.sp + +.LP +\fBExample 7 \fRPrinting All Lines Whose First Field is Different from the +Previous One +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints all lines whose first +field is different from the previous one. + +.sp +.in +2 +.nf +\fB$1 != prev { print; prev = $1 }\fR +.fi +.in -2 +.sp + +.LP +\fBExample 8 \fRPrinting a File and Filling in Page numbers +.sp +.LP +The following example is an \fBoawk\fR script that can be executed by an +\fBoawk -f examplescript\fR style command. It prints a file and fills in page +numbers starting at 5: + +.sp +.in +2 +.nf +\fB/Page/ { $2 = n++; } + { print }\fR +.fi +.in -2 +.sp + +.LP +\fBExample 9 \fRPrinting a File and Numbering Its Pages +.sp +.LP +Assuming this program is in a file named \fBprog\fR, the following example +prints the file \fBinput\fR numbering its pages starting at \fB5\fR: + +.sp +.in +2 +.nf +example% \fBoawk -f prog n=5 input\fR +.fi +.in -2 +.sp + +.SH ENVIRONMENT VARIABLES +See \fBenviron\fR(5) for descriptions of the following environment variables +that affect the execution of \fBoawk\fR: \fBLANG\fR, \fBLC_ALL\fR, +\fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, \fBNLSPATH\fR, and +\fBPATH\fR. +.sp +.ne 2 +.na +\fB\fBLC_NUMERIC\fR\fR +.ad +.RS 14n +Determine the radix character used when interpreting numeric input, +performing conversions between numeric and string values and formatting +numeric output. Regardless of locale, the period character (the +decimal-point character of the POSIX locale) is the decimal-point character +recognized in processing \fBoawk\fR programs (including assignments in +command-line arguments). +.RE + +.SH ATTRIBUTES +See \fBattributes\fR(5) for descriptions of the following attributes: +.SS "/usr/bin/oawk" + +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +CSI Not Enabled +.TE + +.SH SEE ALSO +\fBegrep\fR(1), \fBgrep\fR(1), \fBawk\fR(1), \fBsed\fR(1), \fBprintf\fR(3C), +\fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5) +.SH NOTES +Input white space is not preserved on output if fields are involved. +.sp +.LP +There are no explicit conversions between numbers and strings. To force an +expression to be treated as a number, add \fB0\fR to it. To force an expression +to be treated as a string, concatenate the null string (\fB""\fR) to it. diff --git a/usr/src/man/man7d/i40e.7d b/usr/src/man/man7d/i40e.7d index 81ab257f6e..c5ba043149 100644 --- a/usr/src/man/man7d/i40e.7d +++ b/usr/src/man/man7d/i40e.7d @@ -11,7 +11,7 @@ .\" .\" Copyright (c) 2018 Joyent, Inc. .\" -.Dd Jan 10, 2020 +.Dd April 15, 2020 .Dt I40E 7D .Os .Sh NAME @@ -44,6 +44,8 @@ Promiscuous access via IPv4 Checksum Offload .It TCP, UDP, and SCTP checksum offload +.It +IPv4 and IPv6 TCP Segmentation offload .El .Pp At this time, the diff --git a/usr/src/pkg/manifests/driver-network-bge.mf b/usr/src/pkg/manifests/driver-network-bge.mf index 6ac1368ea0..0dc0ff7a50 100644 --- a/usr/src/pkg/manifests/driver-network-bge.mf +++ b/usr/src/pkg/manifests/driver-network-bge.mf @@ -48,6 +48,16 @@ $(i386_ONLY)driver name=bge clone_perms="bge 0666 root sys" \ alias=pci108e,1648 \ alias=pci108e,16a7 \ alias=pci108e,16a8 \ + alias=pci14e4,0x1682 \ + alias=pci14e4,0x1686 \ + alias=pci14e4,0x16b0 \ + alias=pci14e4,0x16b1 \ + alias=pci14e4,0x16b2 \ + alias=pci14e4,0x16b3 \ + alias=pci14e4,0x16b4 \ + alias=pci14e4,0x16b5 \ + alias=pci14e4,0x16b6 \ + alias=pci14e4,0x16b7 \ alias=pci14e4,1600 \ alias=pci14e4,1601 \ alias=pci14e4,1644 \ @@ -77,6 +87,16 @@ $(i386_ONLY)driver name=bge clone_perms="bge 0666 root sys" \ alias=pci14e4,16a7 \ alias=pci14e4,16a8 \ alias=pci14e4,16c7 \ + alias=pciex14e4,0x1682 \ + alias=pciex14e4,0x1686 \ + alias=pciex14e4,0x16b0 \ + alias=pciex14e4,0x16b1 \ + alias=pciex14e4,0x16b2 \ + alias=pciex14e4,0x16b3 \ + alias=pciex14e4,0x16b4 \ + alias=pciex14e4,0x16b5 \ + alias=pciex14e4,0x16b6 \ + alias=pciex14e4,0x16b7 \ alias=pciex14e4,1643 \ alias=pciex14e4,1655 \ alias=pciex14e4,1656 \ @@ -106,6 +126,16 @@ $(sparc_ONLY)driver name=bge clone_perms="bge 0666 root sys" \ alias=pci108e,1648 \ alias=pci108e,16a7 \ alias=pci108e,16a8 \ + alias=pci14e4,0x1682 \ + alias=pci14e4,0x1686 \ + alias=pci14e4,0x16b0 \ + alias=pci14e4,0x16b1 \ + alias=pci14e4,0x16b2 \ + alias=pci14e4,0x16b3 \ + alias=pci14e4,0x16b4 \ + alias=pci14e4,0x16b5 \ + alias=pci14e4,0x16b6 \ + alias=pci14e4,0x16b7 \ alias=pci14e4,1645 \ alias=pci14e4,1647 \ alias=pci14e4,1648 \ @@ -118,6 +148,16 @@ $(sparc_ONLY)driver name=bge clone_perms="bge 0666 root sys" \ alias=pci14e4,16a7 \ alias=pci14e4,16a8 \ alias=pci14e4,16c7 \ + alias=pciex14e4,0x1682 \ + alias=pciex14e4,0x1686 \ + alias=pciex14e4,0x16b0 \ + alias=pciex14e4,0x16b1 \ + alias=pciex14e4,0x16b2 \ + alias=pciex14e4,0x16b3 \ + alias=pciex14e4,0x16b4 \ + alias=pciex14e4,0x16b5 \ + alias=pciex14e4,0x16b6 \ + alias=pciex14e4,0x16b7 \ alias=pciex14e4,1655 \ alias=pciex14e4,1656 \ alias=pciex14e4,1659 \ diff --git a/usr/src/pkg/manifests/driver-network-mlxcx.mf b/usr/src/pkg/manifests/driver-network-mlxcx.mf index dec1aa726c..35c6634f0d 100644 --- a/usr/src/pkg/manifests/driver-network-mlxcx.mf +++ b/usr/src/pkg/manifests/driver-network-mlxcx.mf @@ -24,7 +24,7 @@ set name=pkg.fmri value=pkg:/driver/network/mlxcx@$(PKGVERS) set name=pkg.description value="Mellanox ConnectX-4/5/6 Ethernet Driver" set name=pkg.summary value="Mellanox ConnectX-4/5/6 Ethernet Driver" set name=info.classification \ - value=org.opensolaris.category.2008:Drivers/Storage + value=org.opensolaris.category.2008:Drivers/Networking set name=variant.arch value=i386 dir path=kernel group=sys dir path=kernel/drv group=sys @@ -48,7 +48,5 @@ driver name=mlxcx \ file path=kernel/drv/$(ARCH64)/mlxcx group=sys file path=kernel/drv/mlxcx.conf group=sys file path=usr/share/man/man7d/mlxcx.7d -legacy pkg=SUNWmrsas desc="Mellanox ConnectX-4/5/6 Ethernet Driver" \ - name="Mellanox ConnectX-4/5/6 Ethernet Driver" license cr_Sun license=cr_Sun license lic_CDDL license=lic_CDDL diff --git a/usr/src/pkg/manifests/system-extended-system-utilities.mf b/usr/src/pkg/manifests/system-extended-system-utilities.mf index 0a8502a491..ea58ec0d55 100644 --- a/usr/src/pkg/manifests/system-extended-system-utilities.mf +++ b/usr/src/pkg/manifests/system-extended-system-utilities.mf @@ -23,6 +23,7 @@ # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # Copyright 2012 Nexenta Systems, Inc. All rights reserved. # Copyright 2016 RackTop Systems. +# Copyright 2020 Joyent, Inc. # set name=pkg.fmri value=pkg:/system/extended-system-utilities@$(PKGVERS) @@ -117,10 +118,10 @@ file path=usr/bin/lastcomm mode=0555 file path=usr/bin/lgrpinfo mode=0555 file path=usr/bin/look mode=0755 file path=usr/bin/mkfifo mode=0555 -file path=usr/bin/nawk mode=0555 file path=usr/bin/newform mode=0555 file path=usr/bin/news mode=0555 file path=usr/bin/nl mode=0555 +file path=usr/bin/oawk mode=0555 file path=usr/bin/pack mode=0555 file path=usr/bin/pginfo mode=0555 file path=usr/bin/pgstat mode=0555 @@ -185,10 +186,10 @@ file path=usr/share/man/man1/lgrpinfo.1 file path=usr/share/man/man1/look.1 file path=usr/share/man/man1/madv.so.1.1 file path=usr/share/man/man1/mpss.so.1.1 -file path=usr/share/man/man1/nawk.1 file path=usr/share/man/man1/newform.1 file path=usr/share/man/man1/news.1 file path=usr/share/man/man1/nl.1 +file path=usr/share/man/man1/oawk.1 file path=usr/share/man/man1/pack.1 file path=usr/share/man/man1/pargs.1 file path=usr/share/man/man1/plgrp.1 @@ -223,7 +224,7 @@ $(i386_ONLY)hardlink path=usr/bin/$(ARCH32)/penv \ target=../../../usr/bin/$(ARCH32)/pargs hardlink path=usr/bin/$(ARCH64)/pauxv target=../../../usr/bin/$(ARCH64)/pargs hardlink path=usr/bin/$(ARCH64)/penv target=../../../usr/bin/$(ARCH64)/pargs -hardlink path=usr/bin/oawk target=../../usr/bin/awk +hardlink path=usr/bin/nawk target=../../usr/bin/awk hardlink path=usr/bin/pargs target=../../usr/lib/isaexec hardlink path=usr/bin/pauxv target=../../usr/lib/isaexec hardlink path=usr/bin/pcred target=../../usr/lib/isaexec @@ -284,6 +285,7 @@ link path=usr/proc/bin/pwait target=../../bin/pwait link path=usr/proc/bin/pwdx target=../../bin/pwdx link path=usr/share/man/man1/hashcheck.1 target=spell.1 link path=usr/share/man/man1/hashmake.1 target=spell.1 +link path=usr/share/man/man1/nawk.1 target=awk.1 link path=usr/share/man/man1/pauxv.1 target=pargs.1 link path=usr/share/man/man1/pcat.1 target=pack.1 link path=usr/share/man/man1/penv.1 target=pargs.1 diff --git a/usr/src/test/crypto-tests/tests/Makefile.crypto b/usr/src/test/crypto-tests/tests/Makefile.crypto index f53bd7d89b..8d7396fa64 100644 --- a/usr/src/test/crypto-tests/tests/Makefile.crypto +++ b/usr/src/test/crypto-tests/tests/Makefile.crypto @@ -96,8 +96,6 @@ clean: $(CMDS): $(TESTDIR_pkcs) $(TESTDIR_kcf) $(PROGS) -.PARALLEL: $(CMDS) $(PROGS) - $(TESTDIR_pkcs) $(TESTDIR_kcf): $(INS.dir) diff --git a/usr/src/test/crypto-tests/tests/digest/Makefile b/usr/src/test/crypto-tests/tests/digest/Makefile index c381d0c584..a5732aa375 100644 --- a/usr/src/test/crypto-tests/tests/digest/Makefile +++ b/usr/src/test/crypto-tests/tests/digest/Makefile @@ -27,6 +27,4 @@ all clean clobber install: $(ALGS) $(ALGS): FRC $(MAKE) -e -f Makefile.digest BASEPROG=$@ $(TARGET) -.PARALLEL: $(ALGS) - FRC: diff --git a/usr/src/test/util-tests/tests/awk/runtests.sh b/usr/src/test/util-tests/tests/awk/runtests.sh index 28d127dc3c..fd94d3585a 100755 --- a/usr/src/test/util-tests/tests/awk/runtests.sh +++ b/usr/src/test/util-tests/tests/awk/runtests.sh @@ -12,10 +12,10 @@ # # -# Copyright 2018, Joyent, Inc. +# Copyright 2020 Joyent, Inc. # -AWK=/usr/bin/nawk +AWK=/usr/bin/awk WORKDIR=$(mktemp -d /tmp/nawktest.XXXXXX) SUCCESSES=0 diff --git a/usr/src/test/util-tests/tests/awk/tests/T.misc b/usr/src/test/util-tests/tests/awk/tests/T.misc index ee603014e2..04e9794de9 100755 --- a/usr/src/test/util-tests/tests/awk/tests/T.misc +++ b/usr/src/test/util-tests/tests/awk/tests/T.misc @@ -132,7 +132,7 @@ $AWK 'BEGIN { foo() }' 2> $TEMP0 grep "calling undefined function foo" $TEMP0 >/dev/null || fail "BAD: T.misc undefined function" -# gawk arrayparm test; should give error about function +# gawk arrayparm test; should give error about function $AWK ' BEGIN { foo[1]=1; @@ -365,14 +365,14 @@ cmp -s $TEMP1 $TEMP2 || fail 'BAD: T.misc immmediate exit 4' echo 1 > $TEMP1 $AWK ' { n = split($0, x) for (i in x) { - if (i == 1) + if (i == 1) exit } } END { print NR }' /etc/passwd > $TEMP2 cmp -s $TEMP1 $TEMP2 || fail 'BAD: T.misc immmediate exit 5' echo XXXXXXXX > $TEMP1 $AWK 'BEGIN { s = "ab\fc\rd\be" - t = s; gsub("[" s "]", "X", t); print t }' > $TEMP2 + t = s; gsub("[" s "]", "X", t); print t }' > $TEMP2 cmp -s $TEMP1 $TEMP2 || fail 'BAD: T.misc weird escapes in char class' $AWK '{}' /etc/passwd glop/glop > $TEMP0 2> $TEMP2 diff --git a/usr/src/uts/common/io/bge/bge_chip2.c b/usr/src/uts/common/io/bge/bge_chip2.c index 0ceb070556..14797ac90f 100644 --- a/usr/src/uts/common/io/bge/bge_chip2.c +++ b/usr/src/uts/common/io/bge/bge_chip2.c @@ -243,7 +243,8 @@ bge_ind_get32(bge_t *bgep, bge_regno_t regno) #ifdef __sparc if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { regno = LE_32(regno); } #endif @@ -270,7 +271,8 @@ bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val) val = LE_32(val); #ifdef __sparc if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { regno = LE_32(regno); } #endif @@ -366,7 +368,8 @@ bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) */ cidp->device = pci_config_get16(handle, PCI_CONF_DEVID); if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { pci_config_put32(handle, PCI_CONF_BGE_MHCR, 0); } @@ -378,6 +381,8 @@ bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) if (DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep)) { prodid = CHIP_ASIC_REV_PROD_ID_GEN2_REG; + } else if (DEVICE_57765_SERIES_CHIPSETS(bgep)) { + prodid = CHIP_ASIC_REV_PROD_ID_GEN15_REG; } cidp->asic_rev_prod_id = pci_config_get32(handle, prodid); } @@ -564,7 +569,8 @@ bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL_5723, DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); } else if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL_5717, DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); } else { @@ -667,7 +673,8 @@ bge_reg_get64(bge_t *bgep, bge_regno_t regno) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type() || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); regval <<= 32; regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); @@ -677,7 +684,8 @@ bge_reg_get64(bge_t *bgep, bge_regno_t regno) #elif defined(__sparc) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); regval <<= 32; regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); @@ -715,7 +723,8 @@ bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type() || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), (uint32_t)data); BGE_PCICHK(bgep); @@ -728,7 +737,8 @@ bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data) #elif defined(__sparc) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno + 4), (uint32_t)data); BGE_PCICHK(bgep); @@ -887,7 +897,8 @@ bge_nic_setwin(bge_t *bgep, bge_regno_t base) } #ifdef __sparc if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { base = LE_32(base); } #endif @@ -949,7 +960,8 @@ bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data) #ifdef __sparc if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { addr = LE_32(addr); } pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); @@ -981,7 +993,8 @@ bge_nic_get64(bge_t *bgep, bge_regno_t addr) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type() || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr + 4)); data <<= 32; @@ -992,7 +1005,8 @@ bge_nic_get64(bge_t *bgep, bge_regno_t addr) #elif defined(__sparc) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep || + DEVICE_57765_SERIES_CHIPSETS(bgep))) { data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); data <<= 32; data |= ddi_get32(bgep->io_handle, @@ -1027,7 +1041,8 @@ bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type() || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), (uint32_t)data); BGE_PCICHK(bgep); @@ -1039,7 +1054,8 @@ bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data) #elif defined(__sparc) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), (uint32_t)data); BGE_PCICHK(bgep); @@ -1082,7 +1098,8 @@ bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type() || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), (uint32_t)(*p)); ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), @@ -1099,7 +1116,8 @@ bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) #elif defined(__sparc) if (DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), (uint32_t)(*p)); ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), @@ -1801,7 +1819,8 @@ bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) { + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_reg_set32(bgep, NVM_ACCESS_REG, NVM_ACCESS_ENABLE); } @@ -1811,7 +1830,8 @@ bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) { + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_reg_clr32(bgep, NVM_ACCESS_REG, NVM_ACCESS_ENABLE); } @@ -1822,7 +1842,8 @@ bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) { + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_reg_set32(bgep, NVM_ACCESS_REG, NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); } @@ -1834,7 +1855,8 @@ bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) { + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_reg_clr32(bgep, NVM_ACCESS_REG, NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); } @@ -2047,6 +2069,16 @@ bge_nvmem_id(bge_t *bgep) case DEVICE_ID_5714S: case DEVICE_ID_5715C: case DEVICE_ID_5715S: + case DEVICE_ID_57761: + case DEVICE_ID_57762: + case DEVICE_ID_57765: + case DEVICE_ID_57766: + case DEVICE_ID_57781: + case DEVICE_ID_57782: + case DEVICE_ID_57785: + case DEVICE_ID_57786: + case DEVICE_ID_57791: + case DEVICE_ID_57795: config1 = bge_reg_get32(bgep, NVM_CONFIG1_REG); if (config1 & NVM_CFG1_FLASH_MODE) if (config1 & NVM_CFG1_BUFFERED_MODE) @@ -2603,6 +2635,16 @@ bge_chip_id_init(bge_t *bgep) case DEVICE_ID_5724: case DEVICE_ID_5725: case DEVICE_ID_5727: + case DEVICE_ID_57761: + case DEVICE_ID_57762: + case DEVICE_ID_57765: + case DEVICE_ID_57766: + case DEVICE_ID_57781: + case DEVICE_ID_57782: + case DEVICE_ID_57785: + case DEVICE_ID_57786: + case DEVICE_ID_57791: + case DEVICE_ID_57795: if (cidp->device == DEVICE_ID_5717) { cidp->chip_label = 5717; } else if (cidp->device == DEVICE_ID_5718) { @@ -2620,9 +2662,30 @@ bge_chip_id_init(bge_t *bgep) cidp->chip_label = 5724; } else if (cidp->device == DEVICE_ID_5725) { cidp->chip_label = 5725; - } else /* (cidp->device == DEVICE_ID_5727) */ { + } else if (cidp->device == DEVICE_ID_5727) { cidp->chip_label = 5727; + } else if (cidp->device == DEVICE_ID_57761) { + cidp->chip_label = 57761; + } else if (cidp->device == DEVICE_ID_57762) { + cidp->chip_label = 57762; + } else if (cidp->device == DEVICE_ID_57765) { + cidp->chip_label = 57765; + } else if (cidp->device == DEVICE_ID_57766) { + cidp->chip_label = 57766; + } else if (cidp->device == DEVICE_ID_57781) { + cidp->chip_label = 57781; + } else if (cidp->device == DEVICE_ID_57782) { + cidp->chip_label = 57782; + } else if (cidp->device == DEVICE_ID_57785) { + cidp->chip_label = 57785; + } else if (cidp->device == DEVICE_ID_57786) { + cidp->chip_label = 57786; + } else if (cidp->device == DEVICE_ID_57791) { + cidp->chip_label = 57791; + } else if (cidp->device == DEVICE_ID_57795) { + cidp->chip_label = 57795; } + cidp->msi_enabled = bge_enable_msi; #ifdef __sparc cidp->mask_pci_int = LE_32(MHCR_MASK_PCI_INT_OUTPUT); @@ -2635,7 +2698,11 @@ bge_chip_id_init(bge_t *bgep) cidp->mbuf_base = bge_mbuf_pool_base_5705; cidp->mbuf_length = bge_mbuf_pool_len_5705; cidp->recv_slots = BGE_RECV_SLOTS_5705; - cidp->bge_mlcr_default = MLCR_DEFAULT_5717; + if (DEVICE_57765_SERIES_CHIPSETS(bgep)) { + cidp->bge_mlcr_default = MLCR_DEFAULT_57765; + } else { + cidp->bge_mlcr_default = MLCR_DEFAULT_5717; + } cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; cidp->statistic_type = BGE_STAT_REG; @@ -3048,7 +3115,8 @@ bge_chip_id_init(bge_t *bgep) (cidp->default_mtu > BGE_DEFAULT_MTU)) { if (DEVICE_5714_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5714_JUMBO; cidp->mbuf_lo_water_rmac = @@ -3210,7 +3278,8 @@ bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) DEVICE_5721_SERIES_CHIPSETS(bgep) || DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5714_SERIES_CHIPSETS(bgep) || - DEVICE_5906_SERIES_CHIPSETS(bgep)) { + DEVICE_5906_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { regval |= MISC_CONFIG_GPHY_POWERDOWN_OVERRIDE; if (bgep->chipid.pci_type == BGE_PCI_E) { if (bgep->chipid.asic_rev == @@ -3298,7 +3367,8 @@ bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) } if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { val16 = pci_config_get16(bgep->cfg_handle, PCI_CONF_DEV_CTRL_5717); val16 &= ~READ_REQ_SIZE_MASK; @@ -3460,7 +3530,8 @@ bge_sync_mac_modes(bge_t *bgep) (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) { if (DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) macmode |= ETHERNET_MODE_PORTMODE_GMII; else macmode |= ETHERNET_MODE_PORTMODE_TBI; @@ -4023,7 +4094,8 @@ bge_chip_reset(bge_t *bgep, boolean_t enable_dma) #endif if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_reg_set32(bgep, FAST_BOOT_PC, 0); if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) retval = DDI_FAILURE; @@ -4055,6 +4127,18 @@ bge_chip_reset(bge_t *bgep, boolean_t enable_dma) bge_reg_set32(bgep, TLP_CONTROL_REG, TLP_DATA_FIFO_PROTECT); /* + * In the 57765 family of devices we need to work around an apparent + * transmit hang by dorking with the PCIe serdes training clocks. + */ + if (DEVICE_57765_SERIES_CHIPSETS(bgep) && + (CHIP_ASIC_REV_PROD_ID(bgep) >> 8) != CHIP_ASIC_REV_57765_AX) { + tmp = bge_reg_get32(bgep, CPMU_PADRNG_CTL_REG); + tmp |= CPMU_PADRNG_CTL_RDIV2; + bge_reg_set32(bgep, CPMU_PADRNG_CTL_REG, tmp); + } + + + /* * Step 9: enable MAC memory arbiter,bit30 and bit31 of 5714/5715 should * not be changed. */ @@ -4353,7 +4437,8 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) MODE_HOST_STACK_UP); if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { reg = (CHIP_ASIC_REV(bgep) == CHIP_ASIC_REV_5762) ? RDMA_RSRV_CTRL_REG2 : RDMA_RSRV_CTRL_REG; regval = bge_reg_get32(bgep, reg); @@ -4459,7 +4544,8 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) if (bgep->chipid.device == DEVICE_ID_5719) regval |= BUFFER_MANAGER_MODE_NO_TX_UNDERRUN; if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) regval |= BUFFER_MANAGER_MODE_MBLOW_ATTN_ENABLE; if (!bge_chip_enable_engine(bgep, BUFFER_MANAGER_MODE_REG, regval)) retval = DDI_FAILURE; @@ -4471,17 +4557,24 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) * Steps 37-39: initialise Receive Buffer (Producer) RCBs */ if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { buff_ring_t *brp = &bgep->buff[BGE_STD_BUFF_RING]; bge_reg_put64(bgep, STD_RCV_BD_RING_RCB_REG, brp->desc.cookie.dmac_laddress); bge_reg_put32(bgep, STD_RCV_BD_RING_RCB_REG + 8, (brp->desc.nslots) << 16 | brp->buf[0].size << 2); - bge_reg_put32(bgep, STD_RCV_BD_RING_RCB_REG + 0xc, - NIC_MEM_SHADOW_BUFF_STD_5717); - } else + if (DEVICE_57765_SERIES_CHIPSETS(bgep)) { + bge_reg_put32(bgep, STD_RCV_BD_RING_RCB_REG + 0xc, + NIC_MEM_SHADOW_BUFF_STD); + } else { + bge_reg_put32(bgep, STD_RCV_BD_RING_RCB_REG + 0xc, + NIC_MEM_SHADOW_BUFF_STD_5717); + } + } else { bge_reg_putrcb(bgep, STD_RCV_BD_RING_RCB_REG, &bgep->buff[BGE_STD_BUFF_RING].hw_rcb); + } if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { bge_reg_putrcb(bgep, JUMBO_RCV_BD_RING_RCB_REG, @@ -4673,7 +4766,8 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) else coalmode = 0; if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) coalmode = COALESCE_CLR_TICKS_RX; if (!bge_chip_enable_engine(bgep, HOST_COALESCE_MODE_REG, coalmode)) retval = DDI_FAILURE; @@ -4753,6 +4847,10 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) drv_usecwait(40); + /* + * These chipsets no longer use the rdprio logic (bits 31:30 are + * reserved). + */ if (DEVICE_5723_SERIES_CHIPSETS(bgep) || DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep)) @@ -4797,7 +4895,8 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) * Steps 89-90: enable Transmit & Receive MAC Engines */ regval = 0; - if (DEVICE_5717_SERIES_CHIPSETS(bgep)) { + if (DEVICE_5717_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { regval |= TRANSMIT_MODE_MBUF_LOCKUP_FIX; } if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, regval)) @@ -4911,7 +5010,8 @@ bge_chip_start(bge_t *bgep, boolean_t reset_phys) #endif if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL_5717, DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); #if 0 @@ -5076,7 +5176,8 @@ bge_intr(caddr_t arg1, caddr_t arg2) */ regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); if (!(DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) && + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) && (regval & MLCR_INTA_STATE)) { if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) @@ -6413,7 +6514,8 @@ bge_nic_read32(bge_t *bgep, bge_regno_t addr) } #else if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { addr = LE_32(addr); } #endif diff --git a/usr/src/uts/common/io/bge/bge_hw.h b/usr/src/uts/common/io/bge/bge_hw.h index 506b97774e..7dfb86fb0d 100644 --- a/usr/src/uts/common/io/bge/bge_hw.h +++ b/usr/src/uts/common/io/bge/bge_hw.h @@ -109,6 +109,16 @@ extern "C" { #define DEVICE_ID_5906 0x1712 #define DEVICE_ID_5906M 0x1713 #define DEVICE_ID_57780 0x1692 +#define DEVICE_ID_57761 0x16b0 +#define DEVICE_ID_57762 0x1682 +#define DEVICE_ID_57765 0x16b4 +#define DEVICE_ID_57766 0x1686 +#define DEVICE_ID_57781 0x16b1 +#define DEVICE_ID_57782 0x16b7 +#define DEVICE_ID_57785 0x16b5 +#define DEVICE_ID_57786 0x16b3 +#define DEVICE_ID_57791 0x16b2 +#define DEVICE_ID_57795 0x16b6 #define REVISION_ID_5700_B0 0x10 #define REVISION_ID_5700_B2 0x12 @@ -227,6 +237,23 @@ extern "C" { (bgep->chipid.device == DEVICE_ID_5906M)) /* + * Even though the hardware register calls this the 57785 family, all of the + * BSDs call this the 57765 series, so we call it that way to make it more + * similar. + */ +#define DEVICE_57765_SERIES_CHIPSETS(bgep) \ + ((bgep->chipid.device == DEVICE_ID_57761) || \ + (bgep->chipid.device == DEVICE_ID_57762) || \ + (bgep->chipid.device == DEVICE_ID_57765) || \ + (bgep->chipid.device == DEVICE_ID_57766) || \ + (bgep->chipid.device == DEVICE_ID_57781) || \ + (bgep->chipid.device == DEVICE_ID_57782) || \ + (bgep->chipid.device == DEVICE_ID_57785) || \ + (bgep->chipid.device == DEVICE_ID_57786) || \ + (bgep->chipid.device == DEVICE_ID_57791) || \ + (bgep->chipid.device == DEVICE_ID_57795)) + +/* * Second section: * Offsets of important registers & definitions for bits therein */ @@ -334,12 +361,12 @@ extern "C" { #define MHCR_CHIP_ASIC_REV_5704 (0x2 << 28) #define MHCR_CHIP_ASIC_REV_5705 (0x3 << 28) #define MHCR_CHIP_ASIC_REV_5721_5751 (0x4 << 28) -#define MHCR_CHIP_ASIC_REV_5714 (0x5 << 28) +#define MHCR_CHIP_ASIC_REV_5714 (0x5 << 28) #define MHCR_CHIP_ASIC_REV_5752 (0x6 << 28) #define MHCR_CHIP_ASIC_REV_5754 (0xb << 28) #define MHCR_CHIP_ASIC_REV_5787 ((uint32_t)0xb << 28) #define MHCR_CHIP_ASIC_REV_5755 ((uint32_t)0xa << 28) -#define MHCR_CHIP_ASIC_REV_5715 ((uint32_t)0x9 << 28) +#define MHCR_CHIP_ASIC_REV_5715 ((uint32_t)0x9 << 28) #define MHCR_CHIP_ASIC_REV_5906 ((uint32_t)0xc << 28) /* (0xf << 28) touches all 5717 and 5725 series as well (OK) */ #define MHCR_CHIP_ASIC_REV_5723 ((uint32_t)0xf << 28) @@ -348,6 +375,7 @@ extern "C" { #define CHIP_ASIC_REV_5761 0x5761 #define CHIP_ASIC_REV_5785 0x5785 #define CHIP_ASIC_REV_57780 0x57780 +#define CHIP_ASIC_REV_57785 0x57785 #define CHIP_ASIC_REV_5717 0x5717 #define CHIP_ASIC_REV_5719 0x5719 @@ -356,6 +384,7 @@ extern "C" { #define CHIP_ASIC_REV_PROD_ID_REG 0x000000bc #define CHIP_ASIC_REV_PROD_ID_GEN2_REG 0x000000f4 +#define CHIP_ASIC_REV_PROD_ID_GEN15_REG 0x000000fc #define CHIP_ASIC_REV_5717_B0 0x05717100 #define CHIP_ASIC_REV_5717_C0 0x05717200 @@ -367,6 +396,11 @@ extern "C" { #define CHIP_ASIC_REV_5727_B0 0x05762100 /* + * Match any Metal Layer Revision. + */ +#define CHIP_ASIC_REV_57765_AX 0x577850 + +/* * PCI DMA read/write Control Register, in PCI config space * * Note that several fields previously defined here have been deleted @@ -504,7 +538,7 @@ extern "C" { #define PCI_CONF_DEV_CTRL_5717 0xb4 #define READ_REQ_SIZE_MASK 0x7000 #define READ_REQ_SIZE_MAX 0x5000 -#define READ_REQ_SIZE_2K 0x4000 +#define READ_REQ_SIZE_2K 0x4000 #define DEV_CTRL_NO_SNOOP 0x0800 #define DEV_CTRL_RELAXED 0x0010 @@ -1144,15 +1178,17 @@ extern "C" { #define JUMBO_RCV_BD_REPLENISH_DEFAULT 0x00000020 /* 32 */ /* - * CPMU registers (5717/18/19/20 only) + * CPMU registers (5717/18/19/20/57765 only) */ #define CPMU_CLCK_ORIDE_REG 0x3624 #define CPMU_CLCK_ORIDE_MAC_ORIDE_EN 0x80000000 #define CPMU_STATUS_REG 0x362c #define CPMU_STATUS_FUNC_NUM 0x20000000 #define CPMU_STATUS_FUNC_NUM_SHIFT 29 -#define CPMU_STATUS_FUNC_NUM_5719 0xc0000000 +#define CPMU_STATUS_FUNC_NUM_5719 0xc0000000 #define CPMU_STATUS_FUNC_NUM_5719_SHIFT 30 +#define CPMU_PADRNG_CTL_REG 0x3668 +#define CPMU_PADRNG_CTL_RDIV2 0x00040000 /* * EEE registers (5718/19/20 only) @@ -1444,6 +1480,12 @@ extern "C" { #define MLCR_DEFAULT_5717 (MLCR_AUTO_SEEPROM_ACCESS) /* + * MLCR_AUTO_SEEPROM_ACCESS is marked reserved in the 57765 family, so we don't + * try to enable it like on the 5717. + */ +#define MLCR_DEFAULT_57765 0 + +/* * Serial EEPROM Data/Address Registers (auto-access mode) */ #define SERIAL_EEPROM_DATA_REG 0x683c @@ -1544,7 +1586,7 @@ extern "C" { /* * NVM access register - * Applicable to BCM5721,BCM5751,BCM5752,BCM5714 + * Applicable to BCM5721,BCM5751,BCM5752,BCM5714,BCM57725 * and BCM5715 only. */ #define NVM_ACCESS_REG 0x7024 @@ -1731,7 +1773,7 @@ extern "C" { /* * Third section: - * Hardware-defined data structures + * Hardware-defined data structures * * Note that the chip is naturally BIG-endian, so, for a big-endian * host, the structures defined below match those described in the PRM. diff --git a/usr/src/uts/common/io/bge/bge_impl.h b/usr/src/uts/common/io/bge/bge_impl.h index 848f039359..37a927fce5 100644 --- a/usr/src/uts/common/io/bge/bge_impl.h +++ b/usr/src/uts/common/io/bge/bge_impl.h @@ -794,8 +794,8 @@ typedef struct bge { /* * For the BCM5705/5788/5721/5751/5752/5714 and 5715, * the statistic block is not available,the statistic counter must - * be gotten from statistic registers.And bge_statistics_reg_t record - * the statistic registers value + * be gotten from statistic registers. And bge_statistics_reg_t record + * the statistic registers value. */ bge_statistics_reg_t *pstats; diff --git a/usr/src/uts/common/io/bge/bge_lint.c b/usr/src/uts/common/io/bge/bge_lint.c deleted file mode 100644 index 2f51987068..0000000000 --- a/usr/src/uts/common/io/bge/bge_lint.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ - -/* - * This is a dummy lint file to pacify lint for bge, which due to its upstream, - * makes it, unfortunately, not realistic to lint. We have a dummy definition to - * ensure that we don't trigger lint's empty translation unit. - */ - -extern int bge_lint; diff --git a/usr/src/uts/common/io/bge/bge_main2.c b/usr/src/uts/common/io/bge/bge_main2.c index dc0174c4a3..ab511c068d 100644 --- a/usr/src/uts/common/io/bge/bge_main2.c +++ b/usr/src/uts/common/io/bge/bge_main2.c @@ -83,8 +83,8 @@ static ddi_dma_attr_t dma_attr = { 0x00000001, /* dma_attr_minxfer */ 0x000000000000FFFFull, /* dma_attr_maxxfer */ 0x00000000FFFFFFFFull, /* dma_attr_seg */ - 1, /* dma_attr_sgllen */ - 0x00000001, /* dma_attr_granular */ + 1, /* dma_attr_sgllen */ + 0x00000001, /* dma_attr_granular */ DDI_DMA_FLAGERR /* dma_attr_flags */ }; @@ -119,9 +119,7 @@ static ddi_device_acc_attr_t bge_data_accattr = { static int bge_m_start(void *); static void bge_m_stop(void *); static int bge_m_promisc(void *, boolean_t); -static int bge_m_unicst(void * pArg, const uint8_t *); static int bge_m_multicst(void *, boolean_t, const uint8_t *); -static void bge_m_resources(void * arg); static void bge_m_ioctl(void *, queue_t *, mblk_t *); static boolean_t bge_m_getcapab(void *, mac_capab_t, void *); static int bge_unicst_set(void *, const uint8_t *, @@ -140,47 +138,19 @@ static void bge_priv_propinfo(const char *, mac_prop_info_handle_t); static mac_callbacks_t bge_m_callbacks = { - MC_IOCTL -#ifdef MC_RESOURCES - | MC_RESOURCES -#endif -#ifdef MC_SETPROP - | MC_SETPROP -#endif -#ifdef MC_GETPROP - | MC_GETPROP -#endif -#ifdef MC_PROPINFO - | MC_PROPINFO -#endif - | MC_GETCAPAB, - bge_m_stat, - bge_m_start, - bge_m_stop, - bge_m_promisc, - bge_m_multicst, - bge_m_unicst, - bge_m_tx, -#ifdef MC_RESOURCES - bge_m_resources, -#else - NULL, -#endif - bge_m_ioctl, - bge_m_getcapab, -#ifdef MC_OPEN - NULL, - NULL, -#endif -#ifdef MC_SETPROP - bge_m_setprop, -#endif -#ifdef MC_GETPROP - bge_m_getprop, -#endif -#ifdef MC_PROPINFO - bge_m_propinfo -#endif + .mc_callbacks = MC_IOCTL | MC_SETPROP | MC_GETPROP | MC_PROPINFO | + MC_GETCAPAB, + .mc_getstat = bge_m_stat, + .mc_start = bge_m_start, + .mc_stop = bge_m_stop, + .mc_setpromisc = bge_m_promisc, + .mc_multicst = bge_m_multicst, + .mc_tx = bge_m_tx, + .mc_ioctl = bge_m_ioctl, + .mc_getcapab = bge_m_getcapab, + .mc_setprop = bge_m_setprop, + .mc_getprop = bge_m_getprop, + .mc_propinfo = bge_m_propinfo }; char *bge_priv_prop[] = { @@ -1288,21 +1258,6 @@ bge_priv_propinfo(const char *pr_name, mac_prop_info_handle_t mph) mac_prop_info_set_default_str(mph, valstr); } - -static int -bge_m_unicst(void * arg, const uint8_t * mac_addr) -{ - bge_t *bgep = arg; - int i; - - /* XXX sets the mac address for all ring slots... OK? */ - for (i = 0; i < MIN(bgep->chipid.rx_rings, MAC_ADDRESS_REGS_MAX); i++) - bge_addmac(&bgep->recv[i], mac_addr); - - return (0); -} - - /* * Compute the index of the required bit in the multicast hash map. * This must mirror the way the hardware actually does it! @@ -1463,37 +1418,6 @@ bge_m_promisc(void *arg, boolean_t on) return (0); } -#ifdef MC_RESOURCES - -static void -bge_blank(void * arg, time_t tick_cnt, uint_t pkt_cnt) -{ - (void)arg; - (void)tick_cnt; - (void)pkt_cnt; -} - -static void -bge_m_resources(void * arg) -{ - bge_t *bgep = arg; - mac_rx_fifo_t mrf; - int i; - - mrf.mrf_type = MAC_RX_FIFO; - mrf.mrf_blank = bge_blank; - mrf.mrf_arg = (void *)bgep; - mrf.mrf_normal_blank_time = 25; - mrf.mrf_normal_pkt_count = 8; - - for (i = 0; i < BGE_RECV_RINGS_MAX; i++) { - bgep->macRxResourceHandles[i] = - mac_resource_add(bgep->mh, (mac_resource_t *)&mrf); - } -} - -#endif /* MC_RESOURCES */ - /* * Find the slot for the specified unicast address */ @@ -1540,7 +1464,10 @@ bge_addmac(void *arg, const uint8_t * mac_addr) * First add the unicast address to a available slot. */ slot = bge_unicst_find(bgep, mac_addr); - ASSERT(slot == -1); + if (slot != -1) { + mutex_exit(bgep->genlock); + return (EEXIST); + } for (slot = 0; slot < bgep->unicst_addr_total; slot++) { if (!bgep->curr_addr[slot].set) { @@ -1549,7 +1476,7 @@ bge_addmac(void *arg, const uint8_t * mac_addr) } } - ASSERT(slot < bgep->unicst_addr_total); + VERIFY3S(slot, <, bgep->unicst_addr_total); bgep->unicst_addr_avail--; mutex_exit(bgep->genlock); @@ -1671,7 +1598,7 @@ bge_remmac(void *arg, const uint8_t *mac_addr) static int -bge_flag_intr_enable(mac_ring_driver_t ih) +bge_flag_intr_enable(mac_intr_handle_t ih) { recv_ring_t *rrp = (recv_ring_t *)ih; bge_t *bgep = rrp->bgep; @@ -1684,7 +1611,7 @@ bge_flag_intr_enable(mac_ring_driver_t ih) } static int -bge_flag_intr_disable(mac_ring_driver_t ih) +bge_flag_intr_disable(mac_intr_handle_t ih) { recv_ring_t *rrp = (recv_ring_t *)ih; bge_t *bgep = rrp->bgep; @@ -1736,8 +1663,9 @@ bge_fill_ring(void *arg, mac_ring_type_t rtype, const int rg_index, infop->mri_stat = bge_rx_ring_stat; mintr = &infop->mri_intr; - mintr->mi_enable = (mac_intr_enable_t)bge_flag_intr_enable; - mintr->mi_disable = (mac_intr_disable_t)bge_flag_intr_disable; + mintr->mi_handle = (mac_intr_handle_t)rx_ring; + mintr->mi_enable = bge_flag_intr_enable; + mintr->mi_disable = bge_flag_intr_disable; break; } @@ -2691,7 +2619,8 @@ bge_alloc_bufs(bge_t *bgep) * Enable PCI relaxed ordering only for RX/TX data buffers */ if (!(DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep))) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep))) { if (bge_relaxed_ordering) dma_attr.dma_attr_flags |= DDI_DMA_RELAXED_ORDERING; } @@ -2727,7 +2656,8 @@ bge_alloc_bufs(bge_t *bgep) txbuffsize)); if (!(DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep))) { + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep))) { /* no relaxed ordering for descriptors rings? */ dma_attr.dma_attr_flags &= ~DDI_DMA_RELAXED_ORDERING; } @@ -3716,6 +3646,8 @@ bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) bgep->ape_enabled = B_FALSE; bgep->ape_regs = NULL; + cidp = &bgep->chipid; + cidp->device = pci_config_get16(bgep->cfg_handle, PCI_CONF_DEVID); if (DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep)) { err = ddi_regs_map_setup(devinfo, BGE_PCI_APEREGS_RNUMBER, @@ -3749,8 +3681,6 @@ bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) * registers. (This information will be used by bge_ind_put32, * bge_ind_get32 and bge_nic_read32) */ - bgep->chipid.device = pci_config_get16(bgep->cfg_handle, - PCI_CONF_DEVID); value16 = pci_config_get16(bgep->cfg_handle, PCI_CONF_COMM); value16 = value16 | (PCI_COMM_MAE | PCI_COMM_ME); pci_config_put16(bgep->cfg_handle, PCI_CONF_COMM, value16); @@ -3767,7 +3697,8 @@ bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) * byte-swapped value to it. So we just write zero first for simplicity. */ if (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, 0); #else mhcrValue = MHCR_ENABLE_INDIRECT_ACCESS | @@ -3792,8 +3723,6 @@ bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) goto attach_fail; } bgep->progress |= PROGRESS_CFG; - cidp = &bgep->chipid; - bzero(cidp, sizeof(*cidp)); bge_chip_cfg_init(bgep, cidp, B_FALSE); if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); @@ -4065,14 +3994,6 @@ bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) * Determine whether to override the chip's own MAC address */ bge_find_mac_address(bgep, cidp); - { - int slot; - for (slot = 0; slot < MAC_ADDRESS_REGS_MAX; slot++) { - ethaddr_copy(cidp->vendor_addr.addr, - bgep->curr_addr[slot].addr); - bgep->curr_addr[slot].set = 1; - } - } bge_read_fw_ver(bgep); @@ -4090,10 +4011,7 @@ bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) macp->m_max_sdu = cidp->ethmax_size - sizeof (struct ether_header); macp->m_margin = VLAN_TAGSZ; macp->m_priv_props = bge_priv_prop; - -#if defined(ILLUMOS) - bge_m_unicst(bgep, cidp->vendor_addr.addr); -#endif + macp->m_v12n = MAC_VIRT_LEVEL1; /* * Finally, we're ready to register ourselves with the MAC layer diff --git a/usr/src/uts/common/io/bge/bge_mii.c b/usr/src/uts/common/io/bge/bge_mii.c index 68823b3cba..30cd7c94d9 100644 --- a/usr/src/uts/common/io/bge/bge_mii.c +++ b/usr/src/uts/common/io/bge/bge_mii.c @@ -586,7 +586,7 @@ bge_restart_copper(bge_t *bgep, boolean_t powerdown) case MHCR_CHIP_ASIC_REV_5906: case MHCR_CHIP_ASIC_REV_5700: case MHCR_CHIP_ASIC_REV_5701: - case MHCR_CHIP_ASIC_REV_5723: /* 5717 and 5725 series as well */ + case MHCR_CHIP_ASIC_REV_5723: /* 5717, 5725, 57765 series as well */ case MHCR_CHIP_ASIC_REV_5721_5751: /* * Just a plain reset; the "check" code breaks these chips @@ -1333,7 +1333,8 @@ bge_restart_serdes(bge_t *bgep, boolean_t powerdown) macmode &= ~ETHERNET_MODE_PORTMODE_MASK; if (DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) { + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { macmode |= ETHERNET_MODE_PORTMODE_GMII; } else { macmode |= ETHERNET_MODE_PORTMODE_TBI; @@ -1561,11 +1562,12 @@ bge_check_serdes(bge_t *bgep, boolean_t recheck) * Don't call function bge_autoneg_serdes() as * RX_1000BASEX_AUTONEG_REG (0x0448) is not applicable * to BCM5705, BCM5788, BCM5721, BCM5751, BCM5752, - * BCM5714, and BCM5715 devices. + * BCM5714, BCM5715, and BCM57765 family devices. */ if (DEVICE_5717_SERIES_CHIPSETS(bgep) || DEVICE_5725_SERIES_CHIPSETS(bgep) || - DEVICE_5714_SERIES_CHIPSETS(bgep)) { + DEVICE_5714_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) { tx_status = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); linkup = BIS(tx_status, TRANSMIT_STATUS_LINK_UP); diff --git a/usr/src/uts/common/io/bge/bge_send.c b/usr/src/uts/common/io/bge/bge_send.c index 87e0c0105d..c00f8ac124 100644 --- a/usr/src/uts/common/io/bge/bge_send.c +++ b/usr/src/uts/common/io/bge/bge_send.c @@ -451,7 +451,8 @@ start_tx: hw_sbd_p->flags |= SBD_FLAG_TCP_UDP_CKSUM; if (!(bgep->chipid.flags & CHIP_FLAG_NO_JUMBO) && (DEVICE_5717_SERIES_CHIPSETS(bgep) || - DEVICE_5725_SERIES_CHIPSETS(bgep)) && + DEVICE_5725_SERIES_CHIPSETS(bgep) || + DEVICE_57765_SERIES_CHIPSETS(bgep)) && (txbuf->copy_len > ETHERMAX)) hw_sbd_p->flags |= SBD_FLAG_JMB_PKT; hw_sbd_p->flags |= SBD_FLAG_PACKET_END; diff --git a/usr/src/uts/common/io/i40e/i40e_gld.c b/usr/src/uts/common/io/i40e/i40e_gld.c index ccf814be0b..1bf40bbce3 100644 --- a/usr/src/uts/common/io/i40e/i40e_gld.c +++ b/usr/src/uts/common/io/i40e/i40e_gld.c @@ -733,8 +733,10 @@ i40e_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) mac_capab_lso_t *cap_lso = cap_data; if (i40e->i40e_tx_lso_enable == B_TRUE) { - cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; + cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4 | + LSO_TX_BASIC_TCP_IPV6; cap_lso->lso_basic_tcp_ipv4.lso_max = I40E_LSO_MAXLEN; + cap_lso->lso_basic_tcp_ipv6.lso_max = I40E_LSO_MAXLEN; } else { return (B_FALSE); } diff --git a/usr/src/uts/common/io/i40e/i40e_transceiver.c b/usr/src/uts/common/io/i40e/i40e_transceiver.c index 9662cb58f5..e324957625 100644 --- a/usr/src/uts/common/io/i40e/i40e_transceiver.c +++ b/usr/src/uts/common/io/i40e/i40e_transceiver.c @@ -1782,7 +1782,8 @@ i40e_tx_context(i40e_t *i40e, i40e_trqpair_t *itrq, mblk_t *mp, * LSO requires that checksum offloads are enabled. If for * some reason they're not we bail out with an error. */ - if ((chkflags & HCK_IPV4_HDRCKSUM) == 0 || + if ((meo->meoi_l3proto == ETHERTYPE_IP && + (chkflags & HCK_IPV4_HDRCKSUM) == 0) || (chkflags & HCK_PARTIALCKSUM) == 0) { txs->itxs_lso_nohck.value.ui64++; return (-1); diff --git a/usr/src/uts/common/io/igb/igb_gld.c b/usr/src/uts/common/io/igb/igb_gld.c index 2bb4f99d6f..f68c4b73e9 100644 --- a/usr/src/uts/common/io/igb/igb_gld.c +++ b/usr/src/uts/common/io/igb/igb_gld.c @@ -965,8 +965,10 @@ igb_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) mac_capab_lso_t *cap_lso = cap_data; if (igb->lso_enable) { - cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; + cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4 | + LSO_TX_BASIC_TCP_IPV6; cap_lso->lso_basic_tcp_ipv4.lso_max = IGB_LSO_MAXLEN; + cap_lso->lso_basic_tcp_ipv6.lso_max = IGB_LSO_MAXLEN; break; } else { return (B_FALSE); @@ -1645,7 +1647,7 @@ igb_priv_prop_info(igb_t *igb, const char *pr_name, mac_prop_info_handle_t prh) value = DEFAULT_RX_COPY_THRESHOLD; } else if (strcmp(pr_name, "_rx_limit_per_intr") == 0) { value = DEFAULT_RX_LIMIT_PER_INTR; - } else if (strcmp(pr_name, "_intr_throttling") == 0) { + } else if (strcmp(pr_name, "_intr_throttling") == 0) { value = igb->capab->def_intr_throttle; } else { return; diff --git a/usr/src/uts/common/io/igb/igb_sw.h b/usr/src/uts/common/io/igb/igb_sw.h index f689c44b14..2e329d6fdc 100644 --- a/usr/src/uts/common/io/igb/igb_sw.h +++ b/usr/src/uts/common/io/igb/igb_sw.h @@ -227,7 +227,7 @@ extern "C" { enum ioc_reply { IOC_INVAL = -1, /* bad, NAK with EINVAL */ - IOC_DONE, /* OK, reply sent */ + IOC_DONE, /* OK, reply sent */ IOC_ACK, /* OK, just send ACK */ IOC_REPLY /* OK, just send reply */ }; @@ -355,6 +355,7 @@ typedef struct tx_context { uint32_t hcksum_flags; uint32_t ip_hdr_len; uint32_t mac_hdr_len; + uint32_t l3_proto; uint32_t l4_proto; uint32_t mss; uint32_t l4_hdr_len; @@ -558,7 +559,7 @@ typedef struct igb_rx_group { } igb_rx_group_t; typedef struct igb { - int instance; + int instance; mac_handle_t mac_hdl; dev_info_t *dip; struct e1000_hw hw; @@ -606,7 +607,7 @@ typedef struct igb { boolean_t tx_ring_init; boolean_t tx_head_wb_enable; /* Tx head wrtie-back */ boolean_t tx_hcksum_enable; /* Tx h/w cksum offload */ - boolean_t lso_enable; /* Large Segment Offload */ + boolean_t lso_enable; /* Large Segment Offload */ uint32_t tx_copy_thresh; /* Tx copy threshold */ uint32_t tx_recycle_thresh; /* Tx recycle threshold */ uint32_t tx_overload_thresh; /* Tx overload threshold */ diff --git a/usr/src/uts/common/io/igb/igb_tx.c b/usr/src/uts/common/io/igb/igb_tx.c index 0496bf59fe..5245312adc 100644 --- a/usr/src/uts/common/io/igb/igb_tx.c +++ b/usr/src/uts/common/io/igb/igb_tx.c @@ -598,6 +598,7 @@ igb_get_tx_context(mblk_t *mp, tx_context_t *ctx) uint32_t start; uint32_t flags; uint32_t lso_flag; + uint32_t lso_cksum; uint32_t mss; uint32_t len; uint32_t size; @@ -622,19 +623,6 @@ igb_get_tx_context(mblk_t *mp, tx_context_t *ctx) ctx->mss = mss; ctx->lso_flag = (lso_flag == HW_LSO); - /* - * LSO relies on tx h/w checksum, so here the packet will be - * dropped if the h/w checksum flags are not set. - */ - if (ctx->lso_flag) { - if (!((ctx->hcksum_flags & HCK_PARTIALCKSUM) && - (ctx->hcksum_flags & HCK_IPV4_HDRCKSUM))) { - igb_log(NULL, IGB_LOG_INFO, "igb_tx: h/w " - "checksum flags are not set for LSO"); - return (TX_CXT_E_LSO_CSUM); - } - } - etype = 0; mac_hdr_len = 0; l4_proto = 0; @@ -679,6 +667,8 @@ igb_get_tx_context(mblk_t *mp, tx_context_t *ctx) * Here we assume the IP(V6) header is fully included in one * mblk fragment. */ + lso_cksum = HCK_PARTIALCKSUM; + ctx->l3_proto = etype; switch (etype) { case ETHERTYPE_IP: offset = mac_hdr_len; @@ -703,11 +693,27 @@ igb_get_tx_context(mblk_t *mp, tx_context_t *ctx) * with zero. Currently the tcp/ip stack has done * these. */ + lso_cksum |= HCK_IPV4_HDRCKSUM; } l4_proto = *(uint8_t *)(pos + offsetof(ipha_t, ipha_protocol)); break; case ETHERTYPE_IPV6: + /* + * We need to zero out the length in the header. + */ + if (ctx->lso_flag) { + offset = offsetof(ip6_t, ip6_plen) + mac_hdr_len; + while (size <= offset) { + mp = mp->b_cont; + ASSERT(mp != NULL); + len = MBLKL(mp); + size += len; + } + pos = mp->b_rptr + offset + len - size; + *((uint16_t *)(uintptr_t)(pos)) = 0; + } + offset = offsetof(ip6_t, ip6_nxt) + mac_hdr_len; while (size <= offset) { mp = mp->b_cont; @@ -727,6 +733,18 @@ igb_get_tx_context(mblk_t *mp, tx_context_t *ctx) } if (ctx->lso_flag) { + /* + * LSO relies on tx h/w checksum, so here the packet will be + * dropped if the h/w checksum flags are not set. + */ + if ((ctx->hcksum_flags & lso_cksum) != lso_cksum) { + igb_log(NULL, IGB_LOG_INFO, "igb_tx: h/w " + "checksum flags are not set for LSO, found " + "0x%x, needed bits 0x%x", ctx->hcksum_flags, + lso_cksum); + return (TX_CXT_E_LSO_CSUM); + } + offset = mac_hdr_len + start; while (size <= offset) { mp = mp->b_cont; @@ -771,6 +789,7 @@ igb_check_tx_context(igb_tx_ring_t *tx_ring, tx_context_t *ctx) * need to be checked are: * hcksum_flags * l4_proto + * l3_proto * mss (only check for LSO) * l4_hdr_len (only check for LSO) * ip_hdr_len @@ -783,6 +802,7 @@ igb_check_tx_context(igb_tx_ring_t *tx_ring, tx_context_t *ctx) if (ctx->hcksum_flags != 0) { if ((ctx->hcksum_flags != last->hcksum_flags) || (ctx->l4_proto != last->l4_proto) || + (ctx->l3_proto != last->l3_proto) || (ctx->lso_flag && ((ctx->mss != last->mss) || (ctx->l4_hdr_len != last->l4_hdr_len))) || (ctx->ip_hdr_len != last->ip_hdr_len) || @@ -814,10 +834,19 @@ igb_fill_tx_context(struct e1000_adv_tx_context_desc *ctx_tbd, ctx_tbd->type_tucmd_mlhl = E1000_ADVTXD_DCMD_DEXT | E1000_ADVTXD_DTYP_CTXT; - if (ctx->hcksum_flags & HCK_IPV4_HDRCKSUM) - ctx_tbd->type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4; + /* + * When we have a TX context set up, we enforce that the ethertype is + * either IPv4 or IPv6 in igb_get_tx_context(). + */ + if (ctx->lso_flag || ctx->hcksum_flags & HCK_IPV4_HDRCKSUM) { + if (ctx->l3_proto == ETHERTYPE_IP) { + ctx_tbd->type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4; + } else { + ctx_tbd->type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV6; + } + } - if (ctx->hcksum_flags & HCK_PARTIALCKSUM) { + if (ctx->lso_flag || ctx->hcksum_flags & HCK_PARTIALCKSUM) { switch (ctx->l4_proto) { case IPPROTO_TCP: ctx_tbd->type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP; diff --git a/usr/src/uts/common/io/ixgbe/ixgbe_gld.c b/usr/src/uts/common/io/ixgbe/ixgbe_gld.c index ea888220fa..8508e32b82 100644 --- a/usr/src/uts/common/io/ixgbe/ixgbe_gld.c +++ b/usr/src/uts/common/io/ixgbe/ixgbe_gld.c @@ -304,8 +304,10 @@ ixgbe_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) mac_capab_lso_t *cap_lso = cap_data; if (ixgbe->lso_enable) { - cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; + cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4 | + LSO_TX_BASIC_TCP_IPV6; cap_lso->lso_basic_tcp_ipv4.lso_max = IXGBE_LSO_MAXLEN; + cap_lso->lso_basic_tcp_ipv6.lso_max = IXGBE_LSO_MAXLEN; break; } else { return (B_FALSE); diff --git a/usr/src/uts/common/io/ixgbe/ixgbe_sw.h b/usr/src/uts/common/io/ixgbe/ixgbe_sw.h index cfd987787a..8bf93afe9c 100644 --- a/usr/src/uts/common/io/ixgbe/ixgbe_sw.h +++ b/usr/src/uts/common/io/ixgbe/ixgbe_sw.h @@ -408,6 +408,7 @@ typedef struct ixgbe_tx_context { uint32_t hcksum_flags; uint32_t ip_hdr_len; uint32_t mac_hdr_len; + uint32_t l3_proto; uint32_t l4_proto; uint32_t mss; uint32_t l4_hdr_len; diff --git a/usr/src/uts/common/io/ixgbe/ixgbe_tx.c b/usr/src/uts/common/io/ixgbe/ixgbe_tx.c index 9191aad058..b6926fc3b7 100644 --- a/usr/src/uts/common/io/ixgbe/ixgbe_tx.c +++ b/usr/src/uts/common/io/ixgbe/ixgbe_tx.c @@ -697,6 +697,7 @@ ixgbe_get_context(mblk_t *mp, ixgbe_tx_context_t *ctx) uint32_t start; uint32_t hckflags; uint32_t lsoflags; + uint32_t lsocksum; uint32_t mss; uint32_t len; uint32_t size; @@ -722,19 +723,6 @@ ixgbe_get_context(mblk_t *mp, ixgbe_tx_context_t *ctx) ctx->mss = mss; ctx->lso_flag = (lsoflags == HW_LSO); - /* - * LSO relies on tx h/w checksum, so here will drop the package - * if h/w checksum flag is not declared. - */ - if (ctx->lso_flag) { - if (!((ctx->hcksum_flags & HCK_PARTIALCKSUM) && - (ctx->hcksum_flags & HCK_IPV4_HDRCKSUM))) { - IXGBE_DEBUGLOG_0(NULL, "ixgbe_tx: h/w " - "checksum flags are not specified when doing LSO"); - return (-1); - } - } - etype = 0; mac_hdr_len = 0; l4_proto = 0; @@ -779,6 +767,8 @@ ixgbe_get_context(mblk_t *mp, ixgbe_tx_context_t *ctx) * Here we don't assume the IP(V6) header is fully included in * one mblk fragment. */ + lsocksum = HCK_PARTIALCKSUM; + ctx->l3_proto = etype; switch (etype) { case ETHERTYPE_IP: if (ctx->lso_flag) { @@ -810,6 +800,7 @@ ixgbe_get_context(mblk_t *mp, ixgbe_tx_context_t *ctx) * (ip_source_addr, ip_destination_addr, l4_proto) * Currently the tcp/ip stack has done it. */ + lsocksum |= HCK_IPV4_HDRCKSUM; } offset = offsetof(ipha_t, ipha_protocol) + mac_hdr_len; @@ -824,6 +815,21 @@ ixgbe_get_context(mblk_t *mp, ixgbe_tx_context_t *ctx) l4_proto = *(uint8_t *)pos; break; case ETHERTYPE_IPV6: + /* + * We need to zero out the length in the header. + */ + if (ctx->lso_flag) { + offset = offsetof(ip6_t, ip6_plen) + mac_hdr_len; + while (size <= offset) { + mp = mp->b_cont; + ASSERT(mp != NULL); + len = MBLKL(mp); + size += len; + } + pos = mp->b_rptr + offset + len - size; + *((uint16_t *)(uintptr_t)(pos)) = 0; + } + offset = offsetof(ip6_t, ip6_nxt) + mac_hdr_len; while (size <= offset) { mp = mp->b_cont; @@ -842,6 +848,18 @@ ixgbe_get_context(mblk_t *mp, ixgbe_tx_context_t *ctx) } if (ctx->lso_flag) { + /* + * LSO relies on tx h/w checksum, so here will drop the packet + * if h/w checksum flag is not declared. + */ + if ((ctx->hcksum_flags & lsocksum) != lsocksum) { + IXGBE_DEBUGLOG_2(NULL, "ixgbe_tx: h/w checksum flags " + "are not set for LSO, found 0x%x, needed bits 0x%x", + ctx->hcksum_flags, lsocksum); + return (-1); + } + + offset = mac_hdr_len + start; while (size <= offset) { mp = mp->b_cont; @@ -898,6 +916,7 @@ ixgbe_check_context(ixgbe_tx_ring_t *tx_ring, ixgbe_tx_context_t *ctx) if ((ctx->hcksum_flags != last->hcksum_flags) || (ctx->l4_proto != last->l4_proto) || + (ctx->l3_proto != last->l3_proto) || (ctx->mac_hdr_len != last->mac_hdr_len) || (ctx->ip_hdr_len != last->ip_hdr_len) || (ctx->lso_flag != last->lso_flag) || @@ -928,11 +947,19 @@ ixgbe_fill_context(struct ixgbe_adv_tx_context_desc *ctx_tbd, ctx_tbd->type_tucmd_mlhl = IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; + /* + * When we have a TX context set up, we enforce that the ethertype is + * either IPv4 or IPv6 in ixgbe_get_tx_context(). + */ + if (ctx->lso_flag || ctx->hcksum_flags & HCK_IPV4_HDRCKSUM) { + if (ctx->l3_proto == ETHERTYPE_IP) { + ctx_tbd->type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; + } else { + ctx_tbd->type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6; + } + } - if (ctx->hcksum_flags & HCK_IPV4_HDRCKSUM) - ctx_tbd->type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; - - if (ctx->hcksum_flags & HCK_PARTIALCKSUM) { + if (ctx->lso_flag || ctx->hcksum_flags & HCK_PARTIALCKSUM) { switch (ctx->l4_proto) { case IPPROTO_TCP: ctx_tbd->type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; diff --git a/usr/src/uts/common/os/devcfg.c b/usr/src/uts/common/os/devcfg.c index c82a8f86d9..ef2fb9b8a4 100644 --- a/usr/src/uts/common/os/devcfg.c +++ b/usr/src/uts/common/os/devcfg.c @@ -255,7 +255,7 @@ i_ddi_node_cache_init() * The allocated node has a reference count of 0. */ dev_info_t * -i_ddi_alloc_node(dev_info_t *pdip, char *node_name, pnode_t nodeid, +i_ddi_alloc_node(dev_info_t *pdip, const char *node_name, pnode_t nodeid, int instance, ddi_prop_t *sys_prop, int flag) { struct dev_info *devi; @@ -2046,7 +2046,7 @@ ndi_devi_tryenter(dev_info_t *dip, int *circular) * not allowed to sleep. */ int -ndi_devi_alloc(dev_info_t *parent, char *node_name, pnode_t nodeid, +ndi_devi_alloc(dev_info_t *parent, const char *node_name, pnode_t nodeid, dev_info_t **ret_dip) { ASSERT(node_name != NULL); @@ -2066,7 +2066,7 @@ ndi_devi_alloc(dev_info_t *parent, char *node_name, pnode_t nodeid, * This routine may sleep and should not be called at interrupt time */ void -ndi_devi_alloc_sleep(dev_info_t *parent, char *node_name, pnode_t nodeid, +ndi_devi_alloc_sleep(dev_info_t *parent, const char *node_name, pnode_t nodeid, dev_info_t **ret_dip) { ASSERT(node_name != NULL); @@ -2536,7 +2536,7 @@ i_ddi_get_exported_classes(dev_info_t *dip, char ***classes) * Helper functions, returns NULL if no memory. */ char * -i_ddi_strdup(char *str, uint_t flag) +i_ddi_strdup(const char *str, uint_t flag) { char *copy; diff --git a/usr/src/uts/common/sys/autoconf.h b/usr/src/uts/common/sys/autoconf.h index ee97f8d274..5a3ad7df60 100644 --- a/usr/src/uts/common/sys/autoconf.h +++ b/usr/src/uts/common/sys/autoconf.h @@ -274,7 +274,7 @@ extern int exclude_level(int); extern major_t path_to_major(char *); extern void i_ddi_node_cache_init(void); -extern dev_info_t *i_ddi_alloc_node(dev_info_t *, char *, pnode_t, int, +extern dev_info_t *i_ddi_alloc_node(dev_info_t *, const char *, pnode_t, int, ddi_prop_t *, int); extern void i_ddi_forceattach_drivers(void); extern int i_ddi_io_initialized(void); diff --git a/usr/src/uts/common/sys/ddi_implfuncs.h b/usr/src/uts/common/sys/ddi_implfuncs.h index 522366aa23..c5e84e576a 100644 --- a/usr/src/uts/common/sys/ddi_implfuncs.h +++ b/usr/src/uts/common/sys/ddi_implfuncs.h @@ -164,7 +164,7 @@ extern int peekpoke_mem(ddi_ctl_enum_t, peekpoke_ctlops_t *); /* * Helper functions */ -extern char *i_ddi_strdup(char *, uint_t); +extern char *i_ddi_strdup(const char *, uint_t); extern void i_ddi_prop_list_delete(ddi_prop_t *); extern ddi_prop_t *i_ddi_prop_list_dup(ddi_prop_t *, uint_t); extern int i_ddi_load_drvconf(major_t); diff --git a/usr/src/uts/common/sys/sunndi.h b/usr/src/uts/common/sys/sunndi.h index e6a998322d..94313a450e 100644 --- a/usr/src/uts/common/sys/sunndi.h +++ b/usr/src/uts/common/sys/sunndi.h @@ -118,11 +118,11 @@ ndi_prop_remove_all(dev_info_t *dip); * not allowed to sleep. */ int -ndi_devi_alloc(dev_info_t *parent, char *node_name, pnode_t nodeid, +ndi_devi_alloc(dev_info_t *parent, const char *node_name, pnode_t nodeid, dev_info_t **ret_dip); void -ndi_devi_alloc_sleep(dev_info_t *parent, char *node_name, pnode_t nodeid, +ndi_devi_alloc_sleep(dev_info_t *parent, const char *node_name, pnode_t nodeid, dev_info_t **ret_dip); /* @@ -174,7 +174,7 @@ ndi_devi_bind_driver_async(dev_info_t *dip, uint_t flags); */ int ndi_devctl_device_getstate(dev_info_t *parent, struct devctl_iocdata *dcp, - uint_t *state); + uint_t *state); /* * Transition the child addressed by "name@addr" to the online state. @@ -182,7 +182,7 @@ ndi_devctl_device_getstate(dev_info_t *parent, struct devctl_iocdata *dcp, */ int ndi_devctl_device_online(dev_info_t *dip, struct devctl_iocdata *dcp, - uint_t flags); + uint_t flags); /* * Transition the child addressed by "name@addr" to the offline state. @@ -190,7 +190,7 @@ ndi_devctl_device_online(dev_info_t *dip, struct devctl_iocdata *dcp, */ int ndi_devctl_device_offline(dev_info_t *dip, struct devctl_iocdata *dcp, - uint_t flags); + uint_t flags); /* * Remove the child addressed by name@addr. @@ -198,7 +198,7 @@ ndi_devctl_device_offline(dev_info_t *dip, struct devctl_iocdata *dcp, */ int ndi_devctl_device_remove(dev_info_t *dip, struct devctl_iocdata *dcp, - uint_t flags); + uint_t flags); /* * Bus get state @@ -206,7 +206,7 @@ ndi_devctl_device_remove(dev_info_t *dip, struct devctl_iocdata *dcp, */ int ndi_devctl_bus_getstate(dev_info_t *dip, struct devctl_iocdata *dcp, - uint_t *state); + uint_t *state); /* * Place the devinfo in the ONLINE state @@ -219,7 +219,7 @@ ndi_devi_online(dev_info_t *dip, uint_t flags); */ int ndi_devctl_ioctl(dev_info_t *dip, int cmd, intptr_t arg, int mode, - uint_t flags); + uint_t flags); /* * Asynchronous version of ndi_devi_online, callable from interrupt @@ -524,7 +524,7 @@ typedef struct ndi_event_set { */ int ndi_event_alloc_hdl(dev_info_t *dip, ddi_iblock_cookie_t cookie, - ndi_event_hdl_t *ndi_event_hdl, uint_t flag); + ndi_event_hdl_t *ndi_event_hdl, uint_t flag); /* * free the ndi event handle @@ -536,40 +536,28 @@ ndi_event_free_hdl(ndi_event_hdl_t handle); * bind or unbind a set of events to/from the event handle */ int -ndi_event_bind_set(ndi_event_hdl_t handle, - ndi_event_set_t *ndi_event_set, - uint_t flag); +ndi_event_bind_set(ndi_event_hdl_t handle, ndi_event_set_t *ndi_event_set, + uint_t flag); int -ndi_event_unbind_set(ndi_event_hdl_t handle, - ndi_event_set_t *ndi_event_set, - uint_t flag); +ndi_event_unbind_set(ndi_event_hdl_t handle, ndi_event_set_t *ndi_event_set, + uint_t flag); /* * get an event cookie */ int -ndi_event_retrieve_cookie(ndi_event_hdl_t handle, - dev_info_t *child_dip, - char *eventname, - ddi_eventcookie_t *cookiep, - uint_t flag); +ndi_event_retrieve_cookie(ndi_event_hdl_t handle, dev_info_t *child_dip, + char *eventname, ddi_eventcookie_t *cookiep, uint_t flag); /* * add an event callback info to the ndi event handle */ int -ndi_event_add_callback(ndi_event_hdl_t handle, - dev_info_t *child_dip, - ddi_eventcookie_t cookie, - void (*event_callback) - (dev_info_t *, - ddi_eventcookie_t, - void *arg, - void *impldata), - void *arg, - uint_t flag, - ddi_callback_id_t *cb_id); +ndi_event_add_callback(ndi_event_hdl_t handle, dev_info_t *child_dip, + ddi_eventcookie_t cookie, void (*event_callback)(dev_info_t *, + ddi_eventcookie_t, void *arg, void *impldata), void *arg, uint_t flag, + ddi_callback_id_t *cb_id); /* * remove an event callback registration from the ndi event handle @@ -588,7 +576,7 @@ ndi_event_run_callbacks(ndi_event_hdl_t handle, dev_info_t *child_dip, * do callback for just one child_dip, regardless of attributes */ int ndi_event_do_callback(ndi_event_hdl_t handle, dev_info_t *child_dip, - ddi_eventcookie_t cookie, void *bus_impldata); + ddi_eventcookie_t cookie, void *bus_impldata); /* * ndi_event_tag_to_cookie: utility function to find an event cookie @@ -603,7 +591,7 @@ ndi_event_tag_to_cookie(ndi_event_hdl_t handle, int event_tag); */ int ndi_event_cookie_to_tag(ndi_event_hdl_t handle, - ddi_eventcookie_t cookie); + ddi_eventcookie_t cookie); /* * ndi_event_cookie_to_name: utility function to find an event @@ -611,7 +599,7 @@ ndi_event_cookie_to_tag(ndi_event_hdl_t handle, */ char * ndi_event_cookie_to_name(ndi_event_hdl_t handle, - ddi_eventcookie_t cookie); + ddi_eventcookie_t cookie); /* * ndi_event_tag_to_name: utility function to find an event @@ -681,7 +669,7 @@ typedef struct ndi_ra_request { uint64_t ra_boundlen; /* Length of the area, starting */ /* from ra_boundbase, for the */ /* allocated resource to be */ - /* restricted to. */ + /* restricted to. */ uint64_t ra_align_mask; /* Alignment mask used for */ /* allocated base address */ @@ -743,11 +731,11 @@ ndi_ra_map_destroy(dev_info_t *dip, char *type); int ndi_ra_alloc(dev_info_t *dip, ndi_ra_request_t *req, uint64_t *basep, - uint64_t *lenp, char *type, uint_t flag); + uint64_t *lenp, char *type, uint_t flag); int ndi_ra_free(dev_info_t *dip, uint64_t base, uint64_t len, char *type, - uint_t flag); + uint_t flag); /* * ndi_dev_is_prom_node: Return non-zero if the node is a prom node diff --git a/usr/src/uts/intel/bge/Makefile b/usr/src/uts/intel/bge/Makefile index 456cbc9043..95527d4424 100644 --- a/usr/src/uts/intel/bge/Makefile +++ b/usr/src/uts/intel/bge/Makefile @@ -39,7 +39,6 @@ UTSBASE = ../.. # MODULE = bge OBJECTS = $(BGE_OBJS:%=$(OBJS_DIR)/%) -LINTS = $(LINTS_DIR)/bge_lint.ln ROOTMODULE = $(ROOT_DRV_DIR)/$(MODULE) CONF_SRCDIR = $(UTSBASE)/common/io/bge @@ -52,7 +51,6 @@ include $(UTSBASE)/intel/Makefile.intel # Define targets # ALL_TARGET = $(BINARY) -LINT_TARGET = $(MODULE).lint INSTALL_TARGET = $(BINARY) $(ROOTMODULE) $(ROOT_CONFFILE) # @@ -63,7 +61,6 @@ INSTALL_TARGET = $(BINARY) $(ROOTMODULE) $(ROOT_CONFFILE) # to investigate and remove these for maximum lint coverage. # Please do not carry these forward to new Makefiles. # -LINTTAGS += -erroff=E_BAD_PTR_CAST_ALIGN CERRWARN += $(CNOWARN_UNINIT) CERRWARN += -_gcc=-Wno-switch @@ -92,12 +89,6 @@ clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) -lint: $(LINT_DEPS) - -modlintlib: $(MODLINTLIB_DEPS) - -clean.lint: $(CLEAN_LINT_DEPS) - install: $(INSTALL_DEPS) # diff --git a/usr/src/uts/intel/os/driver_aliases b/usr/src/uts/intel/os/driver_aliases index 8f4c2f1bf2..7e8c801f03 100644 --- a/usr/src/uts/intel/os/driver_aliases +++ b/usr/src/uts/intel/os/driver_aliases @@ -142,6 +142,16 @@ bge "pci108e,1647" bge "pci108e,1648" bge "pci108e,16a7" bge "pci108e,16a8" +bge "pci14e4,0x1682" +bge "pci14e4,0x1686" +bge "pci14e4,0x16b0" +bge "pci14e4,0x16b1" +bge "pci14e4,0x16b2" +bge "pci14e4,0x16b3" +bge "pci14e4,0x16b4" +bge "pci14e4,0x16b5" +bge "pci14e4,0x16b6" +bge "pci14e4,0x16b7" bge "pci14e4,1600" bge "pci14e4,1601" bge "pci14e4,1643" @@ -176,6 +186,16 @@ bge "pci14e4,16a7" bge "pci14e4,16a8" bge "pci14e4,16c7" bge "pci14e4,16f3" +bge "pciex14e4,0x1682" +bge "pciex14e4,0x1686" +bge "pciex14e4,0x16b0" +bge "pciex14e4,0x16b1" +bge "pciex14e4,0x16b2" +bge "pciex14e4,0x16b3" +bge "pciex14e4,0x16b4" +bge "pciex14e4,0x16b5" +bge "pciex14e4,0x16b6" +bge "pciex14e4,0x16b7" bge "pciex14e4,1643" bge "pciex14e4,1655" bge "pciex14e4,1656" diff --git a/usr/src/uts/sparc/bge/Makefile b/usr/src/uts/sparc/bge/Makefile index a0b56a51b0..0a8b2cabc4 100644 --- a/usr/src/uts/sparc/bge/Makefile +++ b/usr/src/uts/sparc/bge/Makefile @@ -39,7 +39,6 @@ UTSBASE = ../.. # MODULE = bge OBJECTS = $(BGE_OBJS:%=$(OBJS_DIR)/%) -LINTS = $(LINTS_DIR)/bge_lint.ln ROOTMODULE = $(ROOT_DRV_DIR)/$(MODULE) CONF_SRCDIR = $(UTSBASE)/common/io/bge @@ -52,7 +51,6 @@ include $(UTSBASE)/sparc/Makefile.sparc # Define targets # ALL_TARGET = $(BINARY) -LINT_TARGET = $(MODULE).lint INSTALL_TARGET = $(BINARY) $(ROOTMODULE) $(ROOT_CONFFILE) # @@ -75,7 +73,6 @@ LDFLAGS += -dy -N misc/mac # to investigate and remove these for maximum lint coverage. # Please do not carry these forward to new Makefiles. # -LINTTAGS += -erroff=E_BAD_PTR_CAST_ALIGN CERRWARN += $(CNOWARN_UNINIT) CERRWARN += -_gcc=-Wno-switch @@ -96,12 +93,6 @@ clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) -lint: $(LINT_DEPS) - -modlintlib: $(MODLINTLIB_DEPS) - -clean.lint: $(CLEAN_LINT_DEPS) - install: $(INSTALL_DEPS) # |
