1991-10-06 20:00:00 -04:00
|
|
|
/*
|
|
|
|
* jerror.c
|
|
|
|
*
|
1992-03-16 19:00:00 -05:00
|
|
|
* Copyright (C) 1991, 1992, Thomas G. Lane.
|
1991-10-06 20:00:00 -04:00
|
|
|
* This file is part of the Independent JPEG Group's software.
|
|
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
|
|
*
|
|
|
|
* This file contains simple error-reporting and trace-message routines.
|
|
|
|
* These are suitable for Unix-like systems and others where writing to
|
|
|
|
* stderr is the right thing to do. If the JPEG software is integrated
|
|
|
|
* into a larger application, you may well need to replace these.
|
|
|
|
*
|
|
|
|
* The error_exit() routine should not return to its caller. Within a
|
|
|
|
* larger application, you might want to have it do a longjmp() to return
|
|
|
|
* control to the outer user interface routine. This should work since
|
1992-03-16 19:00:00 -05:00
|
|
|
* the portable JPEG code doesn't use setjmp/longjmp. You should make sure
|
|
|
|
* that free_all is called either within error_exit or after the return to
|
|
|
|
* the outer-level routine.
|
1991-10-06 20:00:00 -04:00
|
|
|
*
|
|
|
|
* These routines are used by both the compression and decompression code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jinclude.h"
|
1991-12-12 19:00:00 -05:00
|
|
|
#ifdef INCLUDES_ARE_ANSI
|
1991-10-06 20:00:00 -04:00
|
|
|
#include <stdlib.h> /* to declare exit() */
|
|
|
|
#endif
|
|
|
|
|
1992-03-16 19:00:00 -05:00
|
|
|
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
#endif
|
|
|
|
|
1991-10-06 20:00:00 -04:00
|
|
|
|
1992-03-16 19:00:00 -05:00
|
|
|
static external_methods_ptr methods; /* saved for access to message_parm, free_all */
|
1991-10-06 20:00:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
METHODDEF void
|
1991-12-12 19:00:00 -05:00
|
|
|
trace_message (const char *msgtext)
|
1991-10-06 20:00:00 -04:00
|
|
|
{
|
|
|
|
fprintf(stderr, msgtext,
|
|
|
|
methods->message_parm[0], methods->message_parm[1],
|
|
|
|
methods->message_parm[2], methods->message_parm[3],
|
|
|
|
methods->message_parm[4], methods->message_parm[5],
|
|
|
|
methods->message_parm[6], methods->message_parm[7]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
METHODDEF void
|
1991-12-12 19:00:00 -05:00
|
|
|
error_exit (const char *msgtext)
|
1991-10-06 20:00:00 -04:00
|
|
|
{
|
|
|
|
trace_message(msgtext);
|
1992-03-16 19:00:00 -05:00
|
|
|
(*methods->free_all) (); /* clean up memory allocation */
|
|
|
|
exit(EXIT_FAILURE);
|
1991-10-06 20:00:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The method selection routine for simple error handling.
|
|
|
|
* The system-dependent setup routine should call this routine
|
|
|
|
* to install the necessary method pointers in the supplied struct.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GLOBAL void
|
|
|
|
jselerror (external_methods_ptr emethods)
|
|
|
|
{
|
1992-03-16 19:00:00 -05:00
|
|
|
methods = emethods; /* save struct addr for later access */
|
1991-10-06 20:00:00 -04:00
|
|
|
|
|
|
|
emethods->error_exit = error_exit;
|
|
|
|
emethods->trace_message = trace_message;
|
|
|
|
|
|
|
|
emethods->trace_level = 0; /* default = no tracing */
|
|
|
|
}
|