xref: /onnv-gate/usr/src/lib/libast/common/include/error.h (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin  * Glenn Fowler
254887Schin  * AT&T Research
264887Schin  *
274887Schin  * option, error and message formatter external definitions
284887Schin  */
294887Schin 
304887Schin #ifndef _ERROR_H
314887Schin #define _ERROR_H
324887Schin 
334887Schin #include <ast.h>
344887Schin #include <option.h>
354887Schin #include <errno.h>
364887Schin 
374887Schin #define ERROR_VERSION	20070319L
384887Schin 
394887Schin #if !defined(errno) && defined(__DYNAMIC__)
404887Schin #define errno		__DYNAMIC__(errno)
414887Schin #endif
424887Schin 
434887Schin #define ERROR_debug(n)	(-(n))
444887Schin #define ERROR_exit(n)	((n)+ERROR_ERROR)
454887Schin #define ERROR_system(n)	(((n)+ERROR_ERROR)|ERROR_SYSTEM)
464887Schin #define ERROR_usage(n)	((((n)?2:0)+ERROR_ERROR)|ERROR_USAGE)
474887Schin #define ERROR_warn(n)	(ERROR_WARNING)
484887Schin 
494887Schin #ifndef ERROR_catalog
504887Schin #define ERROR_catalog(t)		t
514887Schin #endif
524887Schin #ifndef ERROR_dictionary
534887Schin #define ERROR_dictionary(t)		t
544887Schin #endif
554887Schin 
564887Schin #ifndef ERROR_translate
574887Schin #define ERROR_translating()		(error_info.translate&&(ast.locale.set&(1<<AST_LC_MESSAGES)))
58*12068SRoger.Faulkner@Oracle.COM #define ERROR_translate(l,i,d,m)	(ERROR_translating()?errorx((const char*)(l),(const char*)(i),(const char*)(d),(const char*)(m)):(char*)(m))
594887Schin #endif
604887Schin 
614887Schin #define ERROR_INFO	0		/* info message -- no err_id	*/
624887Schin #define ERROR_WARNING	1		/* warning message		*/
634887Schin #define ERROR_ERROR	2		/* error message -- no err_exit	*/
644887Schin #define ERROR_FATAL	3		/* error message with err_exit	*/
654887Schin #define ERROR_NOEXEC	EXIT_NOEXEC	/* shell convention		*/
664887Schin #define ERROR_NOENT	EXIT_NOTFOUND	/* shell convention		*/
674887Schin #define ERROR_PANIC	ERROR_LEVEL	/* panic message with err_exit	*/
684887Schin 
694887Schin #define ERROR_LEVEL	0x00ff		/* level portion of status	*/
704887Schin #define ERROR_SYSTEM	0x0100		/* report system errno message	*/
714887Schin #define ERROR_OUTPUT	0x0200		/* next arg is error fd		*/
724887Schin #define ERROR_SOURCE	0x0400		/* next 2 args are FILE,LINE	*/
734887Schin #define ERROR_USAGE	0x0800		/* usage message		*/
744887Schin #define ERROR_PROMPT	0x1000		/* omit trailing newline	*/
754887Schin #define ERROR_NOID	0x2000		/* omit err_id			*/
764887Schin #define ERROR_LIBRARY	0x4000		/* library routine error	*/
774887Schin 
784887Schin #define ERROR_INTERACTIVE	0x0001	/* context is interactive	*/
794887Schin #define ERROR_SILENT		0x0002	/* context is silent		*/
804887Schin #define ERROR_NOTIFY		0x0004	/* main(-sig,0,ctx) on signal	*/
814887Schin 
824887Schin #define ERROR_FREE		0x0010	/* free context on pop		*/
834887Schin #define ERROR_POP		0x0020	/* pop context			*/
844887Schin #define ERROR_PUSH		0x0040	/* push context			*/
854887Schin #define ERROR_SET		0x0080	/* set context			*/
864887Schin 
874887Schin /*
884887Schin  * errorpush()/errorpop() are obsolete -- use errorctx() instead
894887Schin  */
904887Schin 
914887Schin #ifndef ERROR_CONTEXT_T
924887Schin #define ERROR_CONTEXT_T		Error_info_t
934887Schin #endif
944887Schin 
954887Schin #define ERROR_CONTEXT_BASE	((Error_context_t*)&error_info.context)
964887Schin 
974887Schin #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))
984887Schin #define errorpop(p)	(*ERROR_CONTEXT_BASE=*(p))
994887Schin 
1004887Schin typedef struct Error_info_s Error_info_t;
1014887Schin typedef struct Error_context_s Error_context_t;
1024887Schin 
1034887Schin #define ERROR_CONTEXT \
1044887Schin 	ERROR_CONTEXT_T* context;	/* prev context stack element	*/ \
1054887Schin 	int	errors;			/* >= ERROR_ERROR count		*/ \
1064887Schin 	int	flags;			/* context flags		*/ \
1074887Schin 	int	line;			/* input|output line number	*/ \
1084887Schin 	int	warnings;		/* ERROR_WARNING count		*/ \
1094887Schin 	char*	file;			/* input|output file name	*/ \
1104887Schin 	char*	id;			/* command id			*/
1114887Schin 
1124887Schin struct Error_context_s			/* context stack element	*/
1134887Schin {
1144887Schin 	ERROR_CONTEXT
1154887Schin };
1164887Schin 
1174887Schin struct Error_info_s			/* error state			*/
1184887Schin {
1194887Schin 	int	fd;			/* write(2) fd			*/
1204887Schin 
1214887Schin 	void	(*exit)(int);		/* error exit			*/
1224887Schin 	ssize_t	(*write)(int, const void*, size_t); /* error output	*/
1234887Schin 
1244887Schin 	/* the rest are implicitly initialized				*/
1254887Schin 
1264887Schin 	int	clear;			/* default clear ERROR_* flags	*/
1274887Schin 	int	core;			/* level>=core -> core dump	*/
1284887Schin 	int	indent;			/* debug trace indent level	*/
1294887Schin 	int	init;			/* initialized			*/
1304887Schin 	int	last_errno;		/* last reported errno		*/
1314887Schin 	int	mask;			/* multi level debug trace mask	*/
1324887Schin 	int	set;			/* default set ERROR_* flags	*/
1334887Schin 	int	trace;			/* debug trace level		*/
1344887Schin 
1354887Schin 	char*	version;		/* ERROR_SOURCE command version	*/
1364887Schin 
1374887Schin 	int	(*auxilliary)(Sfio_t*, int, int); /* aux info to append	*/
1384887Schin 
1394887Schin 	ERROR_CONTEXT			/* top of context stack		*/
1404887Schin 
1414887Schin 	Error_context_t	empty;		/* empty context stack element	*/
1424887Schin 
1434887Schin 	unsigned long	time;		/* debug time trace		*/
1444887Schin 
1454887Schin 	char*	(*translate)(const char*, const char*, const char*, const char*);	/* format translator */
1464887Schin 
1474887Schin 	const char*	catalog;	/* message catalog		*/
1484887Schin };
1494887Schin 
1504887Schin #ifndef errno
1514887Schin extern int	errno;			/* system call error status	*/
1524887Schin #endif
1534887Schin 
1544887Schin #if _BLD_ast && defined(__EXPORT__)
1554887Schin #define extern		extern __EXPORT__
1564887Schin #endif
1574887Schin #if !_BLD_ast && defined(__IMPORT__)
1584887Schin #define extern		extern __IMPORT__
1594887Schin #endif
1604887Schin 
1614887Schin extern Error_info_t*	_error_infop_;
1624887Schin 
1634887Schin #define error_info	(*_error_infop_)
1644887Schin 
1654887Schin #undef	extern
1664887Schin 
1674887Schin #if _BLD_ast && defined(__EXPORT__)
1684887Schin #define extern		__EXPORT__
1694887Schin #endif
1704887Schin 
1714887Schin extern void		error(int, ...);
1724887Schin extern int		errormsg(const char*, int, ...);
1734887Schin extern int		errorf(void*, void*, int, ...);
1744887Schin extern void		errorv(const char*, int, va_list);
1754887Schin #ifndef errorx
1764887Schin extern char*		errorx(const char*, const char*, const char*, const char*);
1774887Schin #endif
1784887Schin extern Error_info_t*	errorctx(Error_info_t*, int, int);
1794887Schin 
1804887Schin #undef	extern
1814887Schin 
1824887Schin #endif
183