byte inerror=0,lasterror=0;
//errors
?define	ERR_UNKNOWN	1	/* Unknown error 			*/
?define ERR_NOTIMP	2	/* Command not implemented 		*/
?define ERR_ARCOPEN	3	/* Could not open archive		*/
?define ERR_MEM		4	/* Out of memory			*/
?define ERR_NOHA	5	/* Not a ha archive			*/
?define ERR_WRITE	6	/* Write error				*/
?define ERR_READ	7	/* Read error 				*/
?define ERR_INT		8	/* Got signal...			*/
?define ERR_NOFILES	9	/* No files found			*/
?define ERR_REMOVE	10	/* Could not remove 			*/
?define ERR_INVSW	11	/* Invalid switch			*/
?define ERR_TOONEW	12	/* Version identifier too high		*/
?define ERR_TOOOLD	13	/* Version identifier too old		*/
?define ERR_UNKMET	14	/* Unknown compression method		*/
?define ERR_SEEK	15	/* Lseek error				*/
?define ERR_OPEN	16	/* Could not open file			*/
?define ERR_MKDIR	17	/* Could not make directory		*/
?define ERR_CRC		18	/* CRC error 				*/
?define ERR_WRITENN	19	/* Write error (no name)		*/
?define ERR_STAT	20	/* Stat failed				*/
?define ERR_DIROPEN     21      /* Open dir                             */
?define ERR_CORRUPTED   22      /* Corrupted archive                    */

byte error_string=
		"Error in error handling !!!\000"
    "Unknown error\000"
    "Command %c not implemented\000"
    "Could not open archive %s\000"
    "Out of memory in %s\000"
    "%s is not a HA archive\000"
    "Write error on %s\000"
    "Read error on %s\000"
    "Got signal %d\000"
    "No files found\000"
    "Could not remove %s\000"
    "Invalid switch %c\000"
    "Archive needs newer version of HA\000"
    "Archive made with unsupported version\000"
    "Unknown compression method %d\000"
    "Lseek error in %s\000"
    "Could not open file %s\000"
    "Could not make directory %s\000"
    "CRC error\000"
    "Write error\000"
    "Could not get file status for %s\000"
    "Could not open directory %s\000"
    "Archive corrupted !\000";

void error(byte fatal,number;word param1,param2)
{
	DWRITESTR("\nHA: ");
	IF(inerror!=0){
		DWRITESTR(#error_string);
		DWRITELN();
		EXIT(inerror);
	}
	inerror=number;
	SI=#error_string;
	$CLD
	CX=0;
	IF(number){
		do
		{
			do{
				$LODSB
			}while(AL);
			CX++;
		} while ( number!=CX );
	}
	AX=SI;
	PRINTF(,param1,param2);
	DWRITELN();
	IF (fatal!=0)EXIT(number);
	lasterror=inerror;
	inerror=0;
}
