#if !defined(PS_ERROR_H)
#define PS_ERROR_H
#include <stdio.h>
#include <errno.h>
/*
 * Classes of errors that Pan-STARRS uses; more or less the equivalent of the values of errno
 *
 * This initialisation is machine-generated from psError.dat
 */
#include <stdarg.h>
#include "psErrorCodes.h"

typedef struct {
    psErrorCode code;			///< An error code
    const char *descrip;		///< the associated description
} psErrorDescription;

typedef struct {
    char *name;				///< category of code that caused the error
    psErrorCode code;			///< class of error (equivalent to errno)
    char *msg;				///< the message associated with the error
} psErr;

/// Prints an error message and doesn't abort; returns code
int psError(const char *name,		///< Category of code that caused the error
	    psErrorCode code,		///< class of error (equivalent to errno)
	    bool new,	                ///< is this a new error?
	    const char *fmt,		///< Format
	    ...)			///< Extra arguments to use format
;

void p_psErrorRegister(const psErrorDescription *errors, ///< register a set of errors
		       int nerror)	///< number of errors
;

///< return specified error (or an "error" with code PS_ERR_NONE)
const psErr *psErrorGet(int which);	

///< return last error (or an "error" with code PS_ERR_NONE)
const psErr *psErrorLast(void);		

///< Clear the error stack
void psErrorClear(void);		

///< return the string associated with the error code
const char *psErrorCodeString(psErrorCode code);	

///< print the errorstack to this file descriptor
void psErrorStackPrint(FILE *fd,	///< write to this file descriptor
		       const char *fmt, ///< format for any header information; may be NULL
		       ...)		///< arguments for format
;	

///< print the errorstack to this file descriptor (stdargs version)
void psErrorStackPrintV(FILE *fd,	///< write to this file descriptor
			const char *fmt,///< format for any header information; may be NULL
			va_list ap)	///< arguments for format
;


#endif
