Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jerror.c |
| 3 | * |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 4 | * Copyright (C) 1991, 1992, Thomas G. Lane. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 5 | * 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. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 16 | * 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. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 19 | * |
| 20 | * These routines are used by both the compression and decompression code. |
| 21 | */ |
| 22 | |
| 23 | #include "jinclude.h" |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 24 | #ifdef INCLUDES_ARE_ANSI |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 25 | #include <stdlib.h> /* to declare exit() */ |
| 26 | #endif |
| 27 | |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 28 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ |
| 29 | #define EXIT_FAILURE 1 |
| 30 | #endif |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 31 | |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 32 | |
| 33 | static external_methods_ptr methods; /* saved for access to message_parm, free_all */ |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | METHODDEF void |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 37 | trace_message (const char *msgtext) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 38 | { |
| 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 | |
| 48 | METHODDEF void |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 49 | error_exit (const char *msgtext) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 50 | { |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame^] | 51 | (*methods->trace_message) (msgtext); |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 52 | (*methods->free_all) (); /* clean up memory allocation */ |
| 53 | exit(EXIT_FAILURE); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 54 | } |
| 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 | |
| 63 | GLOBAL void |
| 64 | jselerror (external_methods_ptr emethods) |
| 65 | { |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 66 | methods = emethods; /* save struct addr for later access */ |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 67 | |
| 68 | emethods->error_exit = error_exit; |
| 69 | emethods->trace_message = trace_message; |
| 70 | |
| 71 | emethods->trace_level = 0; /* default = no tracing */ |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame^] | 72 | |
| 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. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 81 | } |