1 | /* $Header: /afs/dev.mit.edu/source/repository/third/tcsh/sh.err.c,v 1.1.1.1 1996-10-02 06:09:20 ghudson Exp $ */ |
---|
2 | /* |
---|
3 | * sh.err.c: Error printing routines. |
---|
4 | */ |
---|
5 | /*- |
---|
6 | * Copyright (c) 1980, 1991 The Regents of the University of California. |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions |
---|
11 | * are met: |
---|
12 | * 1. Redistributions of source code must retain the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer. |
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer in the |
---|
16 | * documentation and/or other materials provided with the distribution. |
---|
17 | * 3. All advertising materials mentioning features or use of this software |
---|
18 | * must display the following acknowledgement: |
---|
19 | * This product includes software developed by the University of |
---|
20 | * California, Berkeley and its contributors. |
---|
21 | * 4. Neither the name of the University nor the names of its contributors |
---|
22 | * may be used to endorse or promote products derived from this software |
---|
23 | * without specific prior written permission. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
35 | * SUCH DAMAGE. |
---|
36 | */ |
---|
37 | #define _h_sh_err /* Don't redefine the errors */ |
---|
38 | #include "sh.h" |
---|
39 | |
---|
40 | RCSID("$Id: sh.err.c,v 1.1.1.1 1996-10-02 06:09:20 ghudson Exp $") |
---|
41 | |
---|
42 | /* |
---|
43 | * C Shell |
---|
44 | */ |
---|
45 | |
---|
46 | #ifdef lint |
---|
47 | #undef va_arg |
---|
48 | #define va_arg(a, b) (a ? (b) 0 : (b) 0) |
---|
49 | #endif |
---|
50 | |
---|
51 | char *seterr = NULL; /* Holds last error if there was one */ |
---|
52 | |
---|
53 | #define ERR_FLAGS 0xf0000000 |
---|
54 | #define ERR_NAME 0x10000000 |
---|
55 | #define ERR_SILENT 0x20000000 |
---|
56 | #define ERR_OLD 0x40000000 |
---|
57 | |
---|
58 | static char *errorlist[] = |
---|
59 | { |
---|
60 | #define ERR_SYNTAX 0 |
---|
61 | "Syntax Error", |
---|
62 | #define ERR_NOTALLOWED 1 |
---|
63 | "%s is not allowed", |
---|
64 | #define ERR_WTOOLONG 2 |
---|
65 | "Word too long", |
---|
66 | #define ERR_LTOOLONG 3 |
---|
67 | "$< line too long", |
---|
68 | #define ERR_DOLZERO 4 |
---|
69 | "No file for $0", |
---|
70 | #define ERR_INCBR 5 |
---|
71 | "Incomplete [] modifier", |
---|
72 | #define ERR_EXPORD 6 |
---|
73 | "$ expansion must end before ]", |
---|
74 | #define ERR_BADMOD 7 |
---|
75 | "Bad : modifier in $ (%c)", |
---|
76 | #define ERR_SUBSCRIPT 8 |
---|
77 | "Subscript error", |
---|
78 | #define ERR_BADNUM 9 |
---|
79 | "Badly formed number", |
---|
80 | #define ERR_NOMORE 10 |
---|
81 | "No more words", |
---|
82 | #define ERR_FILENAME 11 |
---|
83 | "Missing file name", |
---|
84 | #define ERR_GLOB 12 |
---|
85 | "Internal glob error", |
---|
86 | #define ERR_COMMAND 13 |
---|
87 | "Command not found", |
---|
88 | #define ERR_TOOFEW 14 |
---|
89 | "Too few arguments", |
---|
90 | #define ERR_TOOMANY 15 |
---|
91 | "Too many arguments", |
---|
92 | #define ERR_DANGER 16 |
---|
93 | "Too dangerous to alias that", |
---|
94 | #define ERR_EMPTYIF 17 |
---|
95 | "Empty if", |
---|
96 | #define ERR_IMPRTHEN 18 |
---|
97 | "Improper then", |
---|
98 | #define ERR_NOPAREN 19 |
---|
99 | "Words not parenthesized", |
---|
100 | #define ERR_NOTFOUND 20 |
---|
101 | "%s not found", |
---|
102 | #define ERR_MASK 21 |
---|
103 | "Improper mask", |
---|
104 | #define ERR_LIMIT 22 |
---|
105 | "No such limit", |
---|
106 | #define ERR_TOOLARGE 23 |
---|
107 | "Argument too large", |
---|
108 | #define ERR_SCALEF 24 |
---|
109 | "Improper or unknown scale factor", |
---|
110 | #define ERR_UNDVAR 25 |
---|
111 | "Undefined variable", |
---|
112 | #define ERR_DEEP 26 |
---|
113 | "Directory stack not that deep", |
---|
114 | #define ERR_BADSIG 27 |
---|
115 | "Bad signal number", |
---|
116 | #define ERR_UNKSIG 28 |
---|
117 | "Unknown signal; kill -l lists signals", |
---|
118 | #define ERR_VARBEGIN 29 |
---|
119 | "Variable name must begin with a letter", |
---|
120 | #define ERR_VARTOOLONG 30 |
---|
121 | "Variable name too long", |
---|
122 | #define ERR_VARALNUM 31 |
---|
123 | "Variable name must contain alphanumeric characters", |
---|
124 | #define ERR_JOBCONTROL 32 |
---|
125 | "No job control in this shell", |
---|
126 | #define ERR_EXPRESSION 33 |
---|
127 | "Expression Syntax", |
---|
128 | #define ERR_NOHOMEDIR 34 |
---|
129 | "No home directory", |
---|
130 | #define ERR_CANTCHANGE 35 |
---|
131 | "Can't change to home directory", |
---|
132 | #define ERR_NULLCOM 36 |
---|
133 | "Invalid null command", |
---|
134 | #define ERR_ASSIGN 37 |
---|
135 | "Assignment missing expression", |
---|
136 | #define ERR_UNKNOWNOP 38 |
---|
137 | "Unknown operator", |
---|
138 | #define ERR_AMBIG 39 |
---|
139 | "Ambiguous", |
---|
140 | #define ERR_EXISTS 40 |
---|
141 | "%s: File exists", |
---|
142 | #define ERR_ARGC 41 |
---|
143 | "Argument for -c ends in backslash", |
---|
144 | #define ERR_INTR 42 |
---|
145 | "Interrupted", |
---|
146 | #define ERR_RANGE 43 |
---|
147 | "Subscript out of range", |
---|
148 | #define ERR_OVERFLOW 44 |
---|
149 | "Line overflow", |
---|
150 | #define ERR_NOSUCHJOB 45 |
---|
151 | "No such job", |
---|
152 | #define ERR_TERMINAL 46 |
---|
153 | "Can't from terminal", |
---|
154 | #define ERR_NOTWHILE 47 |
---|
155 | "Not in while/foreach", |
---|
156 | #define ERR_NOPROC 48 |
---|
157 | "No more processes", |
---|
158 | #define ERR_NOMATCH 49 |
---|
159 | "No match", |
---|
160 | #define ERR_MISSING 50 |
---|
161 | "Missing %c", |
---|
162 | #define ERR_UNMATCHED 51 |
---|
163 | "Unmatched %c", |
---|
164 | #define ERR_NOMEM 52 |
---|
165 | "Out of memory", |
---|
166 | #define ERR_PIPE 53 |
---|
167 | "Can't make pipe", |
---|
168 | #define ERR_SYSTEM 54 |
---|
169 | "%s: %s", |
---|
170 | #define ERR_STRING 55 |
---|
171 | "%s", |
---|
172 | #define ERR_JOBS 56 |
---|
173 | "Usage: jobs [ -l ]", |
---|
174 | #define ERR_JOBARGS 57 |
---|
175 | "Arguments should be jobs or process id's", |
---|
176 | #define ERR_JOBCUR 58 |
---|
177 | "No current job", |
---|
178 | #define ERR_JOBPREV 59 |
---|
179 | "No previous job", |
---|
180 | #define ERR_JOBPAT 60 |
---|
181 | "No job matches pattern", |
---|
182 | #define ERR_NESTING 61 |
---|
183 | "Fork nesting > %d; maybe `...` loop", |
---|
184 | #define ERR_JOBCTRLSUB 62 |
---|
185 | "No job control in subshells", |
---|
186 | #define ERR_SYNC 63 |
---|
187 | "Sunc fault: Process %d not found", |
---|
188 | #define ERR_STOPPED 64 |
---|
189 | #ifdef SUSPENDED |
---|
190 | "%sThere are suspended jobs", |
---|
191 | #else |
---|
192 | "%sThere are stopped jobs", |
---|
193 | #endif /* SUSPENDED */ |
---|
194 | #define ERR_NODIR 65 |
---|
195 | "No other directory", |
---|
196 | #define ERR_EMPTY 66 |
---|
197 | "Directory stack empty", |
---|
198 | #define ERR_BADDIR 67 |
---|
199 | "Bad directory", |
---|
200 | #define ERR_DIRUS 68 |
---|
201 | "Usage: %s [-%s]%s", |
---|
202 | #define ERR_HFLAG 69 |
---|
203 | "No operand for -h flag", |
---|
204 | #define ERR_NOTLOGIN 70 |
---|
205 | "Not a login shell", |
---|
206 | #define ERR_DIV0 71 |
---|
207 | "Division by 0", |
---|
208 | #define ERR_MOD0 72 |
---|
209 | "Mod by 0", |
---|
210 | #define ERR_BADSCALE 73 |
---|
211 | "Bad scaling; did you mean \"%s\"?", |
---|
212 | #define ERR_SUSPLOG 74 |
---|
213 | "Can't suspend a login shell (yet)", |
---|
214 | #define ERR_UNKUSER 75 |
---|
215 | "Unknown user: %s", |
---|
216 | #define ERR_NOHOME 76 |
---|
217 | "No $home variable set", |
---|
218 | #define ERR_HISTUS 77 |
---|
219 | "Usage: history [-%s] [# number of events]", |
---|
220 | #define ERR_SPDOLLT 78 |
---|
221 | "$, ! or < not allowed with $# or $?", |
---|
222 | #define ERR_NEWLINE 79 |
---|
223 | "Newline in variable name", |
---|
224 | #define ERR_SPSTAR 80 |
---|
225 | "* not allowed with $# or $?", |
---|
226 | #define ERR_DIGIT 81 |
---|
227 | "$?<digit> or $#<digit> not allowed", |
---|
228 | #define ERR_VARILL 82 |
---|
229 | "Illegal variable name", |
---|
230 | #define ERR_NLINDEX 83 |
---|
231 | "Newline in variable index", |
---|
232 | #define ERR_EXPOVFL 84 |
---|
233 | "Expansion buffer overflow", |
---|
234 | #define ERR_VARSYN 85 |
---|
235 | "Variable syntax", |
---|
236 | #define ERR_BADBANG 86 |
---|
237 | "Bad ! form", |
---|
238 | #define ERR_NOSUBST 87 |
---|
239 | "No previous substitute", |
---|
240 | #define ERR_BADSUBST 88 |
---|
241 | "Bad substitute", |
---|
242 | #define ERR_LHS 89 |
---|
243 | "No previous left hand side", |
---|
244 | #define ERR_RHSLONG 90 |
---|
245 | "Right hand side too long", |
---|
246 | #define ERR_BADBANGMOD 91 |
---|
247 | "Bad ! modifier: %c", |
---|
248 | #define ERR_MODFAIL 92 |
---|
249 | "Modifier failed", |
---|
250 | #define ERR_SUBOVFL 93 |
---|
251 | "Substitution buffer overflow", |
---|
252 | #define ERR_BADBANGARG 94 |
---|
253 | "Bad ! arg selector", |
---|
254 | #define ERR_NOSEARCH 95 |
---|
255 | "No prev search", |
---|
256 | #define ERR_NOEVENT 96 |
---|
257 | "%s: Event not found", |
---|
258 | #define ERR_TOOMANYRP 97 |
---|
259 | "Too many )'s", |
---|
260 | #define ERR_TOOMANYLP 98 |
---|
261 | "Too many ('s", |
---|
262 | #define ERR_BADPLP 99 |
---|
263 | "Badly placed (", |
---|
264 | #define ERR_MISRED 100 |
---|
265 | "Missing name for redirect", |
---|
266 | #define ERR_OUTRED 101 |
---|
267 | "Ambiguous output redirect", |
---|
268 | #define ERR_REDPAR 102 |
---|
269 | "Can't << within ()'s", |
---|
270 | #define ERR_INRED 103 |
---|
271 | "Ambiguous input redirect", |
---|
272 | #define ERR_BADPLPS 104 |
---|
273 | "Badly placed ()'s", |
---|
274 | #define ERR_ALIASLOOP 105 |
---|
275 | "Alias loop", |
---|
276 | #define ERR_NOWATCH 106 |
---|
277 | "No $watch variable set", |
---|
278 | #define ERR_NOSCHED 107 |
---|
279 | "No scheduled events", |
---|
280 | #define ERR_SCHEDUSAGE 108 |
---|
281 | "Usage: sched -<item#>.\nUsage: sched [+]hh:mm <command>", |
---|
282 | #define ERR_SCHEDEV 109 |
---|
283 | "Not that many scheduled events", |
---|
284 | #define ERR_SCHEDCOM 110 |
---|
285 | "No command to run", |
---|
286 | #define ERR_SCHEDTIME 111 |
---|
287 | "Invalid time for event", |
---|
288 | #define ERR_SCHEDREL 112 |
---|
289 | "Relative time inconsistent with am/pm", |
---|
290 | #define ERR_TCNOSTR 113 |
---|
291 | "Out of termcap string space", |
---|
292 | #define ERR_SETTCUS 114 |
---|
293 | "Usage: settc %s [yes|no]", |
---|
294 | #define ERR_TCCAP 115 |
---|
295 | "Unknown capability `%s'", |
---|
296 | #define ERR_TCPARM 116 |
---|
297 | "Unknown termcap parameter `%%%c'", |
---|
298 | #define ERR_TCARGS 117 |
---|
299 | "Too many arguments for `%s' (%d)", |
---|
300 | #define ERR_TCNARGS 118 |
---|
301 | "`%s' requires %d arguments", |
---|
302 | #define ERR_TCUSAGE 119 |
---|
303 | "Usage: echotc [-v|-s] [<capability> [<args>]]", |
---|
304 | #define ERR_ARCH 120 |
---|
305 | "%s: %s. Wrong Architecture", |
---|
306 | #define ERR_HISTLOOP 121 |
---|
307 | "!# History loop", |
---|
308 | #define ERR_FILEINQ 122 |
---|
309 | "Malformed file inquiry", |
---|
310 | #define ERR_SELOVFL 123 |
---|
311 | "Selector overflow", |
---|
312 | #define ERR_TCSHUSAGE 124 |
---|
313 | #ifdef apollo |
---|
314 | "Unknown option: -%s\nUsage: tcsh [ -bcdefilmnqstvVxX -Dname[=value] ] [ argument ... ]", |
---|
315 | #else /* !apollo */ |
---|
316 | # ifdef convex |
---|
317 | "Unknown option: -%s\nUsage: tcsh [ -bcdefFilmnqstvVxX ] [ argument ... ]", |
---|
318 | # else /* rest */ |
---|
319 | "Unknown option: -%s\nUsage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ]", |
---|
320 | # endif /* convex */ |
---|
321 | #endif /* apollo */ |
---|
322 | #define ERR_COMPCOM 125 |
---|
323 | "Illegal completion: \"%s\"", |
---|
324 | #define ERR_COMPILL 126 |
---|
325 | "Illegal %s: '%c'", |
---|
326 | #define ERR_COMPINC 127 |
---|
327 | "Incomplete %s: \"%s\"", |
---|
328 | #define ERR_INVALID 128 |
---|
329 | "Invalid Error" |
---|
330 | }; |
---|
331 | |
---|
332 | /* |
---|
333 | * The parser and scanner set up errors for later by calling seterr, |
---|
334 | * which sets the variable err as a side effect; later to be tested, |
---|
335 | * e.g. in process. |
---|
336 | */ |
---|
337 | void |
---|
338 | /*VARARGS1*/ |
---|
339 | #if __STDC__ |
---|
340 | seterror(unsigned int id, ...) |
---|
341 | #else |
---|
342 | seterror(va_alist) |
---|
343 | va_dcl |
---|
344 | #endif |
---|
345 | { |
---|
346 | |
---|
347 | if (seterr == 0) { |
---|
348 | va_list va; |
---|
349 | char berr[BUFSIZE]; |
---|
350 | #if __STDC__ |
---|
351 | va_start(va, id); |
---|
352 | #else |
---|
353 | unsigned int id; |
---|
354 | va_start(va); |
---|
355 | id = va_arg(va, unsigned int); |
---|
356 | #endif |
---|
357 | |
---|
358 | if (id >= sizeof(errorlist) / sizeof(errorlist[0])) |
---|
359 | id = ERR_INVALID; |
---|
360 | xvsprintf(berr, errorlist[id], va); |
---|
361 | va_end(va); |
---|
362 | |
---|
363 | seterr = strsave(berr); |
---|
364 | } |
---|
365 | } |
---|
366 | |
---|
367 | /* |
---|
368 | * Print the error with the given id. |
---|
369 | * |
---|
370 | * Special ids: |
---|
371 | * ERR_SILENT: Print nothing. |
---|
372 | * ERR_OLD: Print the previously set error if one was there. |
---|
373 | * otherwise return. |
---|
374 | * ERR_NAME: If this bit is set, print the name of the function |
---|
375 | * in bname |
---|
376 | * |
---|
377 | * This routine always resets or exits. The flag haderr |
---|
378 | * is set so the routine who catches the unwind can propogate |
---|
379 | * it if they want. |
---|
380 | * |
---|
381 | * Note that any open files at the point of error will eventually |
---|
382 | * be closed in the routine process in sh.c which is the only |
---|
383 | * place error unwinds are ever caught. |
---|
384 | */ |
---|
385 | void |
---|
386 | /*VARARGS*/ |
---|
387 | #if __STDC__ |
---|
388 | stderror(unsigned int id, ...) |
---|
389 | #else |
---|
390 | stderror(va_alist) |
---|
391 | va_dcl |
---|
392 | #endif |
---|
393 | { |
---|
394 | va_list va; |
---|
395 | register Char **v; |
---|
396 | int flags; |
---|
397 | |
---|
398 | #if __STDC__ |
---|
399 | va_start(va, id); |
---|
400 | #else |
---|
401 | unsigned int id; |
---|
402 | |
---|
403 | va_start(va); |
---|
404 | id = va_arg(va, unsigned int); |
---|
405 | #endif |
---|
406 | |
---|
407 | /* |
---|
408 | * Reset don't free flag for buggy os's |
---|
409 | */ |
---|
410 | dont_free = 0; |
---|
411 | |
---|
412 | flags = id & ERR_FLAGS; |
---|
413 | id &= ~ERR_FLAGS; |
---|
414 | |
---|
415 | if ((flags & ERR_OLD) && seterr == NULL) { |
---|
416 | va_end(va); |
---|
417 | return; |
---|
418 | } |
---|
419 | |
---|
420 | if (id >= sizeof(errorlist) / sizeof(errorlist[0])) |
---|
421 | id = ERR_INVALID; |
---|
422 | |
---|
423 | /* |
---|
424 | * Must flush before we print as we wish output before the error to go on |
---|
425 | * (some form of) standard output, while output after goes on (some form |
---|
426 | * of) diagnostic output. If didfds then output will go to 1/2 else to |
---|
427 | * FSHOUT/FSHDIAG. See flush in sh.print.c. |
---|
428 | */ |
---|
429 | flush(); |
---|
430 | haderr = 1; /* Now to diagnostic output */ |
---|
431 | timflg = 0; /* This isn't otherwise reset */ |
---|
432 | |
---|
433 | |
---|
434 | if (!(flags & ERR_SILENT)) { |
---|
435 | if (flags & ERR_NAME) |
---|
436 | xprintf("%s: ", bname); |
---|
437 | if ((flags & ERR_OLD)) |
---|
438 | /* Old error. */ |
---|
439 | xprintf("%s.\n", seterr); |
---|
440 | else { |
---|
441 | xvprintf(errorlist[id], va); |
---|
442 | xprintf(".\n"); |
---|
443 | } |
---|
444 | } |
---|
445 | va_end(va); |
---|
446 | |
---|
447 | if (seterr) { |
---|
448 | xfree((ptr_t) seterr); |
---|
449 | seterr = NULL; |
---|
450 | } |
---|
451 | |
---|
452 | if ((v = pargv) != 0) |
---|
453 | pargv = 0, blkfree(v); |
---|
454 | if ((v = gargv) != 0) |
---|
455 | gargv = 0, blkfree(v); |
---|
456 | |
---|
457 | didfds = 0; /* Forget about 0,1,2 */ |
---|
458 | /* |
---|
459 | * Go away if -e or we are a child shell |
---|
460 | */ |
---|
461 | if (exiterr || child) |
---|
462 | xexit(1); |
---|
463 | |
---|
464 | /* |
---|
465 | * Reset the state of the input. This buffered seek to end of file will |
---|
466 | * also clear the while/foreach stack. |
---|
467 | */ |
---|
468 | btoeof(); |
---|
469 | |
---|
470 | set(STRstatus, Strsave(STR1)); |
---|
471 | #ifdef BSDJOBS |
---|
472 | if (tpgrp > 0) |
---|
473 | (void) tcsetpgrp(FSHTTY, tpgrp); |
---|
474 | #endif |
---|
475 | reset(); /* Unwind */ |
---|
476 | } |
---|