J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 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 |
| 32 | // Copyright (C) 1998-2006 Marti Maria |
| 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, ...); |
| 60 | int LCMSEXPORT cmsErrorAction(int lAbort); |
| 61 | void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn); |
| 62 | |
| 63 | |
| 64 | // ****************************************************************** |
| 65 | |
| 66 | static int nDoAbort = LCMS_ERROR_ABORT; |
| 67 | static cmsErrorHandlerFunction UserErrorHandler = (cmsErrorHandlerFunction) NULL; |
| 68 | |
| 69 | |
| 70 | int LCMSEXPORT cmsErrorAction(int nAction) |
| 71 | { |
| 72 | int nOld = nDoAbort; |
| 73 | nDoAbort = nAction; |
| 74 | |
| 75 | return nOld; |
| 76 | } |
| 77 | |
| 78 | void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn) |
| 79 | { |
| 80 | UserErrorHandler = Fn; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | // Default error handler |
| 85 | |
| 86 | |
| 87 | void cmsSignalError(int ErrorCode, const char *ErrorText, ...) |
| 88 | { |
| 89 | va_list args; |
| 90 | |
| 91 | if (nDoAbort == LCMS_ERROR_IGNORE) return; |
| 92 | |
| 93 | va_start(args, ErrorText); |
| 94 | |
| 95 | if (UserErrorHandler != NULL) { |
| 96 | |
| 97 | char Buffer[1024]; |
| 98 | |
| 99 | vsprintf(Buffer, ErrorText, args); |
| 100 | va_end(args); |
| 101 | |
| 102 | if (UserErrorHandler(ErrorCode, Buffer)) { |
| 103 | |
| 104 | return; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #if defined( __CONSOLE__ ) || defined( NON_WINDOWS ) |
| 109 | |
| 110 | fprintf(stderr, "lcms: Error #%d; ", ErrorCode); |
| 111 | vfprintf(stderr, ErrorText, args); |
| 112 | fprintf(stderr, "\n"); |
| 113 | va_end(args); |
| 114 | |
| 115 | if (nDoAbort == LCMS_ERROR_ABORT) exit(1); |
| 116 | #else |
| 117 | { |
| 118 | char Buffer1[1024]; |
| 119 | char Buffer2[256]; |
| 120 | |
| 121 | sprintf(Buffer1, "Error #%x; ", ErrorCode); |
| 122 | vsprintf(Buffer2, ErrorText, args); |
| 123 | strcat(Buffer1, Buffer2); |
| 124 | MessageBox(NULL, Buffer1, "Little cms", |
| 125 | MB_OK|MB_ICONSTOP|MB_TASKMODAL); |
| 126 | va_end(args); |
| 127 | |
| 128 | if (nDoAbort == LCMS_ERROR_ABORT) { |
| 129 | |
| 130 | #ifdef __BORLANDC__ |
| 131 | _cexit(); |
| 132 | #endif |
| 133 | |
| 134 | FatalAppExit(0, "lcms is terminating application"); |
| 135 | } |
| 136 | } |
| 137 | #endif |
| 138 | } |