2 * Copyright (c) 2005, Herv� Drolon, FreeImage Team
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
29 #include "opj_includes.h"
32 /* ==========================================================
34 ==========================================================*/
36 #if !defined(_MSC_VER) && !defined(__MINGW32__)
38 i2a(OPJ_UINT32 i, OPJ_CHAR *a, OPJ_UINT32 r) {
39 if (i/r > 0) a = i2a(i/r,a,r);
40 *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
44 /* ----------------------------------------------------------------------- */
46 bool opj_event_msg(opj_event_mgr_t * p_event_mgr, OPJ_INT32 event_type, const OPJ_CHAR *fmt, ...) {
47 #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
48 opj_msg_callback msg_handler = 00;
52 if(p_event_mgr != 00) {
55 msg_handler = p_event_mgr->error_handler;
56 l_data = p_event_mgr->m_error_data;
59 msg_handler = p_event_mgr->warning_handler;
60 l_data = p_event_mgr->m_warning_data;
63 msg_handler = p_event_mgr->info_handler;
64 l_data = p_event_mgr->m_info_data;
69 if(msg_handler == 00) {
76 if ((fmt != 00) && (p_event_mgr != 00)) {
78 OPJ_INT32 str_length/*, i, j*/; /* UniPG */
79 OPJ_CHAR message[MSG_SIZE];
80 memset(message, 0, MSG_SIZE);
81 /* initialize the optional parameter list */
83 /* check the length of the format string */
84 str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
85 /* parse the format string and put the result in 'message' */
86 vsprintf(message, fmt, arg); /* UniPG */
87 /* deinitialize the optional parameter list */
90 /* output the message to the user program */
91 msg_handler(message, l_data);