1 /* 2 * BEGIN illumos section 3 * This is an unstable interface; changes may be made 4 * without notice. 5 * END illumos section 6 */ 7 /*********************************************************************** 8 * * 9 * This software is part of the ast package * 10 * Copyright (c) 1985-2012 AT&T Intellectual Property * 11 * and is licensed under the * 12 * Eclipse Public License, Version 1.0 * 13 * by AT&T Intellectual Property * 14 * * 15 * A copy of the License is available at * 16 * http://www.eclipse.org/org/documents/epl-v10.html * 17 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 18 * * 19 * Information and Software Systems Research * 20 * AT&T Research * 21 * Florham Park NJ * 22 * * 23 * Glenn Fowler <gsf@research.att.com> * 24 * David Korn <dgk@research.att.com> * 25 * Phong Vo <kpv@research.att.com> * 26 * * 27 ***********************************************************************/ 28 #pragma prototyped 29 /* 30 * Glenn Fowler 31 * AT&T Research 32 * 33 * option, error and message formatter external definitions 34 */ 35 36 #ifndef _ERROR_H 37 #define _ERROR_H 38 39 #include <ast.h> 40 #include <option.h> 41 #include <errno.h> 42 43 #define ERROR_VERSION 20070319L 44 45 #if !defined(errno) && defined(__DYNAMIC__) 46 #define errno __DYNAMIC__(errno) 47 #endif 48 49 #define ERROR_debug(n) (-(n)) 50 #define ERROR_exit(n) ((n)+ERROR_ERROR) 51 #define ERROR_system(n) (((n)+ERROR_ERROR)|ERROR_SYSTEM) 52 #define ERROR_usage(n) ((((n)?2:0)+ERROR_ERROR)|ERROR_USAGE) 53 #define ERROR_warn(n) (ERROR_WARNING) 54 55 #ifndef ERROR_catalog 56 #define ERROR_catalog(t) t 57 #endif 58 #ifndef ERROR_dictionary 59 #define ERROR_dictionary(t) t 60 #endif 61 62 #ifndef ERROR_translate 63 #define ERROR_translating() (error_info.translate&&(ast.locale.set&(1<<AST_LC_MESSAGES))) 64 #define ERROR_translate(l,i,d,m) (ERROR_translating()?errorx((const char*)(l),(const char*)(i),(const char*)(d),(const char*)(m)):(char*)(m)) 65 #endif 66 67 #define ERROR_INFO 0 /* info message -- no err_id */ 68 #define ERROR_WARNING 1 /* warning message */ 69 #define ERROR_ERROR 2 /* error message -- no err_exit */ 70 #define ERROR_FATAL 3 /* error message with err_exit */ 71 #define ERROR_NOEXEC EXIT_NOEXEC /* shell convention */ 72 #define ERROR_NOENT EXIT_NOTFOUND /* shell convention */ 73 #define ERROR_PANIC ERROR_LEVEL /* panic message with err_exit */ 74 75 #define ERROR_LEVEL 0x00ff /* level portion of status */ 76 #define ERROR_SYSTEM 0x0100 /* report system errno message */ 77 #define ERROR_OUTPUT 0x0200 /* next arg is error fd */ 78 #define ERROR_SOURCE 0x0400 /* next 2 args are FILE,LINE */ 79 #define ERROR_USAGE 0x0800 /* usage message */ 80 #define ERROR_PROMPT 0x1000 /* omit trailing newline */ 81 #define ERROR_NOID 0x2000 /* omit err_id */ 82 #define ERROR_LIBRARY 0x4000 /* library routine error */ 83 84 #define ERROR_INTERACTIVE 0x0001 /* context is interactive */ 85 #define ERROR_SILENT 0x0002 /* context is silent */ 86 #define ERROR_NOTIFY 0x0004 /* main(-sig,0,ctx) on signal */ 87 88 #define ERROR_FREE 0x0010 /* free context on pop */ 89 #define ERROR_POP 0x0020 /* pop context */ 90 #define ERROR_PUSH 0x0040 /* push context */ 91 #define ERROR_SET 0x0080 /* set context */ 92 93 #ifdef ECONNRESET 94 #define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET||(e)==EIO) 95 #else 96 #define ERROR_PIPE(e) ((e)==EPIPE||(e)==EIO) 97 #endif 98 99 /* 100 * errorpush()/errorpop() are obsolete -- use errorctx() instead 101 */ 102 103 #ifndef ERROR_CONTEXT_T 104 #define ERROR_CONTEXT_T Error_info_t 105 #endif 106 107 #define ERROR_CONTEXT_BASE ((Error_context_t*)&error_info.context) 108 109 #define errorpush(p,f) (*(p)=*ERROR_CONTEXT_BASE,*ERROR_CONTEXT_BASE=error_info.empty,error_info.context=(Error_context_t*)(p),error_info.flags=(f)) 110 #define errorpop(p) (*ERROR_CONTEXT_BASE=*(p)) 111 112 typedef struct Error_info_s Error_info_t; 113 typedef struct Error_context_s Error_context_t; 114 115 #define ERROR_CONTEXT \ 116 ERROR_CONTEXT_T* context; /* prev context stack element */ \ 117 int errors; /* >= ERROR_ERROR count */ \ 118 int flags; /* context flags */ \ 119 int line; /* input|output line number */ \ 120 int warnings; /* ERROR_WARNING count */ \ 121 char* file; /* input|output file name */ \ 122 char* id; /* command id */ 123 124 struct Error_context_s /* context stack element */ 125 { 126 ERROR_CONTEXT 127 }; 128 129 struct Error_info_s /* error state */ 130 { 131 int fd; /* write(2) fd */ 132 133 void (*exit)(int); /* error exit */ 134 ssize_t (*write)(int, const void*, size_t); /* error output */ 135 136 /* the rest are implicitly initialized */ 137 138 int clear; /* default clear ERROR_* flags */ 139 int core; /* level>=core -> core dump */ 140 int indent; /* debug trace indent level */ 141 int init; /* initialized */ 142 int last_errno; /* last reported errno */ 143 int mask; /* multi level debug trace mask */ 144 int set; /* default set ERROR_* flags */ 145 int trace; /* debug trace level */ 146 147 char* version; /* ERROR_SOURCE command version */ 148 149 int (*auxilliary)(Sfio_t*, int, int); /* aux info to append */ 150 151 ERROR_CONTEXT /* top of context stack */ 152 153 Error_context_t empty; /* empty context stack element */ 154 155 unsigned long time; /* debug time trace */ 156 157 char* (*translate)(const char*, const char*, const char*, const char*); /* format translator */ 158 159 const char* catalog; /* message catalog */ 160 }; 161 162 #ifndef errno 163 extern int errno; /* system call error status */ 164 #endif 165 166 #if _BLD_ast && defined(__EXPORT__) 167 #define extern extern __EXPORT__ 168 #endif 169 #if !_BLD_ast && defined(__IMPORT__) 170 #define extern extern __IMPORT__ 171 #endif 172 173 extern Error_info_t* _error_infop_; 174 175 #define error_info (*_error_infop_) 176 177 #undef extern 178 179 #if _BLD_ast && defined(__EXPORT__) 180 #define extern __EXPORT__ 181 #endif 182 183 extern void error(int, ...); 184 extern int errormsg(const char*, int, ...); 185 extern int errorf(void*, void*, int, ...); 186 extern void errorv(const char*, int, va_list); 187 #ifndef errorx 188 extern char* errorx(const char*, const char*, const char*, const char*); 189 #endif 190 extern Error_info_t* errorctx(Error_info_t*, int, int); 191 192 #undef extern 193 194 #endif 195