Blame src/lib/libast/include/error.h

Packit Service a8c26c
/***********************************************************************
Packit Service a8c26c
*                                                                      *
Packit Service a8c26c
*               This software is part of the ast package               *
Packit Service a8c26c
*          Copyright (c) 1985-2012 AT&T Intellectual Property          *
Packit Service a8c26c
*                      and is licensed under the                       *
Packit Service a8c26c
*                 Eclipse Public License, Version 1.0                  *
Packit Service a8c26c
*                    by AT&T Intellectual Property                     *
Packit Service a8c26c
*                                                                      *
Packit Service a8c26c
*                A copy of the License is available at                 *
Packit Service a8c26c
*          http://www.eclipse.org/org/documents/epl-v10.html           *
Packit Service a8c26c
*         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
Packit Service a8c26c
*                                                                      *
Packit Service a8c26c
*              Information and Software Systems Research               *
Packit Service a8c26c
*                            AT&T Research                             *
Packit Service a8c26c
*                           Florham Park NJ                            *
Packit Service a8c26c
*                                                                      *
Packit Service a8c26c
*                 Glenn Fowler <gsf@research.att.com>                  *
Packit Service a8c26c
*                  David Korn <dgk@research.att.com>                   *
Packit Service a8c26c
*                   Phong Vo <kpv@research.att.com>                    *
Packit Service a8c26c
*                                                                      *
Packit Service a8c26c
***********************************************************************/
Packit Service a8c26c
#pragma prototyped
Packit Service a8c26c
/*
Packit Service a8c26c
 * Glenn Fowler
Packit Service a8c26c
 * AT&T Research
Packit Service a8c26c
 *
Packit Service a8c26c
 * option, error and message formatter external definitions
Packit Service a8c26c
 */
Packit Service a8c26c
Packit Service a8c26c
#ifndef _ERROR_H
Packit Service a8c26c
#define _ERROR_H
Packit Service a8c26c
Packit Service a8c26c
#include <ast.h>
Packit Service a8c26c
#include <option.h>
Packit Service a8c26c
#include <errno.h>
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_VERSION	20070319L
Packit Service a8c26c
Packit Service a8c26c
#if !defined(errno) && defined(__DYNAMIC__)
Packit Service a8c26c
#define errno		__DYNAMIC__(errno)
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_debug(n)	(-(n))
Packit Service a8c26c
#define ERROR_exit(n)	((n)+ERROR_ERROR)
Packit Service a8c26c
#define ERROR_system(n)	(((n)+ERROR_ERROR)|ERROR_SYSTEM)
Packit Service a8c26c
#define ERROR_usage(n)	((((n)?2:0)+ERROR_ERROR)|ERROR_USAGE)
Packit Service a8c26c
#define ERROR_warn(n)	(ERROR_WARNING)
Packit Service a8c26c
Packit Service a8c26c
#ifndef ERROR_catalog
Packit Service a8c26c
#define ERROR_catalog(t)		t
Packit Service a8c26c
#endif
Packit Service a8c26c
#ifndef ERROR_dictionary
Packit Service a8c26c
#define ERROR_dictionary(t)		t
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
#ifndef ERROR_translate
Packit Service a8c26c
#define ERROR_translating()		(error_info.translate&&(ast.locale.set&(1<
Packit Service a8c26c
#define ERROR_translate(l,i,d,m)	(ERROR_translating()?errorx((const char*)(l),(const char*)(i),(const char*)(d),(const char*)(m)):(char*)(m))
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_INFO	0		/* info message -- no err_id	*/
Packit Service a8c26c
#define ERROR_WARNING	1		/* warning message		*/
Packit Service a8c26c
#define ERROR_ERROR	2		/* error message -- no err_exit	*/
Packit Service a8c26c
#define ERROR_FATAL	3		/* error message with err_exit	*/
Packit Service a8c26c
#define ERROR_NOEXEC	EXIT_NOEXEC	/* shell convention		*/
Packit Service a8c26c
#define ERROR_NOENT	EXIT_NOTFOUND	/* shell convention		*/
Packit Service a8c26c
#define ERROR_PANIC	ERROR_LEVEL	/* panic message with err_exit	*/
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_LEVEL	0x00ff		/* level portion of status	*/
Packit Service a8c26c
#define ERROR_SYSTEM	0x0100		/* report system errno message	*/
Packit Service a8c26c
#define ERROR_OUTPUT	0x0200		/* next arg is error fd		*/
Packit Service a8c26c
#define ERROR_SOURCE	0x0400		/* next 2 args are FILE,LINE	*/
Packit Service a8c26c
#define ERROR_USAGE	0x0800		/* usage message		*/
Packit Service a8c26c
#define ERROR_PROMPT	0x1000		/* omit trailing newline	*/
Packit Service a8c26c
#define ERROR_NOID	0x2000		/* omit err_id			*/
Packit Service a8c26c
#define ERROR_LIBRARY	0x4000		/* library routine error	*/
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_INTERACTIVE	0x0001	/* context is interactive	*/
Packit Service a8c26c
#define ERROR_SILENT		0x0002	/* context is silent		*/
Packit Service a8c26c
#define ERROR_NOTIFY		0x0004	/* main(-sig,0,ctx) on signal	*/
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_FREE		0x0010	/* free context on pop		*/
Packit Service a8c26c
#define ERROR_POP		0x0020	/* pop context			*/
Packit Service a8c26c
#define ERROR_PUSH		0x0040	/* push context			*/
Packit Service a8c26c
#define ERROR_SET		0x0080	/* set context			*/
Packit Service a8c26c
Packit Service a8c26c
#ifdef ECONNRESET
Packit Service a8c26c
#define ERROR_PIPE(e)		((e)==EPIPE||(e)==ECONNRESET)
Packit Service a8c26c
#else
Packit Service a8c26c
#define ERROR_PIPE(e)		((e)==EPIPE)
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
/*
Packit Service a8c26c
 * errorpush()/errorpop() are obsolete -- use errorctx() instead
Packit Service a8c26c
 */
