blob: 0256f5635e2278ca235829b55d225f94d6caaa86 [file] [log] [blame]
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +00001/*
2 * jerror.c
3 *
Thomas G. Lane4a6b7301992-03-17 00:00:00 +00004 * Copyright (C) 1991, 1992, Thomas G. Lane.
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +00005 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
7 *
8 * This file contains simple error-reporting and trace-message routines.
9 * These are suitable for Unix-like systems and others where writing to
10 * stderr is the right thing to do. If the JPEG software is integrated
11 * into a larger application, you may well need to replace these.
12 *
13 * The error_exit() routine should not return to its caller. Within a
14 * larger application, you might want to have it do a longjmp() to return
15 * control to the outer user interface routine. This should work since
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000016 * the portable JPEG code doesn't use setjmp/longjmp. You should make sure
17 * that free_all is called either within error_exit or after the return to
18 * the outer-level routine.
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000019 *
20 * These routines are used by both the compression and decompression code.
21 */
22
23#include "jinclude.h"
Thomas G. Lanebd543f01991-12-13 00:00:00 +000024#ifdef INCLUDES_ARE_ANSI
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000025#include <stdlib.h> /* to declare exit() */
26#endif
27
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000028#ifndef EXIT_FAILURE /* define exit() codes if not provided */
29#define EXIT_FAILURE 1
30#endif
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000031
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000032
33static external_methods_ptr methods; /* saved for access to message_parm, free_all */
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000034
35
36METHODDEF void
Thomas G. Lanebd543f01991-12-13 00:00:00 +000037trace_message (const char *msgtext)
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000038{
39 fprintf(stderr, msgtext,
40 methods->message_parm[0], methods->message_parm[1],
41 methods->message_parm[2], methods->message_parm[3],
42 methods->message_parm[4], methods->message_parm[5],
43 methods->message_parm[6], methods->message_parm[7]);
44 fprintf(stderr, "\n");
45}
46
47
48METHODDEF void
Thomas G. Lanebd543f01991-12-13 00:00:00 +000049error_exit (const char *msgtext)
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000050{
Thomas G. Lane88aeed41992-12-10 00:00:00 +000051 (*methods->trace_message) (msgtext);
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000052 (*methods->free_all) (); /* clean up memory allocation */
53 exit(EXIT_FAILURE);
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000054}
55
56
57/*
58 * The method selection routine for simple error handling.
59 * The system-dependent setup routine should call this routine
60 * to install the necessary method pointers in the supplied struct.
61 */
62
63GLOBAL void
64jselerror (external_methods_ptr emethods)
65{
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000066 methods = emethods; /* save struct addr for later access */
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000067
68 emethods->error_exit = error_exit;
69 emethods->trace_message = trace_message;
70
71 emethods->trace_level = 0; /* default = no tracing */
Thomas G. Lane88aeed41992-12-10 00:00:00 +000072
73 emethods->num_warnings = 0; /* no warnings emitted yet */
74 /* By default, the first corrupt-data warning will be displayed,
75 * but additional ones will appear only if trace level is at least 3.
76 * A corrupt data file could generate many warnings, so it's a good idea
77 * to suppress additional messages except at high tracing levels.
78 */
79 emethods->first_warning_level = 0;
80 emethods->more_warning_level = 3;
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +000081}