2 * Copyright (c) 2005, Herve Drolon, FreeImage Team
3 * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France
4 * Copyright (c) 2012, CS Systemes d'Information, France
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include "opj_includes.h"
31 /* ==========================================================
33 ==========================================================*/
35 #ifdef OPJ_CODE_NOT_USED
38 i2a(unsigned i, char *a, unsigned r) {
39 if (i/r > 0) a = i2a(i/r,a,r);
40 *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
45 Transforms integer i into an ascii string and stores the result in a;
46 string is encoded in the base indicated by r.
47 @param i Number to be converted
48 @param a String result
49 @param r Base of value; must be in the range 2 - 36
53 _itoa(int i, char *a, int r) {
54 r = ((r < 2) || (r > 36)) ? 10 : r;
59 else *i2a(i, a, r) = 0;
66 /* ----------------------------------------------------------------------- */
68 * Default callback function.
71 static void opj_default_callback (const char *msg, void *client_data)
73 OPJ_ARG_NOT_USED(msg);
74 OPJ_ARG_NOT_USED(client_data);
77 /* ----------------------------------------------------------------------- */
80 /* ----------------------------------------------------------------------- */
81 OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) {
82 #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
83 opj_msg_callback msg_handler = 00;
86 if(p_event_mgr != 00) {
89 msg_handler = p_event_mgr->error_handler;
90 l_data = p_event_mgr->m_error_data;
93 msg_handler = p_event_mgr->warning_handler;
94 l_data = p_event_mgr->m_warning_data;
97 msg_handler = p_event_mgr->info_handler;
98 l_data = p_event_mgr->m_info_data;
103 if(msg_handler == 00) {
110 if ((fmt != 00) && (p_event_mgr != 00)) {
112 size_t str_length/*, i, j*/; /* UniPG */
113 char message[OPJ_MSG_SIZE];
114 memset(message, 0, OPJ_MSG_SIZE);
115 /* initialize the optional parameter list */
117 /* check the length of the format string */
118 str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
120 /* parse the format string and put the result in 'message' */
121 vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
122 /* deinitialize the optional parameter list */
125 /* output the message to the user program */
126 msg_handler(message, l_data);
132 void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
134 p_manager->m_error_data = 00;
135 p_manager->m_warning_data = 00;
136 p_manager->m_info_data = 00;
137 p_manager->error_handler = opj_default_callback;
138 p_manager->info_handler = opj_default_callback;
139 p_manager->warning_handler = opj_default_callback;