Packit Service a8c26c
Packit Service a8c26c
#ifndef ERROR_CONTEXT_T
Packit Service a8c26c
#define ERROR_CONTEXT_T		Error_info_t
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_CONTEXT_BASE	((Error_context_t*)&error_info.context)
Packit Service a8c26c
Packit Service a8c26c
#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))
Packit Service a8c26c
#define errorpop(p)	(*ERROR_CONTEXT_BASE=*(p))
Packit Service a8c26c
Packit Service a8c26c
typedef struct Error_info_s Error_info_t;
Packit Service a8c26c
typedef struct Error_context_s Error_context_t;
Packit Service a8c26c
Packit Service a8c26c
#define ERROR_CONTEXT \
Packit Service a8c26c
	ERROR_CONTEXT_T* context;	/* prev context stack element	*/ \
Packit Service a8c26c
	int	errors;			/* >= ERROR_ERROR count		*/ \
Packit Service a8c26c
	int	flags;			/* context flags		*/ \
Packit Service a8c26c
	int	line;			/* input|output line number	*/ \
Packit Service a8c26c
	int	warnings;		/* ERROR_WARNING count		*/ \
Packit Service a8c26c
	char*	file;			/* input|output file name	*/ \
Packit Service a8c26c
	char*	id;			/* command id			*/
Packit Service a8c26c
Packit Service a8c26c
struct Error_context_s			/* context stack element	*/
Packit Service a8c26c
{
Packit Service a8c26c
	ERROR_CONTEXT
Packit Service a8c26c
};
Packit Service a8c26c
Packit Service a8c26c
struct Error_info_s			/* error state			*/
Packit Service a8c26c
{
Packit Service a8c26c
	int	fd;			/* write(2) fd			*/
Packit Service a8c26c
Packit Service a8c26c
	void	(*exit)(int);		/* error exit			*/
Packit Service a8c26c
	ssize_t	(*write)(int, const void*, size_t); /* error output	*/
Packit Service a8c26c
Packit Service a8c26c
	/* the rest are implicitly initialized				*/
Packit Service a8c26c
Packit Service a8c26c
	int	clear;			/* default clear ERROR_* flags	*/
Packit Service a8c26c
	int	core;			/* level>=core -> core dump	*/
Packit Service a8c26c
	int	indent;			/* debug trace indent level	*/
Packit Service a8c26c
	int	init;			/* initialized			*/
Packit Service a8c26c
	int	last_errno;		/* last reported errno		*/
Packit Service a8c26c
	int	mask;			/* multi level debug trace mask	*/
Packit Service a8c26c
	int	set;			/* default set ERROR_* flags	*/
Packit Service a8c26c
	int	trace;			/* debug trace level		*/
Packit Service a8c26c
Packit Service a8c26c
	char*	version;		/* ERROR_SOURCE command version	*/
Packit Service a8c26c
Packit Service a8c26c
	int	(*auxilliary)(Sfio_t*, int, int); /* aux info to append	*/
Packit Service a8c26c
Packit Service a8c26c
	ERROR_CONTEXT			/* top of context stack		*/
Packit Service a8c26c
Packit Service a8c26c
	Error_context_t	empty;		/* empty context stack element	*/
Packit Service a8c26c
Packit Service a8c26c
	unsigned long	time;		/* debug time trace		*/
Packit Service a8c26c
Packit Service a8c26c
	char*	(*translate)(const char*, const char*, const char*, const char*);	/* format translator */
Packit Service a8c26c
Packit Service a8c26c
	const char*	catalog;	/* message catalog		*/
Packit Service a8c26c
};
Packit Service a8c26c
Packit Service a8c26c
#ifndef errno
Packit Service a8c26c
extern int	errno;			/* system call error status	*/
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
#if _BLD_ast && defined(__EXPORT__)
Packit Service a8c26c
#define extern		extern __EXPORT__
Packit Service a8c26c
#endif
Packit Service a8c26c
#if !_BLD_ast && defined(__IMPORT__)
Packit Service a8c26c
#define extern		extern __IMPORT__
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
extern Error_info_t*	_error_infop_;
Packit Service a8c26c
Packit Service a8c26c
#define error_info	(*_error_infop_)
Packit Service a8c26c
Packit Service a8c26c
#undef	extern
Packit Service a8c26c
Packit Service a8c26c
#if _BLD_ast && defined(__EXPORT__)
Packit Service a8c26c
#define extern		__EXPORT__
Packit Service a8c26c
#endif
Packit Service a8c26c
Packit Service a8c26c
extern void		error(int, ...);
Packit Service a8c26c
extern int		errormsg(const char*, int, ...);
Packit Service a8c26c
extern int		errorf(void*, void*, int, ...);
Packit Service a8c26c
extern void		errorv(const char*, int, va_list);
Packit Service a8c26c
#ifndef errorx
Packit Service a8c26c
extern char*		errorx(const char*, const char*, const char*, const char*);
Packit Service a8c26c
#endif
Packit Service a8c26c
extern Error_info_t*	errorctx(Error_info_t*, int, int);
Packit Service a8c26c
Packit Service a8c26c
#undef	extern
Packit Service a8c26c
Packit Service a8c26c
#endif