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