2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
|
6 |
* published by the Free Software Foundation. Sun designates this
|
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
|
8 |
* by Sun in the LICENSE file that accompanied this code.
|
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
|
20 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
21 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
22 |
* have any questions.
|
|
23 |
*/
|
|
24 |
|
|
25 |
// This file is available under and governed by the GNU General Public
|
|
26 |
// License version 2 only, as published by the Free Software Foundation.
|
|
27 |
// However, the following notice accompanied the original version of this
|
|
28 |
// file:
|
|
29 |
//
|
|
30 |
//
|
|
31 |
// Little cms
|
2394
|
32 |
// Copyright (C) 1998-2007 Marti Maria
|
2
|
33 |
//
|
|
34 |
// Permission is hereby granted, free of charge, to any person obtaining
|
|
35 |
// a copy of this software and associated documentation files (the "Software"),
|
|
36 |
// to deal in the Software without restriction, including without limitation
|
|
37 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
38 |
// and/or sell copies of the Software, and to permit persons to whom the Software
|
|
39 |
// is furnished to do so, subject to the following conditions:
|
|
40 |
//
|
|
41 |
// The above copyright notice and this permission notice shall be included in
|
|
42 |
// all copies or substantial portions of the Software.
|
|
43 |
//
|
|
44 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
45 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
46 |
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
47 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
48 |
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
49 |
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
50 |
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
51 |
|
|
52 |
|
|
53 |
#include "lcms.h"
|
|
54 |
|
|
55 |
|
|
56 |
// As a rule, only the functions visible from API can signal
|
|
57 |
// errors.
|
|
58 |
|
|
59 |
void cdecl cmsSignalError(int ErrorCode, const char *ErrorText, ...);
|
2394
|
60 |
|
2
|
61 |
int LCMSEXPORT cmsErrorAction(int lAbort);
|
|
62 |
void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn);
|
|
63 |
|
|
64 |
|
|
65 |
// ******************************************************************
|
|
66 |
|
|
67 |
static int nDoAbort = LCMS_ERROR_ABORT;
|
|
68 |
static cmsErrorHandlerFunction UserErrorHandler = (cmsErrorHandlerFunction) NULL;
|
|
69 |
|
|
70 |
|
|
71 |
int LCMSEXPORT cmsErrorAction(int nAction)
|
|
72 |
{
|
|
73 |
int nOld = nDoAbort;
|
|
74 |
nDoAbort = nAction;
|
|
75 |
|
|
76 |
return nOld;
|
|
77 |
}
|
|
78 |
|
|
79 |
void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn)
|
|
80 |
{
|
|
81 |
UserErrorHandler = Fn;
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
// Default error handler
|
|
86 |
|
|
87 |
|
|
88 |
void cmsSignalError(int ErrorCode, const char *ErrorText, ...)
|
|
89 |
{
|
|
90 |
va_list args;
|
|
91 |
|
|
92 |
if (nDoAbort == LCMS_ERROR_IGNORE) return;
|
|
93 |
|
|
94 |
va_start(args, ErrorText);
|
|
95 |
|
|
96 |
if (UserErrorHandler != NULL) {
|
|
97 |
|
|
98 |
char Buffer[1024];
|
|
99 |
|
2394
|
100 |
vsnprintf(Buffer, 1023, ErrorText, args);
|
2
|
101 |
va_end(args);
|
|
102 |
|
|
103 |
if (UserErrorHandler(ErrorCode, Buffer)) {
|
|
104 |
|
|
105 |
return;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
#if defined( __CONSOLE__ ) || defined( NON_WINDOWS )
|
|
110 |
|
|
111 |
fprintf(stderr, "lcms: Error #%d; ", ErrorCode);
|
|
112 |
vfprintf(stderr, ErrorText, args);
|
|
113 |
fprintf(stderr, "\n");
|
|
114 |
va_end(args);
|
|
115 |
|
|
116 |
if (nDoAbort == LCMS_ERROR_ABORT) exit(1);
|
|
117 |
#else
|
|
118 |
{
|
|
119 |
char Buffer1[1024];
|
|
120 |
char Buffer2[256];
|
|
121 |
|
2394
|
122 |
snprintf(Buffer1, 767, "Error #%x; ", ErrorCode);
|
|
123 |
vsnprintf(Buffer2, 255, ErrorText, args);
|
2
|
124 |
strcat(Buffer1, Buffer2);
|
|
125 |
MessageBox(NULL, Buffer1, "Little cms",
|
|
126 |
MB_OK|MB_ICONSTOP|MB_TASKMODAL);
|
|
127 |
va_end(args);
|
|
128 |
|
|
129 |
if (nDoAbort == LCMS_ERROR_ABORT) {
|
|
130 |
|
|
131 |
#ifdef __BORLANDC__
|
|
132 |
_cexit();
|
|
133 |
#endif
|
|
134 |
|
|
135 |
FatalAppExit(0, "lcms is terminating application");
|
|
136 |
}
|
|
137 |
}
|
|
138 |
#endif
|
|
139 |
}
|