/src/freeimage-svn/FreeImage/trunk/Source/LibOpenJPEG/event.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
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 |
5 | | * All rights reserved. |
6 | | * |
7 | | * Redistribution and use in source and binary forms, with or without |
8 | | * modification, are permitted provided that the following conditions |
9 | | * are met: |
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. |
15 | | * |
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. |
27 | | */ |
28 | | |
29 | | #include "opj_includes.h" |
30 | | |
31 | | /* ========================================================== |
32 | | Utility functions |
33 | | ==========================================================*/ |
34 | | |
35 | | #ifdef OPJ_CODE_NOT_USED |
36 | | #ifndef _WIN32 |
37 | | static char* |
38 | | i2a(unsigned i, char *a, unsigned r) { |
39 | | if (i/r > 0) a = i2a(i/r,a,r); |
40 | | *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; |
41 | | return a+1; |
42 | | } |
43 | | |
44 | | /** |
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 |
50 | | @return Returns a |
51 | | */ |
52 | | static char * |
53 | | _itoa(int i, char *a, int r) { |
54 | | r = ((r < 2) || (r > 36)) ? 10 : r; |
55 | | if(i < 0) { |
56 | | *a = '-'; |
57 | | *i2a(-i, a+1, r) = 0; |
58 | | } |
59 | | else *i2a(i, a, r) = 0; |
60 | | return a; |
61 | | } |
62 | | |
63 | | #endif /* !_WIN32 */ |
64 | | #endif |
65 | | |
66 | | /* ----------------------------------------------------------------------- */ |
67 | | /** |
68 | | * Default callback function. |
69 | | * Do nothing. |
70 | | */ |
71 | | static void opj_default_callback (const char *msg, void *client_data) |
72 | 0 | { |
73 | 0 | OPJ_ARG_NOT_USED(msg); |
74 | 0 | OPJ_ARG_NOT_USED(client_data); |
75 | 0 | } |
76 | | |
77 | | /* ----------------------------------------------------------------------- */ |
78 | | |
79 | | |
80 | | /* ----------------------------------------------------------------------- */ |
81 | 0 | OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) { |
82 | 0 | #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ |
83 | 0 | opj_msg_callback msg_handler = 00; |
84 | 0 | void * l_data = 00; |
85 | |
|
86 | 0 | if(p_event_mgr != 00) { |
87 | 0 | switch(event_type) { |
88 | 0 | case EVT_ERROR: |
89 | 0 | msg_handler = p_event_mgr->error_handler; |
90 | 0 | l_data = p_event_mgr->m_error_data; |
91 | 0 | break; |
92 | 0 | case EVT_WARNING: |
93 | 0 | msg_handler = p_event_mgr->warning_handler; |
94 | 0 | l_data = p_event_mgr->m_warning_data; |
95 | 0 | break; |
96 | 0 | case EVT_INFO: |
97 | 0 | msg_handler = p_event_mgr->info_handler; |
98 | 0 | l_data = p_event_mgr->m_info_data; |
99 | 0 | break; |
100 | 0 | default: |
101 | 0 | break; |
102 | 0 | } |
103 | 0 | if(msg_handler == 00) { |
104 | 0 | return OPJ_FALSE; |
105 | 0 | } |
106 | 0 | } else { |
107 | 0 | return OPJ_FALSE; |
108 | 0 | } |
109 | | |
110 | 0 | if ((fmt != 00) && (p_event_mgr != 00)) { |
111 | 0 | va_list arg; |
112 | 0 | size_t str_length/*, i, j*/; /* UniPG */ |
113 | 0 | char message[OPJ_MSG_SIZE]; |
114 | 0 | memset(message, 0, OPJ_MSG_SIZE); |
115 | | /* initialize the optional parameter list */ |
116 | 0 | va_start(arg, fmt); |
117 | | /* check the length of the format string */ |
118 | 0 | str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt); |
119 | 0 | (void)str_length; |
120 | | /* parse the format string and put the result in 'message' */ |
121 | 0 | vsprintf(message, fmt, arg); /* UniPG */ |
122 | | /* deinitialize the optional parameter list */ |
123 | 0 | va_end(arg); |
124 | | |
125 | | /* output the message to the user program */ |
126 | 0 | msg_handler(message, l_data); |
127 | 0 | } |
128 | |
|
129 | 0 | return OPJ_TRUE; |
130 | 0 | } |
131 | | |
132 | | void opj_set_default_event_handler(opj_event_mgr_t * p_manager) |
133 | 0 | { |
134 | 0 | p_manager->m_error_data = 00; |
135 | 0 | p_manager->m_warning_data = 00; |
136 | 0 | p_manager->m_info_data = 00; |
137 | 0 | p_manager->error_handler = opj_default_callback; |
138 | 0 | p_manager->info_handler = opj_default_callback; |
139 | 0 | p_manager->warning_handler = opj_default_callback; |
140 | 0 | } |
141 | | |