#include <errno.h>
#include <stdio.h>

/* Both of these routines are here to handle errors -- error is for
* those errors that the programmer wants to cause, without system
* help.  CheckError is for ones that are brought on by some true
* system error (like out of memory, or other equivalent foolishness).
* Both use Shutdown() to turn off anything the program is doing.
* Shutdown() is assumed to 1) exist and 2) be the program-specific
* method of turning off the program to exit.
*/

void error(s)
char *s;
    {
    void Shutdown();

    Shutdown();
    printf("-%s\r\n",s);
    fflush(stdout);  
    perror(s);
    fflush(stderr);
    exit(1);
    }

void CheckError(s,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)
char *s;
long a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
    {
    void Shutdown();
    extern char *sys_errlist[];
    extern int errno;
    char ibuf[2048];
    char *s1, *s2;

    s1 = ibuf;
    *s1++ = '-';
    while( *s )
	if( s[0] != '%' || s[1]!='E' )
	    *s1++ = *s++;
	else
	    {
	    for( s2=sys_errlist[errno]; *s2; s2++ )
		*s1++ = *s2;
	    s+=2;
	    }
    strcpy( s1, "\n" );
    Shutdown();
    fflush(stderr);
    printf( ibuf, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 );
    fflush(stdout);  
    exit(1);
    }
