* Copyright (c) 1980, 1991 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)err.c 5.6 (Berkeley) %G%";
#define _h_tc_err /* Don't redefine the errors */
char *seterr
= (char *) 0; /* 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 [-rht] [# 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]))
xvsprintf(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
== (char *) 0)
if (id
< 0 || id
> sizeof(errorlist
) / sizeof(errorlist
[0]))
* Must flush before we print as we wish output before the error to go on
* (some form of) standard output, while output after goes on (some form
* of) diagnostic output. If didfds then output will go to 1/2 else to
* FSHOUT/FSHDIAG. See flush in sh.print.c.
haderr
= 1; /* Now to diagnostic output */
timflg
= 0; /* This isn't otherwise reset */
if (!(flags
& ERR_SILENT
)) {
xprintf("%s.\n", seterr
);
xvprintf(errorlist
[id
], va
);
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
);