Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * jerror.c |
| 3 | * |
| 4 | * Copyright (C) 1991, Thomas G. Lane. |
| 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 |
| 16 | * the portable JPEG code doesn't use setjmp/longjmp. However, this won't |
| 17 | * release allocated memory or close temp files --- some bookkeeping would |
| 18 | * need to be added to the memory manager module to make that work. |
| 19 | * |
| 20 | * These routines are used by both the compression and decompression code. |
| 21 | */ |
| 22 | |
| 23 | #include "jinclude.h" |
| 24 | #ifdef __STDC__ |
| 25 | #include <stdlib.h> /* to declare exit() */ |
| 26 | #endif |
| 27 | |
| 28 | |
| 29 | static external_methods_ptr methods; /* saved for access to message_parm */ |
| 30 | |
| 31 | |
| 32 | METHODDEF void |
| 33 | trace_message (char *msgtext) |
| 34 | { |
| 35 | fprintf(stderr, msgtext, |
| 36 | methods->message_parm[0], methods->message_parm[1], |
| 37 | methods->message_parm[2], methods->message_parm[3], |
| 38 | methods->message_parm[4], methods->message_parm[5], |
| 39 | methods->message_parm[6], methods->message_parm[7]); |
| 40 | fprintf(stderr, "\n"); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | METHODDEF void |
| 45 | error_exit (char *msgtext) |
| 46 | { |
| 47 | trace_message(msgtext); |
| 48 | exit(1); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /* |
| 53 | * The method selection routine for simple error handling. |
| 54 | * The system-dependent setup routine should call this routine |
| 55 | * to install the necessary method pointers in the supplied struct. |
| 56 | */ |
| 57 | |
| 58 | GLOBAL void |
| 59 | jselerror (external_methods_ptr emethods) |
| 60 | { |
| 61 | methods = emethods; /* save struct addr for msg parm access */ |
| 62 | |
| 63 | emethods->error_exit = error_exit; |
| 64 | emethods->trace_message = trace_message; |
| 65 | |
| 66 | emethods->trace_level = 0; /* default = no tracing */ |
| 67 | } |