[trunk] Import patch from sumatrapdf team. This handle some Part-2 compliant file...
[openjpeg.git] / src / lib / openjp2 / event.c
index cfc68c195f3a788f30492e397040bcf320ed9202..42f59f0faf425148e0f99bf3ca954e423fa33a08 100644 (file)
@@ -1,5 +1,7 @@
 /*
  * Copyright (c) 2005, Herve Drolon, FreeImage Team
+ * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France 
+ * Copyright (c) 2012, CS Systemes d'Information, France
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -66,59 +68,18 @@ _itoa(int i, char *a, int r) {
  * Default callback function.
  * Do nothing.
  */
-static void opj_default_callback (const char *msg, void *client_data){}
+static void opj_default_callback (const char *msg, void *client_data)
+{
+    OPJ_ARG_NOT_USED(msg);
+    OPJ_ARG_NOT_USED(client_data);
+}
 
 /* ----------------------------------------------------------------------- */
-opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
-#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
-       opj_msg_callback msg_handler = NULL;
-
-       opj_event_mgr_t *event_mgr = cinfo->event_mgr;
-       if(event_mgr != NULL) {
-               switch(event_type) {
-                       case EVT_ERROR:
-                               msg_handler = event_mgr->error_handler;
-                               break;
-                       case EVT_WARNING:
-                               msg_handler = event_mgr->warning_handler;
-                               break;
-                       case EVT_INFO:
-                               msg_handler = event_mgr->info_handler;
-                               break;
-                       default:
-                               break;
-               }
-               if(msg_handler == NULL) {
-                       return OPJ_FALSE;
-               }
-       } else {
-               return OPJ_FALSE;
-       }
-
-       if ((fmt != NULL) && (event_mgr != NULL)) {
-               va_list arg;
-               size_t str_length/*, i, j*/; /* UniPG */
-               char message[MSG_SIZE];
-               memset(message, 0, MSG_SIZE);
-               /* initialize the optional parameter list */
-               va_start(arg, fmt);
-               /* check the length of the format string */
-               str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
-               /* parse the format string and put the result in 'message' */
-               vsprintf(message, fmt, arg); /* UniPG */
-               /* deinitialize the optional parameter list */
-               va_end(arg);
-
-               /* output the message to the user program */
-               msg_handler(message, cinfo->client_data);
-       }
 
-       return OPJ_TRUE;
-}
 
 /* ----------------------------------------------------------------------- */
-opj_bool OPJ_CALLCONV opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_type, const char *fmt, ...) {
-#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
+OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) {
+#define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
        opj_msg_callback msg_handler = 00;
        void * l_data = 00;
 
@@ -149,14 +110,15 @@ opj_bool OPJ_CALLCONV opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_t
        if ((fmt != 00) && (p_event_mgr != 00)) {
                va_list arg;
                size_t str_length/*, i, j*/; /* UniPG */
-               char message[MSG_SIZE];
-               memset(message, 0, MSG_SIZE);
+               char message[OPJ_MSG_SIZE];
+               memset(message, 0, OPJ_MSG_SIZE);
                /* initialize the optional parameter list */
                va_start(arg, fmt);
                /* check the length of the format string */
-               str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
+               str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
+        (void)str_length;
                /* parse the format string and put the result in 'message' */
-               vsprintf(message, fmt, arg); /* UniPG */
+               vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
                /* deinitialize the optional parameter list */
                va_end(arg);
 
@@ -167,7 +129,7 @@ opj_bool OPJ_CALLCONV opj_event_msg_v2(opj_event_mgr_t* p_event_mgr, int event_t
        return OPJ_TRUE;
 }
 
-void OPJ_CALLCONV opj_set_default_event_handler(opj_event_mgr_t * p_manager)
+void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
 {
        p_manager->m_error_data = 00;
        p_manager->m_warning_data = 00;