1c80476e4SDavid E. O'Brien /*
2c80476e4SDavid E. O'Brien * sh.err.c: Error printing routines.
3c80476e4SDavid E. O'Brien */
4c80476e4SDavid E. O'Brien /*-
5c80476e4SDavid E. O'Brien * Copyright (c) 1980, 1991 The Regents of the University of California.
6c80476e4SDavid E. O'Brien * All rights reserved.
7c80476e4SDavid E. O'Brien *
8c80476e4SDavid E. O'Brien * Redistribution and use in source and binary forms, with or without
9c80476e4SDavid E. O'Brien * modification, are permitted provided that the following conditions
10c80476e4SDavid E. O'Brien * are met:
11c80476e4SDavid E. O'Brien * 1. Redistributions of source code must retain the above copyright
12c80476e4SDavid E. O'Brien * notice, this list of conditions and the following disclaimer.
13c80476e4SDavid E. O'Brien * 2. Redistributions in binary form must reproduce the above copyright
14c80476e4SDavid E. O'Brien * notice, this list of conditions and the following disclaimer in the
15c80476e4SDavid E. O'Brien * documentation and/or other materials provided with the distribution.
1629301572SMark Peek * 3. Neither the name of the University nor the names of its contributors
17c80476e4SDavid E. O'Brien * may be used to endorse or promote products derived from this software
18c80476e4SDavid E. O'Brien * without specific prior written permission.
19c80476e4SDavid E. O'Brien *
20c80476e4SDavid E. O'Brien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21c80476e4SDavid E. O'Brien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22c80476e4SDavid E. O'Brien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23c80476e4SDavid E. O'Brien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24c80476e4SDavid E. O'Brien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25c80476e4SDavid E. O'Brien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26c80476e4SDavid E. O'Brien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27c80476e4SDavid E. O'Brien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28c80476e4SDavid E. O'Brien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29c80476e4SDavid E. O'Brien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30c80476e4SDavid E. O'Brien * SUCH DAMAGE.
31c80476e4SDavid E. O'Brien */
32c80476e4SDavid E. O'Brien #define _h_sh_err /* Don't redefine the errors */
33c80476e4SDavid E. O'Brien #include "sh.h"
3445e5710bSMark Peek #include <assert.h>
35c80476e4SDavid E. O'Brien
36c80476e4SDavid E. O'Brien /*
37c80476e4SDavid E. O'Brien * C Shell
38c80476e4SDavid E. O'Brien */
39c80476e4SDavid E. O'Brien
40c80476e4SDavid E. O'Brien #ifdef lint
41c80476e4SDavid E. O'Brien #undef va_arg
42c80476e4SDavid E. O'Brien #define va_arg(a, b) (a ? (b) 0 : (b) 0)
43c80476e4SDavid E. O'Brien #endif
44c80476e4SDavid E. O'Brien
45c80476e4SDavid E. O'Brien char *seterr = NULL; /* Holds last error if there was one */
46*d803a9d0SBrooks Davis extern int enterhist;
47c80476e4SDavid E. O'Brien
48c80476e4SDavid E. O'Brien #define ERR_FLAGS 0xf0000000
49c80476e4SDavid E. O'Brien #define ERR_NAME 0x10000000
50c80476e4SDavid E. O'Brien #define ERR_SILENT 0x20000000
51c80476e4SDavid E. O'Brien #define ERR_OLD 0x40000000
529ccc37e3SMark Peek #define ERR_INTERRUPT 0x80000000
53c80476e4SDavid E. O'Brien
54c80476e4SDavid E. O'Brien #define ERR_SYNTAX 0
55c80476e4SDavid E. O'Brien #define ERR_NOTALLOWED 1
56c80476e4SDavid E. O'Brien #define ERR_WTOOLONG 2
57c80476e4SDavid E. O'Brien #define ERR_LTOOLONG 3
58c80476e4SDavid E. O'Brien #define ERR_DOLZERO 4
59c80476e4SDavid E. O'Brien #define ERR_INCBR 5
60c80476e4SDavid E. O'Brien #define ERR_EXPORD 6
61c80476e4SDavid E. O'Brien #define ERR_BADMOD 7
62c80476e4SDavid E. O'Brien #define ERR_SUBSCRIPT 8
63c80476e4SDavid E. O'Brien #define ERR_BADNUM 9
64c80476e4SDavid E. O'Brien #define ERR_NOMORE 10
65c80476e4SDavid E. O'Brien #define ERR_FILENAME 11
66c80476e4SDavid E. O'Brien #define ERR_GLOB 12
67c80476e4SDavid E. O'Brien #define ERR_COMMAND 13
68c80476e4SDavid E. O'Brien #define ERR_TOOFEW 14
69c80476e4SDavid E. O'Brien #define ERR_TOOMANY 15
70c80476e4SDavid E. O'Brien #define ERR_DANGER 16
71c80476e4SDavid E. O'Brien #define ERR_EMPTYIF 17
72c80476e4SDavid E. O'Brien #define ERR_IMPRTHEN 18
73c80476e4SDavid E. O'Brien #define ERR_NOPAREN 19
74c80476e4SDavid E. O'Brien #define ERR_NOTFOUND 20
75c80476e4SDavid E. O'Brien #define ERR_MASK 21
76c80476e4SDavid E. O'Brien #define ERR_LIMIT 22
77c80476e4SDavid E. O'Brien #define ERR_TOOLARGE 23
78c80476e4SDavid E. O'Brien #define ERR_SCALEF 24
79c80476e4SDavid E. O'Brien #define ERR_UNDVAR 25
80c80476e4SDavid E. O'Brien #define ERR_DEEP 26
81c80476e4SDavid E. O'Brien #define ERR_BADSIG 27
82c80476e4SDavid E. O'Brien #define ERR_UNKSIG 28
83c80476e4SDavid E. O'Brien #define ERR_VARBEGIN 29
84c80476e4SDavid E. O'Brien #define ERR_VARTOOLONG 30
85c80476e4SDavid E. O'Brien #define ERR_VARALNUM 31
86c80476e4SDavid E. O'Brien #define ERR_JOBCONTROL 32
87c80476e4SDavid E. O'Brien #define ERR_EXPRESSION 33
88c80476e4SDavid E. O'Brien #define ERR_NOHOMEDIR 34
89c80476e4SDavid E. O'Brien #define ERR_CANTCHANGE 35
90c80476e4SDavid E. O'Brien #define ERR_NULLCOM 36
91c80476e4SDavid E. O'Brien #define ERR_ASSIGN 37
92c80476e4SDavid E. O'Brien #define ERR_UNKNOWNOP 38
93c80476e4SDavid E. O'Brien #define ERR_AMBIG 39
94c80476e4SDavid E. O'Brien #define ERR_EXISTS 40
95c80476e4SDavid E. O'Brien #define ERR_ARGC 41
96c80476e4SDavid E. O'Brien #define ERR_INTR 42
97c80476e4SDavid E. O'Brien #define ERR_RANGE 43
98c80476e4SDavid E. O'Brien #define ERR_OVERFLOW 44
99c80476e4SDavid E. O'Brien #define ERR_NOSUCHJOB 45
100c80476e4SDavid E. O'Brien #define ERR_TERMINAL 46
101c80476e4SDavid E. O'Brien #define ERR_NOTWHILE 47
102c80476e4SDavid E. O'Brien #define ERR_NOPROC 48
103c80476e4SDavid E. O'Brien #define ERR_NOMATCH 49
104c80476e4SDavid E. O'Brien #define ERR_MISSING 50
105c80476e4SDavid E. O'Brien #define ERR_UNMATCHED 51
106c80476e4SDavid E. O'Brien #define ERR_NOMEM 52
107c80476e4SDavid E. O'Brien #define ERR_PIPE 53
108c80476e4SDavid E. O'Brien #define ERR_SYSTEM 54
109c80476e4SDavid E. O'Brien #define ERR_STRING 55
110c80476e4SDavid E. O'Brien #define ERR_JOBS 56
111c80476e4SDavid E. O'Brien #define ERR_JOBARGS 57
112c80476e4SDavid E. O'Brien #define ERR_JOBCUR 58
113c80476e4SDavid E. O'Brien #define ERR_JOBPREV 59
114c80476e4SDavid E. O'Brien #define ERR_JOBPAT 60
115c80476e4SDavid E. O'Brien #define ERR_NESTING 61
116c80476e4SDavid E. O'Brien #define ERR_JOBCTRLSUB 62
117c80476e4SDavid E. O'Brien #define ERR_SYNC 63
118c80476e4SDavid E. O'Brien #define ERR_STOPPED 64
119c80476e4SDavid E. O'Brien #define ERR_NODIR 65
120c80476e4SDavid E. O'Brien #define ERR_EMPTY 66
121c80476e4SDavid E. O'Brien #define ERR_BADDIR 67
122c80476e4SDavid E. O'Brien #define ERR_DIRUS 68
123c80476e4SDavid E. O'Brien #define ERR_HFLAG 69
124c80476e4SDavid E. O'Brien #define ERR_NOTLOGIN 70
125c80476e4SDavid E. O'Brien #define ERR_DIV0 71
126c80476e4SDavid E. O'Brien #define ERR_MOD0 72
127c80476e4SDavid E. O'Brien #define ERR_BADSCALE 73
128c80476e4SDavid E. O'Brien #define ERR_SUSPLOG 74
129c80476e4SDavid E. O'Brien #define ERR_UNKUSER 75
130c80476e4SDavid E. O'Brien #define ERR_NOHOME 76
131c80476e4SDavid E. O'Brien #define ERR_HISTUS 77
132c80476e4SDavid E. O'Brien #define ERR_SPDOLLT 78
133c80476e4SDavid E. O'Brien #define ERR_NEWLINE 79
134c80476e4SDavid E. O'Brien #define ERR_SPSTAR 80
135c80476e4SDavid E. O'Brien #define ERR_DIGIT 81
136c80476e4SDavid E. O'Brien #define ERR_VARILL 82
137c80476e4SDavid E. O'Brien #define ERR_NLINDEX 83
138c80476e4SDavid E. O'Brien #define ERR_EXPOVFL 84
139c80476e4SDavid E. O'Brien #define ERR_VARSYN 85
140c80476e4SDavid E. O'Brien #define ERR_BADBANG 86
141c80476e4SDavid E. O'Brien #define ERR_NOSUBST 87
142c80476e4SDavid E. O'Brien #define ERR_BADSUBST 88
143c80476e4SDavid E. O'Brien #define ERR_LHS 89
144c80476e4SDavid E. O'Brien #define ERR_RHSLONG 90
145c80476e4SDavid E. O'Brien #define ERR_BADBANGMOD 91
146c80476e4SDavid E. O'Brien #define ERR_MODFAIL 92
147c80476e4SDavid E. O'Brien #define ERR_SUBOVFL 93
148c80476e4SDavid E. O'Brien #define ERR_BADBANGARG 94
149c80476e4SDavid E. O'Brien #define ERR_NOSEARCH 95
150c80476e4SDavid E. O'Brien #define ERR_NOEVENT 96
151c80476e4SDavid E. O'Brien #define ERR_TOOMANYRP 97
152c80476e4SDavid E. O'Brien #define ERR_TOOMANYLP 98
153c80476e4SDavid E. O'Brien #define ERR_BADPLP 99
154c80476e4SDavid E. O'Brien #define ERR_MISRED 100
155c80476e4SDavid E. O'Brien #define ERR_OUTRED 101
156c80476e4SDavid E. O'Brien #define ERR_REDPAR 102
157c80476e4SDavid E. O'Brien #define ERR_INRED 103
158c80476e4SDavid E. O'Brien #define ERR_BADPLPS 104
159c80476e4SDavid E. O'Brien #define ERR_ALIASLOOP 105
160c80476e4SDavid E. O'Brien #define ERR_NOWATCH 106
161c80476e4SDavid E. O'Brien #define ERR_NOSCHED 107
162c80476e4SDavid E. O'Brien #define ERR_SCHEDUSAGE 108
163c80476e4SDavid E. O'Brien #define ERR_SCHEDEV 109
164c80476e4SDavid E. O'Brien #define ERR_SCHEDCOM 110
165c80476e4SDavid E. O'Brien #define ERR_SCHEDTIME 111
166c80476e4SDavid E. O'Brien #define ERR_SCHEDREL 112
167c80476e4SDavid E. O'Brien #define ERR_TCNOSTR 113
168c80476e4SDavid E. O'Brien #define ERR_SETTCUS 114
169c80476e4SDavid E. O'Brien #define ERR_TCCAP 115
170c80476e4SDavid E. O'Brien #define ERR_TCPARM 116
171c80476e4SDavid E. O'Brien #define ERR_TCARGS 117
172c80476e4SDavid E. O'Brien #define ERR_TCNARGS 118
173c80476e4SDavid E. O'Brien #define ERR_TCUSAGE 119
174c80476e4SDavid E. O'Brien #define ERR_ARCH 120
175c80476e4SDavid E. O'Brien #define ERR_HISTLOOP 121
176c80476e4SDavid E. O'Brien #define ERR_FILEINQ 122
177c80476e4SDavid E. O'Brien #define ERR_SELOVFL 123
178c80476e4SDavid E. O'Brien #define ERR_TCSHUSAGE 124
179c80476e4SDavid E. O'Brien #define ERR_COMPCOM 125
180c80476e4SDavid E. O'Brien #define ERR_COMPINV 126
181c80476e4SDavid E. O'Brien #define ERR_COMPMIS 127
182c80476e4SDavid E. O'Brien #define ERR_COMPINC 128
183c80476e4SDavid E. O'Brien #define ERR_MFLAG 129
184c80476e4SDavid E. O'Brien #define ERR_ULIMUS 130
185c80476e4SDavid E. O'Brien #define ERR_READONLY 131
186c80476e4SDavid E. O'Brien #define ERR_BADJOB 132
187c80476e4SDavid E. O'Brien #define ERR_INVALID 133
188c80476e4SDavid E. O'Brien #define ERR_BADCOLORVAR 134
1899ccc37e3SMark Peek #define ERR_EOF 135
1909ccc37e3SMark Peek #define NO_ERRORS 136
191c80476e4SDavid E. O'Brien
19223338178SMark Peek static const char *elst[NO_ERRORS] INIT_ZERO_STRUCT;
193c80476e4SDavid E. O'Brien
194c80476e4SDavid E. O'Brien /*
195c80476e4SDavid E. O'Brien * Init the elst depending on the locale
196c80476e4SDavid E. O'Brien */
197c80476e4SDavid E. O'Brien void
errinit(void)19845e5710bSMark Peek errinit(void)
199c80476e4SDavid E. O'Brien {
200c80476e4SDavid E. O'Brien #ifdef NLS_CATALOGS
20145e5710bSMark Peek size_t i;
202c80476e4SDavid E. O'Brien
203c80476e4SDavid E. O'Brien for (i = 0; i < NO_ERRORS; i++)
20445e5710bSMark Peek xfree((char *)(intptr_t)elst[i]);
205a15e6f9aSMark Peek # if defined(__FreeBSD__) || defined(hpux) || defined(__MidnightBSD__)
206c80476e4SDavid E. O'Brien # define NLS_MAXSET 30
207c80476e4SDavid E. O'Brien for (i = 1; i <= NLS_MAXSET; i++)
208c80476e4SDavid E. O'Brien CGETS(i, 1, "" );
209c80476e4SDavid E. O'Brien # endif
210c80476e4SDavid E. O'Brien #endif
211c80476e4SDavid E. O'Brien
212c80476e4SDavid E. O'Brien elst[ERR_SYNTAX] = CSAVS(1, 1, "Syntax Error");
213c80476e4SDavid E. O'Brien elst[ERR_NOTALLOWED] = CSAVS(1, 2, "%s is not allowed");
214c80476e4SDavid E. O'Brien elst[ERR_WTOOLONG] = CSAVS(1, 3, "Word too long");
215c80476e4SDavid E. O'Brien elst[ERR_LTOOLONG] = CSAVS(1, 4, "$< line too long");
216c80476e4SDavid E. O'Brien elst[ERR_DOLZERO] = CSAVS(1, 5, "No file for $0");
217c80476e4SDavid E. O'Brien elst[ERR_INCBR] = CSAVS(1, 6, "Incomplete [] modifier");
218c80476e4SDavid E. O'Brien elst[ERR_EXPORD] = CSAVS(1, 7, "$ expansion must end before ]");
21919d2e3deSDmitry Chagin elst[ERR_BADMOD] = CSAVS(1, 8, "Bad : modifier in $ '%c'");
220c80476e4SDavid E. O'Brien elst[ERR_SUBSCRIPT] = CSAVS(1, 9, "Subscript error");
221c80476e4SDavid E. O'Brien elst[ERR_BADNUM] = CSAVS(1, 10, "Badly formed number");
222c80476e4SDavid E. O'Brien elst[ERR_NOMORE] = CSAVS(1, 11, "No more words");
223c80476e4SDavid E. O'Brien elst[ERR_FILENAME] = CSAVS(1, 12, "Missing file name");
224c80476e4SDavid E. O'Brien elst[ERR_GLOB] = CSAVS(1, 13, "Internal glob error");
225c80476e4SDavid E. O'Brien elst[ERR_COMMAND] = CSAVS(1, 14, "Command not found");
226c80476e4SDavid E. O'Brien elst[ERR_TOOFEW] = CSAVS(1, 15, "Too few arguments");
227c80476e4SDavid E. O'Brien elst[ERR_TOOMANY] = CSAVS(1, 16, "Too many arguments");
228c80476e4SDavid E. O'Brien elst[ERR_DANGER] = CSAVS(1, 17, "Too dangerous to alias that");
229c80476e4SDavid E. O'Brien elst[ERR_EMPTYIF] = CSAVS(1, 18, "Empty if");
230c80476e4SDavid E. O'Brien elst[ERR_IMPRTHEN] = CSAVS(1, 19, "Improper then");
231c80476e4SDavid E. O'Brien elst[ERR_NOPAREN] = CSAVS(1, 20, "Words not parenthesized");
232c80476e4SDavid E. O'Brien elst[ERR_NOTFOUND] = CSAVS(1, 21, "%s not found");
233c80476e4SDavid E. O'Brien elst[ERR_MASK] = CSAVS(1, 22, "Improper mask");
234c80476e4SDavid E. O'Brien elst[ERR_LIMIT] = CSAVS(1, 23, "No such limit");
235c80476e4SDavid E. O'Brien elst[ERR_TOOLARGE] = CSAVS(1, 24, "Argument too large");
236c80476e4SDavid E. O'Brien elst[ERR_SCALEF] = CSAVS(1, 25, "Improper or unknown scale factor");
237c80476e4SDavid E. O'Brien elst[ERR_UNDVAR] = CSAVS(1, 26, "Undefined variable");
238c80476e4SDavid E. O'Brien elst[ERR_DEEP] = CSAVS(1, 27, "Directory stack not that deep");
239c80476e4SDavid E. O'Brien elst[ERR_BADSIG] = CSAVS(1, 28, "Bad signal number");
240c80476e4SDavid E. O'Brien elst[ERR_UNKSIG] = CSAVS(1, 29, "Unknown signal; kill -l lists signals");
241c80476e4SDavid E. O'Brien elst[ERR_VARBEGIN] = CSAVS(1, 30, "Variable name must begin with a letter");
242c80476e4SDavid E. O'Brien elst[ERR_VARTOOLONG] = CSAVS(1, 31, "Variable name too long");
243c80476e4SDavid E. O'Brien elst[ERR_VARALNUM] = CSAVS(1, 32,
244c80476e4SDavid E. O'Brien "Variable name must contain alphanumeric characters");
245c80476e4SDavid E. O'Brien elst[ERR_JOBCONTROL] = CSAVS(1, 33, "No job control in this shell");
246c80476e4SDavid E. O'Brien elst[ERR_EXPRESSION] = CSAVS(1, 34, "Expression Syntax");
247c80476e4SDavid E. O'Brien elst[ERR_NOHOMEDIR] = CSAVS(1, 35, "No home directory");
248c80476e4SDavid E. O'Brien elst[ERR_CANTCHANGE] = CSAVS(1, 36, "Can't change to home directory");
249c80476e4SDavid E. O'Brien elst[ERR_NULLCOM] = CSAVS(1, 37, "Invalid null command");
250c80476e4SDavid E. O'Brien elst[ERR_ASSIGN] = CSAVS(1, 38, "Assignment missing expression");
251c80476e4SDavid E. O'Brien elst[ERR_UNKNOWNOP] = CSAVS(1, 39, "Unknown operator");
252c80476e4SDavid E. O'Brien elst[ERR_AMBIG] = CSAVS(1, 40, "Ambiguous");
253c80476e4SDavid E. O'Brien elst[ERR_EXISTS] = CSAVS(1, 41, "%s: File exists");
254c80476e4SDavid E. O'Brien elst[ERR_ARGC] = CSAVS(1, 42, "Argument for -c ends in backslash");
255c80476e4SDavid E. O'Brien elst[ERR_INTR] = CSAVS(1, 43, "Interrupted");
256c80476e4SDavid E. O'Brien elst[ERR_RANGE] = CSAVS(1, 44, "Subscript out of range");
257c80476e4SDavid E. O'Brien elst[ERR_OVERFLOW] = CSAVS(1, 45, "Line overflow");
258c80476e4SDavid E. O'Brien elst[ERR_NOSUCHJOB] = CSAVS(1, 46, "No such job");
259c80476e4SDavid E. O'Brien elst[ERR_TERMINAL] = CSAVS(1, 47, "Can't from terminal");
260c80476e4SDavid E. O'Brien elst[ERR_NOTWHILE] = CSAVS(1, 48, "Not in while/foreach");
261c80476e4SDavid E. O'Brien elst[ERR_NOPROC] = CSAVS(1, 49, "No more processes");
262c80476e4SDavid E. O'Brien elst[ERR_NOMATCH] = CSAVS(1, 50, "No match");
26319d2e3deSDmitry Chagin elst[ERR_MISSING] = CSAVS(1, 51, "Missing '%c'");
26419d2e3deSDmitry Chagin elst[ERR_UNMATCHED] = CSAVS(1, 52, "Unmatched '%c'");
265c80476e4SDavid E. O'Brien elst[ERR_NOMEM] = CSAVS(1, 53, "Out of memory");
266c80476e4SDavid E. O'Brien elst[ERR_PIPE] = CSAVS(1, 54, "Can't make pipe");
267c80476e4SDavid E. O'Brien elst[ERR_SYSTEM] = CSAVS(1, 55, "%s: %s");
268c80476e4SDavid E. O'Brien elst[ERR_STRING] = CSAVS(1, 56, "%s");
269c80476e4SDavid E. O'Brien elst[ERR_JOBS] = CSAVS(1, 57, "Usage: jobs [ -l ]");
270c80476e4SDavid E. O'Brien elst[ERR_JOBARGS] = CSAVS(1, 58, "Arguments should be jobs or process id's");
271c80476e4SDavid E. O'Brien elst[ERR_JOBCUR] = CSAVS(1, 59, "No current job");
272c80476e4SDavid E. O'Brien elst[ERR_JOBPREV] = CSAVS(1, 60, "No previous job");
273c80476e4SDavid E. O'Brien elst[ERR_JOBPAT] = CSAVS(1, 61, "No job matches pattern");
274c80476e4SDavid E. O'Brien elst[ERR_NESTING] = CSAVS(1, 62, "Fork nesting > %d; maybe `...` loop");
275c80476e4SDavid E. O'Brien elst[ERR_JOBCTRLSUB] = CSAVS(1, 63, "No job control in subshells");
276c80476e4SDavid E. O'Brien elst[ERR_SYNC] = CSAVS(1, 64, "Sync fault: Process %d not found");
277c80476e4SDavid E. O'Brien elst[ERR_STOPPED] =
278c80476e4SDavid E. O'Brien #ifdef SUSPENDED
279c80476e4SDavid E. O'Brien CSAVS(1, 65, "%sThere are suspended jobs");
280c80476e4SDavid E. O'Brien #else
281c80476e4SDavid E. O'Brien CSAVS(1, 66, "%sThere are stopped jobs");
282c80476e4SDavid E. O'Brien #endif /* SUSPENDED */
283c80476e4SDavid E. O'Brien elst[ERR_NODIR] = CSAVS(1, 67, "No other directory");
284c80476e4SDavid E. O'Brien elst[ERR_EMPTY] = CSAVS(1, 68, "Directory stack empty");
285c80476e4SDavid E. O'Brien elst[ERR_BADDIR] = CSAVS(1, 69, "Bad directory");
286c80476e4SDavid E. O'Brien elst[ERR_DIRUS] = CSAVS(1, 70, "Usage: %s [-%s]%s");
287c80476e4SDavid E. O'Brien elst[ERR_HFLAG] = CSAVS(1, 71, "No operand for -h flag");
288c80476e4SDavid E. O'Brien elst[ERR_NOTLOGIN] = CSAVS(1, 72, "Not a login shell");
289c80476e4SDavid E. O'Brien elst[ERR_DIV0] = CSAVS(1, 73, "Division by 0");
290c80476e4SDavid E. O'Brien elst[ERR_MOD0] = CSAVS(1, 74, "Mod by 0");
291c80476e4SDavid E. O'Brien elst[ERR_BADSCALE] = CSAVS(1, 75, "Bad scaling; did you mean \"%s\"?");
292c80476e4SDavid E. O'Brien elst[ERR_SUSPLOG] = CSAVS(1, 76, "Can't suspend a login shell (yet)");
293c80476e4SDavid E. O'Brien elst[ERR_UNKUSER] = CSAVS(1, 77, "Unknown user: %s");
294c80476e4SDavid E. O'Brien elst[ERR_NOHOME] = CSAVS(1, 78, "No $home variable set");
295c80476e4SDavid E. O'Brien elst[ERR_HISTUS] = CSAVS(1, 79,
296c80476e4SDavid E. O'Brien "Usage: history [-%s] [# number of events]");
297c80476e4SDavid E. O'Brien elst[ERR_SPDOLLT] = CSAVS(1, 80, "$, ! or < not allowed with $# or $?");
298c80476e4SDavid E. O'Brien elst[ERR_NEWLINE] = CSAVS(1, 81, "Newline in variable name");
299c80476e4SDavid E. O'Brien elst[ERR_SPSTAR] = CSAVS(1, 82, "* not allowed with $# or $?");
300c80476e4SDavid E. O'Brien elst[ERR_DIGIT] = CSAVS(1, 83, "$?<digit> or $#<digit> not allowed");
301c80476e4SDavid E. O'Brien elst[ERR_VARILL] = CSAVS(1, 84, "Illegal variable name");
302c80476e4SDavid E. O'Brien elst[ERR_NLINDEX] = CSAVS(1, 85, "Newline in variable index");
303c80476e4SDavid E. O'Brien elst[ERR_EXPOVFL] = CSAVS(1, 86, "Expansion buffer overflow");
304c80476e4SDavid E. O'Brien elst[ERR_VARSYN] = CSAVS(1, 87, "Variable syntax");
305c80476e4SDavid E. O'Brien elst[ERR_BADBANG] = CSAVS(1, 88, "Bad ! form");
306c80476e4SDavid E. O'Brien elst[ERR_NOSUBST] = CSAVS(1, 89, "No previous substitute");
307c80476e4SDavid E. O'Brien elst[ERR_BADSUBST] = CSAVS(1, 90, "Bad substitute");
308c80476e4SDavid E. O'Brien elst[ERR_LHS] = CSAVS(1, 91, "No previous left hand side");
309c80476e4SDavid E. O'Brien elst[ERR_RHSLONG] = CSAVS(1, 92, "Right hand side too long");
31019d2e3deSDmitry Chagin elst[ERR_BADBANGMOD] = CSAVS(1, 93, "Bad ! modifier: '%c'");
311c80476e4SDavid E. O'Brien elst[ERR_MODFAIL] = CSAVS(1, 94, "Modifier failed");
312c80476e4SDavid E. O'Brien elst[ERR_SUBOVFL] = CSAVS(1, 95, "Substitution buffer overflow");
313c80476e4SDavid E. O'Brien elst[ERR_BADBANGARG] = CSAVS(1, 96, "Bad ! arg selector");
314c80476e4SDavid E. O'Brien elst[ERR_NOSEARCH] = CSAVS(1, 97, "No prev search");
315c80476e4SDavid E. O'Brien elst[ERR_NOEVENT] = CSAVS(1, 98, "%s: Event not found");
316c80476e4SDavid E. O'Brien elst[ERR_TOOMANYRP] = CSAVS(1, 99, "Too many )'s");
317c80476e4SDavid E. O'Brien elst[ERR_TOOMANYLP] = CSAVS(1, 100, "Too many ('s");
318c80476e4SDavid E. O'Brien elst[ERR_BADPLP] = CSAVS(1, 101, "Badly placed (");
319c80476e4SDavid E. O'Brien elst[ERR_MISRED] = CSAVS(1, 102, "Missing name for redirect");
320c80476e4SDavid E. O'Brien elst[ERR_OUTRED] = CSAVS(1, 103, "Ambiguous output redirect");
321c80476e4SDavid E. O'Brien elst[ERR_REDPAR] = CSAVS(1, 104, "Can't << within ()'s");
322c80476e4SDavid E. O'Brien elst[ERR_INRED] = CSAVS(1, 105, "Ambiguous input redirect");
323c80476e4SDavid E. O'Brien elst[ERR_BADPLPS] = CSAVS(1, 106, "Badly placed ()'s");
324c80476e4SDavid E. O'Brien elst[ERR_ALIASLOOP] = CSAVS(1, 107, "Alias loop");
325c80476e4SDavid E. O'Brien elst[ERR_NOWATCH] = CSAVS(1, 108, "No $watch variable set");
326c80476e4SDavid E. O'Brien elst[ERR_NOSCHED] = CSAVS(1, 109, "No scheduled events");
327c80476e4SDavid E. O'Brien elst[ERR_SCHEDUSAGE] = CSAVS(1, 110,
328c80476e4SDavid E. O'Brien "Usage: sched -<item#>.\nUsage: sched [+]hh:mm <command>");
329c80476e4SDavid E. O'Brien elst[ERR_SCHEDEV] = CSAVS(1, 111, "Not that many scheduled events");
330c80476e4SDavid E. O'Brien elst[ERR_SCHEDCOM] = CSAVS(1, 112, "No command to run");
331c80476e4SDavid E. O'Brien elst[ERR_SCHEDTIME] = CSAVS(1, 113, "Invalid time for event");
332c80476e4SDavid E. O'Brien elst[ERR_SCHEDREL] = CSAVS(1, 114, "Relative time inconsistent with am/pm");
333c80476e4SDavid E. O'Brien elst[ERR_TCNOSTR] = CSAVS(1, 115, "Out of termcap string space");
334c80476e4SDavid E. O'Brien elst[ERR_SETTCUS] = CSAVS(1, 116, "Usage: settc %s [yes|no]");
335c80476e4SDavid E. O'Brien elst[ERR_TCCAP] = CSAVS(1, 117, "Unknown capability `%s'");
33619d2e3deSDmitry Chagin elst[ERR_TCPARM] = CSAVS(1, 118, "Unknown termcap parameter '%%%c'");
337c80476e4SDavid E. O'Brien elst[ERR_TCARGS] = CSAVS(1, 119, "Too many arguments for `%s' (%d)");
338c80476e4SDavid E. O'Brien elst[ERR_TCNARGS] = CSAVS(1, 120, "`%s' requires %d arguments");
339c80476e4SDavid E. O'Brien elst[ERR_TCUSAGE] = CSAVS(1, 121,
340c80476e4SDavid E. O'Brien "Usage: echotc [-v|-s] [<capability> [<args>]]");
341c80476e4SDavid E. O'Brien elst[ERR_ARCH] = CSAVS(1, 122, "%s: %s. Binary file not executable");
342c80476e4SDavid E. O'Brien elst[ERR_HISTLOOP] = CSAVS(1, 123, "!# History loop");
343c80476e4SDavid E. O'Brien elst[ERR_FILEINQ] = CSAVS(1, 124, "Malformed file inquiry");
344c80476e4SDavid E. O'Brien elst[ERR_SELOVFL] = CSAVS(1, 125, "Selector overflow");
345c80476e4SDavid E. O'Brien #ifdef apollo
346c80476e4SDavid E. O'Brien elst[ERR_TCSHUSAGE] = CSAVS(1, 126,
347c80476e4SDavid E. O'Brien "Unknown option: `-%s'\nUsage: %s [ -bcdefilmnqstvVxX -Dname[=value] ] [ argument ... ]");
348c80476e4SDavid E. O'Brien #else /* !apollo */
349c80476e4SDavid E. O'Brien # ifdef convex
350c80476e4SDavid E. O'Brien elst[ERR_TCSHUSAGE] = CSAVS(1, 127,
351c80476e4SDavid E. O'Brien "Unknown option: `-%s'\nUsage: %s [ -bcdefFilmnqstvVxX ] [ argument ... ]");
352c80476e4SDavid E. O'Brien # else /* rest */
353c80476e4SDavid E. O'Brien elst[ERR_TCSHUSAGE] = CSAVS(1, 128,
354c80476e4SDavid E. O'Brien "Unknown option: `-%s'\nUsage: %s [ -bcdefilmnqstvVxX ] [ argument ... ]");
355c80476e4SDavid E. O'Brien # endif /* convex */
356c80476e4SDavid E. O'Brien #endif /* apollo */
357c80476e4SDavid E. O'Brien elst[ERR_COMPCOM] = CSAVS(1, 129, "\nInvalid completion: \"%s\"");
358c80476e4SDavid E. O'Brien elst[ERR_COMPINV] = CSAVS(1, 130, "\nInvalid %s: '%c'");
359c80476e4SDavid E. O'Brien elst[ERR_COMPMIS] = CSAVS(1, 131,
360c80476e4SDavid E. O'Brien "\nMissing separator '%c' after %s \"%s\"");
361c80476e4SDavid E. O'Brien elst[ERR_COMPINC] = CSAVS(1, 132, "\nIncomplete %s: \"%s\"");
362c80476e4SDavid E. O'Brien elst[ERR_MFLAG] = CSAVS(1, 133, "No operand for -m flag");
363c80476e4SDavid E. O'Brien elst[ERR_ULIMUS] = CSAVS(1, 134, "Usage: unlimit [-fh] [limits]");
364c80476e4SDavid E. O'Brien elst[ERR_READONLY] = CSAVS(1, 135, "$%S is read-only");
365c80476e4SDavid E. O'Brien elst[ERR_BADJOB] = CSAVS(1, 136, "No such job (badjob)");
36619d2e3deSDmitry Chagin elst[ERR_BADCOLORVAR] = CSAVS(1, 137, "Unknown colorls variable '%c%c'");
3679ccc37e3SMark Peek elst[ERR_EOF] = CSAVS(1, 138, "Unexpected end of file");
368c80476e4SDavid E. O'Brien }
36945e5710bSMark Peek
37045e5710bSMark Peek /* Cleanup data. */
37145e5710bSMark Peek struct cleanup_entry
37245e5710bSMark Peek {
37345e5710bSMark Peek void *var;
37445e5710bSMark Peek void (*fn) (void *);
37545e5710bSMark Peek #ifdef CLEANUP_DEBUG
37645e5710bSMark Peek const char *file;
37745e5710bSMark Peek size_t line;
37845e5710bSMark Peek #endif
37945e5710bSMark Peek };
38045e5710bSMark Peek
38119d2e3deSDmitry Chagin static struct cleanup_entry *cleanup_stack INIT_ZERO; /* = NULL; */
38219d2e3deSDmitry Chagin static size_t cleanup_sp INIT_ZERO; /* = 0; Next free entry */
38319d2e3deSDmitry Chagin static size_t cleanup_mark INIT_ZERO; /* = 0; Last entry to handle before unwinding */
38419d2e3deSDmitry Chagin static size_t cleanup_stack_size INIT_ZERO; /* = 0 */
38545e5710bSMark Peek
38645e5710bSMark Peek /* fn() will be run with all signals blocked, so it should not do anything
38745e5710bSMark Peek risky. */
38845e5710bSMark Peek void
cleanup_push_internal(void * var,void (* fn)(void *),const char * file,size_t line)38945e5710bSMark Peek cleanup_push_internal(void *var, void (*fn) (void *)
39045e5710bSMark Peek #ifdef CLEANUP_DEBUG
39145e5710bSMark Peek , const char *file, size_t line
39245e5710bSMark Peek #endif
39345e5710bSMark Peek )
39445e5710bSMark Peek {
39545e5710bSMark Peek struct cleanup_entry *ce;
39645e5710bSMark Peek
39745e5710bSMark Peek if (cleanup_sp == cleanup_stack_size) {
39845e5710bSMark Peek if (cleanup_stack_size == 0)
39945e5710bSMark Peek cleanup_stack_size = 64; /* Arbitrary */
40045e5710bSMark Peek else
40145e5710bSMark Peek cleanup_stack_size *= 2;
40245e5710bSMark Peek cleanup_stack = xrealloc(cleanup_stack,
40345e5710bSMark Peek cleanup_stack_size * sizeof (*cleanup_stack));
40445e5710bSMark Peek }
40545e5710bSMark Peek ce = cleanup_stack + cleanup_sp;
40645e5710bSMark Peek ce->var = var;
40745e5710bSMark Peek ce->fn = fn;
40845e5710bSMark Peek #ifdef CLEANUP_DEBUG
40945e5710bSMark Peek ce->file = file;
41045e5710bSMark Peek ce->line = line;
41145e5710bSMark Peek #endif
41245e5710bSMark Peek cleanup_sp++;
41345e5710bSMark Peek }
41445e5710bSMark Peek
41545e5710bSMark Peek static void
cleanup_ignore_fn(void * dummy)41645e5710bSMark Peek cleanup_ignore_fn(void *dummy)
41745e5710bSMark Peek {
41845e5710bSMark Peek USE(dummy);
41945e5710bSMark Peek }
42045e5710bSMark Peek
42145e5710bSMark Peek void
cleanup_ignore(void * var)42245e5710bSMark Peek cleanup_ignore(void *var)
42345e5710bSMark Peek {
42445e5710bSMark Peek struct cleanup_entry *ce;
42545e5710bSMark Peek
42645e5710bSMark Peek ce = cleanup_stack + cleanup_sp;
42745e5710bSMark Peek while (ce != cleanup_stack) {
42845e5710bSMark Peek ce--;
42945e5710bSMark Peek if (ce->var == var) {
43045e5710bSMark Peek ce->fn = cleanup_ignore_fn;
43145e5710bSMark Peek return;
43245e5710bSMark Peek }
43345e5710bSMark Peek }
43445e5710bSMark Peek abort();
43545e5710bSMark Peek }
43645e5710bSMark Peek
43745e5710bSMark Peek void
cleanup_until(void * last_var)43845e5710bSMark Peek cleanup_until(void *last_var)
43945e5710bSMark Peek {
44045e5710bSMark Peek while (cleanup_sp != 0) {
44145e5710bSMark Peek struct cleanup_entry ce;
44245e5710bSMark Peek
44345e5710bSMark Peek cleanup_sp--;
44445e5710bSMark Peek ce = cleanup_stack[cleanup_sp];
44545e5710bSMark Peek ce.fn(ce.var);
44645e5710bSMark Peek if (ce.var == last_var)
44745e5710bSMark Peek return;
44845e5710bSMark Peek }
44945e5710bSMark Peek abort();
45045e5710bSMark Peek }
45145e5710bSMark Peek
4529ccc37e3SMark Peek int
cleanup_reset(void)4539ccc37e3SMark Peek cleanup_reset(void)
4549ccc37e3SMark Peek {
4559ccc37e3SMark Peek return cleanup_sp > cleanup_mark;
4569ccc37e3SMark Peek }
4579ccc37e3SMark Peek
45845e5710bSMark Peek void
cleanup_until_mark(void)45945e5710bSMark Peek cleanup_until_mark(void)
46045e5710bSMark Peek {
46145e5710bSMark Peek while (cleanup_sp > cleanup_mark) {
46245e5710bSMark Peek struct cleanup_entry ce;
46345e5710bSMark Peek
46445e5710bSMark Peek cleanup_sp--;
46545e5710bSMark Peek ce = cleanup_stack[cleanup_sp];
46645e5710bSMark Peek ce.fn(ce.var);
46745e5710bSMark Peek }
46845e5710bSMark Peek }
46945e5710bSMark Peek
47045e5710bSMark Peek size_t
cleanup_push_mark(void)47145e5710bSMark Peek cleanup_push_mark(void)
47245e5710bSMark Peek {
47345e5710bSMark Peek size_t old_mark;
47445e5710bSMark Peek
47545e5710bSMark Peek old_mark = cleanup_mark;
47645e5710bSMark Peek cleanup_mark = cleanup_sp;
47745e5710bSMark Peek return old_mark;
47845e5710bSMark Peek }
47945e5710bSMark Peek
48045e5710bSMark Peek void
cleanup_pop_mark(size_t mark)48145e5710bSMark Peek cleanup_pop_mark(size_t mark)
48245e5710bSMark Peek {
48345e5710bSMark Peek assert (mark <= cleanup_sp);
48445e5710bSMark Peek cleanup_mark = mark;
48545e5710bSMark Peek }
48645e5710bSMark Peek
48745e5710bSMark Peek void
sigint_cleanup(void * xsa)48845e5710bSMark Peek sigint_cleanup(void *xsa)
48945e5710bSMark Peek {
49045e5710bSMark Peek const struct sigaction *sa;
49145e5710bSMark Peek
49245e5710bSMark Peek sa = xsa;
49345e5710bSMark Peek sigaction(SIGINT, sa, NULL);
49445e5710bSMark Peek }
49545e5710bSMark Peek
49645e5710bSMark Peek void
sigprocmask_cleanup(void * xmask)49745e5710bSMark Peek sigprocmask_cleanup(void *xmask)
49845e5710bSMark Peek {
49945e5710bSMark Peek sigset_t *mask;
50045e5710bSMark Peek
50145e5710bSMark Peek mask = xmask;
50245e5710bSMark Peek sigprocmask(SIG_SETMASK, mask, NULL);
50345e5710bSMark Peek }
50445e5710bSMark Peek
50545e5710bSMark Peek void
open_cleanup(void * xptr)50645e5710bSMark Peek open_cleanup(void *xptr)
50745e5710bSMark Peek {
50845e5710bSMark Peek int *ptr;
50945e5710bSMark Peek
51045e5710bSMark Peek ptr = xptr;
51145e5710bSMark Peek xclose(*ptr);
51245e5710bSMark Peek }
51345e5710bSMark Peek
51445e5710bSMark Peek void
opendir_cleanup(void * xdir)51545e5710bSMark Peek opendir_cleanup(void *xdir)
51645e5710bSMark Peek {
51745e5710bSMark Peek DIR *dir;
51845e5710bSMark Peek
51945e5710bSMark Peek dir = xdir;
52045e5710bSMark Peek xclosedir(dir);
52145e5710bSMark Peek }
52245e5710bSMark Peek
52345e5710bSMark Peek void
xfree_indirect(void * xptr)52445e5710bSMark Peek xfree_indirect(void *xptr)
52545e5710bSMark Peek {
52645e5710bSMark Peek void **ptr; /* This is actually type punning :( */
52745e5710bSMark Peek
52845e5710bSMark Peek ptr = xptr;
52945e5710bSMark Peek xfree(*ptr);
53045e5710bSMark Peek }
53145e5710bSMark Peek
53245e5710bSMark Peek void
reset(void)53345e5710bSMark Peek reset(void)
53445e5710bSMark Peek {
53545e5710bSMark Peek cleanup_until_mark();
53645e5710bSMark Peek _reset();
5379ccc37e3SMark Peek abort();
53845e5710bSMark Peek }
53945e5710bSMark Peek
540c80476e4SDavid E. O'Brien /*
541c80476e4SDavid E. O'Brien * The parser and scanner set up errors for later by calling seterr,
542c80476e4SDavid E. O'Brien * which sets the variable err as a side effect; later to be tested,
543c80476e4SDavid E. O'Brien * e.g. in process.
544c80476e4SDavid E. O'Brien */
545c80476e4SDavid E. O'Brien void
546c80476e4SDavid E. O'Brien /*VARARGS1*/
seterror(unsigned int id,...)547c80476e4SDavid E. O'Brien seterror(unsigned int id, ...)
548c80476e4SDavid E. O'Brien {
549c80476e4SDavid E. O'Brien if (seterr == 0) {
550c80476e4SDavid E. O'Brien va_list va;
551c80476e4SDavid E. O'Brien
55245e5710bSMark Peek va_start(va, id);
553c80476e4SDavid E. O'Brien if (id >= sizeof(elst) / sizeof(elst[0]))
554c80476e4SDavid E. O'Brien id = ERR_INVALID;
55545e5710bSMark Peek seterr = xvasprintf(elst[id], va);
556c80476e4SDavid E. O'Brien va_end(va);
557c80476e4SDavid E. O'Brien }
558c80476e4SDavid E. O'Brien }
559c80476e4SDavid E. O'Brien
560c80476e4SDavid E. O'Brien void
fixerror(void)5619ccc37e3SMark Peek fixerror(void)
562c80476e4SDavid E. O'Brien {
563c80476e4SDavid E. O'Brien didfds = 0; /* Forget about 0,1,2 */
564c80476e4SDavid E. O'Brien /*
565c80476e4SDavid E. O'Brien * Go away if -e or we are a child shell
566c80476e4SDavid E. O'Brien */
5673b6eaa7bSAndrey A. Chernov if (!exitset || exiterr || child)
568c80476e4SDavid E. O'Brien xexit(1);
569c80476e4SDavid E. O'Brien
570c80476e4SDavid E. O'Brien /*
571c80476e4SDavid E. O'Brien * Reset the state of the input. This buffered seek to end of file will
572c80476e4SDavid E. O'Brien * also clear the while/foreach stack.
573c80476e4SDavid E. O'Brien */
574c80476e4SDavid E. O'Brien btoeof();
575c80476e4SDavid E. O'Brien
57645e5710bSMark Peek setcopy(STRstatus, STR1, VAR_READWRITE);/*FIXRESET*/
577c80476e4SDavid E. O'Brien #ifdef BSDJOBS
578c80476e4SDavid E. O'Brien if (tpgrp > 0)
579c80476e4SDavid E. O'Brien (void) tcsetpgrp(FSHTTY, tpgrp);
580c80476e4SDavid E. O'Brien #endif
5819ccc37e3SMark Peek }
5829ccc37e3SMark Peek
5839ccc37e3SMark Peek /*
5849ccc37e3SMark Peek * Print the error with the given id.
5859ccc37e3SMark Peek *
5869ccc37e3SMark Peek * Special ids:
5879ccc37e3SMark Peek * ERR_SILENT: Print nothing.
5889ccc37e3SMark Peek * ERR_OLD: Print the previously set error
5899ccc37e3SMark Peek * ERR_NAME: If this bit is set, print the name of the function
5909ccc37e3SMark Peek * in bname
5919ccc37e3SMark Peek *
5929ccc37e3SMark Peek * This routine always resets or exits. The flag haderr
5939ccc37e3SMark Peek * is set so the routine who catches the unwind can propogate
5949ccc37e3SMark Peek * it if they want.
5959ccc37e3SMark Peek *
5969ccc37e3SMark Peek * Note that any open files at the point of error will eventually
5979ccc37e3SMark Peek * be closed in the routine process in sh.c which is the only
5989ccc37e3SMark Peek * place error unwinds are ever caught.
5999ccc37e3SMark Peek */
6009ccc37e3SMark Peek void
6019ccc37e3SMark Peek /*VARARGS*/
stderror(unsigned int id,...)6029ccc37e3SMark Peek stderror(unsigned int id, ...)
6039ccc37e3SMark Peek {
6049ccc37e3SMark Peek va_list va;
6059ccc37e3SMark Peek int flags;
6069ccc37e3SMark Peek
6079ccc37e3SMark Peek va_start(va, id);
6089ccc37e3SMark Peek
6099ccc37e3SMark Peek /*
6109ccc37e3SMark Peek * Reset don't free flag for buggy os's
6119ccc37e3SMark Peek */
6129ccc37e3SMark Peek dont_free = 0;
6139ccc37e3SMark Peek
6149ccc37e3SMark Peek flags = (int) id & ERR_FLAGS;
6159ccc37e3SMark Peek id &= ~ERR_FLAGS;
6169ccc37e3SMark Peek
6179ccc37e3SMark Peek /* Pyramid's OS/x has a subtle bug in <varargs.h> which prevents calling
6189ccc37e3SMark Peek * va_end more than once in the same function. -- sterling@netcom.com
6199ccc37e3SMark Peek */
6209ccc37e3SMark Peek assert(!((flags & ERR_OLD) && seterr == NULL));
6219ccc37e3SMark Peek
6229ccc37e3SMark Peek if (id >= sizeof(elst) / sizeof(elst[0]))
6239ccc37e3SMark Peek id = ERR_INVALID;
6249ccc37e3SMark Peek
6259ccc37e3SMark Peek if (!(flags & ERR_SILENT)) {
6269ccc37e3SMark Peek /*
6279ccc37e3SMark Peek * Must flush before we print as we wish output before the error
6289ccc37e3SMark Peek * to go on (some form of) standard output, while output after
6299ccc37e3SMark Peek * goes on (some form of) diagnostic output. If didfds then output
6309ccc37e3SMark Peek * will go to 1/2 else to FSHOUT/FSHDIAG. See flush in sh.print.c.
6319ccc37e3SMark Peek */
6329ccc37e3SMark Peek flush();/*FIXRESET*/
6339ccc37e3SMark Peek haderr = 1; /* Now to diagnostic output */
634*d803a9d0SBrooks Davis if (enterhist)
635*d803a9d0SBrooks Davis xprintf("Can't load history: ");/*FIXRESET*/
6369ccc37e3SMark Peek if (flags & ERR_NAME)
6379ccc37e3SMark Peek xprintf("%s: ", bname);/*FIXRESET*/
6389ccc37e3SMark Peek if ((flags & ERR_OLD)) {
6399ccc37e3SMark Peek /* Old error. */
6409ccc37e3SMark Peek xprintf("%s.\n", seterr);/*FIXRESET*/
6419ccc37e3SMark Peek } else {
6429ccc37e3SMark Peek xvprintf(elst[id], va);/*FIXRESET*/
6439ccc37e3SMark Peek xprintf(".\n");/*FIXRESET*/
6449ccc37e3SMark Peek }
6459ccc37e3SMark Peek }
6469ccc37e3SMark Peek va_end(va);
6479ccc37e3SMark Peek
6489ccc37e3SMark Peek if (seterr) {
6499ccc37e3SMark Peek xfree(seterr);
6509ccc37e3SMark Peek seterr = NULL;
6519ccc37e3SMark Peek }
6529ccc37e3SMark Peek
6539ccc37e3SMark Peek fixerror();
6549ccc37e3SMark Peek
655c80476e4SDavid E. O'Brien reset(); /* Unwind */
656c80476e4SDavid E. O'Brien }
657