1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * option, error and message formatter external definitions
37 #define ERROR_VERSION 20070319L
39 #if !defined(errno) && defined(__DYNAMIC__)
40 #define errno __DYNAMIC__(errno)
43 #define ERROR_debug(n) (-(n))
44 #define ERROR_exit(n) ((n)+ERROR_ERROR)
45 #define ERROR_system(n) (((n)+ERROR_ERROR)|ERROR_SYSTEM)
46 #define ERROR_usage(n) ((((n)?2:0)+ERROR_ERROR)|ERROR_USAGE)
47 #define ERROR_warn(n) (ERROR_WARNING)
50 #define ERROR_catalog(t) t
52 #ifndef ERROR_dictionary
53 #define ERROR_dictionary(t) t
56 #ifndef ERROR_translate
57 #define ERROR_translating() (error_info.translate&&(ast.locale.set&(1<<AST_LC_MESSAGES)))
58 #define ERROR_translate(l,i,d,m) (ERROR_translating()?errorx((const char*)(l),(const char*)(i),(const char*)(d),(const char*)(m)):(char*)(m))
61 #define ERROR_INFO 0 /* info message -- no err_id */
62 #define ERROR_WARNING 1 /* warning message */
63 #define ERROR_ERROR 2 /* error message -- no err_exit */
64 #define ERROR_FATAL 3 /* error message with err_exit */
65 #define ERROR_NOEXEC EXIT_NOEXEC /* shell convention */
66 #define ERROR_NOENT EXIT_NOTFOUND /* shell convention */
67 #define ERROR_PANIC ERROR_LEVEL /* panic message with err_exit */
69 #define ERROR_LEVEL 0x00ff /* level portion of status */
70 #define ERROR_SYSTEM 0x0100 /* report system errno message */
71 #define ERROR_OUTPUT 0x0200 /* next arg is error fd */
72 #define ERROR_SOURCE 0x0400 /* next 2 args are FILE,LINE */
73 #define ERROR_USAGE 0x0800 /* usage message */
74 #define ERROR_PROMPT 0x1000 /* omit trailing newline */
75 #define ERROR_NOID 0x2000 /* omit err_id */
76 #define ERROR_LIBRARY 0x4000 /* library routine error */
78 #define ERROR_INTERACTIVE 0x0001 /* context is interactive */
79 #define ERROR_SILENT 0x0002 /* context is silent */
80 #define ERROR_NOTIFY 0x0004 /* main(-sig,0,ctx) on signal */
82 #define ERROR_FREE 0x0010 /* free context on pop */
83 #define ERROR_POP 0x0020 /* pop context */
84 #define ERROR_PUSH 0x0040 /* push context */
85 #define ERROR_SET 0x0080 /* set context */
88 * errorpush()/errorpop() are obsolete -- use errorctx() instead
91 #ifndef ERROR_CONTEXT_T
92 #define ERROR_CONTEXT_T Error_info_t
95 #define ERROR_CONTEXT_BASE ((Error_context_t*)&error_info.context)
97 #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))
98 #define errorpop(p) (*ERROR_CONTEXT_BASE=*(p))
100 typedef struct Error_info_s Error_info_t
;
101 typedef struct Error_context_s Error_context_t
;
103 #define ERROR_CONTEXT \
104 ERROR_CONTEXT_T* context; /* prev context stack element */ \
105 int errors; /* >= ERROR_ERROR count */ \
106 int flags; /* context flags */ \
107 int line; /* input|output line number */ \
108 int warnings; /* ERROR_WARNING count */ \
109 char* file; /* input|output file name */ \
110 char* id; /* command id */
112 struct Error_context_s
/* context stack element */
117 struct Error_info_s
/* error state */
119 int fd
; /* write(2) fd */
121 void (*exit
)(int); /* error exit */
122 ssize_t (*write
)(int, const void*, size_t); /* error output */
124 /* the rest are implicitly initialized */
126 int clear
; /* default clear ERROR_* flags */
127 int core
; /* level>=core -> core dump */
128 int indent
; /* debug trace indent level */
129 int init
; /* initialized */
130 int last_errno
; /* last reported errno */
131 int mask
; /* multi level debug trace mask */
132 int set
; /* default set ERROR_* flags */
133 int trace
; /* debug trace level */
135 char* version
; /* ERROR_SOURCE command version */
137 int (*auxilliary
)(Sfio_t
*, int, int); /* aux info to append */
139 ERROR_CONTEXT
/* top of context stack */
141 Error_context_t empty
; /* empty context stack element */
143 unsigned long time
; /* debug time trace */
145 char* (*translate
)(const char*, const char*, const char*, const char*); /* format translator */
147 const char* catalog
; /* message catalog */
151 extern int errno
; /* system call error status */
154 #if _BLD_ast && defined(__EXPORT__)
155 #define extern extern __EXPORT__
157 #if !_BLD_ast && defined(__IMPORT__)
158 #define extern extern __IMPORT__
161 extern Error_info_t
* _error_infop_
;
163 #define error_info (*_error_infop_)
167 #if _BLD_ast && defined(__EXPORT__)
168 #define extern __EXPORT__
171 extern void error(int, ...);
172 extern int errormsg(const char*, int, ...);
173 extern int errorf(void*, void*, int, ...);
174 extern void errorv(const char*, int, va_list);
176 extern char* errorx(const char*, const char*, const char*, const char*);
178 extern Error_info_t
* errorctx(Error_info_t
*, int, int);