2017-06-08 16:12:17 +03:00
|
|
|
# $NetBSD: nodetypes,v 1.18 2017/06/08 13:12:17 kre Exp $
|
1994-05-11 21:09:42 +04:00
|
|
|
# Copyright (c) 1991, 1993
|
|
|
|
# The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
#
|
|
|
|
# This code is derived from software contributed to Berkeley by
|
|
|
|
# Kenneth Almquist.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
2003-08-22 15:22:23 +04:00
|
|
|
# 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
# may be used to endorse or promote products derived from this software
|
|
|
|
# without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
#
|
1995-05-12 01:28:33 +04:00
|
|
|
# @(#)nodetypes 8.2 (Berkeley) 5/4/95
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
# This file describes the nodes used in parse trees. Unindented lines
|
|
|
|
# contain a node type followed by a structure tag. Subsequent indented
|
|
|
|
# lines specify the fields of the structure. Several node types can share
|
|
|
|
# the same structure, in which case the fields of the structure should be
|
|
|
|
# specified only once.
|
|
|
|
#
|
|
|
|
# A field of a structure is described by the name of the field followed
|
|
|
|
# by a type. The currently implemented types are:
|
|
|
|
# nodeptr - a pointer to a node
|
|
|
|
# nodelist - a pointer to a list of nodes
|
|
|
|
# string - a pointer to a nul terminated string
|
|
|
|
# int - an integer
|
|
|
|
# other - any type that can be copied by assignment
|
|
|
|
# temp - a field that doesn't have to be copied when the node is copied
|
|
|
|
# The last two types should be followed by the text of a C declaration for
|
|
|
|
# the field.
|
|
|
|
|
|
|
|
NSEMI nbinary # two commands separated by a semicolon
|
|
|
|
type int
|
|
|
|
ch1 nodeptr # the first child
|
|
|
|
ch2 nodeptr # the second child
|
|
|
|
|
|
|
|
NCMD ncmd # a simple command
|
|
|
|
type int
|
|
|
|
backgnd int # set to run command in background
|
|
|
|
args nodeptr # the arguments
|
|
|
|
redirect nodeptr # list of file redirections
|
An initial attempt at implementing LINENO to meet the specs.
Aside from one problem (not too hard to fix if it was ever needed) this version
does about as well as most other shell implementations when expanding
$((LINENO)) and better for ${LINENO} as it retains the "LINENO hack" for the
latter, and that is very accurate.
Unfortunately that means that ${LINENO} and $((LINENO)) do not always produce
the same value when used on the same line (a defect that other shells do not
share - aside from the FreeBSD sh as it is today, where only the LINENO hack
exists and so (like for us before this commit) $((LINENO)) is always either
0, or at least whatever value was last set, perhaps by
LINENO=${LINENO}
which does actually work ... for that one line...)
This could be corrected by simply removing the LINENO hack (look for the string
LINENO in parser.c) in which case ${LINENO} and $((LINENO)) would give the
same (not perfectly accurate) values, as do most other shells.
POSIX requires that LINENO be set before each command, and this implementation
does that fairly literally - except that we only bother before the commands
which actually expand words (for, case and simple commands). Unfortunately
this forgot that expansions also occur in redirects, and the other compound
commands can also have redirects, so if a redirect on one of the other compound
commands wants to use the value of $((LINENO)) as a part of a generated file
name, then it will get an incorrect value. This is the "one problem" above.
(Because the LINENO hack is still enabled, using ${LINENO} works.)
This could be fixed, but as this version of the LINENO implementation is just
for reference purposes (it will be superseded within minutes by a better one)
I won't bother. However should anyone else decide that this is a better choice
(it is probably a smaller implementation, in terms of code & data space then
the replacement, but also I would expect, slower, and definitely less accurate)
this defect is something to bear in mind, and fix.
This version retains the *BSD historical practice that line numbers in functions
(all functions) count from 1 from the start of the function, and elsewhere,
start from 1 from where the shell started reading the input file/stream in
question. In an "eval" expression the line number starts at the line of the
"eval" (and then increases if the input is a multi-line string).
Note: this version is not documented (beyond as much as LINENO was before)
hence this slightly longer than usual commit message.
2017-06-07 07:44:17 +03:00
|
|
|
lineno int
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
NPIPE npipe # a pipeline
|
|
|
|
type int
|
|
|
|
backgnd int # set to run pipeline in background
|
|
|
|
cmdlist nodelist # the commands in the pipeline
|
|
|
|
|
2002-11-25 01:35:38 +03:00
|
|
|
NREDIR nredir # redirection (of a complex command)
|
1993-03-21 12:45:37 +03:00
|
|
|
type int
|
|
|
|
n nodeptr # the command
|
|
|
|
redirect nodeptr # list of file redirections
|
|
|
|
|
|
|
|
NBACKGND nredir # run command in background
|
|
|
|
NSUBSHELL nredir # run command in a subshell
|
|
|
|
|
|
|
|
NAND nbinary # the && operator
|
|
|
|
NOR nbinary # the || operator
|
|
|
|
|
|
|
|
NIF nif # the if statement. Elif clauses are handled
|
|
|
|
type int # using multiple if nodes.
|
|
|
|
test nodeptr # if test
|
|
|
|
ifpart nodeptr # then ifpart
|
|
|
|
elsepart nodeptr # else elsepart
|
|
|
|
|
|
|
|
NWHILE nbinary # the while statement. First child is the test
|
|
|
|
NUNTIL nbinary # the until statement
|
|
|
|
|
|
|
|
NFOR nfor # the for statement
|
|
|
|
type int
|
|
|
|
args nodeptr # for var in args
|
|
|
|
body nodeptr # do body; done
|
|
|
|
var string # the for variable
|
|
|
|
|
|
|
|
NCASE ncase # a case statement
|
|
|
|
type int
|
|
|
|
expr nodeptr # the word to switch on
|
|
|
|
cases nodeptr # the list of cases (NCLIST nodes)
|
An initial attempt at implementing LINENO to meet the specs.
Aside from one problem (not too hard to fix if it was ever needed) this version
does about as well as most other shell implementations when expanding
$((LINENO)) and better for ${LINENO} as it retains the "LINENO hack" for the
latter, and that is very accurate.
Unfortunately that means that ${LINENO} and $((LINENO)) do not always produce
the same value when used on the same line (a defect that other shells do not
share - aside from the FreeBSD sh as it is today, where only the LINENO hack
exists and so (like for us before this commit) $((LINENO)) is always either
0, or at least whatever value was last set, perhaps by
LINENO=${LINENO}
which does actually work ... for that one line...)
This could be corrected by simply removing the LINENO hack (look for the string
LINENO in parser.c) in which case ${LINENO} and $((LINENO)) would give the
same (not perfectly accurate) values, as do most other shells.
POSIX requires that LINENO be set before each command, and this implementation
does that fairly literally - except that we only bother before the commands
which actually expand words (for, case and simple commands). Unfortunately
this forgot that expansions also occur in redirects, and the other compound
commands can also have redirects, so if a redirect on one of the other compound
commands wants to use the value of $((LINENO)) as a part of a generated file
name, then it will get an incorrect value. This is the "one problem" above.
(Because the LINENO hack is still enabled, using ${LINENO} works.)
This could be fixed, but as this version of the LINENO implementation is just
for reference purposes (it will be superseded within minutes by a better one)
I won't bother. However should anyone else decide that this is a better choice
(it is probably a smaller implementation, in terms of code & data space then
the replacement, but also I would expect, slower, and definitely less accurate)
this defect is something to bear in mind, and fix.
This version retains the *BSD historical practice that line numbers in functions
(all functions) count from 1 from the start of the function, and elsewhere,
start from 1 from where the shell started reading the input file/stream in
question. In an "eval" expression the line number starts at the line of the
"eval" (and then increases if the input is a multi-line string).
Note: this version is not documented (beyond as much as LINENO was before)
hence this slightly longer than usual commit message.
2017-06-07 07:44:17 +03:00
|
|
|
lineno int
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2017-05-04 07:37:51 +03:00
|
|
|
NCLISTCONT nclist # a case terminated by ';&' (fall through)
|
1993-03-21 12:45:37 +03:00
|
|
|
NCLIST nclist # a case
|
|
|
|
type int
|
|
|
|
next nodeptr # the next case in list
|
|
|
|
pattern nodeptr # list of patterns for this case
|
|
|
|
body nodeptr # code to execute for this case
|
A better LINENO implementation. This version deletes (well, #if 0's out)
the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)).
(Code to invert the LINENO hack when required, like when de-compiling the
execution tree to provide the "jobs" command strings, is still included,
that can be deleted when the LINENO hack is completely removed - look for
refs to VSLINENO throughout the code. The var funclinno in parser.c can
also be removed, it is used only for the LINENO hack.)
This version produces accurate results: $((LINENO)) was made as accurate
as the LINENO hack made ${LINENO} which is very good. That's why the
LINENO hack is not yet completely removed, so it can be easily re-enabled.
If you can tell the difference when it is in use, or not in use, then
something has broken (or I managed to miss a case somewhere.)
The way that LINENO works is documented in its own (new) section in the
man page, so nothing more about that, or the new options, etc, here.
This version introduces the possibility of having a "reference" function
associated with a variable, which gets called whenever the value of the
variable is required (that's what implements LINENO). There is just
one function pointer however, so any particular variable gets at most
one of the set function (as used for PATH, etc) or the reference function.
The VFUNCREF bit in the var flags indicates which func the variable in
question uses (if any - the func ptr, as before, can be NULL).
I would not call the results of this perfect yet, but it is close.
2017-06-07 08:08:32 +03:00
|
|
|
lineno int
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
NDEFUN narg # define a function. The "next" field contains
|
|
|
|
# the body of the function.
|
|
|
|
|
|
|
|
NARG narg # represents a word
|
|
|
|
type int
|
|
|
|
next nodeptr # next word in list
|
|
|
|
text string # the text of the word
|
|
|
|
backquote nodelist # list of commands in back quotes
|
A better LINENO implementation. This version deletes (well, #if 0's out)
the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)).
(Code to invert the LINENO hack when required, like when de-compiling the
execution tree to provide the "jobs" command strings, is still included,
that can be deleted when the LINENO hack is completely removed - look for
refs to VSLINENO throughout the code. The var funclinno in parser.c can
also be removed, it is used only for the LINENO hack.)
This version produces accurate results: $((LINENO)) was made as accurate
as the LINENO hack made ${LINENO} which is very good. That's why the
LINENO hack is not yet completely removed, so it can be easily re-enabled.
If you can tell the difference when it is in use, or not in use, then
something has broken (or I managed to miss a case somewhere.)
The way that LINENO works is documented in its own (new) section in the
man page, so nothing more about that, or the new options, etc, here.
This version introduces the possibility of having a "reference" function
associated with a variable, which gets called whenever the value of the
variable is required (that's what implements LINENO). There is just
one function pointer however, so any particular variable gets at most
one of the set function (as used for PATH, etc) or the reference function.
The VFUNCREF bit in the var flags indicates which func the variable in
question uses (if any - the func ptr, as before, can be NULL).
I would not call the results of this perfect yet, but it is close.
2017-06-07 08:08:32 +03:00
|
|
|
lineno int
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
NTO nfile # fd> fname
|
2002-05-15 20:33:35 +04:00
|
|
|
NCLOBBER nfile # fd>| fname
|
1993-03-21 12:45:37 +03:00
|
|
|
NFROM nfile # fd< fname
|
1999-02-04 19:17:39 +03:00
|
|
|
NFROMTO nfile # fd<> fname
|
1993-03-21 12:45:37 +03:00
|
|
|
NAPPEND nfile # fd>> fname
|
|
|
|
type int
|
|
|
|
next nodeptr # next redirection in list
|
|
|
|
fd int # file descriptor being redirected
|
|
|
|
fname nodeptr # file name, in a NARG node
|
|
|
|
expfname temp char *expfname # actual file name
|
|
|
|
|
|
|
|
NTOFD ndup # fd<&dupfd
|
|
|
|
NFROMFD ndup # fd>&dupfd
|
|
|
|
type int
|
|
|
|
next nodeptr # next redirection in list
|
|
|
|
fd int # file descriptor being redirected
|
|
|
|
dupfd int # file descriptor to duplicate
|
1994-06-14 09:49:19 +04:00
|
|
|
vname nodeptr # file name if fd>&$var
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-05-12 01:28:33 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
NHERE nhere # fd<<\!
|
|
|
|
NXHERE nhere # fd<<!
|
|
|
|
type int
|
|
|
|
next nodeptr # next redirection in list
|
|
|
|
fd int # file descriptor being redirected
|
|
|
|
doc nodeptr # input to command (NARG node)
|
1994-05-11 21:09:42 +04:00
|
|
|
|
|
|
|
NNOT nnot # ! command (actually pipeline)
|
2017-05-09 08:14:03 +03:00
|
|
|
NDNOT nnot # ! ! pipeline (optimisation)
|
2009-05-26 11:30:51 +04:00
|
|
|
type int
|
|
|
|
com nodeptr
|