2018-06-22 14:04:55 +03:00
|
|
|
/* $NetBSD: exec.h,v 1.27 2018/06/22 11:04:55 kre Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
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-07 13:05:01 +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-06-09 05:53:44 +04:00
|
|
|
* @(#)exec.h 8.3 (Berkeley) 6/8/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* values of cmdtype */
|
2003-01-22 23:36:03 +03:00
|
|
|
#define CMDUNKNOWN -1 /* no entry in table for command */
|
|
|
|
#define CMDNORMAL 0 /* command is an executable program */
|
|
|
|
#define CMDFUNCTION 1 /* command is a shell function */
|
|
|
|
#define CMDBUILTIN 2 /* command is a shell builtin */
|
|
|
|
#define CMDSPLBLTIN 3 /* command is a special shell builtin */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
struct cmdentry {
|
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
|
|
|
short cmdtype;
|
|
|
|
short lno_frel; /* for functions: Line numbers count from 1 */
|
|
|
|
int lineno; /* for functions: Abs line number of defn */
|
1993-03-21 12:45:37 +03:00
|
|
|
union param {
|
|
|
|
int index;
|
2002-11-25 01:35:38 +03:00
|
|
|
int (*bltin)(int, char**);
|
2018-06-22 14:04:55 +03:00
|
|
|
struct funcdef *func;
|
1993-03-21 12:45:37 +03:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-01-22 23:36:03 +03:00
|
|
|
/* action to find_command() */
|
|
|
|
#define DO_ERR 0x01 /* prints errors */
|
|
|
|
#define DO_ABS 0x02 /* checks absolute paths */
|
|
|
|
#define DO_NOFUNC 0x04 /* don't return shell functions, for command */
|
|
|
|
#define DO_ALTPATH 0x08 /* using alternate path */
|
|
|
|
#define DO_ALTBLTIN 0x20 /* %builtin in alt. path */
|
1997-07-21 01:27:35 +04:00
|
|
|
|
1999-07-09 07:05:49 +04:00
|
|
|
extern const char *pathopt; /* set by padvance */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2012-03-15 06:02:20 +04:00
|
|
|
void shellexec(char **, char **, const char *, int, int) __dead;
|
Make cd (really) do cd -P, and not just claim that is what it is doing
while doing a half-hearted, broken, partial, version of cd -L instead.
The latter (as the manual says) is not supported, what's more, it is an
abomination, and should never be supported (anywhere.)
Fix the doc so that the pretense that we notice when a path given crosses
a symlink (and turns on printing of the destination directory) is claimed
no more (that used to be true until late Dec 2016, but was changed). Now
the print happens if -o cdprint is set, or if an entry from CDPATH that is
not "" or "." is used (or if the "cd dest repl" cd cmd variant is used.)
Fix CDPATH processing: avoid the magic '%' processing that is used for
PATH and MAILPATH from corrupting CDPATH. The % magic (both variants)
remains undocumented.
Also, don't double the '/' if an entry in PATH or CDPATH ends in '/'
(as in CDPATH=":/usr/src/"). A "cd usr.bin" used to do
chdir("/usr/src//usr.bin"). No more. This is almost invisible,
and relatively harmless, either way....
Also fix a bug where if a plausible destination directory in CDPATH
was located, but the chdir() failed (eg: permission denied) and then
a later "." or "" CDPATH entry succeeded, "print" mode was turned on.
That is:
cd /tmp; mkdir bin
mkdir -p P/bin; chmod 0 P/bin
CDPATH=/tmp/P:
cd bin
would cd to /tmp/bin (correctly) but print it (incorrectly).
Also when in "cd dest replace" mode, if the result of the replacement
generates '-' as the path named, as in:
cd $PWD -
then simply change to '-' (or attempt to, with CDPATH search), rather
than having this being equivalent to "cd -")
Because of these changes, the pwd command (and $PWD) essentially
always acts as pwd -P, even when called as pwd -L (which is still
the default.) That is, even more than it did before.
Also fixed a (kind of minor) mem management error (CDPATH related)
"whosoever shall padvance must stunalloc before repeating" (and the
same for MAILPATH).
2017-06-04 23:27:14 +03:00
|
|
|
char *padvance(const char **, const char *, int);
|
2002-11-25 01:35:38 +03:00
|
|
|
void find_command(char *, struct cmdentry *, int, const char *);
|
|
|
|
int (*find_builtin(char *))(int, char **);
|
|
|
|
int (*find_splbltin(char *))(int, char **);
|
|
|
|
void hashcd(void);
|
|
|
|
void changepath(const char *);
|
|
|
|
void deletefuncs(void);
|
|
|
|
void getcmdentry(char *, struct cmdentry *);
|
2018-06-22 14:04:55 +03:00
|
|
|
union node;
|
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
|
|
|
void defun(char *, union node *, int);
|
2002-11-25 01:35:38 +03:00
|
|
|
int unsetfunc(char *);
|
|
|
|
void hash_special_builtins(void);
|