doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jerror.c
Go to the documentation of this file.
1 /*
2  * jerror.c
3  *
4  * Copyright (C) 1991-1994, 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. Many applications will want to replace
11  * some or all of these routines.
12  *
13  * These routines are used by both the compression and decompression code.
14  */
15 
16 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
17 
18 #include "jinclude.h"
19 #include "jpeglib.h"
20 #include "jversion.h"
21 #include "jerror.h"
22 
23 extern jpg_Error( const char *fmt, ... );
24 extern jpg_Printf( const char *fmt, ... );
25 
26 #ifndef EXIT_FAILURE /* define exit() codes if not provided */
27 #define EXIT_FAILURE 1
28 #endif
29 
30 
31 /*
32  * Create the message string table.
33  * We do this from the master message list in jerror.h by re-reading
34  * jerror.h with a suitable definition for macro JMESSAGE.
35  * The message table is made an external symbol just in case any applications
36  * want to refer to it directly.
37  */
38 
39 #ifdef NEED_SHORT_EXTERNAL_NAMES
40 #define jpeg_std_message_table jMsgTable
41 #endif
42 
43 #define JMESSAGE(code,string) string ,
44 
45 const char * const jpeg_std_message_table[] = {
46 #include "jerror.h"
47  NULL
48 };
49 
50 
51 /*
52  * Error exit handler: must not return to caller.
53  *
54  * Applications may override this if they want to get control back after
55  * an error. Typically one would longjmp somewhere instead of exiting.
56  * The setjmp buffer can be made a private field within an expanded error
57  * handler object. Note that the info needed to generate an error message
58  * is stored in the error object, so you can generate the message now or
59  * later, at your convenience.
60  * You should make sure that the JPEG object is cleaned up (with jpeg_abort
61  * or jpeg_destroy) at some point.
62  */
63 
64 METHODDEF void
66 {
67  char buffer[JMSG_LENGTH_MAX];
68 
69  /* Create the message */
70  (*cinfo->err->format_message) (cinfo, buffer);
71 
72  /* Let the memory manager delete any temp files before we die */
73  jpeg_destroy(cinfo);
74 
75  jpg_Error( "%s\n", buffer );
76 }
77 
78 
79 /*
80  * Actual output of an error or trace message.
81  * Applications may override this method to send JPEG messages somewhere
82  * other than stderr.
83  */
84 
85 METHODDEF void
87 {
88  char buffer[JMSG_LENGTH_MAX];
89 
90  /* Create the message */
91  (*cinfo->err->format_message) (cinfo, buffer);
92 
93  /* Send it to stderr, adding a newline */
94  jpg_Printf( "%s\n", buffer );
95 }
96 
97 
98 /*
99  * Decide whether to emit a trace or warning message.
100  * msg_level is one of:
101  * -1: recoverable corrupt-data warning, may want to abort.
102  * 0: important advisory messages (always display to user).
103  * 1: first level of tracing detail.
104  * 2,3,...: successively more detailed tracing messages.
105  * An application might override this method if it wanted to abort on warnings
106  * or change the policy about which messages to display.
107  */
108 
109 METHODDEF void
110 emit_message (j_common_ptr cinfo, int msg_level)
111 {
112  struct jpeg_error_mgr * err = cinfo->err;
113 
114  if (msg_level < 0) {
115  /* It's a warning message. Since corrupt files may generate many warnings,
116  * the policy implemented here is to show only the first warning,
117  * unless trace_level >= 3.
118  */
119  if (err->num_warnings == 0 || err->trace_level >= 3)
120  (*err->output_message) (cinfo);
121  /* Always count warnings in num_warnings. */
122  err->num_warnings++;
123  } else {
124  /* It's a trace message. Show it if trace_level >= msg_level. */
125  if (err->trace_level >= msg_level)
126  (*err->output_message) (cinfo);
127  }
128 }
129 
130 
131 /*
132  * Format a message string for the most recent JPEG error or message.
133  * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
134  * characters. Note that no '\n' character is added to the string.
135  * Few applications should need to override this method.
136  */
137 
138 METHODDEF void
140 {
141  struct jpeg_error_mgr * err = cinfo->err;
142  int msg_code = err->msg_code;
143  const char * msgtext = NULL;
144  const char * msgptr;
145  char ch;
146  boolean isstring;
147 
148  /* Look up message string in proper table */
149  if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
150  msgtext = err->jpeg_message_table[msg_code];
151  } else if (err->addon_message_table != NULL &&
152  msg_code >= err->first_addon_message &&
153  msg_code <= err->last_addon_message) {
154  msgtext = err->addon_message_table[msg_code - err->first_addon_message];
155  }
156 
157  /* Defend against bogus message number */
158  if (msgtext == NULL) {
159  err->msg_parm.i[0] = msg_code;
160  msgtext = err->jpeg_message_table[0];
161  }
162 
163  /* Check for string parameter, as indicated by %s in the message text */
164  isstring = FALSE;
165  msgptr = msgtext;
166  while ((ch = *msgptr++) != '\0') {
167  if (ch == '%') {
168  if (*msgptr == 's') isstring = TRUE;
169  break;
170  }
171  }
172 
173  /* Format the message into the passed buffer */
174  if (isstring)
175  sprintf(buffer, msgtext, err->msg_parm.s);
176  else
177  sprintf(buffer, msgtext,
178  err->msg_parm.i[0], err->msg_parm.i[1],
179  err->msg_parm.i[2], err->msg_parm.i[3],
180  err->msg_parm.i[4], err->msg_parm.i[5],
181  err->msg_parm.i[6], err->msg_parm.i[7]);
182 }
183 
184 
185 /*
186  * Reset error state variables at start of a new image.
187  * This is called during compression startup to reset trace/error
188  * processing to default state, without losing any application-specific
189  * method pointers. An application might possibly want to override
190  * this method if it has additional error processing state.
191  */
192 
193 METHODDEF void
195 {
196  cinfo->err->num_warnings = 0;
197  /* trace_level is not reset since it is an application-supplied parameter */
198  cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
199 }
200 
201 
202 /*
203  * Fill in the standard error-handling methods in a jpeg_error_mgr object.
204  * Typical call is:
205  * struct jpeg_compress_struct cinfo;
206  * struct jpeg_error_mgr err;
207  *
208  * cinfo.err = jpeg_std_error(&err);
209  * after which the application may override some of the methods.
210  */
211 
212 GLOBAL struct jpeg_error_mgr *
214 {
215  err->error_exit = error_exit;
216  err->emit_message = emit_message;
217  err->output_message = output_message;
218  err->format_message = format_message;
219  err->reset_error_mgr = reset_error_mgr;
220 
221  err->trace_level = 0; /* default = no tracing */
222  err->num_warnings = 0; /* no warnings emitted yet */
223  err->msg_code = 0; /* may be useful as a flag for "no error" */
224 
225  /* Initialize message table pointers */
227  err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
228 
229  err->addon_message_table = NULL;
230  err->first_addon_message = 0; /* for safety */
231  err->last_addon_message = 0;
232 
233  return err;
234 }
METHODDEF void emit_message(j_common_ptr cinfo, int msg_level)
Definition: jerror.c:110
long num_warnings
Definition: jpeglib.h:663
int last_jpeg_message
Definition: jpeglib.h:676
int last_addon_message
Definition: jpeglib.h:682
char s[JMSG_STR_PARM_MAX]
Definition: jpeglib.h:650
case const int
Definition: Callbacks.cpp:52
const char *const * addon_message_table
Definition: jpeglib.h:680
jpg_Error(const char *fmt,...)
Definition: Image_files.cpp:55
METHODDEF void output_message(j_common_ptr cinfo)
Definition: jerror.c:86
const char *const jpeg_std_message_table[]
Definition: jerror.c:45
GLOBAL void jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.c:57
int trace_level
Definition: jpeglib.h:655
union jpeg_error_mgr::@90 msg_parm
#define JMSG_LENGTH_MAX
Definition: jpeglib.h:639
#define NULL
Definition: Lib.h:88
int first_addon_message
Definition: jpeglib.h:681
GLuint buffer
Definition: glext.h:3108
METHODDEF void error_exit(j_common_ptr cinfo)
Definition: jerror.c:65
METHODDEF void reset_error_mgr(j_common_ptr cinfo)
Definition: jerror.c:194
#define GLOBAL
Definition: jmorecfg.h:190
#define METHODDEF
Definition: jmorecfg.h:188
int i[8]
Definition: jpeglib.h:649
METHODDEF void format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:139
static WindowRef ValidModeCallbackProc inCallback OSStatus err
const char *const * jpeg_message_table
Definition: jpeglib.h:675
GLOBAL struct jpeg_error_mgr * jpeg_std_error(struct jpeg_error_mgr *err)
Definition: jerror.c:213
#define FALSE
Definition: mprintf.c:70
#define TRUE
Definition: mprintf.c:69
jpg_Printf(const char *fmt,...)
Definition: Image_files.cpp:66
int sprintf(idStr &string, const char *fmt,...)
Definition: Str.cpp:1528