* Copyright (c) 1980, 1991, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 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
static char sccsid
[] = "@(#)err.c 8.1 (Berkeley) 5/31/93";
char *seterr
= NULL
; /* Holds last error if there was one */
#define ERR_FLAGS 0xf0000000
#define ERR_NAME 0x10000000
#define ERR_SILENT 0x20000000
#define ERR_OLD 0x40000000
static char *errorlist
[] =
"Incomplete [] modifier",
"$ expansion must end before ]",
"Bad : modifier in $ (%c)",
"Too dangerous to alias that",
"Words not parenthesized",
"Improper or unknown scale factor",
"Directory stack not that deep",
"Unknown signal; kill -l lists signals",
"Variable name must begin with a letter",
#define ERR_VARTOOLONG 31
"Variable name too long",
"Variable name must contain alphanumeric characters",
#define ERR_JOBCONTROL 33
"No job control in this shell",
#define ERR_EXPRESSION 34
#define ERR_CANTCHANGE 36
"Can't change to home directory",
"Assignment missing expression",
"Subscript out of range",
"Unknown variable modifier",
"Arguments should be jobs or process id's",
"No job matches pattern",
"Fork nesting > %d; maybe `...` loop",
#define ERR_JOBCTRLSUB 63
"No job control in subshells",
"%sThere are suspended jobs",
"No operand for -h flag",
"Bad scaling; did you mean \"%s\"?",
"Can't suspend a login shell (yet)",
"Usage: history [-rh] [# number of events]",
"$, ! or < not allowed with $# or $?",
"Newline in variable name",
"* not allowed with $# or $?",
"$?<digit> or $#<digit> not allowed",
"Newline in variable index",
"Expansion buffer overflow",
"No previous substitute",
"No previous left hand side",
"Right hand side too long",
#define ERR_BADBANGMOD 92
"Substitution buffer overflow",
#define ERR_BADBANGARG 95
"Missing name for redirect",
"Ambiguous output redirect",
"Ambiguous input redirect",
#define ERR_ALIASLOOP 105
"%s: %s. Wrong Architecture",
"Malformed file inquiry",
* The parser and scanner set up errors for later by calling seterr,
* which sets the variable err as a side effect; later to be tested,
if (id
< 0 || id
> sizeof(errorlist
) / sizeof(errorlist
[0]))
vsprintf(berr
, errorlist
[id
], va
);
* Print the error with the given id.
* ERR_SILENT: Print nothing.
* ERR_OLD: Print the previously set error if one was there.
* ERR_NAME: If this bit is set, print the name of the function
* This routine always resets or exits. The flag haderr
* is set so the routine who catches the unwind can propogate
* Note that any open files at the point of error will eventually
* be closed in the routine process in sh.c which is the only
* place error unwinds are ever caught.
int flags
= id
& ERR_FLAGS
;
if ((flags
& ERR_OLD
) && seterr
== NULL
)
if (id
< 0 || id
> sizeof(errorlist
) / sizeof(errorlist
[0]))
haderr
= 1; /* Now to diagnostic output */
timflg
= 0; /* This isn't otherwise reset */
if (!(flags
& ERR_SILENT
)) {
(void) fprintf(csherr
, "%s: ", bname
);
(void) fprintf(csherr
, "%s.\n", seterr
);
(void) vfprintf(csherr
, errorlist
[id
], va
);
(void) fprintf(csherr
, ".\n");
didfds
= 0; /* Forget about 0,1,2 */
* Go away if -e or we are a child shell
* Reset the state of the input. This buffered seek to end of file will
* also clear the while/foreach stack.
set(STRstatus
, Strsave(STR1
));
(void) tcsetpgrp(FSHTTY
, tpgrp
);