sh.err.c revision 167465
1167465Smp/* $Header: /p/tcsh/cvsroot/tcsh/sh.err.c,v 3.48 2006/03/02 18:46:44 christos Exp $ */ 259243Sobrien/* 359243Sobrien * sh.err.c: Error printing routines. 459243Sobrien */ 559243Sobrien/*- 659243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California. 759243Sobrien * All rights reserved. 859243Sobrien * 959243Sobrien * Redistribution and use in source and binary forms, with or without 1059243Sobrien * modification, are permitted provided that the following conditions 1159243Sobrien * are met: 1259243Sobrien * 1. Redistributions of source code must retain the above copyright 1359243Sobrien * notice, this list of conditions and the following disclaimer. 1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1559243Sobrien * notice, this list of conditions and the following disclaimer in the 1659243Sobrien * documentation and/or other materials provided with the distribution. 17100616Smp * 3. Neither the name of the University nor the names of its contributors 1859243Sobrien * may be used to endorse or promote products derived from this software 1959243Sobrien * without specific prior written permission. 2059243Sobrien * 2159243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2259243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2359243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2459243Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2559243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2659243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2759243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2859243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2959243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3059243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3159243Sobrien * SUCH DAMAGE. 3259243Sobrien */ 3359243Sobrien#define _h_sh_err /* Don't redefine the errors */ 3459243Sobrien#include "sh.h" 35167465Smp#include <assert.h> 3659243Sobrien 37167465SmpRCSID("$tcsh: sh.err.c,v 3.48 2006/03/02 18:46:44 christos Exp $") 3859243Sobrien 3959243Sobrien/* 4059243Sobrien * C Shell 4159243Sobrien */ 4259243Sobrien 4359243Sobrien#ifdef lint 4459243Sobrien#undef va_arg 4559243Sobrien#define va_arg(a, b) (a ? (b) 0 : (b) 0) 4659243Sobrien#endif 4759243Sobrien 4859243Sobrienchar *seterr = NULL; /* Holds last error if there was one */ 4959243Sobrien 5059243Sobrien#define ERR_FLAGS 0xf0000000 5159243Sobrien#define ERR_NAME 0x10000000 5259243Sobrien#define ERR_SILENT 0x20000000 5359243Sobrien#define ERR_OLD 0x40000000 5459243Sobrien 5559243Sobrien#define ERR_SYNTAX 0 5659243Sobrien#define ERR_NOTALLOWED 1 5759243Sobrien#define ERR_WTOOLONG 2 5859243Sobrien#define ERR_LTOOLONG 3 5959243Sobrien#define ERR_DOLZERO 4 6059243Sobrien#define ERR_INCBR 5 6159243Sobrien#define ERR_EXPORD 6 6259243Sobrien#define ERR_BADMOD 7 6359243Sobrien#define ERR_SUBSCRIPT 8 6459243Sobrien#define ERR_BADNUM 9 6559243Sobrien#define ERR_NOMORE 10 6659243Sobrien#define ERR_FILENAME 11 6759243Sobrien#define ERR_GLOB 12 6859243Sobrien#define ERR_COMMAND 13 6959243Sobrien#define ERR_TOOFEW 14 7059243Sobrien#define ERR_TOOMANY 15 7159243Sobrien#define ERR_DANGER 16 7259243Sobrien#define ERR_EMPTYIF 17 7359243Sobrien#define ERR_IMPRTHEN 18 7459243Sobrien#define ERR_NOPAREN 19 7559243Sobrien#define ERR_NOTFOUND 20 7659243Sobrien#define ERR_MASK 21 7759243Sobrien#define ERR_LIMIT 22 7859243Sobrien#define ERR_TOOLARGE 23 7959243Sobrien#define ERR_SCALEF 24 8059243Sobrien#define ERR_UNDVAR 25 8159243Sobrien#define ERR_DEEP 26 8259243Sobrien#define ERR_BADSIG 27 8359243Sobrien#define ERR_UNKSIG 28 8459243Sobrien#define ERR_VARBEGIN 29 8559243Sobrien#define ERR_VARTOOLONG 30 8659243Sobrien#define ERR_VARALNUM 31 8759243Sobrien#define ERR_JOBCONTROL 32 8859243Sobrien#define ERR_EXPRESSION 33 8959243Sobrien#define ERR_NOHOMEDIR 34 9059243Sobrien#define ERR_CANTCHANGE 35 9159243Sobrien#define ERR_NULLCOM 36 9259243Sobrien#define ERR_ASSIGN 37 9359243Sobrien#define ERR_UNKNOWNOP 38 9459243Sobrien#define ERR_AMBIG 39 9559243Sobrien#define ERR_EXISTS 40 9659243Sobrien#define ERR_ARGC 41 9759243Sobrien#define ERR_INTR 42 9859243Sobrien#define ERR_RANGE 43 9959243Sobrien#define ERR_OVERFLOW 44 10059243Sobrien#define ERR_NOSUCHJOB 45 10159243Sobrien#define ERR_TERMINAL 46 10259243Sobrien#define ERR_NOTWHILE 47 10359243Sobrien#define ERR_NOPROC 48 10459243Sobrien#define ERR_NOMATCH 49 10559243Sobrien#define ERR_MISSING 50 10659243Sobrien#define ERR_UNMATCHED 51 10759243Sobrien#define ERR_NOMEM 52 10859243Sobrien#define ERR_PIPE 53 10959243Sobrien#define ERR_SYSTEM 54 11059243Sobrien#define ERR_STRING 55 11159243Sobrien#define ERR_JOBS 56 11259243Sobrien#define ERR_JOBARGS 57 11359243Sobrien#define ERR_JOBCUR 58 11459243Sobrien#define ERR_JOBPREV 59 11559243Sobrien#define ERR_JOBPAT 60 11659243Sobrien#define ERR_NESTING 61 11759243Sobrien#define ERR_JOBCTRLSUB 62 11859243Sobrien#define ERR_SYNC 63 11959243Sobrien#define ERR_STOPPED 64 12059243Sobrien#define ERR_NODIR 65 12159243Sobrien#define ERR_EMPTY 66 12259243Sobrien#define ERR_BADDIR 67 12359243Sobrien#define ERR_DIRUS 68 12459243Sobrien#define ERR_HFLAG 69 12559243Sobrien#define ERR_NOTLOGIN 70 12659243Sobrien#define ERR_DIV0 71 12759243Sobrien#define ERR_MOD0 72 12859243Sobrien#define ERR_BADSCALE 73 12959243Sobrien#define ERR_SUSPLOG 74 13059243Sobrien#define ERR_UNKUSER 75 13159243Sobrien#define ERR_NOHOME 76 13259243Sobrien#define ERR_HISTUS 77 13359243Sobrien#define ERR_SPDOLLT 78 13459243Sobrien#define ERR_NEWLINE 79 13559243Sobrien#define ERR_SPSTAR 80 13659243Sobrien#define ERR_DIGIT 81 13759243Sobrien#define ERR_VARILL 82 13859243Sobrien#define ERR_NLINDEX 83 13959243Sobrien#define ERR_EXPOVFL 84 14059243Sobrien#define ERR_VARSYN 85 14159243Sobrien#define ERR_BADBANG 86 14259243Sobrien#define ERR_NOSUBST 87 14359243Sobrien#define ERR_BADSUBST 88 14459243Sobrien#define ERR_LHS 89 14559243Sobrien#define ERR_RHSLONG 90 14659243Sobrien#define ERR_BADBANGMOD 91 14759243Sobrien#define ERR_MODFAIL 92 14859243Sobrien#define ERR_SUBOVFL 93 14959243Sobrien#define ERR_BADBANGARG 94 15059243Sobrien#define ERR_NOSEARCH 95 15159243Sobrien#define ERR_NOEVENT 96 15259243Sobrien#define ERR_TOOMANYRP 97 15359243Sobrien#define ERR_TOOMANYLP 98 15459243Sobrien#define ERR_BADPLP 99 15559243Sobrien#define ERR_MISRED 100 15659243Sobrien#define ERR_OUTRED 101 15759243Sobrien#define ERR_REDPAR 102 15859243Sobrien#define ERR_INRED 103 15959243Sobrien#define ERR_BADPLPS 104 16059243Sobrien#define ERR_ALIASLOOP 105 16159243Sobrien#define ERR_NOWATCH 106 16259243Sobrien#define ERR_NOSCHED 107 16359243Sobrien#define ERR_SCHEDUSAGE 108 16459243Sobrien#define ERR_SCHEDEV 109 16559243Sobrien#define ERR_SCHEDCOM 110 16659243Sobrien#define ERR_SCHEDTIME 111 16759243Sobrien#define ERR_SCHEDREL 112 16859243Sobrien#define ERR_TCNOSTR 113 16959243Sobrien#define ERR_SETTCUS 114 17059243Sobrien#define ERR_TCCAP 115 17159243Sobrien#define ERR_TCPARM 116 17259243Sobrien#define ERR_TCARGS 117 17359243Sobrien#define ERR_TCNARGS 118 17459243Sobrien#define ERR_TCUSAGE 119 17559243Sobrien#define ERR_ARCH 120 17659243Sobrien#define ERR_HISTLOOP 121 17759243Sobrien#define ERR_FILEINQ 122 17859243Sobrien#define ERR_SELOVFL 123 17959243Sobrien#define ERR_TCSHUSAGE 124 18059243Sobrien#define ERR_COMPCOM 125 18159243Sobrien#define ERR_COMPINV 126 18259243Sobrien#define ERR_COMPMIS 127 18359243Sobrien#define ERR_COMPINC 128 18459243Sobrien#define ERR_MFLAG 129 18559243Sobrien#define ERR_ULIMUS 130 18659243Sobrien#define ERR_READONLY 131 18759243Sobrien#define ERR_BADJOB 132 18859243Sobrien#define ERR_INVALID 133 18959243Sobrien#define ERR_BADCOLORVAR 134 19059243Sobrien#define NO_ERRORS 135 19159243Sobrien 192145479Smpstatic const char *elst[NO_ERRORS] INIT_ZERO_STRUCT; 19359243Sobrien 19459243Sobrien/* 19559243Sobrien * Init the elst depending on the locale 19659243Sobrien */ 19759243Sobrienvoid 198167465Smperrinit(void) 19959243Sobrien{ 20059243Sobrien#ifdef NLS_CATALOGS 201167465Smp size_t i; 20259243Sobrien 20359243Sobrien for (i = 0; i < NO_ERRORS; i++) 204167465Smp xfree((char *)(intptr_t)elst[i]); 20559243Sobrien# if defined(__FreeBSD__) || defined(hpux) 20659243Sobrien# define NLS_MAXSET 30 20759243Sobrien for (i = 1; i <= NLS_MAXSET; i++) 20859243Sobrien CGETS(i, 1, "" ); 20959243Sobrien# endif 21059243Sobrien#endif 21159243Sobrien 21259243Sobrien elst[ERR_SYNTAX] = CSAVS(1, 1, "Syntax Error"); 21359243Sobrien elst[ERR_NOTALLOWED] = CSAVS(1, 2, "%s is not allowed"); 21459243Sobrien elst[ERR_WTOOLONG] = CSAVS(1, 3, "Word too long"); 21559243Sobrien elst[ERR_LTOOLONG] = CSAVS(1, 4, "$< line too long"); 21659243Sobrien elst[ERR_DOLZERO] = CSAVS(1, 5, "No file for $0"); 21759243Sobrien elst[ERR_INCBR] = CSAVS(1, 6, "Incomplete [] modifier"); 21859243Sobrien elst[ERR_EXPORD] = CSAVS(1, 7, "$ expansion must end before ]"); 21959243Sobrien elst[ERR_BADMOD] = CSAVS(1, 8, "Bad : modifier in $ (%c)"); 22059243Sobrien elst[ERR_SUBSCRIPT] = CSAVS(1, 9, "Subscript error"); 22159243Sobrien elst[ERR_BADNUM] = CSAVS(1, 10, "Badly formed number"); 22259243Sobrien elst[ERR_NOMORE] = CSAVS(1, 11, "No more words"); 22359243Sobrien elst[ERR_FILENAME] = CSAVS(1, 12, "Missing file name"); 22459243Sobrien elst[ERR_GLOB] = CSAVS(1, 13, "Internal glob error"); 22559243Sobrien elst[ERR_COMMAND] = CSAVS(1, 14, "Command not found"); 22659243Sobrien elst[ERR_TOOFEW] = CSAVS(1, 15, "Too few arguments"); 22759243Sobrien elst[ERR_TOOMANY] = CSAVS(1, 16, "Too many arguments"); 22859243Sobrien elst[ERR_DANGER] = CSAVS(1, 17, "Too dangerous to alias that"); 22959243Sobrien elst[ERR_EMPTYIF] = CSAVS(1, 18, "Empty if"); 23059243Sobrien elst[ERR_IMPRTHEN] = CSAVS(1, 19, "Improper then"); 23159243Sobrien elst[ERR_NOPAREN] = CSAVS(1, 20, "Words not parenthesized"); 23259243Sobrien elst[ERR_NOTFOUND] = CSAVS(1, 21, "%s not found"); 23359243Sobrien elst[ERR_MASK] = CSAVS(1, 22, "Improper mask"); 23459243Sobrien elst[ERR_LIMIT] = CSAVS(1, 23, "No such limit"); 23559243Sobrien elst[ERR_TOOLARGE] = CSAVS(1, 24, "Argument too large"); 23659243Sobrien elst[ERR_SCALEF] = CSAVS(1, 25, "Improper or unknown scale factor"); 23759243Sobrien elst[ERR_UNDVAR] = CSAVS(1, 26, "Undefined variable"); 23859243Sobrien elst[ERR_DEEP] = CSAVS(1, 27, "Directory stack not that deep"); 23959243Sobrien elst[ERR_BADSIG] = CSAVS(1, 28, "Bad signal number"); 24059243Sobrien elst[ERR_UNKSIG] = CSAVS(1, 29, "Unknown signal; kill -l lists signals"); 24159243Sobrien elst[ERR_VARBEGIN] = CSAVS(1, 30, "Variable name must begin with a letter"); 24259243Sobrien elst[ERR_VARTOOLONG] = CSAVS(1, 31, "Variable name too long"); 24359243Sobrien elst[ERR_VARALNUM] = CSAVS(1, 32, 24459243Sobrien "Variable name must contain alphanumeric characters"); 24559243Sobrien elst[ERR_JOBCONTROL] = CSAVS(1, 33, "No job control in this shell"); 24659243Sobrien elst[ERR_EXPRESSION] = CSAVS(1, 34, "Expression Syntax"); 24759243Sobrien elst[ERR_NOHOMEDIR] = CSAVS(1, 35, "No home directory"); 24859243Sobrien elst[ERR_CANTCHANGE] = CSAVS(1, 36, "Can't change to home directory"); 24959243Sobrien elst[ERR_NULLCOM] = CSAVS(1, 37, "Invalid null command"); 25059243Sobrien elst[ERR_ASSIGN] = CSAVS(1, 38, "Assignment missing expression"); 25159243Sobrien elst[ERR_UNKNOWNOP] = CSAVS(1, 39, "Unknown operator"); 25259243Sobrien elst[ERR_AMBIG] = CSAVS(1, 40, "Ambiguous"); 25359243Sobrien elst[ERR_EXISTS] = CSAVS(1, 41, "%s: File exists"); 25459243Sobrien elst[ERR_ARGC] = CSAVS(1, 42, "Argument for -c ends in backslash"); 25559243Sobrien elst[ERR_INTR] = CSAVS(1, 43, "Interrupted"); 25659243Sobrien elst[ERR_RANGE] = CSAVS(1, 44, "Subscript out of range"); 25759243Sobrien elst[ERR_OVERFLOW] = CSAVS(1, 45, "Line overflow"); 25859243Sobrien elst[ERR_NOSUCHJOB] = CSAVS(1, 46, "No such job"); 25959243Sobrien elst[ERR_TERMINAL] = CSAVS(1, 47, "Can't from terminal"); 26059243Sobrien elst[ERR_NOTWHILE] = CSAVS(1, 48, "Not in while/foreach"); 26159243Sobrien elst[ERR_NOPROC] = CSAVS(1, 49, "No more processes"); 26259243Sobrien elst[ERR_NOMATCH] = CSAVS(1, 50, "No match"); 26359243Sobrien elst[ERR_MISSING] = CSAVS(1, 51, "Missing %c"); 26459243Sobrien elst[ERR_UNMATCHED] = CSAVS(1, 52, "Unmatched %c"); 26559243Sobrien elst[ERR_NOMEM] = CSAVS(1, 53, "Out of memory"); 26659243Sobrien elst[ERR_PIPE] = CSAVS(1, 54, "Can't make pipe"); 26759243Sobrien elst[ERR_SYSTEM] = CSAVS(1, 55, "%s: %s"); 26859243Sobrien elst[ERR_STRING] = CSAVS(1, 56, "%s"); 26959243Sobrien elst[ERR_JOBS] = CSAVS(1, 57, "Usage: jobs [ -l ]"); 27059243Sobrien elst[ERR_JOBARGS] = CSAVS(1, 58, "Arguments should be jobs or process id's"); 27159243Sobrien elst[ERR_JOBCUR] = CSAVS(1, 59, "No current job"); 27259243Sobrien elst[ERR_JOBPREV] = CSAVS(1, 60, "No previous job"); 27359243Sobrien elst[ERR_JOBPAT] = CSAVS(1, 61, "No job matches pattern"); 27459243Sobrien elst[ERR_NESTING] = CSAVS(1, 62, "Fork nesting > %d; maybe `...` loop"); 27559243Sobrien elst[ERR_JOBCTRLSUB] = CSAVS(1, 63, "No job control in subshells"); 27659243Sobrien elst[ERR_SYNC] = CSAVS(1, 64, "Sync fault: Process %d not found"); 27759243Sobrien elst[ERR_STOPPED] = 27859243Sobrien#ifdef SUSPENDED 27959243Sobrien CSAVS(1, 65, "%sThere are suspended jobs"); 28059243Sobrien#else 28159243Sobrien CSAVS(1, 66, "%sThere are stopped jobs"); 28259243Sobrien#endif /* SUSPENDED */ 28359243Sobrien elst[ERR_NODIR] = CSAVS(1, 67, "No other directory"); 28459243Sobrien elst[ERR_EMPTY] = CSAVS(1, 68, "Directory stack empty"); 28559243Sobrien elst[ERR_BADDIR] = CSAVS(1, 69, "Bad directory"); 28659243Sobrien elst[ERR_DIRUS] = CSAVS(1, 70, "Usage: %s [-%s]%s"); 28759243Sobrien elst[ERR_HFLAG] = CSAVS(1, 71, "No operand for -h flag"); 28859243Sobrien elst[ERR_NOTLOGIN] = CSAVS(1, 72, "Not a login shell"); 28959243Sobrien elst[ERR_DIV0] = CSAVS(1, 73, "Division by 0"); 29059243Sobrien elst[ERR_MOD0] = CSAVS(1, 74, "Mod by 0"); 29159243Sobrien elst[ERR_BADSCALE] = CSAVS(1, 75, "Bad scaling; did you mean \"%s\"?"); 29259243Sobrien elst[ERR_SUSPLOG] = CSAVS(1, 76, "Can't suspend a login shell (yet)"); 29359243Sobrien elst[ERR_UNKUSER] = CSAVS(1, 77, "Unknown user: %s"); 29459243Sobrien elst[ERR_NOHOME] = CSAVS(1, 78, "No $home variable set"); 29559243Sobrien elst[ERR_HISTUS] = CSAVS(1, 79, 29659243Sobrien "Usage: history [-%s] [# number of events]"); 29759243Sobrien elst[ERR_SPDOLLT] = CSAVS(1, 80, "$, ! or < not allowed with $# or $?"); 29859243Sobrien elst[ERR_NEWLINE] = CSAVS(1, 81, "Newline in variable name"); 29959243Sobrien elst[ERR_SPSTAR] = CSAVS(1, 82, "* not allowed with $# or $?"); 30059243Sobrien elst[ERR_DIGIT] = CSAVS(1, 83, "$?<digit> or $#<digit> not allowed"); 30159243Sobrien elst[ERR_VARILL] = CSAVS(1, 84, "Illegal variable name"); 30259243Sobrien elst[ERR_NLINDEX] = CSAVS(1, 85, "Newline in variable index"); 30359243Sobrien elst[ERR_EXPOVFL] = CSAVS(1, 86, "Expansion buffer overflow"); 30459243Sobrien elst[ERR_VARSYN] = CSAVS(1, 87, "Variable syntax"); 30559243Sobrien elst[ERR_BADBANG] = CSAVS(1, 88, "Bad ! form"); 30659243Sobrien elst[ERR_NOSUBST] = CSAVS(1, 89, "No previous substitute"); 30759243Sobrien elst[ERR_BADSUBST] = CSAVS(1, 90, "Bad substitute"); 30859243Sobrien elst[ERR_LHS] = CSAVS(1, 91, "No previous left hand side"); 30959243Sobrien elst[ERR_RHSLONG] = CSAVS(1, 92, "Right hand side too long"); 31059243Sobrien elst[ERR_BADBANGMOD] = CSAVS(1, 93, "Bad ! modifier: %c"); 31159243Sobrien elst[ERR_MODFAIL] = CSAVS(1, 94, "Modifier failed"); 31259243Sobrien elst[ERR_SUBOVFL] = CSAVS(1, 95, "Substitution buffer overflow"); 31359243Sobrien elst[ERR_BADBANGARG] = CSAVS(1, 96, "Bad ! arg selector"); 31459243Sobrien elst[ERR_NOSEARCH] = CSAVS(1, 97, "No prev search"); 31559243Sobrien elst[ERR_NOEVENT] = CSAVS(1, 98, "%s: Event not found"); 31659243Sobrien elst[ERR_TOOMANYRP] = CSAVS(1, 99, "Too many )'s"); 31759243Sobrien elst[ERR_TOOMANYLP] = CSAVS(1, 100, "Too many ('s"); 31859243Sobrien elst[ERR_BADPLP] = CSAVS(1, 101, "Badly placed ("); 31959243Sobrien elst[ERR_MISRED] = CSAVS(1, 102, "Missing name for redirect"); 32059243Sobrien elst[ERR_OUTRED] = CSAVS(1, 103, "Ambiguous output redirect"); 32159243Sobrien elst[ERR_REDPAR] = CSAVS(1, 104, "Can't << within ()'s"); 32259243Sobrien elst[ERR_INRED] = CSAVS(1, 105, "Ambiguous input redirect"); 32359243Sobrien elst[ERR_BADPLPS] = CSAVS(1, 106, "Badly placed ()'s"); 32459243Sobrien elst[ERR_ALIASLOOP] = CSAVS(1, 107, "Alias loop"); 32559243Sobrien elst[ERR_NOWATCH] = CSAVS(1, 108, "No $watch variable set"); 32659243Sobrien elst[ERR_NOSCHED] = CSAVS(1, 109, "No scheduled events"); 32759243Sobrien elst[ERR_SCHEDUSAGE] = CSAVS(1, 110, 32859243Sobrien "Usage: sched -<item#>.\nUsage: sched [+]hh:mm <command>"); 32959243Sobrien elst[ERR_SCHEDEV] = CSAVS(1, 111, "Not that many scheduled events"); 33059243Sobrien elst[ERR_SCHEDCOM] = CSAVS(1, 112, "No command to run"); 33159243Sobrien elst[ERR_SCHEDTIME] = CSAVS(1, 113, "Invalid time for event"); 33259243Sobrien elst[ERR_SCHEDREL] = CSAVS(1, 114, "Relative time inconsistent with am/pm"); 33359243Sobrien elst[ERR_TCNOSTR] = CSAVS(1, 115, "Out of termcap string space"); 33459243Sobrien elst[ERR_SETTCUS] = CSAVS(1, 116, "Usage: settc %s [yes|no]"); 33559243Sobrien elst[ERR_TCCAP] = CSAVS(1, 117, "Unknown capability `%s'"); 33659243Sobrien elst[ERR_TCPARM] = CSAVS(1, 118, "Unknown termcap parameter `%%%c'"); 33759243Sobrien elst[ERR_TCARGS] = CSAVS(1, 119, "Too many arguments for `%s' (%d)"); 33859243Sobrien elst[ERR_TCNARGS] = CSAVS(1, 120, "`%s' requires %d arguments"); 33959243Sobrien elst[ERR_TCUSAGE] = CSAVS(1, 121, 34059243Sobrien "Usage: echotc [-v|-s] [<capability> [<args>]]"); 34159243Sobrien elst[ERR_ARCH] = CSAVS(1, 122, "%s: %s. Binary file not executable"); 34259243Sobrien elst[ERR_HISTLOOP] = CSAVS(1, 123, "!# History loop"); 34359243Sobrien elst[ERR_FILEINQ] = CSAVS(1, 124, "Malformed file inquiry"); 34459243Sobrien elst[ERR_SELOVFL] = CSAVS(1, 125, "Selector overflow"); 34559243Sobrien#ifdef apollo 34659243Sobrien elst[ERR_TCSHUSAGE] = CSAVS(1, 126, 34759243Sobrien"Unknown option: `-%s'\nUsage: %s [ -bcdefilmnqstvVxX -Dname[=value] ] [ argument ... ]"); 34859243Sobrien#else /* !apollo */ 34959243Sobrien# ifdef convex 35059243Sobrien elst[ERR_TCSHUSAGE] = CSAVS(1, 127, 35159243Sobrien"Unknown option: `-%s'\nUsage: %s [ -bcdefFilmnqstvVxX ] [ argument ... ]"); 35259243Sobrien# else /* rest */ 35359243Sobrien elst[ERR_TCSHUSAGE] = CSAVS(1, 128, 35459243Sobrien"Unknown option: `-%s'\nUsage: %s [ -bcdefilmnqstvVxX ] [ argument ... ]"); 35559243Sobrien# endif /* convex */ 35659243Sobrien#endif /* apollo */ 35759243Sobrien elst[ERR_COMPCOM] = CSAVS(1, 129, "\nInvalid completion: \"%s\""); 35859243Sobrien elst[ERR_COMPINV] = CSAVS(1, 130, "\nInvalid %s: '%c'"); 35959243Sobrien elst[ERR_COMPMIS] = CSAVS(1, 131, 36059243Sobrien "\nMissing separator '%c' after %s \"%s\""); 36159243Sobrien elst[ERR_COMPINC] = CSAVS(1, 132, "\nIncomplete %s: \"%s\""); 36259243Sobrien elst[ERR_MFLAG] = CSAVS(1, 133, "No operand for -m flag"); 36359243Sobrien elst[ERR_ULIMUS] = CSAVS(1, 134, "Usage: unlimit [-fh] [limits]"); 36459243Sobrien elst[ERR_READONLY] = CSAVS(1, 135, "$%S is read-only"); 36559243Sobrien elst[ERR_BADJOB] = CSAVS(1, 136, "No such job (badjob)"); 36659243Sobrien elst[ERR_BADCOLORVAR] = CSAVS(1, 137, "Unknown colorls variable `%c%c'"); 36759243Sobrien} 368167465Smp 369167465Smp/* Cleanup data. */ 370167465Smpstruct cleanup_entry 371167465Smp{ 372167465Smp void *var; 373167465Smp void (*fn) (void *); 374167465Smp#ifdef CLEANUP_DEBUG 375167465Smp const char *file; 376167465Smp size_t line; 377167465Smp#endif 378167465Smp}; 379167465Smp 380167465Smpstatic struct cleanup_entry *cleanup_stack; /* = NULL; */ 381167465Smpstatic size_t cleanup_sp; /* = 0; Next free entry */ 382167465Smpstatic size_t cleanup_mark; /* = 0; Last entry to handle before unwinding */ 383167465Smpstatic size_t cleanup_stack_size; /* = 0 */ 384167465Smp 385167465Smp/* fn() will be run with all signals blocked, so it should not do anything 386167465Smp risky. */ 387167465Smpvoid 388167465Smpcleanup_push_internal(void *var, void (*fn) (void *) 389167465Smp#ifdef CLEANUP_DEBUG 390167465Smp , const char *file, size_t line 391167465Smp#endif 392167465Smp) 393167465Smp{ 394167465Smp struct cleanup_entry *ce; 395167465Smp 396167465Smp if (cleanup_sp == cleanup_stack_size) { 397167465Smp if (cleanup_stack_size == 0) 398167465Smp cleanup_stack_size = 64; /* Arbitrary */ 399167465Smp else 400167465Smp cleanup_stack_size *= 2; 401167465Smp cleanup_stack = xrealloc(cleanup_stack, 402167465Smp cleanup_stack_size * sizeof (*cleanup_stack)); 403167465Smp } 404167465Smp ce = cleanup_stack + cleanup_sp; 405167465Smp ce->var = var; 406167465Smp ce->fn = fn; 407167465Smp#ifdef CLEANUP_DEBUG 408167465Smp ce->file = file; 409167465Smp ce->line = line; 410167465Smp#endif 411167465Smp cleanup_sp++; 412167465Smp} 413167465Smp 414167465Smpstatic void 415167465Smpcleanup_ignore_fn(void *dummy) 416167465Smp{ 417167465Smp USE(dummy); 418167465Smp} 419167465Smp 420167465Smpvoid 421167465Smpcleanup_ignore(void *var) 422167465Smp{ 423167465Smp struct cleanup_entry *ce; 424167465Smp 425167465Smp ce = cleanup_stack + cleanup_sp; 426167465Smp while (ce != cleanup_stack) { 427167465Smp ce--; 428167465Smp if (ce->var == var) { 429167465Smp ce->fn = cleanup_ignore_fn; 430167465Smp return; 431167465Smp } 432167465Smp } 433167465Smp abort(); 434167465Smp} 435167465Smp 436167465Smpvoid 437167465Smpcleanup_until(void *last_var) 438167465Smp{ 439167465Smp while (cleanup_sp != 0) { 440167465Smp struct cleanup_entry ce; 441167465Smp 442167465Smp cleanup_sp--; 443167465Smp ce = cleanup_stack[cleanup_sp]; 444167465Smp ce.fn(ce.var); 445167465Smp if (ce.var == last_var) 446167465Smp return; 447167465Smp } 448167465Smp abort(); 449167465Smp} 450167465Smp 451167465Smpvoid 452167465Smpcleanup_until_mark(void) 453167465Smp{ 454167465Smp while (cleanup_sp > cleanup_mark) { 455167465Smp struct cleanup_entry ce; 456167465Smp 457167465Smp cleanup_sp--; 458167465Smp ce = cleanup_stack[cleanup_sp]; 459167465Smp ce.fn(ce.var); 460167465Smp } 461167465Smp} 462167465Smp 463167465Smpsize_t 464167465Smpcleanup_push_mark(void) 465167465Smp{ 466167465Smp size_t old_mark; 467167465Smp 468167465Smp old_mark = cleanup_mark; 469167465Smp cleanup_mark = cleanup_sp; 470167465Smp return old_mark; 471167465Smp} 472167465Smp 473167465Smpvoid 474167465Smpcleanup_pop_mark(size_t mark) 475167465Smp{ 476167465Smp assert (mark <= cleanup_sp); 477167465Smp cleanup_mark = mark; 478167465Smp} 479167465Smp 480167465Smpvoid 481167465Smpsigint_cleanup(void *xsa) 482167465Smp{ 483167465Smp const struct sigaction *sa; 484167465Smp 485167465Smp sa = xsa; 486167465Smp sigaction(SIGINT, sa, NULL); 487167465Smp} 488167465Smp 489167465Smpvoid 490167465Smpsigprocmask_cleanup(void *xmask) 491167465Smp{ 492167465Smp sigset_t *mask; 493167465Smp 494167465Smp mask = xmask; 495167465Smp sigprocmask(SIG_SETMASK, mask, NULL); 496167465Smp} 497167465Smp 498167465Smpvoid 499167465Smpopen_cleanup(void *xptr) 500167465Smp{ 501167465Smp int *ptr; 502167465Smp 503167465Smp ptr = xptr; 504167465Smp xclose(*ptr); 505167465Smp} 506167465Smp 507167465Smpvoid 508167465Smpopendir_cleanup(void *xdir) 509167465Smp{ 510167465Smp DIR *dir; 511167465Smp 512167465Smp dir = xdir; 513167465Smp xclosedir(dir); 514167465Smp} 515167465Smp 516167465Smpvoid 517167465Smpxfree_indirect(void *xptr) 518167465Smp{ 519167465Smp void **ptr; /* This is actually type punning :( */ 520167465Smp 521167465Smp ptr = xptr; 522167465Smp xfree(*ptr); 523167465Smp} 524167465Smp 525167465Smpvoid 526167465Smpreset(void) 527167465Smp{ 528167465Smp cleanup_until_mark(); 529167465Smp _reset(); 530167465Smp} 531167465Smp 53259243Sobrien/* 53359243Sobrien * The parser and scanner set up errors for later by calling seterr, 53459243Sobrien * which sets the variable err as a side effect; later to be tested, 53559243Sobrien * e.g. in process. 53659243Sobrien */ 53759243Sobrienvoid 53859243Sobrien/*VARARGS1*/ 53959243Sobrienseterror(unsigned int id, ...) 54059243Sobrien{ 54159243Sobrien if (seterr == 0) { 54259243Sobrien va_list va; 543167465Smp 54459243Sobrien va_start(va, id); 54559243Sobrien if (id >= sizeof(elst) / sizeof(elst[0])) 54659243Sobrien id = ERR_INVALID; 547167465Smp seterr = xvasprintf(elst[id], va); 54859243Sobrien va_end(va); 54959243Sobrien } 55059243Sobrien} 55159243Sobrien 55259243Sobrien/* 55359243Sobrien * Print the error with the given id. 55459243Sobrien * 55559243Sobrien * Special ids: 55659243Sobrien * ERR_SILENT: Print nothing. 55759243Sobrien * ERR_OLD: Print the previously set error if one was there. 55859243Sobrien * otherwise return. 55959243Sobrien * ERR_NAME: If this bit is set, print the name of the function 56059243Sobrien * in bname 56159243Sobrien * 56259243Sobrien * This routine always resets or exits. The flag haderr 56359243Sobrien * is set so the routine who catches the unwind can propogate 56459243Sobrien * it if they want. 56559243Sobrien * 56659243Sobrien * Note that any open files at the point of error will eventually 56759243Sobrien * be closed in the routine process in sh.c which is the only 56859243Sobrien * place error unwinds are ever caught. 56959243Sobrien */ 57059243Sobrienvoid 57159243Sobrien/*VARARGS*/ 57259243Sobrienstderror(unsigned int id, ...) 57359243Sobrien{ 57459243Sobrien va_list va; 57559243Sobrien int flags; 57659243Sobrien int vareturn; 57759243Sobrien 57859243Sobrien va_start(va, id); 57959243Sobrien 58059243Sobrien /* 58159243Sobrien * Reset don't free flag for buggy os's 58259243Sobrien */ 58359243Sobrien dont_free = 0; 58459243Sobrien 58559243Sobrien flags = (int) id & ERR_FLAGS; 58659243Sobrien id &= ~ERR_FLAGS; 58759243Sobrien 58859243Sobrien /* Pyramid's OS/x has a subtle bug in <varargs.h> which prevents calling 58959243Sobrien * va_end more than once in the same function. -- sterling@netcom.com 59059243Sobrien */ 59159243Sobrien if (!((flags & ERR_OLD) && seterr == NULL)) { 59259243Sobrien vareturn = 0; /* Don't return immediately after va_end */ 59359243Sobrien if (id >= sizeof(elst) / sizeof(elst[0])) 59459243Sobrien id = ERR_INVALID; 59559243Sobrien 59659243Sobrien /* 59759243Sobrien * Must flush before we print as we wish output before the error to go 59859243Sobrien * on (some form of) standard output, while output after goes on (some 59959243Sobrien * form of) diagnostic output. If didfds then output will go to 1/2 60059243Sobrien * else to FSHOUT/FSHDIAG. See flush in sh.print.c. 60159243Sobrien */ 602167465Smp flush();/*FIXRESET*/ 60359243Sobrien haderr = 1; /* Now to diagnostic output */ 60459243Sobrien 60559243Sobrien if (!(flags & ERR_SILENT)) { 60659243Sobrien if (flags & ERR_NAME) 607167465Smp xprintf("%s: ", bname);/*FIXRESET*/ 60859243Sobrien if ((flags & ERR_OLD)) { 60959243Sobrien /* Old error. */ 610167465Smp xprintf("%s.\n", seterr);/*FIXRESET*/ 611167465Smp } else { 612167465Smp xvprintf(elst[id], va);/*FIXRESET*/ 613167465Smp xprintf(".\n");/*FIXRESET*/ 614167465Smp } 61559243Sobrien } 61659243Sobrien } else { 61759243Sobrien vareturn = 1; /* Return immediately after va_end */ 61859243Sobrien } 61959243Sobrien va_end(va); 62059243Sobrien if (vareturn) 62159243Sobrien return; 62259243Sobrien 62359243Sobrien if (seterr) { 624167465Smp xfree(seterr); 62559243Sobrien seterr = NULL; 62659243Sobrien } 62759243Sobrien 62859243Sobrien didfds = 0; /* Forget about 0,1,2 */ 62959243Sobrien /* 63059243Sobrien * Go away if -e or we are a child shell 63159243Sobrien */ 63269408Sache if (!exitset || exiterr || child) 63359243Sobrien xexit(1); 63459243Sobrien 63559243Sobrien /* 63659243Sobrien * Reset the state of the input. This buffered seek to end of file will 63759243Sobrien * also clear the while/foreach stack. 63859243Sobrien */ 63959243Sobrien btoeof(); 64059243Sobrien 641167465Smp setcopy(STRstatus, STR1, VAR_READWRITE);/*FIXRESET*/ 64259243Sobrien#ifdef BSDJOBS 64359243Sobrien if (tpgrp > 0) 64459243Sobrien (void) tcsetpgrp(FSHTTY, tpgrp); 64559243Sobrien#endif 64659243Sobrien reset(); /* Unwind */ 64759243Sobrien} 648